
/**
 * 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 Email Address.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

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

 		 return true					
	}
	
function sendToConstantContact() {

	d = document.dform;
	tempName = d.name.value;
	strName = tempName.split(' ');
	firstname = strName[0];
	lastname = strName[1];
	phone = d.phone.value;
	email = d.email.value;
	address = d.address.value;
	instructor = d.instructor.value;
	foundout = d.foundout.value;
	taught = d.taught.value;
	comments = d.comments.value;
	
	constantcontact.location.href = "http://api.constantcontact.com/0.1/API_AddSiteVisitor.jsp?loginName=deekron&loginPassword=Eight88&ea="+email+"&ic=Deekron 'The Fitness DJ' Email List&First_Name="+firstname+"&First_Name="+firstname+"&Last_Name="+lastname+"&Home_Phone="+phone+"&Address_Line_1="+address+"&Custom_Field_1="+instructor+"&Custom_Field_2="+taught+"&Custom_Field_3="+foundout+"&Custom_Field_4="+comments;
}

function submitForm() {

	document.dform.submit();
}

function ValidateForm(){

	var emailID=document.dform.email
	var name=document.dform.name
	var instructor=document.dform.instructor
	var foundout=document.dform.foundout

	if ((name.value=="")||(instructor.value=="")||(foundout.value=="")) {
		alert("Please complete all required fields.")
		return false
	}
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter a valid email address.")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	
	sendToConstantContact();	
	setTimeout('submitForm()', 3000);
 }
 

