
// ============================================
// Data Posting Functions
// ============================================

function universalPostToServer(path, mode, postData, async, asyncCallBackFunction, httpRequest, responseXML){
   try {
        var  hostname = window.location.hostname;
        var  port = window.location.port;
       
        if (mode != ""){
            //Debug
            //var url = "http://"+hostname + ":" + port + "/Uncompiled" + path + "?mode=" + mode;
            var url = "http://"+hostname + ":" + port + path + "?mode=" + mode;
        } else {
            url = "http://"+hostname + ":90" + path;
        }
        
        if (async==null){
        	async=false;
        } 
        if (responseXML==null){
        	responseXML=false;
        }
        
        if (httpRequest == null){
        	var httpRequest = new XMLHttpRequest();
        }
        
        httpRequest.open("POST", url, async, null, null);
        httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  
        if (async == true){
        
        	if (asyncCallBackFunction != null){
        		httpRequest.onreadystatechange = asyncCallBackFunction;
        	}
        	
        	httpRequest.send(postData);
        	return httpRequest;
        	
        } else {       
        
            httpRequest.send(postData);
			if (responseXML==true){
				return httpRequest.responseXML;
			} else {
				return httpRequest.responseText;
			}
			
        }
        
    } catch (ex){alert(ex);}
    return null;
}


function createXMLRequest(){

    //Browser supports XMLHTTPRequest (Mozilla / IE7)
    if (window.XMLHttpRequest){
    
        return new XMLHttpRequest();
        
    }else{
    
        //Old browser only supports ActiveX
        return new ActiveXObject("Microsoft.XMLHTTP");
    
    }

    //If still in function the browser does not support AJAX
    alert('Your browser / browser version is not supported by our website.\nPlease view our disclaimer to view a list of supported browsers.');

}



function convertXMLResponseToArray(message, parent_node, child_node){

    //Get top logs node
    var parentNode = message.getElementsByTagName(parent_node);

    var parentNode = parentNode[0]; 
    
    //Get top logs node
    var chileNode = parentNode.getElementsByTagName(child_node);

    var dataArray = new Array();

    for(var i = 0; i < chileNode.length; i++){

        chileNodeCurrent = chileNode[i]; 

        var chileNodeCurrent = chileNodeCurrent.childNodes;

        var childNodeArray = new Array()

        //Go through each child node:
        for(var i_s = 0; i_s < chileNodeCurrent.length; i_s++){

            try{
				
                childNodeArray[chileNodeCurrent[i_s].nodeName] = chileNodeCurrent[i_s].firstChild.nodeValue;

            }catch(e){

            //Fail Silently

            }

        }

        dataArray[i] = childNodeArray;

    }

    return dataArray;
    
}




