<!--
//THIS FILE HOLDS THE VARIOUS FORM FIELD VALIDATION
//ALL REQUIRED FIELDS THAT ARE USED ON THE SITE
//ARE INCLUDED IN THIS FILE. EACH FIELD IS CHECKED TO
//SEE IF IT BELONGS ON THE FORM. IF IT IS THEN THE FIELD
//WILL BE CHECKED
//

//Declare variables
blanks = " \t\n\r"; 
phoneNumberDelimiters = "()- ";
invalidChar="`!@#$%^&*||~?<>:;\"{}()[]\\/,";
period =".";
underscore="_";
dash ="-";
empty='';
open_bracket="(";
close_bracket=")";
slash="/";
space=" ";
apostrophe ="'";
intCharSet = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ"

function validateForm(theForm){

			// Newsletter Registration Validation
			//check if the form has a username field
			if(theForm.username){
				if(trim(theForm.username.value) == ""){
					alert(JS_FIRSTNAME_MISSING_ERROR);
					theForm.username.focus();
					return false;
				}
				else{
					if(!isAlphaNumeric(theForm.username.value)){
						alert(JS_FIRSTNAME_FORMAT_ERROR);
						theForm.username.focus();
						return false;
					}
					theForm.username.value = trim(theForm.username.value);						
				}
			}			
			
			//check if the form has a name
			if(theForm.fname){
				if(trim(theForm.fname.value) == ""){
					alert("Please enter your first name.");
					theForm.fname.focus();
					return false;
				}else{
				theForm.fname.value = trim(theForm.fname.value);
						
				}
			}			
			
			//check if the form has a name
			if(theForm.lname){
				if(trim(theForm.lname.value) == ""){
					alert("Please enter your last name.");
					theForm.lname.focus();
					return false;
				}else{
				theForm.lname.value = trim(theForm.lname.value);
						
				}
			}	
			
			//check if the form has an address field
			if(theForm.address1) {
				if(trim(theForm.address1.value) == ""){
					alert("Please enter your street address.");
					theForm.address1.focus();
					return false;
				}
				else{
					theForm.address1.value = trim(theForm.address1.value);						
				}
			}		
			
			//check if the form has an email address field (used in newsletter registration)
			if(theForm.email){	
			
				if(theForm.email.value == ""){
					alert("Please enter your e-mail address.");
					theForm.email.focus();
					return false;				
				}else{
					if(!isValidEmail(theForm.email.value)){
						alert("Please enter a valid e-mail address.");
						theForm.email.focus();
						return false;
					}
					theForm.email.value = trim(theForm.email.value);
				}
			}		
			
			//check if the form has a phone number
			if(theForm.phone){
				if(trim(theForm.phone.value) == ""){
					alert("Please enter your phone number.");
					theForm.phone.focus();
					return false;
				}else{
				theForm.phone.value = trim(theForm.phone.value);
						
				}
			}
			
			//check if the form has type of piece
			if(theForm.type_of_piece) {
				if(trim(theForm.type_of_piece.value) == ""){
					alert("Please enter type of piece you have.");
					theForm.type_of_piece.focus();
					return false;
				}
				else{
					theForm.type_of_piece.value = trim(theForm.type_of_piece.value);						
				}
			}		
			
			//check if the form has type of piece
			if(theForm.description_of_problems) {
				if(trim(theForm.description_of_problems.value) == ""){
					alert("Please enter a brief description of the problems.");
					theForm.description_of_problems.focus();
					return false;
				}
				else{
					theForm.description_of_problems.value = trim(theForm.description_of_problems.value);						
				}
			}		
			
			
			
			
			
			//validate the address field
			if(theForm.textAddress){
				if(trim(theForm.textAddress.value) == ""){
					alert(JS_ADDRESS_MISSING_ERROR);
					theForm.textAddress.focus();
					return false;
				}else{
					if(!isValidAddress(theForm.textAddress.value)){
						alert(JS_ADDRESS_FORMAT_ERROR);
						theForm.textAddress.focus();
						return false;
					}
				theForm.textAddress.value = trim(theForm.textAddress.value)
				}
			}
			
			if(theForm.textAptNo){	
				if(trim(theForm.textAptNo.value) != ""){
					if(!isWhateverDoesNotFitInAnother(theForm.textAptNo.value)){
						alert(JS_ADDRESS_FORMAT_ERROR);
						theForm.textAptNo.focus();
						return false;
					}
				theForm.textAptNo.value = trim(theForm.textAptNo.value);
				}
			}
			
			//validate the city field
			if(theForm.textCity){
				if(trim(theForm.textCity.value) == ""){
					alert(JS_CITY_MISSING_ERROR);
					theForm.textCity.focus();
					return false;
				}else{
					if(theForm.textCity.value == "-"){
						alert(JS_CITY_FORMAT_ERROR);
						theForm.textCity.focus();
						return false;
					}else if(!isAlphaNumeric(theForm.textCity.value)){
						alert(JS_CITY_FORMAT_ERROR);
						theForm.textCity.focus();
						return false;
					}
				theForm.textCity.value = trim(theForm.textCity.value);
				}
			}
			
			
			if(theForm.selectState){
				//validate the sate
				if(theForm.selectState.selectedIndex=="0"){
					alert(JS_STATE_MISSING_ERROR);
					theForm.selectState.focus();
					return false;
				}
			}
			
			//validate the zip code
			if(theForm.textZip){
				if(trim(theForm.textZip.value) == ""){
					alert(JS_ZIP_MISSING_ERROR);
					theForm.textZip.focus();
					return false;
				}else {
					if(!isZipCode(theForm.textZip.value)){
						alert(JS_ZIP_FORMAT_ERROR);
						theForm.textZip.focus();
						return false;
					}
				theForm.textZip.value = trim(theForm.textZip.value);
				}	
			}
			
			
			
			
			//validate phone number
			if((theForm.textAreaCode) && (theForm.textPhone) && (theForm.textSuffix)){
				var phoneNumber = theForm.textAreaCode.value + "" + theForm.textPhone.value + "" + theForm.textSuffix.value;
				if(theForm.textAreaCode.value.length < 3){
						alert(JS_AREACODE_MISSING_ERROR);
						theForm.textAreaCode.focus();
						return false;				
				}else if(theForm.textPhone.value.length < 3){
					alert(JS_PREFIX_PHONE_MISSING_ERROR);
					theForm.textPhone.focus();
					return false;
				}else if(theForm.textSuffix.value.length < 4){
					alert(JS_SUFFIX_PHONE_MISSING_ERROR);
					theForm.textSuffix.focus();
					return false;
				}else{
					if(!isPhone(phoneNumber)){
						alert(JS_PHONE_FORMAT_ERROR);
						theForm.textAreaCode.focus();
						return false;
					}
				theForm.textAreaCode.value = trim(theForm.textAreaCode.value);
				theForm.textPhone.value = trim(theForm.textPhone.value);
				theForm.textSuffix.value = trim(theForm.textSuffix.value);
				}
			}		
				
			//check if the form has an email address field
			if(theForm.textEmailAddress){	
			
				if(theForm.textEmailAddress.value == ""){
					alert(JS_EMAILADDRESS_MISSING_ERROR);
					theForm.textEmailAddress.focus();
					return false;				
				}else{
					if(!isValidEmail(theForm.textEmailAddress.value)){
						alert(JS_EMAILADDRESS_FORMAT_ERROR);
						theForm.textEmailAddress.focus();
						return false;
					}
					theForm.textEmailAddress.value = trim(theForm.textEmailAddress.value);
				}
			}
			
			//check if the form has an email address field- for Unity Email
			if(theForm.EmailAddress){	
			
				if(theForm.EmailAddress.value == ""){
					alert(JS_EMAILADDRESS_MISSING_ERROR);
					theForm.EmailAddress.focus();
					return false;				
				}else{
					if(!isValidEmail(theForm.EmailAddress.value)){
						alert(JS_EMAILADDRESS_FORMAT_ERROR);
						theForm.EmailAddress.focus();
						return false;
					}
					theForm.EmailAddress.value = trim(theForm.EmailAddress.value);
				}
			}
			
			//check date
			if(theForm.textMonth){
				if((theForm.textMonth.value.length < 2) || !isDigit(theForm.textMonth.value)){
					alert(JS_MONTH_MISSING_ERROR)
					theForm.textMonth.focus()
					return false;
				}else{
					if((theForm.textMonth.value <1) || (theForm.textMonth.value >12)){
						alert(JS_MONTH_MISSING_ERROR)
						theForm.textMonth.focus()
						return false;
					}else{
					
					theMonth = theForm.textMonth.value -1
					}
				}
					
				
				if((theForm.textDay.value.length < 2 ) || !isDigit(theForm.textDay.value)){
					alert(JS_DAY_MISSING_ERROR)
					theForm.textDay.focus()
					return false;
				}else{
					if((theForm.textDay.value <1) || (theForm.textDay.value >31)){
						alert(JS_DAY_MISSING_ERROR)
						theForm.textDay.focus()
						return false;
					}else{
					theDay = theForm.textDay.value
					}
				}
				
				if((theForm.textYear.value.length < 4) || !isDigit(theForm.textYear.value)){
					alert(JS_YEAR_MISSING_ERROR)
					theForm.textYear.focus()
					return false;
				}else{
					if(theForm.textYear.value < 1901){
						alert(JS_YEAR_MISSING_ERROR)
						theForm.textYear.focus()
						return false;
					}else{
					theYear = theForm.textYear.value
					}
				}
				
				
				if((theMonth) && (theDay) && (theYear)){
					
					
					if(!isValidDate(theMonth,theDay,theYear)){
						alert(JS_DATE_FORMAT_ERROR)
						return false;
					}else{
						theDate = new Date(theYear, theMonth, theDay)
						today = new Date()
						var oneMinute = 60 * 1000
 						var oneHour = oneMinute * 60
 						var oneDay = oneHour * 24
 						var oneWeek = oneDay * 7
 						var oneYear = oneDay * 365
						
						newDate = Date.parse(today) - Date.parse(theDate)
						newDate = Math.floor(newDate / oneYear)
						if(newDate < 21){
							alert(JS_AGE_INCORRECT_ERROR)
							return false;
						}


						
					}
					
				}
				
			}
				
			//this will validate the start date only if one of the date fields is filed in
			if((theForm.selectDay) || (theForm.selectMonth) || (theForm.selectYear)){
				if((!theForm.selectDay.selectedIndex == "0" ) || (!theForm.selectMonth.selectedIndex == "0") || (!theForm.selectYear.selectedIndex == "0")){
					if(theForm.selectDay.selectedIndex == "0"){
						alert("Please select a Day.")
						theForm.selectDay.focus()	
						return false;
					}
			
			
			
					if(theForm.selectMonth.selectedIndex == "0"){
						alert("Please select a Month.");
						theForm.selectMonth.focus();
						return false;
					}
				
				
			
					if(theForm.selectYear.selectedIndex == "0"){
						alert("Please select a Year.");
						theForm.selectYear.focus()
						return false;
					}
				
					if(!isValidDate(theForm.selectMonth.value,theForm.selectDay.value,theForm.selectYear.value)){
							alert("Please select a valid date.")
							return false;
					}else{
						//alert("the index" + theForm.selectYear.selectedIndex)
						theDate = new Date(theForm.selectYear.options[theForm.selectYear.selectedIndex].value,theForm.selectMonth.options[theForm.selectMonth.selectedIndex].value,theForm.selectDay.options[theForm.selectDay.selectedIndex].value)
						today = new Date()
						
						theMonth = theDate.getMonth()-1
						theDay = theDate.getDate()
						theYear = theDate.getFullYear()
						
						
						todayMonth = today.getMonth()
						todayDay = today.getDate()
						todayYear = today.getFullYear()
						
						
						chosenDate = new Date(theYear, theMonth, theDay)
						compareDate = new Date(todayYear, todayMonth, todayDay)
						
							
						if(Date.parse(compareDate) < Date.parse(chosenDate)){
							alert("Sorry you can't use a date in the future. Please enter a new date.")
							return false
						}
						
						
					}
						
										
			
				}
			}
			
			
				
				
				
			
			//check if the form has a username field
			if(theForm.textUsername){	
				if(theForm.textUsername.value == ""){
					alert(JS_USERNAME_MISSING_ERROR);
					theForm.textUsername.focus();
					return false;
				}else{
					if(!isValidEmail(theForm.textUsername.value)){
						alert(JS_EMAILADDRESS_FORMAT_ERROR);
						theForm.textUsername.focus();
						return false;
					}
					theForm.textUsername.value = trim(theForm.textUsername.value);
				}
			}
			
			
			//check if the form has a password field
			if(theForm.textPassword){	
			theSize = trim(theForm.textPassword.value)
				if(theForm.textPassword.value == ""){					
						alert(JS_PASSWORD_MISSING_ERROR);
						theForm.textPassword.focus()
						return false;
					
				}else if(theSize.length == 0) {
					alert(JS_PASSWORD_FORMAT_ERROR)
					theForm.textPassword.value=""
					theForm.textConfirm.value=""
					theForm.textPassword.focus()
					return false;
				}else{
					if((theForm.textPassword.value.length < 6) ||(theForm.textPassword.value.length >16)){
						if(!isPassword(theForm.textPassword.value)){
									alert(JS_PASSWORD_FORMAT_ERROR);
									theForm.textConfirm.value=""	
									theForm.textPassword.value=""
									theForm.textConfirm.focus();
									return false;
								}else{
									alert(JS_PASSWORD_SIZE_ERROR);
									theForm.textPassword.focus()
									return false;
								}
					}else{
						if(theForm.textConfirm){
							if(theForm.textPassword.value != theForm.textConfirm.value){
								alert(JS_PASSWORD_CONFIRMATION_ERROR)								
								theForm.textConfirm.value=""	
								theForm.textPassword.value=""
								theForm.textConfirm.focus()					
								return false;
							}else{
								if(!isPassword(theForm.textPassword.value)){
									alert(JS_PASSWORD_FORMAT_ERROR);
									theForm.textConfirm.value=""	
									theForm.textPassword.value=""
									theForm.textConfirm.focus();
									return false;
								}
							theForm.textPassword.value = trim(theForm.textPassword.value)
							}
						}
					}
				}
			}	
			
			if(theForm.textLoginPWD){
			theSize = trim(theForm.textLoginPWD.value)
				if((theForm.textLoginPWD.value=="")||(theSize.length == 0)){
					alert(JS_LOGINPWD_MISSING_ERROR);
					theForm.textLoginPWD.focus()
					return false;
				}else{
					if((theForm.textLoginPWD.value.length < 6) ||(theForm.textLoginPWD.value.length >16)){
						alert(JS_PASSWORD_SIZE_ERROR);
						theForm.textLoginPWD.focus();
						return false;
					}
				}
						
			}
			
			//check that the reminder of lost passwords is set
			if((theForm.selectReminder) && (theForm.textReminder)){
				if(theForm.selectReminder.selectedIndex == 0){
					alert(JS_REMINDER_QUESTION_MISSING_ERROR)
					theForm.textReminder.selectedIndex = 0
					return false
				}else{
					if(trim(theForm.textReminder.value) == ""){
						alert(JS_REMINDER_MISSING_ERROR)
						theForm.textReminder.focus()
						return false;
					}else{
						if(!isAlphaNumeric(theForm.textReminder.value)){
							alert(JS_REMINDER_FORMAT_ERROR);
							theForm.textReminder.focus();
							return false;
						}
					theForm.textReminder.value = trim(theForm.textReminder.value)
					}
				}
			}
			
			//check the method comparitor
			if(theForm.checkMethod){
			
				counter = 0
				for(i=0; i<theForm.elements.length; i++){
					if(theForm.elements[i].checked){
						counter += 1;
				}
			}
			if(counter == 0){
				alert(JS_METHOD_MIN_ERROR);
				return false;
			}
			
			if(counter > 2){
				alert(JS_METHOD_MAX_ERROR)
				return false;
			}
		}
				
		//check sending page - friend name		
		if(theForm.textFriendName){
				if(trim(theForm.textFriendName.value) == ""){
					alert("Please enter your friend's name.");
					theForm.textFriendName.focus();
					return false;
				}				
				else{
				theForm.textFriendName.value = trim(theForm.textFriendName.value);
			}
		}				

			//check sending page - your email
		if(theForm.textFriendEmail){	
			
				if(trim(theForm.textFriendEmail.value) == ""){
					alert("Please enter your friend's mail address.");
					theForm.textFriendEmail.focus();
					return false;				
				}else{
					if(!isValidEmail(theForm.textFriendEmail.value)){
						alert("Please enter your friend's mail address in valid e-mail format.");
						theForm.textFriendEmail.focus();
						return false;
					}
					theForm.textFriendEmail.value = trim(theForm.textFriendEmail.value);
				}
			}
		//check sending page - your name					
		if(theForm.textYourName){
			if(trim(theForm.textYourName.value) == ""){
				alert("Please enter your name.");
				theForm.textYourName.focus();
				return false;
				}				
				else{
				theForm.textYourName.value = trim(theForm.textYourName.value);
			}
		}		
		
		//check sending page - your email
		if(theForm.textYourEmail){	
			
				if(trim(theForm.textYourEmail.value) == ""){
					alert("Please enter your mail address.");
					theForm.textYourEmail.focus();
					return false;				
				}else{
					if(!isValidEmail(theForm.textYourEmail.value)){
						alert("Please enter your mail address in valid e-mail format.");
						theForm.textYourEmail.focus();
						return false;
					}
					theForm.textYourEmail.value = trim(theForm.textYourEmail.value);
				}
			}
		
		if(theForm.textMessage){	
			
				if (!isMessageCommentLengthOK(theForm.textMessage.value,500)){
					alert("too long");
					theForm.textMessage.focus();
					return false;				
				}
			}
		
		//checks length of rep connect email message, max 500 chars
		if(theForm.repConnectMsg){	
			
				if (!isMessageCommentLengthOK(theForm.repConnectMsg.value,500)){
					alert(JS_COMMENTS_MESSAGE_TOO_LONG);
					theForm.repConnectMsg.focus();
					return false;				
				}
			}
			
		//checks search string input
		if(theForm.searchInput){
			if(trim(theForm.searchInput.value)==""){
				alert(JS_SEARCH_MISSING_ERROR);
				theForm.searchInput.focus();
				return false;
			}else{
				if(!isAlphaNumeric(theForm.searchInput.value)){
					alert(JS_SEARCH_FORMAT_ERROR);
					theForm.searchInput.focus();
					return false;
				}
			}
		}
		return true;
}
	
	
//sweepstakes validation
//this code will check to ensure all the questions in the survey are filled in
function validateSurvey(theForm, theNumber){

			total = 0
			for(i=0; i<theForm.elements.length; i++){
				beenChecked = false;
				
				//get the name of the element
				theName = theForm.elements[i].name
				
				//check if the name is the current element
				if(theName == theForm.elements[i].name){
					if(theForm.elements[i].checked){
						beenChecked = true;				
					}else{
						//alert("nope")
						beenChecked = false;
					}			
				}
				
				//check if the the element has been checked
				if(beenChecked){
					total++
				}
				
			}
			
			
			if(total < theNumber){
				alert(JS_MISSING_RESPONSES);
				return false;
			}
			return true;
}
		
	
		

