//--------------------------------- TEST CENTER VALIDATION ----------------------------------------//
function select_center() { 
	var val="";

	for (var i=0; i < document.phase2.test_city.length; i++)
	{
	  if (document.phase2.test_city[i].selected)
	  {
		  val = Trim(document.phase2.test_city[i].value);		  
	  }
	}
	//alert("val = "+val);
	if(val==""){
		alert("Please select a test center");
		document.getElementById('star19').style.visibility='visible';
		document.getElementById('star19').style.display = "block";
		document.phase2.test_city.focus();
		return false;
	}
	else{
		document.getElementById('star19').style.visibility='hidden';
		document.getElementById('star19').style.display = "none";
		return true;
	}
} 

//--------------------------------- PROGRAMME VALIDATION ----------------------------------------//
function select_pathway() { 
	var val="";

	for (var i=0; i < document.phase1.pathway_type.length; i++)
	{
	  if (document.phase1.pathway_type[i].checked)
	  {
		  val = Trim(document.phase1.pathway_type[i].value);		  
	  }
	}
	//alert("val = "+val);
	if(val==""){
		alert("Please select a Pathways type:");
		document.getElementById('star0').style.visibility='visible';
		document.getElementById('star0').style.display = "block";
		document.phase1.pathway_type[0].focus();
		return false;
	}
	else{
		document.getElementById('star0').style.visibility='hidden';
		document.getElementById('star0').style.display = "none";
		return true;
	}
} 

//--------------------------------- PROGRAMME VALIDATION ----------------------------------------//
function select_progtype() { 
	var val="";

	for (var i=0; i < document.phase1.prog_type.length; i++)
	{
	  if (document.phase1.prog_type[i].checked)
	  {
		  val = Trim(document.phase1.prog_type[i].value);		  
	  }
	}
	//alert("val = "+val);
	if(val==""){
		alert("Please select a Programme type:");
		document.getElementById('star0').style.visibility='visible';
		document.getElementById('star0').style.display = "block";
		return false;
	}
	else{
		document.getElementById('star0').style.visibility='hidden';
		document.getElementById('star0').style.display = "none";
		return true;
	}
} 

//--------------------------------- PROGRAMME VALIDATION ----------------------------------------//
function select_program() { 
	var val="";

	for (var i=0; i < document.phase1.sub_prog_id.length; i++)
	{
	  if (document.phase1.sub_prog_id[i].checked)
	  {
		  val = Trim(document.phase1.sub_prog_id[i].value);		  
	  }
	}
	//alert("val = "+val);
	if(val==""){
		alert("Please select a Programme");
		document.getElementById('star1').style.visibility='visible';
		document.getElementById('star1').style.display = "block";
		document.phase1.sub_prog_id[0].focus();
		return false;
	}
	else{
		document.getElementById('star1').style.visibility='hidden';
		document.getElementById('star1').style.display = "none";
		return true;
	}
} 
//--------------------------------- CAMPUS PREFERENCE VALIDATION ----------------------------------------//
function select_campus() { 
	var val="";

	for (var i=0; i < document.phase1.campus_id.length; i++)
	{
	  if (document.phase1.campus_id[i].checked)
	  {
		  val = Trim(document.phase1.campus_id[i].value);		  
	  }
	}
	//alert("val = "+val);
	if(val==""){
		alert("Please select a Campus");
		document.getElementById('star2').style.visibility='visible';
		document.getElementById('star2').style.display = "block";
		document.phase1.campus_id[0].focus();
		return false;
	}
	else{
		document.getElementById('star2').style.visibility='hidden';
		document.getElementById('star2').style.display = "none";
		return true;
	}
} 
//--------------------------------- NAME VALIDATION ----------------------------------------//
function select_name() { 
	var fname = Trim(document.phase1.fname.value);
	if(fname=="" || fname==" " || fname==null){
		document.getElementById('star3').style.visibility='visible';
		document.getElementById('star3').style.display = "block";
		alert("Please fill in your first name");
		document.phase1.fname.focus();
		return false;
	}
	else{
		document.getElementById('star3').style.visibility='hidden';
		document.getElementById('star3').style.display = "none";
		return true;
	}

}
//--------------------------------- GUARDIAN NAME VALIDATION ----------------------------------------//
function select_gname() { 
	var guardian = Trim(document.phase1.guardian.value);

	if(guardian=="" || guardian==" " || guardian==null){
		document.getElementById('star4').style.visibility='visible';
		document.getElementById('star4').style.display = "block";
		alert("Please fill in your guardian name");
		document.phase1.guardian.focus();
		return false;
	}
	else{
		document.getElementById('star4').style.visibility='hidden';
		document.getElementById('star4').style.display = "none";
		return true;
	}
}
//--------------------------------- ADDRESS VALIDATION ----------------------------------------//
function select_address() { 
	var address = Trim(document.phase1.address.value);

	if(address=="" || address==" " || address==null || address==0){
		document.getElementById('star10').style.visibility='visible';
		document.getElementById('star10').style.display = "block";
		alert("Please fill in your address");
		document.phase1.address.focus();
		return false;
	}
	else{
		document.getElementById('star10').style.visibility='hidden';
		document.getElementById('star10').style.display = "none";
		return true;
	}
}
//--------------------------------- PHONE WITH STD/ISD VALIDATION ----------------------------------------//
function select_phone() { 
	//var std = Trim(document.phase1.std.value);
	var ph = Trim(document.phase1.phone.value);
	/*
	if(std=="" || std==" " || std==null){
		document.getElementById('star15').style.visibility='visible';
		document.getElementById('star15').style.display = "block";
		alert("Please fill in your alternate number with std code");
		document.phase1.std.focus();
		return false;
	}else
	*/ 
	if(ph=="" || ph==" " || ph==null){
		document.getElementById('star16').style.visibility='visible';
		document.getElementById('star16').style.display = "block";
		alert("Please fill in your alternate number");
		document.phase1.phone.focus();
		return false;
	}
	else{
		document.getElementById('star16').style.visibility='hidden';
		document.getElementById('star16').style.display = "none";
		return true;
	}
}
//--------------------------------- MOBILE VALIDATION ----------------------------------------//
function select_mobile() { 
	var mobile = Trim(document.phase1.mobile.value);

	if(mobile=="" || mobile==" " || mobile==null){
		document.getElementById('star15').style.visibility='visible';
		document.getElementById('star15').style.display = "block";
		alert("Please fill in your mobile number");
		document.phase1.mobile.focus();
		return false;
	}
	else{
		document.getElementById('star15').style.visibility='hidden';
		document.getElementById('star15').style.display = "none";
		return true;
	}
}
//--------------------------------- DATE OF BIRTH(DOB)VALIDATION ----------------------------------------//

