/* AVAIALBLE FUNCTIONS:


	isEmail (objectId) 
	isPhone (objectId) 
	isPassword (objectId) 
	isUsername (objectId) 
	isName (objectId) 
	isEmpty(objectId)
	isInt(objectId)
	checkRadio(checkvalue)
	isDropDownListSelected(objectId)
	IsCreditCardNumberValid(ccNumb)
	
	all functions recive field Id
	all functions return true or false
	
	
	
	var reWhitespace     = /^\s$/ 
	var reLetter         = /^[a-zA-Z]$/ 
	var reAlphabetic     = /^[a-zA-Z]$/  
	var reAlphnumeric    = /^[a-zA-Z0-9]$/  
	var reDigit          = /^\d/  
	var reLetterOrDigit  = /^[a-zA-Z]|\d$/ 
	var reInteger        = /^\d/  
	var reSignedInteger  = /^(\|-)?\d$/ 
	var reEmail          = /^%20\@.%20\..$/ 

*/

function checkError(errorString){
	// the html page have to include a tag with the id of "formError"
	if(errorString!=""){
		errorString="Please correct: "+errorString
		if(document.all){
	    	document.getElementById("formError").innerText=errorString.substr(0,errorString.length-2)
		}else{
			document.getElementById("formError").innerContent=errorString.substr(0,errorString.length-2)
		}
		return false;
	}
	return true
}

function getValue(objectId){
	return document.getElementById(objectId).value
}
function getSelectedIndex(objectId){
	return document.getElementById(objectId).selectedIndex
}

//
function isEmail (objectId) {
	var error_str=""; 
	var strng=getValue(objectId);
	if(isEmpty(objectId)){
		return false
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		 return false
	}
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
    if (strng.match(illegalChars)) {
		 return false; 
    }
	return true; 
}


// phone number - strip out delimiters and check for 10 digits

function isPhone (objectId) {
	var error_str=""; var strng=getValue(objectId);
	if (strng == "") {
	   error_str = "You didn't enter a phone number.\n";
	}
	
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) {
		   error_str = "The phone number contains illegal characters.";
	  
		}
		/*if (!(stripped.length == 10)) {
		error_str = "The phone number is the wrong length. Make sure you included an area code.\n";
		} */
	return error_str==""; 
}


// password - between 6-8 chars, uppercase, lowercase, and numeral

function isPassword (objectId) {
	var error_str=""; var strng=getValue(objectId);
	if (strng == "") {
	   error_str = "You didn't enter a password.\n";
	}
	
		var illegalChars = /[\W_]/; // allow only letters and numbers
		
		if ((strng.length < 6) || (strng.length > 8)) {
		   error_str = "The password is the wrong length.\n";
		}
		else if (illegalChars.test(objectId)) {
		  error_str = "The password contains illegal characters.\n";
		} 
		else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
		   error_str = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
		}  
	return error_str==""; 
}    

function isName(objectId) {
	var error_str=""; 
	var strng=getValue(objectId);
	
	var myRegxp = /[a-zA-Z]/;
	if(isEmpty(objectId)){
		return false;
	}
	return myRegxp.test(strng)
}

// username - 4-10 chars, uc, lc, and underscore only.

function isUsername (objectId) {
	var error_str=""; var strng=getValue(objectId);
	if (strng == "") {
	   error_str = "You didn't enter a username.\n";
	}
	
	
		var illegalChars = /\W/; // allow letters, numbers, and underscores
		if ((strng.length < 4) || (strng.length > 10)) {
		   error_str = "The username is the wrong length.\n";
		}
		else if (illegalChars.test(objectId)) {
		error_str = "The username contains illegal characters.\n";
		} 
	return error_str==""; 
}       


// non-empty textbox

function isEmpty(objectId) {
	var error_str=""; 
	var strng=getValue(objectId);

	  if (strng.length == 0) {
		 return true
	  }
	
	return false; 
}

function isChecked(objectId){
	var cb;
	cb=document.getElementById(objectId);
	return cb.checked;
}


