// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4){
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
		else if  (window.onload){
				if (window.onload != SafeOnload){
					gSafeOnload[0] = window.onload;
					window.onload = SafeOnload;
				}
		gSafeOnload[gSafeOnload.length] = f;
		}
	else
		window.onload = f;
}

function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}


//
// Main Form Functions
//

// This holds our form values when we need to regenerate the form

var gValue = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14); // ne diraj
var gType = new Array("Awning","Casement","DblHung","DblSlider","Pic/Fix","SglHung","SglSlider","Type C");
var gLocation = new Array("Bath","Bsm","Bed","Dining","Family","Garage","Kitchen","Laundry","Living","M.Bath","M.Bed","Office","Other");
var gTint = new Array( "No","Grey","Bronze","Frost");
var gColor = new Array("W/W","W/C","W/B","W/S","W/G","W/O");
var gBayBow = new Array("No", "Existing", "New");
var gArgon = new Array("No", "LowE", "Argon", "Both"); 

var NumberOfRows;


var gOneVal = new Array();
var gTwoVal = new Array();
var gThreeVal = new Array();
var gFourVal = new Array();
var gFiveVal = new Array();
var gSixVal = new Array();
var gSevenVal = new Array();
var gEightVal = new Array();
var gNineVal = new Array();
var gTenVal = new Array();

