$(document).ready(function() {
	
	$("#submit").click(function(){
//--------------------------------------------------
    
  if(document.ADD.first_name.value == "")
       {
         alert(" Please Enter Your First Name")
         document.ADD.first_name.focus();
		 document.ADD.first_name.style.backgroundColor='#FFE6DD';
         return false;
  } 
  
 
 	if(document.ADD.last_name.value == "")
       {
         alert(" Please Enter Your Last Name")
         document.ADD.last_name.focus();
		  document.ADD.last_name.style.backgroundColor='#FFE6DD';
         return false;
       } 
	   
	  var email =document.ADD.email.value;
  	  var phone =document.ADD.phone.value;
  
	   if(email=="" && phone ==""){
	 
	   /* Email validation */
		var new_email_add=document.ADD.email.value;
		 document.ADD.first_name.focus();//alert(new_email_add);
		var len=new_email_add.length
		if (len==0)
		{
			alert("Please Type Email Address.");
			document.ADD.email.focus();
		    document.ADD.email.style.backgroundColor='#FFE6DD';
			return false;
		}
		var mystring= new String(document.ADD.email.value);
		var mymailid=/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/;
		var mailid=mystring.search(mymailid)
		if (mailid==-1)
		{
			alert("Incorrect e-mail address.\n Please Type again (check @ and .'s)");
			document.ADD.email.focus();
			
			return false;
		}
		
		}

//---------------------------------------------------

   		 if(email=="" && phone ==""){
	   
         alert(" Please Enter Phone Number")
         document.ADD.phone.focus();
		 document.ADD.phone.style.backgroundColor='#FFE6DD';
         return false;
      	 }

//---------------------------------------------------
		
		var first_name = $('#first_name').val();
		var last_name = $('#last_name').val();
		var email = $('#email').val();
		var phone = $('#phone').val();
		var besttime = $('#besttime').val();
		var weightloss = "";
		var hormones = "";
		
		if ($('input[id=weightloss]').is(':checked') == true) {
			weightloss = "Weightloss";	
		}
		
		if ($('input[id=hormones]').is(':checked') == true) {
			hormones = "Hormones";	
		}
		
		$.ajax({
			type: "POST",
		    url:"contact.php",					
			data:"first_name="+first_name+"&email="+email+"&phone="+phone+"&last_name="+last_name+"&besttime="+besttime+"&intrests="+weightloss+","+hormones+"&fresh="+new Date().getTime(),
  			cache: false,
  			success: function(val){
			//alert(val);
			$('.jquery_valid_msg').html(val).css({'display':'block'});
			document.ADD.first_name.value ="";
			document.ADD.last_name.value ="";
			document.ADD.email.value="";
			document.ADD.phone.value="";
			document.ADD.besttime.value ="";
			document.location='successemail.php';	
		
			}
			
			});
 
	})
	
	$("#connect").click(function(){

		var url ="popupcontact.php";
		window.open(url,'popupWin',"height=" + 480 + ",width=" +720 + "location = 0, status = 1, resizable= 0, scrollbars=1, toolbar = 0");
	})
	
	       
});