//Declare variables
blanks = " \t\n\r"; 

// Removes leading blank chars (as defined by blanks) from s

function stripLeadingBlanks(s)
  { 
  var i = 0;
  while ((i < s.length) && (blanks.indexOf(s.charAt(i)) != -1))
     i++;
  return s.substring(i, s.length);
  }


// Removes trailing blank chars (as defined by blanks) from s

function stripTrailingBlanks(s)
  { 
  var i = s.length - 1;
  while ((i >= 0) && (blanks.indexOf(s.charAt(i)) != -1))
     i--;
  return s.substring(0, i+1);
  }


// Removes leading+trailing blank chars (as defined by blanks) from s

function stripLeadingTrailingBlanks(s)
  { 
  s = stripLeadingBlanks(s);
  s = stripTrailingBlanks(s);
  return s;
  }



// This function checks the postive integer entry
function isPositiveInteger(inte2){
	 inte=stripLeadingTrailingBlanks(inte2)
	 ok=true;
	 if (inte.length==0)
	 { ok=false;
	 }
	  for (i=0;i<inte.length;i++ )
	  { 
		   theChar=inte.charAt(i);
		   if ((theChar<"0")||(theChar>"9"))
		   {
			   ok=false;
			   break;
		   } 
		   if (eval(inte)<=0)
		   {
			   ok=false;
			   break;
		   }
	  }
	  return ok;
}

