$(document).ready(function() {
	$('#submit_bgn_quote').click(function(){
										  
										 
		if($("#name").val() == ''){
			alert("Please insert your name.");
			$("#name").focus();
			return false;
		}
			if($("#email").val() == ''){
			alert("Please insert your email Id.");
			$("#email").focus();
			return false;
		}
		
 if (echeck($("#email").val())==false){
		$("#email").val("");
		$("#email").focus();
		return false
	}
		
		
		var c_value='';
		for (var i=0; i < document.quotation.add_ons.length; i++)
   {
   if (document.quotation.add_ons[i].checked)
      {
		   
      c_value = c_value + document.quotation.add_ons[i].value + ",";
      }
   }

		//if($("#country").val() == ''){
//			alert("Please Select Your Company.");
//			$("#country").focus();
//			return false;
//		}
//		if($("#phone").val() == ''){
//			alert("Please insert your phone number.");
//			$("#phone").focus();
//			return false;
//		}
//	
//		if($("#contact_massage").val() == ''){
//			alert("Please insert message");
//			$("#contact_massage").focus();
//			return false;
//		}
//		if($("#contact_captcha").val() == ''){
//			alert("Please insert the text written in image.");
//			$("#contact_captcha").focus();
//			return false;
//		}
		var req_str = 'action=ask_a_quote';
		req_str += '&name=' + $("#name").val();
		req_str += '&email=' + $("#email").val();
		req_str += '&country=' + $("#country").val();
		req_str += '&phone=' + $("#phone").val();
		req_str += '&url=' + $("#url").val();
		req_str += '&benchmark_sites=' + $("#benchmark_sites").val();
		req_str += '&solreq=' + $("#solreq").val();
		req_str += '&job_desc=' + $("#job_desc").val();
		
		req_str += '&add_ons='+c_value;req_str += '&Expected_start_date=' + $("#Expected_start_date").val();
		
	 
	 
		$("#submit_bgn_quote").css("display", "none");
		$("#inactive_btn").css("display", "block");
		$.ajax({
			 type: "POST",
			 url: "xmailer.class.php",
			 cache: false,
			 data: req_str,
			 dataType: "html",
			 success: function(msg){
				$("#submit_bgn_quote").css("display", "block");
				$("#inactive_btn").css("display", "none");
				//if(msg == 'true'){
				if(msg = 'true'){
					$("#name").val("");
					$("#email").val("");
					$("#country").val("");
					$("#phone").val("");
					$("#url").val("");
					$("#benchmark_sites").val("");
					$("#solreq").val("");
					$("#job_desc").val("");
					$("#Expected_start_date").val("");
					for (var i=0; i <  document.quotation.add_ons.length; i++)
					{ 
					if (document.quotation.add_ons[i].checked)
						  {
							 document.quotation.add_ons[i].checked=false;
						  }
					}
					alert("Message has been send successfully.");
				}
			 }
		 });
  });
});

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 ID")
		   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					
	}
