function validatenew()
{
	strErrorMessage = "";
			
	// *** G E N E R A L   F O R M   V A L U E S ***
	if (document.reg.fname.value.length == 0)
		{
		strErrorMessage += "You must enter your first name.\n";
		}
	if (document.reg.lname.value.length == 0)
		{
		strErrorMessage += "You must enter your last name.\n";
		}
	if (document.reg.email.value.length < 5)
		{
		strErrorMessage += "You must enter your email address.\n";
		}
		
		var strEmail=document.reg.email.value;
		var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,4}$/;

		if(((strEmail.search(exclude) != -1)||(strEmail.search(check)) == -1)||(strEmail.search(checkend) == -1))
		{
		strErrorMessage += "Please Enter A valid Email address.\n";
		}		
		
	if (document.reg.dob_month.selectedIndex == 0)
		{
		strErrorMessage += "You must the month of your birthdate.\n";
		}
	if (document.reg.dob_day.selectedIndex == 0)
		{
		strErrorMessage += "You must the day of your birthdate.\n";
		}
	if (document.reg.dob_year.selectedIndex == 0)
		{
		strErrorMessage += "You must the year of your birthdate.\n";
		}

	var dt=document.reg.dob_month.value
	dt += "/";
	dt += document.reg.dob_day.value;
	dt += "/";
	dt += document.reg.dob_year.value;
	if (isDate(dt)==false)
		{
		strErrorMessage += "Please enter a valid birthdate.\n";
		}
	
	if (document.reg.pass.value.length == 0)
		{
		strErrorMessage += "You must enter a password.\n";
		}
	if (document.reg.pass.value.length < 6)
		{
		strErrorMessage += "Passwords must be at least 6 characters long.\n";
		}		
	if (document.reg.pass2.value.length == 0)
		{
		strErrorMessage += "Please confirm your password.\n";
		}
	if (document.reg.pass.value != document.reg.pass2.value)
		{
		strErrorMessage += "Your password and password confirmation do not match.  Please re-enter them.\n";
		}
	
	var UserPassword = document.reg.pass.value;
	var exclude=/@@/;
	if (UserPassword.search(exclude) != -1)
		{
		strErrorMessage += "Your password may not contain the @@ symbols.  Please change your password.\n";
		}
		
	if (document.reg.sex)
		{
		if (!document.reg.sex[0].checked && !document.reg.sex[1].checked)
			{
			strErrorMessage += "Please select your gender..\n";
			}
		}
		
	//if (document.reg.sadd.value.length == 0)
	//	{
	//	strErrorMessage += "You must enter an address.\n";
	//	}
	//if (document.reg.city.value.length == 0)
	//	{
	//	strErrorMessage += "You must enter your city.\n";
	//	}
	//if ((document.reg.cty.value == 1) && (document.reg.state.selectedIndex == 0))
	//	{
	//	strErrorMessage += "You must select your state.\n";
	//	}
	//else
	//	{
	//	If document.reg.state.value.length < 3
	//		{
	//		strErrorMessage += "You must enter your state/province.\n";
	//		}
	//	}
	//if ((document.reg.cty.value == 1) && (document.reg.zip.value.length < 5))
	//	{
	//	strErrorMessage += "Please enter a valid zip code.\n";
	//	}
	//else
	//	{
	//	if (document.reg.zip.value.length == 0)
	//		{
	//		strErrorMessage += "You must enter your zip code.\n";
	//		}
	//	}
	
	
	if (document.reg.dnum.value.length < 10)
		{
		strErrorMessage += "You must enter a valid phone number.\n";
		}

	// SHOULD WE SUBMIT
	if (strErrorMessage==''|| strErrorMessage==null)
		{
		//there was no error
		document.reg.submit();
		return (true);
		}
	else
		{
		//display the error and do not allow them to submit
		alert (strErrorMessage);
		return (false);
		}					
}



function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) 
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
	
return true
}

function validateNameCorrection()
{
    var strErrorMessage = "";
    if (document.frmNameCorrection.strFirstName.value.length == 0) {
        strErrorMessage += "You must enter your first name.\n";
    }
    if (document.frmNameCorrection.strLastName.value.length == 0) {
        strErrorMessage += "You must enter your last name.\n";
    }
    if (document.frmNameCorrection.txtDayPhoneAreaCode.value.length == 0 || document.frmNameCorrection.txtDayPhoneAreaCode.value.length < 3 || document.frmNameCorrection.txtDayPhoneAreaCode.value.length > 3) {
        strErrorMessage += "Please Enter a valid phone area code.\n";
    }

    if (document.frmNameCorrection.txtDayPhone.value.length == 0 || document.frmNameCorrection.txtDayPhone.value.length < 7 || document.frmNameCorrection.txtDayPhone.value.length > 7) {
        strErrorMessage += "Please Enter a valid phone number.\n";
    }
    
    if (IsPhone(document.frmNameCorrection.txtDayPhoneAreaCode.value.replace("-","")) == false)
    {
        strErrorMessage += "Please enter a valid numeric value for area code!\n" ;
    }

    if (IsPhone(document.frmNameCorrection.txtDayPhone.value.replace("-","")) == false)
    {
        strErrorMessage += "Please enter a valid numeric value for phone number!\n" ;
    }    

    // SHOULD WE SUBMIT
    if (strErrorMessage == '' || strErrorMessage == null) {
        //there was no error
        document.frmNameCorrection.submit();
        return (true);
    }
    else 
    {
        //display the error and do not allow them to submit
        alert(strErrorMessage);
        return (false);
    }	
}