function select_dob() { 
	var dob = Trim(document.phase1.dob.value);
	if(dob=="" || dob==" " || dob==null){
		alert("Please select your Date of Birth");
		document.getElementById('star5').style.visibility='visible';
		document.getElementById('star5').style.display = "block";
		document.phase1.dob.focus();
		return false;
	}
	else{
		document.getElementById('star5').style.visibility='hidden';
		document.getElementById('star5').style.display = "none";
		return true;
	}
}
//--------------------------------- CATEGORY VALIDATION ----------------------------------------//
function select_category() { 
	var val="";

	for (var i=0; i < document.phase1.category.length; i++)
	{
	  if (document.phase1.category[i].checked)
	  {
		  val = document.phase1.category[i].value; 
	  }
	}
	//alert("val = "+val);
	if(val==""){
		alert("Please select your category");
		document.getElementById('star8').style.visibility='visible';
		document.getElementById('star8').style.display = "block";
		document.phase1.category[0].focus();
		return false;
	}
	else if(val=="O"){
		document.getElementById('other_cat').style.visibility='visible';
		document.getElementById('other_cat').style.display = "block";
		if(document.forms[0].other_cat.value==""){
			alert("Fill in other category");
			document.forms[0].other_cat.focus();
			return false;
		}
		else{
			return true;
		}
	}
	else if(val!="O"){
		document.getElementById('other_cat').style.visibility='hidden';
		document.getElementById('other_cat').style.display = "none";
		document.forms[0].other_cat.value="";
	}	
	else{
		document.getElementById('star8').style.visibility='hidden';
		document.getElementById('star8').style.display = "none";
		return true;
	}
}
//--------------------------------- GENDER VALIDATION ----------------------------------------//
function select_gender() { 
	var val="";

	for (var i=0; i < document.phase1.gender.length; i++)
	{
	  if (document.phase1.gender[i].checked)
	  {
		  val = document.phase1.gender[i].value;		  
	  }
	}
	//alert("val = "+val);
	if(val==""){
		alert("Please select your gender");
		document.getElementById('star9').style.visibility='visible';
		document.getElementById('star9').style.display = "block";
		document.phase1.gender[0].focus();
		return false;
	}
	else{
		document.getElementById('star9').style.visibility='hidden';
		document.getElementById('star9').style.display = "none";
		return true;
	}
} 
//--------------------------------- EMAIL VALIDATION ----------------------------------------//

function select_email() { 
	var email=Trim(document.forms[0].email.value);		
	email = email.replace(/^\s*|\s*$/g,"");
	
	var fieldLength = email.length; 
	var err01="Enter your E-mail"; 
	var err02="Invalid E-mail"; 
	if (fieldLength < 1) 
	{
		alert( err01 ); 
		document.getElementById('star17').style.visibility='visible';
		document.getElementById('star17').style.display = "block";
		document.phase1.email.focus();
		document.phase1.email.select();
		return false;
	}
	else 
	{ 
		if( /^[\w\.-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]+$/.test(email)) 
		{
			//return true;
		}
		else 
		{ 
			alert(err02); 
			document.getElementById('star17').style.visibility='visible';
			document.getElementById('star17').style.display = "block";
			document.phase1.email.focus();
			document.phase1.email.select();
			return false;
		}
	}

	var emailpart1=email.substring(0,email.indexOf("@"));
	var ch3 = emailpart1.charAt(0);

	if((ch3 < "a" || ch3 > "z") && (ch3 < "A" || ch3 > "Z")) 
	{
		alert("Invalid E-mail");
		document.getElementById('star17').style.visibility='visible';
		document.getElementById('star17').style.display = "block";
		document.phase1.email.focus();
		document.phase1.email.select();
		return false;
	}

	if(email=="" || email==" " || email==null){
		document.getElementById('star17').style.visibility='visible';
		document.getElementById('star17').style.display = "block";
		alert("Please fill in your address");
		document.phase1.email.focus();
		return false;
	}
	else{
		document.getElementById('star17').style.visibility='hidden';
		document.getElementById('star17').style.display = "none";
		return true;
	}
}


