var	sfv2_myStations = new Array();
var	sfv2_myStations_length = 0;
var sfv2_markerCluster = new Array();
var	sfv2_closedStations = new Array();
var sfv2_mouse_been_inside = false;
var sfv2_filter_shown = true;
var sfv2_baseMarker = null;
var	sfv2_baseMarker_position = null;
var sfv2_map = null;
var sfv2_station_info = new Array();
var sfv2_type = "all";
var sfv2_opened = false;
var sfv2_locale = "";
var sfv2_lang = "";
var	sfv2_interval;
var	sfv2_chkdate_status = false;
var sfv2_am_pm_array = new Array();
var sfv2_url_args = new Array();
sfv2_am_pm_array["en-GB"] = 1;
var sfv2_array_pdf = new Array();
var sfv2_infoboxes = new Array();
sfv2_array_pdf["BODL02"] = 1;
sfv2_array_pdf["CDGT01"] = 1;
sfv2_array_pdf["CDGT02"] = 1;
sfv2_array_pdf["CFET02"] = 1;
sfv2_array_pdf["CFRC02"] = 1;
sfv2_array_pdf["GNBL01"] = 1;
sfv2_array_pdf["GVFT01"] = 1;
sfv2_array_pdf["LILL05"] = 1;
sfv2_array_pdf["LILL06"] = 1;
sfv2_array_pdf["LYSL01"] = 1;
sfv2_array_pdf["LYSL02"] = 1;
sfv2_array_pdf["LYST01"] = 1;
sfv2_array_pdf["MPLL02"] = 1;
sfv2_array_pdf["MRSL01"] = 1;
sfv2_array_pdf["MZML02"] = 1;
sfv2_array_pdf["ORYT01"] = 1;
sfv2_array_pdf["PARC22"] = 1;
sfv2_array_pdf["PARC26"] = 1;
sfv2_array_pdf["PARL01"] = 1;
sfv2_array_pdf["PARL06"] = 1;
sfv2_array_pdf["PARL09"] = 1;
sfv2_array_pdf["PARL10"] = 1;
sfv2_array_pdf["PARL11"] = 1;
// JavaScript Document

function	sfv2_activate_datepicker_fields(datepicker) {
	if (typeof datepicker !== "undefined") {
		$("#sfv2_subfilter_date").hide();
		sfv2_show_chk('date', false);
		sfv2_chkdate_status = false;

	}
	if ($("#sfv2_datepicker").val()) {
		$("#sfv2_hours").show();
		$("#sfv2_datepicker").css("color", "#333");
		if ($("#sfv2_hours").val() != "no") {
			$("#sfv2_mins").show();
		} else {
			$("#sfv2_mins").hide();
		}
	} else {
		sfv2_show_chk('date', false);
		sfv2_chkdate_status = false;
		$("#sfv2_subfilter_date").hide();
		$("#sfv2_hours").hide();
		$("#sfv2_mins").hide();
	}
}

function	sfv2_myCalculator(markers, numStyles) {
	var index = 0;
	var count = 0;
	var length = markers.length;
	for (var i=0; i<length; i++) {
		if (markers[i].myvisibility == true) {
			count++;
		}
	}
	var dv = count;
	while (dv !== 0) {
		dv = parseInt(dv / 10, 10);
		index++;
	}
	
	index = Math.min(index, numStyles);
	return {text: count, index: index};
}

function	sfv2_gen_infowindow_url(stationcode) {
	var dateFormat = $.datepicker.regional[sfv2_locale]["dateFormat"];
	var date = sfv2_convert_date($("#sfv2_datepicker")[0].value, dateFormat);
	var station_hour_url = "scripts/sfv2_json_station_hours.php?sc="+stationcode;
	var chkdate_className = $("#sfv2_subfilter_chk_date").attr("class");
	sfv2_chkdate_status = (chkdate_className == "sfv2_subfilter_chk checked") ? true : false;
//	station_hour_url += "&fd="+$.datepicker.regional[sfv2_locale]["firstDay"];		
	station_hour_url += "&df="+dateFormat;		
	if (sfv2_chkdate_status == true) {
		station_hour_url += "&cd="+date;
		var hours = $("#sfv2_hours").val();
		if (hours != "no") {
			station_hour_url += "&ch="+hours+$("#sfv2_mins").val();
		}
	}
	return station_hour_url;
}

function	sfv2_checkRegexp(o, regexp, n) {
	if (!( regexp.test(o.val()))) {
		return false;
	} else {
		return true;
	}
}		

