﻿// JScript File
/*
This webservice helper js.
ExecuteWebserviceCall fn is used to call webservice using jquery.
ConvertWebServiceResponseToJsonObject fn this converts webservice response to json object.
*/
function ConvertWebServiceResponseToJsonObject(msg)
  {
    var responseText = msg.replace(/\<.+?\>/g,"");  
     var JSONobject = null;
    if(responseText.length>3)   
    JSONobject = eval('('+ responseText +')');  
    return JSONobject
  }
  
  function htmlDecode(t) {
    var x = t.replace(/\&amp\;/g, '\&');
    x = x.replace(/\&gt\;/g, '\>');
    x = x.replace(/\&lt\;/g, '\<');
    x = x.replace(/\&quot\;/g, '\'');
    x = x.replace(/\&\#39\;/g, '\'');
    return(x);
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
  
  
 /**
 weburl -  url with parameters
 responseDataType : Response DataType - xml,text,html,json
 callBackfunction : Function to handle the response from the server.
 **/ 
 function ExecuteWebserviceCall(weburl,responseDataType,callBackfunction)
  {
    $.ajax({ 
    type: "POST",   
    
    data: {},   
    url:weburl,     
    beforeSend: function(xhr) {
      xhr.setRequestHeader("Content-type", 
                           "application/json; charset=utf-8");
    },
    dataType:"text",     
    success: function(msg) {   
       var details =  ConvertWebServiceResponseToJsonObject(msg);      
       callBackfunction(details) 
     } ,
     error:function(xml,msg,e)
     {
       // alert("here");
     }   
  });
  }  
  