// This function check email address 
function isEmail_bak(email2){
	 ok=true;
	 email=stripLeadingTrailingBlanks(email2).toLowerCase();
	 if ((email.indexOf('@')<1) || ((email.indexOf('.com')<3) && (email.indexOf('.edu')<3)&&(email.indexOf('.net')<3) && (email.indexOf('.gov')<3)&&(email.indexOf('.mil')<3) && (email.indexOf('.org')<3)))
	 { ok=false;
	 }
	 return ok;
}


// This function check email address 
function isEmail_bak(email2){
	 ok=true;
	 email=stripLeadingTrailingBlanks(email2).toLowerCase();
	 if ((email.indexOf('@')<1) || ((email.indexOf('.com')<3) && (email.indexOf('.edu')<3)&&(email.indexOf('.net')<3) && (email.indexOf('.gov')<3)&&(email.indexOf('.mil')<3) && (email.indexOf('.org')<3)))
	 { ok=false;
	 }
	 return ok;
}

//check if the passed string is vaid email address characters
function isEmailChars(str){
	var theText = /^[\@\.a-z0-9_-]+$/gi;
		var result = str.match(theText);
		if(result != null){
			return true;			
		}else{
			return false;
		}

}

// check if the passed string is vaid email address 
function isValidEmail(strEmail){
   if (trim(strEmail)=='')
	{
	return false;
	}

   if (!isEmailChars(strEmail))
	{  
	return false;
	}
   var emailPattern = /^[a-z0-9]+([_.-][a-z0-9]+)*@[a-z0-9]+([-.][a-z0-9]+)*[.]{1}[a-z]{2,}$/gi;
   var result = strEmail.match(emailPattern);
   if(result != null)
	{
	return true;
	} else 
	{
	return false; 
	}		
}