function	sfv2_init_modal_popup_send_mail() {
	var valid = true;
	var email = $("#sfv2_email_input");
	valid = sfv2_checkRegexp(email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. ui@jquery.com");
	if (valid) {
		$.ajax({url: sfv2_gen_infowindow_url(sfv2_station_info["infos"].stationcode),
				success: function(json) {sfv2_station_info["openhours"] = $.parseJSON(json);},
				async: false});
		$.ajax({type: "POST",
			   	url: "scripts/sfv2_send_mail.php",
			   	data: {infos: sfv2_station_info["infos"],
						openhours: sfv2_station_info["openhours"],
						dayNames: $.datepicker.regional[sfv2_locale].dayNames,
						lang: sfv2_lang,
						locale: sfv2_locale,
						firstDay: $.datepicker.regional[sfv2_locale].firstDay,
						mailto: email.val()},
				success: function(data) {
							if (data == 1) {
								$("#sfv2_modal_error_msg").hide();
								$("#sfv2_modal_success_msg").text($("#sfv2_modal_success_msg_txt").text());
								$("#sfv2_modal_success_msg").show();
							} else {
								$("#sfv2_modal_success_msg").hide();
								$("#sfv2_modal_error_msg").text($("#sfv2_modal_error_send_msg_txt").text());
								$("#sfv2_modal_error_msg").show();
							}},
				async: false});
//		$("#sfv2_modal_popup").dialog("close");
	} else {
		$("#sfv2_modal_success_msg").hide();
		$("#sfv2_modal_error_msg").text($("#sfv2_modal_error_address_msg_txt").text());
		$("#sfv2_modal_error_msg").show();
	}
	return false;
}

function	sfv2_init_modal_popup() {
	$("#sfv2_send_mail_button").click(sfv2_init_modal_popup_send_mail);
	$("#sfv2_close_mail_button").click(function() {
											$("#sfv2_modal_success_msg").hide();
											$("#sfv2_modal_error_msg").hide();
											$("#sfv2_modal_popup").dialog("close");
											return false;
										});
	$("#sfv2_modal_popup").dialog({
			dialogClass: 'sfv2_dialog',
			resizable: false,
			autoOpen: false,
			draggable: false,
			modal: true,
			width: 490,
			minHeight: 0,
			close: function() {
				$("#sfv2_modal_success_msg").hide();
				$("#sfv2_modal_error_msg").hide();
				$("#sfv2_email_input").val("");
			}
	});
}

function	sfv2_gen_infowindow_content(stationcode, infos, country, hostname) {
	var title = ((infos.stationname) ? infos.stationname : stationcode);
	var contentString  = [
	'<div class="sfv2_infowindow_content">',
		'<span id="sfv2_infowindow_content_title_'+stationcode+'" class="sfv2_infowindow_content_title">'+title+'</span>',
		'<div class="clear"></div>',
		'<div id="sfv2_infowindow_tabs_'+stationcode+'">',
			'<ul>',
				'<li>',
					'<a id="sfv2_infowindow_tab_'+stationcode+'_a_info" href="#sfv2_infowindow_tab_'+stationcode+'_1">',
						'<span class="first_tab tab_lft"></span>',
						'<span class="first_tab tab_mid">',
						$("#sfv2_infobox_information_tab_title_text").text(),
						'</span>',
						'<span class="first_tab tab_rgt"></span>',
					'</a>',
				'</li>',
				'<li>',
					'<a id="sfv2_openhour_url_'+stationcode+'" title="sfv2_infowindow_tab_'+stationcode+'_2" href="">',
						'<span class="last_tab tab_lft"></span>',
						'<span class="last_tab tab_mid">',
						$("#sfv2_infobox_hours_tab_title_text").text(),
						'</span>',
						'<span class="last_tab tab_rgt"></span>',
					'</a>',
				'</li>',
			'</ul>',
			'<div id="sfv2_infowindow_tab_'+stationcode+'_1">',
				'<ul class="sfv2_infowindow_tab_list">'].join('');
					if (infos.address) {
						contentString += [
						'<li class="sfv2_tabs_row"><ul><li class="sublist_title">',
						$("#sfv2_infobox_information_address_text").text(),
						'</li>',
							'<li class="sublist"><ul>',
							(infos.address.address1) ? '<li>'+infos.address.address1+'</li>' : '',
							(infos.address.address2) ? '<li>'+infos.address.address2+'</li>' : '',
							(infos.address.postalcode || infos.address.cityname) ? '<li>' : '',
								(infos.address.postalcode) ? infos.address.postalcode+'&nbsp;' : '',
								(infos.address.cityname) ? infos.address.cityname : '',
							(infos.address.postalcode || infos.address.cityname) ? '</li>' : '',
							(infos.address.countryname) ? '<li>'+infos.address.countryname+'</li>' : '',
							'</ul></li>',
						'</ul></li>'].join('');
					}
					if (infos.phonenumber) {
						contentString += [
						'<li class="sfv2_tabs_row"><ul><li class="sublist_title">',
						$("#sfv2_infobox_information_phone_text").text(),
						'</li>',
							'<li class="sublist"><ul>',
								'<li>'+infos.phonenumber+'</li>',
							'</ul></li>',
						'</ul></li>'].join('');
					}
					if (infos.faxnumber) {
						contentString += [
						'<li class="sfv2_tabs_row"><ul><li class="sublist_title">',
						$("#sfv2_infobox_information_fax_text").text(),
						'</li>',
							'<li class="sublist"><ul>',
								'<li>'+infos.faxnumber+'</li>',
							'</ul></li>',
						'</ul></li>'].join('');
					}
					contentString += [
						'<li class="sfv2_tabs_row"><ul><li class="sublist_title">',
						$("#sfv2_infobox_information_code_text").text(),
						'</li>',
							'<li class="sublist"><ul>',
								'<li>'+stationcode+'</li>',
							'</ul></li>',
						'</ul></li>',
						'<li class="sfv2_tabs_row"><ul><li class="sublist_title">',
						$("#sfv2_infobox_information_satnav_text").text(),
						'</li>',
							'<li class="sublist"><ul>',
								'<li>',
									$("#sfv2_infobox_information_latitude_short_text").text()+'&nbsp;'+infos.lat,
									'&nbsp;-&nbsp;',
									$("#sfv2_infobox_information_longitude_short_text").text()+'&nbsp;'+infos.lng,
								'</li>',
							'</ul></li>',
						'</ul></li>',
					'</ul>',
				'</div>',
				'<div class="sfv2_infowindow_tab_hours clear" id="sfv2_infowindow_tab_'+stationcode+'_2">',
					'<span class="loading"></span>',
				'</div>',
			'</div>',
			'<div class="clear"></div>',
			'<div id="sfv2_infowindow_afterhours_legend_'+stationcode+'" class="sfv2_infowindow_afterhours_legend sfv2_hidden"></div>',
			'<div class="sfv2_info_extra">',
				'<ul>',
					'<li>',
						'<a class="sfv2_infowindow_send_mail" title="'+$("#sfv2_infobox_information_mail_text").text()+'" href="#"></a>',
					'</li>'].join('');
			if (typeof sfv2_array_pdf[stationcode] !== "undefined") {
				contentString += '<li><a class="sfv2_infowindow_pdf" title="'+$("#sfv2_infobox_information_dowlnload_details_text").html()+'" target="blank" href="files/'+stationcode+'.pdf"></a></li>';
			}
	contentString += '</ul></div>';
	if (hostname) {
		var url_button = document.location.protocol + "//" + hostname;
		url_button += (sfv2_url_args["fsite"]) ? "/?" : "/DotcarClient/step1.action?";
		var changeStation = (sfv2_url_args["dotcarClientTypeCheckinCheckout"] && sfv2_url_args["dotcarClientTypeCheckinCheckout"] !== "undefined") ? sfv2_url_args["dotcarClientTypeCheckinCheckout"] : "checkout"
		if (changeStation == 'checkin') {
			url_button += "checkoutStation=";
			url_button += (sfv2_url_args["dotcarClientCheckoutLocation"] && sfv2_url_args["dotcarClientCheckoutLocation"] !== "undefined") ? sfv2_url_args["dotcarClientCheckoutLocation"] : stationcode;
			url_button += "&checkinStation="+stationcode+"&checkinCountry="+country;			
		} else {
			url_button += "checkinStation=";
			url_button += (sfv2_url_args["dotcarClientCheckinLocation"] && sfv2_url_args["dotcarClientCheckinLocation"] !== "undefined") ? sfv2_url_args["dotcarClientCheckinLocation"] : stationcode;
			url_button += "&checkoutStation="+stationcode+"&checkoutCountry="+country;
		}		
		var button_text = $("#sfv2_infobox_hours_choose_location_text").text();
		var trackevent = "_gaq.push(['_trackEvent', 'Choose Location', 'Click', '"+stationcode+"']);";
		contentString += [
			'<div class="sfv2_infowindow_button">',
				'<a onclick="'+trackevent+'" target="_parent" title="'+button_text+'" href="'+url_button+'">',
					'<span class="sfv2_infowindow_button_lft"></span>',
					'<span class="sfv2_infowindow_button_mid">',
					button_text,
					'</span>',
					'<span class="sfv2_infowindow_button_rgt"></span>',
				'</a>',
			'</div>',
		].join('');
	}
	contentString += '<div class="clear"></div></div>';
	return contentString;
}

function	sfv2_tabs_ajax_error(xhr, status, index, anchor) {
	$(anchor.hash).html("Can't get this station open hours");	
}

function	sfv2_formatHour(hour) {
	var len = len_min = 0;
	var len_min_array = new Array(4,3);
	var ampm = (sfv2_locale && typeof sfv2_am_pm_array[sfv2_locale] == "undefined") ? 0 : 1;
	var ampm_string = (ampm == 1) ? ((hour >= 1200) ? " PM" : " AM") : "";
	hour = (ampm == 1 && hour != 1200) ? (hour%1200) : hour;
	hour += "";
	len_min = len_min_array[ampm];
	for (len = hour.length; len < len_min; len++) {
		hour = "0" + hour;
	}
	hour = hour.slice(0, -2) + ":" + hour.slice(-2);
	return (hour + ampm_string);
}

function	sfv2_tabs_ajax_dataFilter(json) {
//	$.getJSON("scripts/sfv2_json_stations.php", function(json) {
//	var	incClusterer = 0;
	var data = $.parseJSON(json);
//	var	daynb = $.datepicker.regional[sfv2_locale].firstDay;
	var	daynb = data.todaynb;
	var return_value = "<ul class='sfv2_infowindow_tab_list'>";
	var hours = [];
	var myclass = "";
	var	afterhours = 0;
	var stationcode = data.stationcode;
//	sfv2_infoboxes[stationcode].afterhours = false;
	$("#sfv2_infowindow_afterhours_legend_"+stationcode).hide().text("");
	for (var i = 0; i < 8; i++) {
		hours = data[daynb][0];
		if (typeof data[daynb][1] !== "undefined") {
			data[daynb][0] = data[daynb][1];
		}
		myclass = (hours.selectedDay == true) ? "sfv2_openhours_current " : "";
		myclass += (i%2 == 0) ? "clear sfv2_tabs_row " : "";
		myclass += (i%2 == 0) ? "left " : "right ";
		return_value += "<li class='sfv2_openhours_day "+myclass+"'><ul><li class='boldday'>"+$.datepicker.regional[sfv2_locale].dayNames[daynb];
		return_value += "&nbsp;"+hours.dispDate+"</li><li><ul>";
		if (hours.hoursArray.opened == false) {
			return_value += "<li class='sfv2_dayclose'>"+$("#sfv2_infobox_hours_closed_text").text()+"</li>";
		} else {
			if (typeof hours.hoursArray.N !== "undefined") {
				$.each(hours.hoursArray.N.timeBegin, function(key, dayHour) {
					myclass = (hours.hoursArray.N.selectedTime[key] == true) ? "sfv2_openhours_current" : "";
					return_value += "<li class='"+myclass+"'>"+sfv2_formatHour(dayHour);
					return_value += "&nbsp;-&nbsp;"+sfv2_formatHour(hours.hoursArray.N.timeEnd[key])+"</li>";
				});
			}
			if (typeof hours.hoursArray.Y !== "undefined") {
/*				return_value += "<li class='sfv2_openhours_afterhours'>";
				return_value += $("#sfv2_infobox_hours_after_hours_text").text();
				return_value += "*</li>";*/
//				sfv2_infoboxes[stationcode].afterhours = true;
				$("#sfv2_infowindow_afterhours_legend_"+stationcode).show().html($("#sfv2_subscript").html()+$("#sfv2_extra_charges_txt").text());
				$.each(hours.hoursArray.Y.timeBegin, function(key, dayHour) {
					myclass = (hours.hoursArray.Y.selectedTime[key] == true) ? "sfv2_openhours_current" : "";
					return_value += "<li class='"+myclass+" sfv2_afterhours'>"+sfv2_formatHour(dayHour);
					return_value += "&nbsp;-&nbsp;"+sfv2_formatHour(hours.hoursArray.Y.timeEnd[key]);
					return_value += $("#sfv2_subscript").html()+"</li>";
				});
			}
		}
		return_value += "</ul></li></ul></li>";
		daynb = (daynb + 1)%7;
	}
	return_value += "</ul>";
//	sfv2_update_afterhours_legend();
	return return_value;
}

function	sfv2_del_infobox(stationcode) {
	delete sfv2_infoboxes[stationcode];	
//	sfv2_update_afterhours_legend();
}

function	sfv2_update_afterhours_legend() {
	var	displayLegend = 0;
	for (stationcode in sfv2_infoboxes) {
		if (sfv2_infoboxes[stationcode].afterhours === true) {
			displayLegend++;
		}
	}
	if (displayLegend > 0) {
		$("#sfv2_info_area").text($("#sfv2_extra_charges_txt").text()).show();		
	} else {
		$("#sfv2_info_area").text("").hide();				
	}
}

function	sfv2_add_infobox(infobox) {
	var	size = 0, max_infobox = 2, key, myreturn = 1, first_key;
	for (stationcode in sfv2_infoboxes) {
		if (size == 0) first_stationcode = stationcode;
		if (stationcode == infobox.stationcode) {
			sfv2_del_infobox[stationcode];
			infobox.close();
			myreturn = 0;
		}
		size++;
	}
	if (myreturn == 1) {
		if (size >= max_infobox) {
			sfv2_infoboxes[first_stationcode].close();
			sfv2_del_infobox(first_stationcode);
		}
		sfv2_infoboxes[infobox.stationcode] = infobox;
	}
	return myreturn;
}

function	sfv2_split_date(date) {
	var dateFormat = $.datepicker.regional[sfv2_locale]["dateFormat"];
	var year = month = day = "";
	dateFormat = dateFormat.replace("yy", "yyyy");
	var length = date.length;
	if (length == date.length) {
		for (var i = 0; i < length; i++) {
			if (dateFormat[i] == "y")
				year += date[i];
			else if (dateFormat[i] == "m")
				month += date[i];
			else if (dateFormat[i] == "d")
				day += date[i];
		}
	}
	var return_array = new Array();
	return_array["d"] = day;
	return_array["m"] = month-1;
	return_array["y"] = year;
	return (return_array);
}

function	sfv2_setDistance(marker, setto) {
	if (sfv2_baseMarker !== null && typeof marker !== "undefined"
		&& typeof marker.position !== "undefined") {
			$("#sfv2_map").gmap3({ 
				action:'getRoute',
				options:{
					origin:sfv2_baseMarker.position,
					destination:marker.position,
					travelMode: google.maps.DirectionsTravelMode.DRIVING
				},
				callback: function(results){
					var distance = null;
					if (results.status == "OK" && results.routes.length > 0) {
						distance = results.routes[0].legs[0].distance.value;
					}
					if (distance !== null)
						var dist_km = dist_mile = 0;
						dist_km = distance / 1000;
						dist_mile = distance / 1609;
						if (setto == "infobox") {
							var title = $("#sfv2_infowindow_content_title_"+marker.stationcode).text();
							title += " <span title=\""+dist_mile.toFixed(1)+" miles\">";
							title += "("+dist_km.toFixed(1)+" km)</span>";
							$("#sfv2_infowindow_content_title_"+marker.stationcode).html(title);
						} else if (setto == "title"){
							var new_title = marker.title_orig+"\n"+dist_km.toFixed(1)+" km";
							new_title += " - "+dist_mile.toFixed(1)+" miles";
							if (new_title !== marker.title) {
								marker.title = new_title;
							}
						}
				}
			});
	}
}

function	sfv2_init(locale, lang) {
	//$(document).pngFix();
	if(navigator.geolocation) {
		$("#sfv2_search_input").css("width", "376px");
		$("#sfv2_search_mylocation").show();
	}
	sfv2_locale = locale;
	sfv2_lang = lang;
	var clearMePrevious_date = title_date = infowindow_title = clearMePrevious_search = "";
	title_date = $.datepicker.regional[sfv2_locale]["dateFormat"].replace("yy", "yyyy").replace(/y/g, $("#sfv2_datepicker_year").text().charAt(0)).replace(/m/g, $("#sfv2_datepicker_month").text().charAt(0)).replace(/d/g, $("#sfv2_datepicker_day").text().charAt(0)).toUpperCase();
	$("#sfv2_datepicker").attr("title", title_date);
	$("#sfv2_search_mylocation").attr("title", $("#sfv2_filter_by_location_input_guess_location_title").html());
	clearMePrevious_search = $("#sfv2_filter_by_location_input_placeholder").html();
	$("#sfv2_search_input").attr("title", clearMePrevious_search);
	$("#sfv2_search_input").val(clearMePrevious_search);
	$("#sfv2_datepicker_loading_img").attr("title", $("#sfv2_loading_text").html());
	$("#sfv2_loading_info_img").attr("title", $("#sfv2_loading_text").html());
	$("#sfv2_cities_loading_img").attr("title", $("#sfv2_loading_text").html());
	$("#sfv2_search_loading_img").attr("title", $("#sfv2_loading_text").html());
	$("#sfv2_subfilter_chk_date").attr("title", $("#sfv2_filter_by_date_enable_disable_title").html());
	sfv2_init_modal_popup();
	$("#sfv2_search_input").focus(function() {
		if($(this).val() == $(this).attr("title")) {
			clearMePrevious_search = $(this).val();
			$(this).val("");
			$(this).css("color", "#333");
		}
	});
	$("#sfv2_search_input").blur(function() {
		if($(this).val()=="") {
			$(this).val(clearMePrevious_search);
			$(this).css("color", "#CCC");
		}
	});
	$("#sfv2_datepicker").focus(function()
	{
		if($(this).val() == $(this).attr("title"))
		{
			clearMePrevious_date = $(this).val();
			$(this).val("");
			$(this).css("color", "#333");
		}
	});
	$("#sfv2_datepicker").blur(function() {
		if($(this).val()=="") {
			$(this).val(clearMePrevious_date);
			$(this).css("color", "#CCC");
		}
	});
	$("#sfv2_countries_cities_filter_ok").click(function() {
		if ($("#sfv2_cities_select").is(":disabled") === false)
			$("#sfv2_cities_select").trigger("change");
		else 
			$("#sfv2_countries_select").trigger("change");
	});
	$("#sfv2_search_input_ok").click(function() {
		if ($("#sfv2_search_input").val() !== $("#sfv2_search_input").attr("title"))
			sfv2_goto_address($("#sfv2_search_input").val());
	});
	$("#sfv2_search_input").keypress(function(e) {
		if(e.keyCode == 13) {
			sfv2_goto_address($(this).val());
		}
	});

    $("#sfv2_filter_box").hover(function(){ 
		sfv2_mouse_been_inside=true; 
    });
	
	$("#sfv2_datepicker").datepicker({
			defaultDate: "0",
			showButtonPanel: false,
			minDate: 0,
			firstDay: 1,
			showOtherMonths: false,
			selectOtherMonths: false/*,
			showOn: "both",
			buttonImage: "img/calendar-button.gif",
			buttonImageOnly: true*/
	});
	$("#sfv2_datepicker").datepicker("option", $.datepicker.regional[sfv2_locale]);
	$.extend($.datepicker,{_checkOffset:function(inst,offset,isFixed){
		offset.left -= (this.dpDiv[0].clientWidth)-$("#sfv2_datepicker_box").width();
		offset.top += 4;
		return offset;
	 }});
	$.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];
		}
	});
	sfv2_url_args = $.getUrlVars();
	var hostname = "";
	if (sfv2_url_args["fsite"]) {
		hostname = sfv2_url_args["fsite"];
	} else if (sfv2_url_args["site"]) {
		hostname = (sfv2_url_args["sd"]) ? sfv2_url_args["sd"] : "www";
		hostname += ".europcar."+sfv2_url_args["site"];
	}
