var nFHTMLC = null; // Next focusable Html component.

function getStateByCountry(divId, countryId, stateId) {
        if(countryId) {
                var url = 'index.php?module=user&task=getStateByCountry&countryId='+countryId+'&stateId='+stateId;
                ajaxManager('load_page', url, divId);
        }
        else {
                document.getElementById(divId).innerHTML = "<select disabled=\"disabled\" size=\"1\" class=\"textBoxN\"  style=\"width:160px;\"></select>";
        }
}
function getCityBySate(stateId, cityValue, divId) {
	if(stateId) {
		if(cityValue.length >= 2) {
			var url = 'index.php?module=user&task=getCityByState&stateId='+stateId+'&cityName='+cityValue;
			ajaxManager('load_page', url, divId);
			setTimeout('madeFocus(document.forms[0].cityText)', 400);
		}
		else{
			document.getElementById(divId).innerHTML = "";
		}
	}
	else {
		alert("Please select the state");
	}
}

function listAllCity(stateId, cityValue, divId) {
	if(cityValue.length >= 3) {
		var url = 'index.php?module=user&task=getCityByState&stateId='+stateId+'&cityName='+cityValue;
		ajaxManager('load_page', url, divId);
		setTimeout('madeFocus(document.forms[0].cityText)', 400);
	}
	else{
		document.getElementById(divId).innerHTML = "";
	}
}

function setStateName(val, name) {
	document.forms[0].stateName.value = name;
	document.forms[0].organisationState.value = val;
}

function setCityName(val, name) {
	document.forms[0].cityName.value = name;
	document.forms[0].organisationCity.value = val;
}

function clearStateHTML() {
	document.getElementById('stateList').innerHTML="";
}

/*
* Original code written by Akhil
*/
/*
function clearCityHTML() {
	document.getElementById('cityList').innerHTML="";
}
//*/

/*
* Modified by code written by Sohan
*/
function clearCityHTML() {
	if (nFHTMLC && getMyElement(nFHTMLC)) {
		getMyElement(nFHTMLC).focus();
		nFHTMLC = null;
	}
	getMyElement('cityList').innerHTML="";
}

function setCityBlank() {
	document.forms[0].cityName.value = "";
}

function checkEnter(e) {
	if(window.event) {
		key = window.event.keyCode;
	}
	else {
		key = e.which;
	}

	if (key == 13) {
		clearCityHTML();
		return false;
	}
	else {
		return true;
	}
}

function madeFocus(htmlObj) {
	if(htmlObj) {
		htmlObj.focus();
		htmlObj.selectedIndex = 0;
	}
}






/*
* JS code written by Sohan for home search functionality.
*/
function listAllState(stateValue, divId, id) {
	if(stateValue.length >= 2) {
		nFHTMLC = id;
		var strUrl = 'index.php?module=user&task=getAllStateStartsWith&stateName='+stateValue;
		ajaxManager('load_page', strUrl, divId);
		setTimeout('madeFocus(document.forms[0].stateText)', 400);
	}
	else{
		nFHTMLC = null;
		document.getElementById(divId).innerHTML = "";
	}
}

function clearStateHTML2() {
	if (nFHTMLC && document.getElementById(nFHTMLC)) {
		document.getElementById(nFHTMLC).focus();
		nFHTMLC = null;
	}
	document.getElementById('stateList').innerHTML="";
}

function checkEnter2(e) {
	if(window.event) {
		key = window.event.keyCode;
	}
	else {
		key = e.which;
	}
	if (key == 13) {
		clearStateHTML2();
		return false;
	}
	else {
		return true;
	}
}

function listAllCity2(stateId, cityValue, divId, id) {
	if(cityValue.length >= 3) {
		nFHTMLC = id;
		var url = 'index.php?module=user&task=getCityByState&stateId='+stateId+'&cityName='+cityValue;
		ajaxManager('load_page', url, divId);
		setTimeout('madeFocus(document.forms[0].cityText)', 400);
	}
	else{
		nFHTMLC = null;
		document.getElementById(divId).innerHTML = "";
	}
}

function getMyElement(id) {
	if (document.getElementById && !document.all) {
		return document.getElementById(id);
	}	else if (document.getElementById && document.all) {
		return document.all[id];
	}
	return null;
}