function GetFormHTML()
{

	var htmlStr = '';
	htmlStr += '<form name="windows_form" action="asp/estimateform.asp" method="POST">';
	
htmlStr += '<TABLE cellpadding=2 border=2 cellspacing=2 width="98%" >';
htmlStr += '<TR><font face="Arial" size="2">';
htmlStr += 'Get a window quote or <b>estimate online absolutely free</b>. Whether you are thinking about replacing windows or doors..... </b>';
htmlStr += 'Know the <b>right price </b>before you contact <a href="contact.htm"><b>HomesRenovation</a></b>.<br>';
htmlStr += 'Please note that all quotes are viewed as approximate costs you could expect based on the ';
htmlStr += 'information submitted.  ';
htmlStr += 'For width and height measurements enter sizes in "inches".  ';
htmlStr += 'Round size up to the nearest inch.<br><br></font>';


	htmlStr += '<TD width="165" bgcolor="#C0C0C0"><font size="2"><a href="javascript:popUp(\'type.htm\')">WindowType<font color="#990000">?</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:popUp(\'window_location.htm\')">Location<font color="#990000">?</font></a></TD><TD width="65"  bgcolor="#C0C0C0"><font size="2"><a href="javascript:popUp(\'width.htm\')">&nbsp;W"<font color="#990000">?</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:popUp(\'height.htm\')">H"<font color="#990000">?</font> </a></TD><TD width="110" bgcolor="#C0C0C0"><font size="2"><a href="javascript:popUp(\'tint.htm\')">Tint/Frost</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:popUp(\'grills.htm\')">Grills<font color="#990000">?</font></a></TD><TD  width="140" bgcolor="#C0C0C0"><font size="2"><a href="javascript:popUp(\'color.htm\')">Color<font color="#990000">?</font></a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:popUp(\'replace_frame.htm\')">Frame<font color="#990000">?</font></a></TD><TD width="140" bgcolor="#C0C0C0"><font size="2"><a href="javascript:popUp(\'bay_bow.htm\')">Bay/Bow<font color="#990000">?</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:popUp(\'other">LowE/Argon<font color="#990000">?</font></a></TD></TR>';




	
	for (var j=0;j<NumberOfRows;j++){			
		htmlStr += '<TR>';
		htmlStr += '<TD  width="165">';
	    	
	    	htmlStr += '<font size="2"><select size="1" name="Type">';
		     for (var i=0;i<gType.length;i++){	
		  	if ( gValue[i] == gOneVal[j]){
				htmlStr += '<option selected value="'+gValue[i]+'">'+gType[i];
			}else
				{
				htmlStr += '<option value="'+gValue[i]+'">'+gType[i];
			}
		     }
	  	htmlStr += '</select></font>';
	  	
	  	htmlStr += '<font size="2"><select size="1" name="Location">';
		     for (var i=0;i<(gLocation.length);i++){	
		  	if ( gValue[i] == gTwoVal[j]){
				htmlStr += '<option selected value="'+gValue[i]+'">'+gLocation[i];
			}else
				{
				htmlStr += '<option value="'+gValue[i]+'">'+gLocation[i];
			}
		     }
	  	htmlStr += '</select></font></TD>';
		
		htmlStr += '<TD  width="75"><INPUT type="text" name="Width" ONKEYPRESS="CheckNumeric()" size="2" value="'+gThreeVal[j]+'">&nbsp;';
		htmlStr += '<INPUT type="text" name="Height" ONKEYPRESS="CheckNumeric()"size="2" value="'+gFourVal[j]+'"></TD>';
		htmlStr += '<TD  width="100">';
		
		htmlStr += '<select size="1" name="Tint">';
		     for (var i=0;i<(gTint.length);i++){	
		  	if ( gValue[i] == gFiveVal[j]){
				htmlStr += '<option selected value="'+gValue[i]+'">'+gTint[i];
			}else
				{
				htmlStr += '<option value="'+gValue[i]+'">'+gTint[i];
			}
		     }
		htmlStr += '</select>';
		
                	if( gSixVal[j] == 'ON' ){
                    		htmlStr += '<input type="checkbox" name="Grills" value="ON" checked>';
                	}
                	else{
                    		htmlStr += '<input type="checkbox" name="Grills" value="OFF">';
                	}  
		
		
		htmlStr += '<TD  width="120"><font size="2"><select size="1" name="Color">';
		     for (var i=0;i<(gColor.length);i++){	
		  	if ( gValue[i] == gSevenVal[j]){
				htmlStr += '<option selected value="'+gValue[i]+'">'+gColor[i];
			}else
				{
				htmlStr += '<option value="'+gValue[i]+'">'+gColor[i];
			}
		     }		
		htmlStr += '</select>';
		
                	if( gEightVal[j] == 'ON' ){
                    		htmlStr += '<input type="checkbox" name="Frame" value="ON" checked>';
                	}
                	else{
                    		htmlStr += '<input type="checkbox" name="Frame" value="OFF">';
                	}  
		
		
		htmlStr += '<TD  width="180"><select size="1" name="BayBow">';
		     for (var i=0;i<(gBayBow.length);i++){	
		  	if ( gValue[i] == gNineVal[j]){
				htmlStr += '<option selected value="'+gValue[i]+'">'+gBayBow[i];
			}else
				{
				htmlStr += '<option value="'+gValue[i]+'">'+gBayBow[i];
			}
		     }
		htmlStr += '</select>&nbsp;';
		
		htmlStr += '<select size="1" name="Argon">';
		     for (var i=0;i<(gArgon.length);i++){	
		  	if ( gValue[i] == gTenVal[j]){
				htmlStr += '<option selected value="'+gValue[i]+'">'+gArgon[i];
			}else
				{
				htmlStr += '<option value="'+gValue[i]+'">'+gArgon[i];
			}
		     }
		htmlStr += '</select></TD>';
		
		htmlStr += '</TR>';	
	}
htmlStr += '<TR><TD colspan="5" width="98%" align="right" bgcolor="#C0C0C0"><font size="2">SUBTOTAL <INPUT type="text" name="subtotal"></TD></TR>';
htmlStr += ' <tr>';
htmlStr += '   <TD colspan="5" width="98%" align="right"><font size="2">GST - 7% <INPUT type="text" name="taxgst" size="20"></TD>';
htmlStr += ' </tr>';
htmlStr += '<TR><TD colspan="5" width="98%" align="right"><font size="2">PST - 8% <INPUT type="text" name="taxpst" size="20"></TD></TR>';
htmlStr += '  <tr>';
htmlStr += '    <TD colspan="5" width="98%" align="right"><font size="2">TAX TOTAL <INPUT type="text" name="tax"></TD>';
htmlStr += '  </tr>';
htmlStr += '<TR><TD colspan="5" width="98%" align="right" bgcolor="#C0C0C0"><font size="2">GRAND TOTAL <INPUT type="text" name="total"></TD></TR>';


	htmlStr += '</TABLE>&nbsp;';
	htmlStr += '<p><input type="button" value="Add Item" onClick="AddField()">&nbsp;&nbsp;&nbsp;<INPUT type="reset" Value="  Reset  ">&nbsp;&nbsp;&nbsp;<INPUT type="button" Value="Calculate" ONCLICK="calculate()"></p>';
	
	
	
		
	htmlStr += '</center>';
	htmlStr += '<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=4 height="0%" WIDTH="100%">';
	htmlStr += '<TR>';
	htmlStr += '<TD>';
	htmlStr += '<font face="Arial" size="2">';
	htmlStr += 'For exact pricing please <a href="contact.htm">contact us</a>.';
	htmlStr += 'One of our representatives would be pleased to provide you  no cost, no obligation in-home estimate and offer you a contract. ';
	
	htmlStr += '<br><b>Please enter your contact information. </b>';
	
	
	
	htmlStr += '</font>';
	htmlStr += '</TD>';
	htmlStr += '<TR>';
	htmlStr += '</TABLE>';
	htmlStr += '<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 height="0%" WIDTH="100%" >';
	htmlStr += '	<tr>';
	htmlStr += '		<td >';
	htmlStr += '			&nbsp;&nbsp;<font face="Arial" size="2">First name : ';
	htmlStr += '		</td>';
	htmlStr += '		<td>';
	htmlStr += '			<INPUT TYPE="text" NAME="sFirst" SIZE=35 MAXLENGTH="35" VALUE="">';
	htmlStr += '		</td>';
	htmlStr += '	</tr>';
	htmlStr += '	<tr>';
	htmlStr += '		<td>';
	htmlStr += '			&nbsp;&nbsp;<font face="Arial" size="2">Last name  :';
	htmlStr += '		</td>';
	htmlStr += '		<td>';
	htmlStr += '		<INPUT TYPE="text" NAME="sLast" SIZE=30 MAXLENGTH="30" VALUE="">';
	htmlStr += '		</td>';
	htmlStr += '	</tr>';
	htmlStr += '	<tr>';
	htmlStr += '		<td>';
	htmlStr += '			&nbsp;&nbsp;<font face="Arial" size="2">Street Address :';
	htmlStr += '		</td>';
	htmlStr += '		<td>';
	htmlStr += '			<INPUT TYPE="text" NAME="sStreet" SIZE=35 MAXLENGTH="35" VALUE="">';
	htmlStr += '		</td>';
	htmlStr += '	</tr>';
	htmlStr += '	<tr>';
	htmlStr += '		<td>';
	htmlStr += '			&nbsp;&nbsp;<font face="Arial" size="2">City :';
	htmlStr += '		</td>';
	htmlStr += '		<td>';
	htmlStr += '			<INPUT TYPE="text" NAME="sCity" SIZE=35 MAXLENGTH="35" VALUE="">';
	htmlStr += '		</td>';
	htmlStr += '	</tr>';
	htmlStr += '	<tr>';
	htmlStr += '		<td>';
	htmlStr += '			&nbsp;&nbsp;<font face="Arial" size="2">Province :';
	htmlStr += '		</td>';
	htmlStr += '		<td>';
	htmlStr += '			<INPUT TYPE="text" NAME="sProvince" SIZE=2 MAXLENGTH="2" VALUE="">';
	htmlStr += '		</td>';
	htmlStr += '	</tr>';
	htmlStr += '	<tr>';
	htmlStr += '		<td>';
	htmlStr += '			&nbsp;&nbsp;<font face="Arial" size="2">Postal Code :';
	htmlStr += '		</td>';
	htmlStr += '		<td>';
	htmlStr += '			<INPUT TYPE="text" NAME="sPostal" SIZE=10 MAXLENGTH="10" VALUE="">';
	htmlStr += '		</td>';
	htmlStr += '	</tr>';
	htmlStr += '	<tr>';
	htmlStr += '		<td>';
	htmlStr += '			&nbsp;&nbsp;<font face="Arial" size="2">Phone :';
	htmlStr += '		</td>';
	htmlStr += '		<td>';
	htmlStr += '			<INPUT TYPE="text" NAME="sPhone" SIZE=14 MAXLENGTH="14" VALUE="">';
	htmlStr += '		</td>';
	htmlStr += '	</tr>';
	htmlStr += '	<tr>';
	htmlStr += '		<td>';
	htmlStr += '			&nbsp;&nbsp;<font face="Arial" size="2">E-mail :    ';
	htmlStr += '		</td>';
	htmlStr += '		<td>';
	htmlStr += '			<INPUT TYPE="text" NAME="sEmail" SIZE=35 MAXLENGTH="35" VALUE="">';
	htmlStr += '		</td>';
	htmlStr += '	</tr>';
	
	
	htmlStr += '</TABLE>';
	
	
	
	

	htmlStr += '<center>';
	htmlStr += '<font face="Arial" size="2">';
	htmlStr += '<p>&nbsp Click here for a <b>free, no-obligation in-home estimate</font></b><br><br> ';
	htmlStr += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp <INPUT type="submit" Value="    Order   " align="center"></p><br><br><br>';
	htmlStr += '</center>';

	
	
	
	
	
	
	htmlStr += '</FORM>';

	return htmlStr;
}

