// to valid the myInfo page
function validateMyInfo()
{
	if (!validateEmail(document.frmMyInfo.useremail.value))
	{
		alert("Please enter an email address.");
		document.frmMyInfo.useremail.focus();
		return false;
	}

	if (document.frmMyInfo.password.value != document.frmMyInfo.confirmpassword.value)
	{
		alert('Your passwords do not match. Please try again.');
		document.frmMyInfo.password.focus();
		return false;
	}
	if(document.frmMyInfo.password.value.length<6)
	{
		alert('Your passwords must have at least 6 characters.');
		document.frmMyInfo.password.focus();
		return false;
	}
	if(document.frmMyInfo.webringID.value!="")
	{
		if (document.frmMyInfo.webringname.value == "")
		{
			alert("Please enter a site name.");
			document.frmMyInfo.webringname.focus();
			return false;
		}		
		if (document.frmMyInfo.websiteURL.value.length<=7 | document.frmMyInfo.websiteURL.value.substring(0,7).toLowerCase()!="http://")
		{			
			alert('Please enter a valid website URL starting with http://.');
			document.frmMyInfo.websiteURL.focus();
			return false;
		}

		if (document.frmMyInfo.selWebringCategory.value =="")
		{
			alert('Please select a category.');
			document.frmMyInfo.selWebringCategory.focus();
			return false;
		}

		if (document.frmMyInfo.description.value =="")
		{
			alert('Please enter a description.');
			document.frmMyInfo.description.focus()
			return false;
		}
		if(document.frmMyInfo.webringstanding[1].checked)
		{
			return confirm("Are you sure you want to be removed from the Rent Web Ring directory?");
		}		
	}	
	return true;
}
function validateForgetPassword()
{
	if (document.loginPage.email.value == "")
	{
		alert("Please enter your email address.");
		document.loginPage.email.focus();
		return false;
	}
	return true;
}

function sendNewPassword()
{
	var email=document.loginPage.email.value;
	var url="forgetpassword.php?email="+email;	
	window.open(url,'newwindow','toolbar=no,width=300,height=150');	
}

function validateWebringRegistration()
{
	if (document.webringRegistration.siteName.value == "")
	{
		alert("Please enter a site name.");
		document.webringRegistration.siteName.focus();
		return false;
	}
	if (document.webringRegistration.siteURL.value.length<=7 | document.webringRegistration.siteURL.value.substring(0,7).toLowerCase()!="http://")
	{		
		alert('Please enter a valid website URL starting with http://.');
		document.webringRegistration.siteURL.focus();
		return false;
	}

	if (document.webringRegistration.selWebringCategory.value =="")
	{
		alert('Please select a category.');
		document.webringRegistration.selWebringCategory.focus();
		return false;
	}

	if (document.webringRegistration.description.value =="")
	{
		alert('Please enter a description.');
		document.webringRegistration.description.focus()
		return false;
	}

	if(!document.webringRegistration.chkconfirm.checked)
	{
		alert('Please insert the Web Ring Media Player code into your website as instructed above\nand tick the checkbox to confirm.');
		document.webringRegistration.chkconfirm.focus();
		return false;
	}
	return true;
}

function textCounterReport()
{
	if(document.frmMyInfo)
	{
		if(document.frmMyInfo.flag.value!=""){
		var iCount=document.frmMyInfo.description.value.length;
		if(iCount>200)
		{
			var str=document.frmMyInfo.description.value;
			document.frmMyInfo.description.value=str.substring(0,200);
		}
		else
		{
			iCount=200-iCount;
			document.frmMyInfo.textCount.value=iCount;
		}
		}
	}
	else if(document.webringRegistration)
	{
		var iCount=document.webringRegistration.description.value.length;
		if(iCount>200)
		{
			var str=document.webringRegistration.description.value;
			document.webringRegistration.description.value=str.substring(0,200);
		}
		else
		{
			iCount=200-iCount;
			document.webringRegistration.textCount.value=iCount;
		}
	}
	else if(document.webringreport)
	{
		var iCount=document.webringreport.description.value.length;
		if(iCount>200)
		{
			var str=document.webringreport.description.value;
			document.webringreport.description.value=str.substring(0,200);
		}
		else
		{
			iCount=200-iCount;
			document.webringreport.textCount.value=iCount;
		}
	}
}