//Check email (tested by QA)
function isEmail(emailStr) {

/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */

   var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ] */

   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */

   var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */

   var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */

   var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of
   non-special characters.) */

   var atom=validChars + '+';

/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */

   var word="(" + atom + "|" + quotedUser + ")";

/* The following pattern describes the structure of the user */

   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */

   var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */

   var matchArray=emailStr.match(emailPat);

/* Too many/few @'s or something; basically, this address doesn't
      even fit the general mould of a valid e-mail address. */

   if (matchArray==null) {
	 // alert("Please enter a valid e-mail address.");
	  return false;
   }

   var user=matchArray[1];
   var domain=matchArray[2];

/* See if "user" is valid */

   if (user.match(userPat)==null || user.indexOf("\"\"")>=0) {
      // user is not valid

      if (user.indexOf("@")>=0) {
       // alert("Your e-mail address contains more than one \'@\' symbol.\nPlease remove any additonal \'@\' symbols.");
      }
      else {
       // alert("Please enter a valid username.");
      }
      return false;
   }

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */

   var IPArray=domain.match(ipDomainPat);

   if (IPArray!=null) {
      // this is an IP address

	  for (var i=1;i<=4;i++) {

	     if (IPArray[i]>255) {
	       // alert("Please check that your IP address is correct.");
		    return false;
	     }

      }
      return true;
   }