// exactly one radio button is chosen

function checkRadio(checkvalue) {
	var error_str=""; 
	var strng=getValue(objectId);
	   if (!(checkvalue)) {
		   error_str = "Please check a radio button.\n";
		}
	return error_str==""; 
}

// valid selector from dropdown list

function isDropDownListSelected(objectId) {
	var error_str=""; 
	var index=getSelectedIndex(objectId);
		if (index == 0) {
			return false
		}    
	return  true; 
}  
  
function isInt(objectId) {
	var strng=getValue(objectId);
	var valid = "0123456789"
	var temp;
	for (var i=0; i<field.value.length; i++) {
		char = "" + field.value.substring(i, i+1);
		if (valid.indexOf(char) <0){
			 return false;
		}
	}
	return true;
	
}
function isNumber(objectId) {
	var field=getValue(objectId);
	var valid = "0123456789."
	var temp;
	var dotCount=0;
	if(field.length==0){
		return false;	
	}
	for (var i=0; i<field.length; i++) {
		char = "" + field.substring(i, i+1);
		if (valid.indexOf(char) <0){
			 return false;
		}
		if(char=='.'){
			dotCount++	
		}
		if(dotCount>1){
			 return false;
		}
	}
	return true;
	
}

<!--
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: David Leppek :: https://www.azcode.com/Mod10

Basically, the alorithum takes each digit, from right to left and muliplies each second
digit by two. If the multiple is two-digits long (i.e.: 6 * 2 = 12) the two digits of
the multiple are then added together for a new number (1 + 2 = 3). You then add up the 
string of numbers, both unaltered and new values and get a total sum. This sum is then
divided by 10 and the remainder should be zero if it is a valid credit card. Hense the
name Mod 10 or Modulus 10. */
function IsCreditCardNumberValid(objectId) {  // v2.0
	var strng=getValue(objectId);
	var valid = "0123456789"  // Valid digits in a credit card number
	var len = ccNumb.length;  // The length of the submitted cc number
	var iCCN = parseInt(ccNumb);  // integer of ccNumb
	var sCCN = ccNumb.toString();  // string of ccNumb
	sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
	var iTotal = 0;  // integer total set at zero
	var bNum = true;  // by default assume it is a number
	var bResult = false;  // by default assume it is NOT a valid cc
	var temp;  // temp variable for parsing string
	var calc;  // used for calculation of each digit
	
	// Determine if the ccNumb is in fact all numbers
	for (var j=0; j<len; j++) {
	  temp = "" + sCCN.substring(j, j+1);
	  if (valid.indexOf(temp) == "-1"){bNum = false;}
	}
	
	// if it is NOT a number, you can either alert to the fact, or just pass a failure
	if(!bNum){
	  /*alert("Not a Number");*/bResult = false;
	}
	
	// Determine if it is the proper length 
	if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
	  bResult = false;
	} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
	  if(len >= 15){  // 15 or 16 for Amex or V/MC
		for(var i=len;i>0;i--){  // LOOP throught the digits of the card
		  calc = parseInt(iCCN) % 10;  // right most digit
		  calc = parseInt(calc);  // assure it is an integer
		  iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
		  i--;  // decrement the count - move to the next digit in the card
		  iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
		  calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
		  calc = calc *2;                                 // multiply the digit by two
		  // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
		  // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
		  switch(calc){
			case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
			case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
			case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
			case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
			case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
			default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
		  }                                               
		iCCN = iCCN / 10;  // subtracts right most digit from ccNum
		iTotal += calc;  // running total of the card number as we loop
	  }  // END OF LOOP
	  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
		bResult = true;  // This IS (or could be) a valid credit card number.
	  } else {
		bResult = false;  // This could NOT be a valid credit card number
		}
	  }
	}
	// change alert to on-page display or other indication as needed.
	/*if(bResult) {
	  alert("This IS a valid Credit Card Number!");
	}
	if(!bResult){
	  alert("This is NOT a valid Credit Card Number!");
	}*/
	  return bResult; // Return the results
}
