
function alertWin(x, err) {
	h = eval("'height=" + (220 + (x * 10)) + ",width=380'");
	detail=open("","Alert",h);
	detail.document.writeln("<html>\n<title>Alert</title>");
	detail.document.writeln("\n<body bgcolor='#ffffff'>\n<font face='verdana,arial' size=2 color=#5f8cc7><b>Errors:</b></font>\n<br>");
	detail.document.writeln("\n<font face='verdana,arial' size=1 color=#000000><b>The following fields are required:</b></font>\n<p>");
	detail.document.writeln("\n<font face='verdana,arial,sans-serif' size='2'>")
		for (i = 0; i < x; i++){
			detail.document.write((i+1) + "." + err[i] + "<br>\n");
		}
	detail.document.writeln("</font>")
	detail.document.write("\n<form>\n<input type='button' value='close window'" + "onClick='self.close()'>" + "\n</form>" + "\n</body>\n</html>");
}
function isValidForm1(theForm) {
	var err = new Array();
	var x=0;

  if (theForm.ShipFirstName.value == "")
  {
    err[x] = " Please enter a value for the \"first name\" field.";
    x=x+1

  }

  if (theForm.ShipFirstName.value.length < 2)
  {
    err[x] = " Please enter at least 2 characters in the \"first name\" field.";
    theForm.ShipFirstName.focus();
    x=x+1
  }

  if (theForm.ShipFirstName.value.length > 25)
  {
    err[x] = " Please enter at most 25 characters in the \"first name\" field.";
    theForm.ShipFirstName.focus();
    x=x+1
  }

  if (theForm.ShipLastName.value == "")
  {
    err[x] = " Please enter a value for the \"last name\" field.";
    theForm.ShipLastName.focus();
    x=x+1
  }

  if (theForm.ShipLastName.value.length < 2)
  {
    err[x] = " Please enter at least 2 characters in the \"last name\" field.";
    theForm.ShipLastName.focus();
    x=x+1
  }

  if (theForm.ShipLastName.value.length > 50)
  {
    err[x] = " Please enter at most 50 characters in the \"last name\" field.";
    theForm.ShipLastName.focus();
    x=x+1
  }
  
  ///////////////////////////
  if (theForm.BillLastName.value == "")
  {
    err[x] = " Please enter a value for the \"last name\" field.";
    theForm.BillLastName.focus();
    x=x+1
  }

  if (theForm.BillLastName.value.length < 2)
  {
    err[x] = " Please enter at least 2 characters in the \"last name\" field.";
    theForm.BillLastName.focus();
    x=x+1
  }

  if (theForm.BillLastName.value.length > 50)
  {
    err[x] = " Please enter at most 50 characters in the \"last name\" field.";
    theForm.BillLastName.focus();
    x=x+1
  }

  if (theForm.ShipEmail.value == "" || 
		theForm.ShipEmail.value.indexOf('@', 0) == -1 ||
		theForm.ShipEmail.value.indexOf('.', 0) == -1){
		err[x] = " Valid email address.";
		x = x + 1;
	}

///
if (theForm.BillEmail.value == "" || 
		theForm.BillEmail.value.indexOf('@', 0) == -1 ||
		theForm.BillEmail.value.indexOf('.', 0) == -1){
		err[x] = " Valid email address.";
		x = x + 1;
	}

  
  if (theForm.BillAddress.value == "")
  {
    err[x] = " Please enter a value for the \"Bill Address\" field.";
    theForm.BillAddress.focus();
    x=x+1
  }

  if (theForm.BillAddress.value.length < 5)
  {
    err[x] = " Please enter at least 5 characters in the \"Bill Address\" field.";
    theForm.BillAddress.focus();
    x=x+1
  }

  if (theForm.BillAddress.value.length > 250)
  {
    err[x] = " Please enter at most 250 characters in the \"Bill Address\" field.";
    theForm.BillAddress.focus();
    x=x+1
  }

  if (theForm.BillCity.value == "")
  {
    err[x] = " Please enter a value for the \"bill city\" field.";
    theForm.BillCity.focus();
    x=x+1
  }

  if (theForm.BillCity.value.length < 2)
  {
    err[x] = " Please enter at least 2 characters in the \"bill city\" field.";
    theForm.BillCity.focus();
    x=x+1
  }

  if (theForm.BillCity.value.length > 50)
  {
    err[x] = " Please enter at most 50 characters in the \"bill city\" field.";
    theForm.BillCity.focus();
    x=x+1
  }

  if (theForm.BillStateSelect.value == "")
  {
	if (theForm.BillState.value == "") {
		err[x] = " Please enter a value for the \"either the bill state or other state\" fields.";
		theForm.BillStateSelect.focus();
		x=x+1
	}
  }
  
  if (theForm.ShipStateSelect.value == "")
  {
	if (theForm.ShipState.value == "") {
		err[x] = " Please enter a value for the \"either the ship state or other state\" fields.";
		theForm.ShipStateSelect.focus();
		x=x+1
	}
  }

  if (theForm.BillZip.value == "")
  {
    err[x] = " Please enter a value for the \"bill zip\" field.";
    theForm.BillZip.focus();
    x=x+1
  }

if (theForm.ShipCountry.value == "")
  {
    err[x] = " Please enter a value for the \"Ship Country\" field.";
    theForm.ShipCountry.focus();
    x=x+1
  }

if (theForm.BillCountry.value == "")
  {
    err[x] = " Please enter a value for the \"Bill Country\" field.";
    theForm.BillCountry.focus();
    x=x+1
  }

  if (theForm.BillZip.value.length < 3)
  {
    err[x] = " Please enter at least 3 characters in the \"bill zip\" field.";
    theForm.BillZip.focus();
    x=x+1
  }

  if (theForm.BillZip.value.length > 10)
  {
    err[x] = " Please enter at most 10 characters in the \"bill zip\" field.";
    theForm.BillZip.focus();
    x=x+1
  }

  if (theForm.BillPhone.value == "")
  {
    err[x] = " Please enter a value for the \"bill phone\" field.";
    theForm.BillPhone.focus();
    x=x+1
  }

  if (theForm.BillPhone.value.length < 10)
  {
    err[x] = " Please enter at least 10 characters in the \"bill phone\" field.";
    theForm.BillPhone.focus();
    x=x+1
  }

  if (theForm.BillFirstName.value == "")
  {
    err[x] = " Please enter a value for the \"Bill First Name\" field.";
    theForm.BillFirstName.focus();
    x=x+1
  }

  if (theForm.BillFirstName.value.length < 2)
  {
    err[x] = " Please enter at least 2 characters in the \"Bill First Name\" field.";
    theForm.BillFirstName.focus();
    x=x+1
  }

  if (theForm.BillFirstName.value.length > 50)
  {
    err[x] = " Please enter at most 50 characters in the \"ship attn\" field.";
    theForm.BillFirstName.focus();
    x=x+1
  }

  if (theForm.ShipAddress.value == "")
  {
    err[x] = " Please enter a value for the \"ship address\" field.";
    theForm.ShipAddress.focus();
    x=x+1
  }

  if (theForm.ShipAddress.value.length < 5)
  {
    err[x] = " Please enter at least 5 characters in the \"ship address\" field.";
    theForm.ShipAddress.focus();
    x=x+1
  }

  if (theForm.ShipAddress.value.length > 250)
  {
    err[x] = " Please enter at most 250 characters in the \"ship address\" field.";
    theForm.ShipAddress.focus();
    x=x+1
  }

  if (theForm.ShipCity.value == "")
  {
    err[x] = " Please enter a value for the \"ship city\" field.";
    theForm.ShipCity.focus();
    x=x+1
  }

  if (theForm.ShipCity.value.length < 2)
  {
    err[x] = " Please enter at least 2 characters in the \"ship city\" field.";
    theForm.ShipCity.focus();
    x=x+1
  }

  if (theForm.ShipCity.value.length > 50)
  {
    err[x] = " Please enter at most 50 characters in the \"ship city\" field.";
    theForm.ShipCity.focus();
    x=x+1
  }

  
  
  if (theForm.source.value == "")
  {
    err[x] = " Please enter a value for the \"How Did You Hear\" field.";
    theForm.source.focus();
    x=x+1
  }

  

  if (theForm.ShipZip.value == "")
  {
    err[x] = " Please enter a value for the \"ship zip\" field.";
    theForm.ShipZip.focus();
    x=x+1
  }

  if (theForm.ShipZip.value.length < 3)
  {
    err[x] = " Please enter at least 3 characters in the \"ship zip\" field.";
    theForm.ShipZip.focus();
    x=x+1
  }

  if (theForm.ShipZip.value.length > 9)
  {
    err[x] = " Please enter at most 9 characters in the \"ship zip\" field.";
    theForm.ShipZip.focus();
    x=x+1
  }

  if (theForm.ShipPhone.value == "")
  {
    err[x] = " Please enter a value for the \"ship phone\" field.";
    theForm.ShipPhone.focus();
    x=x+1
  }

  if (theForm.ShipPhone.value.length < 10)
  {
    err[x] = " Please enter at least 10 characters in the \"ship phone\" field.";
    theForm.ShipPhone.focus();
    x=x+1
  }

  if (x > 0){
		alertWin(x, err);
		//return false;
	}

	else {
		theForm.submit();
	}
}


