$(document).ready( function() {	
	$("#enquiry-form-button").click(function() {
		var name, mobile, email, country, intcountry, type, send_to, errors ;
		name = $("#name").val();
		mobile = $("#mobile").val();
		email = $("#email").val();
		country = $("#country").val();
		intcountry = $("#intcountry").val();
		type = $("#type").val();
		errors = "";	
		if( name == "" || name == 'Name' )
		{ 
			errors += "Name is required\n";
		}
		if( mobile == "" || mobile == 'Mobile' )
		{
			errors += "Mobile is required\n";
		}
		else if( mobile.length < 10 )
		{
			errors += "Invalid Mobile Number.\n";
		}
		if( email == "" || email == 'Email' )
		{
			errors += "Email is required\n";
		}
		else if ( !validateEmail( email ) )
		{
			errors += "Invalid Email provided\n";
			
		}
		if( country == "" || country == 'null' )
		{
			errors += "Country is required\n";
		}
		if( intcountry == "" || intcountry == 'null' )
		{
			errors += "Select interested country \n";
		}

		if( type == "" || type == 'null' )
		{
			errors += "Select visa type \n";
		}

		if( errors != "" )
		{
			alert( "Enquiry could not be send due to following errors\n" + errors );
			return false;
		}
		
		$.ajax({
			type:'POST',
			url:'enquiry1_action.php',
			data:'name=' + name + '&mobile=' + mobile + '&email=' + email + '&country=' + country + '&intcountry=' + intcountry + "&type="+ type,
			success:function( response, status ){
				//if( response == 'sent')
				//	{
						$("#response").html('<font color="green">Your enquiry has been sent. We will contact you soon.</font>');
						$("#name").val('Name');
						$("#mobile").val('Mobile');
						$("#email").val('Email');
						$("#country").val('null');
						$("#intcountry").val('null');
						$("#type").val('null');
				//	}
				//	else{
				//		$("#response").html('<font color="red">Your enquiry sending fail.<br/>Please try again.</font>')
				//	}
			},
			error:function(){
				alert('There is some problem. Please try after some time.');
			}		
		})
		
	});

	$("#enquiry-form2-button").click(function() {
		var name, email, mobile, country, intcountry, type, others, send_to, errors ;
		name = $("#name").val();
		email = $("#email").val();
		mobile = $("#mobile").val();
		country = $("#country").val();
		intcountry = $("#intcountry").val();
		type = $("#type").val();
		others = $("#others").val();
		errors = "";	
		if( name == "" || name == 'Name' )
		{ 
			errors += "Name is required\n";
		}
		if( email == "" || email == 'Email' )
		{
			errors += "Email is required\n";
		}
		else if ( !validateEmail( email ) )
		{
			errors += "Invalid Email provided\n";
			
		}
		if( mobile == "" || mobile == 'Mobile' )
		{
			errors += "Mobile is required\n";
		}
		if( country == "" || country == 'Country' )
		{
			errors += "Country is required\n";
		}
		if( intcountry == "" || intcountry == 'null' )
		{
			errors += "Select interested country\n";
		}
		if( type == "" || type == 'null' )
		{
			errors += "Select visa type\n";
		}
		if( errors != "" )
		{
			alert( "Enquiry could not be send due to following errors\n" + errors );
			return false;
		}
		
		$("#enquiry-form").submit();
		
	});

	$("#enquiry-submit").click(function() {
		var title, full_name, mobile, email, resident, want_to_go_countries, why_want_visa, errors ;
		title = $("#title").val();
		full_name = $("#full_name").val();
		mobile = $("#cell_number").val();
		email = $("#email_address").val();
		resident = $("#resident").val();
		want_to_go_countries = $("#want_to_go_countries").val();
		why_want_visa = $("#why_want_visa").val();
		errors = "";	
		if( $.trim(full_name) == "" )
		{ 
			errors += "Full name is required.\n";
		}
		if( $.trim(mobile) == "")
		{
			errors += "Mobile Number is required.\n";
		}
		else if( mobile.length < 10 )
		{
			errors += "Invalid Mobile Number.\n";
		}
		if( $.trim(email) == "" )
		{
			errors += "Email address is required.\n";
		}
		else if ( !validateEmail( $.trim(email) ) )
		{
			errors += "Invalid Email Address.\n";
			
		}
		if( $.trim(resident) == "" )
		{
			errors += "Place of residence is required.\n";
		}
		if( $.trim(want_to_go_countries) == "" )
		{
			errors += "Destination country is required.\n";
		}
		if( $.trim(why_want_visa) == "" )
		{
			errors += "Reason for applying a visa is required.\n";
		}
		if( errors != "" )
		{
			alert( "Enquiry could not be send due to following errors\n" + errors );
			return false;
		}
		
		$("#enquiry_form").submit();
		
	});

	$("#assessment-submit").click(function() {
		var name, marital, email, cell, dob, resident, intcountry, visatype, english, qualification, study, occupation, experience, others, send_to, errors ;
		name = $("#name").val();
		marital = $("#marital_status").val();
		email = $("#email").val();
		cell = $("#cell").val();
		//dd = $("#dd").val();
		//mm = $("#mm").val();
		//yyyy = $("#yyyy").val();
		dob = $("#dob").val();
		resident = $("#resident").val();
		intcountry = $("#intcountry").val();
		visatype = $("#visatype").val();
		english = $("#english").val();
		qualification = $("#qualification").val();
		study = $("#study").val();
		occupation = $("#occupation").val();
		experience = $("#experience").val();
		others = $("#others").val();
		errors = "";
		
		if( name == "" || name == ' ' )
		{ 
			errors += "Full Name Required.\n";
		}
		if( email == "" || email == ' ' )
		{
			errors += "Email Address Required.\n";
		} 
		else if( !validateEmail(email) )
		{
			errors += "Invalid Email Address.\n";
		}
		if( cell == "" || cell == ' ' )
		{
			errors += "Mobile Number Required.\n";
		}
		else if( cell.length < 10 )
		{
			errors += "Invalid Mobile Number.\n";
		}
		//if( dd == "" || mm == "" || yyyy == "" || dd == 'dd' || mm == 'mm' || yyyy == 'yyyy' )
		//{
		//	errors += "Date of Birth required.\n"; 
		//}
		if( dob == "" )
		{
			errors += "Date of Birth required.\n"; 
		}
		if( resident == "" || resident == 'null' )
		{
			errors += "Select your City / State / Country.\n";
		}
		if( intcountry == "" || intcountry == 'null' )
		{
			errors += "Select country interested for.\n";
		}
		if( visatype == "" || visatype == 'null' )
		{
			errors += "Select visa type.\n";
		}
		if( qualification == "" || qualification == 'null' )
		{
			errors += "Education Highest Qualification Required.\n";
		}
		if( study == "" || study == 'null' )
		{
			errors += "Field of Study Required.\n";
		}
		if( occupation == "" || occupation == ' ' )
		{
			errors += "Current Occupation Required.\n";
		}
		if( errors != "" )
		{
			alert( "Assessment form could not be saved due to following errors:\n" + errors );
			return false;
		}
		
		$("#assessment_form").submit();

		
	});

	$("#points_calculator_denmark_submit").click(function() {
		var title, full_name, marital_status, email_address, cell_number, dd, mm, yyyy, resident, want_to_go_countries, why_want_visa, highest_qualification, field_of_study, rate_english, current_occupation, employment_type, experience, otherInformation;
		title = $("#title").val();
		full_name = $("#full_name").val();
		email_address = $("#email_address").val();
		cell_number = $("#cell_number").val();
		dd = $("#dd").val();
		mm = $("#mm").val();
		yyyy = $("#yyyy").val();
		current_occupation = $("#current_occupation").val();
		errors = "";	
		if( $.trim(full_name) == '' )
		{ 
			errors += "Full Name Required.\n";
		}
		if( $.trim(email_address) == '' )
		{
			errors += "Email Address Required.\n";
		} 
		else if( !validateEmail(email_address) )
		{
			errors += "Invalid Email Address.\n";
		}
		if( $.trim(cell_number) == '' )
		{
			errors += "Mobile Number Required.\n";
		} 
		else if( cell_number.length < 10 )
		{
			errors += "Invalid Mobile Number.\n";
		}
		if( errors != "" )
		{
			alert( "Points calculator has the following errors:\n" + errors );
			return false;
		}
		
		$("#points_calculator_denmark_form").submit();
		
	});

	$("#points_calculator_aus_submit").click(function() {
		var title, full_name, marital_status, email_address, cell_number, dd, mm, yyyy, resident, want_to_go_countries, why_want_visa, highest_qualification, field_of_study, rate_english, current_occupation, employment_type, experience, otherInformation;
		title = $("#title").val();
		full_name = $("#full_name").val();
		email_address = $("#email_address").val();
		cell_number = $("#cell_number").val();
		dd = $("#dd").val();
		mm = $("#mm").val();
		yyyy = $("#yyyy").val();
		current_occupation = $("#current_occupation").val();
		errors = "";	
		if( $.trim(full_name) == '' )
		{ 
			errors += "Full Name Required.\n";
		}
		if( $.trim(email_address) == '' )
		{
			errors += "Email Address Required.\n";
		} 
		else if( !validateEmail(email_address) )
		{
			errors += "Invalid Email Address.\n";
		}
		if( $.trim(cell_number) == '' )
		{
			errors += "Mobile Number Required.\n";
		} 
		else if( cell_number.length < 10 )
		{
			errors += "Invalid Mobile Number.\n";
		}
		if( errors != "" )
		{
			alert( "Points calculator has the following errors:\n" + errors );
			return false;
		}
		
		$("#points_calculator_aus_form").submit();
		
	});

});


