var url = "honeycomb_get_quote_ajax.php";

var size_url = "honeycomb_get_size_ajax.php";



var min_width = 6;

var min_length = 6;

var max_width = 120;

var max_length = 144;



function getSize()

{

	loadXMLDoc(size_url, setSize, false);

}

function setSize() 

{

	var size = resultXML;

	size = size.split("|");



	min_width = size[0];

	min_length = size[2];

	max_width = size[1];

	max_length = size[3];

}

function getQuote()

{

	var wid = document.myForm.blind_width.value

	var len = document.myForm.blind_length.value

	

	if(wid == max_width)

	{

		document.myForm.blind_width_fraction.value = "0.000";

	}

	if(len == max_length)

	{

		document.myForm.blind_length_fraction.value = "0.000";

	}

	if(wid != "" && len != "")

	{

		wid = parseInt(wid);

		if(wid < min_width || wid > max_width || isNaN(wid))

		{

			alert("Please enter the correct Blind Width.");

			document.myForm.blind_width.focus();

			return false;

		}

		wid = wid + parseFloat(document.myForm.blind_width_fraction.value);

		len = parseInt(len);

		if(len < min_length || len > max_length || isNaN(len))

		{

			alert("Please enter the correct Blind Length.");

			document.myForm.blind_length.focus();

			return false;

		}

		len = len + parseFloat(document.myForm.blind_length_fraction.value);

		var get_url = url + "?width=" + wid + "&length=" + len;

		loadXMLDoc(get_url, setQuote, false);

	}

}

function setQuote() 

{

	var quote = resultXML;

	quote = quote.split("|");

	


	document.getElementById("essence").innerHTML = quote[0];

	document.getElementById("tranquility").innerHTML = quote[1];

	document.getElementById("harmony").innerHTML = quote[2];

	document.getElementById("eclipse").innerHTML = quote[3];

	document.getElementById("expresscordless").innerHTML = quote[4];

}

function loadXMLDoc(url, callFunc, ignoreWhite) 

{

	functionToCall = callFunc;

	stripWS = ignoreWhite;

	xmlRequestObj = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")

	xmlRequestObj.onreadystatechange = proccessXML;

	xmlRequestObj.open("GET", url, true);

	xmlRequestObj.send(null);

}

function is_ws(nod) 

{

	return !(/[^\t\n\r ]/.test(nod.data));

}

function findWhiteSpace(node, nodeNo) 

{

	for (i=0; i<node.childNodes.length; i++) 

	{

		if (node.childNodes[i].nodeType == 3 && is_ws(node.childNodes[i])) 

		{

			nodesToDelete[nodesToDelete.length] = node.childNodes[i]

		}

		if (node.childNodes[i].hasChildNodes()) 

		{

			findWhiteSpace(node.childNodes[i], i);

		}

	}

	node = node.parentNode;

	i = nodeNo;

}

function stripWhiteSpace(node)

{

	nodesToDelete = Array();

	findWhiteSpace(node, 0);

	for(i=nodesToDelete.length-1;i>=0;i--) 

	{

		nodeRef = nodesToDelete[i];

		nodeRef.parentNode.removeChild(nodeRef)

	}

}

function proccessXML() 

{

	if (xmlRequestObj.readyState == 4 && (xmlRequestObj.status == 200 || xmlRequestObj.status == 304)) 

	{

		if(stripWS) 

		{

			stripWhiteSpace(xmlRequestObj.responseText);

		}

		resultXML = xmlRequestObj.responseText;

		functionToCall()

	}

}