/*	$("body").mouseup(function(){ 
        if(!sfv2_mouse_inside) {
			sfv2_toggle_filter();
		}
    });*/
	$("#sfv2_datepicker").val(title_date);
	var mapTypeId = null;
	if (sfv2_url_args["mt"] == 0)  mapTypeId = google.maps.MapTypeId.ROADMAP;
	else if (sfv2_url_args["mt"] == 1)  mapTypeId = google.maps.MapTypeId.SATELLITE;
	else if (sfv2_url_args["mt"] == 2)  mapTypeId = google.maps.MapTypeId.HYBRID;
	else if (sfv2_url_args["mt"] == 3)  mapTypeId = google.maps.MapTypeId.TERRAIN;
	else mapTypeId = google.maps.MapTypeId.ROADMAP;
	$("#sfv2_map").gmap3({action: 'init', zoomControlOptions: {position: google.maps.ControlPosition.LEFT_BOTTOM}, mapTypeId: mapTypeId});
	var defaultcountrycode = null;
	if (typeof sfv2_url_args["countryCode"] !== "undefined" && sfv2_url_args["countryCode"] && sfv2_url_args["countryCode"] !== "undefined") {
		defaultcountrycode = sfv2_url_args["countryCode"].toUpperCase();
	} else if (typeof sfv2_url_args["dc"] !== "undefined" && sfv2_url_args["dc"] && sfv2_url_args["dc"] !== "undefined") {
		defaultcountrycode = sfv2_url_args["dc"].toUpperCase();
	}
	sfv2_map = $("#sfv2_map").gmap3("get");