function GetFormObj()
{
	var returnObj = null;

	if (IE4plus){
		returnObj =  document.windows_form;
	}
		else if (NS4){
			returnObj =  document.formlayer.document.windows_form;
		}
			else if (NS6){
				returnObj =  document.getElementById("windows_form");
			}	
	return returnObj;
}

function AddField()
{
	// Save previously entered data here
	var formObj = GetFormObj();

	for (var i=0;i<formObj.Type.length;i++){	
		gOneVal[i]= formObj.Type[i].options[formObj.Type[i].selectedIndex].value;
		gTwoVal[i]= formObj.Location[i].options[formObj.Location[i].selectedIndex].value;
		gThreeVal[i]= formObj.Width[i].value;
		gFourVal[i]= formObj.Height[i].value;
		gFiveVal[i]= formObj.Tint[i].options[formObj.Tint[i].selectedIndex].value;		
		if (formObj.Grills[i].checked) {gSixVal[i]= 'ON';}
        		else {gSixVal[i]= 'OFF';}		
		gSevenVal[i]= formObj.Color[i].options[formObj.Color[i].selectedIndex].value;
		if (formObj.Frame[i].checked) {gEightVal[i]= 'ON';}
        		else {gEightVal[i]= 'OFF';}
		gNineVal[i]= formObj.BayBow[i].options[formObj.BayBow[i].selectedIndex].value;
		gTenVal[i]= formObj.Argon[i].options[formObj.Argon[i].selectedIndex].value;
	}
	
	gOneVal[formObj.Type.length]= "";
	gTwoVal[formObj.Location.length]= "";
	gThreeVal[formObj.Width.length]= "";
	gFourVal[formObj.Height.length]= "";
	gFiveVal[formObj.Tint.length]= "";
	gSixVal[formObj.Grills.length]= "OFF"; 
	gSevenVal[formObj.Color.length]= ""; 
	gEightVal[formObj.Frame.length]= "OFF"; 
	gNineVal[formObj.BayBow.length]= ""; 
	gTenVal[formObj.Argon.length]= ""; 
	
	NumberOfRows = formObj.Type.length +1;
	
	UpdateForm();
}

