// JavaScript Document

function checkStudentInformation(){
	var firstName 	= document.getElementById('first_name').value;
	var dd			= document.getElementById('dd').value;
	var mm			= document.getElementById('mm').value;
	var yyyy		= document.getElementById('yy').value;
	var dob         = yyyy+"-"+mm+"-"+dd
	var passportNo  = document.getElementById('passport_no').value;
	var redioObj = document.getElementsByName("appTypeRadio");
	for(i=0;i<redioObj.length;i++){
		if(redioObj[i].checked == true){
		 applicationType = redioObj[i].value;
		}
	}
	var postCode    = document.getElementById('pcode_cor').value;		
	requesturl  	= "include/php/ajax/studentAS.php";
	action   		= "checkStuInfo";
	urlData 		= "action="+action+"&firstName="+firstName+"&dob="+dob+"&passportNo="+passportNo+"&applicationType="+applicationType+"&postCode="+postCode;
	ajaxRequestSynchronous(requesturl, urlData, "GET");
	return resultResponse ;
			
}
function checkPassportNo(){
	if(document.getElementById('passport_no').value!=""){
		var passportNo  = document.getElementById('passport_no').value;
		}else{
		return 0;
		}
	requesturl  	= "include/php/ajax/studentAS.php";
	action   		= "checkPassportNo";
	urlData 		= "action="+action+"&passportNo="+passportNo;
	ajaxRequestSynchronous(requesturl, urlData, "GET");
	return resultResponse ;
			
}
function validatePermanentAddress(){ 
   
	if($("#line1_home").val() == ""){
		alert('Please enter address on Address Line 1');
		$("#line1_home").focus();
		return false;
	}
	if($("#home_country").val() == ""){
		alert('Please select Country');
		$("#home_country").focus();
		return false;
	}
	if($("#home_state").val() == ""){
		alert('Please select State / Province');
		$("#home_state").focus();
		return false;
	}
	if($("#home_city").val() == ""){
		alert('Please select City');
		$("#home_city").focus();
		return false;
	}
	if($("#pcode_home").val() == ""){
		alert('Please enter Post code');
		$("#pcode_home").focus();
		return false;
	}
	if( ($("#homeMobile").val() == "") && ($("#tel_no").val() == "")){
		alert('Please enter any one contact number');
		$("#homeMobile").focus();
		return false;
	}
	
}

function validateUkAddress(){ 
	if($("#line1_cor").val() == ""){
		alert('Please enter address on Address Line 1');
		$("#line1_cor").focus();
		return false;
	}
	if($("#cor_country").val() == ""){
		alert('Please select Country');
		$("#cor_country").focus();
		return false;
	}
	if($("#cor_state").val() == ""){
		alert('Please select State / Province');
		$("#cor_state").focus();
		return false;
	}
	if($("#cor_city").val() == ""){
		alert('Please select City');
		$("#cor_city").focus();
		return false;
	}
	if($("#pcode_cor").val() == ""){
		alert('Please enter Post code');
		$("#pcode_cor").focus();
		return false;
	}
	if( ($("#tel_uk").val() == "") && ($("#mobile_uk").val() == "")){
		alert('Please enter any one contact number');
		$("#main_telephone").focus();
		return false;
	}
	
}


