	// Number of rows
	var rowCount = 7

	// Used to store the grand total for the order
	var windowGrandTotalValue = 0;
	var containsQuotes = false;
	
	// Updates all the total values including the grand total
	function updateTotals()
	{
		var windowGrandTotal = document.orderonline.window_grand_total;

		containsQuotes = false;
		windowGrandTotalValue = 0;
		for( i = 0 ; i < rowCount ; i++ )
		{
			var windowWidth		= document.orderonline.window_width[i];
			var windowHeight		= document.orderonline.window_drop[i];
			var windowQuantity	= document.orderonline.quantity[i];
			var rowTotal			= document.orderonline.window_total[i];

			if( parseInt(windowWidth.value) > 0 && parseInt(windowHeight.value) > 0 && parseInt(windowQuantity.value) > 0 )
			{
				rowTotal.value	= getCost( windowWidth, windowHeight) * parseInt(windowQuantity.value);

				if( parseInt(rowTotal.value) == 0 || isNaN( rowTotal.value ) )
				{
					rowTotal.value = 'Quote';
				}
				else
				{				
					windowGrandTotalValue += parseInt(rowTotal.value);
				}
			}
		}

		windowGrandTotal.value = windowGrandTotalValue;
	}

	// Returns the cost for different widths and heights.
	function getCost(windowWidth, windowHeight)
	{
		var width = parseInt(windowWidth.value);
		var height = parseInt(windowHeight.value);
		
		if( ( width || height ) > 1800 || (width && height) > 1800 )
		{
			return 'Quote';
		}
		else
		{
			if( width < 300 )
			{
				if( height < 300 )
				{
					return 46;
				}
				if( height < 400 )
				{
					return 48;
				}
				else if ( height < 500 ) 
				{
					return 50;
				}
				else if ( height < 600 ) 
				{
					return 52;
				}
				else if ( height < 700 ) 
				{
					return 53;
				}
				else if ( height < 800 ) 
				{
					return 54;
				}
				else if ( height < 900 ) 
				{
					return 56;
				}
				else if ( height < 1000 ) 
				{
					return 58;
				}
				else if ( height < 1100 ) 
				{
					return 59;
				}
				else if ( height < 1200 ) 
				{
					return 61;
				}
				else if ( height < 1300 ) 
				{
					return 63;
				}
				else if ( height < 1400 ) 
				{
					return 64;
				}
				else if ( height < 1500 ) 
				{
					return 66;
				}
				else if ( height < 1600 ) 
				{
					return 68;
				}
				else if ( height < 1700 ) 
				{
					return 70;
				}
				else 
				{
					return 72;
				}
			}
			else if( width < 400 )
			{
				if( height < 300 )
				{
					return 48;
				}
				if( height < 400 )
				{
					return 51;
				}
				else if ( height < 500 ) 
				{
					return 52;
				}
				else if ( height < 600 ) 
				{
					return 53;
				}
				else if ( height < 700 ) 
				{
					return 55;
				}
				else if ( height < 800 ) 
				{
					return 56;
				}
				else if ( height < 900 ) 
				{
					return 57;
				}
				else if ( height < 1000 ) 
				{
					return 58;
				}
				else if ( height < 1100 ) 
				{
					return 60;
				}
				else if ( height < 1200 ) 
				{
					return 62;
				}
				else if ( height < 1300 ) 
				{
					return 64;
				}
				else if ( height < 1400 ) 
				{
					return 66;
				}
				else if ( height < 1500 ) 
				{
					return 68;
				}
				else if ( height < 1600 ) 
				{
					return 70;
				}
				else if ( height < 1700 ) 
				{
					return 72;
				}
				else 
				{
					return 74;
				}
	
			}
			else if ( width < 500 ) 
			{
				if( height < 300 )
				{
					return 50;
				}
				else if( height < 400 )
				{
					return 52;
				}
				else if ( height < 500 ) 
				{
					return 54;
				}
				else if ( height < 600 ) 
				{
					return 55;
				}
				else if ( height < 700 ) 
				{
					return 56;
				}
				else if ( height < 800 ) 
				{
					return 57;
				}
				else if ( height < 900 ) 
				{
					return 58;
				}
				else if ( height < 1000 ) 
				{
					return 60;
				}
				else if ( height < 1100 ) 
				{
					return 62;
				}
				else if ( height < 1200 ) 
				{
					return 64;
				}
				else if ( height < 1300 ) 
				{
					return 66;
				}
				else if ( height < 1400 ) 
				{
					return 68;
				}
				else if ( height < 1500 ) 
				{
					return 70;
				}
				else if ( height < 1600 ) 
				{
					return 72;
				}
				else if ( height < 1700 ) 
				{
					return 74;
				}
				else 
				{
					return 76;
				}
			}
			else if ( width < 600 ) 
			{
				if( height < 300 )
				{
					return 52;
				}
				else if( height < 400 )
				{
					return 53;
				}
				else if ( height < 500 ) 
				{
					return 55;
				}
				else if ( height < 600 ) 
				{
					return 56;
				}
				else if ( height < 700 ) 
				{
					return 58;
				}
				else if ( height < 800 ) 
				{
					return 60;
				}
				else if ( height < 900 ) 
				{
					return 62;
				}
				else if ( height < 1000 ) 
				{
					return 64;
				}
				else if ( height < 1100 ) 
				{
					return 66;
				}
				else if ( height < 1200 ) 
				{
					return 68;
				}
				else if ( height < 1300 ) 
				{
					return 70;
				}
				else if ( height < 1400 ) 
				{
					return 72;
				}
				else if ( height < 1500 ) 
				{
					return 74;
				}
				else if ( height < 1600 ) 
				{
					return 75;
				}
				else if ( height < 1700 ) 
				{
					return 76;
				}
				else
				{
					return 78;
				}
			}
			else if ( width < 700 ) 
			{
				if( height < 300 )
				{
					return 53;
				}
				else if( height < 400 )
				{
					return 55;
				}
				else if ( height < 500 ) 
				{
					return 56;
				}
				else if ( height < 600 ) 
				{
					return 58;
				}
				else if ( height < 700 ) 
				{
					return 60;
				}
				else if ( height < 800 ) 
				{
					return 62;
				}
				else if ( height < 900 ) 
				{
					return 64;
				}
				else if ( height < 1000 ) 
				{
					return 66;
				}
				else if ( height < 1100 ) 
				{
					return 68;
				}
				else if ( height < 1200 ) 
				{
					return 70;
				}
				else if ( height < 1300 ) 
				{
					return 72;
				}
				else if ( height < 1400 ) 
				{
					return 74;
				}
				else if ( height < 1500 ) 
				{
					return 76;
				}
				else if ( height < 1600 ) 
				{
					return 76;
				}
				else if ( height < 1700 ) 
				{
					return 78;
				}
				else
				{
					return 80;
				}
			}
			else if ( width < 800 ) 
			{
				if( height < 300 )
				{
					return 54;
				}
				else if( height < 400 )
				{
					return 56;
				}
				else if ( height < 500 ) 
				{
					return 57;
				}
				else if ( height < 600 ) 
				{
					return 60;
				}
				else if ( height < 700 ) 
				{
					return 62;
				}
				else if ( height < 800 ) 
				{
					return 64;
				}
				else if ( height < 900 ) 
				{
					return 66;
				}
				else if ( height < 1000 ) 
				{
					return 68;
				}
				else if ( height < 1100 ) 
				{
					return 70;
				}
				else if ( height < 1200 ) 
				{
					return 72;
				}
				else if ( height < 1300 ) 
				{
					return 74;
				}
				else if ( height < 1400 ) 
				{
					return 76;
				}
				else if ( height < 1500 ) 
				{
					return 78;
				}
				else if ( height < 1600 ) 
				{
					return 79;
				}
				else if ( height < 1700 ) 
				{
					return 80;
				}
				else
				{
					return 82;
				}
			}
			else if ( width < 900 ) 
			{
				if( height < 300 )
				{
					return 56;
				}
				else if( height < 400 )
				{
					return 57;
				}
				else if ( height < 500 ) 
				{
					return 58;
				}
				else if ( height < 600 ) 
				{
					return 62;
				}
				else if ( height < 700 ) 
				{
					return 64;
				}
				else if ( height < 800 ) 
				{
					return 66;
				}
				else if ( height < 900 ) 
				{
					return 68;
				}
				else if ( height < 1000 ) 
				{
					return 72;
				}
				else if ( height < 1100 ) 
				{
					return 72;
				}
				else if ( height < 1200 ) 
				{
					return 74;
				}
				else if ( height < 1300 ) 
				{
					return 76;
				}
				else if ( height < 1400 ) 
				{
					return 78;
				}
				else if ( height < 1500 ) 
				{
					return 80;
				}
				else if ( height < 1600 ) 
				{
					return 81;
				}
				else if ( height < 1700 ) 
				{
					return 82;
				}
				else
				{
					return 84;
				}
			}
			else if ( width < 1000 ) 
			{
				if( height < 300 )
				{
					return 58;
				}
				else if( height < 400 )
				{
					return 58;
				}
				else if ( height < 500 ) 
				{
					return 60;
				}
				else if ( height < 600 ) 
				{
					return 64;
				}
				else if ( height < 700 ) 
				{
					return 66;
				}
				else if ( height < 800 ) 
				{
					return 68;
				}
				else if ( height < 900 ) 
				{
					return 70;
				}
				else if ( height < 1000 ) 
				{
					return 72;
				}
				else if ( height < 1100 ) 
				{
					return 74;
				}
				else if ( height < 1200 ) 
				{
					return 76;
				}
				else if ( height < 1300 ) 
				{
					return 78;
				}
				else if ( height < 1400 ) 
				{
					return 80;
				}
				else if ( height < 1500 ) 
				{
					return 82;
				}
				else if ( height < 1600 ) 
				{
					return 83;
				}
				else if ( height < 1700 ) 
				{
					return 84;
				}
				else
				{
					return 88;
				}
			}
			else if ( width < 1100 ) 
			{
				if( height < 300 )
				{
					return 59;
				}
				else if( height < 400 )
				{
					return 60;
				}
				else if ( height < 500 ) 
				{
					return 62;
				}
				else if ( height < 600 ) 
				{
					return 66;
				}
				else if ( height < 700 ) 
				{
					return 68;
				}
				else if ( height < 800 ) 
				{
					return 70;
				}
				else if ( height < 900 ) 
				{
					return 72;
				}
				else if ( height < 1000 ) 
				{
					return 74;
				}
				else if ( height < 1100 ) 
				{
					return 76;
				}
				else if ( height < 1200 ) 
				{
					return 78;
				}
				else if ( height < 1300 ) 
				{
					return 80;
				}
				else if ( height < 1400 ) 
				{
					return 82;
				}
				else if ( height < 1500 ) 
				{
					return 84;
				}
				else if ( height < 1600 ) 
				{
					return 86;
				}
				else if ( height < 1700 ) 
				{
					return 88;
				}
				else
				{
					return 90;
				}
			}
			else if ( width < 1200 ) 
			{
				if( height < 300 )
				{
					return 61;
				}
				else if( height < 400 )
				{
					return 62;
				}
				else if ( height < 500 ) 
				{
					return 64;
				}
				else if ( height < 600 ) 
				{
					return 68;
				}
				else if ( height < 700 ) 
				{
					return 70;
				}
				else if ( height < 800 ) 
				{
					return 72;
				}
				else if ( height < 900 ) 
				{
					return 74;
				}
				else if ( height < 1000 ) 
				{
					return 76;
				}
				else if ( height < 1100 ) 
				{
					return 78;
				}
				else if ( height < 1200 ) 
				{
					return 80;
				}
				else if ( height < 1300 ) 
				{
					return 82;
				}
				else if ( height < 1400 ) 
				{
					return 84;
				}
				else if ( height < 1500 ) 
				{
					return 86;
				}
				else if ( height < 1600 ) 
				{
					return 88;
				}
				else if ( height < 1700 ) 
				{
					return 90;
				}
				else
				{
					return 92;
				}
			}
			else if ( width < 1300 ) 
			{
				if( height < 300 )
				{
					return 63;
				}
				else if( height < 400 )
				{
					return 64;
				}
				else if ( height < 500 ) 
				{
					return 66;
				}
				else if ( height < 600 ) 
				{
					return 70;
				}
				else if ( height < 700 ) 
				{
					return 72;
				}
				else if ( height < 800 ) 
				{
					return 74;
				}
				else if ( height < 900 ) 
				{
					return 76;
				}
				else if ( height < 1000 ) 
				{
					return 78;
				}
				else if ( height < 1100 ) 
				{
					return 80;
				}
				else if ( height < 1200 ) 
				{
					return 82;
				}
				else if ( height < 1300 ) 
				{
					return 84;
				}
				else if ( height < 1400 ) 
				{
					return 86;
				}
				else if ( height < 1500 ) 
				{
					return 88;
				}
				else if ( height < 1600 ) 
				{
					return 90;
				}
				else if ( height < 1700 ) 
				{
					return 92;
				}
				else 
				{
					return 94;
				}
			}
			else if ( width < 1400 ) 
			{
				if( height < 300 )
				{
					return 64;
				}
				else if( height < 400 )
				{
					return 66;
				}
				else if ( height < 500 ) 
				{
					return 68;
				}
				else if ( height < 600 ) 
				{
					return 72;
				}
				else if ( height < 700 ) 
				{
					return 74;
				}
				else if ( height < 800 ) 
				{
					return 76;
				}
				else if ( height < 900 ) 
				{
					return 78;
				}
				else if ( height < 1000 ) 
				{
					return 80;
				}
				else if ( height < 1100 ) 
				{
					return 82;
				}
				else if ( height < 1200 ) 
				{
					return 84;
				}
				else if ( height < 1300 ) 
				{
					return 86;
				}
				else if ( height < 1400 ) 
				{
					return 88;
				}
				else if ( height < 1500 ) 
				{
					return 90;
				}
				else if ( height < 1600 ) 
				{
					return 92;
				}
				else if ( height < 1700 ) 
				{
					return 94;
				}
				else
				{
					return 96;
				}
			}
			else if ( width < 1500 ) 
			{
				if( height < 300 )
				{
					return 66;
				}
				else if( height < 400 )
				{
					return 68;
				}
				else if ( height < 500 ) 
				{
					return 70;
				}
				else if ( height < 600 ) 
				{
					return 74;
				}
				else if ( height < 700 ) 
				{
					return 76;
				}
				else if ( height < 800 ) 
				{
					return 78;
				}
				else if ( height < 900 ) 
				{
					return 80;
				}
				else if ( height < 1000 ) 
				{
					return 82;
				}
				else if ( height < 1100 ) 
				{
					return 84;
				}
				else if ( height < 1200 ) 
				{
					return 86;
				}
				else if ( height < 1300 ) 
				{
					return 88;
				}
				else if ( height < 1400 ) 
				{
					return 90;
				}
				else if ( height < 1500 ) 
				{
					return 92;
				}
				else if ( height < 1600 ) 
				{
					return 94;
				}
				else if ( height < 1700 ) 
				{
					return 96;
				}
				else
				{
					return 98;
				}
			}
			else if ( width < 1600 ) 
			{
				if( height < 300 )
				{
					return 68;
				}
				else if( height < 400 )
				{
					return 70;
				}
				else if ( height < 500 ) 
				{
					return 72;
				}
				else if ( height < 600 ) 
				{
					return 75;
				}
				else if ( height < 700 ) 
				{
					return 76;
				}
				else if ( height < 800 ) 
				{
					return 79;
				}
				else if ( height < 900 ) 
				{
					return 81;
				}
				else if ( height < 1000 ) 
				{
					return 83;
				}
				else if ( height < 1100 ) 
				{
					return 86;
				}
				else if ( height < 1200 ) 
				{
					return 88;
				}
				else if ( height < 1300 ) 
				{
					return 90;
				}
				else if ( height < 1400 ) 
				{
					return 92;
				}
				else if ( height < 1500 ) 
				{
					return 94;
				}
				else if ( height < 1600 ) 
				{
					return 95;
				}
				else if ( height < 1700 ) 
				{
					return 97;
				}
				else
				{
					return 99;
				}
			}
			else if ( width < 1700 ) 
			{
				if( height < 300 )
				{
					return 70;
				}
				else if( height < 400 )
				{
					return 72;
				}
				else if ( height < 500 ) 
				{
					return 74;
				}
				else if ( height < 600 ) 
				{
					return 76;
				}
				else if ( height < 700 ) 
				{
					return 78;
				}
				else if ( height < 800 ) 
				{
					return 80;
				}
				else if ( height < 900 ) 
				{
					return 82;
				}
				else if ( height < 1000 ) 
				{
					return 84;
				}
				else if ( height < 1100 ) 
				{
					return 88;
				}
				else if ( height < 1200 ) 
				{
					return 90;
				}
				else if ( height < 1300 ) 
				{
					return 92;
				}
				else if ( height < 1400 ) 
				{
					return 94;
				}
				else if ( height < 1500 ) 
				{
					return 96;
				}
				else if ( height < 1600 ) 
				{
					return 97;
				}
				else if ( height < 1700 ) 
				{
					return 98;
				}
				else
				{
					return 100;
				}
			}
			else if ( width < 1800 ) 
			{
				if( height < 300 )
				{
					return 72;
				}
				else if( height < 400 )
				{
					return 74;
				}
				else if ( height < 500 ) 
				{
					return 76;
				}
				else if ( height < 600 ) 
				{
					return 78;
				}
				else if ( height < 700 ) 
				{
					return 80;
				}
				else if ( height < 800 ) 
				{
					return 82;
				}
				else if ( height < 900 ) 
				{
					return 84;
				}
				else if ( height < 1000 ) 
				{
					return 88;
				}
				else if ( height < 1100 ) 
				{
					return 90;
				}
				else if ( height < 1200 ) 
				{
					return 92;
				}
				else if ( height < 1300 ) 
				{
					return 94;
				}
				else if ( height < 1400 ) 
				{
					return 96;
				}
				else if ( height < 1500 ) 
				{
					return 98;
				}
				else if ( height < 1600 ) 
				{
					return 99;
				}
				else if ( height < 1700 ) 
				{
					return 100;
				}
				else
				{
					return 102;
				}
			}
		}
	}
