function create_object(){
	if(window.XMLHttpRequest){
		var obj	=	new XMLHttpRequest();
	}else if(window.ActiveXObject){
		var obj	=	new ActiveXObject("Microsoft.XMLHTTP");
	}
	return obj;
}

htp		=	create_object();
http		=	create_object();

function send_request(id,t,sid)
{
	var x=t;
	if(sid=="" || sid==0)
	{
		url	=	"ajax_response.php?action=state&id="+id;	
	}
	else
	{
		url	=	"ajax_response.php?action=state&id="+id+"&sid="+sid;	
	}
	
	http.open('get',url,false);
	http.onreadystatechange	=	function handle_response()
	{
		if(http.readyState==4)
		{
			var txt	=	http.responseText;
	    	if(txt!="")
			{
				document.getElementById('div_state'+x).innerHTML	=	txt;
        	}
     	}
 	};
 	http.send(null);
}


function send_request_wh(id,t,sid)
{
	var x=t;
	if(sid=="" || sid==0)
	{
		url	=	site_ws_path+"/ajax_response.php?action=wstate&id="+id;	
		//url	=	"ajax_response.php?action=wstate&id="+id;	
		//url	=	site_ws_email_path+"/ajax_response.php?action=wstate&id="+id;	
	}
	else
	{
		url	=	site_ws_path+"/ajax_response.php?action=wstate&id="+id+"&sid="+sid;	
		//url	=	"ajax_response.php?action=wstate&id="+id+"&sid="+sid;	
		//url	=	site_ws_email_path+"/ajax_response.php?action=wstate&id="+id+"&sid="+sid;	
	}
	http.open('get',url,false);
 	http.onreadystatechange	=	
 		function handle_response_wh()
 		{
	 		if(http.readyState==4)
	 		{
				var txt	=	http.responseText;
	    		if(txt!="")
	    		{
					//alert(txt);
					document.getElementById('div_state'+x).innerHTML	=	txt;
        		}
     		}
 		};
 	http.send(null);
}


function send_request1(id,t,sid){
var x=t;
url	=	"ajax_response.php?action=search_state&id="+id;	
http.open('get',url,false);
 http.onreadystatechange	=	function handle_response1(){
	 if(http.readyState==4){
		var txt	=	http.responseText;
	    if(txt!=""){
			document.getElementById('div_state'+x).innerHTML	=	txt;
        }
     }
 };
 http.send(null);
}


/*
function send_request_cost(action,id){
url	=	"ajax_response.php?action="+action+"&id="+id;
htp.open('get',url,false);
htp.onreadystatechange	=	function handle_sms_price(){
	 if(htp.readyState==4){
		var txt	=	htp.responseText;
		//alert(txt);
	    if(txt!=""){
			document.getElementById('cost_sms').value	=	txt;
        }
     }
 };
 htp.send(null);
}
*/

/*
function send_sales(id,comp_id,sa){
	url	=	'ajax_response.php?act=sales&id='+id+'&comp_id='+comp_id+'&sa='+sa;
	htp.open('get',url,false);
	htp.onreadystatechange	=	function handle_sales(){
	 if(htp.readyState==4){
		var txt	=	htp.responseText;
		 if(txt!=""){
			document.getElementById('div_sales').innerHTML	=	txt;
        }
     }
 };
 htp.send(null);

}
*/

/*
function send_address(id){

	url	=	'ajax_response.php?act1=address&id='+id;
	htp.open('get',url,false);
	htp.onreadystatechange	=	function handle_address(){
	 if(htp.readyState==4){
		var txt	=	htp.responseText;
		 if(txt!=""){
			arr	=	txt.split('~DM~'); 
			document.getElementById('whs_address').value	=	arr[0];
			document.getElementById('whs_city').value	=	arr[1];
			document.getElementById('whs_country').value	=	arr[3];
			document.getElementById('whs_website').value	=	arr[4];
			send_request(arr[3],1,arr[2]);
        }
     }
 };
 htp.send(null);

}

*/

