$(document).ready(function() {
/*Information Form	*/

	$(".error").hide();
	$("#submit_btn_information").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		
		if(!$("#option1").is(':checked') && !$("#option2").is(':checked') && !$("#option3").is(':checked') && !$("#option4").is(':checked') && !$("#option5").is(':checked') && !$("#option6").is(':checked') ) {
			$("label#option_error").show();  
			hasError = true;
		}

		var otherVal = $("#other").val();
		if($("#option6").is(':checked') && otherVal == '') {
			$("label#other_error").show();  
       		$("input#other").focus();  
			hasError = true;
		}

		var nameVal = $("#name").val();
		if(nameVal == '') {
			$("label#name_error").show();  
       		$("input#name").focus();  
			hasError = true;
		}

		var emailVal = $("#email").val();
		if(emailVal == '') {
			$("label#email_error").show();  
       		$("input#email").focus();  
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			$("label#email_error").show();  
       		$("input#email").focus();  
			hasError = true;
		}
		
		if(hasError == false) {
			$(this).hide();
			$("#form1").append('<img src="/images/loading.gif" alt="Loading" id="loading" />');
			$.post("/forms/information.php",
   				{ option1: ($("#option1").is(':checked')? $("#option1").val():"" ), option2: ($("#option2").is(':checked')? $("#option2").val():"" ), option3: ($("#option3").is(':checked')? $("#option3").val():"" ), option4: ($("#option4").is(':checked')? $("#option4").val():"" ), option5: ($("#option5").is(':checked')? $("#option5").val():"" ), option6: ($("#option6").is(':checked')? $("#option6").val():"" ), other: $("#other").val(), name: nameVal, email: emailVal, page: $("#page").val(), submit: $("#submit_btn_information").val()},
   					function(data){
						$("#form1").slideUp("normal", function() {				   
							$("#form1").before('<p>Thank you for your information.<br /><br />We invite you to continue reading to know about this great opportunity of learning English fast while enjoying the best vacation plan you will ever choose.</p><p>ILAC STAFF</p>');	
							$("#option1").attr('checked', false);
							$("#option2").attr('checked', false);
							$("#option3").attr('checked', false);
							$("#option4").attr('checked', false);
							$("#option5").attr('checked', false);
							$("#option6").attr('checked', false);
							$("input#other").val("");
							$("input#name").val("");
							$("input#email").val("");
						});
   					}
				 );
		}
		
		return false;
	});	
						   
/*Get Access Form*/
	$(".error").hide();
	$("#submit_btn").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		var firstNameVal = $("#firstName").val();
		if(firstNameVal == '') {
			$("label#firstName_error").show();  
       		$("input#firstName").focus();  
			hasError = true;
		}
		var lastNameVal = $("#lastName").val();
		if(lastNameVal == '') {
			$("label#lastName_error").show();  
       		$("input#lastName").focus();  
			hasError = true;
		}

		var countryVal = $("#country").val();
		if(countryVal == '') {
			$("label#country_error").show();  
       		$("input#country").focus();  
			hasError = true;
		}

		var cityVal = $("#city").val();
		if(cityVal == '') {
			$("label#city_error").show();  
       		$("input#city").focus();  
			hasError = true;
		}

		var emailVal = $("#email").val();
		if(emailVal == '') {
			$("label#email_error").show();  
       		$("input#email").focus();  
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			$("label#email_error").show();  
       		$("input#email").focus();  
			hasError = true;
		}
		var phoneVal = $("#phone").val();
		
		if(hasError == false) {
			$(this).hide();
			$("#form1").append('<img src="/images/loading.gif" alt="Loading" id="loading" />');
			
			$.post("/forms/getaccess.php",
   				{ firstName: firstNameVal, lastName: lastNameVal, country: countryVal, city: cityVal, email: emailVal, phone: $("#phone").val(), page: $("#page").val(), submit: $("#submit_btn").val()},
   					function(data){
						$("#form1").slideUp("normal", function() {				   
							$("#form1").before('<p class="thanks-form">Thank you for your contact information.<br />We will contact you soon.<br />We invite you to continue reading to know about this great opportunity of learning English fast while enjoying the best vacation plan you will ever choose.</p><p class="thanks-form">ILAC STAFF</p>');	
							$("input#firstName").val("");
							$("input#lastName").val("");
							$("input#country").val("");
							$("input#city").val("");
							$("input#email").val("");
						});
   					}
				 );
		}
		
		return false;
	});		
	

});

function MM_openBrWindow(mypage,myname,w,h,features) { //v2.0
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  
}
