//vilpesh-for offices search form

function openSearchpopup(form, popup, width, height, e) {
	var xx, yy;
	xx = e.screenX;
	yy = e.screenY;
	window.open('','Popup','width=' + width + ', height=' + height + ',toolbar=no,scrollbars=yes,location=no');//, 'directories=0, location=0, menubar=0, status=0, toolbar=0, width=' + width + ', height=' + height + ', top=' + yy + ', left=' + xx); 	
	var action = form.action;
	var target = form.target;
	if (popup == null || popup == "") {
		popup = action;
	}
	form.target='Popup';
	form.action = popup
	form.submit();
	form.target = target;
	form.action = action;
	form.elements['reqCode'].value='';		
	return false;
}
function isEmpty() {
	var value = document.officesPopUpForm.cityName.value;
	if (value.length == 0)
	{
	  window.alert("Please type in the name of City");	  
	  return false;
	}	
	else
	{
	for (i=0; i < value.length; i++)
		{
			//get the unicode character code at ith position
			var cc = value.charCodeAt(i);
			//the char code must lie between ie it must be between/equal to 'A' or 'Z' and 'a' or 'z'
			if ((cc >= 97 && cc <= 122) || (cc >= 65 && cc <= 90))
			{			
			}
			else
			{
				alert('Invalid Character Present In Input,Please Correct It..');
				document.officesPopUpForm.cityName.value = "";
				document.officesPopUpForm.cityName.focus();
				return false;			
			}	
		}	
		return true;
	}
}
function Erase()
{ //function used to clear contents in search field
 document.officesPopUpForm.cityName.value='';
 return true;
}

//below function closes the popup and also takes the city selected and passes 
//it to the officesinner.jsp form
function closeSearchPopUp(form,openerField,popupField) {	
	var inputField = form[popupField];
	var value;
	if (inputField.options) {
		value = inputField.options[form[popupField].selectedIndex].value;
		
	}
	else if (inputField.type == "file") {
		value = inputField.value;
	} else {
		for (i=0; i < form.elements.length; i++) {
			var element = form.elements[i];
			if (element.name == popupField && element.checked) {
				value = element.value;
				break;
			}
		}
	}	
	//below code assigns the city selected into the cityName textbox control
	//on the officesinner.jsp form
	window.opener.document.forms[1][openerField].value = value;
	window.opener.document.officesPopUpForm.submit();
	//alert(value);
	window.close();	
}
//To validate if correct option from Country dropdown list is selected
function countrySelected(form)
{
	if(document.officesPopUpForm.countryID.value == 'IN1')
	{
		alert("Invalid Option Selected");
	}
	else
	{
		form.submit();
	}
}
//To validate if correct option from State dropdown list is selected
function stateSelected(form)
{
	if(document.officesPopUpForm.stateID.value == 'oo')
	{
		alert("Invalid Option Selected");
	}
	else
	{
		form.submit();
	}
}