
$(document).ready(function(){
	$('#next1').click(function(){
		$(".error").hide();
		var hasError = false;
 		var title = $("#title").val();
 		var fname = $("#firstname").val();
 		var lname = $("#lastname").val();
 		var email = $("#email").val();
		var g= $("#T5").val();
		var h= $("#T6").val();
		var i= $("#T7").val();
		var address= jQuery.trim($("#address").val());
		var city= $("#city").val();
		var country= $("#country").val();
		var telephone= $("#telephone").val();
		var gen = $("input[name='gender']:checked").val();
		if(title == '') {
			$("#title").after('<span class="error">You forgot to select title.</span>');
			hasError = true;
		}
		else if(fname == '' || !isValidString(fname)) {
			$("#firstname").after('<span class="error">You forgot to enter the first name.</span>');
			hasError = true;
		}
		else if(lname == '' || !isValidString(lname)) {
			$("#lastname").after('<span class="error">You forgot to enter the last name.</span>');
			hasError = true;
		}
		else if(email == '' || !isEmailAddr(email)) {
			$("#email").after('<span class="error">You forgot to enter the email id.</span>');
			hasError = true;
		}
		else if(i == "" || h == "" || g == "" || !isValidNumber(g) || g.toString().indexOf(' ') > -1 || !checkdate((h-1),g,i)){
			$("#T5").after('<span class="error">Enter correct date of birth.</span>');
			hasError = true;
		}
		else if(city == '' || !isValidString(city)) {
			$("#city").after('<span class="error">You forgot to enter the city.</span>');
			hasError = true;
		}
		else if(country == '') {
			$("#country").after('<span class="error">You forgot to select the country.</span>');
			hasError = true;
		}
		else if(telephone == '' || !isValidNumber(telephone)) {
			$("#telephone").after('<span class="error">You forgot to enter telephone no.</span>');
			hasError = true;
		}
		if(hasError == false) {
			$("#step1").hide();
			$("#step2").fadeIn(600);
		}
		return false;
	});

	$('#next2').click(function(){
		$(".error").hide();
		var hasError = false;
		var nationality= $("#nationality").val();
		var dependents= $("#dependents").val();
		var from = $("input[name='applyfrom']:checked").val();
		if(from == 'i'){
			$('#amount').attr('innerHTML', '800');
		}else if(from == 'o'){
			$('#amount').attr('innerHTML', '2800');
		}
		var marital = $("input[name='marital']:checked").val();
		if(from == "" || from==undefined){
			$("#o").after('<span class="error">You forgot to select applying from.</span>');
			hasError = true;
		}
		else if(nationality == '') {
			$("#nationality").after('<span class="error">You forgot to select the nationality.</span>');
			hasError = true;
		}
		else if(marital == "" || marital==undefined){
			$("#ms").after('<span class="error">You forgot to select marital status.</span>');
			hasError = true;
		}
		else if(dependents == '') {
			$("#dependents").after('<span class="error">You forgot to select the nationality.</span>');
			hasError = true;
		}
		if(hasError == false) {
			$("#step2").hide();
			$("#step3").fadeIn(600);
		}
		return false;
	});
	$('#next3').click(function(){
		$(".error").hide();
		var hasError = false;
		var college= jQuery.trim($("#college").val());
		$("#qual").attr("value", $("input[name='qualification']").getValue());
		if($("input[name='qualification']").getValue()=="") {
			$("#qual").after('<span class="error">You forgot to select the qualification.</span>');
			hasError = true;
		}
		else if(college == '') {
			$("#college").after('<span class="error">You forgot to enter the college.</span>');
			hasError = true;
		}
		else if($("#yeargrad").val() == '') {
			$("#yeargrad").after('<span class="error">You forgot to select year graduated.</span>');
			hasError = true;
		}
		else if($("#gradcountry").val() == '') {
			$("#gradcountry").after('<span class="error">You forgot to select the country.</span>');
			hasError = true;
		}
		if(hasError == false) {
			$("#step3").hide();
			$("#step4").fadeIn(600);
		}
		return false;
	});
	$('#next4').click(function(){
		$(".error").hide();
		var hasError = false;
		var jobtitle= jQuery.trim($("#jobtitle").val());
		var jobdesc= jQuery.trim($("#jobdesc").val());
		if(jobtitle == '') {
			$("#jobtitle").after('<span class="error">You forgot to enter the job titile.</span>');
			hasError = true;
		}
		else if(jobdesc == '') {
			$("#jobdesc").after('<span class="error">You forgot to enter job description.</span>');
			hasError = true;
		}
		else if($("#earning").val() == '') {
			$("#earning").after('<span class="error">You forgot to select earnings.</span>');
			hasError = true;
		}
		else if($("#ecountry").val() == '') {
			$("#ecountry").after('<span class="error">You forgot to select earning country.</span>');
			hasError = true;
		}
		if(hasError == false) {
			$("#step4").hide();
			$("#step5").fadeIn(600);
		}
		return false;
	});
	$('#next5').click(function(){
		$(".error").hide();
		var hasError = false;
		var maj = $("input[name='maj']:checked").val();
		var speakcountry= $("#speakcountry").val();
		var nnmesc= $("#nnmesc").val();
		if(maj == "" || maj==undefined){
			$("#majno").after('<span class="error">You forgot to select.</span>');
			hasError = true;
		}
		else if(speakcountry == "" && maj == "Yes"){
			$("#speakcountry").after('<span class="error">You forgot to select the country.</span>');
			hasError = true;
		}
		else if((nnmesc == "" &&  maj == "No")){
			$("#nnmesc").after('<span class="error"><br/><br/>You forgot to select test you have passed.</span>');
			hasError = true;
		}
		if(hasError == false) {
			$("#step5").hide();
			$("#step6").fadeIn(600);
		}
		return false;
	});
    $("input[name='maj']").click(function(){
		var maj = $("input[name='maj']:checked").val();
		if(maj == "Yes"){
			$("#option2").hide();
			$("#option3").hide();
			$("#nnmesc").hide();
			$("#option1").fadeIn(600);
			$("#speakcountry").fadeIn(600);
		}
		else if(maj == "No"){
			$("#option1").hide();
			$("#speakcountry").hide();
			$("#option2").fadeIn(600);
			$("#option3").fadeIn(600);
			$("#nnmesc").fadeIn(600);
		}
	});
	$('#next6').click(function(){
		$(".error").hide();
		var hasError = false;
		var havemoney = $("input[name='havemoney']:checked").val();
		if(havemoney == "" || havemoney==undefined){
			$("#haveno").after('<span class="error">You forgot to select.</span>');
			hasError = true;
		}
		else if(!$("input[name='agree']").attr('checked')) {
			$("#iagree").before('<span class="error">Please select I agree.</span>');
			hasError = true;
		}
		return !hasError;
	});
	$('#back1').click(function(){
		$("#step2").hide();
		$("#step1").fadeIn(600);
	});
	$('#back2').click(function(){
		$("#step3").hide();
		$("#step2").fadeIn(600);
	});
	$('#back3').click(function(){
		$("#step4").hide();
		$("#step3").fadeIn(600);
	});
	$('#back4').click(function(){
		$("#step5").hide();
		$("#step4").fadeIn(600);
	});
	$('#back5').click(function(){
		$("#step6").hide();
		$("#step5").fadeIn(600);
	});
});


function isValidUsername(Username)
{
	var pattern = /[^a-zA-Z0-9_]+/;
	return ! pattern.test ( Username );
}
function isValidstringnumber(stringnumber)
{
	var pattern = /[^a-zA-Z0-9]+/;
	return ! pattern.test ( stringnumber );
}
function isValidString(string)
{
	var pattern = /[^a-zA-Z]+/;
	return ! pattern.test ( string );
}
function isValidNumber(number)
{
	var pattern = /[^0-9]+/;
	return ! pattern.test ( number );
}
function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function checkdate(entered_month,entered_day,entered_year)
{


	if ((entered_year % 4) == 0)
	{
		var days_in_month = "312931303130313130313031";
 	}
 	else	{

		var days_in_month = "312831303130313130313031";
 	}
	if (entered_month != -1)
	{
		if ( parseInt(entered_day) > parseInt(days_in_month.substring(2*entered_month,2*entered_month+2)) )
		{
			return false;
		}
	}
	return true;

}