//	google.maps.event.addListener(sfv2_map, 'idle', sfv2_loading);
	google.maps.event.addListener(sfv2_map, 'bounds_changed', sfv2_show_loading);
	google.maps.event.addListener(sfv2_map, 'idle', sfv2_hide_loading);
	sfv2_hide_loading_timed();
	$.getJSON("scripts/sfv2_json_stations.php?l="+sfv2_lang, function(json) {
		var	incClusterer = 0;
		var mcStyles = [{
				height: 53,
				url: "img/m1.png",
				width: 53,
				textColor: "#FFFFFF"
			},
			{
				height: 56,
				url: "img/m2.png",
				width: 56,
				textColor: "#FFFFFF"
			},
			{
				height: 66,
				url: "img/m3.png",
				width: 66,
				textColor: "#FFFFFF"
			},
			{
				height: 78,
				url: "img/m4.png",
				width: 78,
				textColor: "#FFFFFF"
			},
			{
				height: 90,
				url: "img/m5.png",
				width: 90,
				textColor: "#FFFFFF"
			}];
		var mcOptions = {gridSize: 70, averageCenter: true, minimumClusterSize: 1,
						maxZoom: 7, zoomOnClick: true, styles: mcStyles};
		$.each(json, function(country, stations) {
			var country_markers = [];
			$.each(stations, function(stationcode, infos) {
				infos.stationcode = stationcode;
				var latLng = new google.maps.LatLng(infos.lat, infos.lng);
				var icon = "img/marker.png";
				var icon_hover = "img/markerOn.png";
				if (infos.type == "T") {
					icon = "img/markerAir.png";
					icon_hover = "img/markerOnAir.png";
				} else if (infos.type == "L") {
					icon = "img/markerTrain.png";
					icon_hover = "img/markerOnTrain.png";
				}
				var infowindow_content = "";
				var marker = new google.maps.Marker({'position': latLng,
							'icon': icon,
							'title': (infos.stationname) ? infos.stationname : infos.address.cityname});
				var infobox_myOptions = {
					content: sfv2_gen_infowindow_content(stationcode, infos, country, hostname),
					disableAutoPan: true,
					maxWidth: 0,
					pixelOffset: new google.maps.Size(-140, 0),
					zIndex: null,
					closeBoxMargin: "8px",
					closeBoxURL: "img/close.gif",
					boxClass: "sfv2_infobox",
					infoBoxClearance: new google.maps.Size(1, 1),
					isHidden: false,
					pane: "floatPane"
				};
				var infobox = new InfoBox(infobox_myOptions);
				google.maps.event.addListener(infobox, 'closeclick', function() {sfv2_del_infobox(stationcode);});
				marker.mytype = infos.type;
				marker.cityname = infos.address.cityname;
				marker.fullcityname = infos.address.fullcityname;
				marker.stationcode = stationcode;
				marker.myvisibility = true;
				marker.title_orig = marker.title;
				google.maps.event.addListener(marker, 'mouseover', function() {
					marker.setIcon(icon_hover);
				});
				google.maps.event.addListener(marker, 'mouseout', function() {
					marker.setIcon(icon);
				});
				google.maps.event.addListener(marker, 'mouseover', function() {
					sfv2_setDistance(marker, 'title');
				});
				google.maps.event.addListener(marker, 'click', function() {
					if (typeof sfv2_infoboxes[stationcode] === "undefined") {
						infobox.stationcode = stationcode;
						sfv2_add_infobox(infobox);
						$("#sfv2_map").gmap3({action: "panTo", args: [marker.position]});
						sfv2_map.panBy(0, 100);
						google.maps.event.addListenerOnce(infobox, 'domready', function() {
							var url = sfv2_gen_infowindow_url(stationcode);
							sfv2_setDistance(marker, 'infobox');
							$("#sfv2_openhour_url_"+stationcode).attr("href", url);
							$("#sfv2_infowindow_tab_"+stationcode+"_a_info").click(function() {
												$("#sfv2_infowindow_afterhours_legend_"+stationcode).hide().text("");
//																	sfv2_infoboxes[stationcode].afterhours = false;
//																	sfv2_update_afterhours_legend();
																});
							$("#sfv2_infowindow_tabs_"+stationcode).tabs({spinner: '',
																		ajaxOptions: {
																			error: sfv2_tabs_ajax_error,
																			dataFilter: sfv2_tabs_ajax_dataFilter
																		}});
							$(".sfv2_infowindow_button a:first").click(function() {
								var url = $(this).attr("href");
								if (sfv2_chkdate_status == true
									&& sfv2_url_args["dotcarClientTypeCheckinCheckout"] !== "checkin")
								{
									var date_array = sfv2_split_date($("#sfv2_datepicker").val());
									url += "&preselectedCheckoutYear="+date_array["y"];
									url += "&preselectedCheckoutMonth="+date_array["m"];
									url += "&preselectedCheckoutDay="+date_array["d"];
									if ($("#sfv2_hours").val() !== 'no') {
										url += "&checkoutHour="+$("#sfv2_hours").val();
										url += "&checkoutMinute="+$("#sfv2_mins").val();
									}
								}
								$(this).attr("href", url);
								return true;
							});
							$(".sfv2_infowindow_send_mail").click(function() {
								sfv2_station_info["infos"] = infos;
								sfv2_station_info["infos"].buttonUrl = $(this).parents(".sfv2_infowindow_content").find(".sfv2_infowindow_button a:first").attr("href");
								$("#sfv2_modal_popup").dialog("open");
								return false;
							});
							
							$(".sfv2_infobox").click(function() {
														$(".sfv2_infobox").css("z-index", 0);
														$(this).css("z-index", 1);
													});
						});
						infobox.open(sfv2_map, marker);
					} else {
						sfv2_infoboxes[stationcode].close();
						sfv2_del_infobox(stationcode);
					}
				});
				sfv2_myStations.push(marker);
				sfv2_myStations_length++;
				country_markers.push(marker);
			});
			sfv2_markerCluster[incClusterer] = new MarkerClusterer(sfv2_map, country_markers, mcOptions);
			sfv2_markerCluster[incClusterer].setCalculator(sfv2_myCalculator);
			incClusterer++;
		});
		$("#sfv2_filter_box_more_content").oneTime(2000, sfv2_toggle_filter);
	 });
	$.getJSON("scripts/sfv2_json_countries.php?l="+sfv2_lang, function(json) {
		$.each(json, function(countries, country) {
			$("#sfv2_countries_select").append($("<option></option>").attr("value",country.ccode).text(country.cname));
			if (defaultcountrycode == country.ccode)
				$('#sfv2_countries_select option:last-child').attr("selected", "selected");
		});
		$("#sfv2_countries_select").change(function() {
			$("#sfv2_countries_cities_filter_ok").hide();
			$("#sfv2_cities_loading_img").show();
			var codecountry = $("#sfv2_countries_select option:selected").val();
			var namecountry = $("#sfv2_countries_select option:selected").text();
			$("#sfv2_cities_select").empty();
			$("#sfv2_cities_select").append($("<option></option>").attr("value", "all").text($("#sfv2_select_cities_default").text()));
			if (codecountry == "all") {
				sfv2_disable_street_view();
				$("#sfv2_cities_select").attr('disabled', true);
				sfv2_map.setCenter(new google.maps.LatLng(46.578498,2.457275));
				sfv2_map.setZoom(2);
				$("#sfv2_cities_loading_img").hide();
				$("#sfv2_countries_cities_filter_ok").show();
			}
			else {
			
				if(codecountry=="FI")
				{
					sfv2_disable_street_view();
					sfv2_map.setCenter(new google.maps.LatLng(65.5,26.3));
					sfv2_map.setZoom(5);
					$("#sfv2_cities_loading_img").hide();
					$("#sfv2_countries_cities_filter_ok").show();
				}
				else
					sfv2_goto('Country: '+namecountry, codecountry);
					
				$.getJSON("scripts/sfv2_json_cities.php?c="+codecountry, function(json) {
					$.each(json, function(cityname, cityname_formated) {
		$("#sfv2_cities_select").append($("<option></option>").attr("value", cityname).text(cityname_formated));
					});
					$("#sfv2_cities_loading_img").hide();
					$("#sfv2_cities_select").attr('disabled', false);
					$("#sfv2_countries_cities_filter_ok").show();
					$("#sfv2_cities_select").unbind('change');
					$("#sfv2_cities_select").change(function() {
						var cityname = $(this).val();
						var codecountry = $("#sfv2_countries_select option:selected").val();
						var namecountry = $("#sfv2_countries_select option:selected").text();
						if (cityname == "all") {
							sfv2_goto('Country: '+codecountry, namecountry);
						} else {
							sfv2_pantocity(codecountry+cityname);
						}
					});
				});
			}
		});
		if (defaultcountrycode) $("#sfv2_countries_select").trigger("change");
	 });
