// JavaScript Document

function start() { 
	if (window.ActiveXObject) {
		objXmlHTTP = new ActiveXObject("Microsoft.XMLHTTP") ;  
	}
	else if (window.XMLHttpRequest) {
		objXmlHTTP = new XMLHttpRequest();
	}
}
function getCity(val)
{
	start();
	var next_data = "";
	url = "getCity.php?id="+val;
	objXmlHTTP.open("GET", url, false);  
	objXmlHTTP.send('');
	
	var inData=objXmlHTTP.responseText;
   	document.getElementById('getcity').innerHTML = inData;
}
function getpreCity(val)
{
	start();
	var next_data = "";
	url = "getpreCity.php?id="+val;
	objXmlHTTP.open("GET", url, false);  
	objXmlHTTP.send('');
	
	var inData=objXmlHTTP.responseText;
   	document.getElementById('getprecity').innerHTML = inData;
}
function getUniversity(val)
{
	start();
	var next_data = "";
	url = "getUniversity.php?id="+val;
	objXmlHTTP.open("GET", url, false);  
	objXmlHTTP.send('');
	
	var inData=objXmlHTTP.responseText;
   	document.getElementById('getuniversity').innerHTML = inData;
}

function getGudUniversity(val)
{
	start();
	var next_data = "";
	url = "getGudUniversity.php?id="+val;
	objXmlHTTP.open("GET", url, false);  
	objXmlHTTP.send('');
	
	var inData=objXmlHTTP.responseText;
   	document.getElementById('getguduniversity').innerHTML = inData;
}

function getStream(val)
{
	start();
	var next_data = "";
	url = "getStream.php?id="+val;
	objXmlHTTP.open("GET", url, false);  
	objXmlHTTP.send('');
	
	var inData=objXmlHTTP.responseText;
   	document.getElementById('getstream').innerHTML = inData;
}
function getGudStream(val)
{
	start();
	var next_data = "";
	url = "getGudStream.php?id="+val;
	objXmlHTTP.open("GET", url, false);  
	objXmlHTTP.send('');
	
	var inData=objXmlHTTP.responseText;
   	document.getElementById('getGudStream').innerHTML = inData;
}
function checkothers(val)
    {
		if(val==-1){
			document.getElementById('grudst').style.display ='block';
		}else { 
			document.getElementById('grudst').style.display ='none';
		}
		return true;
    }  
function checkpsothers(val)
    {
		if(val==-1){
			document.getElementById('pgst').style.display ='block';
		}else { 
			document.getElementById('pgst').style.display ='none';
		}
		return true;
    }  
function checkpothers(val)
    {
		if(val==-1){
			document.getElementById('pgstudy1').style.display ='block';
		}else { 
			document.getElementById('pgstudy1').style.display ='none';
		}
    	return true;
    }
function checkcity(val)
    {
		if(val==-1){
			document.getElementById('city').style.display ='block';
		}else { 
			document.getElementById('city').style.display ='none';
		}
    	return true;
    }  
function checkprecity(val)
    {
		if(val==-1){
			document.getElementById('precity').style.display ='block';
		}else { 
			document.getElementById('precity').style.display ='none';
		}
    	return true;
    }  
	
function checkuniversity(val){
	if(val==-1)
		document.getElementById('uni').style.display = 'block';
	else
		document.getElementById('uni').style.display = 'none';
}

function checkguduniversity(val){
	if(val==-1)
		document.getElementById('guduni').style.display = 'block';
	else
		document.getElementById('guduni').style.display = 'none';
}
function enableField(){
		f= document.Registration;
		if(f.degree[0].checked==true){
			document.getElementById('pg').style.display ='block';
			document.getElementById('grad').style.display ='none';
		}else if(f.degree[1].checked==true){
			document.getElementById('grad').style.display ='block';
			document.getElementById('pg').style.display ='none';
		}
    	return true;
}

function insertemail(){
	f = document.Registration;
	f.txtwusername.value = f.txtemail.value ;
	
}

