<!--
function Validate(theform) {
	if (theform.first_name.value==""){
		alert("\nThe First Name field is blank.\n\nPlease enter your First Name.")
		theform.first_name.focus();
		return false
	}
	if (theform.last_name.value==""){
		alert("\nThe Last Name field is blank.\n\nPlease enter your Last Name.")
		theform.last_name.focus();
		return false
	}
	if (theform.address.value==""){
		alert("\nThe Address field is blank.\n\nPlease enter your Address.")
		theform.address.focus();
		return false
	}
	if (theform.city.value==""){
		alert("\nThe City field is blank.\n\nPlease enter your City.")
		theform.city.focus();
		return false
	}
	if (theform.state.value==""){
		alert("\nPlease enter your State.");
		theform.state.focus();
		return false;
	}
	var zipstr = theform.postal_code.value;
	var digits="0123456789-"
	if (zipstr==""){
		alert("\nThe Zip field is blank.\n\nPlease enter your Zip Code.");
		theform.postal_code.focus();
		return false;
	}
	if (zipstr.length < 5 || 10 < zipstr.length) {
		alert("\nPlease enter a valid Zip Code.");
		theform.postal_code.focus();
		return false;
	}
	for (var i = 0;i < zipstr.length;i++){
		temp = zipstr.substring(i,i+1)
		if (digits.indexOf(temp)==-1){
			alert("\nPlease enter a valid Zip Code.");
			return false;
		}
	}
	if(theform.email.value==""){
		alert("Please enter your Email Address.");
		theform.email.focus();
		return false;
	}else{
		if (theform.email.value.indexOf ('@',0) == -1 || theform.email.value.indexOf ('.',0) == -1) {
			alert("Invalid Email Address.\n\nPlease try again.");
			theform.email.select();
			return false;
		}	
	}
	
	var ssnstr = theform.ssn1.value;
	var ssndigits="0123456789"	
	if(ssnstr==""){
		alert("Please enter your Social Security Number.");
		theform.ssn1.focus();
		return false;
	}
	if(ssnstr.length!=3){
		alert("Please enter a valid Social Security Number.");
		theform.ssn1.focus();
		return false
	}
	for (var i = 0;i < ssnstr.length;i++){
		temp = ssnstr.substring(i,i+1)
		if (ssndigits.indexOf(temp)==-1){
			alert("Please enter a valid Social Security Number.");
			theform.ssn1.select();
			return false
		}
	}	
	var ssnstr = theform.ssn2.value;
	var ssndigits="0123456789"	
	if(ssnstr==""){
		alert("Please enter your Social Security Number.");
		theform.ssn2.focus();
		return false;
	}
	if(ssnstr.length!=2){
		alert("Please enter a valid Social Security Number.");
		theform.ssn2.focus();
		return false
	}
	for (var i = 0;i < ssnstr.length;i++){
		temp = ssnstr.substring(i,i+1)
		if (ssndigits.indexOf(temp)==-1){
			alert("Please enter a valid Social Security Number.");
			theform.ssn2.select();
			return false;
		}
	}	
	var ssnstr = theform.ssn3.value;
	var ssndigits="0123456789"	
	if(ssnstr==""){
		alert("Please enter your Social Security Number.");
		theform.ssn3.focus();
		return false;
	}
	if(ssnstr.length!=4){
		alert("Please enter a valid Social Security Number.");
		theform.ssn3.focus();
		return false;
	}
	for (var i = 0;i < ssnstr.length;i++){
		temp = ssnstr.substring(i,i+1)
		if (ssndigits.indexOf(temp)==-1){
			alert("Please enter a valid Social Security Number.");
			theform.ssn3.select();
			return false;
		}
	}	
	if(theform.birth_date.value==""){
		alert("Please enter your Birth Date.");
		theform.birth_date.focus();
		return false;
	}
//	if(theform.drivers_license_no.value==""){
//		alert("Please enter your Driver's License Number.");
//		theform.drivers_license_no.focus();
//		return false;
//	}
//	if(theform.drivers_license_state.value==""){
//		alert("Please enter your Driver's License Issuing State.");
//		theform.drivers_license_state.focus();
//		return false;
//	}
	if (theform.phone_no.value==""){
		alert("Please enter your Phone Number.");
		theform.phone_no.focus();
		return false;
	} else {
		var digits="0123456789()- "
		var strPhone = theform.phone_no.value;
		if(strPhone!=""){
			for (var i = 0;i < strPhone.length;i++){
				temp = strPhone.substring(i,i+1);
				if (digits.indexOf(temp)==-1){
					alert("\nPhone Number: Please enter your phone number in the format (###) ###-####.");
					theform.phone_no.focus();
					return false;
				}
			}
		}
	}
	if (theform.phone2_no.value!=""){
		var digits="0123456789()- ";
		var strPhone = theform.phone2_no.value;
		if(strPhone!=""){
			for (var i = 0;i < strPhone.length;i++){
				temp = strPhone.substring(i,i+1);
				if (digits.indexOf(temp)==-1){
					alert("\nPhone Number: Please enter your phone number in the format (###) ###-####.");
					theform.phone2_no.focus();
					return false;
				}
			}
		}
	}
	if(theform.user_name.value==""){
		alert("Please enter your User Name.");
		theform.user_name.focus();
		return false;
	}
	else{
		strUserName=theform.user_name.value;
		if(strUserName.length<4){
			alert("Your user name must be at least 4 characters.  Please try again.");
			theform.user_name.focus();
			return false;
		}
	}
	if(theform.user_password.value==""){
		alert("Please enter your Password.");
		theform.user_password.focus();
		return false;
	}
	else{
		strPassword=theform.user_password.value;
		if(strPassword.length<4){
			alert("Your Password must be at least 4 characters.  Please try again.");
			theform.user_password.focus();
			return false;
		}
	}
	strPassword2 = theform.user_password2.value;
	if(strPassword!=strPassword2){
		alert("You did not re-type your Password correctly.  Please try again.");
		theform.user_password2.focus();
		return false;
	}
	if (theform.bill_address.value==""){
		alert("\nPlease enter your Billing Address.");
		theform.bill_address.focus();
		return false;
	}
	if (theform.bill_city.value==""){
		alert("\nPlease enter your Billing City.");
		theform.bill_city.focus();
		return false;
	}
	if (theform.bill_state.value==""){
		alert("\nPlease enter your Billing State.");
		theform.bill_state.focus();
		return false;
	}
// Return false if characters are not '0-9' or '-' . 
	zipstr = theform.bill_postal_code.value;
	var digits="0123456789-";
	if (zipstr==""){
		alert("\nPlease enter the ship-to Zip Code.");
		theform.bill_postal_code.focus();
		return false;
	}
	if (zipstr.length < 5 || 10 < zipstr.length) {
		alert("\nPlease enter a valid Zip Code.");
		theform.bill_postal_code.focus();
		return false;
	}
	for (var i = 0;i < zipstr.length;i++){
		temp = zipstr.substring(i,i+1)
		if (digits.indexOf(temp)==-1){
			alert("\nPlease enter a valid Zip Code.");
			theform.bill_postal_code.focus();
			return false;
		}
	}

		var cardno = theform.cardNum.value;
		var cardtype = theform.cardtype.value;
		var cardname;
		
		if(theform.billing_name.value==""){
			alert("Please enter the Card Holder's Name");
			theform.billing_name.focus();
			return false;
		}
		
		if (theform.cardtype[0].selected) {
			cardtype="MC";
			cardname = "Master Card";
		}
		else if (theform.cardtype[1].selected) {
			cardtype = "VISA";
			cardname = "Visa";
		}
		else if (theform.cardtype[2].selected) {
			cardtype="AMEX";
			cardname = "American Express";
		}
		else if (theform.cardtype[3].selected) {
			cardtype="DISC";
			cardname = "Discover";
			if(theform.card_id.value==""){
				alert("Please enter your 3 digit Card Identification Number.");
				theform.card_id.focus();
				return false;
			}
		}
		var i;
		for (i = 0; i < theform.expmonth.length; i++)
			if (theform.expmonth[i].selected)
				var expmonth = theform.expmonth[i].value;
		for (i = 0; i < theform.expyear.length; i++)
			if (theform.expyear[i].selected)
				var expyear = theform.expyear[i].value;
		
		today = new Date();
		expiry = new Date(expyear, expmonth);
		if (today.getTime() > expiry.getTime()) {
			alert("You have entered an expired credit card.\n\n Please enter a new card.");
			theform.expmonth.focus();
			return false;
		}
		
	// alert("card no:" + cardno);

		errorStrings = new Array(
	      "", //0
	      "Invalid Credit Card", //1
	      "Invalid Credit Card", //2
	      "Invalid Credit Card", //3
	      "Invalid Credit Card", //4
	      "Invalid Credit Card", //5
	      "Invalid Credit Card", //6
	      "Invalid Credit Card", //7
	      "Invalid Credit Card", //8
	      "Invalid Credit Card", //9
	      "Number of digits must be greater than 12", //10
	      "Master Card prefix must be 5", //11
	      "Visa prefix must be 4", //12
	      "American Express prefix must be 34 or 37", //13
	      "Discover prefix must be 6011", //14
	      "Diner's Club/Carte Blanche prefix must be 36, 38, or 300-305", //15
	      "enRoute prefix must be 2014 or 2149", //16
	      "JCB prefix must be 3, 2131 or 1800", //17
	      "", //18
	      "", //19
	      "", //20
	      "Number of digits must be 16 for Master Card", //21
	      "Number of digits must be 13 or 16 for Visa", //22
	      "Number of digits must be 15 for American Express", //23
	      "Number of digits must be 16 for Discover ", //24
	      "Number of digits must be 14 for Diner's Club/Carte Blanche", //25
	      "Number of digits must be 15 for enRoute", //26
	      "Number of digits must be 16 for JCB with prefix of 3", //27
	      "Number of digits must be 15 for JCB with prefix of 2131 or 1800") //28

	//          if (cardtype == "") {
	//               alert("Please select a payment type");
	//               return false;
	//          }
			  if (cardno == "")  {
	               alert("Please enter your credit card number.");
	               theform.cardNum.focus();
	               return false;
	          }
			  if (nochars(cardno) == false) {
	               alert("Non-numeric credit card number is not allowed!\n\nPlease remove all spaces and dashes.");
								 theform.cardNum.focus();
	               return false;
			  }
	// alert("before checking number");
		    
	          if((reason = verify_ccard(cardno, cardtype)) == 0)
	          {
	//                return true;
	//				alert(cardtype);
	          }
	          else
	          {
	//                alert("Card Number Invalid.  Reason is " + errorStrings[reason]);
					alert("Invalid " + cardname + " Card Number.\n\nPlease Re-enter.");
					theform.cardNum.focus();
	                return false;
	          }

	if(theform.checkbox.checked) {
	}
	else {
		alert("You cannot continue until you agree to the Terms and Conditions of the Retainer Agreement.");
		return false;
	}
	var oSubmitButtons = document.all.tags("INPUT");
	var sElementType;

	for (var i = 0 ; i < oSubmitButtons.length ; i++){
		sElementType = oSubmitButtons[i].type.toLowerCase();

		if ((sElementType == "submit") || (sElementType == "image")){
	  	oSubmitButtons[i].disabled = true;
	 	}
	}
}