function validateWebringReport()
{
	if (document.webringreport.selWebringReportType.value =="")
	{
		alert('Please select a problem type.');
		document.webringreport.selWebringReportType.focus();
		return false;
	}
	if (document.webringreport.description.value =="")
	{
		alert('Please enter a description.');
		document.webringreport.description.focus();
		return false;
	}
	return true;
}
function validateFormReg()
{
	if (document.registration.username.value == "")
	{
		alert("Please enter a username.");
		document.registration.username.focus();
		return false;
	}

	if (!validateEmail(document.registration.email.value))
	{
		alert("Please enter an email address.");
		document.registration.email.focus();
		return false;
	}

	if (document.registration.password.value != document.registration.confirmpassword.value)
	{
		alert('Your passwords do not match. Please try again.');
		document.registration.password.focus();
		return false;
	}
	if(document.registration.password.value.length<6)
	{
		alert('Your passwords must have at least 6 characters.');
		document.registration.password.focus();
		return false;
	}

	if (!validateDate(document.registration.year.value,document.registration.month.value,document.registration.day.value))
	{
		alert("Please enter a valid date of birth. MM/DD/YYYY");
		document.registration.month.focus();
		return false
	}
	return true;
}
 function validateDate(year,month,day)
{
	if(year.length != 4 || year<1900)
		return false;

	var strBirth = year + '-' + month + '-' + day;

	var sRegular = /^(\d{2,4}-((((0?[13578])|(1[02]))-((0?[1-9]|[0-2][0-9])|(3[01])))|(((0?[469])|(11))-((0?[1-9]|[0-2][0-9])|(30)))|(0?[2]-(0?[1-9]|[0-2][0-9]))))$/;

	if(!sRegular.test(strBirth))		
		return false;

	return true;
}
//regular function to check @ and . in the email address
function checkEMail(sEMail)
{
	var sRegular = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	if (sRegular.test(sEMail)) 
		return true;
	else 
		return false;
}
function validateEmail( emailIn )
{
	/*/// Number of '@' chars present in input string.
	var numAtChars;

	/// The part of input address before the '@' character.
	var userNameIn;

	/// The part of input address after the '@' character.
	var domainNameIn;

	/// Holds the fields of the entered address, delimitted by '@' chars.
	var addressFields = new Array();

	// Concatenate all alert output to here.
	var alertString = "";

	/// Divide the input email address into fields.
	/// Note that the array "addressFields" will have one more element
	/// than the number of '@' signs in the input string.
	/// IE4 handles this OK with '@' as last character but NS4,4.5 and Opera 3.5 don't.
	addressFields = emailIn.split( '@' );

	numAtChars = addressFields.length - 1;
	//alertString += "The Email Address field:  \"" + emailIn + "\"\n\n";

	if ( emailIn == "" )
		alertString += "The Email Address field:  \"" + emailIn + "\"\n\n is EMPTY.";
	else if ( numAtChars == 0 )
		alertString += "The Email Address field:  \"" + emailIn + "\"\n\n contains no '@' character and is therefore Not a valid Email Address.";
	else if ( numAtChars > 1 )
		alertString += "The Email Address field:  \"" + emailIn + "\"\n\ncontains " + numAtChars + " '@' characters and is therefore Not a valid Email Address.";
	else if ( addressFields[0] == "" )
		alertString += "The Email Address field:  \"" + emailIn + "\"\n\nhas no Username before the '@' character and is therefore Not a valid Email Address.";
	else if ( addressFields[1] == "" )
		alertString += "The Email Address field:  \"" + emailIn + "\"\n\nhas no Domain Name after the '@' character and is therefore Not a valid Email Address.";
	else {
		userNameIn  = addressFields[0];
		domainNameIn = addressFields[1];

		if ( userNameIn.indexOf( " " ) != -1 )
			alertString += "The Email Address field:  \"" + emailIn + "\"\n\nhas one or more Spaces in the Username before the '@' character and is therefore Not a valid Email Address.";
		else if ( domainNameIn.indexOf( " " ) != -1 )
			alertString += "The Email Address field:  \"" + emailIn + "\"\n\nhas one or more Spaces in the Domain Name after the '@' character and is therefore Not a valid Email Address.";
		else if ( isStandardDomain( domainNameIn ) == false )
			alertString += "The Email Address field:  \"" + emailIn + "\"\n\ndoes not end with a '.com' style domain or two letter country code domain and is therefore Not a valid Email Address.";

		} // Ends else from outer string of if-then-else's.

	// Post the alert box.
	if (alertString.length > 0)
		return false;
	else
		return true;*/

	var sRegular = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/;
	if (sRegular.test(emailIn)) 
		return true;
	else 
		return false;
} // Ends validateEmailAddress2().

function isStandardDomain( domainIn )
{
	/// The VALUE to return, start out assuming invalid domain.
	var isStandardReturn = false;
	/// Holds the last 4 characters of domain name.
	var last4chars = domainIn.substring( domainIn.length-4, domainIn.length );
	/// Holds the last 3 characters of domain name.
	var last3chars = domainIn.substring( domainIn.length-3, domainIn.length );
	/// Uppercase it for comparison purposes.
	last4chars = last4chars.toUpperCase();
	/// A regular expression pattern to match country code domains.
	/// In otherwords a Dot character followed by two alphabetic characters.
	/// NOTE: This line doesn't work at all in Opera3.5 and prevents the
	/// entire script from running!!! BUMMER!!!
	/// It also seems to not work in Opera4.02 but only prevents
	/// the 2 letter codes from working but doesn't crash the script.
	var countryCodePattern = /\.[a-zA-Z][a-zA-Z]/;

	if   ( last4chars == ".COM" ) isStandardReturn = true;
	else if ( last4chars == ".EDU" ) isStandardReturn = true;
	else if ( last4chars == ".GOV" ) isStandardReturn = true;
	else if ( last4chars == ".NET" ) isStandardReturn = true;
	else if ( last4chars == ".MIL" ) isStandardReturn = true;
	else if ( last4chars == ".ORG" ) isStandardReturn = true;

	else if ( last3chars.search( countryCodePattern )  != -1 )
		isStandardReturn = true;

	return isStandardReturn;

} // Ends isStandardDomain( domainIn ).