function isValidForm2() {
	document.step2.submit();
}
//no credit card collection, AJC
function isValidForm2_noCC_AJC() {
	var err = new Array();
	var x=0
		if (document.step2.cctype.value == ""){
			err[x] = " Please select the credit card type from the menu.";
			x = x + 1;
		}
		if (document.step2.ccnumber.value == ""){
			err[x] = " Please enter a valid credit card number.";
			x = x + 1;
		}
//		alert(document.step2.ccnumber.value);
		if (document.step2.cctype.value == "AmericanExpress"){
			if (document.step2.ccnumber.value.length < 15) {
				err[x] = " American Express cards have 15 digits.  Please enter only 15 digits with no spaces or dashes.";
				x = x + 1;
			}
			if (document.step2.ccnumber.value.length > 17) {
				err[x] = " American Express cards have 15 digits.  Please enter only 15 digits with no spaces or dashes.";
				x = x + 1;
			}
		}
		
		else {
			if (document.step2.ccnumber.value.length < 16) {
				err[x] = " Visa, Mastercard and Discover cards have 16 digits.  Please enter only 16 digits with no spaces or dashes.";
				x = x + 1;
			}
			if (document.step2.ccnumber.value.length > 19) {
				err[x] = " Visa, Mastercard and Discover cards have 16 digits.  Please enter only 16 digits with no spaces or dashes.";
				x = x + 1;
			}
		}
		
		
		if (document.step2.expdate.value == ""){
			err[x] = " Please enter the expiration date of the credit card.";
			x = x + 1;
		}
		
		
	if (x > 0){
		alertWin(x, err);
		//return false;
	}
	else {
		document.step2.submit();
	}
}

