//object available to page
var oApplication = new application();
/**
 * the application class provides methods for javascript functionalities common to all applications
 *
 */
function application(){
  //properties
  var pathToRoot;
  var localBoot;
  //methods
  this.makeAjaxCall = makeAjaxCall;
  this.getXMLHttpObj = getXMLHttpObj;
  this.checkApplicationParameters = checkApplicationParameters;
}
/*
 * makes an ajax call
 *  
 * @param string id
 * 
 * @return string cleaned id   
 */
function makeAjaxCall(fileToLoad,callbackFunction,oCallbackFunctionParameters,bSync,sendMethod,oPostData){
	//auto add boot name
	fileToLoad += '&boot_name='+this.localBoot;
  var http_request = this.getXMLHttpObj();
  if (!http_request) {
      alert('Giving up :( Cannot create an XMLHTTP instance');
      return false;
  }
  http_request.onreadystatechange = function() {
      if (http_request.readyState == 4) {
          if (http_request.status == 200) {
            if(callbackFunction){
              var callbackFunctionParameters = '(http_request.responseText';
              if(oCallbackFunctionParameters){
                for(i in oCallbackFunctionParameters){
                  callbackFunctionParameters += ',\''+oCallbackFunctionParameters[i]+'\'';
                }
              }
              callbackFunctionParameters += ')';
              eval(callbackFunction + callbackFunctionParameters);
            }
          }else{
          	if(oDebugManager.bOn){
            	alert('There was a problem with the request.(Code: '+http_request.status+', URL: '+fileToLoad+')');
            }
          }
      }
  };
  bAsync = bSync ? !bSync : true;
  if(sendMethod == 'post'){
    http_request.open('POST', fileToLoad, true);
    var parametersString = '';
    for(i in oPostData){
      parametersString += '&'+i+'='+encodeURI(oPostData[i]);
    }
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parametersString.length);
    if(!(oDisplayManager.browserDetect.browser == 'Explorer' && oDisplayManager.browserDetect.version < 7)){
      http_request.setRequestHeader("Connection", "close");
    }
    http_request.send(parametersString);
  }else{
    http_request.open('GET', fileToLoad, bAsync);
    http_request.setRequestHeader('If-Modified-Since','Sat, 1 Jan 2000 00:00:00 GMT');
    http_request.send(null);
  }
  delete bAsync;
}
/*by Mark Kahn, from www.webreference.com*/
function getXMLHttpObj(){
	if(typeof(XMLHttpRequest)!='undefined')
		return new XMLHttpRequest();
	var axO=['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0',
		'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'], i;
	for(i=0;i<axO.length;i++)
		try{
			return new ActiveXObject(axO[i]);
		}catch(e){}
	return null;
}

/*
 * checks mandatory class parameters and displays alert if necessry
 *  
 * @param object className: class name
 * @param object oApplication: class object  
 * @param array aMandatories: mandatory parameters list  
 *   
 * @return boolean     
 */
function checkApplicationParameters(className,oApplication,aMandatories){
  var aEmptyMandatories = new Array();
  for(i in aMandatories){
    if(!oApplication[aMandatories[i]]) aEmptyMandatories.push(aMandatories[i]);
  }
  if(aEmptyMandatories.length > 0){
    alert('WARNING,the following properties *MUST* be defined for object of class \''+className+'\': '+aEmptyMandatories.join(','));
    return false;
  }else{
    return true;
  }
}
