function GetXmlHttpObject(){
	var xmlHttp=null;
	try{		
	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){		  
		// Internet Explorer
		try{		    
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){		    
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	return xmlHttp;
}
		
function getDataByAJAX(url, func, method, parameters){		
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){		
 		alert ("Your browser does not support AJAX!");
  		return;
 	}		
 	xmlHttp.onreadystatechange=func;
 	
	var tmpM = 'GET';
	if(method!=undefined && method!=null)
		tmpM = method;
		
	xmlHttp.open(tmpM,url,true);		
		
	if(tmpM == 'GET'){		
		xmlHttp.send(null);
	}else if(tmpM == 'POST'){
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", parameters.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(parameters);		
	}
}

function getResponseXMLDoc(xmlHttp){
	if(xmlHttp.responseXML.documentElement==null){
		var responseXML = xmlHttp.responseText;	
		responseXML = responseXML.substring(responseXML.indexOf('<?xml'));		
		xmlHttp.responseXML.loadXML(responseXML);		
	}
	return xmlHttp.responseXML.documentElement;
}

function fillComboByAJAX(xmlHttp, box, firstOption, lastAction){
	if (xmlHttp.readyState==4){				
		box.options.length=0;	
		var tmpArr = eval(xmlHttp.responseText);
		var i=0;
		if(firstOption!=null){
			box.options[i]=firstOption;
			i++;
		}	
		var j=0;
		while(j<tmpArr.length){
			box.options[i]=tmpArr[j];
			j++;
			i++;
		}				
		if(lastAction!=null)
			eval(lastAction);
	}
}

function convertFormToAjax(frm) {
	var getstr = "";
    for (i=0; i<frm.elements.length; i++) {
    	var node = frm.elements[i];
      	var tagName = node.tagName == null ? "": node.tagName;
      	var name = node.name == null ? "": node.name;
      	var type  = node.type == null ? "": node.type;
      	var value = node.value == null ? "": node.value;
      	
      	
      	if (tagName.equalsIgnoreCase("INPUT")) {
        	if (type.equalsIgnoreCase("text") || type.equalsIgnoreCase("hidden")) {
               getstr += name + "=" + value + "&";
            }
            if (type.equalsIgnoreCase("checkbox")) {
            	checked = node.checked;
               if (checked) {
                  getstr += name + "=" + value + "&";
               } else {
                  getstr += name + "=&";
               }
            }
            if (type.equalsIgnoreCase("radio")) {
           	 checked = node.checked;
               if (checked) {
                  getstr += name + "=" + value + "&";
               }
            }
        }   
        if (tagName.equalsIgnoreCase("SELECT")) {
        	var sel = node;
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
        }        
	}
	if(getstr.length > 1)
    	getstr = getstr + '&sid='+Math.random(); 

	return getstr;
}
		

