var width;
var drop;
var wood;

var counter=0;
var beginRow = 0;
var rate = 0;// rate for per m2

function getQuote() 
{
width=document.GetQuote.width.value;
drop=document.GetQuote.drop.value;
wood=document.GetQuote.wood.value;


if (isNaN(width))
	{
		alert('Please enter a Width');
	}
else if (isNaN(drop))
	{
		alert('Please enter a Drop');
	}	

else 
	{

		//10/6/11 add Vertical - Vivid White Vertical - Chalk USA  parts
		
		if ((wood == "vertical_dark") || (wood == "vertical_medium") || (wood == "vertical_light")|| (wood == "vertical_vivid_white")|| (wood == "vertical_chalk_usa"))
		{
			// TODO:  confirm lowest values for width and drop
			if ((width < 300 ) || (width > 3000) || (drop < 200) || (drop > 2250))
			{
						document.GetQuote.price.value = "Non-standard size:  call 1 300 55 66 75";
			}
			else
			{
				// round up width 
				if (width < 600) { width = 600 }
				else if ((width%100) > 0)
					{ 
						width = 100 - +(width%100) + +width; 
					}
				// round up drop
				if (drop > 1500) { drop = 2250; }
				else if (drop >= 200) { drop = 1500; }
					
					document.GetQuote.price.value = "document:"+wood;
					loadXMLData("vertical_89x4.xml");
			}
		}
		// 12/05/2011 change pricing method for basswod 50mm * 3mm
		else if(wood == "basswood")//for basswood 50mm*3mm
		{
			//confirm lowest values for width and drop
			//make changing 12/05/2011
			//24/05/11change drop < 600 to 620
			//7/06/11 change drop range to from 100<= drop <= 3000
			if ((width < 300 ) || (width > 2410) || (drop < 100) || (drop > 3000))
			{
						document.GetQuote.price.value = "Non-standard size:  call 1 300 55 66 75";
			}
			else
			{	
				// round up width 
				if (width > 2310) { width = 2410;}
				else if (width < 310) {width = 310;}
				else if (((width - 10)%100) > 0)
				{ 
					width = 100 - +((width - 10)%100) + +width; 
				}
		
		
				// round up drop
				//change drop area from < x00 to x20
				if (drop > 2920) { drop = 3000; }
				else if (drop < 620) { drop = 620}
				else if (drop > 2820) { drop = 2920; }
				else if (drop > 2720) { drop = 2820; }
				else if (drop > 2620) { drop = 2720; }
				else if (drop > 2520) { drop = 2620; }
				else if (drop > 2420) { drop = 2520; }
				else if (drop > 2320) { drop = 2420; }
				else if (drop > 2220) { drop = 2320; }
				else if (drop > 2120) { drop = 2220; }
				else if (drop > 2020) { drop = 2120; }
				else if (drop > 1920) { drop = 2020; }
				else if (drop > 1820) { drop = 1920; }
				else if (drop > 1720) { drop = 1820; }
				else if (drop > 1620) { drop = 1720; }
				else if (drop > 1520) { drop = 1620; }
				else if (drop > 1420) { drop = 1520; }
				else if (drop > 1320) { drop = 1420; }
				else if (drop > 1220) { drop = 1320; }
				else if (drop > 1120) { drop = 1220; }
				else if (drop > 1020) { drop = 1120; }
				else if (drop > 920) { drop = 1020; }
				else if (drop > 820) { drop = 920; }
				else if (drop > 720) { drop = 820; }
				else if (drop > 620) { drop = 720; }
		
				
				loadXMLData("basswood.xml");
		
		 
		
					
			}
		}// 16/05/2011 change pricing method for basswod 60mm * 3mm
		else if(wood == "basswoodwide")//for basswood 60mm*3mm
		//7/06/11 change drop range to from 100<= drop <= 3000
		{
				if ((width < 300 ) || (width > 2410) || (drop < 100) || (drop > 3000))
			{
						document.GetQuote.price.value = "Non-standard size:  call 1 300 55 66 75";
			}
			else
			{	
				// round up width 
				if (width > 2310) { width = 2410;}
				else if (width < 310) {width = 310;}
				else if (((width - 10)%100) > 0)
				{ 
					width = 100 - +((width - 10)%100) + +width; 
				}
		
		
				// round up drop
				//change drop area from < x00 to x20
				if (drop > 2920) { drop = 3000; }
				else if (drop < 620) { drop = 620}
				else if (drop > 2820) { drop = 2920; }
				else if (drop > 2720) { drop = 2820; }
				else if (drop > 2620) { drop = 2720; }
				else if (drop > 2520) { drop = 2620; }
				else if (drop > 2420) { drop = 2520; }
				else if (drop > 2320) { drop = 2420; }
				else if (drop > 2220) { drop = 2320; }
				else if (drop > 2120) { drop = 2220; }
				else if (drop > 2020) { drop = 2120; }
				else if (drop > 1920) { drop = 2020; }
				else if (drop > 1820) { drop = 1920; }
				else if (drop > 1720) { drop = 1820; }
				else if (drop > 1620) { drop = 1720; }
				else if (drop > 1520) { drop = 1620; }
				else if (drop > 1420) { drop = 1520; }
				else if (drop > 1320) { drop = 1420; }
				else if (drop > 1220) { drop = 1320; }
				else if (drop > 1120) { drop = 1220; }
				else if (drop > 1020) { drop = 1120; }
				else if (drop > 920) { drop = 1020; }
				else if (drop > 820) { drop = 920; }
				else if (drop > 720) { drop = 820; }
				else if (drop > 620) { drop = 720; }
		
				
				loadXMLData("basswoodwide.xml");
		
		
					
			}
		
				
		
		
		
		}
		else  // cedar, rustic, cedar wide
		{
			if ((width < 280 ) || (width > 2410) || (drop < 200) || (drop > 3000))
				{
						document.GetQuote.price.value = "Non-standard size:  call 1 300 55 66 75";
				}
			else {
				// round up width 
				if (width > 2310) { width = 2410;}
				else if (width < 410) {width = 410;}
				else if (((width - 10)%100) > 0)
					{ 
						width = 100 - +((width - 10)%100) + +width; 
					}
		
		
				// round up drop
				if (drop > 2700) { drop = 3000; }
				else if (drop > 2500) { drop = 2700; }
				else if (drop > 2400) { drop = 2500; }
				else if (drop > 2300) { drop = 2400; }
				else if (drop > 2200) { drop = 2300; }
				else if (drop > 2100) { drop = 2200; }
				else if (drop > 2000) { drop = 2100; }
				else if (drop > 1900) { drop = 2000; }
				else if (drop > 1800) { drop = 1900; }
				else if (drop > 1700) { drop = 1800; }
				else if (drop > 1600) { drop = 1700; }
				else if (drop > 1500) { drop = 1600; }
				else if (drop > 1400) { drop = 1500; }
				else if (drop > 1300) { drop = 1400; }
				else if (drop > 1200) { drop = 1300; }
				else if (drop > 1100) { drop = 1200; }
				else if (drop > 1000) { drop = 1100; }
				else if (drop > 900) { drop = 1000; }
				else if (drop > 600) { drop = 900; }
					  else if (drop >= 200) { drop = 600; }
		
		
			if (wood == "cedar")
				{
					loadXMLData("cedar.xml");
				}
			   else if (wood == "cedarwide")
					  {
							 loadXMLData("cedarwide.xml");
					  }
			   else if (wood == "rustic_cedar")
					  {
							 loadXMLData("rustic_cedar.xml");
					  }
			}
		 
		}
				}
}

