$(document).ready(function () {

 
		var error=new Array();
		var status;
    $("#sendform").click(function(e) { 							  
							  
		e.preventDefault();
        $("#message_feedback").html("");
                if ($.trim($("#firstname").val())=="")
                {
                   error[0]=" Please input First name";
                  
                }else{
                   error[0]="ok";
                   
                }

                if ($.trim($("#lastname").val())=="")
                {
                   error[1]=" Please input Last name";
                  
                }else{
                   error[1]="ok";
                   
                }

                if ($.trim($("#email").val())=="")
                {
                   error[2]=" Please input Email Address";
                   
                }else{
                   if (validate_email($.trim($("#email").val())))
                   {
                     error[2]="ok";
                     
                   }else{
                     error[2]=" Email is invalid";
                      
                   }
                }



        var n=0;
		$(":checkbox").each(function (i) {
	    	
				if (this.checked)
                {	
					n++;
				}
			

		});
		
		if(n==0)
		{
			error[3]="Please choose one";
		}else{error[3]="ok";}
		



                
				$(".error_message").each(function (i) {
                     if (error[i]!="ok")
					 {
						$(this).fadeIn("slow").html(error[i]);
					 }else{$(this).fadeIn("slow").html("");}
				});
                
				
				$(".error_message").each(function (i) {
					if (error[i].indexOf("ok")==-1)
					{
						status=false;
						return false; 	
						
					}else{status=true;}					
				    	
				});
				
				//return false; 	
                if (!status)
				{
					return false;		
				}
                
                
				
				
				
				
                

						$.ajax({
							url: 'event_form.php',
							data: $('form').serialize(),
							type: 'post',
							cache: false,
							dataType: 'html',
							//complete: function (xhr) {
						    success: function(xhr){     
							                              
                                                          if (xhr=="ok")
                                                          {
                                                           _tag.WT.si_cs = "1";
                                                            _tag.DCSext.successevent="info_request_banner";
							    _tag.dcsMultiTrack('DCS.dcsuri', '/4wayMBA_info_request.htm','WT.ti', '4wayEMBA_info_request', 'WT.si_n', '4wayMBA_info_request','WT.si_x', '1');                                                          
 															  
                                                            $("#message_feedback").fadeIn("slow").html("Your message has been sent.");
															$("form")[0].reset();


                                                          }else{
                                                            $("#message_feedback").html("Error! Please try again");
                                                          }		
							}
							
						});









                 

               
	});

});




function validate_email(email) {
		var at = email.lastIndexOf("@");

		// Make sure the at (@) sybmol exists and  
		// it is not the first or last character
		if (at < 1 || (at + 1) === email.length)
			return false;

		// Make sure there aren't multiple periods together
		if (/(\.{2,})/.test(email))
			return false;

		// Break up the local and domain portions
		var local = email.substring(0, at);
		var domain = email.substring(at + 1);

		// Check lengths
		if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
			return false;

		// Make sure local and domain don't start with or end with a period
		if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
			return false;

		// Check for quoted-string addresses
		// Since almost anything is allowed in a quoted-string address,
		// we're just going to let them go through
		if (!/^"(.+)"$/.test(local)) {
			// It's a dot-string address...check for valid characters
			if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
				return false;
		}

		// Make sure domain contains only valid characters and at least one period
		if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
			return false;	

		return true;
}

