function RequestParam(name,value){this.getName=function(){return name;}
this.getValue=function(){return value;}}
function callGetJSON(param,url,callback,debug){if(!isValidJSONParams(param,url,"callGetJSON"))return;param[param.length]=new RequestParam("get","");getJSONMethod(param,url,callback,debug);}
function callSaveJSON(param,url,callback,debug){if(!isValidJSONParams(param,url,"callSaveJSON"))return;param[param.length]=new RequestParam("save","");getJSONMethod(param,url,callback,debug);}
function callUpdateJSON(param,url,callback,debug){if(!isValidJSONParams(param,url,"callUpdateJSON"))return;param[param.length]=new RequestParam("update","");getJSONMethod(param,url,callback,debug);}
function callDeleteJSON(param,url,callback,debug){if(!isValidJSONParams(param,url,"callDeleteJSON"))return;param[param.length]=new RequestParam("delete","");getJSONMethod(param,url,callback,debug);}
function isValidJSONParams(p,u,f){if(p==null){alert("Param in "+f+" is Null");return false;}
else if(u==null||u==""){alert("Url in "+f+" is Null");return false;}
return true;}
function getJSONMethod(param,url,callback,debug){var request=getXMLHTTP();request.open('POST',url,true);request.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');request.onreadystatechange=function(){if(request.readyState==4){if(request.status!=200){alert("HTTP Error "+request.status+':\n'+request.statusText);}
else if(trim(request.responseText)==""){alert("Error: Connection with Server has been lost, please retry...");}
else{if(debug)alert(request.responseText);var response=eval('('+request.responseText+')');if(response.error&&response.critical){alert("Error:\n"+response.error);}
else{callback(response,request.responseText,(!response.critical?response.error:null));}}}}
var params="";for(var i=0;i<param.length;i++){params+=param[i].getName()+"="+encodeURIComponent(param[i].getValue());if(i!=param.length-1)params+="&";}
if(debug)alert(params);request.send(params);}