/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var message = "Please enter a valid email address";
		if (str.indexOf(at)==-1){
		   alert(message)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(message)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(message)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(message)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(message)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(message)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(message)
		    return false
		 }

 		 return true					
	}

function ValidateEmail(emailID)
//function ValidateEmail()
	{
//	var emailID=document.form1.toemail
//		alert(emailID.value)	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
//		emailID.value=""
		emailID.focus()
		return false
	}

	return true
 }


function ValidateRegistration(emailID,passwordID, confirmID, nameID)
	{
//return true;
	if ((nameID.value==null)||(nameID.value=="")){
		alert("Please enter your name, it will be used in high-scores")
		nameID.focus()
		return false
	}

	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
//		emailID.value=""
		emailID.focus()
		return false
	}

	if ((passwordID.value==null)||(passwordID.value=="")){
		alert("Please enter your password")
		passwordID.focus()
		return false
	}
	// checking password length
	if ((passwordID.value).length < 4){
		alert("Password must be at least 4 characters")
		passwordID.focus()
		return false
	}
	
	if ((confirmID.value==null)||(confirmID.value=="")){
		alert("Please enter a valid password confirmation")
		confirmID.focus()
		return false
	}

	// checking if password match
	pass=passwordID.value;
	conf=confirmID.value;
	if (pass != conf){
		alert("Password and Password Confirm dont match")
		confirmID.focus()
		return false
	}

	return true
 }


	
function ValidateTellAFriend(fromnameID,fromemailID,tonameID,toemailID)
	{

	if ((fromnameID.value==null)||(fromnameID.value=="")){
		alert("Please enter your name, it will be used in the email to your friend")
		fromnameID.focus()
		return false
	}

	if ((fromemailID.value==null)||(fromemailID.value=="")){
		alert("Please enter your email address")
		fromemailID.focus()
		return false
	}
	if (echeck(fromemailID.value)==false){
		fromemailID.focus()
		return false
	}

	if ((tonameID.value==null)||(tonameID.value=="")){
		alert("Please enter your friend name")
		tonameID.focus()
		return false
	}

	if ((toemailID.value==null)||(toemailID.value=="")){
		alert("Please enter your friend email address")
		toemailID.focus()
		return false
	}
	if (echeck(toemailID.value)==false){
		toemailID.focus()
		return false
	}


	return true
 }

function ValidateLogin(emailID,passwordID)
	{

	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address")
		toemailID.focus()
		return false
	}
	else if (echeck(emailID.value)==false){
		emailID.focus()
		return false
	}
	else if ((passwordID.value==null)||(passwordID.value=="")){
		alert("Please enter your password")
		passwordID.focus()
		return false
	}

	return true
 }
	


function tell_friend()
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("/hmailer/tellafriend.php","_blank","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=NO,TOP=40,LEFT=20,WIDTH=411,HEIGHT=570"); 
	return false;
}

function contact_us()
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("/hmailer/contactus.php","_blank","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=NO,TOP=40,LEFT=20,WIDTH=391,HEIGHT=400"); 
	return true;
}
function mailing_list()
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("/hmailer/mailinglist.php","_blank","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=NO,TOP=40,LEFT=20,WIDTH=391,HEIGHT=400"); 
	return true;
}

function register()
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("/hmailer/register.php","_blank","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=NO,TOP=40,LEFT=20,WIDTH=391,HEIGHT=470"); 
	return true;
}

function login(returnto)
{
//  window.open("tellafriend.htm","FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=300,HEIGHT=420"); 
  window.open("/hmailer/login.php?returnto="+returnto,"_blank","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=NO,TOP=40,LEFT=20,WIDTH=391,HEIGHT=400"); 
	return true;
}
