function checkPassEmail()	{
	var ePat = /[\w\-]+\@[\w\-]+\.\w{2,3}/;

	if (!ePat.test(document.getElementById('dlr_email').value))	{
		alert("The email address you have entered appears to be incorrect, please check it and resubmit the form");
		return false;
		}
	}

function fillFormData()	{
	document.getElementById('creditAddy1').value = document.getElementById('dlr_address').value;
	document.getElementById('creditZipcode').value = document.getElementById('dlr_zipcode').value;
	document.getElementById('creditPhone').value = document.getElementById('dlr_areacode').value+"-"+document.getElementById('dlr_phone_1').value+"-"+document.getElementById('dlr_phone_2').value;
	}

function rightCCType()	{
	var cards = ["MC", "VS", "AM", "DS"];
	var firstNums = ["5", "4", "3", "6"];
	var goodfirst = false;
	loop :
	for (var x = 0 ; x < cards.length ; x++)	{
		if (document.getElementById('ccType').value == cards[x])	{
			if (document.getElementById('ccNum').value.substring(0, 1) == firstNums[x])	{
				goodfirst = true;
				break loop;
				}
			}
		}
	return goodfirst;
	}

function goodCreditCard(field) {
  var sum=0, mul=1, l=field.value.length;
  var digit, tproduct;

    for (var i=0; i<l; i++) {
      digit=field.value.substring(l-i-1,l-i);
      tproduct=parseInt(digit ,10)*mul;
      if (tproduct>=10) {
        sum+=(tproduct%10)+1;
		}
      else {
        sum+=tproduct;
		}

      if (mul==1) {
        mul++;
		}
      else {
        mul--;
      }
    }

    if ((sum%10)==0) {
      return true;
		}
    else {
      return false;
    }
}

function checkOuterContact()	{
	if (document.getElementById('custName').value.length < 4)	{
		alert("Please enter your name");
		document.getElementById('custName').focus();
		return false;
		}
	var emailPat = /[\w\-]+\@[\w\-]+\.\w{2,3}/;
	if (!emailPat.test(document.getElementById('custEmail').value))	{
		alert("The email addresss is either missing or you have typed it incorrectly.\n\nPlease verify it and resubmit the form");
		document.getElementById('custEmail').focus();
		return false;
		}
	if (document.getElementById('comments').value.length == 0 || document.getElementById('comments').value == 'Comments, Questions')	{
		alert("Please specify the comments, question or reason for this contact so we may help you");
		document.getElementById('comments').focus();
		return false;
		}
	}

function checkLogin(form)	 {
	if (form.username.value.length < 7)	 {
		alert("Please enter your username");
		form.username.focus();
		return false;
		}
	if (form.password.value.length < 6)	{
		alert("Please enter your password");
		form.password.focus();
		return false;
		}
	}

function checkConfirm(form)	{
	if (form.city.selectedIndex == 0)	 {
		alert("Please select your city from the drop down");
		form.city.focus();
		return false;
		}
	}

function highlightFields(myArray)	 {
	for (var x = 0 ; x < myArray.length ; x++)	{
		document.forms[0].myArray[x].style.backgroundColor = '#F9F11D';
		}
	}

/* function unhighlights fields once they move away from them */
function checkBgColor(myId)	 {
	document.getElementById(myId).style.backgroundColor = '#FFFFFF';
	}

