// JavaScript Document
function InitForm()
{
	var monthlist = new Array(13);
	monthlist[1] = "Jan";
	monthlist[2] = "Feb";
	monthlist[3] = "Mar";
	monthlist[4] = "Apr";
	monthlist[5] = "May";
	monthlist[6] = "Jun";
	monthlist[7] = "Jul";
	monthlist[8] = "Aug";
	monthlist[9] = "Sep";
	monthlist[10] = "Oct";
	monthlist[11] = "Nov";
	monthlist[12] = "Dec";
			
	var now = new Date();
	var yy = now.getYear();
	var mm = now.getMonth() + 1;
	var dd = now.getDate();
	
	document.getElementById("selDateMon").value = monthlist[mm];
	document.getElementById("selDateReqMon").value = monthlist[mm];
	document.getElementById("txtDateYear").value = "2011";
	document.getElementById("txtDateReqYear").value = "2011";
	document.getElementById("txtDateDay").value = dd;
	
	document.getElementById("Door_Draw_Count").value = "30";
	document.getElementById("Frame_Count").value = "5";
	document.getElementById("Panel_Count").value = "15";
	
	document.getElementById("otherCountryName").style.visibility = "hidden";
	/*
	var i;
	for (i = 2; i < 6; i++)
	{
		AddTbl2Tr();
	}
	for (i = 2; i < 11; i++)
	{
		AddTbl1Tr();
		AddTbl3Tr();
	}
	*/
}

function CountryChange()
{
	if (document.getElementById("selCountry").value == "Other")
	{
		document.getElementById("otherCountryName").style.visibility = "visible";
	}
	else
	{
		document.getElementById("otherCountryName").style.visibility = "hidden";
	}
}

function Validation()
{
   if (document.getElementById("txtContactName").value == "")
   {
      alert("Please input contact name!");
	  document.getElementById("txtContactName").focus();
	  return false;
   }
   if (document.getElementById("txtTel1").value == "")
   {
      alert("Please input proper formated telephone number!");
	  document.getElementById("txtTel1").focus();
	  return false;
   }
   if (document.getElementById("txtTel2").value == "")
   {
      alert("Please input proper formated telephone number!");
	  document.getElementById("txtTel2").focus();
	  return false;
   }
   if (document.getElementById("txtTel3").value == "")
   {
      alert("Please input proper formated telephone number!");
	  document.getElementById("txtTel3").focus();
	  return false;
   }
   if (document.getElementById("txtEmail").value == "")
   {
      alert("Please input your email!");
	  document.getElementById("txtEmail").focus();
	  return false;
   }
   if (document.getElementById("txtEmail").value != document.getElementById("txtCEmail").value)
   {
      alert("Your two emails are not the same!");
	  document.getElementById("txtEmail").focus();
	  return false;
   }

   var address = document.getElementById("txtEmail").value;
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(address) == false) {
      alert("Invalid Email Address");
	  document.getElementById("txtEmail").focus();
      return false;
   }

   if(!document.getElementById("chk1").checked)
   {
   		alert("Please read Belmont Doors' Terms and Policies and then click the checkbox!");
		document.getElementById("chk1").focus();
		return false;
   }
   if (!document.getElementById("chk2").checked)
   {
   		alert("Please read Belmont Doors' privacy statement and then click the checkbox!");
		document.getElementById("chk2").focus();
		return false;
   }

	document.forms[0].submit();
	return true;
}

function CountDoorQuantity()
{
	var Door_Quantity_Total = 0;
	var Door_Draw_Quantity = parseInt(document.getElementById("Door_Draw_Count").value);

	for (i = 1; i <= Door_Draw_Quantity; i++)
	{
		if (isNaN(document.getElementById("Door_Quantity_" + i.toString()).value))
		{
			alert(document.getElementById("Door_Quantity_" + i.toString()).value + " is not a number!");
			//document.getElementById("Door_Quantity_" + i.toString()).focus();
			return;
		}
		else if (document.getElementById("Door_Quantity_" + i.toString()).value != "")
			Door_Quantity_Total += parseInt(document.getElementById("Door_Quantity_" + i.toString()).value);
	}
	
	document.getElementById("Door_Quantity_Total").value = Door_Quantity_Total.toString();
}