//  check for valid numeric strings	
function IsNumeric(strString)
{
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
   {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
      }
   }
   
   return blnResult;
}

function IsPhone(strString)
{
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
   {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
      }
   }
   
   return blnResult;
}

function GetInvalidPhoneMessage()
{
    return "Please enter a valid phone number. Numbers only." ;
}

function IsAlphaNumeric(valueToCheck)
{
    var check=/^[0-9A-Za-z]+$/; //alphanumeric only
    if(valueToCheck.search(check) == -1)
    {
        return false
    }

    return true ;
}

function IsNumeric(valueToCheck)
{
    var check=/^[0-9]+$/; //numeric only
    if(valueToCheck.search(check) == -1)
    {
        return false
    }

    return true ;
}

function IsAlpha(valueToCheck)
{
    var check=/^[A-Za-z]+$/; //alpha only
    if(valueToCheck.search(check) == -1)
    {
        return false
    }

    return true ;
}

function IsValidName(valueToCheck)
{
    if(valueToCheck.length < 2)
        return false;

    return IsAlpha(valueToCheck) ;    
}

function GetInvalidNameMessage(firstOrLast)
{
    var message = "You must enter a valid " + firstOrLast + " name. " + toProperCase(firstOrLast) + " name must be at least 2 characters long. Letters only.\n" ;
    return message ;
}

function IsValidPassword(valueToCheck)
{
    if(valueToCheck.length < 6)
        return false;
    
    return IsAlphaNumeric(valueToCheck) ;
}

function GetInvalidPasswordMessage()
{
    return "Please enter a valid password.  Passwords must be at least 6 characters long.  Letters and numbers only.\n" ;
}

function IsValidEmailAddress(valueToCheck)
{
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,5}$/;

    var completeCheck=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,5}$/;
        
    //regular expresion:
    //1. /^[a-zA-Z0-9._-]+:  Means that the email address must begin with alpha-numeric characters (both lowercase and uppercase characters are allowed). It may have periods,underscores and hyphens.
    //2. @:   There must be a ‘@’ symbol after initial characters.
    //3. [a-zA-Z0-9.-]+: After the ‘@’ sign there must be some alpha-numeric characters. It can also contain period (’.') and and hyphens(’-').
    //4. \.: After the second group of characters there must be a period (’.'). This is to separate domain and subdomain names.
    //5. [a-zA-Z]{2,5}$/: Finally, the email address must end with two to five alphabets. Having a-z and A-Z means that both lowercase and uppercase letters are allowed.
	if(((valueToCheck.search(exclude) != -1)||(valueToCheck.search(check)) == -1)||(valueToCheck.search(checkend) == -1))
	{
	    return false;	    
	}
	
	//redundancy check
    if(valueToCheck.search(completeCheck) == -1)
    {
        return false;
	}
	
	if (valueToCheck.length < 5)
	    return false ;
	    
	return true
}

function GetInvalidEmailMessage()
{
    return "Please Enter a valid Email address.  Email address must be at least 5 characters long.\n";
}

function checkInternationalPhone(strPhone)
{
    var bracket=3;
    strPhone=trim(strPhone);
    if(strPhone.length == 0) return false;
    if(strPhone.indexOf("+")>1) return false;
    if(strPhone.indexOf("-")!=-1) bracket=bracket+1;
    if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket) return false;
    var brchr=strPhone.indexOf("(");
    if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")") return false;
    if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1) return false;
    s=stripCharsInBag(strPhone,validWorldPhoneChars);
    return (isInteger(s) && s.length >= minDigitsInIPhoneNumber && s.length <= minDigitsInIPhoneNumber);
}

function GetInvalidInternationPhoneMessage()
{
    return "You must enter a proper phone number.\ne.g. 212-555-5555.  Phone number can not be blank.\n";
}

function IsValidSevenDigitNumericPhone(valueToCheck)
{
    if(valueToCheck.length < 7)
        return false;
        
    return IsNumeric(valueToCheck) ;
}

function GetInvalidSevenDigitNumericPhone()
{
    return "Please enter a valid phone number.  Seven digits numeric only." ;
}

function IsValidTenDigitNumericPhone(valueToCheck)
{
    if(valueToCheck.length < 10)
        return false;
        
    return IsNumeric(valueToCheck) ;
}

function GetInvalidTenDigitNumericPhone()
{
    return "Please enter a valid phone number. A phone number must include area code plus phone number with not spaces or alpha characters.  Example: 4805551212\n";
}

function toProperCase(s)
{
  return s.toLowerCase().replace(/^(.)|\s(.)/g, 
          function($1) { return $1.toUpperCase(); });
}


