var current_sub='';
function hideDivs(){
	if(current_sub!=''){
		document.getElementById(current_sub).style.visibility = "hidden";
		current_sub='';
	}
}
function showdiv(sub_menu){
	hideDivs();
	current_sub=sub_menu;
	document.getElementById(sub_menu).style.visibility = "visible";
}
function hide() {
	if(current_sub!='')
		document.getElementById(current_sub).style.visibility = "hidden";
}


function trim(strText) {
	// this will get rid of leading spaces
	while (strText.substring(0,1) == ' ')
		strText = strText.substring(1, strText.length);

	// this will get rid of trailing spaces
	while (strText.substring(strText.length-1,strText.length) == ' ')
		strText = strText.substring(0, strText.length-1);

	return strText;
}


function ValidateNumber(textbox){
	if(textbox.value != ""){
		if(isNaN(textbox.value)){
			alert("Please enter a number.");
			textbox.focus();
		}
	}
}


function ConfirmDelete(sName, sAdditionalText){
	var strConfirm = "Are you sure you want to delete '" + sName + "'?";
	if(sAdditionalText != ""){
		strConfirm += "\n" + sAdditionalText;
	}
	return confirm(strConfirm);
}


function IsValidEmail(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if(str.indexOf(at)==-1){ return false; }
	if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false; }
	if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false; }
	if(str.indexOf(at,(lat+1))!=-1){ return false; }
	if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false; }
	if(str.indexOf(dot,(lat+2))==-1){ return false; }
	if(str.indexOf(" ")!=-1){ return false; }
	return true;
}

function loadCity(province, idToChange){
   jQuery.ajax({
	    url: "/_includes/ajax/getCities.php",
	    dataType: 'json',
	    async: false,
	    data: {
	        'province': province
	    },
	    success: function(data) {

		    var select = '<select id="city" name="city"><option></option>';
	        for(var d=0;d<data.length;d=d+2){
	            select = select + '<option value="'+data[d]+'">'+data[d+1]+'</option>';
	        }
	        select = select + "</select>";
	        document.getElementById(idToChange).innerHTML = select;
	    },
	    error: function() {
	    }
	});
}