//--------------------------------- UG HSC PERCENTAGE VALIDATION ----------------------------------------//

function hscPerc() {
	var hsc = Trim(document.phase2.hsc_perc.value);
	if(hsc!=""){
		parseInt(hsc);
	}
	else{
		hsc=0;
	}
	if(hsc<=0 || hsc>100){
		alert("HSC should be greater than zero and less than or equal to 100.");
		document.phase2.hsc_perc.value="";
		document.phase2.hsc_perc.focus();
		return false;
	}
	else if(hsc==0){
		alert("Please enter HSC percentage");
		return false;
	}
	else{
		return true;
	}
}

//--------------------------------- PG GRADUATION PERCENTAGE VALIDATION ----------------------------------------//

function checkPerc() {
	
	var status = Trim(document.phase2.exam_status_1.value);
	//alert("status = "+status);
	if(status=="P"){		//IF EXAM STATUS IS PASSED, CHECK GRADUATION PERCENTAGE
		var grad = Trim(document.phase2.perc.value);
		if(grad!=""){
			parseInt(grad);
		}
		else{
			grad=0;
		}
		//alert("grad = "+grad);
		if(grad<=0 || grad>100){
			alert("Percentage should be greater than 0 and less or than equal to 100");
			document.phase2.perc.value="";
			document.phase2.perc.focus();
			return false;
		}
		else if(grad==0){
			alert("Please enter percentage");
			return false;
		}
		else{
			return true;
		}
	}
	else{		//IF EXAM STATUS IS APPEARED, CHECK GRADUATION PERCENTAGE
		return true;
	}
}
//--------------------------------- UG OTHER PERCENTAGE VALIDATION ----------------------------------------//

function otherPerc() {
	if(document.phase2.other_perc.value.length>0){
		var other = Trim(document.phase2.other_perc.value);
		if(other!=""){
			parseInt(other);
		}
		else{
			other=0;
		}
		//alert("other = "+other);
		if(other<=0 || other>100){
			alert("Percentage should be greater than 0 and less or than equal to 100");
			document.phase2.other_perc.value="";
			document.phase2.other_perc.focus();
			return false;
		}
		else if(other==0){
			alert("Please enter the percentage in other");
			return false;
		}
		else{
			return true;
		}
	}
	else{
		document.phase2.other_perc.focus();
		return true;
	}
}
//--------------------------------- PERCENTAGE VALIDATION ----------------------------------------//

function fncPerc() {

	if((window.event.keyCode<46 || window.event.keyCode >57) && (window.event.keyCode!=13) || window.event.keyCode==47)
	{
		 window.event.keyCode = "0";
	}
	else{
		return true;
	}

return true;
}
//--------------------------------- EMAIL VALIDATION ----------------------------------------//

function fncEmail() {
	if((window.event.keyCode==32 ))
	{
		 window.event.keyCode = "0";
	}
}
//--------------------------------- TEST CENTER VALIDATION ----------------------------------------//
function select_test_center() { 
	var val="";

	for (var i=0; i < document.phase1.test_city.length; i++)
	{
	  if (document.phase1.test_city[i].checked)
	  {
		  val = document.phase1.test_city[i].value;		  
	  }
	}
	//alert("val = "+val);
	if(val==""){
		alert("Please select a Test Center");
		document.getElementById('star1').style.visibility='visible';
		document.getElementById('star1').style.display = "block";
		return false;
	}
	else{
		document.getElementById('star1').style.visibility='hidden';
		document.getElementById('star1').style.display = "none";
		return true;
	}
} 
//--------------------------------- INSTRUCTION PAGE PROGRAMME VALIDATION ----------------------------------------//

function select_prog(qual) { 
	var val="";

	/*for (var i=0; i < document.inst.prog.length; i++)
	{
	  if (document.inst.prog[i].checked)
	  {
		  val = document.inst.prog[i].value;		  
	  }
	}
	if(val==""){
		//alert("Please select a Program");
		return false;
	}
	else
	{*/
		document.inst.instBtn.value = " Please wait ... ";
		document.inst.instBtn.disabled = true;
		document.inst.method="POST";
		document.inst.action="mainForm.jsp";
		document.inst.submit();
	//}
}

//--------------------------------- PLACE OF BIRTH (POB) VALIDATION ----------------------------------------//

function select_pob() { 
	var pob = Trim(document.phase1.pob.value);	
	if(pob=="" || pob==" " || pob==null){
		alert("Please fill in your place of birth");
		document.getElementById('star6').style.visibility='visible';
		document.getElementById('star6').style.display = "block";
		document.phase1.pob.focus();
		return false;
	}
	else{
		document.getElementById('star6').style.visibility='hidden';
		document.getElementById('star6').style.display = "none";
		return true;
	}
}
//--------------------------------- NATIONALITY VALIDATION ----------------------------------------//

function select_nat() { 
	var nationality = Trim(document.phase1.nationality.value);	

	if(nationality=="" || nationality==" " || nationality==null){
		alert("Please fill in your nationality");
		document.getElementById('star7').style.visibility='visible';
		document.getElementById('star7').style.display = "block";
		document.phase1.nationality.focus();
		return false;
	}
	else{
		document.getElementById('star7').style.visibility='hidden';
		document.getElementById('star7').style.display = "none";
		return true;
	}
}
//--------------------------------- TOWN VALIDATION ----------------------------------------//

