/*// non-empty textbox
function checkComment(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You didn't enter a comment.\n"
  }
return error;	  
}*/
// name - 4-10 chars, uc, lc, and underscore only. **************************************************************************

function checkFName (strng) {
var error = "";

    var illegalChars = /\W\ /; // allow letters, numbers, and underscores
    if ((strng.length < 2)) {
       error = "Your name is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "Your name contains illegal characters.\n";
    } 
	
if (strng == "") {
   error = "You didn't enter a name.\n";
}	
return error;
}

// surname - 4-10 chars, uc, lc, and underscore only. **************************************************************************

function checkLName (strng) {
var error = "";

    var illegalChars = /\W\ /; // allow letters, numbers, and underscores
    if ((strng.length < 2)) {
       error = "Your surname is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "Your surname contains illegal characters.\n";
    } 
	
if (strng == "") {
   error = "You didn't enter a surname.\n";
}	
return error;
}

// company name - 4-10 chars, uc, lc, and underscore only. **************************************************************************

function checkCompany (strng) {
var error = "";

    var illegalChars = /\W\ /; // allow letters, numbers, and underscores
    if ((strng.length < 2)) {
       error = "Your company name needs to be at least 2 letters.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "Your company name contains illegal characters.\n";
    } 
	
if (strng == "") {
   error = "You didn't enter a company name.\n";
}	
return error;
}

// address - 4-10 chars, uc, lc, and underscore only. **************************************************************************

function checkAddress (strng) {
var error = "";

    var illegalChars = /\W\ /; // allow letters, numbers, and underscores
    if ((strng.length < 2)) {
       error = "Your address is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "Your adress contains illegal characters.\n";
    } 
	
if (strng == "") {
   error = "You didn't enter an address.\n";
}	
return error;
}

// city - 4-10 chars, uc, lc, and underscore only. **************************************************************************

function checkCity (strng) {
var error = "";

    var illegalChars = /\W\ /; // allow letters, numbers, and underscores
    if ((strng.length < 2)) {
       error = "Your city name is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "Your city name contains illegal characters.\n";
    } 
	
if (strng == "") {
   error = "You didn't enter a city.\n";
}	
return error;
}

// postal code - strip out delimiters and check for 4 digits ***********************************************************

function checkPostal (strng) {
var error = "";

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The postal code contains illegal characters.\n";
    }
	
    if ((stripped.length != 4)) {
	error = "The postal code is the wrong length.\n";
    } 	
	

if (strng == "") {
   error = "You didn't enter a postal code.\n";
}
	
return error;
}

// tel number - strip out delimiters and check for 10 digits ***********************************************************

function checkTel (strng) {
var error = "";

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The contact number contains illegal characters.\n";
    }
	
    if ((stripped.length < 7)) {
	error = "The tel number is the wrong length. Make sure you included an area code.\n";
    } 	
	

if (strng == "") {
   error = "You didn't enter a contact number.\n";
}
	
return error;
}
// non-empty codebox
function codeBox(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You didn't enter the code.\n"
  }
return error;	  
}

// email *****************************************************************************************************

function checkEmail (strng) {
var error="";

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }

if (strng == "") {
   error = "You didn't enter an email address.\n";
}
	
return error;    
}

// valid selector from dropdown list

function checkReferral(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}

// check if at least one box has been checked

function checkBusiType(checked) {
var error = "";
	if (document.dealerReg.bus1.checked == false &&
        document.dealerReg.bus2.checked == false &&
		document.dealerReg.bus3.checked == false &&
		document.dealerReg.bus4.checked == false &&
		document.dealerReg.bus5.checked == false &&
		document.dealerReg.bus6.checked == false &&
		document.dealerReg.bus7.checked == false &&
		document.dealerReg.bus8.checked == false &&
		document.dealerReg.bus9.checked == false &&
		document.dealerReg.bus10.checked == false &&
		document.dealerReg.bus11.checked == false &&
		document.dealerReg.bus12.checked == false &&
		document.dealerReg.bus13.checked == false &&
		document.dealerReg.bus14.checked == false &&
	 	document.dealerReg.bus15.checked == false) {
	  
	 error = "You didn't choose your business type.\n";
    }    
return error;
}

// non-empty codebox
function codeBox(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You didn't enter the security code.\n"
  }
return error;	  
}