// JavaScript Document

//var request_o = new ActiveXObject("Microsoft.XMLHTTP");

//var request_o = new XMLHttpRequest();

/* 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
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/



/* The variable http will hold our new XMLHttpRequest object. */
var request = createRequestObject(); 

/* Function called to get the product categories list */
function getGreetings(){
	/* 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. 
	*/
	
	
	request.open('get', 'greeting.php?action=get_products&color=' 
			+ document.pricelist.color.value + '&flatsize=' 
			+ document.pricelist.flatSizes.value + '&paperchoice=' 
			+ document.pricelist.paperChoices.value + '&prooftype=' 
			+ document.pricelist.proofType.value + '&turnaround=' 
			+ document.pricelist.turnaround.value + '&fold=' 
			+ document.pricelist.fold.value + '&quantity=' 
			+ document.pricelist.quantity.value);
	/*http.open('get', 'product_info.php?action=get_products&id=' 
			+ document.form_category_select.select_category_select.selectedIndex);*/
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	request.onreadystatechange = handleGreetings; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	request.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleGreetings(){
	/* 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(request.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 = request.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. */
		var response_stack = response.split('|');
		document.getElementById('product_cage').innerHTML = response_stack[0];
		document.getElementById('price').value = response_stack[1];
		/*document.getElementById('product_cage').innerHTML = response;
		document.getElementById('price').value = response;*/
	}
}


/* Function called to get the product categories list */
function getBusinesscard(){
	/* 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('ffgfg');
		
	var paperChoices=document.pricelist.paperChoices.value;
	var quantity=document.pricelist.quantity.value;	
	var color=document.pricelist.color.value;
	
	request.open('get', 'business_card_calc.php?color='+color+'&paperChoices='+paperChoices+'&quantity='+quantity);
	//var url='business_card_calc.php?color='+color+'&paperChoices='+paperChoices+'&quantity='+quantity;
	//alert(url);
	/*http.open('get', 'product_info.php?action=get_products&id=' 
			+ document.form_category_select.select_category_select.selectedIndex);*/
	/*http.open('get', 'product_info.php?action=get_products&id=' 
			+ document.form_category_select.select_category_select.selectedIndex);*/
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	request.onreadystatechange = handleBusinesscard; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	request.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleBusinesscard(){
	/* 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(request.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 = request.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. */
		var response_stack = response.split('|');
		document.getElementById('product_cage').innerHTML = response_stack[0];
		document.getElementById('price').value = response_stack[1];
		/*document.getElementById('product_cage').innerHTML = response;
		document.getElementById('price').value = response;*/

	}
}

/* Function called to get the product categories list */
function getFilers(){
	/* 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('ffgfg');
	request.open('get', 'filers.php?action=get_products&color=' 
			+ document.pricelist.color.value + '&flatsize=' 
			+ document.pricelist.flatSizes.value + '&paperchoice=' 
			+ document.pricelist.paperChoices.value + '&prooftype=' 
			+ document.pricelist.proofType.value + '&turnaround=' 
			+ document.pricelist.turnaround.value + '&quantity=' 
			+ document.pricelist.quantity.value);
	/*http.open('get', 'product_info.php?action=get_products&id=' 
			+ document.form_category_select.select_category_select.selectedIndex);*/
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	request.onreadystatechange = handleFilers; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	request.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleFilers(){
	/* 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(request.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 = request.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. */
		var response_stack = response.split('|');
		document.getElementById('product_cage').innerHTML = response_stack[0];
		document.getElementById('price').value = response_stack[1];
		/*document.getElementById('product_cage').innerHTML = response;
		document.getElementById('price').value = response;*/

	}
}

function getPostcard(){
	/* 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. 
	*/
	
	request.open('get', 'postcrd.php?action=get_products&color=' 
			+ document.pricelist.color.value + '&flatsize=' 
			+ document.pricelist.flatSizes.value + '&paperchoice=' 
			+ document.pricelist.paperChoices.value + '&prooftype=' 
			+ document.pricelist.proofType.value + '&turnaround=' 
			+ document.pricelist.turnaround.value + '&quantity=' 
			+ document.pricelist.quantity.value);
	/*http.open('get', 'product_info.php?action=get_products&id=' 
			+ document.form_category_select.select_category_select.selectedIndex);*/
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	request.onreadystatechange = handlePostcard; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	request.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handlePostcard(){
	/* 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(request.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 = request.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. */
		var response_stack = response.split('|');
		document.getElementById('product_cage').innerHTML = response_stack[0];
		document.getElementById('price').value = response_stack[1];
		/*document.getElementById('product_cage').innerHTML = response;
		document.getElementById('price').value = response;*/
	}
}


function getBrouchers(){
	/* 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('ffgfg');
	request.open('get', 'brouchers.php?action=get_products&color=' 
			+ document.pricelist.color.value + '&flatsize=' 
			+ document.pricelist.flatSizes.value + '&paperchoice=' 
			+ document.pricelist.paperChoices.value + '&prooftype=' 
			+ document.pricelist.proofType.value + '&turnaround=' 
			+ document.pricelist.turnaround.value + '&fold=' 
			+ document.pricelist.fold.value + '&quantity=' 
			+ document.pricelist.quantity.value);
	/*http.open('get', 'product_info.php?action=get_products&id=' 
			+ document.form_category_select.select_category_select.selectedIndex);*/
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	request.onreadystatechange = handleBrouchers; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	request.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleBrouchers(){
	/* 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(request.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 = request.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. */
			var response_stack = response.split('|');
		document.getElementById('product_cage').innerHTML = response_stack[0];
		document.getElementById('price').value = response_stack[1];
		/*document.getElementById('product_cage').innerHTML = response;
		document.getElementById('price').value = response;*/
		
	}
}

function getCalendars(){
	/* 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('ffgfg');
	request.open('get', 'calen.php');
	//alert('calen.php?action=get_products&flatsize=' 
			//+ document.pricelist.flatSizes.value + '&quantity=' 
			//+ document.pricelist.quantity.value);
	request.open('get', 'calen.php?action=get_products&flatsize=' 
			+ document.pricelist.flatSizes.value + '&quantity=' 
			+ document.pricelist.quantity.value);
	/*http.open('get', 'product_info.php?action=get_products&id=' 
			+ document.form_category_select.select_category_select.selectedIndex);*/
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	request.onreadystatechange = handleCalen; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	request.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleCalen(){
	/* 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(request.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 = request.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. */
		var response_stack = response.split('|');
		document.getElementById('product_cage').innerHTML = response_stack[0];
		document.getElementById('price').value = response_stack[1];
		/*document.getElementById('product_cage').innerHTML = response;
		document.getElementById('price').value = response;*/

	}
}

function getLG(){
	/* 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('ffgfg');
	
	
	request.open('get', 'lg.php?action=get_products&paperchoice=' 
			+ document.pricelist.paperChoices.value + '&height=' 
			+ document.pricelist.height.value + '&width=' 
			+ document.pricelist.width.value);
	
	/*http.open('get', 'product_info.php?action=get_products&id=' 
			+ document.form_category_select.select_category_select.selectedIndex);*/
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	request.onreadystatechange = handleLG; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	request.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleLG(){
	/* 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(request.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 = request.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. */
		var response_stack = response.split('|');
		document.getElementById('product_cage').innerHTML = response_stack[0];
		document.getElementById('price').value = response_stack[1];
		/*document.getElementById('product_cage').innerHTML = response;
		document.getElementById('price').value = response;*/

	}
}



/*function check_price(quantity) {		

	var url ="product_info.php?testprice=100";			
	http.open("GET", url, true);
alert(url);
	http.send(null);


}*/