
// ============ Returns an array containing country and city ============

function onBodyLoad()
{
	document.frmJobSearch.txtKeywords.focus();
	document.frmJobSearch.hidSubVal.value=0;
}

function call()
{
	if(document.frmJobSearch.selCountry.value!="sel")
	{
		getState('frmJobSearch','selState',document.frmJobSearch.selCountry.value);
		restoreDropDownVal();
		getCity('frmJobSearch','selCity',document.frmJobSearch.selState.value);
	}
	document.frmJobSearch.txtKeywords.focus();
}

function populateReqNumber(reqnum)
{
	document.frmReqNum.hidReqNum.value=reqnum;
	document.frmReqNum.submit();


}

function getState(frmName,fieldName,selectedValue)
{
	var states=new Array("India¤Karnataka", "India¤Maharashtra", "India¤Haryana", "USA¤California", "USA¤Florida", "USA¤Illinois", "USA¤Massachusetts");
	populateDropDown(frmName,fieldName,selectedValue,states);
	document.frmJobSearch.selState.focus();
	document.frmJobSearch.selState.blur();
}

function getCity(frmName,fieldName,selectedValue)
{
	var cities=new Array("Karnataka¤Bangalore", "Maharashtra¤Pune", "Haryana¤Delhi", "California¤Irvine", "California¤Orange", "Florida¤Miami", "Illinois¤Peoria", "Massachusetts¤Woburn");
	populateDropDown(frmName,fieldName,selectedValue,cities);
}


function saveDropDownVal()
{
	//alert("saving..."+document.frmJobSearch.selState.selectedIndex);
	document.frmJobSearch.hidIndex.value=document.frmJobSearch.selState.selectedIndex;
}

function restoreDropDownVal()
{
	//alert("restoring..."+document.frmJobSearch.hidIndex.value);
	document.frmJobSearch.selState.selectedIndex=document.frmJobSearch.hidIndex.value;
}

function openWin()
{
	window.open("emailFriend.jsp","","width=440,height=320,top=150,left=250,resizable=no,status");
}


// ============ Populates a drop down on change of previous drop down ============

function populateDropDown(frmName,fieldName,selectedValue,array)
{
	var opt;
	var obj=eval("document."+frmName+"."+fieldName);
	if(selectedValue!="sel")
	{
		obj.options.length=1;
		for(i=0;i<array.length;i++)
		{
			var splitVals="";
			if(array[i].substring(0,array[i].indexOf("¤"))==selectedValue)
			{
				splitVals=array[i].split("¤")[1];
				obj.options.length+=1;
				opt=new Option;
				opt.text=opt.value=splitVals;
				obj.options[obj.options.length-1]=opt;
			}
		}
	}
	else
	{
		obj.options.length=1;
		opt=new Option;
		opt.text="--- All ---";
		opt.value="sel";
		obj.options[obj.options.length-1]=opt;
	}
}

function subForm(param)
{
	var intPgCount=parseInt(document.frmDisp.hidMaxVal.value);
	if(param=="p")
		intPgCount-=intIncr;
	else if(param=="n")
		intPgCount+=intIncr;
	else
		intPgCount=param;
	//alert(intPgCount);
	document.frmDisp.hidMaxVal.value=intPgCount;
	document.frmDisp.submit();
}

// ============ Validates a form ============
function validate()
{
	var keywords = document.frmJobSearch.txtKeywords.value;
	keywords = removeExtraSpaces(keywords);
	var isIegal = "false";
	isLegal	= checkIllegalChar(keywords);
	if (isLegal)
		{	
		document.frmJobSearch.hidSubVal.value=1;
		document.frmJobSearch.submit();
		}
	else
		{
		alert("Unrecognizable character(s) within Keywords");	
		}	

	
	

}

function hitEnter(event)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if(keyCode==13) 
		return false 
	else	
		return true;
}

// ============ Checks illegal characters ============
function checkIllegalChar(keywords)
{
	var strIllegal='!@#%^()\/\\\"\'+?:;<>=[]{}-_`~';
	var strActual=keywords;
	var count=0;
	var character='';
	for(i=0;i<strActual.length;i++)
	{
		for(j=0;j<strIllegal.length;j++)
		{
			if(strActual.charAt(i)==strIllegal.charAt(j))
			{
				character=strActual.charAt(i);
				count++;
			}
		}
	}
	if(count>0)
	{
		
		return false;
	}
	return true;
}

// ============ Replacing extra spaces with single ============

function removeExtraSpaces(str)
{
	if(str!="")
	{
		var str1="";
		for(var i=0;i<str.length;i++)
		{
			if((str.charAt(i)==" ") && (str.charAt(i+1)==" "))
				str1=str1;
			else
				str1=str1+str.charAt(i);
		}
		return str1;
	}
	else
		return str;
}

function chkWebsiteRadio()
{
	if(document.frmSubResume.selWebsite.selectedIndex!=0)
		document.frmSubResume.elements[24].checked=true;
	else	
		document.frmSubResume.elements[24].checked=false;
}

function checkPrefPhone(phone,prefphone)
{
	var txtobj=eval("document.frmSubResume."+phone);
	var chkobj=eval("document.frmSubResume.elements["+parseInt(prefphone)+"]");
	alert(chkobj);
	
	if(txtobj.value.length>0)
		chkobj.disabled=false;
	else
		chkobj.disabled=true;
	
	if(chkobj.checked==true && txtobj.value.length==0)
	{
		chkobj.checked=false;
	}
}

