function ClearFields()
{
	document.RegistrationForm.reset();
	return false;
}

function SubmitForm()
{
	var count = 0;
	
	if(!IsEmail(document.RegistrationForm.txtEmail,'ErrorMail'))
		count++;
	if(!IsValid(document.RegistrationForm.txtUser,'ErrorUser'))
		count++;
	if(!IsValid(document.RegistrationForm.txtpwd,'ErrorPwd'))
		count++;
	if(!IsValid(document.RegistrationForm.txtConfirm,'ErrorConfirmPwd'))
		count++;
	if(!IsSame(document.RegistrationForm.txtConfirm,'ErrorConfirmPwd'))
		count++;
	if(!IsValid(document.RegistrationForm.txtCompany,'ErrorCompany'))
		count++;
	if(!IsValid(document.RegistrationForm.txtFname,'ErrorFname'))
		count++;
	if(!IsValid(document.RegistrationForm.txtLname,'ErrorLast'))
		count++;
	if(!IsValid(document.RegistrationForm.txtAdd1,'ErrorAdd1'))
		count++;
	if(!IsValid(document.RegistrationForm.txtCity,'ErrorCity'))
		count++;
	if(!IsValid(document.RegistrationForm.State1,'ErrorState'))
		count++;
	if(!IsValid(document.RegistrationForm.txtPostal,'ErrorPostal'))
		count++;
	if(!IsValid(document.RegistrationForm.Country1,'ErrorCountry'))
		count++;
	if(!IsNumber(document.RegistrationForm.txtPhone1,'ErrorPhone1'))
		count++;
	if(!IsEmpty(document.RegistrationForm.txtCompany1,'ErrorCompany1'))
		count++;
	if(!IsEmpty(document.RegistrationForm.txtFname1,'ErrorFname1'))
		count++;
	if(!IsEmpty(document.RegistrationForm.txtLname1,'ErrorLast1'))
		count++;
	if(!IsEmpty(document.RegistrationForm.txtAdd11,'ErrorAdd11'))
		count++;
	if(!IsEmpty(document.RegistrationForm.txtCity1,'ErrorCity1'))
		count++;
	if(!IsEmpty(document.RegistrationForm.State2,'ErrorState1'))
		count++;
	if(!IsEmpty(document.RegistrationForm.txtPostal1,'ErrorPostal1'))
		count++;
	if(!IsEmpty(document.RegistrationForm.Country2,'ErrorCountry1'))
		count++;
	if(count > 0)
		return false;
	else
	{
		document.RegistrationForm.submit();
		return true;
	}
}

function IsValid(Field, error)
{
	var Error = document.getElementById(error);
	if(Field.value == "")
	{
		Error.innerHTML = "<span style='color:#FF0000;'>Error: Invalid Data</span>";
		return false;
	}
	return true;
}

function IsSame(Field, error)
{
	var Error = document.getElementById(error);
	if(IsValid(Field, error))
	{
		if(RegistrationForm.txtpwd.value != Field.value)
		{
			Error.innerHTML = "<span style='color:#FF0000;'>Error: Passwords Mismatch</span>";
			return false;
		}
		return true;
	}
}

function IsNumber(Field, error)
{
	var Error = document.getElementById(error);
	if(IsValid(Field, error))
	{
		if(/^(0|[1-9][0-9]*)$/.test(Field.value))
		{
			return true;
		}
		else
		{
			Error.innerHTML = "<span style='color:#FF0000;'>Error: Phone Number must be in Numbers</span>";
			return false;
		}
	}
	return false;
}

function IsEmpty(Field, error)
{
	if(!document.RegistrationForm.chkship.checked)
	{
		return IsValid(Field, error);
	}
	return true;
}

function OnFocus(error)
{
	var Error = document.getElementById(error);
	Error.innerHTML = "&nbsp;";
}