function select_town() { 
	var town = Trim(document.phase1.town.value);


if(town=="" || town==" " || town==null){
		alert("Please fill in your city");
		document.getElementById('star11').style.visibility='visible';
		document.getElementById('star11').style.display = "block";
		document.phase1.town.focus();
		return false;
	}
	else{
		document.getElementById('star11').style.visibility='hidden';
		document.getElementById('star11').style.display = "none";
		return true;
	}
}
//--------------------------------- STATE VALIDATION ----------------------------------------//

function select_state() { 
	var state = Trim(document.phase1.state.value);

	if(state=="" || state==" " || state==null){
		alert("Please fill in your state");
		document.getElementById('star12').style.visibility='visible';
		document.getElementById('star12').style.display = "block";
		document.phase1.state.focus();
		return false;
	}
	else{
		document.getElementById('star12').style.visibility='hidden';
		document.getElementById('star12').style.display = "none";
		return true;
	}
}
//--------------------------------- PIN VALIDATION ----------------------------------------//
function select_pin() { 
	var pin = Trim(document.phase1.pin.value);
	if(pin=="" || pin==" " || pin==null){
		alert("Please fill in your pin code");
		document.getElementById('star13').style.visibility='visible';
		document.getElementById('star13').style.display = "block";
		document.phase1.pin.focus();
		return false;
	}
	else{
		document.getElementById('star13').style.visibility='hidden';
		document.getElementById('star13').style.display = "none";
		return true;
	}
}
//--------------------------------- COUNTRY VALIDATION ----------------------------------------//
function select_ctry() { 

	var ctry = Trim(document.phase1.country.value);
	if(ctry=="" || ctry==" " || ctry==null){
		alert("Please fill in your country");
		document.getElementById('star14').style.visibility='visible';
		document.getElementById('star14').style.display = "block";
		document.phase1.country.focus();
		return false;
	}
	else{
		document.getElementById('star14').style.visibility='hidden';
		document.getElementById('star14').style.display = "none";
		return true;
	}
}
//--------------------------------- PHASE 1 SUBMIT ----------------------------------------//

function go_phase_1() { 

	/*
	if(select_pathway()==false){
		return false;
	}
	*/
	if(select_progtype()==false){
		return false;
	}
	if(select_program()==false){
		return false;
	}
	/*
	if(select_campus()==false){
		return false;
	}*/
	if(select_name()==false){
		return false;
	}
	if(select_gname()==false){
		return false;
	}
	if(select_dob()==false){
		return false;
	}
	if(select_pob()==false){
		return false;
	}
	if(select_nat()==false){
		return false;
	}
	if(select_category()==false){
		return false;
	}
	if(select_gender()==false){
		return false;
	}
	if(select_address()==false){
		return false;
	}
	if(select_town()==false){
		return false;
	}
	if(select_state()==false){
		return false;
	}
	/*
	if(select_pin()==false){
		return false;
	}*/
	if(select_ctry()==false){
		return false;
	}
	if(select_mobile()==false){
		return false;
	}
	if(mobile_digits()==false){
		return false;
	}	
	if(select_phone()==false){
		return false;
	}
	
	
	if(select_email()==false){
		return false;
	}
	if(document.phase1.mobile.value.length==10){
		var c = confirm("Is your mobile number correct?\n"+document.phase1.mobile.value);
		if(c==false){
			return false;
		}
	}
	if(document.phase1.email.value.length>1){
		var c = confirm("Is your email id correct?\n"+document.phase1.email.value);
		if(c==false){
			return false;
		}
	}
	ajaxcall();
	/*document.phase1.continue_btn.disabled=true;
	document.phase1.method="POST";
	document.phase1.action="phase1Pro.jsp";
	document.phase1.submit();
	*/
}
//--------------------------------- PHASE 2 SUBMIT ----------------------------------------//

function go_phase_2(prog) { 
	document.phase2.method="POST";
			
	if(select_center()==false){
		return false;
	}
	if(about_iam()==false){
		return false;
	}
	if(limit_words_workex()==false){
		return false;
	}
	if(limit_words_other_about()==false){
		return false;
	}
	if(select_qual(prog)==false){
		return false;
	}
	if(checkPerc()==false){
		return false;
	}
	if(checkAllPercents(prog) == false)
	{
		return false;
	}
	if(limit_words_extracurr()==false){
		return false;
	}
	if(limit_words_explain()==false){
		return false;
	}
	if(limit_words_award_1()==false){
		return false;
	}
	if(limit_words_award_2()==false){
		return false;
	}
	document.phase2.agree_sumbit.disabled=true;
	//alert("Submitting");
	document.phase2.action="pgPhase2Pro.jsp";
	document.phase2.submit();

}
//--------------------------------- UNDER GRADUATE QUALIFICATION VALIDATION ----------------------------------------//