function checkDealerSignForm(form)	{
	if (form.dlr_name.value.length < 5)	{
		alert("Please enter the dealership name");
		form.dlr_name.focus();
		return false;
		}
	if (form.dlr_address.value.length < 5)	{
		alert("Please enter the address of your dealership");
		form.dlr_address.focus();
		return false;
		}
	var zipTest = /\d{5}/;
	if (!zipTest.test(form.dlr_zipcode.value))	{
		alert("Please enter your 5 digit zipcode (digits only)");
		form.dlr_zipcode.focus();
		return false;
		}
	var phoneInfo = ["dlr_areacode", "dlr_phone_1", "dlr_phone_2"];
	var counter = 0;
	for (var x = 0 ; x < phoneInfo.length ; x++)	{
		var required = (x != 2) ? 3 : 4;
		var numPat = /\d+/;
		if (document.getElementById(phoneInfo[x]).value.length == required && numPat.test(document.getElementById(phoneInfo[x]).value))	{
			counter++;
			}
		}
	if (counter != 3)	{
		alert("Please enter your phone number with areacode (digits only)");
		form.dlr_areacode.focus();
		return false;
		}
	var emailPat = /[\w\-]+\@[\w\-]+\.\w{2,3}/;
	if (!emailPat.test(form.dlr_email.value))	{
		alert("The email addresss is either missing or you have typed it incorrectly.\n\nPlease verify it and resubmit the form");
		form.dlr_email.focus();
		return false;
		}
	if (form.dlr_license_no.value.length < 5 || form.dlr_license_state.selectedIndex == 0 || form.dlr_license_exp_month.selectedIndex == 0 || form.dlr_license_exp_year.selectedIndex == 0)	 {
		alert("For Your protection and to  allow us to verify your dealership the following information MUST be submitted:\n\nDealer license number\nState of issue\nLicense Expiration Month\nLicense Expiration year");
		form.dlr_license_no.focus();
		return false;
		}
	var today = new Date();
	var month = today.getMonth() + 1;
	var year = today.getFullYear();
	var formMonth = parseInt(form.dlr_license_exp_month.value);
	var formYear = parseInt(form.dlr_license_exp_year.value);
	if ((formMonth < month && formYear < year) || (formMonth < month && formYear == year))	{
		alert("It appears your state dealers license has expired. Please check the expiration date and resubmit the form.\n\nDealer licenses must be current and valid to complete your registration");
		form.dlr_license_exp_month.focus();
		return false;
		}
	if (!goodCreditCard(form.ccNum) || form.ccNum.value.length == 0)	{
		alert("The Credit Card number you have entered is invalid, please check it an resubmit the form");
		document.getElementById('ccNum').focus();
		return false;
		}
	if (document.getElementById('ccType').selectedIndex == 0)	{
		alert("Please selct your credit card type");
		document.getElementById('ccType').focus();
		return false;
		}
	if (!rightCCType())	{
		alert("The Credit Card Type you have selected does not match the number you have entered");
		document.getElementById('ccNum').focus();
		return false;
		}
	if (document.getElementById('expMonth').selectedIndex == 0)	{
		alert("Please enter the expiration MONTH of your credit card");
		document.getElementById('expMonth').focus();
		return false;
		}
	if (document.getElementById('expYear').selectedIndex == 0)	{
		alert("Please enter the expiration YEAR of your credit card");
		document.getElementById('expYear').focus();
		return false;
		}
	var today = new Date();
	var month = today.getMonth() + 1;
	var year = today.getFullYear();
	var ccMonth = parseInt(form.expMonth.value);
	var ccYear = parseInt(form.expYear.value);
	if ((ccMonth < month && ccYear < year) || (ccMonth < month && ccYear == year))	{
		alert("It appears your credit card has expired. Please check the expiration date and resubmit the form.");
		form.expMonth.focus();
		return false;
		}
	if (document.getElementById('credit_f_Name').value.length < 2)	{
		alert("Please enter your first name EXACTLY as it appears on your credit card");
		document.getElementById('credit_f_Name').focus();
		return false;
		}
	if (document.getElementById('credit_l_Name').value.length < 2)	{
		alert("Please enter your last name EXACTLY as it appears on your credit card");
		document.getElementById('credit_l_Name').focus();
		return false;
		}
	if (document.getElementById('creditAddy1').value.length < 5)	{
		alert("Please enter your billing address as it appears on your credit card statement");
		document.getElementById('creditAddy1').focus();
		return false;
		}
	if (document.getElementById('creditZipcode').value.length != 5)	{
		alert("Please enter your billing zipcode as it appears on your credit card statement");
		document.getElementById('creditZipcode').focus();
		return false;
		}
	var phonePat = /\d{3}\-\d{3}\-\d{4}/;
	if (!phonePat.test(document.getElementById('creditPhone').value))	 {
		alert("Please enter your billing phone number in xxx-xxx-xxxx format");
		document.getElementById('creditPhone').focus();
		return false;
		}
	if (!form.readTerms.checked)	{
		alert("All dealers must read and accept the terms of use for this website");
		form.readTerms.focus();
		return false;
		}
	}

function openPopup(url, width, height)	 {
	window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+width+",height="+height+",left=10,top=10");
	}

function openTermsPopup(url)	 {
	window.open(url,"terms","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=475,height=500,left=10,top=10");
	}
