 var class1=0,class2=0,class3=0;
 function validate()
 {
   
      var flag = true;
 	if((getSel(document.searchJobs.region) == '0' && getSel(document.searchJobs.country) == '0' && getSel(document.searchJobs.mpost1) == '0'  && getSel(document.searchJobs.class1) == '0') && document.searchJobs.jtitle.value =='' && document.searchJobs.adno.value == ''&& document.searchJobs.adType.value=='')
 	{
 	  alert("Specify your search criteria OR Enter an advertisement no.");
 	  document.searchJobs.adType.focus();
 	  flag = false;
 	}
 	class1 = parseInt(getSel(document.searchJobs.class1));
	class2 = parseInt(getSel(document.searchJobs.class2));
	class3 = parseInt(getSel(document.searchJobs.class3));
	if(class1 != 0 && class2 != 0 && class1 == class2)
	{
 	  alert("Classification 1 and 2 are same.\nSelect different classification for 2.");
 	  document.searchJobs.class2.focus();
 	  flag = false;
	}
	if(class3 != 0 && (class1 == class3 || class2 == class3))
	{
 	  alert("Classification 3 is same as 1 0r 2.\nSelect a different value for classification 3.");
 	  document.searchJobs.class3.focus();
 	  flag = false;
	}
	if((getSel(document.searchJobs.class1) >= 6 && getSel(document.searchJobs.class1)<=23)&& document.searchJobs.jtitle.value != '')	
	{
		if(confirm("CAUTION:\n It is advisible to select either Functional Area or Occupation Title\n but you have used both.\nDo you want to Continue ? "))		
		{
			flag = true;
		}
		else{
					
			flag = false;
			}
			
	}else if ((getSel(document.searchJobs.class2) >= 6 && getSel(document.searchJobs.class2)<=23)&& document.searchJobs.jtitle.value != '')
	{
		if(confirm("CAUTION:\n It is advisible to select either Functional Area or Occupation Title\n but you have used both.\nDo you want to Continue ? "))
		{		
			flag = true;
		}	
		else{
		
			flag = false;
		}
	}
	else if ((getSel(document.searchJobs.class3) >= 6 && getSel(document.searchJobs.class3)<=23)&& document.searchJobs.jtitle.value != '')
	{
		if(confirm("CAUTION:\n It is advisible to select either Functional Area or Occupation Title\n but you have used both.\nDo you want to Continue ? "))
		{
			flag = true;
		}
		 else {
			flag = false;
		}
	}
	if(getSel(document.searchJobs.class1) == 5 || getSel(document.searchJobs.class1)==24  ||getSel(document.searchJobs.class3) == 5 || getSel(document.searchJobs.class3)==24 ||  getSel(document.searchJobs.class2) == 5 || getSel(document.searchJobs.class2)==24 )
	{alert("You have seleced the Title not the value in one of the Classification Areas");
	flag = false;
	}
	if(flag && (getSel(document.searchJobs.region) != '0' || getSel(document.searchJobs.country) != '0' || getSel(document.searchJobs.mpost1) != '0'  || getSel(document.searchJobs.class1) != '0' || document.searchJobs.jtitle.value != '' || document.searchJobs.adType.value!='' ) && document.searchJobs.adno.value != '')
	{	  
	  if(confirm("You have entered both Advt. no. and search criteria.\n The system will search by search criteria"))
	    document.searchJobs.adno.value = '';	    
	    
	}
	var classifications = new Array();
	if (parseInt(class1) != 0)
		classifications[classifications.length] = class1;
	if (parseInt(class2) != 0)
		classifications[classifications.length] = class2;
	if (parseInt(class3) != 0)
		classifications[classifications.length] = class3;
	if (classifications.length > 1){
		if (!isSameClassificationCategory(classifications) && document.searchJobs.operand[0].checked)
		{
			if (!confirm("Your selection criteria ANY is too lax. Do you want to convert ANY to ALL condition and continue?")){
				document.searchJobs.isAnyClassificationsOptedExplicitly.value='true';
			}
			else{
				document.searchJobs.operand[1].checked=true;
				document.searchJobs.isAnyClassificationsOptedExplicitly.value='false';
			}
		}
		if (isSameClassificationCategory(classifications) && document.searchJobs.operand[1].checked)
		{
			alert("Since you have selected very strict criteria, the ALL condition will be altered to ANY");
			document.searchJobs.isAnyClassificationsOptedExplicitly.value='true';
			document.searchJobs.operand[0].checked=true;
		}
	}
	if(flag && document.searchJobs.adno.value == '')
	{
		document.searchJobs.method ='POST';		
		document.searchJobs.action = '../jsp/jjsearchResult.jsp';
		document.searchJobs.submit();
	}
	if(flag && document.searchJobs.adno.value != '')
	{
		if (isProperJobCode(document.searchJobs.adno.value))
		{
			document.searchJobs.method ='POST';		
			document.searchJobs.action = '../jsp/jjapplyByAdno.jsp';
			document.searchJobs.submit();
		}
	}	
 }

 function validatenormal()
 {
    document.searchJobsnormal.class1.value = getSel(document.searchJobsnormal.functional);
	document.searchJobsnormal.class2.value = getSel(document.searchJobsnormal.lineof);	
	document.searchJobsnormal.class3.value = getSel(document.searchJobsnormal.sizeof);	
      var flag = true;
 	if((getSel(document.searchJobsnormal.region) == '0' && getSel(document.searchJobsnormal.country) == '0'  && getSel(document.searchJobsnormal.functional) == '0')  && document.searchJobsnormal.adno.value == ''&& document.searchJobsnormal.adType.value=='')
 	{
 	  alert("Specify your search criteria OR Enter an advertisement no.");
 	  document.searchJobsnormal.adType.focus();
 	  flag = false;
 	}
 	
 	
 	if(getSel(document.searchJobsnormal.functional) == '0' && getSel(document.searchJobsnormal.lineof) != '0' && getSel(document.searchJobsnormal.sizeof) != '0')
 	{
 	   {
 	   	document.searchJobsnormal.class1.value = getSel(document.searchJobsnormal.lineof);
        document.searchJobsnormal.class2.value = getSel(document.searchJobsnormal.sizeof);
        document.searchJobsnormal.class3.value='0';
 	   }
 	  
 	} 	
 	else if(getSel(document.searchJobsnormal.functional) == '0' && getSel(document.searchJobsnormal.lineof) != '0' && getSel(document.searchJobsnormal.sizeof) == '0')
 	{
		document.searchJobsnormal.class1.value = getSel(document.searchJobsnormal.lineof);
		document.searchJobsnormal.class2.value = '0';
	} 	
 	else if(getSel(document.searchJobsnormal.functional) == '0' && getSel(document.searchJobsnormal.lineof) == '0' && getSel(document.searchJobsnormal.sizeof) != '0')
	{	
		document.searchJobsnormal.class1.value = getSel(document.searchJobsnormal.sizeof);
		document.searchJobsnormal.class3.value = '0';
 	} 	
 	else if(getSel(document.searchJobsnormal.functional) != '0'&& getSel(document.searchJobsnormal.lineof) == '0' && getSel(document.searchJobsnormal.sizeof) != '0')
	{
		document.searchJobsnormal.class2.value = getSel(document.searchJobsnormal.sizeof);
		document.searchJobsnormal.class3.value= '0';
	}
	if(flag && (getSel(document.searchJobsnormal.region) != '0' || getSel(document.searchJobsnormal.country) != '0' || document.searchJobsnormal.mpost1 != '0'  || getSel(document.searchJobsnormal.functional) != '0' || document.searchJobsnormal.jtitle.value != '' || document.searchJobsnormal.adType.value!='' ) && document.searchJobsnormal.adno.value != '')
	{	  
	  if(confirm("You have entered both Advt. no. and search criteria.\n The system will search by search criteria"))
	    document.searchJobsnormal.adno.value = '';	    
	    
	}
	if(flag && document.searchJobsnormal.adno.value == '')
	{
	
		document.searchJobsnormal.method ='POST';		
		document.searchJobsnormal.action = '../jsp/jjsearchResult.jsp';
		document.searchJobsnormal.submit();
	}
	if(flag && document.searchJobsnormal.adno.value != '')
	{
		if (isProperJobCode(document.searchJobsnormal.adno.value))
		{
			document.searchJobsnormal.method ='POST';		
			document.searchJobsnormal.action = '../jsp/jjapplyByAdno.jsp';
			document.searchJobsnormal.submit();
		}
	}	
 }
 
 
 function del()
 {
 	document.searchJobs.method = 'POST';	
        document.searchJobs.action = 'jjsearchJobs.jsp?dis=Saved&del='+document.searchJobs.del.value+'&sv='+document.searchJobs.ct.value;
	document.searchJobs.submit(); 
 }
 
 function isProperJobCode(jobCode)
 {
 	if (jobCode == null || jobCode == '')
 	{
 		alert("Not a valid job code");
 		return false;
 	}
 	jobCode = jobCode.replace(/^\s+/g, '').replace(/\s+$/g, '').replace(/ /g, '');
 	var digitsBeforeComma = 7;
 	var maxDigitsAfterComma = 3;
 	var reJobCode = new RegExp("^\\d{" + digitsBeforeComma + "}$|^\\d{" + digitsBeforeComma + "}[,]\\d{1," + maxDigitsAfterComma + "}$");
 	if (jobCode.match(reJobCode) == null)
 	{
	 	alert("Not a valid job code");
 		return false;
 	}
 	return true;
 }