function select_ug_qual() { 

	var hsc_yr = Trim(document.phase2.hsc_yr.value);
	var hsc_dur = Trim(document.phase2.hsc_dur.value);
	var hsc_board = Trim(document.phase2.hsc_board.value);
	var hsc_main = Trim(document.phase2.hsc_main.value);
	var hsc_perc = Trim(document.phase2.hsc_perc.value);

	if(hsc_yr=="" || hsc_dur=="" || hsc_board==""|| hsc_main==""|| hsc_perc==""){
		document.getElementById('star22').style.visibility='visible';
		document.getElementById('star22').style.display = "block";
		alert("Please fill in your hsc qualification details");
		if(hsc_yr==""){
			document.phase2.hsc_yr.focus();
		}
		else if(hsc_dur==""){
			document.phase2.hsc_dur.focus();
		}
		if(hsc_board==""){
			document.phase2.hsc_board.focus();
		}
		else if(hsc_main==""){
			document.phase2.hsc_main.focus();
		}
		else if(hsc_perc==""){
			document.phase2.hsc_perc.focus();
		}
		return false;
	}
	else{
		document.getElementById('star22').style.visibility='hidden';
		document.getElementById('star22').style.display = "none";
		return true;
	}

}
//--------------------------------- POST GRADUATE QUALIFICATION VALIDATION ----------------------------------------//
function select_qual(prog) {
	
	
	//alert("prog = "+prog);
	var yr = Trim(document.phase2.yr.value);
	var dur = Trim(document.phase2.dur.value);
	var board = Trim(document.phase2.univ.value);
	var main = Trim(document.phase2.main.value);
	var perc = Trim(document.phase2.perc.value);
	var status = Trim(document.phase2.exam_status_1.value);
	
	var other1yr = Trim(document.phase2.other_yr_1.value);
	var other1dur = Trim(document.phase2.other_dur_1.value);
	var other1board = Trim(document.phase2.other_univ_1.value);
	var other1main = Trim(document.phase2.other_main_1.value);
	var other1perc = Trim(document.phase2.other_perc_1.value);
	var other1status = Trim(document.phase2.exam_status_2.value);
 
	if(yr=="" || dur=="" || board==""|| main=="" || perc==""
		|| other1yr=="" || other1dur=="" || other1board=="" || other1main=="" || other1perc==""){
		document.getElementById('star22').style.visibility='visible';
		document.getElementById('star22').style.display = "block";
		
	}
	
	
	var firstQual="";
	if(prog == 2){
		firstQual="X / SSC";
	}else{
		firstQual="XII / HSC";
	}
	
	
	if(yr==""){
		alert("Please provide "+firstQual+" Year");
		document.phase2.yr.focus();
		return false;
	}
	if(dur==""){
		alert("Please provide "+firstQual+" Duration");
		document.phase2.dur.focus();
		return false;
	}
	if(board==""){
		alert("Please provide "+firstQual+" Board/University");
		document.phase2.univ.focus();
		return false;
	}
	if(main==""){
		alert("Please provide "+firstQual+" Mainstream");
		document.phase2.main.focus();
		return false;
	}
	if(perc==""){
		alert("Please provide "+firstQual+" Percentage");
		document.phase2.perc.focus();
		return false;
	}
		
	var secQual="";
	if(prog == 2){
		secQual="XII / HSC";
	}else{
		secQual="Graduation";
	}


	if(other1yr==""){
		alert("Please provide "+secQual+" Year");
		document.phase2.other_yr_1.focus();
		return false;
	}
	if(other1dur==""){
		alert("Please provide "+secQual+" Duration");
		document.phase2.other_dur_1.focus();
		return false;
	}
	if(other1board==""){
		alert("Please provide "+secQual+" Board/University");
		document.phase2.other_univ_1.focus();
		return false;
	}
	if(other1main==""){
		alert("Please provide "+secQual+" Mainstream");
		document.phase2.other_main_1.focus();
		return false;
	}
	if(other1perc==""){
		alert("Please provide "+secQual+" Percentage");
		document.phase2.other_perc_1.focus();
		return false;
	}

	
	document.getElementById('star22').style.visibility='hidden';
	document.getElementById('star22').style.display = "none";
	return true;
	

}
//--------------------------------- EXAM STATUS CHECK ----------------------------------------//
function exam_status(ele,percObj) { 
	var status = Trim(ele.value);
	if(status=="A"){
		document.getElementById(percObj).value="Result Awaited";
		document.getElementById(percObj).disabled=true;
	}
	else{
		document.getElementById(percObj).value="";
		document.getElementById(percObj).disabled=false;
		document.getElementById(percObj).focus();
	}
}


//--------------------------------- ABOUT IAM VALIDATION ----------------------------------------//
function about_iam() { 
	//Q5 SELECTION
var val="";
	for (var i=0; i < document.phase2.q11.length; i++)
	{
	  if (document.phase2.q11[i].checked)
	  {
		  val += document.phase2.q11[i].value;		  
		  val+="#";
	  }
	} 

	document.phase2.q1.value=val;
	if(val!=""){
		//alert("alert = "+val.indexOf("O"));
		if((val.indexOf("O")==0) || (val.indexOf("O")==2) || (val.indexOf("O")==4) || (val.indexOf("O")==6) || (val.indexOf("O")==8)) {
			//alert("other");
			document.getElementById('about_iam_other').style.visibility='visible';
			document.getElementById('about_iam_other').style.display = "block";
			document.phase2.about_other.focus();
			if(document.phase2.about_other.value==""){
				alert("Please specify other medium type");
				document.phase2.about_other.focus();
				return false;
			}
		}
		else if(val.indexOf("O")<0){
			//alert("not empty");
			document.getElementById('about_iam_other').style.visibility='hidden';
			document.getElementById('about_iam_other').style.display = "none";
			document.phase2.about_other.value="";
			return true;
		}
		if(val!=""){
			//alert("not empty");
			document.getElementById('star21').style.visibility='hidden';
			document.getElementById('star21').style.display = "none";
			return true;
		}
	}
	/*else if(val==""){
		alert("How did you get to know about IAM?");
		document.getElementById('star21').style.visibility='visible';
		document.getElementById('star21').style.display = "block";
		return false;
	}*/
	else{
		alert("How did you get to know about IAM?");
		document.getElementById('star21').style.visibility='visible';
		document.getElementById('star21').style.display = "block";
		document.phase2.q11[0].focus();
		return false;
	}
}
//--------------------------------- I AGREE CHECK ----------------------------------------//
function agree_submit() { 
	if(document.phase2.agree.checked)
	{
		document.phase2.agree_sumbit.disabled=false;
	}
	else{
		document.phase2.agree_sumbit.disabled=true;
	}
	
}
//--------------------------------- STUDENT LOGIN VALIDATION ----------------------------------------//

