//var title = '';
var first_name ='';
var surname = '';
var birth_day ='';
var country = '';
var gender_val='';
var email = '';
var pass= '';
var repass= '';
var house = '';
var street = '';
var postcode = '';
var town = '';
var district = '';
var presentcountry='';
var phouse = '';
var pstreet = '';
var ppostcode = '';
var ptown = '';
var pdistrict = '';
var pcountry='';

var telephone = '';
var mobile = '';
var fax = '';
//var s_dependency = '';
//var n_dependency = '';

var passport_no = '';
var issue_date = '';
var expiry_no = '';
var passport_copy = '';
var visa_info = '';
var photo = '';
var photoid = '';
<!---------------------------------Qualification----------------------------------->
var academic = '';
var awarding = '';
var subject = '';
var stardate = '';
var enddate = '';
var result = '';
var upload_certificate = '';
var upload_marksheet = '';
var language = '';
var qcountry = '';


var motherlang = '';
var englang= '';

var course_name = '';
var mode_study = '';
var session = '';
var resume = '';
var finance_type = '';
var direct_debit = '';
var electronic_sign = '';
var ethinic_origin = '';
var ethinic_gender = '';
var ethinic_age = '';
var ethinic_disability = '';
var ethinic_check = '';
var d_protection = '';
var db_email ='';

function registration_form()
{
    //title = $('#title').val();    
    first_name = $('#first_name').val();
    surname = $('#surname').val();
    day = $('#day').val();
	month= $('#month').val();
	year= $('#year').val();
	country = $('#country').val();
    email = $('#email').val();
    pass= $('#pass').val();
    repass = $('#repass').val();
    /*if(title==null || title == '')
    {        
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please fill up Title');
        return false;
    }*/
    $('#reg_error').slideUp('fast');
    if(first_name==null || first_name == '')
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please fill up First Name');
        return false;
    }
    $('#reg_error').slideUp('fast');
    if(surname==null || surname == '')
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please fill up Sur Name'); 
        return false;
    }
	
    /*$('#reg_error').slideUp('fast');
    var birth_day_validate = checkdate(birth_day);
    if(birth_day_validate==false)
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please fill up Birth Day');
        return false;
    }*/
	$('#reg_error').slideUp('fast');
    if(day==null || day == '' && month==null || month == '' && year==null || year == '' )
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please full up full birthday');
        return false;
    }

    
	$('#reg_error').slideUp('fast');
    if(country==null || country == '')
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please Select Your Nationality');
        return false;
    }
  
    for (var i=0; i <document.entry_form.gender.length; i++)
    {
        if (document.entry_form.gender[i].checked)
        {            
            gender_val = document.entry_form.gender[i].value;            
        }
    }
    $('#reg_error').slideUp('fast');
    if(gender_val==null || gender_val=='')
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please choose your Gender');
        return false;
    }
    $('#reg_error').slideUp('fast');
    if(email==null || email == '')
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please fill up your Email Address');

        return false;
    }
    $('#reg_error').slideUp('fast');
    var mail_pattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(!mail_pattern.test(email))
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please enter a valid Email Address');
        return false;
    }
    email_check(email);
    if(db_email> 0)
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('The Email Is Already Exists,Please Try One!');
        return false;
    }
    $('#reg_error').slideUp('fast');
    $('#reg_error').slideUp('fast');
    if(pass==null || pass == '')
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please fill up Password');
        return false;
    }
    $('#reg_error').slideUp('fast');
    if(pass.length<6)
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Passwords must be 6 characters minimum');
        return false;
    }
	
    $('#reg_error').slideUp('fast');
    if(repass==null || repass == '')
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Please fill up Repassword');
        return false;
    }
    $('#reg_error').slideUp('fast');
    if(pass!=repass)
    {
        $('#reg_error').slideDown('fast');
        $('#reg_error').html('Password not matched!');
        return false;
    }	
    return true;
}
function personal_info_form()
{ 
    house  = $('#house').val();
    street = $('#street').val();
    postcode= $('#postcode').val();
    town= $('#town').val();
    district= $('#district').val();
    presentcountry= $('#presentcountry').val();
	
    phouse  = $('#phouse').val();
    pstreet = $('#pstreet').val();
    ppostcode= $('#ppostcode').val();
    ptown= $('#ptown').val();
    pdistrict= $('#pdistrict').val();
    pcountry= $('#pcountry').val();
    telephone= $('#telephone').val();
    mobile= $('#mobile').val();
	
    $('#presonal_error').slideUp('fast');
    if(house==null || house == '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up House/Flat No');
        return false;
    }
    $('#presonal_error').slideUp('fast');
    if(street==null || street == '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up Street');
        return false;
    }
	
    $('#presonal_error').slideUp('fast');
    if(postcode==null || postcode == '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up Postcode');

        return false;
    }
    $('#presonal_error').slideUp('fast');
    if(town==null || town == '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up Town');
        return false;
    }
    $('#presonal_error').slideUp('fast');
    if(district==null || district == '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up District');
        return false;
    }  
    $('#presonal_error').slideUp('fast');
    if(presentcountry==null || presentcountry== '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up Country');
        return false;
    }
    <!----------------------------------permanent address	--------------------------------->
    $('#presonal_error').slideUp('fast');
    if(phouse==null || phouse == '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up House');
        return false;
    }
    $('#presonal_error').slideUp('fast');
    if(pstreet==null || pstreet == '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up Street');
        return false;
    }
	
    $('#presonal_error').slideUp('fast');
    if(ppostcode==null || ppostcode == '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up Postcode');

        return false;
    }
    $('#presonal_error').slideUp('fast');
    if(ptown==null || ptown == '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up Town');
        return false;
    }
    $('#presonal_error').slideUp('fast');
    if(pdistrict==null || pdistrict == '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up District');
        return false;
    }  
    $('#presonal_error').slideUp('fast');
    if(pcountry==null || pcountry== '')
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up Country');
        return false;
    }
	
      $('#presonal_error').slideUp('fast');
      if((telephone.toString().search(/^[0-9]+$/))!=0)
          {
           $('#presonal_error').slideDown('fast');
           $('#presonal_error').html('Please fill up valid Telephone Number');
           return false;
     	  }
	/*if(telephone==null || telephone == '')
    
	{
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up Telephone Number');
        return false;
    
	}*/
    $('#presonal_error').slideUp('fast');
   if((mobile.toString().search(/^[0-9]+$/))!=0)
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please fill up valid Mobile Number');
        return false;
    }
    if ( ( entry_form.marrigae_status[0].checked == false ) && ( entry_form.marrigae_status[1].checked == false ) )
    {
        $('#presonal_error').slideDown('fast');
        $('#presonal_error').html('Please choose Marital Status');
        return false;
    }
    /*if( entry_form.marrigae_status[0].checked == 1)
	{
		$("#row1").show();
		//$("#row2").show("fade");
	}
	else if( entry_form.marrigae_status[1].checked ==0)
	{
		$("#row1").hide();
		//$("#row2").hide();
	}*/
    return true;
}
function show()
{
    $('#row1').show();
    $('#row2').show();
}
function hide()
{
    $('#row1').hide();
    $('#row2').hide();
}