/*	var script = document.createElement( 'script' );
	script.type = 'text/javascript';
	script.src = 'scripts/sfv2_genJs.php';
	$("head").append(script);*/
}

function	sfv2_stations_show(type, opened, forced) {
	if ((type !== null && sfv2_type !== type) || (typeof opened !== "undefined" && sfv2_opened !== opened)
		|| (typeof forced !== "undefined" && forced === true))
	{
		if (type !== null)
			sfv2_type = type;
		if (typeof opened !== "undefined")
			sfv2_opened = opened;
		var length = sfv2_myStations.length;
		for (var i=0; i<length; i++) {
			if ((sfv2_type == "all" || sfv2_myStations[i].mytype == sfv2_type)
				&& (sfv2_opened == false || (typeof sfv2_closedStations[sfv2_myStations[i].stationcode] == "undefined"))) {
					sfv2_myStations[i].myvisibility = true;
					sfv2_myStations[i].setVisible(true);
			} else {
				sfv2_myStations[i].myvisibility = false;
				sfv2_myStations[i].setVisible(false);
			}
		}
		var sfv2_markerCluster_length = sfv2_markerCluster.length;
		for (var i=0; i<sfv2_markerCluster_length; i++) {
			sfv2_markerCluster[i].repaint();
		}
	}
	sfv2_display_nb_stations();
}

