<!--

function dp(price) 
{
   string = "" + price;
   number = string.length - string.indexOf('.');
   if (string.indexOf('.') == -1)
      return string + '.00';
   if (number == 1)
      return string + '00';
   if (number == 2)
      return string + '0';
   if (number > 3)
      return string.substring(0,string.length-number+3);
return string;
}

function calculate()
{
var type, grills, frame, baybow, argon, color, sizeValue ,sum;

var installation = 7;
var fact = 10;
var sizeValue = 0;
var TotalV = 0;
var ret = 0;
var check = 0;

FormValue = new Array(70);

WindowsType = new Array(70);
TintType =    new Array(70);
GrillsType =  new Array(70);
FrameType =   new Array(70);
BayBowType =  new Array(70); 
ArgonType =   new Array(70); 
ColorType =   new Array(70); 
var NumRows ;
WindowsValue = new Array(70);
WidthValue= new Array(70);
HeightValue = new Array(70);
TintValue = new Array(70);
GrillsValue = new Array(70);
FrameValue = new Array(70);
BayBowValue = new Array(70); 
ArgonValue = new Array(70); 
ColorValue = new Array(70); 
CheckValue = new Array(70);

TotalValue = new Array(7);

MinimumSize = new Array(7);




NumRows = windows_form.Type.length;


for (var i=0;i< NumRows;i++){ 
	WindowsType[i]= windows_form.Type[i].value;
	TintType[i]= windows_form.Tint[i].value;
	GrillsType[i]= windows_form.Grills[i].value;
	FrameType[i]= windows_form.Frame[i].value;
	ColorType[i]= windows_form.Color[i].value;
	BayBowType[i]= windows_form.BayBow[i].value;
	ArgonType[i]= windows_form.Argon[i].value;

	WidthValue[i]= windows_form.Width[i].value;
	HeightValue[i]= windows_form.Height[i].value;
  }


for (var i=0;i< NumRows;i++)
{ 

   if((WidthValue[i] + HeightValue[i])!=0 )
     {

	if (!document.windows_form.Grills[i].checked) {GrillsValue[i] = 0} else{GrillsValue[i] = 4.50};
 
	if (!document.windows_form.Frame[i].checked) {FrameValue[i] = 0} else{FrameValue[i] = 5.50};



	switch (BayBowType[i])  {
		case '1' : BayBowValue[i] = 0
		break
		case '2' : BayBowValue[i] = 60
		break
		case '3' : BayBowValue[i] = 200
		break
		default  : BayBowValue[i] = 0
			}		

	switch (ArgonType[i])  {
		case '1' : ArgonValue[i] = 0
		break
		case '2' : ArgonValue[i] = 1.10
		break
		case '3' : ArgonValue[i] = 1.20
		break
		case '4' : ArgonValue[i] = 1.95
		break
		default  : ArgonValue[i] = 0
			}
	
	switch (ColorType[i])  {
		case '1' : ColorValue[i] = 1
		break
		case '2' : ColorValue[i] = 1.2
		break
		case '3' : ColorValue[i] = 1.2
		break
		case '4' : ColorValue[i] = 1.2
		break
		case '5' : ColorValue[i] = 1.2
		break
		case '6' : ColorValue[i] = 1.2
		break
		default  : ColorValue[i] = 1
			}



	if (TintType[i] == 1) {TintValue[i] = 0} else {TintValue[i]  = 2.50};




	switch (WindowsType[i]) {

		case '1' :  WindowsValue[i] = 13.25
		break
		case '2' :  WindowsValue[i] = 13.25
		break
		case '3' :  WindowsValue[i] = 12.50
		break
		case '4' :  WindowsValue[i] = 11.75
		break
	        case '5' :  WindowsValue[i] = 11.50
		break
		case '6' :  WindowsValue[i] = 11.35
		break
		case '7' :  WindowsValue[i] = 10.70
		break
		case '8' :  WindowsValue[i]=  10.75
		break
		default  :  WindowsValue[i] = 0	}



	switch (WindowsType[i]) {

		case '1' :  CheckValue[i] = CheckWindowsSize( WidthValue[i],HeightValue[i],19,49,19,37);
		break
		case '2' :  CheckValue[i] = CheckWindowsSize( WidthValue[i],HeightValue[i],14,31,14,73);
		break
		case '3' :  CheckValue[i] =CheckWindowsSize( WidthValue[i],HeightValue[i],16,43,24,73); 
		break
		case '4' :  CheckValue[i] = CheckWindowsSize( WidthValue[i],HeightValue[i],19,73,16,43); 
		break
	        case '5' :  CheckValue[i] = CheckWindowsSize( WidthValue[i],HeightValue[i],14,73,14,73);
		break
		case '6' :  CheckValue[i] = CheckWindowsSize( WidthValue[i],HeightValue[i],16,43,24,73);
		break
		case '7' :  CheckValue[i] = CheckWindowsSize( WidthValue[i],HeightValue[i],19,73,16,43);
		break
		case '8' :  CheckValue[i] = CheckWindowsSize( WidthValue[i],HeightValue[i],23,73,35,73);
		break
		default  : 
				}

	if (CheckValue[i] == 0)
		check =1;
	//alert(CheckValue[i]);



	if (WindowsValue[i] == 10.75)
	{
		if ((( WidthValue[i])*( HeightValue[i])/144)  == 0)
                {
			MinimumSize[i] = 0;
		} 
		else
                {
			if ((( WidthValue[i])*( HeightValue[i])/144) < 9)
                        {
				MinimumSize[i] =16;
	 		}
			else
                        {
				if ((( WidthValue[i])*( HeightValue[i])/144) < 12)
                                {	
				MinimumSize[i] =17;
	 			}
				else
                                {
					if ((( WidthValue[i])*( HeightValue[i])/144) < 18)
                                        {	
					MinimumSize[i] =18;
					}
					else
					{
					MinimumSize[i] = ( WidthValue[i])*( HeightValue[i])/144;
					}
	 		         }
		        }
		} 
	}
	else
	{
		if (WindowsValue[i] == 11.50)
		{
			if ((( WidthValue[i])*( HeightValue[i])/144)  == 0)
			{
			MinimumSize[i] = 0;
			} 
			else
			{
				if ((( WidthValue[i])*( HeightValue[i])/144) < 7)
		  		{
				MinimumSize[i] =9.5;
	 			}
				else
				{
				MinimumSize[i] = ( WidthValue[i])*( HeightValue[i])/144;
				}
			}
                }
		else
		{
			if ((( WidthValue[i])*( HeightValue[i])/144)  == 0)
               		{
			MinimumSize[i] = 0;
			} 
			else
                	{
				if ((( WidthValue[i])*( HeightValue[i])/144) < 6)
                        	{
					MinimumSize[i] =9.5;
	 			}
				else
                        	{
					if ((( WidthValue[i])*( HeightValue[i])/144) < 9)
                                	{	
					MinimumSize[i] =10.8;
	 				}
					else
                                	{
						if ((( WidthValue[i])*( HeightValue[i])/144) < 12)
                                       		{	
						MinimumSize[i] =12;
						}
					        else
					        {
					        MinimumSize[i] = ( WidthValue[i])*( HeightValue[i])/144;
					        }
	 				}
				}
			}

		}


	}

	  if (MinimumSize[i] == 0){
		  sizeValue = (( WidthValue[i])*( HeightValue[i])/144);}
	  else sizeValue = MinimumSize[i];



TotalValue[i] = dp(((installation + fact + WindowsValue[i] +  TintValue[i] + GrillsValue[i]+ FrameValue[i]+ArgonValue[i])*ColorValue[i]*sizeValue) + BayBowValue[i]);    

TotalV = dp(parseFloat(TotalV) + parseFloat(TotalValue[i]) );

}
else
	CheckValue[i] = 1;



}




if (check == 1)
{

document.windows_form.subtotal.value = 0;

document.windows_form.tax.value = 0;
document.windows_form.taxgst.value = 0;
document.windows_form.taxpst.value = 0;
document.windows_form.total.value = 0;
//alert('Please check \n - If windows sizes are in correct range\n - If the W" or H" field is empty');
javascript:popUp('Error.htm');
}
else
{
document.windows_form.subtotal.value = dp(parseFloat(TotalV));

document.windows_form.tax.value = dp((document.windows_form.subtotal.value)*0.15);
document.windows_form.taxgst.value = dp((document.windows_form.subtotal.value)*0.07);
document.windows_form.taxpst.value = dp((document.windows_form.subtotal.value)*0.08);
document.windows_form.total.value = dp((document.windows_form.subtotal.value)*1.15);
}
}

function CheckNumeric()
{
   // Get ASCII value of key that user pressed
   var key = window.event.keyCode;

   // Was key that was pressed a numeric character (0-9)?
   if ( key > 47 && key < 58 )
      return; // if so, do nothing
   else
      window.event.returnValue = null; // otherwise, 
	                               // discard character
}



function CheckWindowsSize(width,height,minw,maxw,minh,maxh)
{

if (((width > minw) && (width < maxw)) && ((height > minh) &&(height < maxh)))
 return 1
//alert ('Please check the windows sizes !');
else
//alert ('Please check the windows sizes !');
return 0

}




//-->