(function($) {
	$.fn.SelectEmpty=function(intRemaining){return this.each(function(){if(this.tagName=='SELECT'){for(var i=this.options.length-1;i>=(intRemaining==null?0:intRemaining);i--){this.remove(i);}}});}
	$.fn.SelectFill=function(objAllData,intRemaining){return this.SelectEmpty(intRemaining).each(function(){if(this.tagName=='SELECT'){var objElement=this;$.each(objAllData,function(intIndex,objData){var objOpt=new Option(objData.text,objData.value);if($.browser.msie){objElement.add(objOpt);}else{objElement.add(objOpt,null);}});}});}
})(jQuery);
function Currency(flt) {if(isNaN(flt)){return"";}str=""+parseFloat(flt).toFixed(2);int=str.indexOf(".");while(int>3){int=int-3;str=str.substr(0,int)+","+str.substr(int);}return str;}

function GotoAddress(strURI) {
	if(strURI!="")document.location.href=strURI;
}
function GotoResultsPage(intOffset) { 
	$("input#page").val(intOffset);
	$("form#resultsfilter").submit();
}

function UpdateSearchType() {
	var intSearchType = $('input[name=searchtype]:checked').val();
	$.getJSON('_dynamic/accommodationtypetocountry.php','step1='+intSearchType.toString(),function(data){$("select#country").SelectFill(data,1);$("select#country").val($("input#forcecountryto").val());UpdateSearchCountry();});
	$.getJSON('_dynamic/accommodationtypetocountry.php','step3=0',function(data){$("select#golfcountry").SelectFill(data,1);$("select#country").val($("input#forcecountryto").val());UpdateSearchGolfCountry();});
}

function UpdatePropertySearchType() {
	var intSearchType = $('select#searchtype').val();
	$.getJSON('_dynamic/accommodationtypetocountry.php','step1='+intSearchType.toString(),function(data){$("select#country").SelectFill(data,1);UpdatePropertySearchCountry();});
}

function UpdatePropertySearchCountry() {
	var intSearchType = $('select#searchtype').val();
	var intSearchCountry = $('select#country').val();
	$("div#regioncontainer").hide();
	$("select#region").val("");
	if ($("select#country").val()!="") {
		$.getJSON('_dynamic/accommodationtypetocountry.php','step1='+intSearchType.toString()+'&step2='+intSearchCountry.toString(),function(data){$("select#region").SelectFill(data,1);$("div#regioncontainer").show();});
	}
}

function UpdateSearchGolfCountry() {
	var intSearchCountry = $('select#golfcountry').val();
	$("div#golfregioncontainer").hide();
	$("select#golfregion").val("");
	if ($("select#golfcountry").val()!="") {
		$.getJSON('_dynamic/accommodationtypetocountry.php','step3='+intSearchCountry.toString(),function(data){$("select#golfregion").SelectFill(data,1);$("div#golfregioncontainer").show();});
	}
}

function UpdateSearchCountry() {
	var intSearchType = $('input[name=searchtype]:checked').val();
	var intSearchCountry = $('select#country').val();
	$("div#regioncontainer").hide();
	$("select#region").val("");
	if ($("select#country").val()!="") {
		$.getJSON('_dynamic/accommodationtypetocountry.php','step1='+intSearchType.toString()+'&step2='+intSearchCountry.toString(),function(data){$("select#region").SelectFill(data,1);$("div#regioncontainer").show();});
	}
}

function SearchFormCountrySelect(strFrom,strTo) {
	SearchFormCopy("country",strFrom,strTo);
	$("select#region").hide();
	$("select#region").val("");
	$("select#region2").hide();
	$("select#region2").val("");
	if ($("select#country").val()!="") {
		$.getJSON('_dynamic/accommodationtypetocountry.php','step1='+$("input#searchtype").val()+'&step2='+$("select#country").val(),function(data){$("select#region").SelectFill(data,1);$("select#region2").SelectFill(data,1);$("select#region").show();$("select#region2").show();});
	}
}
function SearchFormCopy(strVar,strFrom,strTo) {
	$("#"+strVar+strTo).val($("#"+strVar+strFrom).val());
}

// Extend jQuery with a new property that gets the querystring
// Use $.getUrlVar('key') to get the matching value
$.extend({
	getUrlVars: function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	},
	getUrlVar: function(name){
		return $.getUrlVars()[name];
	}
});
	
	
// Global Corrrel8 styles that should be included on every site
$(document).ready(function() {
	$('a[href^="http://"]').attr({
		target: '_blank', 
		title: 'Opens in a new window'
	});
});