function valid()
{
	f= document.Registration;
	
	if(Trim(f.txtsfname.value) == ""){
		alert("Please Enter The First Name");
		f.txtsfname.value="";
		f.txtsfname.focus();
		return false;
	}
	if(isAlpha(f.txtsfname.value) ==""){
		alert("Please Enter The Valid First Name");
		f.txtsfname.value="";
		f.txtsfname.focus();
		return false;
	}
	
	if(Trim(f.txtslname.value) == ""){
		alert("Please Enter The Last Name");
		f.txtslname.value="";
		f.txtslname.focus();
		return false;
	}
	if(isAlpha(f.txtslname.value) ==""){
		alert("Please Enter The Valid Last Name");
		f.txtslname.value="";
		f.txtslname.focus();
		return false;
	}
	if(f.drpdd.value==""){
		alert("Please Select The Date");
		f.drpdd.focus();
		return false;
	}
	if(f.drpmm.value==""){
		alert("Please Select The Month");
		f.drpmm.focus();
		return false;
	}
	if(f.drpyyyy.value==""){
		alert("Please Select The Year");
		f.drpyyyy.focus();
		return false;
	}
	if(f.gender.value == ""){
		alert("Please Select The Gender");
		f.gender.focus();
		return false;
	}
	if(f.mstatus.value == ""){
		alert("Please Select The Marital Status");
		f.mstatus.focus();
		return false;
	}
	if(Trim(f.txtemail.value) == ""){
		alert("Please Enter The Email ID");
		f.txtemail.value="";
		f.txtemail.focus();
		return false;
	}
	if(isEmail(f.txtemail.value) == ""){
		alert("Please Enter The Valid Email Id");
		f.txtemail.focus();
		return false;
	}
	if(isNaN(f.txtnumber.value)){
		alert("Please Enter The Valid Contact Number ");
		f.txtnumber.value="";
		f.txtnumber.focus();
		return false;
	}
	
	if(f.txtcountry.value==""){
		alert("Please Enter The Country of Residence");
		f.txtcountry.focus();
		return false;
	}
	if((Trim(f.txtcity.value) == "") || (f.txtcity.value == "-99")){
		alert("Please Enter The City of Residence");
		f.txtcity.focus();
		return false;
	}
	if(f.txtcity.value == '-1'){
		if(Trim(f.cityname.value) == ""){
			alert("Please Enter The City Name");
			f.cityname.value="";
			f.cityname.focus();
			return false;
		}
	}
	if(f.degree[0].checked==true){
		if(f.txtcountryuni.value==""){
			alert("Please Select The Country of Education");
			f.txtcountryuni.focus();
			return false;
		}
		if(f.txtpguniversity.value==""){
			alert("Please Select The University");
			f.txtpguniversity.focus();
			return false;
		}
		if(f.txtpguniversity.value=="-1"){
			if(Trim(f.university.value)==""){
				alert("Please Enter The University Name");
				f.university.focus();
				return false;
			}
		}
		
		if((f.txtpgstream.value=="")){
			alert("Please Select The Field of Study");
			f.txtpgstream.focus();
			return false;
		}
		if((f.specialpost.value=="")){
			alert("Please Select The Specialization");
			f.specialpost.focus();
			return false;
		}
		if(f.specialpost.value=="-1"){
			if(Trim(f.pgstream.value)==""){
				alert("Please Enter The Field of Study");
				f.pgstream.focus();
				return false;
			}
		}
		if(Trim(f.txtpgscore.value)==""){
			alert("Please Enter The Score (in Percentage)");
			f.txtpgscore.focus();
			return false;
		}
		if((isNaN(f.txtpgscore.value)) || (f.txtpgscore.value<=0) || (f.txtpgscore.value >100)){
			alert("Please Enter The Valid Score (in Percentage)");
			f.txtpgscore.focus();
			return false;
		}
	
		if(Trim(f.txtpgcom.value)==""){
			alert("Please Select Year of Completion");
			f.txtpgcom.focus();
			return false;
		}
	}else if(f.degree[1].checked==true){
		if(f.txtgcountryuni.value==""){
			alert("Please Select The Country of Education");
			f.txtgcountryuni.focus();
			return false;
		}
		if(f.txtguniversity.value==""){
			alert("Please Select The University");
			f.txtguniversity.focus();
			return false;
		}
		if(f.txtguniversity.value=="-1"){
			if(Trim(f.guduniversity.value)==""){
				alert("Please Enter The University Name");
				f.guduniversity.focus();
				return false;
			}
		}
		if((f.txtgstream.value=="")){
			alert("Please Select The Field of Study");
			f.txtgstream.focus();
			return false;
		}
		if((f.specialgud.value=="")){
			alert("Please Select The Specialization");
			f.specialgud.focus();
			return false;
		}
		if(f.specialgud.value=="-1"){
			if(Trim(f.gradstream.value)==""){
				alert("Please Enter The Field of Study");
				f.gradstream.focus();
				return false;
			}
		}
		if(Trim(f.txtgrascore.value)==""){
			alert("Please Enter The Score (in Percentage)");
			f.txtgrascore.focus();
			return false;
		}
		if((isNaN(f.txtgrascore.value)) || (f.txtgrascore.value<=0) || (f.txtgrascore.value >100)){
			alert("Please Enter The Valid Score (in Percentage)");
			f.txtgrascore.focus();
			return false;
		}
		if(Trim(f.txtgracom.value)==""){
			alert("Please Select Year of Completion");
			f.txtgracom.focus();
			return false;
		}
	
	}
	if((Trim(f.txtresume.value)=="") && (Trim(f.txtresume1.value)=="")){
			alert("Please Upload the Resume");
			f.txtresume.focus();
			return false;
	}
	var testFile = document.getElementById('txtresume').value;
	if( testFile != "" )
	{
		var t = testFile.substr(testFile.length-3);
		if((t.toUpperCase() != "DOC")) {
			alert("Invalid Document Type");
			document.getElementById('txtresume').focus();
			return false;
		} 
	}
		if(f.txtprecountry.value==""){
		alert("Please Select The Pefferend Country");
		f.txtprecountry.focus();
		return false;
	}
	if((f.txtprecity.value=="")||(f.txtprecity.value==-99)){
		alert("Please Select The Pefferend City");
		f.txtprecity.focus();
		return false;
	}
	if(f.txtcity.value=="-1"){
		if(Trim(f.cityname.value)==""){
			alert("Please Enter The City Name");
			f.cityname.focus();
			return false;
		}
	}
	if(f.jobarea.value == ""){
		alert("Please Select The Functional area");
		f.jobarea.focus();
		return false;
	}
	if(f.jobtype.value == ""){
		alert("Please Select The Job Type");
		f.jobtype.focus();
		return false;
	}
	
	if(f.faceid.value=="")
	{
		if(Trim(f.txtwpassword.value) == ""){
			alert("Please Enter The Password");
			f.txtwpassword.value="";
			f.txtwpassword.focus();
			return false;
		}
		if((f.txtwpassword.value.length <6 ) || (f.txtwpassword.value.length > 13 )){
			alert("Please Enter Minimum 6 Digits and Maxmimum 12 Digits of Password");
			f.txtwpassword.focus();
			return false;
		}
		if(f.txtwconfirm.value != f.txtwpassword.value){
			alert("Passwords are Mis-Matched");
			f.txtwconfirm.focus();
			return false;
		}
	}
	
	if(Trim(f.txtesecurity.value) == ""){
		alert("Please Enter The Security Code in the Above Image");
		f.txtesecurity.value="";
		f.txtesecurity.focus();
		return false;
	}
	if(f.agree.checked == false){
		alert("Please Check I have read and agreed to the Terms & Conditions.");
		f.agree.focus();
		return false;
	}
	return true;
}

function Trim(str)
			{   
					while(str.charAt(0) == (" ") )
					   {  
						str = str.substring(1);
						
					    }
				while(str.charAt(str.length-1) == " " )
				   {  
						str = str.substring(0,str.length-1);
						
					}
				return str;
			}

function isEmail ( string ) 
{
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}

function isAlpha( string )
{
	if(string.search(/^[A-Za-z,\.\'\-_\\ ]{1,}$/) != -1)
		return true;
    else 
		return false;
}

function isAlphaNumeric( string )
{
	if(string.search(/^[A-Za-z0-9\#\.\'\-_\\ ]+$/) != -1)
		return true;
    else 
		return false;
}