function CountDrawerQuantity()
{
	var Drawer_Quantity_Total = 0;
	var Door_Draw_Quantity = parseInt(document.getElementById("Door_Draw_Count").value);
	
	for (i = 1; i <= Door_Draw_Quantity; i++)
	{
		if (isNaN(document.getElementById("Drawer_Quantity_" + i.toString()).value))
		{
			alert(document.getElementById("Drawer_Quantity_" + i.toString()).value + " is not a number!");
			//document.getElementById("Drawer_Quantity_" + i.toString()).focus();
			return;
		}
		else if (document.getElementById("Drawer_Quantity_" + i.toString()).value != "")
			Drawer_Quantity_Total += parseInt(document.getElementById("Drawer_Quantity_" + i.toString()).value);
	}
	document.getElementById("Drawer_Quantity_Total").value = Drawer_Quantity_Total.toString();
}

function CountFrameQuantity()
{
	var Frame_Quantity_Total = 0;
	var Frame_Quantity = parseInt(document.getElementById("Frame_Count").value);

	for (i = 1; i <= Frame_Quantity; i++)
	{
		if (isNaN(document.getElementById("Frame_Quantity_" + i.toString()).value))
		{
			alert(document.getElementById("Frame_Quantity_" + i.toString()).value + " is not a number!");
			return;
		}
		else if (document.getElementById("Frame_Quantity_" + i.toString()).value != "")
			Frame_Quantity_Total += parseInt(document.getElementById("Frame_Quantity_" + i.toString()).value);
	}
	
	document.getElementById("Frame_Quantity_Total").value = Frame_Quantity_Total.toString();
}

function CountPanelQuantity()
{
	var Panel_Quantity_Total = 0;
	var Panel_Quantity = parseInt(document.getElementById("Panel_Count").value);

	for (i = 1; i <= Panel_Quantity; i++)
	{
		if (isNaN(document.getElementById("Panel_Quantity_" + i.toString()).value))
		{
			alert(document.getElementById("Panel_Quantity_" + i.toString()).value + " is not a number!");
			return;
		}
		else if (document.getElementById("Panel_Quantity_" + i.toString()).value != "")
			Panel_Quantity_Total += parseInt(document.getElementById("Panel_Quantity_" + i.toString()).value);
	}
	
	document.getElementById("Panel_Quantity_Total").value = Panel_Quantity_Total.toString();
}

function checkPhone1()
{
	if (document.getElementById("txtTel1").value.length >= 3)
		document.getElementById("txtTel2").focus();
}

function checkPhone2()
{
	if (document.getElementById("txtTel2").value.length >= 3)
		document.getElementById("txtTel3").focus();
}

function checkPhone3()
{
	if (document.getElementById("txtTel3").value.length >= 4)
		document.getElementById("txtStreet1").focus();
}

function checkFax1()
{
	if (document.getElementById("txtFax1").value.length >= 3)
		document.getElementById("txtFax2").focus();
}

function checkFax2()
{
	if (document.getElementById("txtFax2").value.length >= 3)
		document.getElementById("txtFax3").focus();
}

function checkFax3()
{
	if (document.getElementById("txtFax3").value.length >= 4)
		document.getElementById("txtStreet2").focus();
}

