jQuery(document).ready(function($){
	$.fn.emptySelect = function(optionsDataArray){
		return this.each(function(){
			if(this.tagName =='SELECT') this.options.length = 0;							
		});
	};
	
	$.fn.loadSelect = function(optionsDataArray){
		return this.emptySelect().each(function(){
			if(this.tagName == "SELECT") 
			{
				var selectElement = this;
				$.each(optionsDataArray, function(index, optionData) {
					var option = new Option(optionData.caption,optionData.value, optionData.selected);
					if($.browser.msie)
						selectElement.add(option);
					else
						selectElement.add(option, null);
				});
			}
		});
	};	
});

function debug($msg) {
	if (window.console && window.console.log)
		window.console.log($msg);
}


var xmlhttp2

function GetXmlHttpObject2(){
	if (window.XMLHttpRequest){
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	}
	
	if (window.ActiveXObject){
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}
	 
	return null;
}

var g_locationId;
var g_gotoPage;
function updateLocation(locationId, gotoPage){
	g_locationId=locationId;
	g_gotoPage=gotoPage;
	xmlhttp2=GetXmlHttpObject2();
	if (xmlhttp2==null){
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	xmlhttp2.onreadystatechange=refreshPage;
	xmlhttp2.open ("GET", "ajax/updateLocation.php?loc=" + locationId, true);
	xmlhttp2.send (null);
	
	
	
}

function refreshPage(){
	if (xmlhttp2.readyState==4){
		if(g_gotoPage){
			if(g_gotoPage!=""){
				window.location = g_gotoPage;
			}else{
				window.location = "index.php";
			}
		}else{
			window.location = "index.php";
		}
	}
}
