//ajax class
function clearFields(fields){
  var arr = fields.split('|');
  for (i=0;i<arr.length;i++){
    var fld = document.getElementById(arr[i]);
    if (fld!=null)
      fld.value="";
  }
    
}


function istAjax(){
  var callBackMethod=null;
  this.setCallBackMethod=setCallBackMethod;
  this.getCallBackMethod=getCallBackMethod;
  this.invokeForSelect=invokeForSelect;
  var http = null;
  var select = null;
  var check = true;
  ext_com = '';
  this.invoke = invoke;

	function checkError(b){
	 check = b;
	}
  
  function buildOption(xmlDocument){
		select.options.length=0;
    var root = xmlDocument.documentElement;
    if (ext_com!=''){
      select.options[0] = new Option(ext_com, '');
    }
    for (i=1; i<root.childNodes.length; i++){
      var data = root.childNodes[i];
      var id = data.childNodes[0];
      var name = data.childNodes[1];
      select.options[i] = new Option(name.firstChild.data, id.firstChild.data);
    }	
	}
  
	function invokeForSelect(url,id,_ext_com){
    if (http==null)
      http = getHTTPObject();
    
		select = id;
		ext_com = _ext_com;
    callBackMethod = "buildOption";
    http.open("GET", url, true);
    http.onreadystatechange = getData;
    http.send(null);  
    document.body.style.cursor='wait';    
	}


  function invoke(url){
    if (http==null)
      http = getHTTPObject();
    
    if (callBackMethod==null)
      callBackMethod = "standardCallBackMethod";
    http.open("GET", url, true);

    http.onreadystatechange = getData;
    http.send(null);  
    document.body.style.cursor='wait';    
  }
 
  function standardCallBackMethod(xmlDocument){
    var root = xmlDocument.documentElement;
    for (i=0; i<root.childNodes.length; i++){
      if (!root.childNodes[i].firstChild)
        continue;
        if (document.getElementById(root.childNodes[i].nodeName)==null)
        continue;
        
        document.getElementById(root.childNodes[i].nodeName).value = root.childNodes[i].firstChild.data;
    }  
  }

  function getCallBackMethod(){  
    return callBackMethod;
  }  
  
  function setCallBackMethod(method){  
    callBackMethod = method;  
  }
  
  function getData(){
    if (http.readyState == 4 && http.status==200) { 
        eval(callBackMethod+'(http.responseText);');
        /*
        if (checkAjaxData(http.responseText)){
            eval(callBackMethod+'(http.responseXML);');
        }
        */
       document.body.style.cursor='default';
    }
  }

  function checkAjaxData(response){
    if (response.indexOf('invalid') != -1){
      alert(response);
      return false;
    }
    if(response.indexOf('error')!= -1) {
              errors = response.split('|');
              alert(errors[1]);
              return false;
    }
    else
      return true;
  }


  function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
      try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e) {
        try {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E) {
          xmlhttp = false;
        }
      }
    @else
  
    xmlhttp = false;
    @end @*/
  
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
      try {
        xmlhttp = new XMLHttpRequest();
      }
      catch (e) {
        xmlhttp = false;
      }
    }
    return xmlhttp;
  }
}