/* The following function creates an XMLHttpRequest object... */

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
}

/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 
function chkuser(user)
{
	
	/* 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. 
	*/
	http.open('get', 'intermediate.php?user='+user);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handlechkuser; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
/* Function called to handle the list that was returned from the internal_request.php file.. */
function handlechkuser(){
	/* 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(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. */
		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. */
		
		document.getElementById('divuser').innerHTML = response;
		
		

	}
}




function chkuser1(email1)
{
	
	/* 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. 
	*/
	http.open('get', 'intermediate1.php?user='+email1);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handlechkuser1; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
/* Function called to handle the list that was returned from the internal_request.php file.. */
function handlechkuser1(){
	/* 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(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. */
		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. */
		
		document.getElementById('divemail').innerHTML = response;
		
		

	}
}


















/* Function called to get the province list */
function getprovince(country_id){
	/* 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. 
	*/
	http.open('get', 'intermediate.php?mode=province&country_id='+country_id);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleProvince; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleProvince(){
	/* 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(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. */
		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. */
		
		document.getElementById('divprovince').innerHTML = response;
		
		

	}
}
/* Function called to get the city list */
function getcook(total){
	/* 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. 
	*/
//alert(total);
	
	http.open('get', 'intermediate.php?id='+total);
	
	
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handlecookies; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}




/* Function called to handle the list that was returned from the internal_request.php file.. */
function handlecookies(){
	/* 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(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. */
		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. */
		
		document.getElementById('details').innerHTML = response;
		
		
	}
}
/* Function called to get the area list */
function getarea(city_id){
	/* 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. 
	*/
	http.open('get', 'intermediate.php?mode=area&city_id='+city_id);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleAreas; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleAreas(){
	/* 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(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. */
		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. */
		
		document.getElementById('divarea').innerHTML = response;
	

	}
}

function cookies_val(number,qty)
{
var cook=qty;
var num=number;
http.open('get', 'intermediate_cook.php?cook='+cook+'&num='+num);
http.onreadystatechange = handlecookies; 
http.send(null);
}

function handlecookies(){
	/* 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(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. */
		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. */
		res=response.split("||");
		
		
		var t=parseInt(res[1]);
		document.getElementById('divid'+t).innerHTML=res[0];
		//document.getElementById('divid1').innerHTML=document.getElementById('divid1').innerHTML+"<br>"+res[0];
		/*var t=res[1];
				eval("document.getElementById('divid"+t+"').innerHTML")=res[0];*/
		
		//document.getElementById('number').value=res[1];

	}
}


function cookies_image(id,nm)
{
http.open('get', 'intermediate_image.php?id='+id+'&nm='+nm);
http.onreadystatechange = handlecookies_image; 
http.send(null);
}


function handlecookies_image(){
	/* 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(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. */
		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. */
		
		
		res=response.split("#");
		var t=parseInt(res[1]);
		document.getElementById('cimg_'+t).innerHTML=res[0];
		
		
		

	}
}
