// JavaScript Document
//Registration Script
function validate()
{
//Login Information
var userId=document.registration.userId.value;
var spa=document.registration.userId.value.split(' ').length
var len=userId.length;
	if(len==0)
	{
	alert("Please enter your User Id");
	document.registration.userId.focus(true);
	document.registration.userId.select();
	return false;
	}
	if(spa>1)
	{
	alert("Spaces are not allowed in User Id.");
	document.registration.userId.focus(true);
	document.registration.userId.select();
	return false;
	}
	if(len<6)
	{
	alert ("The User Id must be at least 6 characters in length.");
	document.registration.userId.focus(true);
	document.registration.userId.select();
	return false;
	}
	if(len>20)
	{
	alert ("The User Id must not be more than 20 characters in length.");
	document.registration.userId.focus(true);
	document.registration.userId.select();
	return false;
	}
	for(var i=0;i<len;i++)
	{
		if((userId.charAt(i)>='a' && userId.charAt(i)<='z') ||(userId.charAt(i)>='A' && userId.charAt(i)<='Z')||(userId.charAt(i)>=0 && userId.charAt(i)<=9)||(userId.charAt(i)=='.')||(userId.charAt(i)=='_')||(userId.charAt(i)=='@'))
		{}
		else
		{
		alert("Please enter your User Id in(Alphabet,Number,Dot,@) ");
		document.registration.userId.focus(true);
		document.registration.userId.select();
		return false;
		}
	}
var pass=document.registration.pass.value;
var len=pass.length;
	if(len==0)
	{
	alert("Please enter your password");
	document.registration.pass.focus(true);
	document.registration.pass.select();
	return false;
	}
	if(len<6)
	{
	alert("Password must be at least 6 characters in length.");
	document.registration.pass.focus(true);
	document.registration.pass.select();
	return false;
	}
	if(len>25)
	{
	alert("Password must not be more than 25 characters in length.");
	document.registration.pass.focus(true);
	document.registration.pass.select();
	return false;
	}
var confPass=document.registration.confPass.value;
var len=confPass.length;
	if(len==0)
	{
	alert("Please confirm your password");
	document.registration.confPass.focus(true);
	document.registration.confPass.select();
	return false;
	}		
	if(confPass!=pass)
	{
	alert("Please enter confirm password same as password");
	document.registration.confPass.focus(true);
	document.registration.confPass.select();
	return false;
	}
//End Login Information

//Contact Information
var fname=document.registration.fname.value;
var len=fname.length;
	if(len==0)
	{
	alert("Please enter your full name");
	document.registration.fname.focus(true);
	document.registration.fname.select();
	return false;
	}
	for(var i=0;i<len;i++)
	{
		if((fname.charAt(i)>='a' && fname.charAt(i)<='z') ||(fname.charAt(i)>='A' && fname.charAt(i)<='Z')||(fname.charAt(i)==" "))
		{}
		else
		{
		alert("Please enter name in characters only");
		document.registration.fname.focus(true);
		document.registration.fname.select();
		return false;
		}
	}
var emailId=document.registration.emailId;
//check if email is not entered or only spaces are entereds in appropriate textbox
	if ((emailId.value==null)||(emailId.value==""))
	{
	alert("Please enter your email id");
// set cursor to the textbox provided for email entry
	document.registration.emailId.focus();
	document.registration.emailId.select();
	return false;
	}
	if (emailCheck(emailId.value)==false)
	{
	emailId.value="";
	document.registration.emailId.focus();
	document.registration.emailId.select();
	return false;
	}
var mobile=document.registration.mobile.value;
var len=mobile.length;
	if(len==0)
	{
	alert("Please enter your mobile number");
	document.registration.mobile.focus(true);
	document.registration.mobile.select();
	return false;
	}
	if(len<10)
	{
	alert("Please enter valid mobile number");
	document.registration.mobile.focus(true);
	document.registration.mobile.select();
	return false;
	}
	if(isNaN(mobile))
	{
	alert ("Please enter your mobile number in numbers only.");
	document.registration.mobile.focus(true);
	document.registration.mobile.select();
	return false;
	}
var currLocation=document.registration.currLocation.value;
	if(currLocation=="")
	{
	alert("Please select current location");
	document.registration.currLocation.focus(true);
	return false;
	}
//End Contact Information
//Educational Level
var basicEdu_level=document.registration.basicEdu_level.value;
	if(basicEdu_level=="")
	{
	alert("Please select your education level");
	document.registration.basicEdu_level.focus(true);
	return false;
	}
//End Educational Level
//Work Experience Information
var jobCategory=document.registration.jobCategory.value;
	if(jobCategory=="")
	{
	alert("Please select your job category");
	document.registration.jobCategory.focus(true);
	return false;
	}
var role=document.registration.role.value;
	if(role=="")
	{
	alert("Please select at least one role");
	document.registration.role.focus(true);
	return false;
	}
	if(document.registration.role.selectedIndex!="")
	{
	var lenRole=document.getElementById("role").length;
	var countRole=0;
	var i=1;
		for(i=1;i<lenRole;i++)
		{
			if(document.getElementById("role").options[i].selected)
			{
			countRole++;
			}
		}
		if(countRole>4)
		{
		alert("you can select maximum of 4 roles");
		document.getElementById("role").focus();
		return false;
		}
	}
var keySkills=document.registration.keySkills.value;
var len=keySkills.length;
	if(len==0)
	{
	alert("Please enter your key skills");
	document.registration.keySkills.focus(true);
	document.registration.keySkills.select();
	return false;
	}
var carrLevel=document.registration.carrLevel.value;
	if(carrLevel=="")
	{
	alert("Please select career level");
	document.registration.carrLevel.focus(true);	
	return false;
	}
	if(document.registration.carrLevel.value!="Fresher-Entry Level")
	{
	var exp_in_years=document.registration.exp_in_years.value;
		if(exp_in_years=="")
		{
		alert("Please select experiance in years");
		document.registration.exp_in_years.focus(true);
		return false;
		}
	var exp_in_months=document.registration.exp_in_months.value;
		if(exp_in_months=="")
		{
		alert("Please select experiance in months");
		document.registration.exp_in_months.focus(true);
		return false;
		}
	var currIndustry=document.registration.currIndustry.value;
		if(currIndustry=="")
		{
		alert("Please select your current industry");
		document.registration.currIndustry.focus(true);
		return false;
		}
	var currEmployer=document.registration.currEmployer.value;
	var len=currEmployer.length;
		if(len==0)
		{
		alert("Please enter your current company name.");
		document.registration.currEmployer.focus(true);
		document.registration.currEmployer.select();
		return false;
		}
	var currDesign=document.registration.currDesign.value;
	var len=currDesign.length;
		if(len==0)
		{
		alert("Please enter your current designation.");
		document.registration.currDesign.focus(true);
		document.registration.currDesign.select();
		return false;
		}
	var ctc_lacs=document.registration.ctc_lacs.value;
		if(ctc_lacs=="")
		{
		alert("Please select your current ctc in lacs");
		document.registration.ctc_lacs.focus(true);
		return false;
		}
	var ctc_thousands=document.registration.ctc_thousands.value;
		if(ctc_thousands=="")
		{
		alert("Please select your current ctc in thousands");
		document.registration.ctc_thousands.focus(true);
		return false;
		}
	var annSal=document.registration.annSal.value;
		if(annSal=="")
		{
		alert("Please select your current ctc in INR/USD");
		document.registration.annSal.focus(true);
		return false;
		}
	var empStatus=document.registration.empStatus.value;
		if(empStatus=="")
		{
		alert("Please select your employment status");
		document.registration.empStatus.focus(true);
		return false;
		}
	var jobTiming=document.registration.jobTiming.value;
		if(jobTiming=="")
		{
		alert("Please select your job timing");
		document.registration.jobTiming.focus(true);
		return false;	
		}
	}
//End Work Experience Information
//Resume Details
var resHeading=document.registration.resHeading.value;
var len=resHeading.length;
	if(len==0)
	{
	alert("Please enter your resume heading.");
	document.registration.resHeading.focus(true);
	document.registration.resHeading.select();
	return false;
	}
var cutPasteResume=document.registration.cutPasteResume.value;
var len=cutPasteResume.length;
	if(len==0)
	{
	alert("you are required to Cut&Paste your Resume in the box provided");
	document.registration.cutPasteResume.focus(true);
	return false;
	}
var uploadResume=document.registration.uploadResume.value;
	if(uploadResume=="")
	{
	alert("Please upload a text/word resume.");
	document.registration.uploadResume.focus();
	document.registration.uploadResume.select();
	return(false); 
	}
var fileTypes=["txt","doc"];
var source=document.registration.uploadResume.value;
var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
	for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
	if (i<fileTypes.length)
	{
	globalPic.src=source;
	}
	else
	{
	alert("\nPlease upload your resume in a .txt or .doc format only");
	document.registration.uploadResume.focus();
	return false;
	}
//End Resume Details
}
//Email Function
function emailCheck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
// check if '@' is at the first position or at last position or absent in given email 
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
	alert("Invalid E-mail ID")
	return false
	}
