
/*
	This is a utility page dedicated ONLY to field validation scripts
		
	This file is to be "INCLUDED" as a supplement to existing validation code WITHIN the "script" tags.
*/
		
		
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original:  Torsten Frey (tf@tfrey.de) -->
<!-- Web Site:  http://www.tfrey.de -->

<!-- Begin
function check_date(field){
    var checkstr = "0123456789";
    var DateField = field;
    var Datevalue = "";
    var DateTemp = "";
    var seperator = ".";
    var day;
    var month;
    var year;
    var leap = 0;
    var err = 0;
    var i;
    var minYear = 1800;
   err = 0;
  // DateValue = DateField.value;
   
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateField.length; i++) {
	  if (checkstr.indexOf(DateField.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateField.substr(i,1);
	  }
   }
   DateField = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateField.length == 6) {
      DateField = DateField.substr(0,4) + '20' + DateField.substr(4,2); }
   if (DateField.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateField.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateField.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateField.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   if ((year < minYear)) {
      err = 45;
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      //DateField.value = day + seperator + month + seperator + year;
      return true; 
   }
   /* Error-message if err != 0 */
   else {
      var language = "<%=User_language%>"
      alert("Date entered is incorrect!");
     
      return false; 
      
   }
}
//  End -->
		
		
		
		
		
		
/*******************************************************************************************************************/
/************************						ONSUBMIT FUNCTIONS							************************/
//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	/*
	This script is simple to use.  It receives 3 variables that will then be checked if they are valid numbers,
	if not it will then send the focus back to the input that had the invalid value typed 
	so long as the input type supports the ".focus()" method.
	If the value is not valid, the script will return false back to the calling page.

	The 3 variables needed are :
		1. value	: The value of the input to be checked
		2. name		: The name of the input to be checked.
		3. formname : The name of the form that the input is part of.
		
	The function "checkNaN(value, name, formname)" is to be called from existing validation code.

	N.B.:
	This is used in conjunction with the form method 'onsubmit="return jscript_validation_function(this, this.name);"'.
		Where	: "this" will send the form as an object to validate each input
		And		: "this.name" will send the form name
		To		: the "jscript_validation_function" created will "INCLUDE" this file to check the NaN of the input.
						
	There are more advanced "onkeypress" functions further down this page.
	*/

	function checkNaN(value, name, formname){
		var wildcard1 = "-"
		
		if (value != ""){
 			if (isNaN(value)){
 				//name == NaN
 				alert("The value '" + value + "' is not a valid number.");
 				
 				if (name.match(wildcard1)==null){
 					sendFocus(name, formname);
 				}
 				return false;
 			}
 			else{
 				//name != NaN
 				return true;
 			}
 		}
 		else{
 			//name == empty value
 			//alert("The value entered is not a valid number.);
 			return true;
 		}
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	//A neat little function to send the focus back to a field.
	function sendFocus(where, formname){
		//alert(formname + "." + where + ".focus();");
		//change all bg colours to white, except missing field
		/*
		
		var elements = document.getElementsByTagName('input');
		
		for (var i=0; i<elements.length; i++)
		{
			if (elements.item(i).type != "reset" && elements(i).type != "submit" && elements(i).type != "button"){
			elements.item(i).style.background = "white"
			}
			//alert(i);
		}*/
		eval(formname + "." + where + ".style.background = '#DD9999'");
		//must be a .focus() because select lists and radio's dont support .select()
		eval(formname + "." + where + ".focus();");
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	/*
	For an example of this function see "ecrm/editcontact.asp"
	
	This function is called if an empty form textbox value was found.
		1.	"NonMandFields" is a regular expression similar in pattern to this ... 
				reNonMandFields = //[firstname|lastname]/	//searches for string values "firstname" OR "lastname"
		2.	"NonMandFields" is constructed in a function on the .asp page where the form is located like this ...
			
				**********************************************************
				THIS IS AN EXAMPLE OF HOW TO CONSTRUCT THE VALUE OF "NonMandFields"
					function setNonMandatoryFields(theform){
						//this function stays within the form page and passes no-mandatory fields to the validation script.
						
						//set non-mandatory fields ... the "|" character means "OR"
						var varFields = /busphoneext|altphone|altphoneext|cellphone|fax|web|shared1|account|campaign_newsletter|bitSendMailer/
						var varFields = "no_nonmandatory_fields"
			
						var blnGoodForm = isValidForm2(...);
						
						if (blnGoodForm){return true;}else{return false;}
					}
				**********************************************************
					
		3.	Function "setNonMandatoryFields(...)" is called from the forms 'onSubmit="return(setNonMandatoryFields(this));"' method
				If there are no mandatory fields in the form then "varFields" should equal "no_nonmandatory_fields"
					ie: var varFields = "no_nonmandatory_fields"
		
		4.	Function "isValidForm2(...)" is the function that does all the form validation.
				Function "isValidForm2" is the Heart and Soul of all the needed validation and 
				relies heavily on "function checkMandatoryFields(...)"
				which is located on the .asp page where the form validation is needed.
	*/
	function checkMandatoryFields(val,formname,NonMandFields){
		//	alert('NonMandFields = ' + NonMandFields);
 		if (NonMandFields != "no_nonmandatory_fields"){
			var reNonMandFields = NonMandFields
		//	alert('regexp = ' + reNonMandFields);
		//	alert('NonMandFields = ' + NonMandFields);
		//	alert('val = ' + val);
		//	alert('reNonMandFields.test(val) = ' + reNonMandFields.test(val));
			if (reNonMandFields.test(val)==false){
			   	alert("Please be sure to provide all necessary information.")
				sendFocus(val,formname)
 				return false;
			}
		}
		else if(NonMandFields == "no_nonmandatory_fields"){
			alert("All fields are mandatory.\n\nPlease be sure to provide all necessary information.")
 			sendFocus(val,formname)
 			return false;
		}
	}
	function checkMandatoryFields2(val,formname,NonMandFields){
			//alert('NonMandFields 2 = ' + NonMandFields);
 		if (NonMandFields != "no_nonmandatory_fields"){
			var reNonMandFields = NonMandFields
			if (reNonMandFields.test(val)==false){
			   	alert("Please be sure to provide all necessary information.")
				//sendFocus(val,formname)
 				return false;
			}
		}
		else if(NonMandFields == "no_nonmandatory_fields"){
			alert("All fields are mandatory.\n\nPlease be sure to provide all necessary information.")
 			sendFocus(val,formname)
 			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//

function isEmailValid(s) 
{ 
	var i = 1; 
	var sLength = s.length; 
	// look for @ 
	while ((i < sLength) && (s.charAt(i) != "@")) { i++ } 
		if ((i >= sLength) || (s.charAt(i) != "@")) 
			return false; 
		else i += 2; 
	// look for . 
	while ((i < sLength) && (s.charAt(i) != ".")) { i++ } 
	// there must be at least one character after the . 
		if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
			return false; 
		else 	
			return true;
}



/*	function isEmail(s) {
		//NOT currently implemented yet.
		
		//MUST DO THIS ALL AT ONCE ... 
		//	FIRST find all the .asp pages that use isEmail(s),
		//	SECOND remove that function, 
		//	THIRD include and implement this function
	
		var i = 1; 
		var sLength = s.length; 
		// look for @ 
		while ((i < sLength) && (s.charAt(i) != "@")) { i++ } 
			if ((i >= sLength) || (s.charAt(i) != "@")) 
				return false; 
			else i += 2; 
		// look for . 
		while ((i < sLength) && (s.charAt(i) != ".")) { i++ } 
		// there must be at least one character after the . 
			if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
				return false; 
			else 	
	 			return true;
	}
*/
//-----------------------------------------------------------------------------------------------------------------//
		
//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	/*
	For an example of this function see "ecrm/editcontact.asp" and function "isValidForm2(...)"
	
	This function validates characters in textboxes using regular expressions.
	The Condition Statement is checking for a TRUE value (an invalid character was found in the string).  
		If TRUE is found, then an invalid character (in "re") was found and a warning appears.
			Therefore, the condition statement Searches For "re" in the "str" value.
			
		N.B.: The "^" character at the beginning of the "re" to use means "NOT LIKE THESE".
	*/
	function validateFormTextboxes(str, focusto, formname,valType,valQuoteType){
		//alert('validateFormTextboxes');
		
		/*
		valType = is used for the select case here
		valQuoteType = is used for the select case in function findQuotes(...)
		*/
		var re = "";
		var hasQuotes = false;
		
		hasQuotes = findQuotes(str,focusto,formname,valQuoteType)
		var str = str.replace(/'/gi, "''")
		
		//hasQuotes = false
		var msg = "Some characters entered are not accepted.\nAccepted characters are : \n\n"
		if (hasQuotes==false){//quotes criteria not found.
			switch (valType){
				case 1 :
					msg = msg + "Letters, Numbers and -.@,#\/:'&() characters"
					re = /[^A-Za-z_0-9 \'\#\-\&\(\)\.\@\,\/\:?]/	//searches for non-word chars, non-digits, non-spaces and non-listed symbols (-.@,#\/:'&())
					break;
				case 2 :
					msg = msg + "Non-Letters and Non-Numbers."
					re = /[A-Za-z_0-9]/		//searches for word chars, digits, spaces and underscore
					//re = /\w\d ?_?/		//searches for word chars, digits, spaces and underscore
					//I keep both declared as an example.  Don't erase.
					break;
				case 3 :
					msg = msg + "Letters and Numbers."
					re = /[^A-Za-z_0-9]/	//searches for non-word chars, non-digits, non-spaces and non-underscore
					//re = /^\w\d ?_?/		//searches for non-word chars, non-digits, non-spaces and non-underscore
					//I keep both declared as an example.  Don't erase.
					break;
				case 4 :
					msg = msg + "Non-Numbers only."
					re = /[0-9]/		//searches for digits
					break;
				case 5 :
					msg = msg + "Numbers only."
					re = /[^0-9]/		//searches for non-digits
					break;
				case 6 :
					msg = msg + "Non-Letters only."
					re = /[A-Z_a-z]/	//searches for word chars and underscore
					break;
				case 7 :
					msg = msg + "Letters only."
					re = /[^A-Z_a-z]/	//searches for non-word chars and non-underscore
					break;
				default :
					msg = msg + "Letters and Numbers."
					re = /^\w\d ?_?/	//searches for non-word chars, non-digits, non-spaces and non-underscore
					break;
			}
			
			//Condition Statement
			if (re.test(str)){
				alert(msg);
				sendFocus(focusto, formname);
				return false;
			}
			else{
				//alert('plante');
				return true;
				
				//return false;
			}
		}
		else{//hasQuotes==true therefore return false because quotes were found.
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	/*
		This function will search a string for single and/or double quotes.
		If the search is successfull (a match was found), it will return TRUE.
		If the search is NOT successfull (a match was NOT found), it will return FALSE.
	*/
	function findQuotes(str,focusto,formname,findType){
		/*
		findType = is used for the select case here
		*/
		var reQuote = "";
		var msg = ""
		
		switch (findType){
			case 1 :
				//find only double quotes
				var reQuote = /[\"]/
				msg = "Double quotes are not valid characters."
				break;
			//case 2 :
				//find only single quotes
				//var reQuote = /[\']/
				//msg = "Single quotes are not valid characters."
				//return false;
				//break;
			case 3 :
				//find only double quotes and single quotes
				var reQuote = /[\"\']/
				msg = "Double quotes and single quotes are not valid characters."
				break;
			default :
				//find only double quotes
				//var reQuote = /[\"]/
				//msg = "Double quotes are not valid characters."
				//alert('patate');
				break;
		}
		
		if (reQuote.test(str)){
			alert(msg);
			sendFocus(focusto, formname);
			return true;
		}
		else{
			//alert ('as no quotes');
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

	
//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	/*
	For an example of this function see "ecrm/editcontact.asp" and function "isValidForm2(...)"
	
		This function relies on the fact that there are only TWO password textboxes.
		This function is called in a loop of all form elements of type "password"
			1. Original (first) textbox
			2. Confirmation (second) textbox
			
		N.B.: "tempPW1" and "tempPW2" MUST be OUTSIDE of the function as they need to be GLOBAL variables.
	*/
	var tempPW1 = ""
	var tempPW2 = ""
	function validate2Passwords(value,name,formname)
	{
		//First, test if valid characters are used alphanumeric and underscore only.
		var rePW = /[^A-Za-z_0-9]/	//searches for non-word chars, non-digits and non-underscore
			if (rePW.test(value)){
				alert("Passwords may only contain letters, numbers and underscores (ie: _ ).");
				sendFocus(name, formname);
				tempPW1 = ""
				tempPW2 = ""
				return false;
			}
		//Second, check variable values
		if (formname == "accountupdate")
		{
			if (name == "pass1")
			{
				tempPW1 = value;
				tempPW2 = window.accountupdate.oldpass.value;
				
				if (tempPW1 != tempPW2)
				{	alert("Please make sure the Password is correctly entered.");
					sendFocus(name, formname);
					tempPW1 = ""
					tempPW2 = ""
					return false;
				}
				else
				{	tempPW1 = ""
					tempPW2 = ""
				}
			}
			else
			{	if (tempPW1 == "")
				{	tempPW1 = value;
				}
				else
				{tempPW2 = value;
				}
			}
		}
		else
		{	if (tempPW1 == "")
			{	tempPW1 = value;
			}
			else
			{	tempPW2 = value;
			}
		}
		
		//alert('INSIDE PASSWORD');
		//Third, compaire the 2 values.
		if ((tempPW1 != "") && (tempPW2 != ""))
		{	if (tempPW1 != tempPW2)
			{	alert("Please make sure the Password and Confirmation are identical.");
				sendFocus(name, formname);
				tempPW1 = ""
				tempPW2 = ""
				return false;
			}
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	function myResetBGColor(theform){
		//called withing the form tag with onreset="myResetBGColor(this);"
		//set all backgrounds to white
		
		for (var i=0; i<theform.elements.length; i++)
		{
			if (theform.elements[i].type != "checkbox")
			{
				if (theform.elements[i].type != "reset" && theform.elements[i].type != "submit" && theform.elements[i].type != "button" && theform.elements[i].type != "radio" && theform.elements[i].type != "checkbox" && theform.elements[i].name != "shippinginfo")
				{
					theform.elements[i].style.background = "white"
				}
			}
		}
		
		/*
		for (var i=0; i<theform.elements.length; i++)
		{
			if (theform.elements[i].type != "reset" && theform.elements[i].type != "submit" && theform.elements[i].type != "button" && theform.elements[i].type != "radio" && theform.elements[i].type != "checkbox" && theform.elements[i].name != "shippinginfo")
			{
				theform.elements[i].style.background = "white"
			}
		}
		*/
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	function isValidForm2(theform,NonMandFields,valTextType,valQuoteType){
		//function isValidForm2(){
		/*
		valTextType = is used for the select case in function validateFormTextboxes(...)
		valQuoteType = is used for the select case in function validateFormTextboxes(...) and findQuotes(...)
		
		Function "isValidForm2(...)" is the function that does all the form validation.
			Function "isValidForm2" is the Heart and Soul of all the needed validation and 
			relies heavily on "function checkMandatoryFields(...)"
			which is located on the .asp page where the form validation is needed.
		*/
		
		//loop through form to validate all fields
		//alert(theform.elements.length);
		var blnReturn = true;  //NEW VALUE SET BY LOUIS
		
		//var blnReturn = false;   //ORIGINAL VALUE BY JOHN
		var valuetemp = "";
		var address = /address/;
		var city = /city/;
		var zipcode = /zipcode/;
		var tempName = "";
		var tempCheckboxSelected = false;
		
		
		myResetBGColor(theform);
		
		
		for (var i=0; i<theform.elements.length; i++)
		{	
			//set all backgrounds to white
			myResetBGColor(theform);
			
 			//var userid;
			var bln_IsChecked = false;
			var bln_IsSelected = false;
 			var name = theform.elements[i].name;
 			var value = theform.elements[i].value;
 			var elementid=theform.elements[i].id;
 			if ((theform.elements[i].length != undefined) &&(theform.elements[i].type=="select-multiple")) {
 	        	//alert('name = ' + name + ' --> value = ' +  value+ '   value length = ' + theform.elements[i].length);
			} else {
 				//To find which elements you need to validate use these two alerts
 				//alert('name = ' + name);
 				//alert('value = ' + value);
				
				//This next line removes any white space from begining and end of string.
				//If only spaces entered then value.length = 0, 
				//if value.length = 0, then no text is entered and value = ""
				value = value.replace(/^\s+/,'').replace(/\s+$/,'');
				theform.elements[i].value = value;
			}
			if (elementid.indexOf("mce_editor") ==-1)
			{	
			switch (theform.elements[i].type){
 				case "text" :
 					//alert('name = ' + name + 'value = ' + value);
 					//check only the mandatory fields for empty values
 					if (value == ""){
 						//check all fields except these ones - NonMandFields
						if (checkMandatoryFields(name,theform.name,NonMandFields) == false)
						{
						   // alert('inside');
							return false;
						}
						else
						{
							//alert('name 333 = ' + name + 'value = ' + value + ' return true');
							blnReturn == true;
						}
					}
 					else{	//(value != "")
						if (name == "email"){
							//do email verification ... function call isEmail(value);
							blnReturn = isEmailValid(value);
							
							if (blnReturn == false){
								alert("Please enter A valid e-Mail Address!");
								sendFocus(name, theform.name);
								//alert('2 false');
								return false;
							}
							else{
								//blnReturn = validateFormTextboxes(value, name, theform.name, valTextType, valQuoteType);
								blnReturn == true
								if (blnReturn == false)
								{
									//alert('3 false');
									return false;
								}
								else
								{
									//alert('3 true');
									blnReturn == true;
								}
							}
						}
					
						else if (name == "last" || name == "first")
						{
							var sLength = value.length; 
							if (sLength == 1) 
							{
								if (name == "first")
								{
									//alert("Please enter your complete first name!");
									theform.first.focus();
								}
								if (name == "last")
								{
									//alert("Please enter your complete last name!");
									theform.first.focus();
								}
								return false;
							}
							else
							{
								blnReturn == true;
							}
						}
						
						
						
						//else if (name == "address" || name == "city" || name == "zipcode"){
						
						else if (address.test(name) || city.test(name) || zipcode.test(name))
						{
							
							//do address verification to eliminate double quotes
							//the name of these fields must at LEAST contain the words "address" or "city" or "zipcode"
							//	... function call findQuotes(value,name,theform.name,valQuoteType)
							var blnBadAddress = findQuotes(value,name,theform.name,3);
							if (blnBadAddress)
							{
								return false;
							}
							else
							{
								//alert('name = ' + name + 'value = ' + value + ' return true');
								blnReturn == true;
							}
						}
						
 						else{
							//blnReturn = validateFormTextboxes(value, name, theform.name,valTextType,valQuoteType);
							blnReturn == true;
							if (blnReturn == false)
							{
								//alert('5 false');	
								return false;
							}
							else
							{
								//alert('5 true');
								blnReturn == true;
							}
						}
					} //close if (value == ""){
 					//	alert("text");
					//alert(blnReturn + ' final')
 					break;
			 		
 				case "textarea" :
 					//	alert("textarea");
 					blnReturn == true;
 					break;
 					
 				case "hidden" :
 					//	alert("hidden");
 					blnReturn == true;
 					break;
			 		
 				case "password" :
					//alert('name = ' + name + 'value = ' + value);
					//do password verification
					//see script below to see if it can be integrated.
 					if (value == "")
					{
 						//check all fields except these ones - NonMandFields
 						blnReturn = checkMandatoryFields(name,theform.name,NonMandFields)
						if (blnReturn == false){return false;}else{blnReturn = true}
 					}
					//call password function
					blnReturn = validate2Passwords(value,name,theform.name)
					if (blnReturn == false){tempPW1 = "";tempPW2 = "";return false;}else{blnReturn = true}
 					//	alert("password");
 					break;
			 		
 				case "checkbox" :
 				    //alert('name = ' + name);
                    if (tempName == "")
                    {   tempName = name
                        if ((tempName == "feedback") ||(tempName == "remem"))
                        {   blnReturn = checkMandatoryFields2(tempName,theform.name,NonMandFields)
                            if (blnReturn == false)
                            {   blnReturn = false;
                                tempCheckboxSelected = false;
                               // return false;
                                break;
                            }
                            else
                            {   blnReturn = true;
                               // return true;
                            }
                        }
                        else
                        {   if (theform.elements[i].checked)
                            {   tempCheckboxSelected = true;
                                 blnReturn = true;
                            }
                            else
                            {   tempCheckboxSelected = false;
                                blnReturn = false;
                            }
                        }
                    }
                    else
                    {   
                        if (tempName == name)
                        {   if (tempCheckboxSelected == false)
                            {   // If none check, validate current one
                                if (theform.elements[i].checked)
                                {   tempCheckboxSelected = true;
                                    blnReturn = true;
                                }
                            }
                        }
                        else
                        {   
                            //alert(tempCheckboxSelected);
                            if (tempCheckboxSelected == false)
	                        {   blnReturn = checkMandatoryFields2(tempName,theform.name,NonMandFields)
	                            if (blnReturn == false)
	                            {   
	                                blnReturn = false;
	                                return false;
	                                break;
	                            }
	                        }
	                        tempName = name; //set temp to next Checkbox group/name
                    	    
	                        tempCheckboxSelected = false;
	                        blnReturn = false;
                    	    
	                        if (theform.elements[i].checked)
                            {   tempCheckboxSelected = true;
                                blnReturn = true;
                            }
                            else
                            {   
                               //if (NonMandFields.test(tempName)==false)
                                if (tempName == "feedback")
                                {   if (tempCheckboxSelected == false)
	                                {   blnReturn = checkMandatoryFields2(tempName,theform.name,NonMandFields)
	                                    if (blnReturn == false)
	                                    {   blnReturn = false;
	                                        tempCheckboxSelected = false;
	                                        return false;
	                                        break;
	                                    }
	                                    else
	                                    {   blnReturn = true;
	                                        return true;
		                                }
	                                }
                                }
                            }
                        }
                    }
                    //alert(blnReturn + ' final checkbox')
 					break;
 					
 				case "radio" :
					//alert('name = ' + name + 'value = ' + value);
 					//RADIO'S CANNOT HAVE A FOCUS .. DO NOT CALL sendFocus(name,theform.name)
 					for (var j=0; j<eval("theform.elements."+name+".length"); j++){
 						if (eval("theform.elements."+name+"[j].checked")){bln_IsChecked = true;}
 					}
 						
 					if (bln_IsChecked){blnReturn = true;break;}
 					else{
						alert("Please be sure to select a radio button in each group.");
						return false;
 					}
 					//	alert("radio");
 					break;
 					
 				case "select-one" :
					//alert('select single name = ' + name + 'value = ' + value);
 					bln_IsSelected = true;
					for(var q = 0; q < theform.elements[i].options.length; q++){
						if (theform.elements[i].options[q].selected) {
							if (theform.elements[i].options[q].value == "0"){
 								//check all fields except these ones - NonMandFields
 								blnReturn = checkMandatoryFields(name,theform.name,NonMandFields)
								if (blnReturn == false)
								{return false;}else{blnReturn = true}
							}
							else{blnReturn = true;}
						}
					}
 					break;
			 		
 				case "select-multiple" :
					//alert('select multiple name = ' + name + 'value = ' + value);
 					bln_IsSelected = true;
	 				if (theform.elements[i].options.selectedIndex<0){
 						//check all fields except these ones - NonMandFields
 						blnReturn = checkMandatoryFields(name,theform.name,NonMandFields)
	 					if (blnReturn == false){return false;}
 					}
					else
					{
						blnReturn = true;
					}
 					break;
 				default :
					//blnReturn = false;
 					//	alert("default");
 					break;
 			}
 			}
 			//alert('blnReturn = ' + blnReturn);
 		}
 		
 		
 		//THIS VERIFICATION MUST BE DONE LAST BECAUSE IT PROCEEDS TO A NEW PAGE AND 
		// THE NEW PAGE REQUIRES THE INFO FROM THIS PAGE TO BE VALIDATED.
		if ((theform.name == "editcontact") || (theform.name == "addcontact") || (theform.name == "addpresscontact"))
		{
			if (theform.NewAccount != null){
				if (theform.NewAccount.checked ){	//creating contact after creating account
					if (confirm("You are about to create a new account.  Would you like to proceed?"))
					{
						if (theform.name == "editcontact")
						{
							//alert('edit contact');
							//theform.action="NewaccountEditContact.asp?userid=<%=userid%>&ContID=<%=ContID%>";
							theform.action="NewaccountEditContact.asp";
						}
						else if (theform.name == "addcontact")
						{
							//alert('add contact');
							//theform.action="NewaccountContact.asp?userid=<%=userid%>";
							theform.action="NewaccountContact.asp";
						}
						else if (theform.name == "addpresscontact")
						{
							//alert('add contact');
							//theform.action="NewaccountpressContact.asp?userid=<%=userid%>";
							theform.action="NewaccountpressContact.asp";
						}
					}
					else{
						//confrim == false
						alert("Please select a Related Account.");
						theform.NewAccount.checked = false;
						theform.account.focus();
						return false;
					}
				}
				else	//we create the contact
				{	
					if (theform.account.value == 0)
					{
						alert("Please select a Related Account.");
						theform.NewAccount.checked = false;
						theform.account.focus();
						return(false);
					}
				}
			}
		}
		//alert(' FINAL blnReturn = ' + blnReturn);
		if (blnReturn == true){return true;}else{return false;}
		//return false;
		
	}	//closes function isValidForm2(theform)
//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
		
				
				
				
		
/*******************************************************************************************************************/		
/************************					ONKEYPRESS FUNCTIONS							************************/
//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	/*
	Does what it says.  Does not allow comma's and decimals in number fields.
	keycodes :
		44 = commas (,)
		45 = commas (-)
		46 = commas (.)
	N.B.:
	Called with 'onkeypress="return disallowDigitSymbols(window.event.keyCode);"' method of an HTML textbox.
	*/
	function disallowDigitSymbols(keycode){
		//alert(keycode);
		if (keycode == 44 || keycode == 46){
		//44=",", 46="."
			//alert("This field must be a whole number.");
			alert("This field does not accept comma's or decimals.");
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	/*
	Does what it says.  Does not allow comma's and decimals in number fields.
	keycodes :
		44 = commas (,)
		45 = commas (-)
		46 = commas (.)
	N.B.:
	Called with 'onkeypress="return disallowDigitSymbolsAndNeg(window.event.keyCode);"' method of an HTML textbox.
	*/
	function disallowDigitSymbolsAndNeg(keycode){
		//alert(keycode);
		if (keycode == 44 || keycode == 45 || keycode == 46){
		//44=",",45="-", 46="."
			//alert("This field must be a whole number.");
			alert("This field does not accept comma's, decimals or negative numbers.");
			return false;
		}
		else{
			return true;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//




//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	// copyright 1999 Idocs, Inc. http://www.idocs.com
	// Distribute this script freely but keep this notice in place
	/*
		Does what it says.  Only allows numbers to be entered.
		N.B.:
		Called with 'onkeypress="return numbersonly(this, event);"' method of an HTML textbox.
	*/
	function numbersonly(myfield, e, dec){
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) )
		//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape
			return true;

		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
			return true;

		// decimal point jump
		else if (dec && (keychar == "."))
		{
			myfield.form.elements[dec].focus();
			alert("The value entered is not a valid number.\nThis field only accepts numbers.");
			return false;
		}
		else
		{
			alert("The value entered is not a valid number.\nThis field only accepts numbers.");
			return false;
		}
	}
	
	function numbersonlycheckmax(myfield, e, max){
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) )
		//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape
			return true;

		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
		    if (myfield.value >= max )
		    {
		    
		    alert("The value entered exceeds the maximum number of items that can be added at once.");
			return false;
		    }
		    else
		    {
			return true;
			}

		// decimal point jump
		else if (max >= myfield.value)
		{
			myfield.form.elements[dec].focus();
			alert("The value entered is not a valid number.\nThis field only accepts numbers.");
			return false;
		}
		else
		{
			alert("The value entered is not a valid number.\nThis field only accepts numbers.");
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	// copyright 1999 Idocs, Inc. http://www.idocs.com
	// Distribute this script freely but keep this notice in place
		// Modified 2005 - third party
	/*
		Does what it says.  Only allows letters and underscores to be entered.
		N.B.:
		Called with 'onkeypress="return lettersonly(this, event);"' method of an HTML textbox.
	*/
	function lettersonly(myfield, e, dec){
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) )
		//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape
			return true;

		// letters
		else if ((("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_").indexOf(keychar) > -1))
			return true;

		// decimal point jump
		else if (dec && (keychar == "."))
		{
			myfield.form.elements[dec].focus();
			alert("The value entered is not a valid entry.\nThis field only accepts letters and the underscore (ie: _ ) symbol.");
			return false;
		}
		else
		{
			alert("The value entered is not a valid entry.\nThis field only accepts letters and the underscore (ie: _ ) symbol.");
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//
		
//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	// copyright 1999 Idocs, Inc. http://www.idocs.com
	// Distribute this script freely but keep this notice in place
		// Modified 2005 - third party
	/*
		Does what it says.  Only allows letters and numbers and underscores to be entered.
		N.B.:
		Called with 'onkeypress="return alphanumericonly(this, event);"' method of an HTML textbox.
	*/
	function alphanumericonly(myfield, e, dec){
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) )
		//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape
			return true;

		// alphanumeric
		else if ((("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_").indexOf(keychar) > -1))
			return true;

		// decimal point jump
		else if (dec && (keychar == "."))
		{
			myfield.form.elements[dec].focus();
			alert("The value entered is not a valid entry.\nThis field only accepts numbers, letters and the underscore (ie: _ ) symbol.");
			return false;
		}
		else
		{
			alert("The value entered is not a valid entry.\nThis field only accepts numbers, letters and the underscore (ie: _ ) symbol.");
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	// copyright 1999 Idocs, Inc. http://www.idocs.com
	// Distribute this script freely but keep this notice in place
		// Modified 2005 - third party
	/*
		Does what it says.  Only allows letters and numbers, hyphen, underscor, space to be entered.
		N.B.:
		Called with 'onkeypress="return alphanumericonly2(this, event);"' method of an HTML textbox.
	*/
	function alphanumericonly2(myfield, e, dec){
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) )
		//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape
			return true;

		// alphanumeric
		else if ((("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ ").indexOf(keychar) > -1))
			return true;

		// decimal point jump
		else if (dec && (keychar == "."))
		{
			myfield.form.elements[dec].focus();
			alert("The value entered is not a valid entry.\nThis field only accepts numbers, letters, spaces, hyphen (ie: - ) and the underscore (ie: _ ) symbols.");
			return false;
		}
		else
		{
			alert("The value entered is not a valid entry.\nThis field only accepts numbers, letters, spaces, hyphen (ie: - ) and the underscore (ie: _ ) symbols.");
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	// copyright 1999 Idocs, Inc. http://www.idocs.com
	// Distribute this script freely but keep this notice in place
		// Modified 2005 - third party
	/*
		Does what it says.  Only allows numbers and hyphen.  
			Used mostly to validate order and invoice number searches
		N.B.:
		Called with 'onkeypress="return alphanumeric2only(this, event);"' method of an HTML textbox.
	*/
	function numbersonly2(myfield, e, dec){
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) )
		//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape
			return true;

		// order number format
		else if ((("0123456789-").indexOf(keychar) > -1))
			return true;

		// decimal point jump
		else if (dec && (keychar == "."))
		{
			myfield.form.elements[dec].focus();
			alert("The value entered is not a valid entry.\nThis field only accepts numbers and hyphen (ie: - ) symbols.");
			return false;
		}
		else
		{
			alert("The value entered is not a valid entry.\nThis field only accepts numbers and hyphen (ie: - ) symbols.");
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

/*
THESE NEXT FEW FUNCTIONS NEED TO BE FOUND AND CLEANED ... JL
	CODE #	---	ASCII Char.
	-----------------------
		32	---	space
		39	---	'
		40	---	(
		41	---	)
		44	---	,
		45	---	-
		46	---	.
*/
//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	// copyright 1999 Idocs, Inc. http://www.idocs.com
	// Distribute this script freely but keep this notice in place
		// Modified 2005 - third party
	/*
		Does what it says.  Only allows letters and numbers and underscores to be entered.
		N.B.:
		Called with 'onkeypress="return alphanumericonlyAndCommunChars(this, event);"' method of an HTML textbox.
	*/
	function alphanumericonlyAndCommunChars(myfield, e, dec){
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) || (key==32) || (key==39) || (key==40) || (key==41) || (key==44) || (key==45) || (key==46))
			//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape, 32=(Space), 39="'", 40="(", 41=")", 44=",",45="-", 46="."
			return true;

		// alphanumeric
		else if ((("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_").indexOf(keychar) > -1))
			return true;
		else if ((("-!@#$%&*()+=ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜáíóúñÑ½¼²/'").indexOf(keychar) > -1))
			return true;	

		else
		{
			alert("The value entered is not a valid entry.\nThis field only accepts common naming characters.");
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

function allCommonField(myfield, e, dec){
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) || (key==32) || (key==39) || (key==40) || (key==41) || (key==44) || (key==45) || (key==46) || (key==60))
			//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape, 32=(Space), 39="'", 40="(", 41=")", 44=",",45="-", 46="."
			return true;
		if ((key>=32) || (key<=90))
		{
			return true;	
		}
		if ((key>=95) || (key<=125))
		{
			return true;	
		}
		if ((key>=128) || (key<=151))
		{
			return true;	
		}
		if ((key>=160) || (key<=165))
		{
			return true;	
		}

		else
		{
			alert("The value entered is not a valid entry.\nThis field only accepts common naming characters.");
			return false;
		}
	}

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	// copyright 1999 Idocs, Inc. http://www.idocs.com
	// Distribute this script freely but keep this notice in place
	/*
		Does what it says.  Only allows numbers to be entered.
		N.B.:
		Called with 'onkeypress="return moneyField(this, event);"' method of an HTML textbox.
	*/
	function moneyField(myfield, e, dec){
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) || (key==46) )
			//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape, 46="."
			return true;

		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
			return true;

		else
		{
			alert("The value entered is not a valid number.\nThis field only accepts numbers and period (ie: .) symbols.");
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//


//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	// copyright 1999 Idocs, Inc. http://www.idocs.com
	// Distribute this script freely but keep this notice in place
	/*
		Does what it says.  Only allows numbers to be entered.
		N.B.:
		Called with 'onkeypress="return qtyField(this, event);"' method of an HTML textbox.
	*/
	function qtyField(myfield, e, dec){
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) || (key==46) )
		//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape, 46="."
			return true;

		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
			return true;

		else
		{
			alert("The value entered is not a valid number.\nThis field only accepts numbers and period (ie: .) symbols.");
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------------------------------------//
	// copyright 1999 Idocs, Inc. http://www.idocs.com
	// Distribute this script freely but keep this notice in place
	/*
		Does what it says.  Only allows numbers to be entered.
		N.B.:
		Called with 'onkeypress="return qtyField(this, event);"' method of an HTML textbox.
	*/
	function moneyLimited(myfield, e, dec){
		//myfield.form.elements[dec].focus();
		var totalValue 
		var key;
		var keychar;

		

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
			
		totalValue = myfield.value;	
		keychar = String.fromCharCode(key);
		
		totalValue = totalValue + keychar;
		var totalValueLength
		totalValueLength = totalValue.length;
		var foundComa
		
		totalValue = myfield.value;	
		
		foundComa =	totalValue.indexOf(".",1);
		
		
		alert('totalValue = ' + totalValue);	
		alert('totalValueLength = ' + totalValueLength);
		alert('foundComa = ' + foundComa);	
		
		// control keys
		if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) || (key==46) )
		//0=null, 8=Backspace, 9=Tab, 13=CarriageReturn, 27=Escape, 46="."
			return true;
		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
			return true;
		else
		{
			alert("The value entered is not a valid number.\nThis field only accepts numbers and period (ie: .) symbols.");
			return false;
		}
	}
//-----------------------------------------------------------------------------------------------------------------//