function CopyValues() {
	if (document.form1.shipinfo.checked == true) {
		document.form1.BillFirstName.value=document.form1.ShipFirstName.value;
		document.form1.BillLastName.value=document.form1.ShipLastName.value;
		document.form1.BillEmail.value=document.form1.ShipEmail.value;
		document.form1.BillCompany.value=document.form1.ShipCompany.value;
		document.form1.BillAddress.value=document.form1.ShipAddress.value;
		document.form1.BillAddress2.value=document.form1.ShipAddress2.value;
		document.form1.BillCity.value=document.form1.ShipCity.value;
		document.form1.BillStateSelect.value=document.form1.ShipStateSelect.value;
		document.form1.BillState.value=document.form1.ShipState.value;
		document.form1.BillZip.value=document.form1.ShipZip.value;
		document.form1.BillCountry.value=document.form1.ShipCountry.value;
		document.form1.BillFax.value=document.form1.ShipFax.value;
		document.form1.BillPhone.value=document.form1.ShipPhone.value;
		
	}
	else {
		document.form1.BillFirstName.value= '';
		document.form1.BillLastName.value='';
		document.form1.BillEmail.value='';
		document.form1.BillCompany.value='';
		document.form1.BillAddress.value='';
		document.form1.BillAddress2.value='';
		document.form1.BillCity.value='';
		document.form1.BillStateSelect.value='';
		document.form1.BillState.value='';
		document.form1.BillZip.value='';
		document.form1.BillCountry.value='';
		document.form1.BillFax.value='';
		document.form1.BillPhone.value='';
	}
}