function AddTbl1Tr()
{
	var tr, td, cb, tbl;
    var CurCount = parseInt(document.getElementById("Door_Draw_Count").value);

	CurCount = CurCount + 1;
	tbl = document.getElementsByTagName("tbody")[6];

	//tbl = document.getElementsByTagID("table1");
	tr = document.createElement("tr");
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' id='Door_Width_'" + CurCount.toString() + " name='Door_Width_'" + CurCount.toString() + " class='DoorDrawerRegularInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild (td);
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' id='Door_Height_'" + CurCount.toString() + " name='Door_Height_'" + CurCount.toString() + " class='DoorDrawerRegularInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);

	td = document.createElement("td");
	cb = document.createElement("<input type='text' id='Door_Quantity_'" + CurCount.toString() + " name='Door_Quantity_'" + CurCount.toString() + " class='DoorDrawerRegularInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' id='Drawer_Width_'" + CurCount.toString() + " name='Drawer_Width_'" + CurCount.toString() + " class='DoorDrawerRegularInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' id='Drawer_Height_'" + CurCount.toString() + " name='Drawer_Height_'" + CurCount.toString() + " class='DoorDrawerRegularInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' id='Drawer_Quantity_'" + CurCount.toString() + " name='Drawer_Quantity_'" + CurCount.toString() + " class='DoorDrawerRegularInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);
	
	td = document.createElement("td");
	td.setAttribute("colspan", "2");
	cb = document.createElement("<input type='text' id='Drawer_Notes_'" + CurCount.toString() + " name='Drawer_Notes_'" + CurCount.toString() + " class='DoorDrawerRegularNotes' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	tbl.appendChild(tr);
	document.getElementById("Door_Draw_Count").value = CurCount.toString();
}
    
function RemoveTbl1Tr()
{
	var tbl;
	var CurCount = parseInt(document.getElementById("Door_Draw_Count").value);
    if (CurCount > 1)
	{
		tbl = document.getElementsByTagName("tbody")[6];
		//tbl = document.getElementsByTagName("tbody")[6];
		tbl.removeChild(tbl.lastChild);
		CurCount = CurCount - 1;
		document.getElementById("Door_Draw_Count").value = CurCount.toString();
	}
}

function AddTbl2Tr()
{
	var tr, td, cb, tbl;
    var CurCount = parseInt(document.getElementById("Frame_Count").value);
	CurCount = CurCount + 1;
	//tbl = document.getElementsByTagName("table")[8];
	tbl = document.getElementsByTagName("tbody")[8];
	tr = document.createElement("tr");
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' name='Frame_Width'" + CurCount.toString() + " class='FrameWHLInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild (td);
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' name='Frame_Height'" + CurCount.toString() + " class='FrameWHLInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);

	td = document.createElement("td");
	cb = document.createElement("<input type='text' name='Frame_Lites'" + CurCount.toString() + " class='FrameWHLInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' name='Frame_Quantity'" + CurCount.toString() + " class='DoorDrawerRegularInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);

	td = document.createElement("td");
	cb = document.createElement("<input type='text' name='Frame_Notes'" + CurCount.toString() + " class='DoorDrawerRegularNotes' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	tbl.appendChild(tr);
	document.getElementById("Frame_Count").value = CurCount.toString();
}

function RemoveTbl2Tr()
{
	var tbl;
	var CurCount = parseInt(document.getElementById("Frame_Count").value);
    if (CurCount > 1)
	{
		//tbl = document.getElementsByTagName("table")[8];
		tbl = document.getElementsByTagName("tbody")[8];
		tbl.removeChild(tbl.lastChild);
		CurCount = CurCount - 1;

		document.getElementById("Frame_Count").value = CurCount.toString();
	}
}

function AddTbl3Tr()
{
	var tr, td, cb, tbl;
    var CurCount = parseInt(document.getElementById("Panel_Count").value);
	CurCount = CurCount + 1;
	//tbl = document.getElementsByTagName("table")[11];
	tbl = document.getElementsByTagName("tbody")[11];
	tr = document.createElement("tr");
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' name='Panel_Part'" + CurCount.toString() + " class='FrameWHLInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild (td);
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' name='Panel_Width'" + CurCount.toString() + " class='FrameWHLInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);

	td = document.createElement("td");
	cb = document.createElement("<input type='text' name='Panel_Height'" + CurCount.toString() + " class='FrameWHLInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);
	
	td = document.createElement("td");
	cb = document.createElement("<input type='text' name='Panel_Quantity'" + CurCount.toString() + " class='DoorDrawerRegularInputBox' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	td = document.createElement("td");
	tr.appendChild(td);

	td = document.createElement("td");
	cb = document.createElement("<input type='text' name='Panel_Notes'" + CurCount.toString() + " class='DoorDrawerRegularNotes' />");
	td.appendChild(cb);
	tr.appendChild(td);
	
	tbl.appendChild(tr);
	document.getElementById("Panel_Count").value = CurCount.toString();
}

function RemoveTbl3Tr()
{
	var tbl;
	var CurCount = parseInt(document.getElementById("Panel_Count").value);
    if (CurCount > 1)
	{
		//tbl = document.getElementsByTagName("table")[11];
		tbl = document.getElementsByTagName("tbody")[11];
		tbl.removeChild(tbl.lastChild);
		CurCount = CurCount - 1;

		document.getElementById("Panel_Count").value = CurCount.toString();
	}
}



