// Error checking routines for price calculator

function valid1(){
	var cheight=document.pricer.pheight.value;
	var cwidth=document.pricer.pwidth.value;

	if(cwidth == "")
	{
		alert("Sorry, but you need to enter a width !");
		document.pricer.pwidth.value="";
		document.pricer.pwidth.focus();
		return false;
	}

	if(isBlank(cwidth))
	{
		alert("Sorry, but you need to enter a width !");
		document.pricer.pwidth.value="";
		document.pricer.pwidth.focus();
		return false;
	}

	if(isNaN(cwidth))
	{
		alert("Please enter the measurement as a number only !");
		document.pricer.pwidth.value="";
		document.pricer.pwidth.focus();
		return false;
	}

	if(parseFloat(cwidth)< 60)
	{
		alert("The width you have entered is below our minimum size (60 cm), please re-enter a larger width !");
		document.pricer.pwidth.value="0";
		document.pricer.pwidth.focus();
		return false;
	}
	if(parseFloat(cwidth)> 200)
	{
		alert("The width you have entered is wider than our largest size (200 cm) \nwhy not give me a call, and we can discuss your requirements?\n\nTricia Tucker at Soft Furnishing Design. Telephone: 020 8398 9646");
		document.pricer.pwidth.value="0";
		document.pricer.pwidth.focus();
		return false;
	}

	if(cheight == "")
	{
		alert("You need to enter a drop measurement");
		document.pricer.pheight.value="";
		document.pricer.pheight.focus();
		return false;
	}

	if(isBlank(cheight))
	{
		alert("You need to enter a drop measurement");
		document.pricer.pheight.value="";
		document.pricer.pheight.focus();
		return false;
	}

	if(isNaN(cheight))
	{
		alert("Please enter a number for the drop measurement");
		document.pricer.pheight.value="";
		document.pricer.pheight.focus();
		return false;
	}

	if(parseFloat(cheight)< 75)
	{
		alert("The measurement you have entered is below our minimum drop (75 cm), please re-enter a larger size !");
		document.pricer.pheight.value="0";
		document.pricer.pheight.focus();
		return false;
	}
/*
	if(navigator.appName !="Netscape")
	{
		var pattern ="//PRICE[@width <="+ Math.round(((parseFloat(document.pricer.pwidth.value))))+"]";
		var recnode=doc.selectNodes(pattern);
		var max=0;
		max=recnode[recnode.length-1].getAttribute("height");
		if(parseFloat(cheight)>max)
		{
			alert("The measurement you have entered is bigger than the maximum drop for this width i.e " + max);
			document.pricer.pheight.value="0"
			document.pricer.pheight.focus();
			return false;
		}
	}
*/
	return true;
}

function widthvalid1(){

	var cwidth=document.pricer.pwidth.value;

	if(cwidth == "")
	{
		alert("Please enter a width !");
		document.pricer.pwidth.value="";
		document.pricer.pwidth.focus();
		return false;
	}

	if(isBlank(cwidth))
	{
		alert("Width can not be left blank !");
		document.pricer.pwidth.value="";
		document.pricer.pwidth.focus();
		return false;
	}

	if(isNaN(cwidth))
	{
		alert("Please enter the measurement as a number only !");
		document.pricer.pwidth.value="";
		document.pricer.pwidth.focus();
		return false;
	}

	if(parseFloat(cwidth)< 60)
	{
		alert("The width you have entered is below our minimum size (60 cm), please re-enter a larger width !");
		document.pricer.pwidth.value="0";
		document.pricer.pwidth.focus();
		return false;
	}
	if(parseFloat(cwidth)> 200)
	{
		alert("The width you have entered is wider than our largest size (200 cm) \nwhy not give me a call, and we can discuss your requirements?\n\nTricia Tucker at Soft Furnishing Design. Telephone: 020 8398 9646");
		document.pricer.pwidth.value="0";
		document.pricer.pwidth.focus();
		return false;
	}

	return true;
}

var path="productprice.xml";
var doc1;
if(document.implementation && document.implementation.createDocument)
{
	var doc1 = document.implementation.createDocument("", "", null);
	doc1.load(path);
}else if(window.ActiveXObject)
{
	var doc1 = new ActiveXObject("Microsoft.XMLDOM");
	doc1.load(path);
}

function calculateprice(){
	if(valid1()==true){
		var i=0;
		var intLen=0;
		var flg=false;
		if(doc1)
		{
			var patt ="PRICE";
			var objAtt;
			var recobj=doc1.getElementsByTagName(patt);
			intLen=	recobj.length;
			for(i=0;i<intLen;i++)
			{
				objAtt=recobj[i].attributes;
				if(parseInt(objAtt[0].nodeValue)>=(parseInt(document.pricer.pheight.value,10)) && parseInt(objAtt[1].nodeValue)>=(parseInt(document.pricer.pwidth.value,10)))
				{
					if(flg==false)
					{
						document.pricer.price.value=recobj[i].childNodes[0].nodeValue;
						flg=true;
					}
				}
			}
		}else{
			intLen=	pPrice.length;
			for(i=0;i<intLen;i++)
			{
				if(parseInt(pHeight[i])>=(parseInt(document.pricer.pheight.value,10)) && parseInt(pWidth[i])>=(parseInt(document.pricer.pwidth.value,10)))
				{
					if(flg==false)
					{
						document.pricer.price.value=pPrice[i];
						flg=true;
					}
				}
			}
		}
		if(flg==false)
		{
			alert("Sorry, our blinds are not available in this size");
		}
	}
}