function send_request2(id,t,sid,al)
{
	var x=t;
	if(sid=="" || sid==0)
	{
		url	=	"ajax_response.php?action=state&id="+id+"&al="+al;	
	}
	else
	{
		url	=	"ajax_response.php?action=state&id="+id+"&sid="+sid+"&al="+al;	
	}
	http.open('get',url,false);
 	http.onreadystatechange	=	function handle_response()
 		{
	 		if(http.readyState==4)
	 		{
				var txt	=	http.responseText;
	    		if(txt!="")
	    		{
					document.getElementById('div_state'+x).innerHTML	=	txt;
        		}
     		}
 		};
 	http.send(null);
}

/*
function send_request3(id,t,sid,al){
var x=t;
if(sid=="" || sid==0){
//url	=	site_ws_path+"/ajax_response.php?action=state&id="+id+"&al="+al;	
url	=	site_ws_email_path+"/ajax_response.php?action=state&id="+id+"&al="+al;	
//url	=	"ajax_response.php?action=state&id="+id+"&al="+al;	
}else{
//url	=	site_ws_path+"/ajax_response.php?action=state&id="+id+"&sid="+sid+"&al="+al;	
url	=	site_ws_email_path+"/ajax_response.php?action=state&id="+id+"&sid="+sid+"&al="+al;	
//url	=	"ajax_response.php?action=state&id="+id+"&sid="+sid+"&al="+al;	
}
http.open('get',url,false);
 http.onreadystatechange	=	function handle_response(){
	 if(http.readyState==4){
		var txt	=	http.responseText;
	    if(txt!=""){
			document.getElementById('div_state'+x).innerHTML	=	txt;
        }
     }
 };
 http.send(null);
}
*/

function automatic_address(id,type){
if(type=='Main'){	
 url	=	'ajax_response.php?act1=loc_address&id='+id;
 htp.open('get',url,false);
 htp.onreadystatechange	=	function handle_loc_address(){
 if(htp.readyState==4){
	var txt	=	htp.responseText;

	 if(txt!=""){
		arr	=	txt.split('~DM~'); 
		document.getElementById('wh_address').value	 =	arr[0];
		document.getElementById('wh_city').value	 =	arr[1];
		document.getElementById('u_state').value	 =	arr[2];
		document.getElementById('wh_country').value	 =	arr[3];
		document.getElementById('wh_zipcode').value	 =	arr[4];
		if(arr[5]!=""){
			document.getElementById('wh_loc_name').value =	arr[5];
		}else{
			document.getElementById('wh_loc_name').value =	arr[0]+'-'+arr[1];
		}
		if(arr[3]!=""){
			send_request(document.getElementById('wh_country').value,1,arr[2]);
		}else{
			send_request(220,1,arr[2]);
		}
     }
  }
 };
 htp.send(null);
 }else{
      	document.getElementById('wh_address').value	 =	'';
		document.getElementById('wh_city').value	 =	'';
		document.getElementById('u_state').value	 =	'';
		document.getElementById('wh_country').value	 =	220;
		document.getElementById('wh_zipcode').value	 =	'';
		document.getElementById('wh_loc_name').value =	'';
 }
}


function automatic_address1(id,type){
if(type=='Main'){	
 url	=	'ajax_response.php?act1=loc_address&id='+id;
 htp.open('get',url,false);
 htp.onreadystatechange	=	function handle_loc_address(){
 if(htp.readyState==4){
	var txt	=	htp.responseText;

	 if(txt!=""){
		arr	=	txt.split('~DM~'); 
		document.getElementById('wh_address').value	 =	arr[0];
		document.getElementById('wh_city').value	 =	arr[1];
		document.getElementById('u_state').value	 =	arr[2];
		document.getElementById('wh_country').value	 =	arr[3];
		document.getElementById('wh_zipcode').value	 =	arr[4];
		if(arr[5]!=""){
			document.getElementById('wh_loc_name').value =	arr[5];
		}else{
			document.getElementById('wh_loc_name').value =	arr[0]+'-'+arr[1];
		}
		if(arr[3]!=""){
			send_request(document.getElementById('wh_country').value,1,arr[2]);
		}else{
			send_request(220,1,arr[2]);
		}
     }
  }
 };
 htp.send(null);
 }
}