if(navigator.appName == "Microsoft Internet Explorer") {
  	inline_http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
 	inline_http = new XMLHttpRequest();
}


function update_quote() { 


	// need to create the quote value object

	var myform = document.getElementById("quote_panel_form");

	var product_name = document.getElementById("product_name");	
	var paper_size = document.getElementById("paper_size");
	var num_pages = document.getElementById("num_pages");
	
	var paper_type = document.getElementById("paper_type");
	var paper_type_cover = document.getElementById("paper_type_cover");
	var paper_type_inner = document.getElementById("paper_type_inner");

	var colours_cover = document.forms.quote_panel_form.colours_cover;
	var colours_inner = document.forms.quote_panel_form.colours_inner;
	
	var numsides = document.getElementById("numsides");
	var colours_front = document.forms.quote_panel_form.colours_front;
	var colours_back = document.forms.quote_panel_form.colours_back;
	
	var querystring = "";
	
	if (product_name) { querystring = querystring + "&product_name=" + product_name.value; }
	if (paper_size) { querystring = querystring + "&paper_size=" + get_dropdown_value(paper_size); }
	if (num_pages) { querystring = querystring + "&num_pages=" + num_pages.value; }
	
	if (paper_type) { querystring = querystring + "&paper_type=" + get_dropdown_value(paper_type); }
	if (paper_type_cover) { querystring = querystring + "&paper_type_cover=" + get_dropdown_value(paper_type_cover); }
	if (paper_type_inner) { querystring = querystring + "&paper_type_inner=" + get_dropdown_value(paper_type_inner); }
	
	if (colours_cover) { querystring = querystring + "&colours_cover=" + get_radio_value(myform.colours_cover); }
	if (colours_inner) { querystring = querystring + "&colours_inner=" + get_radio_value(myform.colours_inner); }
	
	if (colours_front) { querystring = querystring + "&colours_front=" + get_radio_value(myform.colours_front); }
	if (colours_back) { querystring = querystring + "&colours_back=" + get_radio_value(myform.colours_back); }
	
	if (numsides) { querystring = querystring + "&numsides=" + get_radio_value(myform.numsides); }
	
	
	var target_matrix = document.getElementById("pricing_matrix");
	
	if (target_matrix) { 
		target_matrix.innerHTML = "<img src=\"images/bigrotation2.gif\" width=32 height=32 alt=\"Loading\" style=\"position: relative; left: 90px; top: 100px;\"><br>";
	
		//busyicon.style.display = "block";
		inline_http.abort();
		inline_http.open("GET","index.php?page=quote_panel" + querystring, true);
		inline_http.onreadystatechange=function() {

			if(inline_http.readyState == 4) {

				// run whatever is returned as javascript

				var target_matrix = document.getElementById("pricing_matrix");

				if (!target_matrix) { 
					alert("Could not locate pricing matrix");
				} else { 
					target_matrix.innerHTML = inline_http.responseText;
				}

				//busyicon.style.display = "none";

			}
		}

		inline_http.send(null);
		
	}
	
}

function change_paper() {

	var paper_dropdown = document.getElementById("paper_dropdown");
	var selected_value = paper_dropdown.options[paper_dropdown.selectedIndex].value;
	
	var myform = document.getElementById("quote_panel_form");
	myform.callback_paper.value = selected_value;
	update_quote();

}

function update_sides() { 

	var myform = document.getElementById("quote_panel_form");

	var selected_value = get_radio_value(myform.numsides);
	
	myform.callback_sides.value = selected_value;
	
	if (selected_value == 1) { 
		document.getElementById("div_colours_back").style.display = "none";
	} else { 
		document.getElementById("div_colours_back").style.display = "block";
	}
	
	update_quote();

}

function update_colours(from_item) { 
	
	var myform = document.getElementById("quote_panel_form");

	if (from_item == "side_1") { 
		var selected_value = get_radio_value(myform.side_1);
		myform.callback_col1.value = selected_value;
	} else { 
		var selected_value = get_radio_value(myform.side_2);
		myform.callback_col2.value = selected_value;
	}
	
	update_quote();

}

function get_radio_value(controls) { 

	for (i=0;i<controls.length;i++) {
		if (controls[i].checked) {
			return controls[i].value;
		}
	}

	return false;

}

function get_dropdown_value(controls) { 
	return controls.options[controls.selectedIndex].value;
}