function ValidateQuote()
{	
	if(QuoteOrder.Email.value == "")
	{
		alert("Invalid Email Address");
		return false;
	}
	var str = document.QuoteOrder.Email.value;
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	{
	   alert("Invalid Email Address");
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid Email Address");
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		alert("Invalid Email Address");
	    return false;
	}
	if (str.indexOf(at,(lat+1))!=-1)
	{
		alert("Invalid Email Address");
	    return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		alert("Invalid Email Address");
	    return false;
	}
	if (str.indexOf(dot,(lat+2))==-1)
	{
		alert("Invalid Email Address");
	    return false;
	}
	if (str.indexOf(" ")!=-1)
	{
		alert("Invalid Email Address");
	    return false;
	}
	return true;
}

function IsEmail(Field, error) 
{
		if(IsValid(Field, error))
		{				   
		var ob = document.getElementById(error);
		var str = Field.value;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1)
		{
		   ob.innerHTML = "<span style='color:#FF0000;'>Error: Invalid Email</span>";
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   ob.innerHTML = "<span style='color:#FF0000;'>Error: Invalid Email</span>";
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			ob.innerHTML = "<span style='color:#FF0000;'>Error: Invalid Email</span>";
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			 ob.innerHTML = "<span style='color:#FF0000;'>Error: Invalid Email</span>";
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			 ob.innerHTML = "<span style='color:#FF0000;'>Error: Invalid Email</span>";
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			 ob.innerHTML = "<span style='color:#FF0000;'>Error: Invalid Email</span>";
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
			 ob.innerHTML = "<span style='color:#FF0000;'>Error: Invalid Email</span>";
		    return false;
		 }
		ob.innerHTML = "<span style='color:#00FF00;'>Email is Valid</span>";
 		 return true;				
		}
	}
	
	
	function ChangeBack(p)
	{
		p.style.background = "url(images/MenuBackHover.jpg) repeat-x";
	}
	
	function ChangeBackNormal(p)
	{
		p.style.background = "url(images/MenuBackNormal.jpg) repeat-x";
	}
	
	function SubmitQuote()
	{
		document.QuoteOrder.Layer1.value = document.QuoteOrder.Layer.value;
		document.QuoteOrder.Material1.value = document.QuoteOrder.Material.value;
		document.QuoteOrder.Thickness1.value = document.QuoteOrder.Thickness.value;
		document.QuoteOrder.SMTSide1.value = document.QuoteOrder.SMTSide.value;
		document.QuoteOrder.SMTPitch1.value =document.QuoteOrder.SMTPitch.value;
		document.QuoteOrder.MaskSides1.value = document.QuoteOrder.MaskSides.value;
		document.QuoteOrder.SilkScreen1.value = document.QuoteOrder.SilkScreen.value;
		document.QuoteOrder.SMDPad1.value = document.QuoteOrder.SMDPad.value;
		document.QuoteOrder.FinishPlating1.value = document.QuoteOrder.FinishPlating.value;
		document.QuoteOrder.ApproxHoles1.value = document.QuoteOrder.ApproxHoles.value;
		document.QuoteOrder.Slots1.value = document.QuoteOrder.Slots.value;
		document.QuoteOrder.CopperWeight1.value = document.QuoteOrder.CopperWeight.value;
		document.QuoteOrder.MinimumHole1.value = document.QuoteOrder.MinimumHole.value;
		document.QuoteOrder.GoldFingers1.value = document.QuoteOrder.GoldFingers.value;
		document.QuoteOrder.TraceSpace1.value = document.QuoteOrder.TraceSpace.value;
		document.QuoteOrder.Quantity11.value = document.QuoteOrder.Quantity1.value;
		document.QuoteOrder.Quantity21.value = document.QuoteOrder.Quantity2.value;
		document.QuoteOrder.Quantity31.value = document.QuoteOrder.Quantity3.value;
		document.QuoteOrder.Quantity41.value = document.QuoteOrder.Quantity4.value;
		document.QuoteOrder.Quantity51.value = document.QuoteOrder.Quantity5.value;
		document.QuoteOrder.Quantity61.value = document.QuoteOrder.Quantity6.value;
		document.QuoteOrder.Quantity71.value = document.QuoteOrder.Quantity7.value;
		document.QuoteOrder.Quantity81.value = document.QuoteOrder.Quantity8.value;
		
		if(type == "")
		{
		  if(document.QuoteOrder.PartNo.value == "")
		  {
			  alert("Please Enter a Value for Part Number","Fine Circuits Inc.");
			  document.QuoteOrder.PartNo.focus();
			  return false;
		  }
		  
		  if(document.QuoteOrder.Layer.value == "")
		  {
			  alert("Please select appropriate Layer Value");
			  document.QuoteOrder.Layer.focus();
			  return false;
		  }
		  
		  if(document.QuoteOrder.ApproxHoles.value == "")
		  {
			  alert("Please Enter a value for \"Approximate Number of Holes\" Field.");
			  document.QuoteOrder.ApproxHoles.focus();
			  return false;
		  }
		  
		  if(parseInt(document.QuoteOrder.ApproxHoles.value) > 5000)
		  {
			  alert("Approximate Number of Holes should not exceed 5000");
			  document.QuoteOrder.ApproxHoles.focus();
			  return false;
		  }
		  
		  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.SMDPad.value)))
		  {
			  alert("\"SMD Pad\" is a Numeric Value.");
			  document.QuoteOrder.SMDPad.focus();
			  return false;
		  }
		  
		  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.GoldFingers.value)))
		  {
			  alert("\"GoldFingers\" is a Numeric Value.");
			  document.QuoteOrder.GoldFingers.focus();
			  return false;
		  }
		  
		  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.ApproxHoles.value)))
		  {
			  alert("\"Approximate Number of Holes\" is a Numeric Value.");
			  document.QuoteOrder.ApproxHoles.focus();
			  return false;
		  }
		  
		  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.Slots.value)))
		  {
			  alert("\"Cutout / Slots\" is a Numeric Value.");
			  document.QuoteOrder.Slots.focus();
			  return false;
		  }
		  
		  if(document.QuoteOrder.Width.value == "")
		  {
			  alert("Please Enter Board Dimension values");
			  document.QuoteOrder.Width.focus();
			  return false;
		  }
		  
		  if(!(/(^(0|[1-9][0-9]*)$)|((^(0?|[1-9][0-9]*)\.(0*[1-9][0-9]*)$)|(^[1-9]+[0-9]*\.0+$)|(^0\.0+$))/.test(document.QuoteOrder.Width.value)))
		  {
			  alert("\"Board width\" is a Numeric Value.");
			  document.QuoteOrder.Width.focus();
			  return false;
		  }
		  
		  if(document.QuoteOrder.Height.value == "")
		  {
			  alert("Please Enter Board Dimension values");
			  document.QuoteOrder.Height.focus();
			  return false;
		  }
		  
		  if(!(/(^(0|[1-9][0-9]*)$)|((^(0?|[1-9][0-9]*)\.(0*[1-9][0-9]*)$)|(^[1-9]+[0-9]*\.0+$)|(^0\.0+$))/.test(document.QuoteOrder.Height.value)))
		  {
			  alert("\"Board Height\" is a Numeric Value.");
			  document.QuoteOrder.Height.focus();
			  return false;
		  }
		  
		  var area = parseFloat(document.QuoteOrder.Height.value)* parseFloat(document.QuoteOrder.Width.value);
		  if(area <= 0.75)
		  {
			  alert("Invalid Dimensions.");
			  document.QuoteOrder.Width.focus();
			  return false;
		  }
		  
		  var layers = parseInt(document.QuoteOrder.Layer.value);
		  
		  if((layers <= 2) && (area > (16*18)))
		  {
			  alert("Invalid Dimensions for selected Layer.");
			  document.QuoteOrder.Layer.focus();
			  return false;	
		  }
		  
		  if(layers >= 3 && area > 12*16)
		  {
			  alert("Invalid Dimensions for selected Layer.");
			  document.QuoteOrder.Layer.focus();
			  return false;	
		  }
		  if(layers >= 6 && (document.QuoteOrder.CopperWeight.value=="3 oz" || document.QuoteOrder.CopperWeight.value=="4 oz" ))

		  {

			  alert("Invalid Copper Weight selected.");
			  document.QuoteOrder.CopperWeight1.focus();
			  return false;	
		  }
		  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.Quantity1.value)))
		  {
			  alert("Please Enter Quantity1 value in numbers");
			  document.QuoteOrder.Quantity1.focus();
			  return false;
		  }
		  
		  if(document.QuoteOrder.Quantity2.value.length > 0)
		  {
			  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.Quantity2.value)))
			  {
				  alert("Please Enter Quantity2 value in numbers");
				  document.QuoteOrder.Quantity2.focus();
				  return false;
			  }
		  }
		  
		  if(document.QuoteOrder.Quantity3.value.length > 0)
		  {
			  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.Quantity3.value)))
			  {
				  alert("Please Enter Quantity3 value in numbers");
				  document.QuoteOrder.Quantity3.focus();
				  return false;
			  }
		  }
		  
		  if(document.QuoteOrder.Quantity4.value.length > 0)
		  {
			  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.Quantity4.value)))
			  {
				  alert("Please Enter Quantity4 value in numbers");
				  document.QuoteOrder.Quantity4.focus();
				  return false;
			  }
		  }
		  
		  if(document.QuoteOrder.Quantity5.value.length > 0)
		  {
			  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.Quantity5.value)))
			  {
				  alert("Please Enter Quantity5 value in numbers");
				  document.QuoteOrder.Quantity5.focus();
				  return false;
			  }
		  }
		  
		  if(document.QuoteOrder.Quantity6.value.length > 0)
		  {
			  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.Quantity6.value)))
			  {
				  alert("Please Enter Quantity6 value in numbers");
				  document.QuoteOrder.Quantity6.focus();
				  return false;
			  }
		  }
		  
		  if(document.QuoteOrder.Quantity7.value.length > 0)
		  {
			  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.Quantity7.value)))
			  {
				  alert("Please Enter Quantity7 value in numbers");
				  document.QuoteOrder.Quantity7.focus();
				  return false;
			  }
		  }
		  
		  if(document.QuoteOrder.Quantity8.value.length > 0)
		  {
			  if(!(/^(0|[1-9][0-9]*)$/.test(document.QuoteOrder.Quantity8.value)))
			  {
				  alert("Please Enter Quantity8 value in numbers");
				  document.QuoteOrder.Quantity8.focus();
				  return false;
			  }
		  }
		  
		  return true;
		}
		else
		{
			  if(document.QuoteOrder.PartNo.value == "")
			  {
				  alert("Please Enter a Value for Part Number","Fine Circuits Inc.");
				  document.QuoteOrder.PartNo.focus();
				  return false;
			  }
			  if(document.QuoteOrder.Width.value == "")
			  {
				  alert("Please Enter Board Dimension values");
				  document.QuoteOrder.Width.focus();
				  return false;
			  }
			  
			  if(!(/(^(0|[1-9][0-9]*)$)|((^(0?|[1-9][0-9]*)\.(0*[1-9][0-9]*)$)|(^[1-9]+[0-9]*\.0+$)|(^0\.0+$))/.test(document.QuoteOrder.Width.value)))
			  {
				  alert("\"Board width\" is a Numeric Value.");
				  document.QuoteOrder.Width.focus();
				  return false;
			  }
			  
			  if(document.QuoteOrder.Height.value == "")
			  {
				  alert("Please Enter Board Dimension values");
				  document.QuoteOrder.Height.focus();
				  return false;
			  }
			  
			  if(!(/(^(0|[1-9][0-9]*)$)|((^(0?|[1-9][0-9]*)\.(0*[1-9][0-9]*)$)|(^[1-9]+[0-9]*\.0+$)|(^0\.0+$))/.test(document.QuoteOrder.Height.value)))
			  {
				  alert("\"Board Height\" is a Numeric Value.");
				  document.QuoteOrder.Height.focus();
				  return false;
			  }
			  
			  var area = parseFloat(document.QuoteOrder.Height.value)* parseFloat(document.QuoteOrder.Width.value);
			  if(area > 10)
			  {
				  alert("User cannot enter dimension more than 10 sq inch.");
				  document.QuoteOrder.Width.focus();
				  return false;
			  }
			  
			 // QuoteOrder.action = "PurchaseOrder.php?Unit=" + value + "&LeadTime=" + leadtime + "&Qty=1&Test=No&TestPrice=0&Tooling=90";
			  return true;
		}
	}