/* validate the card number and type */
function verify_ccard(inNumber, type)
{// returns 0 if valid, positive number if invalid.
        total = 1*0;
        tmp = 1*0;
        number = "";
//alert("Varify");
        // make sure there are only numbers in the string...
        for(i = 0; i < inNumber.length; i++)
        {
                if(inNumber.charAt(i) >= "0" && inNumber.charAt(i) <= "9")
                {
                        number = number + inNumber.charAt(i);
                }
        }

        if(number.length < 13) return 10; // too short for anything

        first = "" + number.charAt(0);
        second = "" + number.charAt(1);
        third = "" + number.charAt(2);
        firstTwo = first + second;
        firstFour = firstTwo + third + number.charAt(3);

        if(type == "MC")
        {
//                if(first != "5" || second < "1" || second > "5")
//                        return 11;// invalid Mastercard prefix
                if(first != "5")
                        return 11;// invalid Mastercard prefix
                if(number.length != 16)
                        return 21;
        }
        else if(type == "VISA" || type == "VIS")
        {
//		alert("you selected VISA");
                if(first != "4")
                        return 12;// invalid Visa prefix
                if(number.length != 13 && number.length != 16)
                        return 22;
        }
        else if(type == "AMEX" || type == "AMX")
        {
                if(first != "3" || (second != "4" && second != "7"))
                        return 13;// invalid American Express Prefix
                if(number.length != 15) 
                        return 23;
        }
        else if(type == "DISC" || type == "DIS")
        {
                        if(firstFour != "6011")
                                return 14;// invalid prefix.
                        if(number.length != 16)
                                return 24;
        }
        else if(type == "DCCB")
        {
                if(firstTwo != "36"
                        && firstTwo != "38"
                        && (firstTwo != "30" ||
                                (third < "0" || third > "5")))
                {
                        return 15;
                }
                if(number.length != 14)
                        return 25;
        }
        else if(type == "enRoute")
        {
                if(firstFour != "2014"
                        && firstFour != "2149")
                        return 16;// invalid enRoute card
                if(number.length != 15)
                        return 26;
                return 0; // no check sum calculation needed
        }
        else if(type == "JCB")
        {
                if(firstFour != "2131"
                        && firstFour != "1800"
                        && (first != "3") )
                        return 17;
                if(number.length != 16 && first =="3")
                        return 27;
                if(number.length != 15 && first != "3")
                        return 28;
        }
        // now check the credit card suffix and length vs. the type

    
         // do the check sum
        for(loc = number.length - 2; loc >= 0; loc -= 2)
        {
                total += 1 * number.charAt(loc +1);
                tmp = number.charAt(loc) * 2;
                if(tmp > 9) total += 1;
                total += tmp%10;
        }
        if(number.length % 2 > 0)
        total += 1 * number.charAt(0);


        return (total % 10);
}


/* nochars: check for the existence of a non int character within a string */
function nochars(strval) {

	var retval=true
	
//  alert("strval");

	for (var i=0; i<strval.length;i++) {
		if (strval.substring(i,i+1) < "0" || strval.substring(i,i+1) > "9") {
			retval=false
			break
		}
	}
	return retval
}


function UpdateBillAddress(form){
	if(form.UseAddress.checked){
		//set temp values
		bill_address = form.bill_address.value;
		bill_city = form.bill_city.value;
		bill_state = form.bill_state.value;
		bill_postal_code = form.bill_postal_code.value;
		
		form.bill_address.value = form.address.value;
		form.bill_city.value = form.city.value;
		form.bill_state.value = form.state.value;
		form.bill_postal_code.value = form.postal_code.value;
	}else{
		form.bill_address.value = bill_address;
		form.bill_city.value = bill_city;
		form.bill_state.value = bill_state;
		form.bill_postal_code.value = bill_postal_code;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
