//***********************************************************************
// Author: Veronique Molinari
//***********************************************************************
//validate(field)
//emailCheck(theForm)
//email_alternateCheck(theForm)
//FrontPage_Form1_Validator(theForm)
//***********************************************************************


//**********************************************************
//Checks that the characters entered for a field are numbers
//**********************************************************

function validate(field) {
var valid = "0123456789";
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = "no";
}

if (ok == "no") {
	alert("Invalid entry!  Only numbers are accepted!");
	field.focus();
	return true;
   }

else {
   return false;
	}
}

//**********************************************************
//Check that the e-mail address entered is like a@a.a
//**********************************************************

function emailCheck(theForm) {
txt=theForm.e_mail.value;
if (txt.indexOf("@")<1){
alert("I'm sorry. This email address seems wrong. Please"
+" check the prefix and '@' sign.");
return true;
}

str=txt.substr(txt.indexOf("@"))
if ((str.indexOf(".")<2)) {
	return true;
   }

return false;
}

function email_alternateCheck(theForm) {
txt=theForm.e_mail_alternate.value;
if (txt !="") {
	if (txt.indexOf("@")<1){
	alert("I'm sorry. This email address seems wrong. Please"
	+" check the prefix and '@' sign.");
	return true;
	}

	str=txt.substr(txt.indexOf("@"))
		if ((str.indexOf(".")<2)) {
		return true;
		}
	return false;
	}
}


//**********************************************************
//Check that the required fields are not left blank
//**********************************************************

function flagRaiser(brian){
	var veromique = eval("document." + brian + "_pic");
	veromique.src = "http://images.strata.com/connect/register/images/flag.gif";
}

function flagLower(brian){
	var veromique = eval("document." + brian + "_pic");
	veromique.src = "http://images.strata.com/connect/register/images/check.gif";
}

function FrontPage_Form1_Validator(theForm)

{

	if (theForm.e_mail.value == ""){
		theForm.e_mail.focus();
		flagRaiser("e_mail");
		alert("Please enter an e-mail address.");
		return (false);
	}else{
		flagLower("e_mail");
	}

 	if (emailCheck(theForm)){
		alert("Please enter a valid e-mail address.");
		theForm.e_mail.focus();
		return (false);
	}

	if (theForm.re_email.value == ""){
		theForm.e_mail.focus();
		flagRaiser("re_email");
		alert("Please re_enter your e-mail address.");
		return (false);
	}else{
		flagLower("e_mail");
	}

   	if (theForm.re_email.value != theForm.e_mail.value){
		theForm.re_email.focus();
		flagRaiser("re_email");
		alert("The e_mail does not match.");
		return (false);
	}else{
		flagLower("re_email");
	}


  	if (theForm.mypassword.value == ""){
		theForm.mypassword.focus();
		flagRaiser("mypassword");
		alert("Please enter a password.");
		return (false);
	}else{
		flagLower("mypassword");
	}

  	if (theForm.mypassword.value.length < 4){
		theForm.mypassword.focus();
		flagRaiser("mypassword");
		alert("Please enter at least 4 characters for your password.");
		return (false);
	}else{
		flagLower("mypassword");
	}



   	if (theForm.repassword.value != theForm.mypassword.value){
		theForm.repassword.focus();
		flagRaiser("repassword");
		alert("The password does not match.");
		return (false);
	}else{
		flagLower("repassword");
	}

   	if (theForm.reminder_phrase.value == ""){
		theForm.reminder_phrase.focus();
		flagRaiser("reminder_phrase");
		alert("Please enter a reminder phrase.");
		return (false);
	}else{
		flagLower("reminder_phrase");
	}


	if (theForm.first_name.value == ""){
		theForm.first_name.focus();
		flagRaiser("first_name");
		alert("Please enter a First Name.");
		return (false);
	}else{
		flagLower("first_name");
	}
	
	if (theForm.last_name.value == ""){
    	theForm.last_name.focus();
		flagRaiser("last_name");
    		alert("Please enter a Last Name.");
     		return (false);
  	}else{
		flagLower("last_name");
	}

	if (theForm.address.value == ""){
    	theForm.address.focus();
		flagRaiser("address");
    	alert("Please enter an address.");
    	return (false);
  	}else{
		flagLower("address");
	}


   	if (theForm.city.value == ""){
		theForm.city.focus();
		flagRaiser("city");
		alert("Please enter a city.");
		return (false);
	}else{
		flagLower("city");
	}

	if (theForm.country.selectedIndex == 0){
		theForm.country.focus();
		flagRaiser("country");
		alert("Please enter a Country.");
		return (false);
	}else{
		flagLower("country");
	}

	
return (true);
}