/* Domain is symbolic name */

   var domainArray=domain.match(domainPat);

   if (domainArray==null) {
     // alert("Please enter a valid domain name or IP address.");
      return false;
   }

/* domain name seems valid, but now make sure that it ends in a
   minimum two-letter word and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */

   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;
   var domStr=domArr+"";
   var posDom=domStr.indexOf(",");

/* the address must end with a minimum of two letter domain. */

   if (domArr[domArr.length-1].length<2 && posDom>0) {
     // alert("The e-mail address must end with a minimum of two characters.");
      return false;
   }

/* Make sure there's a host name preceding the domain. */

   if (len<2) {
      //alert("Please enter a valid domain name.");
      return false;
   }

/* If we've gotten this far, everything's valid! */

   //alert("You have inputed a valid e-mail address.");
   return true;
}



//This function checks leap year
function isLeapYear(intYear) {
	if (intYear % 100 == 0){
		if (intYear % 400 == 0) {
			return true; 
		}
    }  else {
		if ((intYear % 4) == 0) { 
			return true; 
		}
    } //end if
	return false;
} //end function


//This checks that if valid date range checked
function isValidDate(smonth,sday,syear){
	if ((smonth=='')||(sday=='')||(syear==''))
	{
		return false;
	}
    if (((smonth==4)||(smonth==6)||(smonth==9)||(smonth==11))&&(sday>30)){
	return false;
	}
	
	//check leap year and Feb. entry
	if (smonth==2){
	  if ((isLeapYear(syear))&&(sday>29)){
	    return false;
	   } 
	    if ((!isLeapYear(syear))&&(sday>28)){
	    return false;
	   } 
	}	
   return true;
}