function UpdateForm()
{
	var htmlStr = GetFormHTML();
	if (IE4plus){
		document.all.formlayer.innerHTML = htmlStr;
	}
	else if (NS4){
		document.formlayer.document.open();
		document.formlayer.document.write(htmlStr);
		document.formlayer.document.close();
	}
	else if (NS6){
		document.getElementById("formlayer").innerHTML = htmlStr;
	}
}

function IncludeForm()
{
	var htmlStr = GetFormHTML();

	if (IE4plus || NS6){
		document.write('<DIV ID=formlayer name=formlayer  STYLE="position:relative; WIDTH=400px; HEIGHT=50px">' + htmlStr + '</DIV>');
	}
	else if (NS4){
		// Because NS needs floating layers, we need a placeholder graphic to force anything
		// below the layer content to leave whitespace for the layer.  The position of this
		// graphic is also used in determining the position of the layer.
		document.write('<img name="formlocation" border="0" width="400" height="200" src="images/spacer.gif">');
	}

}

//
// Netscape 4.x Ineptness
//
function HandleOnload()
{
	if (NS4){
		var width = document.formlocation.width;
		var height = document.formlocation.height;

		nL=new Layer(width);
		nL.name = "formlayer";
		nL.left=document.formlocation.x;
		nL.top=document.formlocation.y;
		nL.bgColor = "white";
		nL.clip.width=width;
		nL.clip.height=height;
		nL.document.open();
		nL.document.write(GetFormHTML());
		nL.document.close();
		nL.visibility = 'show';

		document.formlayer = nL;
	}
}

function HandleResize()
{
	location.reload();
	return false;
}

if (NS4){
	SafeAddOnload(HandleOnload);
	window.captureEvents(Event.RESIZE);
	window.onresize = HandleResize;
}