// check if '.' is at the first position or at last position or absent in given email
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 ||	str.indexOf(dot)==lstr)
	{
	alert("Invalid E-mail ID")
	return false
	}
// check if '@' is used more than one times in given email
	if (str.indexOf(at,(lat+1))!=-1)
	{
	alert("Invalid E-mail ID")
	return false
	}
// check for the position of '.'
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
	alert("Invalid E-mail ID")
	return false
	}
// check if '.' is present after two characters from location of '@'
	if (str.indexOf(dot,(lat+2))==-1)
	{
	alert("Invalid E-mail ID")
	return false
	}
// check for blank spaces in given email
	if (str.indexOf(" ")!=-1)
	{
	alert("Invalid E-mail ID")
	return false
	}
return true
}
/////////////////////////////////////////////////-----------------AJAX(USER ID)--------------------------////////////////////
function chk_userId(userId)
{ //alert(userId);
	if(window.XMLHttpRequest)
	{
	http=new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
	http=new ActiveXObject("Microsoft.XMLHTTP");
	}
	handle=document.getElementById(userId);
	//alert(document.getElementById(userId));
	var url='chk_ajax.php?';
	//alert(url);
	if(handle.value.length>=6)
	{
	var fullurl=url+'do=chk_userID_exist&userID='+encodeURIComponent(handle.value);
	//alert(fullurl);
	http.open("GET",fullurl,true);
	http.send(null);
	http.onreadystatechange=statechange_userId;
	}
	else
	{
	document.getElementById('userID_exists').innerHTML='';
	}
}