function security_form()
{  
    if ((entry_form.residence[0].checked == false ) && ( entry_form.residence[1].checked == false ) )
    {
        $('#security_error').slideDown('fast');
        $('#security_error').html('Please choose Residence');
        return false;
    }
    if( entry_form.residence[1].checked == true )
    {
        
	  passport_no = $('#passport_no').val();
	 if(passport_no == null || passport_no == '')
      {
        $('#security_error').slideDown('fast');
        $('#security_error').html('Please fill up Your Passport Number');
        return false;
      }
		$('#security_error').slideUp('fast');
        issue_date = $('#issue_date').val();
        var validate_issue_date = checkdate(issue_date);
        if(validate_issue_date == false)
        {
            $('#security_error').slideDown('fast');
            $('#security_error').html('Please fill up Issue Date');

            return false;
        }
        $('#security_error').slideUp('fast');
        expiry_no = $('#expiry_no').val();
        var validate_expire  = checkdate(expiry_no);
        if(validate_expire == false)
        {
            $('#security_error').slideDown('fast');
            $('#security_error').html('Please fill up Expire Date');

            return false;
        }
        $('#security_error').slideUp('fast');
        var date_difference = DateDiff(expiry_no,issue_date);
        if(date_difference<=0)
        {
            $('#security_error').slideDown('fast');
            $('#security_error').html('Expire date never less than Issue date');

            return false;
        }
    }
    $('#security_error').slideUp('fast');

    return true;
}