function isDigit(str){
	var theText = /^[0-9]+$/;
		var result = str.match(theText);
		if(result != null){
			//isValid=true;
			return true;
			
		}else{
			return false;
		}
}

//check alpha only
function isAlpha(str){
	var theText = /^[\'\sa-zA-Z_-]+$/;
		var result = str.match(theText);
		if(result != null){
			//isValid=true;
			return true;
			
		}else{
			return false;
		}

}



function isValidAddress(str){

	var theText =  /^([ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿa-zA-Z0-9]+[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ\'\#\,\'\s\.a-zA-Z0-9_-]*)$/;
	var result = str.match(theText);
		if(result != null){
			return true;
			
		}else{
			return false;
		}

}



//check alphanumeric 
function isAlphaNumeric(str){
	var theText = /^([ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿa-zA-Z0-9]+[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ\'\s\.a-zA-Z0-9_-]*)$/;
		var result = str.match(theText);
		if(result != null){
			return true;
			
		}else{
			return false;
		}

}

//check length of a field
function isFieldLengthOK (strField,min, max){
	if ((trim(strField).length<=max) && (trim(strField).length>=min))
	{
		return true;
	} else {
		return false;
	}
}


//check alphanumeric 
function isWhateverDoesNotFitInAnother(str){
	var theText = /^[\'\s\.#a-zA-Z0-9_-]+$/;
		var result = str.match(theText);
		if(result != null){
			//isValid=true;
			return true;
			
		}else{
			return false;
		}

}

//check valid password entry
function isPassword(str){
	var theText = /^[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ!@#\$%^&*\(\)a-zA-Z0-9_-]+$/;
		var result = str.match(theText);
		if(result != null){
			
			return true;
			
		}else{
			return false;
		}

}

function isZipCode(str){

	if(str.length == 5){
		var theDigit = /\d{5}/;
	}else if(str.length == 9){
		var theDigit = /\d{9}/;
	}else if(str.length == 10){
		var theDigit = /\d{5}-\d{4}/;
	}else{
		return false
	}
		var result = str.match(theDigit);
		if(result != null){
			//isValid=true;
			return true;
			
		}else{
			return false;
		}
}

function isPhone(str){
	if(str.length == 10){
		var theFormat = /\d{10}/;
		var result = str.match(theFormat);
		if(result != null){
			return true;
		}else{
			return false;
		}
	}
}

// This function check if the string is a valid search input
function isValidInternationlSearch(strName){
	strName=stripLeadingTrailingBlanks(strName);
	if ((strName==empty)||(strName==dash)||(strName==underscore)||(strName==apostrophe))
	{
		return false;
	} else {
		for (i=0;i<strName.length;i++ )
		{ 
			badChar=strName.charAt(i);
			invalidChar2=invalidChar+period;
			if (invalidChar2.indexOf(badChar)!=-1)
			{
            return false;
			break;
			}
		}
		return true;
	}
}

// This function check the comments/message length
function isMessageCommentLengthOK(strComment,len){
	if ((trim(strComment)).length>len){
		return false;
	}
	return true;
}




function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also
   // removes consetrimive spaces and replaces it with one space.
   
   var returnValues = inputString;
   var ch = returnValues.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      returnValues = returnValues.substring(1, returnValues.length);
      ch = returnValues.substring(0, 1);
   }
   ch = returnValues.substring(returnValues.length-1, returnValues.length);
   while (ch == " ") { // Check for spaces at the end of the string
      returnValues = returnValues.substring(0, returnValues.length-1);
      ch = returnValues.substring(returnValues.length-1, returnValues.length);
   }
   while (returnValues.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      returnValues = returnValues.substring(0, returnValues.indexOf("  ")) + returnValues.substring(returnValues.indexOf("  ")+1, returnValues.length); // Again, there are two spaces in each of the strings
   		
   }
   
   
   return returnValues; // Return the trimmed string back to the user
} // Ends the "trim" function



//print from javascript
function printWindow(){
	if (window.print){
		window.print()		
	}else{
		alert("You will need to use File->Print from the menu bar.")
	}
}

// Check if the DIN is in the correct format.
function isValidDIN(form_name)
{
	var strippedDIN=stripLeadingTrailingBlanks(form_name.textDIN.value);
	if (strippedDIN.length!=8)
	{
		alert("Please enter a valid DIN and try again.");
		return false;
	}
	return true;
}


// SMS phone validation function
function isPhoneNo(strPhone) {
  strPhone=trim(strPhone);
  if (strPhone=='')
  {
	  return false;
  }

  for (j=0; j<strPhone.length; j++) {
      if ((strPhone.charAt(j)!= dash)&& (strPhone.charAt(j)!= slash)&&(strPhone.charAt(j)!= open_bracket)&&(strPhone.charAt(j)!= close_bracket)&&(strPhone.charAt(j)!= space)&&((!isDigit(strPhone.charAt(j))))) {
		  return false;
		  break;
	  } 
  }
  return true;
}

// Check the data entry for sms form
function checkEntry(form){
	
	if (trim(form.textFirstName.value)=='')
	{	
		alert (JS_FIRSTNAME_MISSING_ERROR);
		form.textFirstName.focus();
		return false;
	}
	if (trim(form.textLastName.value)=='')
	{	
		alert (JS_LASTNAME_MISSING_ERROR);
		form.textLastName.focus();
		return false;
	}	
	if (trim(form.textDin.value)=='')
	{	
		alert (JS_DIN_FORMAT_ERROR);
		form.textDin.focus();
		return false;
	}
	if (!isPhoneNo(form.textPhone.value))
	{	
		alert (JS_SMS_PHONE_FORMAT_ERROR);
		form.textPhone.focus();
		return false;
	}	
	if ((!isValidEmail(form.textEmail.value))&&(trim(form.textEmail.value)!=''))
	{
		alert (JS_EMAILADDRESS_FORMAT_ERROR);
		form.textEmail.focus();
		return false;
	}

	if (!isValidDate(form.selectMonth.options[form.selectMonth.selectedIndex].value,form.selectDay.options[form.selectDay.selectedIndex].value,form.selectYear.options[form.selectYear.selectedIndex].value))
	{
		alert(JS_DATE_FORMAT_ERROR);
		form.selectMonth.focus();
		return false;
	}
	return true;
}

// check smsRmeinder unsubscribe form entry
function checkSMSUnsubscribeEntry(form){
	if (!isPhoneNo(form.textPhone.value))
	{	
		alert (JS_SMS_PHONE_FORMAT_ERROR);
		form.textPhone.focus();
		return false;
	} 
	
	if (!confirm(JS_SMS_UNSUBSCRIBE_CONFIRM))
	{
		return false;
	}

	return true;
}

// cbeck contact us form entry
function checkContactUsFormEntry(form){
	if (trim(form.textFirstName.value)=='')
	{	
		alert (JS_FIRSTNAME_MISSING_ERROR);
		form.textFirstName.focus();
		return false;
	}
	if (trim(form.textLastName.value)=='')
	{	
		alert (JS_LASTNAME_MISSING_ERROR);
		form.textLastName.focus();
		return false;
	}	
	
	if (trim(form.textEmail.value)=='')
	{
		alert (JS_EMAILADDRESS_MISSING_ERROR);
		form.textEmail.focus();
		return false;
	}
	
	if (!isValidEmail(form.textEmail.value))
	{
		alert (JS_EMAILADDRESS_FORMAT_ERROR);
		form.textEmail.focus();
		return false;
	}
	if (trim(form.textareaMessage.value)=='')
	{	
		alert (JS_SMS_CONTACT_US_MESSAGE_MISSING);
		form.textareaMessage.focus();
		return false;
	}else if (!isMessageCommentLengthOK(form.textareaMessage.value,500)){
		alert (JS_COMMENTS_MESSAGE_TOO_LONG);
		form.textareaMessage.focus();
		return false;
	}

}

// Function for segment navigation
function changeUrl(url){

	window.location.href=url;
}

// Function for media login and registration
function checkMediaLoginForm(form){
	if (form.firstname){
		if (trim(form.firstname.value)=='')
		{	
			alert (JS_FIRSTNAME_MISSING_ERROR);
			form.firstname.value='';
			form.firstname.focus();
			return false;
		}
		if (!isAlphaNumeric(trim(form.firstname.value)) ||!isFieldLengthOK(trim(form.firstname.value),1, 35) )
		//	if (!isFieldLengthOK(trim(form.firstname.value),1, 35))
		{
			alert (JS_FIRSTNAME_FORMAT_ERROR);
			form.firstname.focus();
			return false;
		}
	}
	if (form.lastname){
		if (trim(form.lastname.value)=='')
		{	
			alert (JS_LASTNAME_MISSING_ERROR);
			form.lastname.value='';
			form.lastname.focus();
			return false;
		}
		if (!isAlphaNumeric(trim(form.lastname.value)) ||!isFieldLengthOK(trim(form.lastname.value),1, 35) )
		{
			alert (JS_LASTNAME_FORMAT_ERROR);
			form.lastname.focus();
			return false;
		}
	}
	if (form.email){
		if (trim(form.email.value)=='')
		{
			alert (JS_EMAILADDRESS_MISSING_ERROR);
			form.email.value='';
			form.email.focus();
			return false;
		}
		if (!isValidEmail(form.email.value))
		{
			alert (JS_EMAILADDRESS_FORMAT_ERROR);
			form.email.focus();
			return false;
		}
	}
	if (form.password){		
		if (trim(form.password.value)=='')
		{
			alert (JS_PASSWORD_MISSING_ERROR);
			form.password.value='';
			form.password.focus();
			return false;
		}
		if (!isPassword(trim(form.password.value))|| !isFieldLengthOK(trim(form.password.value),6, 16))
		{
			alert (JS_PASSWORD_SIZE_ERROR);
			form.password.value='';
			form.password.focus();
			return false;
		}
		
		if (form.confirmpassword){
			if (trim(form.confirmpassword.value)=='')
			{
				alert (JS_PASSWORD_CONFIRMATION_ERROR);
				form.confirmpassword.value='';
				form.confirmpassword.focus();
				return false;
			}
			if (trim(form.confirmpassword.value).toLowerCase()!=trim(form.password.value).toLowerCase()){
				alert (JS_PASSWORD_CONFIRMATION_ERROR);
				form.confirmpassword.value='';
				form.confirmpassword.focus();
				return false;
			}
		}	//end if (form.confirmpassword)
	}//end if (form.password)
	
	if (form.organization){		
		if (trim(form.organization.value)=='')
		{
			alert (JS_ORGANANIZATION_MISSING_ERROR);
			form.organization.value='';
			form.organization.focus();
			return false;
		}
		if (!isAlphaNumeric(trim(form.organization.value)) ||!isFieldLengthOK(trim(form.organization.value),1, 100) )
		{
			alert (JS_ORGANANIZATION_FORMAT_ERROR);
			form.organization.focus();
			return false;
		}
	}
}

function validatePatientLoginform(form)
{
	if (!(document.patient.patient[0].checked)&& !(document.patient.patient[1].checked)){
		alert(JS_PATIENT_LOGIN_NOCHECK);
		return false;
	}
		
	return true;
}
//-->