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
}