function showhome()
{
    $('#myrow1').hide();
    $('#myrow2').hide();
    $('#myrow3').hide();
    $('#myrow4').hide();
    $('#myrow5').hide();
    $('#myrow6').show();

		
}
function showoverseas()
{
    $('#myrow1').show();
    $('#myrow2').show();
    $('#myrow3').show();
    $('#myrow4').show();
    $('#myrow5').show();
    $('#myrow6').hide();
}
function qualification_form()
{
    academic = $('#academic').val();
    awarding = $('#awarding').val();
    subject = $('#subject').val();
    startdate = $('#Start_Date').val();
	
	qday= $('#qday').val();
	qmonth = $('#qmonth').val();
    qyear = $('#qyear').val();
	
    enddate = $('#End_Date').val();
    result = $('#result').val();
    upload_certificate = $('#upload_certificate').val();
    upload_marksheet = $('#upload_marksheet').val();
    language = $('#language').val();
    qcountry = $('#qcountry').val();
	
	
    $('#qualification_error').slideUp('fast');
    if(academic == null || academic == '')
    {
        $('#qualification_error').slideDown('fast');
        $('#qualification_error').html('Please fill up Degree');

        return false;
    }
    $('#qualification_error').slideUp('fast');
    if(awarding == null || awarding == '')
    {
        $('#qualification_error').slideDown('fast');
        $('#qualification_error').html('Please fill up Awarding');

        return false;
    }
    $('#qualification_error').slideUp('fast');
    if(subject == null || subject == '')
    {
        $('#qualification_error').slideDown('fast');
        $('#qualification_error').html('Please fill up Subject');

        return false;
    }
    $('#qualification_error').slideUp('fast');
    if(qday == null || qday == '' && qmonth== null || qmonth == '' && qyear== null || qyear== '' )
    {
        $('#qualification_error').slideDown('fast');
        $('#qualification_error').html('Please fill up full Start Date');

        return false;
    }
    
	$('#qualification_error').slideUp('fast');
	
    if(enddate == null || enddate == '')
    {
        $('#qualification_error').slideDown('fast');
        $('#qualification_error').html('Please fill up End Date');

        return false;
    }
	/*
    var dif_stat_end = DateDiff(enddate,startdate);
    if(dif_stat_end<=0)
    {
        $('#qualification_error').slideDown('fast');
        $('#qualification_error').html('End date never less than start date');

        return false;
    }*/
    $('#qualification_error').slideUp('fast');
    if(result == null || result == '')
    {
        $('#qualification_error').slideDown('fast');
        $('#qualification_error').html('Please fill up Result');

        return false;
    }
    $('#qualification_error').slideUp('fast');
    
	if(language == null || language == '')
    {
        $('#qualification_error').slideDown('fast');
        $('#qualification_error').html('Please fill up Language');

        return false;
    }
    $('#qualification_error').slideUp('fast');
    if(qcountry == null || qcountry == '')
    {
        $('#qualification_error').slideDown('fast');
        $('#qualification_error').html('Please fill up Country');
        return false;
    }
	  $('#qualification_error').slideUp('fast');
    if ((entry_form.motherlang[0].checked == false ) && ( entry_form.motherlang[1].checked == false ) )
    {
        $('#qualification_error').slideDown('fast');
        $('#qualification_error').html('Please choose Your Native Language');
        return false;
    }
    $('#qualification_error').slideUp('fast');
    if(entry_form.motherlang[1].checked == true )
    {
        if((entry_form.englang[0].checked == false) && (entry_form.englang[1].checked == false) && (entry_form.englang[2].checked == false))
        {
            $('#qualification_error').slideDown('fast');
            $('#qualification_error').html('Please Select Your English Language Proficiency');
            return false;
        }
    }
    $('#qualification_error').slideUp('fast');
    if(entry_form.sit_eng[0].checked == true )
    {
        var exam_date =  $('#exam_date').val();
        var exam_date_validate = checkdate(exam_date);
        if(exam_date_validate == false)
        {
            $('#qualification_error').slideDown('fast');
            $('#qualification_error').html('Please Select Your Exam Date');
            return false;
        }
        var score =  $('#score').val();
        if(score == '' || score =='')
        {
            $('#qualification_error').slideDown('fast');
            $('#qualification_error').html('Please Give  Your Score');
            return false;
        }
        var awardingbody =  $('#awardingbody').val();
        if(awardingbody == null || awardingbody =='')
        {
            $('#qualification_error').slideDown('fast');
            $('#qualification_error').html('Please Give  Your Awarding Body');
            return false;
        }
        var resultdate =  $('#resultdate').val();
        var resultdate_validate = checkdate(resultdate);
        if(resultdate_validate == false)
        {
            $('#qualification_error').slideDown('fast');
            $('#qualification_error').html('Please Give Your Result Date');
            return false;
        }
        var eng_date_diff  = DateDiff(resultdate,exam_date)
        if(eng_date_diff<0)
        {
            $('#qualification_error').slideDown('fast');
            $('#qualification_error').html('Result date can not be less than Exam date' );
            return false;
        }
    }
    $('#qualification_error').slideUp('fast');
    return true;
}
function showOtherlang()
{
    $('#rowno1').show();
    $('#rowno2').show();
    $('#rowno3').hide();
    $('#rowno4').hide();
    $('#rowno5').hide();
    $('#rowno6').hide();
}
function showmotherlang()
{
    $('#rowno1').hide();
    $('#rowno2').hide();
    $('#rowno3').hide();
    $('#rowno4').hide();
    $('#rowno5').hide();
    $('#rowno6').hide();
}
	
