var xmlHttp_obj=null;

function GetxmlHttp_object(){
	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 sendRequest(page,method,formname,divId){
	//alert(divId);
	xmlHttp_obj=GetxmlHttp_object()
	if (xmlHttp_obj==null){
	  alert ("Your browser does not support AJAX!");
	  return false;
	} 
	
	var url=page;
	xmlHttp_obj.onreadystatechange=function(){stateChanged_fnc(divId)};
	
	//xmlHttp_obj.open("GET",url,true);
	//xmlHttp_obj.send(null);
	
	if(method == "POST"){
		xmlHttp_obj.open('POST',page,true);
		// set form http header
		xmlHttp_obj.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		// get form values and send http request
		xmlHttp_obj.send(getFormValues(formname));
	
	
	}else if(method == "GET"){
	
		xmlHttp_obj.open('GET',page,true);
		
		xmlHttp_obj.send(null);						
	}
 
}

function stateChanged_fnc(divId){ 
	//uninitialized
	if (xmlHttp_obj.readyState==0){ 
	 	//document.getElementById(divId).innerHTML="<img src='graphics/loader.gif'  />";
		window.status="uninitialized";
	}
	//loading
	if (xmlHttp_obj.readyState==1){ 
	 	//document.getElementById(divId).innerHTML="<img src='graphics/loader.gif'  />";	
		window.status="loading";
	}
	//loaded
	if (xmlHttp_obj.readyState==2){ 
	 	//document.getElementById(divId).innerHTML="<img src='graphics/loader.gif' />";	
		window.status="loaded";
	}
	//interactive (some data has been returned)
	if (xmlHttp_obj.readyState==3){ 
	 	//document.getElementById(divId).innerHTML="<img src='graphics/loader.gif' />";	
		window.status="interactive (some data has been returned)";
	}
	//alert("");
	//complete
	if (xmlHttp_obj.readyState==4){ 
		window.status="complete";
	 	document.getElementById(divId).innerHTML=xmlHttp_obj.responseText;	
		try{
			document.frm1.reset();
		}
		catch(e){}
		
	}
}


function getFormValues(fobjname){
	var fobj=document.getElementById(fobjname);
    var str='';
    for(var i=0;i< fobj.elements.length;i++){
		if(fobj.elements[i].type=="checkbox" ){
			if(fobj.elements[i].checked==true){
				str+=fobj.elements[i].name+'='+escape(fobj.elements[i].value)+'&';//escape		
			}
		}else{
        	str+=fobj.elements[i].name+'='+ escape(fobj.elements[i].value)+'&';
		}
    }
    str=str.substr(0,(str.length-1));
	//alert(str); 
    return str;
}