function checkForm()
{
		var name, mobile, email, country, intcountry, type, send_to, errors ;
		name = $("#last_name").val();
		mobile = $("#phone").val();
		email = $("#email").val();
		country = $("#00N90000002PtiA").val();
		intcountry = $("#00N90000002PMZl").val();
		type = $("#00N90000002PMZq").val();
		errors = "";	
		if( name == "" || name == 'Name' )
		{ 
			errors += "Name is required\n";
		}
		if( mobile == "" || mobile == 'Mobile' )
		{
			errors += "Mobile is required\n";
		}
		if( email == "" || email == 'Email' )
		{
			errors += "Email is required\n";
		}
		else if ( !validateEmail( email ) )
		{
			errors += "Invalid Email provided\n";
			
		}
		if( country == "" || country == 'null' )
		{
			errors += "Country is required\n";
		}
		if( intcountry == "" || intcountry == 'null' )
		{
			errors += "Select interested country \n";
		}

		if( type == "" || type == 'null' )
		{
			errors += "Select visa type \n";
		}

		if( errors != "" )
		{
			alert( "Enquiry could not be send due to following errors\n" + errors );
			return false;
		}

}

function checkAssForm()
{
		var name, marital, email, cell, dob, resident, intcountry, visatype, english, qualification, study, occupation, experience, others, send_to, errors ;
		name = $("#last_name").val();
		marital = $("#00N90000002PMa5").val();
		email = $("#email").val();
		cell = $("#00N90000002PMb3").val();
		dob = $("#00N90000002PMZb").val();
		resident = $("#00N90000002PtiA").val();
		intcountry = $("#00N90000002PMZl").val();
		visatype = $("#00N90000002PMZq").val();
		english = $("#00N90000002Ptv8").val();
		qualification = $("#00N90000002PMa0").val();
		study = $("#00N90000002PPfu").val();
		occupation = $("#00N90000002PO8V").val();
		experience = $("#00N90000002PMbw").val();
		others = $("#description").val();
		errors = "";
		
		if( name == "" || name == ' ' )
		{ 
			errors += "Full Name Required.\n";
		}
		if( email == "" || email == ' ' )
		{
			errors += "Email Address Required.\n";
		} 
		else if( !validateEmail(email) )
		{
			errors += "Invalid Email Address.\n";
		}
		if( cell == "" || cell == ' ' )
		{
			errors += "Mobile Number Required.\n";
		}
		else if( cell.length < 10 )
		{
			errors += "Invalid Mobile Number.\n";
		}
		if( dob == "" )
		{
			errors += "Date of Birth required.\n"; 
		}
		if( resident == "" || resident == 'null' )
		{
			errors += "Select your City / State / Country.\n";
		}
		if( intcountry == "" || intcountry == ' ' )
		{
			errors += "Select country interested for.\n";
		}
		if( visatype == "" || visatype == 'null' )
		{
			errors += "Select visa type.\n";
		}
		if( qualification == "" || qualification == 'null' )
		{
			errors += "Education Highest Qualification Required.\n";
		}
		if( study == "" || study == 'null' )
		{
			errors += "Field of Study Required.\n";
		}
		if( occupation == "" || occupation == ' ' )
		{
			errors += "Current Occupation Required.\n";
		}
		if( errors != "" )
		{
			alert( "Assessment form could not be saved due to following errors:\n" + errors );
			return false;
		}

}