function showsitfor()
{
    $('#rowno3').show();
    $('#rowno4').show();
    $('#rowno5').show();
    $('#rowno6').show();
}
function showsitforno()
{
    $('#rowno3').hide();
    $('#rowno4').hide();
    $('#rowno5').hide();
    $('#rowno6').hide();
}

function course_details_form()
{   
       course_name = $('#course_name').val();
       if(course_name == null || course_name == '')
       {
           $('#course_error').slideDown('fast');
            $('#course_error').html('Please Enter fill up Course Name');
    
            return false;
        }
		
		$('#course_error').slideUp('fast');
		course_level = $('#course_level').val();
       if(course_level == null || course_level == '')
       {
           $('#course_error').slideDown('fast');
            $('#course_error').html('Please fill up Course Level');
    
            return false;
        }
        $('#course_error').slideUp('fast');
        modeofstudy = $('#modeofstudy').val();
        if(modeofstudy == null || modeofstudy == '')
        {
            $('#course_error').slideDown('fast');
            $('#course_error').html('Please fill up Mode of Study');
    
            return false;
        }
        $('#course_error').slideUp('fast');
        session = $('#session').val();
        if(session == null || session == '')
        {
            $('#course_error').slideDown('fast');
            $('#course_error').html('Please fill up Your Session');
    
            return false;
        }
    return true;
}
function diable_calender()
{
   document.getElementById('enddate').setAttribute('disabled', 'disabled');
}


