function validate(formCheck) //Function with a parameter representing a form name.
{
    if (formCheck.localityid.value=="")
    {
        alert("Please select a locality"); 
        formCheck.localityid.focus();
        return false;
    }
    return true;
}

function getCat(id){ 
	var xhr = createXHR();
	document.getElementById('popup').style.display = 'block';
	xhr.onreadystatechange = function(){		
		if(xhr.readyState == 4){
			if(xhr.status == 200){
				document.getElementById('popup').innerHTML = xhr.responseText;
			}
			else{
				document.getElementById('popup').innerHTML = "Error: returned status code " + xhr.status + " " + xhr.statusText;
			}	
		} 
	}; 
	// send a random url variable to avoid caching problems with IE
	xhr.open("GET", "poppedup.cfm?ID="+id+"&random="+Math.random(), true);
	xhr.send(null); 
}

function getSubCat(id,categoryid){ 
	var xhr = createXHR();
	document.getElementById('popup').style.display = 'block';
	xhr.onreadystatechange = function(){		
		if(xhr.readyState == 4){
			if(xhr.status == 200){
				document.getElementById('popup').innerHTML = xhr.responseText;
			}
			else{
				document.getElementById('popup').innerHTML = "Error: returned status code " + xhr.status + " " + xhr.statusText;
			}	
		} 
	}; 
	// send a random url variable to avoid caching problems with IE
	xhr.open("GET", "popupcat.cfm?ID="+id+"&CategoryID="+categoryid+"&random="+Math.random(), true);
	xhr.send(null); 
}

function suggestSubCat(id,subcat){ 
document.getElementById('subcatsuggest').innerHTML = "";
if (subcat.length >= 3){
	
	var xhr = createXHR();
	xhr.onreadystatechange = function(){		
		if(xhr.readyState == 4){
			if(xhr.status == 200){
				document.getElementById('subcatsuggest').innerHTML = xhr.responseText;
			}
			else{
				document.getElementById('subcatsuggest').innerHTML = "Error: returned status code " + xhr.status + " " + xhr.statusText;
			}	
		} 
	}; 
	// send a random url variable to avoid caching problems with IE
	xhr.open("GET", "ajaxsubcat.cfm?ID="+id+"&subcat="+subcat+"&random="+Math.random(), true);
	xhr.send(null); 
}
}

function closePopup(){
	document.getElementById('popup').innerHTML = '';
	document.getElementById('popup').style.display = 'none';
}

function clearCat(id){
	document.getElementById('businesscategoryname'+id).value = "";
	document.getElementById('businesscategory'+id).value = "";
	document.getElementById('businesscategoryname'+id).disabled = false;
	checkCat();
}

function insertSubCat(id,subcat,subcatid){
	document.getElementById('businesscategoryname'+id).value = subcat;
	document.getElementById('businesscategory'+id).value = subcatid;
	document.getElementById('businesscategoryname'+id).disabled = 'disabled';
	closePopup();
	checkCat();
}

function checkCat(){
	for (i=1;i<=4;i++){
		if(document.getElementById('businesscategory'+i).value!='')
			document.getElementById('buscat'+i).style.visibility='visible';
		else
			document.getElementById('buscat'+i).style.visibility='hidden';
	}
}

function confirmAction(confirmText){
var agree=confirm(confirmText);
if (agree)
	return true ;
else
	return false ;
}