function email_the_link()
{
   var div = $('<div>').attr({ id:'emailform'}).addClass('emailform_class').html('<div><h3>Please enter your email address</h3></div><div><input type="text" id="emailform_text" size="30" /></div><div><input type="button" id="emailform_submit" value=" send " onclick="send_email_link()" />&nbsp;&nbsp;<input type="button" id="emailform_cancel" value=" cancel " onclick="close_email_form()" /></div><div id="emailform_sending" style="display:none"><em>sending email...</em></div>');
   $("#wrapper").append(div);
   $("#emailform").center();
   $("#emailform_text").focus();
   
}

function close_email_form()
{
    $("#emailform").remove();
}

function send_email_link()
{
   var email = $("#emailform_text").val();
   if($.trim(email) == "") alert("Email Address is required");
   else if(!validateEmail(email)) alert("Invalid Email Address provided");
   else {
	$("#emailform_sending").show();
	document.getElementById("emailform_submit").disabled = true;
	$.post("/emailform", { email : email }, function(resp) { alert("Email send successfully"); $("#emailform").remove(); });
   }
}

function slidedown(no)
{
    if(document.getElementById("div_"+no).style.display == 'none')
	$("#div_"+no).slideDown(200);
    else
	$("#div_"+no).slideUp(200);
}

function validateEmail(email)
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;   
   if(reg.test(email) == false) {      
      return false;
	 }
	 return true;   
}

function isNumberKey(evt) 
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

 return true;
}

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