function loadXMLData(pricesheet)
{
	

  	if( ! CJL_loadXmlDocument(pricesheet, processXMLData) )
   {
	document.GetQuote.price.value = "Non-standard size:  call 1 300 55 66 75";
   }

}


function loadXMLDataForPrice(pricesheet)
{
    CJL_loadXmlDocument(pricesheet, processXMLDataForPrice); 
}

function processXMLData(xmlDoc)
{

var widths = xmlDoc.getElementsByTagName('width');

for (i=0;i<widths.length;i++)
{
	var widthValue = widths[i].getAttribute('value');
	if (width == widthValue) 
	{
		var drops =  widths[i].getElementsByTagName('drop');
		
		for (j=0;j<drops.length;j++)
		{
			var dropValue =  widths[i].getElementsByTagName('drop')[j].getAttribute('value');
			if (drop == dropValue)
			{
				var priceValue = widths[i].getElementsByTagName('drop')[j].getAttribute('price');
			
				document.GetQuote.price.value = priceValue;
				//break;
			}
		}
	}
}
	}

function processXMLDataForPrice(xmlDoc)
{
var widths = xmlDoc.getElementsByTagName('width');

for (i=0;i<widths.length;i++)
{
	var widthValue = widths[i].getAttribute('value');
	if (width == widthValue) 
	{
		
		var drops =  widths[i].getElementsByTagName('drop');
		
		for (j=0;j<drops.length;j++)
		{
			var dropValue =  widths[i].getElementsByTagName('drop')[j].getAttribute('value');
			if (drop == dropValue)
			{
				var priceValue = widths[i].getElementsByTagName('drop')[j].getAttribute('price');
			
				document.order_form.elements[beginRow+4].value = priceValue;
			}
		}
	}
}
//alert ('about to add 4');
//counter = counter + 4;
//alert ('counter now is '+counter);
	}

