
//-------------------------
//Check an email address...
//-------------------------
function checkEmail (strng) {
if (strng == "") {
   //alert ("Please enter an email address.\n");
   return false;
}

    var emailFilter=/^.+@.+\..{2,4}$/;
    if (!(emailFilter.test(strng))) { 
       //alert ("Please enter a valid email address.\n");
	   return false;	   
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
	      // alert ("The email address you entered contains illegal characters.\n");
  		   return false;
       }
    }   
return true;
}

//-------------------------
//Compare 2 separate email addresses...
//-------------------------
function checkEmailMatch (strng1, strng2) {
	if (strng1 != strng2) {
		//alert ("The 2 email addresses you entered do not match!");
		return false;
	}
return true;
}


//-----------------------------
//Check for empty newsletters...
//-----------------------------
function isEmptySelect(strng) {
  if (strng.length == 0) {
     //alert ("Please select a newsletter.\n");
	   return false;	 
  }
return true;  
}

//-----------------------------
//Check a whole phone number...
//-----------------------------
function checkWholePhone (strng) {
if (strng == "") {
   alert ("Please enter a phone number.\n");
	   return false;   
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric charactersvar 
var strippedNotNum = /[^0-9]/;
    if (strippedNotNum.test(stripped)) {
	alert ("The phone number you entered contains illegal characters.");
		return false;
    }
    if (stripped.length != 10) {
	alert ("The phone number you entered is the wrong length. Make sure you include an area code followed by a 7-digit number.\n");
	   return false;	
    }
return true;
}

//-------------------------------
//Check a partial phone number...
//-------------------------------
function checkPhone (strng) {
if (strng == "") {
   alert ("Please enter a phone number.\n");
	   return false;   
}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
var strippedNotNum = /[^0-9]/;
    if (strippedNotNum.test(stripped)) {
	alert ("The phone number you entered contains illegal characters.");
	   return false;  
    }
    if (stripped.length != 7) {
	alert ("The phone number you entered is the wrong length. Make sure you put the area code in the area code field.\n");
	   return false;
    } 
return true;
}

//------------------------------------
//Used to check the area code field...
//------------------------------------
function checkAreaCode (strng) {
if (strng == "") {
	alert ("Please enter an area code.\n");
	   return false;	
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
var strippedNotNum = /[^0-9]/;
    if (strippedNotNum.test(stripped)) {
       alert ("The area code you entered contains illegal characters.");
	   return false;	   
    }
    if (stripped.length != 3) {
	alert ("The area code you entered is the wrong length. Please use only three digits.\n");
	   return false;
    } 
return true;	
}

//------------------------------------
//Used to check the extension field...
//------------------------------------
function checkExtension (strng) {
if (strng == "") {
	alert ("Please enter a telephone number extension.\n");
	   return false;	
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
var strippedNotNum = /[^0-9]/;
    if (strippedNotNum.test(stripped)) {
       alert ("The area code you entered contains illegal characters.");
	   return false;	   
    }
    if (!(stripped.length > 0 ) && !(stripped.length < 6)) {
	alert ("The area code you entered is the wrong length. Please use only three digits.\n");
	   return false;
    } 
return true;	
}


//-------------------------------------------------------
//Check any regular field for just letters and numbers...
//-------------------------------------------------------
function checkRegularField (strng,msg) {
	if (strng == "") {
	   alert ("Please enter " + msg + ".\n");
	   return false;	   
	}

    var illegalChars= /[\(\)\<\>\,\;\:\\\[\]\@\#\$\%\^\&\*\_\"]/
    if (illegalChars.test(strng)) {
	  alert ("Please only use letters or numbers in " + msg + ".\n");
	  return false;
	}
	return true;	
}

function checkRegularFieldOpt (strng,msg) {
    var illegalChars= /[\(\)\<\>\,\;\:\\\[\]\@\#\$\%\^\&\*\!\"]/
    if (illegalChars.test(strng)) {
	  alert ("Please only use letters or numbers in " + msg + ".\n");
	  return false;
	}
	return true;	
}


//------------------------------------
//Used to check the address field...
//------------------------------------

function checkAddress (strng,msg) {
    var illegalChars= /[\<\>\;\[\]\@\$\%\^\&\*\~\`\{\}\?\!\"]/
    if (illegalChars.test(strng)) {
	  alert ("You have entered an invalid character in " + msg + ".\n");
	  return false;
	}
	return true;	
}



function checkJustNumbers (strng,msg) {
if (strng == "") {
	alert ("Please enter " + msg + ".\n");
	return false;
}

    var illegalChars= /[^0-9]/
    if (illegalChars.test(strng)) {
	  	alert ("Please only use numbers in " + msg + ".\n");
		return false;
	}
	return true;	
}

function checkMMSI(strng,msg)
{
	if (strng != "")
	{
		if (parseInt(strng) > 2147483647)
		{
			alert(msg + " must be less than 2147483647.");
			return false;
		}
	}
	return true;	
}


//---------------------
//Check the password...
//---------------------
function checkPassword (strng) {
if (strng == "") {
	alert ("Please enter a password.\n");
	return false;
}
    var illegalChars = /[\W_]/; // allow only letters and numbers
	var hasUppercase = /[A-Z]/;
	var hasLowercase = /[a-z]/;
	var hasNumber = /[0-9]/;
	
	if ((strng.length < 6) || (strng.length > 20)) {
       alert ("Your password must contain between 6 and 20 alphanumeric characters.\n");
		return false;
    }
    else if (illegalChars.test(strng)) {
      alert ("Your password may contain only numbers and letters (no spaces).\n");
		return false;
    } 
    /*else if (!(hasUppercase.test(strng) && hasLowercase.test(strng) && hasNumber.test(strng))) {
       alert ("Your password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n");
		return false;
    }  */
	return true;
}    


//---------------------------------
//Check that the passwords match...
//---------------------------------
function checkPasswordMatch (strng1, strng2) {
	if (strng1 != strng2) {
		alert ("The passwords you entered do not match!");
		return false;
	}
return true;
}


//---------------------
//Check the username...`
//---------------------
function checkUsername (strng) {
if (strng == "") {
   alert ("Please enter your username.\n");
	   return false;   
}

    var illegalChars = /\W/; // allow letters, numbers, and underscores
	var spaceChars = /\s/; //don't allow whitespace characters
    if (strng.length > 20) {
       alert ("The username you entered must contain less than 20 characters.\n");
	   return false;	   
    }
    else if (illegalChars.test(strng) || spaceChars.test(strng)) {
    alert ("Your username may contain only numbers and letters with no spaces.\n");
	   return false;
    } 
return true;
}


//-----------------------------
//Check for empty selections...
//-----------------------------
function isEmpty(strng) {
  if (strng.length == 0) {
     alert ("The mandatory text area has not been filled in.\n");
	   return false;	 
  }
return true;  
}


//-----------------------------------------
//Make sure only one radio button is chosen
//-----------------------------------------
function checkRadio(checkvalue) {
   if (!(checkvalue)) {
       alert ("Please check a radio button.\n");
	   return false;
    }
return true;	
}


//--------------------------------------------------
//Make sure something is taken from the drop down...
//--------------------------------------------------
function checkDropdown(choice) {
    if (choice == 0) {
    alert ("Please select an option from the drop-down list.\n");
	return false;
    }
return true;
}

//------------------------------------
//Used to check the zip code field...
//------------------------------------
function checkZipCode (strng) {
if (strng == "") {
	alert ("Please enter a zip code.\n");
	return false;
}

var stripped = strng.replace(/[\-\ ]/g, ''); //strip out acceptable non-numeric characters

var strippedNotNum = /[^0-9]/;
    if (strippedNotNum.test(stripped)) {
       alert ("The zip code you entered contains illegal characters. Please use only numbers.");
	   return false;	   
    }
	
    if  (  (stripped.length != 5)  &&  (stripped.length != 9)  ) {
	alert ("Please make sure the zip code contains 5 or 9 digits.\n");
	return false;
    } 
return true;
}

//------------------------------------
//Used to check the latitude/longitude fields
//------------------------------------
function checkCoords (strng,msg) {
if (strng == "") {
	alert ("Please enter the Vessel\'s complete " + msg + " at date of activation.\n");
	return false;
}

var stripped = strng.replace(/[\-\.\ ]/g, ''); //strip out acceptable non-numeric characters

var strippedNotNum = /[^0-9]/;
    if (strippedNotNum.test(stripped)) {
       alert ("The " + msg + " you entered may contain only digits, decimals, and minus signs.");
	   return false;	   
    }
return true;
}



// Preload images
var blank = new Image(); blank.src = "http://images.barnesandnoble.com/pimages/resources/promo/KMP/buttons/Whitebar.gif";
var blank2 = new Image(); blank.src = "http://images.barnesandnoble.com/pimages/resources/promo/KMP/buttons/Whitebar.gif";
var EmailAddr = new Image(); EmailAddr.src = "http://images.barnesandnoble.com/pimages/resources/promo/KMP/buttons/emailerror.gif";
var EmailAddrConf = new Image(); EmailAddrConf.src = "http://images.barnesandnoble.com/pimages/resources/promo/KMP/buttons/confirmationerror.gif";
var picksMade = new Image(); picksMade.src = "http://images.barnesandnoble.com/pimages/resources/promo/KMP/buttons/Chooseone.gif";
var emailmatch = new Image(); emailmatch.src = "http://images.barnesandnoble.com/pimages/resources/promo/KMP/buttons/EmailMismatch.gif";


 
	function onSubmitForm()	{
	
	function showImage(imagename, imageurl) {
	document[imagename].src = imageurl;	}
  		showImage("picksMade", blank.src)
		showImage("EmailAddr", blank.src)	
		showImage("EmailAddrConf", blank.src)	
		showImage("emailmatch", blank.src)	
		
		
		if (document.form.picksMade.value=="" ||document.form.picksMade.value==0){
		//showImage("picksMade", picksMade.src);  
		showImage("blank2", picksMade.src);  
			//alert ("Please select a newsletter.\n");
			return false; 
		}	
		if (!(checkEmail(document.form.EmailAddr.value))) {
			document.form.EmailAddr.focus();
			//showImage("EmailAddr", EmailAddr.src);  
			showImage("blank2", EmailAddr.src);  			
			return false;		
		}
		if (!(checkEmail(document.form.EmailAddrConf.value))) {
			document.form.EmailAddrConf.focus();
			//showImage("EmailAddrConf", EmailAddrConf.src);  
			showImage("blank2", EmailAddrConf.src);  	
			return false;			
		}
		if (!(checkEmailMatch(document.form.EmailAddr.value, document.form.EmailAddrConf.value))) {
			document.form.EmailAddr.focus();
			//showImage("emailmatch", emailmatch.src);  
			showImage("blank2", emailmatch.src);  
			return false;
		}
		else {
  
  		return true;
		}
	}