function work_form()
{
    var companyname = $('#companyname').val();
    var position  = $('#position').val();
    var startdate  = $('#startdate').val();
    var enddate  = $('#enddate').val();
    var responsibilites  = $('#responsibilites').val();

    return true;
}
function financial_details_form()
{

    finance_type = $('#finance_type').val();
    if(finance_type == null || finance_type == '')
    {
        $('#finnance_error').slideDown('fast');
        $('#finnance_error').html('Please fill up Your Finance Type');
        return false;
    }
    
	/*$('#finnance_error').slideUp('fast');
    grantor = $('#grantor').val();
    if(grantor == null || grantor == '')
    {
        $('#finnance_error').slideDown('fast');
        $('#finnance_error').html('Please fill up Your Grantor');

        return false;
    }*/
    return true;
}
function equal_opportunity_form()
{
    for (var i=0; i <document.entry_form.ethinic_gender.length; i++)
    {
        if (document.entry_form.ethinic_gender[i].checked)
        {
            ethinic_gender = document.entry_form.ethinic_gender[i].value;
        }
    }    
    if(ethinic_gender == null || ethinic_gender == '')
    {
        $('#equal_opportunity_error').slideDown('fast');
        $('#equal_opportunity_error').html('Please fill up Your Ethinic Gender');
        return false;
    }
    $('#equal_opportunity_error').slideUp('fast');
    for (var i=0; i <document.entry_form.ethinic_origin.length; i++)
    {
        if (document.entry_form.ethinic_origin[i].checked)
        {
            ethinic_origin = document.entry_form.ethinic_origin[i].value;
        }
    }
    if(ethinic_origin == null || ethinic_origin == '')
    {
        $('#equal_opportunity_error').slideDown('fast');
        $('#equal_opportunity_error').html('Please fill up Your Ethinic Origin');
        return false;
    }
    $('#equal_opportunity_error').slideUp('fast');
    for (var i=0; i <document.entry_form.ethinic_age.length; i++)
    {
        if (document.entry_form.ethinic_age[i].checked)
        {
            ethinic_age = document.entry_form.ethinic_age[i].value;
        }
    }

    if(ethinic_age == null || ethinic_age == '')
    {

        $('#equal_opportunity_error').slideDown('fast');
        $('#equal_opportunity_error').html('Please fill up Your Age');
        return false;
    }
    $('#equal_opportunity_error').slideUp('fast');
    for (var i=0; i <document.entry_form.ethinic_disability.length; i++)
    {
        if (document.entry_form.ethinic_disability[i].checked)
        {
            ethinic_disability = document.entry_form.ethinic_disability[i].value;
        }    
    }
    if(ethinic_disability == null || ethinic_disability == '')
    {
        $('#equal_opportunity_error').slideDown('fast');
        $('#equal_opportunity_error').html('Please fill up Your Disability Details');
        return false;
    }
    $('#equal_opportunity_error').slideUp('fast');
    if(document.entry_form.ethinic_check.checked)
    {
        ethinic_check = $('#ethinic_check').val();
    }
    else
    {
        $('#equal_opportunity_error').slideDown('fast');
        $('#equal_opportunity_error').html('Please Check The Box ');

        return false;
    }
    return true;
}
function data_protection_form()
{

    if(document.entry_form.d_protection.checked)
    {
        d_protection = $('#d_protection').val();
    }
    else
    {
        $('#data_protect_error').slideDown('fast');
        $('#data_protect_error').html('Please Check The Box ');

        return false;
    }

    return true;
}
function photo_form()
{

    myphoto = $('#myphoto').val();
    if(myphoto == null || myphoto == '')
    {
        $('#photo_error').slideDown('fast');
        $('#photo_error').html('Please upload Your Photo');
        
        return false;
    }
  return true;
}

function summary_form()
{
    var answer = confirm("Are you want to submit without saving the page?");
    if(answer)
    {
        document.entry_form.submit();
    }
    
//form_submit();
}
/*This function is created for ajax submit but not userd at this moment
function form_submit()
{

    var dataString = 'title='+title+'&first_name='+first_name+'&surname='+surname+'&birth_day='+birth_day+
    '&country='+country+'&gender='+gender_val+'&email='+email+'&p_address='+p_address+'&m_address='+m_address+'&telephone='
    +telephone+'&mobile='+mobile+'&fax='+fax+'&s_dependency='+s_dependency+'&n_dependency='+n_dependency+
    '&passport_no='+passport_no+'&issue_date='+issue_date+'&expiry_no='+expiry_no+'&passport_copy='+passport_copy+
    '&visa_info='+visa_info+'&photo='+photo+'&academic='+academic+'&upload_certificate='+upload_certificate
    +'&save_link='+save_link+'&exam_date='+exam_date+'&score='+score+'&vocational='+vocational+'&course_name='
    +course_name+'&mode_study='+mode_study+'&session='+session+'&resume='+resume+'&finance_type='
    +finance_type+'&direct_debit='+direct_debit+'&electronic_sign='+electronic_sign;
    alert(dataString);
    $.ajax({
        type: "POST",
        url: "entry_db.php",
        data: dataString,
        success: function(a) {
           
            $('#container_td').html("Your Information has been submitted successfully")
            .append('<p>'+a+'<p>');
        }
    });
    return false;
}*/
function email_check(em)
{
    $.ajax({
        type: "POST",
        url: "email_check.php",
        data: 'em='+em,
        async: false,
        success: function(a)
		{
			//alert(a);
            db_email=a;
        }
    });
    return false;
}
function checkdate(input){
    var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
    var returnval=false
    if (!validformat.test(input))
        returnval = false;
    else
    { //Detailed check for valid date ranges
        var dayfield=input.split("/")[0]
		var monthfield=input.split("/")[1]
        var yearfield=input.split("/")[2]
        var dayobj = new Date(yearfield, monthfield-1, dayfield)
        if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
            returnval = false;
        else
            returnval=true
    }
    return returnval
}
function DateDiff(date1, date2)
{   
    var minutes = 1000 * 60;
    var hours = minutes * 60;
    var days = hours * 24;
    var years = days * 365;
    var d1 = (Date.parse(date1))/days;
    var d2 = (Date.parse(date2))/days;
    var d = d1-d2;
    return d;
}