function getPrice(cellNumber) 
{

beginRow = cellNumber - (cellNumber%6);
	wood=document.order_form.elements[beginRow].value;
	width=document.order_form.elements[beginRow+1].value;
	drop=document.order_form.elements[beginRow+2].value;

	if (wood == "Empty")
		{
			document.order_form.elements[beginRow+4].value = 0;
			return;
		}

	if ((wood != "Empty") && (width > 0) && (drop > 0)) 
	{
		if((wood == "50mm Basswood Light Oak") || (wood == "50mm Basswood Cedar Dark") 
			||(wood == "50mm Basswood Vivid White") || (wood == "50mm Basswood Chalk USA"))
		{
	
			//////////////////////
	// TODO:  confirm lowest values for width and drop
	//7/06/11 change drop range to from 100<= drop <= 3000
			if ((width < 300 ) || (width > 2410) || (drop < 100) || (drop > 3000))
			{
				document.order_form.elements[beginRow+4].value = "CALL";
				document.getElementById('checkout').setAttribute('disabled', 'true');
				document.getElementById('checkout').value='Please Call 1 300 55 66 75';
			}
			else
			{
				if (width > 2310) { width = 2410;}
				else if (width < 310) {width = 310;}
				else if (((width - 10)%100) > 0)
				{ 
					width = 100 - +((width - 10)%100) + +width; 
				}
		
		
				// round up drop
				if (drop > 2920) { drop = 3000; }
				else if (drop < 620) { drop = 620}
				else if (drop > 2820) { drop = 2920; }
				else if (drop > 2720) { drop = 2820; }
				else if (drop > 2620) { drop = 2720; }
				else if (drop > 2520) { drop = 2620; }
				else if (drop > 2420) { drop = 2520; }
				else if (drop > 2320) { drop = 2420; }
				else if (drop > 2220) { drop = 2320; }
				else if (drop > 2120) { drop = 2220; }
				else if (drop > 2020) { drop = 2120; }
				else if (drop > 1920) { drop = 2020; }
				else if (drop > 1820) { drop = 1920; }
				else if (drop > 1720) { drop = 1820; }
				else if (drop > 1620) { drop = 1720; }
				else if (drop > 1520) { drop = 1620; }
				else if (drop > 1420) { drop = 1520; }
				else if (drop > 1320) { drop = 1420; }
				else if (drop > 1220) { drop = 1320; }
				else if (drop > 1120) { drop = 1220; }
				else if (drop > 1020) { drop = 1120; }
				else if (drop > 920) { drop = 1020; }
				else if (drop > 820) { drop = 920; }
				else if (drop > 720) { drop = 820; }
				else if (drop > 620) { drop = 720; }
						
		
				
				loadXMLDataForPrice("basswood.xml");

			}		
			
			////////////////////////
			
		}
		else if((wood == "63mm Basswood Light Oak") || (wood == "63mm Basswood Cedar Dark") ||(wood == "63mm Basswood Vivid White") || (wood == "63mm Basswood Chalk USA"))
		{
			// 160511 changing pricing for basswood 63mm
			
			// TODO:  confirm lowest values for width and drop
			//7/06/11 change drop range to from 100<= drop <= 3000
			if ((width < 300 ) || (width > 2410) || (drop < 100) || (drop > 3000))
			{
				document.order_form.elements[beginRow+4].value = "CALL";
				document.getElementById('checkout').setAttribute('disabled', 'true');
				document.getElementById('checkout').value='Please Call 1 300 55 66 75';
			}
			else
			{
				if (width > 2310) { width = 2410;}
				else if (width < 310) {width = 310;}
				else if (((width - 10)%100) > 0)
				{ 
					width = 100 - +((width - 10)%100) + +width; 
				}
		
		
				// round up drop
				if (drop > 2920) { drop = 3000; }
				else if (drop < 620) { drop = 620}
				else if (drop > 2820) { drop = 2920; }
				else if (drop > 2720) { drop = 2820; }
				else if (drop > 2620) { drop = 2720; }
				else if (drop > 2520) { drop = 2620; }
				else if (drop > 2420) { drop = 2520; }
				else if (drop > 2320) { drop = 2420; }
				else if (drop > 2220) { drop = 2320; }
				else if (drop > 2120) { drop = 2220; }
				else if (drop > 2020) { drop = 2120; }
				else if (drop > 1920) { drop = 2020; }
				else if (drop > 1820) { drop = 1920; }
				else if (drop > 1720) { drop = 1820; }
				else if (drop > 1620) { drop = 1720; }
				else if (drop > 1520) { drop = 1620; }
				else if (drop > 1420) { drop = 1520; }
				else if (drop > 1320) { drop = 1420; }
				else if (drop > 1220) { drop = 1320; }
				else if (drop > 1120) { drop = 1220; }
				else if (drop > 1020) { drop = 1120; }
				else if (drop > 920) { drop = 1020; }
				else if (drop > 820) { drop = 920; }
				else if (drop > 720) { drop = 820; }
				else if (drop > 620) { drop = 720; }
		
				
				loadXMLDataForPrice("basswoodwide.xml");

			}	
			/*
			//confirm lowest values for width and drop
			if ((width < 220 ) || (width > 2410) || (drop < 100) || (drop > 3600))
			{
				document.order_form.elements[beginRow+4].value = "CALL";
				document.getElementById('checkout').setAttribute('disabled', 'true');
				document.getElementById('checkout').value='Please Call 1 300 55 66 75';
			}
			else
			{

				if(width<450)//rate = $110/m2
				{
					rate = 110;
					document.order_form.elements[beginRow+4].value = Cal_Price(width,drop,rate);
				}
				else// width => 450
				{
					if(drop<2300)//rate = $95/m2
					{
						rate = 95;
						document.order_form.elements[beginRow+4].value = Cal_Price(width,drop,rate);
					}
					else//rate = $100/m2
					{
						rate = 100;
						document.order_form.elements[beginRow+4].value = Cal_Price(width,drop,rate);
					}
					
				}
					
			}		*/
			
		}
		
		else if ((wood == "Vertical Cedar - Dark") || (wood == "Vertical Cedar - Medium") ||
				  (wood == "Vertical Cedar - Light" )|| (wood == "vertical_vivid_white")|| 
				  (wood == "vertical_chalk_usa"))
		{
			// TODO:  confirm lowest values for width and drop
			if ((width < 300 ) || (width > 3000) || (drop < 200) || (drop > 2250))
			{
				document.order_form.elements[beginRow+4].value = "CALL";
				document.getElementById('checkout').setAttribute('disabled', 'true');
				document.getElementById('checkout').value='Please Call 1 300 55 66 75';
			}
			else
			{
				// round up width 
				if (width < 600) { width = 600 }
				else if ((width%100) > 0)
				{ 
					width = 100 - +(width%100) + +width; 
				}
				// round up drop
				if (drop > 1500) { drop = 2250; }
				else if (drop >= 200) { drop = 1500; }

				loadXMLDataForPrice("vertical_89x4.xml");
			}
		}
		else 
		{

			if ((width < 280 ) || (width > 2410) || (drop < 200) || (drop > 3000))
				{
		
					document.order_form.elements[beginRow+4].value = "CALL";
						document.getElementById('checkout').setAttribute('disabled', 'true');
						document.getElementById('checkout').value='Please Call 1 300 55 66 75';
				}
			else {
		
					// round up width 
					if (width > 2310) { width = 2410;}
					else if (width < 410) {width = 410;}
					else if (((width - 10)%100) > 0)
						{ 
							width = 100 - +((width - 10)%100) + +width; 
						}
			
					// round up drop
					if (drop > 2700) { drop = 3000; }
					else if (drop > 2500) { drop = 2700; }
					else if (drop > 2400) { drop = 2500; }
					else if (drop > 2300) { drop = 2400; }
					else if (drop > 2200) { drop = 2300; }
					else if (drop > 2100) { drop = 2200; }
					else if (drop > 2000) { drop = 2100; }
					else if (drop > 1900) { drop = 2000; }
					else if (drop > 1800) { drop = 1900; }
					else if (drop > 1700) { drop = 1800; }
					else if (drop > 1600) { drop = 1700; }
					else if (drop > 1500) { drop = 1600; }
					else if (drop > 1400) { drop = 1500; }
					else if (drop > 1300) { drop = 1400; }
					else if (drop > 1200) { drop = 1300; }
					else if (drop > 1100) { drop = 1200; }
					else if (drop > 1000) { drop = 1100; }
					else if (drop > 900) { drop = 1000; }
					else if (drop > 600) { drop = 900; }
						  else if (drop >= 200) { drop = 600; }
			
			
					if ( (wood == "46mm Cedar Med to Light") || 
						  (wood == "46mm Cedar Med to Dark"))
					{
						loadXMLDataForPrice("cedar.xml");
					}
					else if ((wood == "60mm Cedar Med to Light") || 
							  (wood == "60mm Cedar Med to Dark"))
					{
						 loadXMLDataForPrice("cedarwide.xml");
					} 
					else if (wood == "Rustic Cedar")
					{
						 loadXMLDataForPrice("rustic_cedar.xml");
					}
					else if (wood == "Empty")
					{
						document.order_form.elements[beginRow+4].value = 0;
					}
			}
		}
}

	
	calc_total(); 
}

function calc_total() 
{
total = 0;
i = 0;

while (i < 10)
{
	if (document.order_form.elements[(6*i)+4].value == "CALL")
	{
				document.getElementById('checkout').value='Please Call 1 300 55 66 75';
				document.getElementById('checkout').setAttribute('disabled', 'true');
	total = "Call for Price";
	break;
	}
	else 
	{
		total = total + +document.order_form.elements[(6*i)+4].value;

	}
i++;
}
	 	document.order_form.sub_total.value = total;
		document.order_form.grand_total.value = total;
}



function reset_submit()
	{
				document.getElementById('checkout').value='Proceed to Checkout';
				document.getElementById('checkout').removeAttribute('disabled');
	}
function Cal_Price(width,drop,rate)
{
	if((width * drop / 1000000)<1)
	{
		return rate;
	}
	else
	{
		var c = (width * drop / 1000000) * rate;
		return c = Math.round(c*100)/100; 
	}
}

