/* The following function creates an XMLHttpRequest object... */

var elementId="";
var loadingMesg="";
function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

var http = createRequestObject();

function getRequest(url,id,msg){
	
	//alert("Inside Getrequest()");
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	elementId=id;
	loadingMesg=msg;
	http.open('get', url);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = ManipulateRequest; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function postRequest(url,id,msg){
		//alert("Inside Postrequest()");
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	elementId=id;
	loadingMesg=msg;
	http.open('get', url);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = ManipulateRequest; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}


function ManipulateRequest(){
		//alert("Inside ManipulateRequest()");
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */

	//if(loadingMesg=="") var msg="<span class='bld'><br>Please wait...loading</span><br> <img src='images/squares.gif'>";
	if(loadingMesg==""){
		//var msg="<div align=center><style type='text/css'>.head1 {font-family:Verdana, Arial, Helvetica, sans-serif;font-size:16px;font-weight:bold;color:#2F8996;}.head2 {font-family:Verdana, Arial, Helvetica, sans-serif;font-size:15px;font-weight:bold;color:#2F8996;}</style><table width=437  border=0 cellpadding=0 cellspacing=1 style='border:2px solid #cccccc; '><tr><td height=30 align=center bgcolor='#FFFFFF' class=head1>Great Hawaii Vacations is searching...</td></tr><tr><td height=30 align=center bgcolor='#FFFFFF' class=head1>We Know Hawaii Best... Hawaii is all we do!</td></tr><tr><td align=center bgcolor='#FFFFFF'><img src='images/squares.gif' width=101 height=19></td></tr><tr><td height=30 align=center bgcolor='#FFFFFF' class=head1>Need any help? Call our travel experts</td></tr><tr><td align=center bgcolor='#FFFFFF' style='padding-right:10px;'><img src='images/lady_search.gif' width=111 height=105></td></tr><tr><td align=center bgcolor='#FFFFFF' class=head1>1-800-688-2254 </td></tr></table><br>";
		var msg = "<table width='671' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF' align='center'><tr><td width='166' align='center'><table width='89%'  border='0' cellspacing='0' cellpadding='2' style='border:1px solid #2f8996;'><tr><td align=center><img src='http://hawaiitrips.com/images/ad_search.gif'></td></tr><tr><td  style=' font-family:Verdana; color:#2f8996; font-size:12px;'>&#12488;&#12521;&#12505;&#12523;&#12467;&#12531;&#12469;&#12523;&#12479;&#12531;&#12488;&#12395;&#12418;&#12362;&#21839;&#12356;&#21512;&#12431;&#12379;&#38914;&#12369;&#12414;&#12377;&#12290;<br>&#26085;&#26412;&#12363;&#12425;<br>050-5809-8408<br>&<br>&#20182;&#12398;&#22320;&#22495;&#12363;&#12425;<br>1-818-584-1345</td></tr></table></td><td width='505' valign='top'><table width='100%'  border='0' cellspacing='2' cellpadding='2'><tr><td><p style='font-family:Verdana; font-weight:bold; color:#2f8996; font-size:15px;'>&#12464;&#12524;&#12540;&#12488;&#12495;&#12527;&#12452;&#12496;&#12465;&#12540;&#12471;&#12519;&#12531;&#12474;&#12399;&#12289; <br> &#12450;&#12489;&#12496;&#12531;&#12473;&#12469;&#12540;&#12481;&#12434;&#34892;&#12387;&#12390;&#12362;&#12426;&#12414;&#12377;</p></td></tr><tr><td><img src='http://hawaiitrips.com/images/squares.gif' width='101' height='19'><p style='font-family:Verdana; font-weight:bold; color:#2f8996; font-size:15px;'>&#20170;&#12375;&#12400;&#12425;&#12367;&#12362;&#24453;&#12385;&#12367;&#12384;&#12373;&#12356;</p></td></tr><tr><td><!--<p  style='font-family:Verdana; font-weight:bold; color:#2f8996; font-size:15px;'>your Patience will be rewarded!</p>--></td></tr></table></td></tr></table>";
	}
	else{
			msg=loadingMesg;
	}
	if(http.readyState == 1)
	{
		//alert('case2');
		document.getElementById(elementId).innerHTML=msg;
	}
	else if(http.readyState == 4)
	{ 	//Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
			//alert('case3');
		var response = http.responseText;
		
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
			//alert(response);
		document.getElementById(elementId).innerHTML = response;
	}
}
