/***************************************************

  This file handles all the ajax scripting handles

***************************************************/

var call = {
   	req:false,
   	reqType:"POST",
	reqForm:null,
   	reqUrl:null,
   	reqArr: new Array(),
	reqStr:null,
	reqId:null,
	reqHead:null,
	returnValue:null,
	clearText:"",	
	callBack:"",
	complete:false,
	xml:null,
	debug:function(str){
	    alert(str);
	},
	// Initialize our object to use later
	init:function(){
	    try {
	        this.req = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
	        try {
	            this.req = new ActiveXObject("Microsoft.XMLHTTP");
	        } catch (ea) {
	            this.req = null;
	        }
	    }
	    if (!this.req && typeof XMLHttpRequest != "undefined") {
	        this.req = new XMLHttpRequest();
	    }
	    if (!this.req) {
	        this.debug("Could not load the XMLHttpRequest");
	    }
	    return this.req;
	},
	parse:function() {											   
		this.reqUrl = (this.reqUrl == null) ? this.reqForm.action : this.reqUrl ;
		this.reqType = this.reqForm.method;
		this.reqStr = "";
		for(var a=0;a<this.reqForm.elements.length;a++) {
		 	this.reqStr += (this.reqForm.elements[a].name != "") ? this.reqForm.elements[a].name + "=" + this.reqForm.elements[a].value + "&" : "" ;
		} 
		this.reqStr.substr(0,this.reqStr.length-1);
	},
	doCall:function(obj) {
		//this.clear(); 
		if (this.reqForm != null) this.parse();
	    var el = document.getElementById(this.reqId);
	    var objXml = this.init();
	    //this.debug(objXml);
	    //this.debug(this.reqType + " " + this.reqUrl + " " + this.reqStr);
	    objXml.open(this.reqType,this.reqUrl,true); 
		if (this.reqType.toLowerCase() == "post") { 
			objXml.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			objXml.send(this.reqStr);
			//this.debug("posting");
		} else if (this.reqType.toLowerCase() == "get") {
			objXml.send(this.reqUrl);
		}
	    objXml.onreadystatechange = function() {
	    	if (objXml.readyState == 4) {
			   	this.callback = eval('(' + objXml.responseText + ')' );
				if (this.callback.e == 0) {
					music.update(obj);
					return false;
				}
				if (this.callback.cal != "") {
					calendar.output(this.callback.cal);
				}
	        }
	    }
	},
	clear:function(){ 
		try {
		 	var el = document.getElementById(this.reqId);
			el.innerHTML = this.clearText;
		} catch (e) {
		 	//
		}
	},
	empty:function(){ 
		try {
		 	var el = document.getElementById(this.reqId);	
			el.innerHTML = "";
		} catch (e) {
		 	//
		}
	}
}



