var ns4=(document.layers)?true:false;
var ie4=(document.all)?true:false;
var ie5=(document.getElementbyID)?true:false;
//=================================================
/*Text Validation function*/
function textValidate(incomingString, defaultValue)
{
	if(trimSpace(incomingString).length == 0 || incomingString.search(/[^a-zA-Z ]/g) != -1 || incomingString==defaultValue)
	{
		return false;
	}
	else
		return true;
}
//====================================================
//====================================================
/*Number Validation function*/
function numberValidate(incomingString, defaultValue)
{
	if(trimSpace(incomingString).length == 0 || incomingString.search(/[^0-9\.]/g) != -1 || incomingString==defaultValue || parseInt(incomingString, 10) <= 0 )
	{
		return false;
	}
	else
		return true;	
}
//====================================================
//====================================================
/*Email Validation function*/
function isEmail (s)
	{   
		// there must be >= 1 character before @, so we
		// start looking at character position 1 
		// (i.e. second character)
		var i = 1;
		var sLength = s.length;

		// look for @
		while ((i < sLength) && (s.charAt(i) != "@"))
		{ i++
		}

		if ((i >= sLength) || (s.charAt(i) != "@")) return false;
		else i += 2;

		// look for .
		while ((i < sLength) && (s.charAt(i) != "."))
		{ i++
		}

		// there must be at least one character after the .
		if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
		else return true;
	}
//====================================================
//====================================================
/*Radio Button Validation*/

function checkRadio(radioObj){
	for(i=0;i<radioObj.length;i++){
		if(radioObj[i].checked){
			return true	;
		}
	}
	return false;
}
//====================================================
//====================================================
/*Space Stripper Validation*/

function spaceStripper(incomingText){
	str1 = " ";
	str2 = "";
	workString=incomingText;
	while (workString.indexOf(str1)!=-1){
		workString=workString.substring(0,workString.indexOf(str1))+str2+workString.substring(workString.indexOf(str1)+str1.length,workString.length);
	}
	return workString;
}



function trimSpace(x)
{
	var emptySpace = / /g;
	var trimAfter = x.replace(emptySpace,"");
	return(trimAfter);
}
//======================================================
//======================================================
/*Alphanumeric Validation*/
function alphanumeric(incomingString, defaultValue)
{
	if(trimSpace(incomingString).length == 0 || incomingString.search(/[^0-9a-zA-Z]/g) != -1 || incomingString==defaultValue)
	{
		return false;
	}
	else
		return true;
}
//======================================================
	/*Validation for Drop Down list of Year*/
var myDate=new Date();
var month=myDate.getMonth();
var curYear=myDate.getFullYear();
function listYears(){
	/* Date of Birth(Year)*/
//=================================
		j=0;
		opt=new Option('YYYY');
		document.frmSuvidha.lstYear.options[j++]=opt;
		for(i=curYear-50;i<=curYear;i++){
			opt=new Option(i);
			document.frmSuvidha.lstYear.options[j++]=opt;
		}
//==================================
	/*Expiry Date(Year)*/
	j=0;
	opt=new Option('YYYY');
	document.frmSuvidha.lstExpYear.options[j++]=opt;
	for(i=curYear;i<=curYear+20;i++){
			opt=new Option(i);
			document.frmSuvidha.lstExpYear.options[j++]=opt;
		}
//===================================
	}


//======================================================
/*Validation for the Fields Begins*/
function validate()
{

	
	if((!textValidate(frm.firstname.value,''))){
		alert("Please enter your first name (ALPHABETS Only)")
		frm.firstname.focus();
		return false;
	}
	if((!textValidate(frm.lastname.value,''))){
		alert("Please enter your last name (ALPHABETS Only)")
		frm.lastname.focus();
		return false;
	}
	if(frm.gender.selectedIndex==0){
		alert("Please enter your Gender")
		frm.gender.focus();
		return false;
	}
	if(frm.status.selectedIndex==0){
		alert("Please enter your Marital Status")
		frm.status.focus();
		return false;
	}
	
	/*TextBox Validation for Date of Birth*/
	
	if(!numberValidate(document.frm.txtDay.value,''))
	{
		alert("Please enter Day of Birth(Numbers Only)");
		document.frm.txtDay.focus();
		document.frm.txtDay.select();
		return false;
	}
	if(document.frm.txtDay.value.length<2)
	{
		alert("Please enter two digits Day of Birth(Numbers Only)");
		document.frm.txtDay.focus();
		document.frm.txtDay.select();
		return false;
	}
	if(document.frm.txtDay.value>31)
	{
		alert("Please enter valid Day of Birth(Numbers Only)");
		document.frm.txtDay.focus();
		document.frm.txtDay.select();
		return false;
	}
	if(!numberValidate(document.frm.txtMonth.value,''))
	{
		alert("Please enter Month of Birth(Numbers Only)");
		document.frm.txtMonth.focus();
		document.frm.txtMonth.select();
		return false;
	}
	if(document.frm.txtMonth.value.length<2)
	{
		alert("Please enter two digits Month of Birth(Numbers Only)");
		document.frm.txtMonth.focus();
		document.frm.txtMonth.select();
		return false;
	}
	if(document.frm.txtMonth.value>12)
	{
		alert("Please enter valid Month of Birth(Numbers Only)");
		document.frm.txtMonth.focus();
		document.frm.txtMonth.select();
		return false;
	}
	if(document.frm.txtDay.value>29 && document.frm.txtMonth.value==02)
	{
		alert("Please enter valid Month of Birth");
		document.frm.txtMonth.focus();
		document.frm.txtMonth.select();
		return false;
	}
	
	if(!numberValidate(document.frm.txtYear.value,''))
	{
		alert("Please enter Year of Birth(Numbers Only)");
		document.frm.txtYear.focus();
		document.frm.txtYear.select();
		return false;
	}
	if(document.frm.txtYear.value.length<4)
	{
		alert("Please enter four digits Year of Birth(Numbers Only)");
		document.frm.txtYear.focus();
		document.frm.txtYear.select();
		return false;
	}
	if(document.frm.txtYear.value<(curYear-100)|| document.frm.txtYear.value>(curYear))
	{
			alert("Please enter valid year of Birth");
			document.frm.txtYear.focus();
			document.frm.txtYear.select();
			return false;
	}
	
	if(frm.country.selectedIndex==0){
		alert("Please enter your country")
		frm.country.focus();
		return false;
	}
	if(frm.residential.value==""){
		alert("Please enter your Residential Address")
		frm.residential.focus();
		return false;
	}
	if(frm.phone.value==""){
		alert("Please enter your Contact Phone Number")
		frm.phone.focus();
		return false;
	}
	if(!isEmail(frm.email.value)){
		alert("Please enter correct email id")
		frm.email.focus();
		return false;
	}
	if(frm.institute.selectedIndex==0){
		alert("Please enter your Institution Name ")
		frm.institute.focus();
		return false;
	}
	if(frm.yoa.value==""){
		alert("Please enter your Year of Admission")
		frm.yoa.focus();
		return false;
	}
	if(frm.yog.value==""){
		alert("Please enter your Year of Graduation")
		frm.yog.focus();
		return false;
	}
	if(frm.qualification.selectedIndex==0){
		alert("Please enter your Qualification")
		frm.qualification.focus();
		return false;
	}
	if(frm.discipline.selectedIndex==0){
		alert("Please enter your Discipline")
		frm.insdisc1.focus();
		return false;
	}
	if(frm.grade.selectedIndex==0){
		alert("Please enter your Grade")
		frm.grade.focus();
		return false;
	}
	
return true;
}