function webservice_js_client(){var wsclient=this;this.show_process=true;this.request=function(ws_name,obj_arguments,postprocess_function,pass_info,format){wsclient.request_begin=(new Date()).getTime();if(format=="xml"||format=="txt"){wsclient.format=format;}else{wsclient.format="js";};var ajax=new sack();ajax.setVar("ws",ws_name);if(obj_arguments){wsclient.request_args=obj_arguments;for(curr_var in wsclient.request_args){curr_value=wsclient.request_args[curr_var];if(typeof curr_value=="object"){for(key in curr_value){if(typeof curr_value[key]=="string"&&curr_value[key].indexOf(",")>-1){js_error("At least one parameter for the request contains an invalid character (comma).",curr_var+"-"+key);};};ajax.setVar(curr_var+"_is_array","1");};ajax.setVar(curr_var,wsclient.request_args[curr_var]);};}else{wsclient.request_args=new Object();};if(typeof pass_info!="object"){pass_info={"ws_name":ws_name};}else{pass_info.ws_name=ws_name;};wsclient.pass_info=pass_info;ajax.setVar("f",wsclient.format);ajax.requestFile="ws.php";ajax.method="POST";if(wsclient.show_process){ajax.onLoading=function(){display_pagewide_msg("Sending request...");};ajax.onLoaded=function(){change_pagewide_msg("Receiving response...");};ajax.onInteractive=function(){change_pagewide_msg("Processing data...");};};ajax.onCompletion=function(){wsclient.request_end=(new Date()).getTime();wsclient.execution_time=(wsclient.request_end-wsclient.request_begin)/1000;window.status="Request completed in "+wsclient.execution_time+" seconds.";var request_status;switch(wsclient.format){case'js':if(ajax.response.indexOf("<html>")>-1||ajax.response.indexOf("<HTML>")>-1){if(ajax.response.indexOf("Fatal error")>-1){wsclient.response_is_invalid("php_fatal");}else{wsclient.response_is_invalid("html");};};eval(ajax.response);if(typeof ws_status=="undefined"){wsclient.response_is_invalid();}else if(ws_status=="OK"&&typeof w=="undefined"){wsclient.response_is_invalid();};if(ws_status.code=="OK"){request_status=[true,""];}else{request_status=[false,ws_status.error_msg];};break;default:request_status=wsclient.request_success(ajax.responseXML,ajax.response);};if(request_status[0]){if(wsclient.show_process){hide_pagewide_msg();};if(postprocess_function){switch(wsclient.format){case'xml':eval(postprocess_function+"(ajax.responseXML, wsclient.format, wsclient.request_args, wsclient.pass_info);");break;case'js':eval(postprocess_function+"(w, wsclient.format, wsclient.request_args, wsclient.pass_info);");break;default:eval(postprocess_function+"(ajax.response, wsclient.format, wsclient.request_args, wsclient.pass_info);");};};}else{if(wsclient.show_process){hide_pagewide_msg();};js_error(request_status[1],"WS");};};ajax.runAJAX();};this.request_success=function(responseXML,responseText){switch(wsclient.format){case'xml':if(!responseXML.hasChildNodes()){var is_xml=false;}else if(typeof responseXML.getElementsByTagName("envelope")[0]=="undefined"){var is_xml=false;}else{var is_xml=true;};if(!is_xml){this.response_is_invalid();}else{var env_header=responseXML.getElementsByTagName("envelope")[0].getElementsByTagName("header")[0];var status=env_header.getElementsByTagName("status")[0].firstChild.nodeValue;if(status=="OK"){return[true,""];}else if(status=="ERROR"){var status_msg=env_header.getElementsByTagName("error_msg")[0].firstChild.nodeValue;return[false,status_msg];};};break;case'txt':case'text':if(responseText.substr(0,15)=="WS_STATUS=ERROR"){response_parts=responseText.split("\t");status_msg=response_parts[1];return[false,status_msg];}else{return[true,""];};break;default:js_error("Method for determining the success of the request has not been defined.",wsclient.format);};};this.response_is_invalid=function(invalid_type){if(wsclient.show_process){hide_pagewide_msg();};if(invalid_type=="php_fatal"){c_msg="Response from server has an invalid format. A fatal error occured in the server-side script.";}else if(invalid_type=="html"){c_msg="Response from server has an invalid format. It is an HTML document.";}else{c_msg="Response from server has an invalid format.";};js_error(c_msg);};};function standard_ws_call(ws_name,parms,response_format,post_actions,flags){var ws=new webservice_js_client();if(typeof parms!="object")var parms=new Object();if(typeof flags!="string")flags="";pass_info=new Object();pass_info._respformat=response_format;pass_info._postacts=post_actions;if(flags.indexOf("skip_show_process")>-1){ws.show_process=false;};ws.request(ws_name,parms,"process_standard_ws_call",pass_info,"js");};function process_standard_ws_call(rsp,format,input_args,passed_info){var f=passed_info._respformat;var a=passed_info._postacts;var success=true;if(!f)f="";if(f=="error/result"||f=="error/result_quiet"){var is_quiet=(f=="error/result_quiet"?true:false);if(rsp.status=="ok"){var msgcount=rsp.result_msg.length;if(msgcount==0){msgcount=count_props(rsp.result_msg);};var result_msg=(!is_quiet||msgcount>0?"Operation completed successfully.":"");if(msgcount>0){result_msg+=" Please note:\n";for(var i in rsp.result_msg){result_msg+="\n- "+rsp.result_msg[i];};};if(result_msg){alert(result_msg);};}else{success=false;var err_msg="Sorry, operation could not be completed because:\n";for(var i in rsp.err_msg){err_msg+="\n- "+rsp.err_msg[i];};alert(err_msg);};}else if(f=="boolean"||f=="boolean_quiet"){if(rsp&&f!="boolean_quiet"){alert("Operation completed.");}else if(!rsp){success=false;alert("Sorry, the operation failed.");};}else if(f.substr(0,13)=="filldropdown:"){var args=f.substr(13);args=args.split("|");if(args.length!=3){js_error("Configuration error. Parameters for filling dropdown box are invalid.",args.join("X"));return;};var obj=get_obj(args[0]);obj.options.length=0;if(rsp.length>0){obj.options[0]=new Option("","");for(var i in rsp){next_index=obj.options.length;obj.options[next_index]=new Option(rsp[i][args[2]],rsp[i][args[1]]);};};}else if(f=="nothing"){};var c;a=(typeof a=="string"?[a]:a);for(var act in a){c=a[act];if(c.substr(0,8)=="message:"){alert(c.substr(8));}else if(success&&c.substr(0,8)=="sethtml:"){var args=c.substr(8);args=args.split("|");if(args.length!=2){js_error("Configuration error. Parameters for setting HTML are invalid.",args.join("X"));return;};set_text(args[0],args[1]);}else if(success&&c.substr(0,21)=="callfunction_success:"){var functionname=c.substr(21);window[functionname](rsp,format,input_args,passed_info);}else if(!success&&c.substr(0,21)=="callfunction_failure:"){var functionname=c.substr(21);window[functionname](rsp,format,input_args,passed_info);}else if(success&&c.substr(0,14)=="redirect_page:"){window.location.href=c.substr(14);}else if(success&&c=="reload_page"){window.location.reload();};};}
/*** Powered by phpJSO -- http://www.comrax.com/phpJSO ***/
/*** Copyright © 2006 WinterNet Studio, Allan Jensen (www.winternet.no). All rights reserved. (Except on code not produced by WinterNet Studio) ***/