function statechange_userId()
{
	if(http.readyState==4)
	{
	var xmlObj=http.responseXML;
	var html=xmlObj.getElementsByTagName('result').item(0).firstChild.data;
	document.getElementById('userID_exists').innerHTML=html;
	}
}
/////////////////////////////----------------AJAX(EMAIL ID)---------------///////////////////////////////
function chk_e_Id(emailId)
{
	if(window.XMLHttpRequest)
	{
	http=new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
	http=new ActiveXObject("Microsoft.XMLHTTP");
	}
	handle=document.getElementById(emailId);
	var url='chk_ajax.php?';
	if(handle.value.length>0)
	{
	var fullurl=url+'do=chk_emailID_exist&emailID='+encodeURIComponent(handle.value);
	http.open("GET",fullurl,true);
	http.send(null);
	http.onreadystatechange=statechange_eId;
	}
	else
	{
	document.getElementById('e_ID_exists').innerHTML='';
	}
}
function statechange_eId()
{
	if(http.readyState==4)
	{
	var xmlObj=http.responseXML;
	var html=xmlObj.getElementsByTagName('result').item(0).firstChild.data;
	document.getElementById('e_ID_exists').innerHTML=html;
	}
}
/////////////////////////////----------------AJAX(JOB CATEGORY & ROLE)---------------///////////////////////////////
function Ajax_cat_role(jobCategory)
{
var httpxml;
	try
	{
	// Firefox, Opera 8.0+, Safari
	httpxml=new XMLHttpRequest();
	}
	catch (e)
	{
  // Internet Explorer
		try
		{
		httpxml=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
			httpxml=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			alert("Your browser does not support AJAX!");
			return false;
			}
		}
	}
	function stateck() 
	{
		if(httpxml.readyState==4)
		{
		var myarray=eval(httpxml.responseText);
		// Before adding new we must remove previously loaded elements
			for(j=document.registration.role.options.length-1;j>=0;j--)
			{
			document.registration.role.remove(j);
			}
			for (i=0;i<myarray.length;i++)
			{
			var optn = document.createElement("OPTION");
			optn.text = myarray[i];
			optn.value = myarray[i];
			document.registration.role.options.add(optn);
			} 
		}
	}