window.onload=show;
	function show(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
		}
	if (d) {d.style.display='block';}
	}
	function copytoright()
	{document.addrform.button1.click()
	}
	function mota(f){		
		f.style.backgroundColor="#DDF0FE"; 	
	}	
	function chota(f){		
		f.style.backgroundColor="#ffffff";	
	}	
	
	  HM_DOM = (document.getElementById) ? true : false;
	
	  HM_NS4 = (document.layers) ? true : false;
	
	  HM_IE = (document.all) ? true : false;
	
	  HM_IE4 = HM_IE && !HM_DOM;
	
	  HM_Mac = (navigator.appVersion.indexOf('Mac') != -1);
	
	  HM_IE4M = HM_IE4 && HM_Mac;
	
	  HM_OPERA = (navigator.cpuClass) ? false : true;
	
	  HM_IsMenu = ((HM_IE && !HM_IE4 && !HM_OPERA));
	
	function winopen(url,width,height){		
		var www, screen_w, screen_h, derived_w, derived_h;		
			screen_h = screen.availHeight-60;	
			screen_w = screen.availWidth-20;	
			derived_h = screen_h;	
			derived_w = screen_w;		
			if ( width < screen_w ) 	
				derived_w = width;		
			if ( height < screen_h )	
				derived_h = height;			
			www = top.window.open(url,'www','top=5,left=5,resizable=yes,scrollbars=yes,status=yes,menubar=no,height='+derived_h+',width='+derived_w);
	}
	function submitForm()
	{
		var objform = document.getElementById('apply');
				
		if(document.getElementById('apply').txtName.value == '' )
		{
			alert ('Please enter Your Name.');
			objform.txtName.focus();
			return false;
		}
		else if(document.getElementById('apply').txtEmail.value == '' )
		{
			alert ('Please Enter Your Email Address.');
			objform.txtEmail.focus();
			return false;
		}
		return true;
	}
	function dateCompare(obj,msg)
	{
		var datevalue1	= obj.value;
		var day1		= datevalue1.substring(0,2);//alert(day1);
		var month1		= datevalue1.substring(3,5)-1;	//alert(month1);
		var year1		= datevalue1.substring(6,10);//alert(year1);
		var d1			= new Date(year1,month1,day1);
		var today 		= new Date();
		if (d1<today)
		{
			alert(msg);
			obj.value = "";
			obj.focus();
		}
	}

<!--webbot BOT="GeneratedScript" PREVIEW=" " startspan -->
<!--

function applicationType(type){
	
	if(type == 3){
		$("#selectPermanentAdd").show();
		$("#selectUkAdd").show();
	}else{
		$("#selectPermanentAdd").hide();
		$('#selectUkAdd').hide();
		
	}
	if(type == 1){
		$("#passportNoMandatory").hide();
		$("#passportExpiryMandatory").hide();
		$("#visaNoMandatory").hide();
		$("#visaExpiryMandatory").hide();
	}
	if(type == 2){
		$("#passportNoMandatory").show();
		$("#passportExpiryMandatory").show();
		
	}
	if(type == 2){
		if($("#hdnvisaApp").val() == "Y"){
			$("#visaNoMandatory").show();
			$("#visaExpiryMandatory").show();
		}else{
			$("#visaNoMandatory").hide();
			$("#visaExpiryMandatory").hide();
		}
	}
	if(type == 3){
		$("#passportNoMandatory").show();
		$("#passportExpiryMandatory").show();
		$("#visaNoMandatory").show();
		$("#visaExpiryMandatory").show();
	}
	
}

