function insertStatsExtLink(f) {
	var postData = "f=" + f + "&proID=" + proID;
	var sUrlStats = site_url + "ajax_files/insert_statistics_external_links.php";

	$.ajax({
		type: "POST",
		url: sUrlStats,
		data: postData,
		cache: false
	});
}

var next_pic_no = 1;
var prev_pic_no = images_no;

function showPicture(NrPic){
	var postData = "NrPic=" + NrPic + "&proID=" + proID;
	var sUrlPicture = site_url + "ajax_files/show_pictures.php";

	$.ajax({
		type: "POST",
		url: sUrlPicture,
		data: postData,
		cache: false,
		success: function(data) {
			var col_array = new Array();
			col_array = data.split("\n");
			$('#responsePicture').html(col_array[1]);
			$('#responseCaption').html(col_array[2]);

			prev_pic_no = col_array[3];
			next_pic_no = col_array[4];
		}

	});

	$("#galleryScroll img").removeClass("imgSelected");
	$('#thumb_' + NrPic).addClass("imgSelected");

	if (total_pictures > 4) {
		$("#galleryScroll").animate({scrollLeft: (NrPic-1.5)*78 + "px"}, 500);
	}

}
function showPrevPicture(){
	showPicture(prev_pic_no);
}
function showNextPicture(){
	showPicture(next_pic_no);
}


function changeRates(){
	var selected_value = $("#currency_select option:selected").val();
	for(i=0;i<totalRates;i++){
		var daily_elem = $('#daily_rate_' + i).html();
		var weekend_elem = $('#weekend_rate_' + i).html();
		var weekly_elem = $('#weekly_rate_' + i).html();
		var monthly_elem = $('#monthly_rate_' + i).html();

		$('div.demo-container').html();
		
		daily_value = numberFormat(daily_rates_array[i]);
		if(daily_value != "-"){
			$('#daily_rate_' + i).html(aCurs[selected_value][1] + "&nbsp;" +  daily_value);
		}
		else{
			$('#daily_rate_' + i).html("-");
		}

		weekend_value = numberFormat(weekend_rates_array[i]);
		if(weekend_value != "-"){
			$('#weekend_rate_' + i).html(aCurs[selected_value][1] + "&nbsp;" + weekend_value);
		}
		else{
			$('#weekend_rate_' + i).html("-");
		}

		weekly_value = numberFormat(weekly_rates_array[i]);
		if(weekly_value != "-"){
			$('#weekly_rate_' + i).html(aCurs[selected_value][1] + "&nbsp;" +  weekly_value);
		}
		else{
			$('#weekly_rate_' + i).html("-");
		}

		monthly_value = numberFormat(monthly_rates_array[i]);
		if(monthly_value != "-"){
			$('#monthly_rate_' + i).html(aCurs[selected_value][1] + "&nbsp;" +  monthly_value);
		}
		else{
			$('#monthly_rate_' + i).html("-");
		}
	}
	if(selected_value == -1){
		$('#currency_name').html("");
	}
	else{
		$('#currency_name').html("(" + aCurs[selected_value][2] + ")");
	}
}
if($('#currency_select').length){
	changeRates();
}

//validates that the entry is a positive or negative number
function isNumber(str) {
	var re = /^[-]?\d*\.?\d*$/;
	str = str.toString( );
	if (!str.match(re)) {
		return false;
	}
	return true;
}

function numberFormat(number_value){
	var selected_value = $("#currency_select option:selected").val();
	if(selected_value == '-1'){
		return "-";
	}
	number_value = number_value.replace(',', '');

	var weeklyAmount = number_value * aCurs[selected_value][0];
	weeklyAmount = Math.ceil((Math.round(weeklyAmount * 1000))/1000);
	if(isNumber(weeklyAmount) && weeklyAmount > 0){
		// Now format it with commas.
		weeklyAmount = weeklyAmount.toString();
		pos = weeklyAmount.length;
		while (pos > 0)	{
			pos -= 3;
			if (pos <= 0) {
				break;
			}
			weeklyAmount = weeklyAmount.substring(0, pos) + "," + weeklyAmount.substring(pos, weeklyAmount.length);
		}
		return weeklyAmount;
	}
	else{
		return "-";
	}
}

function openScript(url, width, height) {
	var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=no,status=no' );
}


var sUrlInsStats = site_url + "ajax_files/insert_statistics.ajax.php";

function insert_map_statistics(proID){
	var postData = 'file=local_map&proID=' + proID + '&current_page=' + current_page;
	$.ajax({
		type: "POST",
		url: sUrlInsStats,
		data: postData,
		cache: false
	});
}
function insert_weather_statistics(){
	var postData = 'file=local_weather&proID=' + proID + '&current_page=' + current_page;
	$.ajax({
		type: "POST",
		url: sUrlInsStats,
		data: postData,
		cache: false
	});
}