function	sfv2_filter_type_click(type) {
/*	if (filter.checked) {*/
	sfv2_stations_show(type);
	if (type !== 'all') {
		var bounds = sfv2_unzoom(sfv2_map.getBounds());
		if (bounds !== null) sfv2_map.fitBounds(bounds);
		sfv2_toggle_filter('click');
	}
/*	}*//* else {
		sfv2_type_hide(type);
	}	*/
}

function	sfv2_date_show(date, hour) {
	var url = "scripts/sfv2_json_hours.php?t="+date;
	url += (hour == null) ? "" : "&h="+hour;
	$.getJSON(url, function(json) {
		sfv2_closedStations = [];
		$.each(json, function(stationcode, openstatus) {
			if (openstatus == 0) sfv2_closedStations[stationcode] = 1;
		});
		$("#sfv2_subfilter_chk_date").attr("class", "sfv2_subfilter_chk checked");
		sfv2_chkdate_status = true;
		$("#sfv2_subfilter_date").show();
		sfv2_stations_show(null, true, true);
		$("#sfv2_datepicker_loading_img").hide();
		$("#sfv2_date_filter_ok").show();
	});
}

function	sfv2_show_chk(filtername, hide) {
	sfv2_show_loading();
	if (typeof hide == "undefined")	$("#sfv2_subfilter_chk_"+filtername).toggleClass("unchecked checked");
	else $("#sfv2_subfilter_chk_"+filtername).attr("class", "sfv2_subfilter_chk unchecked");
	var className = $("#sfv2_subfilter_chk_"+filtername).attr("class");
	showhide = (className == "sfv2_subfilter_chk checked") ? true : false;
	sfv2_stations_show(null, showhide);	
	sfv2_hide_loading();
}