function FrontPage_Form3_Validator(theForm)
{
	if($("#title").val() == "Title"){		
		alert('Please Select Title');
		$("#title").focus();
		return false;
	}
	if($("#first_name").val() == ""){
		alert('Please Enter First Name.');
		$("#first_name").focus();
		return false;
	}
	if($("#surname").val() == ""){
		alert('Please Enter Surname.');
		$("#surname").focus();
		return false;
	}
  	
	if($("#gender").val() == "M/F/O"){
		
		alert('Please Select Gender');
		$("#gender").focus();
		return false;
	}
	if($("#dd").val() == ""){		
		alert('Please Select DD Option');
		$("#dd").focus();
		return false;
	}
	if($("#mm").val() == ""){		
		alert('Please Select MM Option');
		$("#mm").focus();
		return false;
	}
   if($("#yy").val() == ""){		
		alert('Please Select yyyy Option');
		$("#yy").focus();
		return false;
	}
	
	if($("#stud_nationality").val() == ""){		
		alert('Please Select Nationality');
		$("#stud_nationality").focus();
		return false;
	}
	
	 
 var applicationType ="";
	var redioObj = document.getElementsByName("appTypeRadio");
	for(i=0;i<redioObj.length;i++){
		if(redioObj[i].checked == true){
		 applicationType = redioObj[i].value;
		}
	}
	if(applicationType == 3){
		if($("#passport_no").val() == ""){
			alert('Please Enter Passport No');
			$("#passport_no").focus();
			return false;
		}
		if($("#passport_expiry").val() == ""){
			alert('Please Enter Passport Expiry');
			$("#passport_expiry").focus();
			return false;
		}
		if($("#visa_no").val() == ""){
			alert('Please Enter Visa No');
			$("#visa_no").focus();
			return false;
		}
		if($("#visa_expiry").val() == ""){
			alert('Please Enter Visa Expiry');
			$("#visa_expiry").focus();
			return false;
		}
	}
	if(applicationType == 2){
		if($("#passport_no").val() == ""){
			alert('Please Enter Passport No');
			$("#passport_no").focus();
			return false;
		}
		if($("#passport_expiry").val() == ""){
			alert('Please Enter Passport Expiry');
			$("#passport_expiry").focus();
			return false;
		}
		
	}	
	if(applicationType == 1){
		if(validateUkAddress() == false){
			return false;
		}
	}else if(applicationType == 2){
		if(validatePermanentAddress() == false){
			return false;
		}
	}else{
			if(applicationType == 3){		
				if(validatePermanentAddress() == false){
					return false;
				}
				if(validateUkAddress() == false){
					return false;
				}
			}
		}

 var result = checkStudentInformation();
 	if(result == 1){
		alert("Application already submitted with given details.");
		$("#passport_no").focus();
		return false;
	}
var passportResult = checkPassportNo();
 	if(passportResult == 1){
		alert("Passport Number already Exit.");
		$("#passport_no").focus();
	return false;
	}
   var shorCourseName =$("#shortCourseCombo1").val();
   	if(shorCourseName!=""){
		if($("#shortCourseCombo1").val() == "0"){
			alert("Please Select Short Course");
			$("#shortCourseCombo1").focus();
			return false;
		}
		
		if($("#durationCombo1").val() == ""){
			alert("Please Select Short Course Duration.");
			$("#durationCombo1").focus();
			return false;
		}	
		if($("#scstartDateTxt1").val() == ""){
			alert("Please Enter Short Course Start Date");
			$("#scstartDateTxt1").focus();
			return false;
		}
		if($("#timeCombo1").val() == ""){
			alert("Please Select Short Course Time of Day");
			$("#timeCombo1").focus();
			return false;
		}	
	}
	var courseName =$("#stud_course_type").val();
	if(courseName!=""){	
		if($("#stud_course_type").val() == ""){
			alert("Please Select Course.");
			$("#stud_course_type").focus();
			return false;
		}
		if($("#course_start_date").val() == ""){
			alert("Enter Course Start Date.");
			$("#course_start_date").focus();
			return false;
		}	
		if($("#course_start_date").val() == ""){
			alert("Enter Course End Date.");
			$("#course_end_date").focus();
			return false;
		}	
	}
	if(shorCourseName == "" && courseName == ""){
		alert("Please Select either Short Course or Professional Course");
		return false;
	}
	if($("#aims_reasons").val() == ""){
			alert("Please Enter Aims Reasons");
			$("#aims_reasons").focus();
			return false;
		}	
	
	if($("#ec_name").val() == ""){
			alert("Please Enter Next Of kin Name");
			$("#ec_name").focus();
			return false;
		}	
	
   if($("#ec_relation").val() == ""){
			alert("Please Enter Next Of kin Relation");
			$("#ec_relation").focus();
			return false;
		}	
	
    if($("#ec_add_line1").val() == ""){
			alert("Please Enter Next Of kin Address");
			$("#ec_add_line1").focus();
			return false;
		}	
	 
	if($("#ec_add_city").val() == ""){
			alert("Please Enter Next Of kin Home City");
			$("#ec_add_city").focus();
			return false;
		}	
	 
   if($("#ec_add_pincode").val() == ""){
			alert("Please Enter Next Of kin Zip Code");
			$("#ec_add_pincode").focus();
			return false;
		}	
	 
	if($("#ec_phone_no").val() == ""){
			alert("Please Enter Next Of kin Phone No");
			$("#ec_phone_no").focus();
			return false;
		}	
	 
	if($("#hear_abt_us").val() == ""){
			alert("Please Select How did you hear about us?");
			$("#hear_abt_us").focus();
			return false;
		}	
	  
  
   theForm.submit();
 }
 