/* 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 called to get the city list */
function get_v_total(disc_total,v_code){
	/* 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_zone.php?mode=leo_disc&disc_total='+disc_total+'&v_code='+v_code);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleRange_Series; 
	/* 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 handleRange_Series(){
	/* 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;
		
		final_arr=response.split("@");
		
		var range_response=final_arr[0];
		var series_response=final_arr[1];
	//	alert(series_response);
		/* 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('div_not_valid').innerHTML = range_response;
		document.getElementById('v_valid_code').innerHTML = series_response;
		//document.getElementById('div_Series').innerHTML = series_response;
		
	}
}
/* Function called to get the city list */
function getColorData(div_counter,product_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. 
	*/
	//var div_counter=session_counter+1;
	/*alert(session_counter);
	alert(user_id);*/
	http.open('get', 'intermediate_zone.php?mode=add_color&div_counter='+div_counter+'&product_id='+product_id);
	
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleColorData; 
	/* 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 handleColorData(){
	/* 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;
	//	alert(response);
		
		var array_value=response.split("@");
	//	alert(array_value[0]);
		//alert(array_value[1]);
		/* 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(array_value[1]);
		document.getElementById('c_'+array_value[0]).innerHTML = array_value[1];
	}
}
/* Function called to get the city list */
function getpopup_catselect(category_id,chng_flag){
	/* 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(zone_name);
//	alert(chng_flag);
	/*if(chng_flag==1)
	{
		http.open('get', 'intermediate_zone.php?mode=pop_zone_district&zone_name='+zone_name+'&chng_flag='+chng_flag);
	}
	else if(chng_flag==0)
	{
		http.open('get', 'intermediate_zone.php?mode=pop_zone&zone_name='+zone_name+'&chng_flag='+chng_flag);
	}*/
	http.open('get', 'intermediate_zone.php?mode=pop_cat&category_id='+category_id+'&chng_flag='+chng_flag);
	
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleCategory; 
	/* 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 handleCategory(){
	/* 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. */	
			//alert(response);
		document.getElementById('divCatpop').innerHTML = response;
	}
}
/* Function called to get the city list */
function getRange_after_close(category_id,x_id,right_link_flag){
	/* 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(zone_name);
//	alert(chng_flag);
	/*if(chng_flag==1)
	{
		http.open('get', 'intermediate_zone.php?mode=pop_zone_district&zone_name='+zone_name+'&chng_flag='+chng_flag);
	}
	else if(chng_flag==0)
	{
		http.open('get', 'intermediate_zone.php?mode=pop_zone&zone_name='+zone_name+'&chng_flag='+chng_flag);
	}*/
	http.open('get', 'intermediate_zone.php?mode=Only_Range&category_id='+category_id+'&x_id='+x_id+'&right_link_flag='+right_link_flag);
	
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleOnlyRange; 
	/* 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 handleOnlyRange(){
	/* 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. */	
			//alert(response);
		document.getElementById('div_Range').innerHTML = response;
	}
}
/* Function called to get the city list */
function getSeries_after_close(category_id,x_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. 
	*/
	//alert(zone_name);
//	alert(chng_flag);
	/*if(chng_flag==1)
	{
		http.open('get', 'intermediate_zone.php?mode=pop_zone_district&zone_name='+zone_name+'&chng_flag='+chng_flag);
	}
	else if(chng_flag==0)
	{
		http.open('get', 'intermediate_zone.php?mode=pop_zone&zone_name='+zone_name+'&chng_flag='+chng_flag);
	}*/
	http.open('get', 'intermediate_zone.php?mode=Only_Series&category_id='+category_id+'&x_id='+x_id);
	
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleOnlySeries; 
	/* 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 handleOnlySeries(){
	/* 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. */	
			//alert(response);
		document.getElementById('div_Series').innerHTML = response;
	}
}
/* Function called to get the city list */
function getProduct_frmRange(range_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. 
	*/
	//alert(zone_name);
//	alert(chng_flag);
	/*if(chng_flag==1)
	{
		http.open('get', 'intermediate_zone.php?mode=pop_zone_district&zone_name='+zone_name+'&chng_flag='+chng_flag);
	}
	else if(chng_flag==0)
	{
		http.open('get', 'intermediate_zone.php?mode=pop_zone&zone_name='+zone_name+'&chng_flag='+chng_flag);
	}*/
	http.open('get', 'intermediate_zone.php?mode=Product_frmRange&range_id='+range_id);
	
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleRange_Products; 
	/* 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 handleRange_Products(){
	/* 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. */	
			//alert(response);
			arr=response.split("@");
			
		document.getElementById('div_OrdProduct').innerHTML = arr[0];
		document.getElementById('div_OrdProduct1').innerHTML = arr[1];
		
	}
}
function setHomePage_News(news_id,flag){
	/* 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_zone.php?mode=Home_Page&news_id='+news_id+'&flag='+flag);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleHomePage; 
	/* 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 handleHomePage(){
	/* 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;
		//alert(response);
		/* 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('Home_Page_Message').innerHTML = response;
		window.setInterval("reFresh()",2000);

	}
}
function reFresh() {
  location.reload(true)
}