function	sfv2_convert_date(datestring, format) {
	datestring += "";
	format += "";
	var year = month = day = formatedstring = "";
	var i_datestring = i_format = 0;
	var format_length = format.length;
	var datestring_length = datestring.length;
	if (datestring_length == 10 && format_length == 8) {
		while (i_format < format_length) {
			token = "";
			c_format = format.charAt(i_format);
			while ((format.charAt(i_format) == c_format) && (i_format < format_length)) {
				token += format.charAt(i_format++);
			}
			if (token=="yy") {
				year = "" + datestring.substring(i_datestring, i_datestring + 4);
				i_datestring += 4;
			} else if (token=="dd") {
				day = "" + datestring.substring(i_datestring, i_datestring + 2);
				i_datestring += 2;
			} else if (token=="mm") {
				month = "" + datestring.substring(i_datestring, i_datestring + 2);
				i_datestring += 2;
			} else {
				i_datestring++;
			}
		}
		formatedstring = year+"-"+month+"-"+day;
	}
	return (formatedstring);
}

function	sfv2_filter_date_click() {
	var hour = null;

	$("#sfv2_date_filter_ok").hide();
	$("#sfv2_datepicker_loading_img").show();
	if ($("#sfv2_hours").val() != "no") { hour = $("#sfv2_hours").val() + $("#sfv2_mins").val(); }
	var date = sfv2_convert_date($("#sfv2_datepicker")[0].value, $.datepicker.regional[sfv2_locale]["dateFormat"]);
	if (date !== "") {
		sfv2_date_show(date, hour);
	} else {
		alert("Bad date format!");
		$("#sfv2_datepicker_loading_img").hide();
		$("#sfv2_date_filter_ok").show();
	}
}

function	sfv2_getmylocation() {
	$("#sfv2_search_mylocation").hide();
	$("#sfv2_search_loading_img").show();
	$("#sfv2_map").gmap3({ action : 'geoLatLng', callback : sfv2_pantolocation});
}

function	sfv2_distanceBetween(station1, station2) {
	var R = 6378137; // earth's mean radius in meters (this was a parameter in V2)
	var rad = function(x) {return x*Math.PI/180;}
	var	s1lat = station1.lat();
	var	s2lat = station2.lat();
	var	s1lng = station1.lng();
	var	s2lng = station2.lng();
	var dLat = rad(s2lat - s1lat);
	var dLong = rad(s2lng - s1lng);
	
	var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(rad(s1lat)) * Math.cos(rad(s2lat)) * Math.sin(dLong/2) * Math.sin(dLong/2);
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
	var d = R * c;
	
	return d.toFixed(3);
}

function	sfv2_compareDistance(StationA, StationB) {
	var	baseMarkerLatLng = sfv2_baseMarker_position;
	var LatLonA = StationA.position;
	var LatLonB = StationB.position;
	return sfv2_distanceBetween(baseMarkerLatLng, LatLonA) - sfv2_distanceBetween(baseMarkerLatLng, LatLonB);
}

function	sfv2_sort(position) {
	var positionSave = null;
	if (typeof position !== "undefined") {
		positionSave = sfv2_baseMarker_position;
		sfv2_baseMarker_position = position;
	} else {
		sfv2_baseMarker_position = sfv2_baseMarker.position;
	}
	sfv2_myStations.sort(sfv2_compareDistance);
	if (positionSave !== null) {
		sfv2_baseMarker_position = positionSave;
	}
}

function	sfv2_get_street_address(marker, change_search_input) {
	$("#sfv2_map").gmap3({
		action:'getAddress',
		latLng:marker.getPosition(),
		callback:function(results){
			var content = (results && results[0]) ? (results[0].formatted_address) : null;
			sfv2_baseMarker = marker;
			if (change_search_input != false && content != null) {
				$("#sfv2_search_input").css("color", "#333");
				$("#sfv2_search_input").val(content);
			}
	}});
}

function	sfv2_get_opposite_point(center_marker, origin_marker) {
	var center_lat = center_marker.position.lat();
	var origin_lat = origin_marker.position.lat();
	var center_lng = center_marker.position.lng();
	var origin_lng = origin_marker.position.lng();
	var	oppose_lat = (center_lat - origin_lat) + center_lat;
	var	oppose_lng = (center_lng - origin_lng) + center_lng;
	return (new google.maps.LatLng(oppose_lat, oppose_lng));
}

function	sfv2_disable_street_view() {
	$("#sfv2_map").gmap3({
		action:'getStreetView',
		callback:function(panorama){
			var visible = panorama.getVisible();
			if (visible) { panorama.setVisible(false); }
	}});	
}

function	sfv2_getnbstationsdisp() {
	var nbstationsdisp = lat = lng = bSWlat = bSWlng = bNElat = bNElng = 0;
	var bounds = sfv2_map.getBounds();
	bSWlat = bounds.getSouthWest().lat();
	bSWlng = bounds.getSouthWest().lng();
	bNElat = bounds.getNorthEast().lat();
	bNElng = bounds.getNorthEast().lng();
	for (var i = 0; i < sfv2_myStations_length; i++) {
		lat = sfv2_myStations[i].position.lat();
		lng = sfv2_myStations[i].position.lng();
		if (sfv2_myStations[i].myvisibility == true
			&& bSWlat < lat && lat < bNElat
			&& bSWlng < lng && lng < bNElng) {
				nbstationsdisp++;
		}
	}
	return nbstationsdisp;
}

function	sfv2_unzoom(bounds) {
	sfv2_sort(bounds.getCenter());
	var lat = lng = bSWlat = bSWlng = bNElat = bNElng = 0;
	bSWlat = bounds.getSouthWest().lat();
	bSWlng = bounds.getSouthWest().lng();
	bNElat = bounds.getNorthEast().lat();
	bNElng = bounds.getNorthEast().lng();	
	for (var i = 0; i < sfv2_myStations_length; i++) {
		if (sfv2_myStations[i].mytype == sfv2_type) {
			lat = sfv2_myStations[i].position.lat();
			lng = sfv2_myStations[i].position.lng();
			if (bSWlat < lat && lat < bNElat && bSWlng < lng && lng < bNElng) {
				bounds = null;
			} else {
				bounds.extend(sfv2_myStations[i].position);
			}
			break;
		}
	}
	return bounds;
}

