var ax = {
	IE 					: false,
	REQUEST_GET        	: 0,
	REQUEST_POST        : 2,
	REQUEST_HEAD    	: 1,
	REQUEST_XML        	: 3,
	xmlHttp				: false,
	
	callMethod : function(pObj, pMethod, pParams, cbMethod, cbContainerID, SID, rfMod, isJson){
		var params = "ajaxReq=true&pObject="+pObj+"&pMethod="+pMethod+"&pParams[]="+pParams+"&cbMethod="+cbMethod+"&cbContainerID="+cbContainerID+"&SID="+SID+"&rfMod="+rfMod+"&isJson="+isJson;
		//alert(params);
		this.sendRequest("ajaxHandler.php", params, 2, 2);
	},
	
	getXMLRequester : function(){
		var tmpXmlHttp = false;	
	    // try to create a new instance of the this.tmpXmlHttprequest object
	    try{
	        // Internet Explorer
	        if( window.ActiveXObject ){
	        	this.IE = true;
	        	for( var i = 5; i; i-- ){
	                try{
	                    // loading of a newer version of msxml dll (msxml3 - msxml5) failed
	                    // use fallback solution
	                    // old style msxml version independent, deprecated
	                    if( i == 2 ){
	                        tmpXmlHttp = new ActiveXObject( "Microsoft.xmlHttp" );
	                    }else{	
	                        tmpXmlHttp = new ActiveXObject( "Msxml2.xmlHttp." + i + ".0" );
	                    }
	                    break;
	                }
	                catch( excNotLoadable ){
	                    tmpXmlHttp = false;
	                }
	            }
	        }else if(window.XMLHttpRequest){
	            tmpXmlHttp = new XMLHttpRequest();
	        }

	    }
	    // loading of tmpXmlHttp object failed
	    catch( excNotLoadable ){
	        tmpXmlHttp = false;
	    }
	    
	    return tmpXmlHttp;
	},
	
	sendRequest : function( strSource, strData, intType, intID ){
		if( !strData )
        	strData = '';
	
	    // default type (0 = GET, 1 = xml, 2 = POST )
	    if( isNaN( intType ) )
	        intType = 0; // GET
	
	    // previous request not finished yet, abort it before sending a new request
	    if( this.xmlHttp && this.xmlHttp.readyState ){
	        this.xmlHttp.abort();
	        this.xmlHttp = false;
	    }
	    
	    // create a new instance of this.xmlHttprequest object
	    // if it fails, return
	    if( !this.xmlHttp ){
	        this.xmlHttp = this.getXMLRequester();
	        if( !this.xmlHttp ){
	        	return;
	        }
	    }
    
	
	    // parse query string
	    if( intType != 1 && ( strData && strData.substr( 0, 1 ) == '&' || strData.substr( 0, 1 ) == '?' ) )
	        strData = strData.substring( 1, strData.length );
	
	    // data to send using POST
	    var dataReturn = strData ? strData : strSource;
	
	    switch( intType )
	    {
	        case 1:    // xml
	            strData = "xml=" + strData;
	        case 2: // POST
	            // open the connection
	            this.xmlHttp.open( "POST", strSource, true );
	            this.xmlHttp.setRequestHeader("Method", "POST " + strSource + " HTTP/1.1");
	            this.xmlHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
	            this.xmlHttp.setRequestHeader( 'Content-length', strData.length );
	            break;
	        case 3: // HEAD
	            // open the connection
	            this.xmlHttp.open( "HEAD", strSource, true );
	            strData = null;
	            break;
	        default: // GET
	            // open the connection
	            var strDataFile = strSource + (strData ? '?' + strData : '' );
	            this.xmlHttp.open( "GET", strDataFile, true );
	            strData = null;
	    }
	    
	    // set onload data event-handler
	    this.xmlHttp.onreadystatechange = new Function( "", "ax.processResponse(" + intID + ")" );
	
	    // send request to server
	    this.xmlHttp.send( strData );    // param = POST data
	},
	
	processResponse : function(intID){
		
		// status 0 UNINITIALIZED open() has not been called yet.
	    // status 1 LOADING send() has not been called yet.
	    // status 2 LOADED send() has been called, headers and status are available.
	    // status 3 INTERACTIVE Downloading, responseText holds the partial data.
	    // status 4 COMPLETED Finished with all operations.
	    switch( this.xmlHttp.readyState ){
	        // uninitialized
	        case 0:
	        // loading
	        case 1:
	        // loaded
	        case 2:
	        // interactive
	        case 3:
	            break;
	        // complete
	        case 4:
	            // check http status
	            // success
	            if( this.xmlHttp.status == 200 ){
	            	return this.processData( this.xmlHttp, intID );
	            }else{
	                if( window.handleAJAXError )
	                    this.handleAJAXError( this.xmlHttp, intID );
	                else
	                    alert( "ERROR\n HTTP status = " + this.xmlHttp.status + "\n" + this.xmlHttp.statusText ) ;
	            }
	    }
	
	    return false;
	},
	
	processData : function(xmlHttp, intID ){
		r = xmlHttp.responseText.replace(/^\s*|\s*$/g,"");

	    if(this.IE == false){
	    	var parser = new DOMParser();
	    	xmlDoc = parser.parseFromString(r, "text/xml");
	    }else{
	    	xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	       	xmlDoc.loadXML(r);
	    }
	
		var axFunction  = xmlDoc.getElementsByTagName("cbMethod")[0].firstChild.nodeValue;
		var axParams	= new Array();
	
		tmp 			= xmlDoc.getElementsByTagName("result");
	
		for(i=0; i < tmp.length; i++){
			axParams[i] = tmp[i].firstChild.nodeValue
		}
	
		
		try {
			tmp = axFunction.split(":");
			cbContainer = undefined;
			if(tmp.length == 2){
				axFunction  = tmp[0];
				cbContainer = tmp[1];
			}
			
			var callback = eval(axFunction);
			callback(eval(axParams), cbContainer);
			
		} catch (e) {
			alert("Caught error " + e + ": Could not eval " + axParams );
		}
		
		this.xmlHttp = false;
		return true;
	},
	
	handleAJAXError : function( xmlHttp, intID ){

	}
	
};

var axcb = {
	ax_cbMethod : function(r){
		alert(r);
	}
}