function slogin() { 
	var pwd = Trim(document.login.password.value);

	/*
	if(user_email()==false){
		return false;
	}
	else */
	
	if(pwd=="" || pwd==" " || pwd==null){
		alert("Please fill in your Registration Number.");
		document.login.password.focus();
		return false;
	}
	else{	
		document.login.method="POST";
		document.login.action="medPro.jsp";
		document.login.submit();
	}
}

//--------------------------------- STUDENT LOGIN EMAIL VALIDATION ----------------------------------------//
function user_email() { 
	var email=Trim(document.forms[0].username.value);		
	email = email.replace(/^\s*|\s*$/g,"");
	
	var fieldLength = email.length; 
	var err01="Enter your E-mail"; 
	var err02="Invalid E-mail"; 
	if (fieldLength < 1) 
	{
		alert( err01 ); 
		document.login.username.focus();
		document.login.username.select();
		return false;
	}
	else 
	{ 
		if( /^[\w\.-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]+$/.test(email)) 
		{
			//return true;
		}
		else 
		{ 
			alert(err02); 
			document.login.username.focus();
			document.login.username.select();
			return false;
		}
	}

	var emailpart1=email.substring(0,email.indexOf("@"));
	var ch3 = emailpart1.charAt(0);

	if((ch3 < "a" || ch3 > "z") && (ch3 < "A" || ch3 > "Z")) 
	{
		alert("Invalid E-mail");
		document.login.username.focus();
		document.login.username.select();
		return false;
	}

}