function isSameClassificationCategory(classifications)
{
	return (isFunctionalAreas(classifications) || isLineOfBusinesses(classifications) || isSizeOfOrganisations(classifications));
}
function isFunctionalAreas(classifications)
{
	var result = true;
	for (var classificationsIndex = 0; parseInt(classificationsIndex) < classifications.length && result; )
	{
		result = result & (parseInt(classifications[parseInt(classificationsIndex)]) > 5 && parseInt(classifications[parseInt(classificationsIndex)]) < 24) || (parseInt(classifications[parseInt(classificationsIndex)]) > 33 && parseInt(classifications[parseInt(classificationsIndex)]) < 37) || (parseInt(classifications[parseInt(classificationsIndex)]) > 78 && parseInt(classifications[parseInt(classificationsIndex)]) < 84);
		classificationsIndex = parseInt(classificationsIndex) + 1;
	}
	return result;
}
function isLineOfBusinesses(classifications)
{
	var result = true;
	for (var classificationsIndex = 0; parseInt(classificationsIndex) < classifications.length && result; )
	{
		result = result & (parseInt(classifications[parseInt(classificationsIndex)]) > 24 && parseInt(classifications[parseInt(classificationsIndex)]) < 34) || (parseInt(classifications[parseInt(classificationsIndex)]) > 36 && parseInt(classifications[parseInt(classificationsIndex)]) < 79) || (parseInt(classifications[parseInt(classificationsIndex)]) > 83 && parseInt(classifications[parseInt(classificationsIndex)]) < 86);
		classificationsIndex = parseInt(classificationsIndex) + 1;
	}
	return result;
}
function isSizeOfOrganisations(classifications)
{
	var result = true;
	for (var classificationsIndex = 0; parseInt(classificationsIndex) < classifications.length && result; )
	{
		result = result & (parseInt(classifications[parseInt(classificationsIndex)]) > 0 && parseInt(classifications[parseInt(classificationsIndex)]) < 5);
		classificationsIndex = parseInt(classificationsIndex) + 1;
	}
	return result;
}
function orgNameValidator(event)
{
     return charsOnly(event) || specificCharactersOnly(' ', event);
}