function notValidEmail(str){
    mailRE = new RegExp( );
    mailRE.compile( '^[\._a-z0-9-]+@[\.a-z0-9-]+[\.]{1}[a-z]{2,4}$', 'gi' );
    return !(mailRE.test( str.value ));
} 
function isEmpty(str){
    strRE = new RegExp( );
    strRE.compile( '/^[\s ]*$/', 'gi' );
    return strRE.test( str.value );
} 

function validateIndex(frm)
{
    //check if form fields are filled
    zip = frm.elements['zip'].value;
	ageMin = frm.elements['ageMin'].value;
    ageMax = frm.elements['ageMax'].value;
    
    if (!((/^\d{5}$/.test(zip)) || (/^\w\d\w\d\w\d$/.test(zip))))
    {
    	alert( 'Please enter a valid zip code.' ); 
    	frm.elements['zip'].focus();
    	return false;
    }
    
    if (ageMax < ageMin)
    {
    	alert('Age range incorrect.');
    	frm.elements['ageMin'].focus();
    	return false;
    }
    
    return true;
}

function validate2( form ){
    //check if form fields are filled
	
	if( form.birthday_month.value=="0" ){ alert( 'Please enter the month of your birth.' ); form.birthday_month.focus();return false; }
	if( form.birthday_day.value=="0" ){ alert( 'Please enter the day of your birth.' ); form.birthday_day.focus();return false; }
	if( form.birthday_year.value=="0" ){ alert( 'Please enter the year of your birth.' ); form.birthday_year.focus();return false; }
	
	if( form.screenname.value == "" ){ alert( 'Please enter your desired screen name.' ); form.screenname.focus();return false; }
	if( form.screenname.value.length < 4 ){ alert( 'Screen name must be 4 or more characters.' ); form.screenname.focus();return false; }
	if(!/^[a-zA-Z0-9_\-]+$/.test(form.screenname.value)) {alert( 'Screen Name can only contain A-Z, a-z, 0-9, - (dash), and _ (underscore).' ); form.screenname.focus();return false; }
	if(!/^[a-zA-Z]/.test(form.screenname.value.substring(0, 1))) {alert( 'Screen Name must must start with a letter.' ); form.screenname.focus();return false; }

	if( form.password.value == "" ){ alert( 'Please enter the password.' ); form.password.focus();return false; }
//	if( isEmpty( form.confirm_password ) ){ alert( 'Please confirm the password.' ); form.confirm_password.focus();return false; }
//	if(form.password.value != form.confirm_password.value) { alert( 'Passwords do not match.' ); form.confirm_password.focus();return false; }
	if( (form.password.value.length < 4)  || (! /^[a-zA-Z0-9_\-.]+$/.test(form.password.value)) || (form.password.value == 'password') || (form.password.value == form.screenname.value)){ alert( 'Password must be at least 4 characters and cannot equal your chosen username or \'password\', and can only contain A-Z, a-z, 0-9, - (dash), and _ (underscore).' ); form.password.focus();return false; }
//	if( (form.confirm_password.value.length < 4)  || (! /^[a-zA-Z0-9_\-.]+$/.test(form.confirm_password.value)) || (form.confirm_password.value == 'password') || (form.confirm_password.value == form.screenname.value)){ alert( 'Password must be at least 4 characters and cannot equal your chosen username or \'password\', and can only contain A-Z, a-z, 0-9, - (dash), and _ (underscore).' ); form.confirm_password.focus();return false; }
	
    if( notValidEmail( form.email ) ){alert( 'Empty or incorrect email address.' ); form.email.focus();return false; }
//    if( notValidEmail( form.confirm_email ) ){alert( 'Empty or incorrect confirmation email address.' ); form.confirm_email.focus();return false; }
//    if( form.email.value != form.confirm_email.value ){alert( 'Email addresses do not match.' ); form.email.focus();return false; }

    return true;
} 


//function validateIndex(frm) 
//{
//	var value = '';
//	_qfMsg = '';
//	var regex = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;    
//
//	zip = frm.elements['zip'];
//	if (zip.value == '') 
//	{
//		_qfMsg = _qfMsg + '\n - Zip Code is required';
//		zip.focus();
//	}
//	else if (zip.value.length < 5 || !regex.test(zip.value)) 
//	{
//		_qfMsg = _qfMsg + '\n - Zip Code is incorrect';
//		zip.focus();    
//	}
//
//	if (_qfMsg != '') {
//		_qfMsg = 'Invalid information entered.' + _qfMsg;
//		_qfMsg = _qfMsg + '\nPlease correct these fields.';
//		alert(_qfMsg);
//		return false;
//	}
//	return true;
//	
//}

//  min = frm.elements['ageMin'].value;
//  max = frm.elements['ageMin'].value;
//
//  max = frm.elements['ageMax'].value;
//  if (max == '') {
//    _qfMsg = _qfMsg + '\n - Age Max is required';
//    frm.elements['ageMax'].focus();
//  }   
//  if (max != '' && !regex.test(max) ) {    
//    _qfMsg = _qfMsg + '\n - Age Max should be a number';
//    frm.elements['ageMax'].focus();    
//  }
//  if (min > max && min != '' && max != '')
//  {
//  	_qfMsg = _qfMsg + '\n - Between ages range is incorrect';
//  	frm.elements['ageMin'].focus();
//  }
//  if (min == '') {
//    _qfMsg = _qfMsg + '\n - Age Min is required';
//    frm.elements['ageMin'].focus();
//  } 
//  if (min != '' && !regex.test(min) ) {
//    _qfMsg = _qfMsg + '\n - Age Min should be a number';
//    frm.elements['ageMin'].focus();
//  }  
//  if (min < 18 && min != '') {
//  	_qfMsg = _qfMsg + '\n - Must be at least 18 birthday_year of age';
//    frm.elements['ageMin'].focus();
//  }
//  if (_qfMsg != '') {
//    _qfMsg = 'Invalid information entered.' + _qfMsg;
//    _qfMsg = _qfMsg + '\nPlease correct these fields.';
//    alert(_qfMsg);
//    return false;
//  }
//  return true;
//}