//--------------------------------- NAME FIELD VALIDATIONS ----------------------------------------//
function fncNameValidate(e) {
	var keynum 
	var keychar
	var numcheck

	if(window.event) // IE
	{
		//alert();
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	
	if(isUsefulKey(keynum) || (keynum>=65 && keynum<=90) || (keynum==8) || (keynum==222) || (keynum==9)){
		return true;
	}
	else{
		return false;
	}
}
//--------------------------------- INPUT ONLY LETTERS VALIDATION ----------------------------------------//
function fncLetter(e) {
	var keynum 
	var keychar
	var numcheck

	if(window.event) // IE
	{
		//alert();
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	if(isUsefulKey(keynum) || (keynum>=65 && keynum<=90) || (keynum==8) || (keynum==32) || (keynum==222) || (keynum==9)){
		return true;
	}
	else{
		return false;
	}
}

function isUsefulKey(keynum){
	if(keynum == 8 || keynum == 46 || keynum == 37 
		|| keynum == 38 || keynum == 39 || keynum == 40){
		return true;
	}else{
		return false;
	}
}

//--------------------------------- INPUT ONLY NUMBERS VALIDATION ----------------------------------------//

function fncNum(e) {
var keynum 
var keychar
var numcheck

if(window.event) // IE
{
	keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
	keynum = e.which
}
//alert(keynum);
//	if(keynum  != 8 && keynum  != 9 && (keynum<48 || keynum >57) || &&  (keynum<48 || keynum >57) && (keynum!=13)){
	if(isUsefulKey(keynum) || (keynum>=48 && keynum<=57) || (keynum>=96 && keynum<=105) || (keynum==8) || (keynum==16) || (keynum==9)){
		return true;
	}
	else{
		return false;
	}
}

//--------------------------------- INPUT ONLY ALPHANUMERICS VALIDATION -----------------------------------
function fncAlphaNum(e) {
	var keynum 
	var keychar
	var numcheck

	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	//alert(keynum);
//		if(keynum  != 8 && keynum  != 9 && (keynum<48 || keynum >57) || &&  (keynum<48 || keynum >57) && (keynum!=13)){
		if(isUsefulKey(keynum) || (keynum>=48 && keynum<=57) || (keynum>=96 && keynum<=105) 
				|| (keynum==8) || (keynum==16) || (keynum==9) || (keynum>=65 && keynum<=90) 
				|| (keynum==32) || (keynum==222)){
			return true;
		}
		else{
			return false;
		}
	}

//--------------------------------- INPUT ONLY NUMBERS WITH DOT VALIDATION ----------------------------------------//

function fncNumWDot(e) {
var keynum 
var keychar
var numcheck

	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	//alert(keynum);
	if(isUsefulKey(keynum) || (keynum>=48 && keynum<=57) || (keynum>=96 && keynum<=105) || (keynum==8) || (keynum==16) || (keynum==9) || (keynum==190) || (keynum==110)){
		return true;
	}
	else{
		return false;
	}
}
//--------------------------------- (LIMIT LENGTH) MOBILE TEXTBOX VALIDATION ----------------------------------------//

function mobile_digits() {
	var len = document.phase1.mobile.value.length;
	//alert(len);
	if (len<10)
	{
		alert("Mobile number should be 10 digit.");
		document.phase1.mobile.focus();
		//window.event.keyCode = "0";
		return false;
	}
	else{
		return true;
	}
}
//--------------------------------- (LIMIT WORDS) EXTRA-CURRICULAR TEXTAREA 1 VALIDATION ----------------------------------------//
function limit_words_extracurr(){
	var obj = Trim(document.phase2.extra_curr.value);
	//alert(obj);
	if(obj.length==0){
		return true;
	}
	else if(obj.length>1){
		var word = obj.match(/\s/g);
		if(word==null){
			return true;
		}
		var len=word.length;
		if(len>49){
			alert("Do not exceed 50 words in extra curricular activities.");
			document.phase2.extra_curr.focus();
			return false;
		}
		else{
			return true;
		}
	}
	else{
			return true;
	}
}
//--------------------------------- (LIMIT WORDS) EXPLAIN TEXTAREA 1 VALIDATION ----------------------------------------//

function limit_words_explain(){
	var obj = Trim(document.phase2.explain_why.value);
	//alert(obj);
	if(obj.length==0){
		return true;
	}
	else if(obj.length>1){
		var word = obj.match(/\s/g);
		if(word==null){
			return true;
		}
		var len=word.length;
		if(len>49){
			alert("Do not exceed 50 words in explaining\nwhy would you like to join iam in the preferred program.");
			document.phase2.explain_why.focus();
			return false;
		}
		else{
			return true;
		}
	}
	else{
			return true;
	}
}
//--------------------------------- (LIMIT WORDS) NATURE OF WORK TEXTBOX VALIDATION ----------------------------------------//

function limit_words_workex(){
	var obj = Trim(document.phase2.work_nature.value);
	if(obj.length==0){
		return true;
	}
	else if(obj.length>1){
		var word = obj.match(/\s/g);
		if(word==null){
			//alert("word is null");
			return true;
		}
		var len=word.length;
		if(len>19){
			alert("Do not exceed 20 words in listing your nature of work.");
			document.phase2.work_nature.focus();
			return false;
		}
		else{
			return true;
		}
	}
	else{
		return true;
	}
}

//--------------------------------- (LIMIT WORDS) NATURE OF ABOUT IAM OTHER TEXTBOX VALIDATION ----------------------------------------//

function limit_words_other_about(){
	var obj = Trim(document.phase2.about_other.value);
	if(obj.length==0){
		return true;
	}
	else if(obj.length>1){
		var word = obj.match(/\s/g);
		if(word==null){
			//alert("word is null");
			return true;
		}
		var len=word.length;
		//alert("len = "+len);
		if(len>19){
			alert("Do not exceed 20 words in listing other medium.");
			document.phase2.about_other.focus();
			return false;
		}
		else{
			return true;
		}
	}
	else{
		return true;
	}
}
//--------------------------------- (LIMIT WORDS) ACHVMNTS/AWARDS TEXTBOX 1 VALIDATION ----------------------------------------//

function limit_words_award_1(){
	var obj = Trim(document.phase2.sig_1_ach.value);
	
	if(obj.length==0){
		return true;
	}
	else if(obj.length>1){
		var word = obj.match(/\s/g);
		if(word==null){
			//alert("word is null");
			return true;
		}
		var len=word.length;
		if(len>19){
			alert("Do not exceed 20 words in listing your awards/achievements.");
			document.phase2.sig_1_ach.focus();
			return false;
		}
		else{
			return true;
		}
	}
	else{
		return true;
	}
}
//--------------------------------- (LIMIT WORDS) ACHVMNTS/AWARDS TEXTBOX 2 VALIDATION ----------------------------------------//
function limit_words_award_2(){
	var obj = Trim(document.phase2.sig_2_ach.value);
	//alert(obj);
	if(obj.length==0){
		return true;
	}
	else if(obj.length>1){
		var word = obj.match(/\s/g);
		if(word==null){
			//alert("word is null");
			return true;
		}
		var len=word.length;
		if(len>19){
			alert("Do not exceed 20 words in listing your awards/achievements.");
			document.phase2.sig_2_ach.focus();
			return false;
		}
		else{
			return true;
		}
	}
	else{
			return true;
	}
}

//--------------------------------- (LIMIT LETTERS FOR TEXTAREA) VALIDATION ----------------------------------------//

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	{
		alert("Text too long. Must be "+mlength+" characters or less!");
		obj.value=obj.value.substring(0,mlength)
	}	
}

//--------------------------------- TRIM ----------------------------------------//

function LTrim(str){if(str==null){return null;}for(var i=0;str.charAt(i)==" ";i++);return str.substring(i,str.length);}

function RTrim(str){if(str==null){return null;}for(var i=str.length-1;str.charAt(i)==" ";i--);return str.substring(0,i+1);}

function Trim(str){return LTrim(RTrim(str));}

//--------------------------------- Check All for SMS ----------------------------------------//

function checkAll(){
	var val="";
	for (var i=0; i < document.forms[0].q11.length; i++)
	{
	  if (document.forms[0].q11[i].checked)
	  {
		  val += document.forms[0].q11[i].value;		  
		  val+="#";
	  }
	}

	document.forms[0].q1.value=val;
	alert(val);
}

//--------------------------------- Check All for SMS ----------------------------------------//

function check_browser()
{
  if (navigator.appName.toUpperCase().match(/MICROSOFT INTERNET EXPLORER/) != null)
  {return false;}
 else
 {window.location.href="browser_check.jsp";}
}

var req;


//--------------------------------- AJAX CALLS ----------------------------------------//

function ajaxcall() 
{

	var email=document.forms[0].email.value;
	var altemail=document.forms[0].alt_email.value;
	var poststr = "axEmail="+email+"&axAltEmail="+altemail;
	//alert(poststr);

	var url = "calage.jsp";
	req=GetXmlHttpObject()
   

   req.open("post", url, true);
   req.onreadystatechange = callback;
   req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   req.setRequestHeader("Content-length", poststr.length);
   //req.setRequestHeader("Connection", "close");
   req.send(poststr);
}



function GetXmlHttpObject()
{
   var xmlHttp=null;

			try
			 {
			 // Firefox, Opera 8.0+, Safari
			 xmlHttp=new XMLHttpRequest();
			 }
			catch (e)
			 {
			 // Internet Explorer
			 try
			  {
			  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			  }
			 catch (e)
			  {
			  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			 }
			return xmlHttp;
}

function callback() 
{
	
			if (req.readyState == 4) 
			 {
				if (req.status == 200) 
				 {
					// update the HTML DOM based on whether or not message is valid
					parseMessage();
				 }
			 }
}

function parseMessage() 
 {

     
 
    var message = (req.responseText);

	     var exp = (req.responseXML).getElementsByTagName('message');
		 //alert("message = "+message);
			 var message;
			  //alert(exp.length);
			 for( var i = 0; i < exp.length; i++ )
		     {
				message = exp[i].firstChild.nodeValue;
			 }
	
	data=message.replace(/^\s+|\s+$/g,"");
	         //alert("data = "+data);  				
			 if(data!="valid")
			 {
				 var con = confirm("You have already registered with IAM.\nTo register yourself again(in result of cancellation of earlier registration) , \nplease continue or else contact at 011-40508149\nDo you wish to continue?");
				 if(con){
					 alert("Your earlier registration no : "+data+" has been cancelled, please use your new registration number for future communication.");
					document.forms[0].continue_btn.value="Processing your request....";
					document.forms[0].prev_reg.value=data;
					document.forms[0].continue_btn.disabled=true;
					document.forms[0].method="POST";
					document.forms[0].action="phase1Pro.jsp";
					document.forms[0].submit();		
				 }
				 else{					 
					 return false;
				 }
			 }
			 else
			 {
				document.forms[0].continue_btn.value="Processing your request....";
				document.forms[0].continue_btn.disabled=true;
				document.forms[0].method="POST";
				document.forms[0].action="phase1Pro.jsp";
				document.forms[0].submit();							
			 }
 }


function percentValidation(perObj){
	perValue = Trim(perObj.value);
	if(perValue!="")
	{
		var re = /^\d{1,3}(\.\d{1,2})?$/;
		if(!re.test(perValue)){
			alert("Please enter valid percentage.\nThe number of digits before decimal should be less than or equal to 3 and the  number of digits after decimal should be less than or equal to 2");
			perObj.focus();
		}
	}	
}

function checkAllPercents(prog){
	var examStatus1 = document.forms[0].exam_status_1.value;
	var examStatus2 = document.forms[0].exam_status_2.value;
	var examStatus3 = document.forms[0].exam_status_3.value;
	var examStatus4 = document.forms[0].exam_status_4.value;
	
	var perVal1 = document.forms[0].perc.value;
	var perVal2 = document.forms[0].other_perc_1.value;
	var perVal3 = document.forms[0].other_perc_2.value;
	var perVal4 = document.forms[0].other_perc_3.value;
	
	var re = /^\d{1,3}(\.\d{1,2})?$/;
	if(perVal1 != "" && examStatus1 == "P"){
		
		if(!re.test(perVal1)){
			if(prog==2){
				alert("Please enter valid percentage of X / SSC.");
			}else{
				alert("Please enter valid percentage of XII / HSC.");
			}
			document.forms[0].perc.focus();
			return false;
		}
	}
	if(perVal2 != "" && examStatus2 == "P"){
		
		if(!re.test(perVal2)){
			if(prog==2){
				alert("Please enter valid percentage of XII / HSC.");
			}else{
				alert("Please enter valid percentage of Graduation.");
			}
			document.forms[0].other_perc_1.focus();
			return false;
		}
	}
	if(perVal3 != "" && examStatus3 == "P"){
		
		if(!re.test(perVal3)){
			
			alert("Please enter valid percentage of Any Other 1.");
			
			document.forms[0].other_perc_2.focus();
			return false;
		}
	}
	if(perVal4 != "" && examStatus4 == "P"){
		
		if(!re.test(perVal4)){
			
			alert("Please enter valid percentage of Any Other 2.");
			
			document.forms[0].other_perc_3.focus();
			return false;
		}
	}
	
	return true;
	
}