function	sfv2_pantocity(fullcityname){
	if(fullcityname=="ESLA PALMA") fullcityname="ESVILLA DE MAZO-LA PALMA";

	var	atleastonemarkervisible = false;
	sfv2_disable_street_view();
	if (fullcityname) {
		var	min_marker_to_d = 5;
		if (typeof sfv2_myStations[min_marker_to_d-1] == 'undefined')
			min_marker_to_d = sfv2_myStations.length;
		if (typeof sfv2_myStations[min_marker_to_d-1] !== 'undefined') {
			var bounds = new google.maps.LatLngBounds();
			for (var i = 0; i < sfv2_myStations_length; i++) {
				if (sfv2_myStations[i].fullcityname == fullcityname) {
					bounds.extend(sfv2_myStations[i].position);
					if (sfv2_myStations[i].myvisibility == true)
						atleastonemarkervisible = true;
				}
			}
			if (atleastonemarkervisible == false) bounds = sfv2_unzoom(bounds);
			sfv2_map.setOptions({maxZoom: 14});
			sfv2_map.fitBounds(bounds);
			sfv2_map.setOptions({maxZoom: null});
		}
	} else {
		alert($("#sfv2_location_error").text());
	}
}

function	sfv2_pantolocation(result){
	sfv2_disable_street_view();
	if (result) {
		var	min_marker_to_d = 5;
		if (typeof sfv2_myStations[min_marker_to_d-1] == 'undefined')
			min_marker_to_d = sfv2_myStations.length;
		if (typeof sfv2_myStations[min_marker_to_d-1] !== 'undefined') {
			var calc_location = (typeof result[0] == 'undefined') ? result : result[0].geometry.location;
			var bounds = new google.maps.LatLngBounds();
			if (sfv2_baseMarker !== null) $("#sfv2_map").gmap3({action:'clear'});
			sfv2_baseMarker = new google.maps.Marker({'position': calc_location});
			if (typeof result[0] == 'undefined') sfv2_get_street_address(sfv2_baseMarker);
			sfv2_sort();
			$("#sfv2_map").gmap3({action: 'addMarker', latLng: calc_location,
				marker:{options:{draggable: true, icon: 'https://maps.gstatic.com/mapfiles/icon_green.png'},
						events:{dragend: sfv2_get_street_address}}});
			bounds.extend(sfv2_get_opposite_point(sfv2_baseMarker, sfv2_myStations[min_marker_to_d-1]));
			bounds.extend(sfv2_myStations[min_marker_to_d-1].position);
			sfv2_map.fitBounds(bounds);
		}
	} else {
		alert($("#sfv2_location_error").text());
	}
	$("#sfv2_search_loading_img").hide();
	$("#sfv2_search_input_loading_img").hide();
	$("#sfv2_search_input_ok").show();
	if(!navigator.geolocation) { $("#sfv2_search_input").css("width", "393px");	}	
	else {$("#sfv2_search_mylocation").show();}
}

function	sfv2_goto_address(destination) {
//	$("#sfv2_search_input").css("width", "376px");
//	$("#sfv2_search_mylocation").hide();
//	$("#sfv2_search_loading_img").show();
	$("#sfv2_search_input_ok").hide();
	$("#sfv2_search_input_loading_img").show();
	if (destination) {
		$("#sfv2_map").gmap3(
		  { action: 'getLatLng', 
			address: destination,
			callback: sfv2_pantolocation}
		);	
	} else {
		$("#sfv2_search_input_loading_img").hide();
		$("#sfv2_search_input_ok").show();
	}
}

function	sfv2_show_loading(message) {
	if ($("#sfv2_loading_info").is(":visible") === false)
		$("#sfv2_loading_info").fadeIn(500);
}

function	sfv2_smart_hide_loading() {
	if (sfv2_myStations.length > 0) {
		clearInterval(sfv2_interval);
		sfv2_hide_loading();
	} else {
		sfv2_show_loading();		
	}
}

function	sfv2_hide_loading_timed() {
	sfv2_interval = setInterval(sfv2_smart_hide_loading, 1000);
}

function	sfv2_display_nb_stations() {
	var nbstationsdisp = sfv2_getnbstationsdisp();
	var nbstations_text = "";
	if (nbstationsdisp > 0) {
		nbstations_text = "<strong>"+nbstationsdisp+"</strong>&nbsp;";
		nbstations_text += $("#sfv2_info_area_nbstations_displayed").text();
	}
	$("#sfv2_info_area").html(nbstations_text);
}

function	sfv2_hide_loading() {
	sfv2_display_nb_stations();
	if ($("#sfv2_loading_info").is(":visible") === true)
		$("#sfv2_loading_info").fadeOut(500);
}

function	dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

function	sfv2_goto(destination, extra)
{
	sfv2_disable_street_view();
	$("#sfv2_map").gmap3(
		{	action: 'getLatLng', 
			address: destination,
			callback: function(result){
				if (result){
					$(this).gmap3({action: 'fitBounds', args:[ result[0].geometry.viewport ]});
				} else {
					if (typeof extra != 'undefined' && destination != extra) {
						sfv2_goto(extra);
					}
				}
			}
		}
	);
	//$.each(global_json, function(country, stations) {alert(country);});
}

function	sfv2_change_text_tongue() {
	var text_option = (sfv2_filter_shown == true) ? $("#sfv2_toggle_filter_text_more").text()
												: $("#sfv2_toggle_filter_text_less").text();	
	$("#sfv2_toggle_filter_text").text(text_option);
	sfv2_filter_shown = (sfv2_filter_shown == false) ? true : false;
}

function	sfv2_toggle_filter(from) {
	var d_filter_area = $("#sfv2_filter_box_more_content").css("display");
	var	is_click = (from == 'click') ? true : false;

	if ((sfv2_mouse_been_inside == false && sfv2_filter_shown == true) || is_click == true) {
		$("#sfv2_filter_box_more_content").slideToggle(1300, 'easeOutBounce', sfv2_change_text_tongue);
		$("#sfv2_top_shadow").fadeToggle(1300);
	}
}