var url="dd.php";
url=url+"?jobCategory="+jobCategory;
url=url+"&catId="+Math.random();
httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
}
/////////////////////////////----------------DISABLE---------------///////////////////////////////
function disable_formEle()
{
	var carrLevel=document.registration.carrLevel;
	if(carrLevel.options[carrLevel.selectedIndex].value=="Fresher-Entry Level")
	{
	document.registration.exp_in_years.disabled=true;
	document.registration.exp_in_months.disabled=true;
	document.registration.currIndustry.disabled=true;
	document.registration.currEmployer.disabled=true;
	document.registration.comp_pro_ser.disabled=true;
	document.registration.currDesign.disabled=true;
	document.registration.ctc_lacs.disabled=true;
	document.registration.ctc_thousands.disabled=true;
	document.registration.annSal.disabled=true;
	document.registration.empStatus.disabled=true;
	document.registration.jobTiming.disabled=true;
	document.getElementById('emp2').style.display="none";
	document.getElementById('emp1').style.display="none";
	document.getElementById('emp3').style.display="none";
	
	}
	else
	{
	document.registration.exp_in_years.disabled=false;
	document.registration.exp_in_months.disabled=false;
	document.registration.currIndustry.disabled=false;
	document.registration.currEmployer.disabled=false;
	document.registration.comp_pro_ser.disabled=false;
	document.registration.currDesign.disabled=false;
	document.registration.ctc_lacs.disabled=false;
	document.registration.ctc_thousands.disabled=false;
	document.registration.annSal.disabled=false;
	document.registration.empStatus.disabled=false;
	document.registration.jobTiming.disabled=false;
	document.getElementById('emp2').style.display="block";
	document.getElementById('emp1').style.display="block";
	document.getElementById('emp3').style.display="block";
	}
}
///////////////////////////-------------------Hide / Display(PG and Doctorate)--------------------////////////////
function hide_pg_doct()
{
var basicEdu_level=document.registration.basicEdu_level;
	if(basicEdu_level.options[basicEdu_level.selectedIndex].value=="Not Pursuing Graduation")
	{
	document.registration.postGr_level.value="";
	document.registration.doct_level.value="";
	var pg_lev = document.getElementById('pg_lev');
	pg_lev.style.display = "none";
	var doct_lev = document.getElementById('doct_lev');
	doct_lev.style.display = "none";
	}
	else
	{
	var pg_lev = document.getElementById('pg_lev');
	pg_lev.style.display = "block";
	var doct_lev = document.getElementById('doct_lev');
	doct_lev.style.display = "block";	
	}
}
/////////////////////////////////-------------------On Load Script------------------//////////////////////////
function loadScript()
{
//document.registration.basicEdu_level.value="";
var basicEdu_level=document.registration.basicEdu_level;
	if(basicEdu_level.options[basicEdu_level.selectedIndex].value=="Not Pursuing Graduation")
	{
	var pg_lev = document.getElementById('pg_lev');
	pg_lev.style.display = "none";
	var doct_lev = document.getElementById('doct_lev');
	doct_lev.style.display = "none";
	}
	else
	{
	var pg_lev = document.getElementById('pg_lev');
	pg_lev.style.display = "block";
	var doct_lev = document.getElementById('doct_lev');
	doct_lev.style.display = "block";	
	}
document.registration.jobCategory.value="";
}
////////////////////////

