/**
 * 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)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var first_name=document.frmSignUp.first_name
	var last_name=document.frmSignUp.last_name
	var emailID=document.frmSignUp.email_address
	var email2=document.frmSignUp.email_address2
	
	if ((first_name.value==null)||(first_name.value=="")){
		alert("Please Enter First Name")
		first_name.focus()
		return false
	}
	if ((last_name.value==null)||(last_name.value=="")){
		alert("Please Enter Last Name")
		last_name.focus()
		return false
	}
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter Email Address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	
	if(email2.value!=emailID.value){
		alert("Email Address does not match")
		email2.focus()
		return false
	}
	return true
 }
 


function checkForm() 
{
	var found;
	/*var ValMsg_Name = "Please enter your name.";
	var ValMsg_SenderEmail = "Please enter your email.";*/
	var ValMsg_Email = "Please enter a valid email address for the recipient";
	var ValMsg_Recip = "Please enter name for the recipient";
	var ValMsg_NoRecips = "Please enter email for recipient(s) to send to";
	
	var sender_name=document.frmForward.sender_name
	var sender_email=document.frmForward.sender_email	
	
	found = false;
	
	if ((sender_name.value==null)||(sender_name.value=="")){
		alert("Please enter your name")
		sender_name.focus()
		return false
	}
	
	if ((sender_email.value==null)||(sender_email.value=="")){
		alert("Please Enter Email Address")
		sender_email.focus()
		return false
	}
	if (echeck(sender_email.value)==false){
		sender_email.value=""
		sender_email.focus()
		return false
	}
	
	for (var i = 0; i < document.forms[0].elements.length; i++)
	{
		if (document.forms[0].elements[i].name.indexOf("recipientEmail") != -1)
		{
			if (document.forms[0].elements[i].value.length > 0)
			{
				found = true;
				if (!verifyEmailAddress(document.forms[0].elements[i].value))
				{
					alert(ValMsg_Email)
					document.forms[0].elements[i].focus();
					return false;
				}
				else
				{
					for (var x = 0; x < document.forms[0].elements.length; x++)
					{
						var cntrlName;
						cntrlName = "recipientEmail" + document.forms[0].elements[i].name.charAt(4);
						if (document.forms[0].elements[i].name.indexOf(cntrlName) != -1)
						{
							if (document.forms[0].elements[i].name.indexOf(cntrlName) != -1)
							alert(ValMsg_Recip)
							document.forms[0].recipientName+i.focus();
							return false;
						}
					}
				}
			}
		}
	}
	
	if (!found)
	{
		alert(ValMsg_NoRecips);
		return false;
	}
	
	return true;
}


 
 
 function ValidateForwardForm(){
	
	var recipientEmail0=document.frmForward.recipientEmail0
	var recipientEmail1=document.frmForward.recipientEmail1	
	var recipientEmail2=document.frmForward.recipientEmail2
	var recipientEmail3=document.frmForward.recipientEmail3
	var recipientEmail4=document.frmForward.recipientEmail4
	
	var recipientName0=document.frmForward.recipientName0
	var recipientName1=document.frmForward.recipientName1	
	var recipientName2=document.frmForward.recipientName2
	var recipientName3=document.frmForward.recipientName3
	var recipientName4=document.frmForward.recipientName4
	
	
	
	
	
	if ((recipientEmail0.value==null)||(recipientEmail0.value=="")&&(recipientEmail1.value==null)||(recipientEmail1.value=="")&&(recipientEmail2.value==null)||(recipientEmail2.value=="")&&(recipientEmail3.value==null)||(recipientEmail3.value=="")&&(recipientEmail4.value==null)||(recipientEmail4.value=="")){
		alert("Please enter an email for the recipient")
		recipientEmail0.focus()
		return false
	}

	if((recipientEmail0.value!=null)||(recipientEmail0.value!="")&&(recipientName0.value==null)||(recipientName0.value=="")){
		alert("Please Enter your friend's name")
		recipientName0.focus()
		return false
	}
	
	return true
 }
