var jbase64 = {
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		input = jbase64._utf8_encode(input);
		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length) {
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		output = jbase64._utf8_decode(output);
		return output;
	},
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) utftext += String.fromCharCode(c);
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			} else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			} else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}

function IE6(){
	var ievs = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
	if (ievs){
		var iev = new Number(RegExp.$1);
		if (iev < 7) return true;
	}
	return false;
}

function IE8(){
	var ievs = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
	if (ievs){
		var iev = new Number(RegExp.$1);
		if (iev >= 8) return true;
	}
	return false;
}

var resetBox = {
	options:{
		myBlock: "boxBooking",
		myHeight: 78,
		myLiHeight: 32,
		myPadding: 20,
		myAction: ""
	},
	init: function(opts) {
		for (name in opts) resetBox.options[name] = opts[name];
	},
	set: function(myValue){
		if(document.getElementById(resetBox.options.myBlock)){
			myPassValue = parseInt(myValue);
			if(myPassValue > 1){
				resetBox.openBox(myPassValue, document.getElementById(resetBox.options.myBlock).offsetHeight-resetBox.options.myPadding, (resetBox.options.myHeight-resetBox.options.myPadding + (resetBox.options.myLiHeight*(myValue*1-1))));
			} else {
				resetBox.openBox(myPassValue, document.getElementById(resetBox.options.myBlock).offsetHeight-resetBox.options.myPadding, resetBox.options.myHeight-resetBox.options.myPadding);
			}
		} else {
			alert("attenzione: "+ resetBox.options.myBlock +"non esiste.");
		}
		return false;
	},
	openBox: function(myVal, height_nowB, heightB){
		myValuePass = parseInt(myVal);
		if(heightB > height_nowB){
			new_heightB = Math.round((heightB-height_nowB)/6)*1+1;
			if(resetBox.options.myAction == ""){
				setRoom(myValuePass, name_adults, name_children, name_childage, name_room);
				resetBox.options.myAction = "opening";
			}
		} else {
			new_heightB = Math.round((heightB-height_nowB)/6)*1-1;
			resetBox.options.myAction = "closing";
		}
		my_heightB = heightB;
		my_height_resultB = height_nowB + new_heightB;
		if ((heightB-height_nowB) > 3 || (heightB-height_nowB) < -3){
			setTimeout("resetBox.openBox(myValuePass, my_height_resultB, my_heightB)", 20);
			document.getElementById(resetBox.options.myBlock).style.height = my_height_resultB +"px";
		} else {
			document.getElementById(resetBox.options.myBlock).style.height = heightB+"px";
			if(resetBox.options.myAction == "closing"){
				setRoom(myValuePass, name_adults, name_children, name_childage, name_room);
			}
			resetBox.options.myAction = "";
			return false;
		}
		return true;
	}
}

function set_room(select_id, value, where){
	var my_options = "";
	var my_block = document.getElementById(select_id);
	if (value=="5" || value=="6" || value=="7" || value=="8"){
		my_options = my_options + '<label>'+ name_apartment +'</label>'+"\n";
		if(where == "home"){
			my_options = my_options + '<select name="bform[numRooms]" onchange="resetBox.set(this.value);">'+"\n";
		} else {
			my_options = my_options + '<select name="bform[numRooms]" onchange="setRoom(this.value, name_adults , name_children, name_childage, name_apartment, name_apartments);">'+"\n";
		}
		my_options = my_options + '<option value="1">1 '+name_apartment+'</option>'+"\n";
		my_options = my_options + '<option value="2">2 '+name_apartments+'</option>'+"\n";
		my_options = my_options + '<option value="3">3 '+name_apartments+'</option>'+"\n";
		my_options = my_options + '<option value="4">4 '+name_apartments+'</option>'+"\n";
		my_options = my_options + '</select>'+"\n";
		my_block.innerHTML = my_options;
		if(where == "home"){
			resetBox.set(1);
			setTimeout("setRoomHome(1, name_adults , name_children, name_childage, name_apartment, name_apartments)", 1000);
		} else {
			setRoom(1, name_adults , name_children, name_childage, name_apartment, name_apartments);
		}
	} else {
		my_options = my_options + '<label>'+ name_room +'</label>'+"\n";
		if(where == "home"){
			my_options = my_options + '<select name="bform[numRooms]" onchange="resetBox.set(this.value);">'+"\n";
		} else {
			my_options = my_options + '<select name="bform[numRooms]" onchange="setRoom(this.value, name_adults, name_children, name_childage, name_room, name_rooms);">'+"\n";
		}
		my_options = my_options + '<option value="1">1 '+name_room+'</option>'+"\n";
		my_options = my_options + '<option value="2">2 '+name_rooms+'</option>'+"\n";
		my_options = my_options + '<option value="3">3 '+name_rooms+'</option>'+"\n";
		my_options = my_options + '<option value="4">4 '+name_rooms+'</option>'+"\n";
		my_options = my_options + '</select>'+"\n";
		my_block.innerHTML = my_options;
		if(where == "home"){
			resetBox.set(1);
			setTimeout("setRoomHome(1, name_adults , name_children, name_childage, name_room, name_rooms)", 1000);
		} else {
			setRoom(1, name_adults , name_children, name_childage, name_room, name_rooms);
		}
	}
}

function setChildAge(nchild, chdid, roomn, label_children_age){
	var selectHtml = "";
	if(nchild > 0){
		if(document.getElementById("shadowCenter")) document.getElementById("shadowCenter").style.display = "none";
		selectHtml = '<label>'+ label_children_age +'</label>';
		for (var cc=1; cc<=nchild; cc++) {
			selectHtml =  selectHtml + '<select name="bform[reqRooms]['+roomn+'][childAge][' + cc + ']">' +
                '<option value="">&nbsp;-</option>' +
                '<option value="0">&lsaquo; 1</option>';
				for(var k=1; k<=18; k++){
					k_opt = k<10 ? "&nbsp;"+ k : k;
					selectHtml =  selectHtml + "\n" + '<option value="'+ k +'">'+ k_opt +'</option>';
				}
				selectHtml =  selectHtml + '</select>';
		}
	} else {
		if(document.getElementById("shadowCenter")) document.getElementById("shadowCenter").style.display = "block";
	}
	if(document.getElementById(chdid)){
		document.getElementById(chdid).innerHTML = selectHtml;
	}
}

function createSelect(num, init, label, selected){
	if(label != ""){
		label = " "+ label;
	}
	var mySel = "";
	for(var k=init; k<=num; k++){
		if (selected != 0 && selected == k){
			mySel = mySel + "\n" + '<option value="'+ k +'" selected="selected">'+ k + label +'</option>';
		} else {
			mySel = mySel + "\n" + '<option value="'+ k +'">'+ k + label +'</option>';
		}
	}
	return mySel;
}

function setRoom(nrooms, label_adults, label_children, label_children_age, label_room){
	var myResults = "";
	myResults = myResults + '<ul>\n';
	for (var i=1; i<=nrooms; i++){
		if(nrooms>1){
			myResults = myResults + '	<li><strong>'+ label_room +' '+i+'</strong>\n';
			if(document.getElementById("shadowCenter")) document.getElementById("shadowCenter").style.display = "none";
		} else {
			myResults = myResults + '	<li>\n';
			if(document.getElementById("shadowCenter")) document.getElementById("shadowCenter").style.display = "block";
		}
		myResults = myResults + '		<li>\n'+
		'			<label>'+ label_adults +'</label>\n'+
		'			<select name="bform[reqRooms]['+ i +'][adults]" class="select_small">\n'+
		'			'+ createSelect(6, 1, '', 2) + 
		'			</select>\n'+
		'		</li>\n'+
		'		<li>\n'+
		'			<label>'+ label_children +'</label>\n'+
		'			<select name="bform[reqRooms]['+ i +'][child]" class="select_small" onchange="setChildAge(this.value,\'chdAge_'+ i +'\', '+ i +',\''+ label_children_age +'\');">\n'+
		'			'+ createSelect(4, 0, '', 0) + 
		'			</select>\n'+
		'		</li>\n'+
		'		<li class="childAge" id="chdAge_'+ i +'"></li>\n'+
		'	</li>\n';
	}
	myResults = myResults + '</ul>\n';
	if (document.getElementById('contOption')){
		document.getElementById('contOption').innerHTML = myResults;
	} else {
		alert("blocco non valido");
	}
}

var checkCallback = {
	send: function(form){
		var testo_err = varCallError+'\n\n';
		var mancato_ins = false;
		var myForm = document.getElementById(form);
		if(myForm){
			if (myForm['callPhone'].value == varPhone || myForm['callPhone'].value == "" || myForm['callPrefix'].value == varPrefix || myForm['callPrefix'].value == "") {
				testo_err = testo_err + '<strong>+XX (international prefix)</strong>\n';
				testo_err = testo_err + '<strong>'+ varPhone +'</strong>\n';
				mancato_ins = true; 
			} else {
				if(!checkValue(myForm['callPrefix'].value, "prefix")){
					testo_err = testo_err + '<strong>+XX (international prefix)</strong>\n';
					mancato_ins = true;
				}
				if(!checkValue(myForm['callPhone'].value, "number")){
					testo_err = testo_err + '<strong>'+ varPhone +'</strong>\n';
					mancato_ins = true;
				}
			}
			if (mancato_ins == true) {
				var ie = false;
				if ((/MSIE (\d+\.\d+);/.test(navigator.userAgent))){
					ie = true;
				}
				if(!ie){
					jAlert(testo_err, 'Call Back', function(){
						if (myForm['callPrefix'].value == varPrefix || myForm['callPrefix'].value == ""){
							myForm['callPrefix'].value = "";
							myForm['callPrefix'].focus();
						} else if (myForm['callPhone'].value == varPhone || myForm['callPhone'].value == ""){
							myForm['callPhone'].value = "";
							myForm['callPhone'].focus();
						}
					});
				} else {
					testo_err = testo_err.replace('<strong>', '').replace('</strong>', '');
					alert(testo_err);
					if (myForm['callPhone'].value == varPhone || myForm['callPhone'].value == ""){
						myForm['callPhone'].value = "";
						myForm['callPhone'].focus();
					} else if (myForm['callPrefix'].value == varPrefix || myForm['callPrefix'].value == ""){
						myForm['callPrefix'].value = "";
						myForm['callPrefix'].focus();
					}
				}
				return false;
			}
			myForm.setAttribute("action", "/assets/mailerCallBack.php");
			return true;
		} else {
			alert(form +" non esiste.");
		}
	},
	init: function(form){
		var myForm = document.getElementById(form);
		if(myForm){
			var ie = false;
			if ((/MSIE (\d+\.\d+);/.test(navigator.userAgent))){
				ie = true;
			}
			document.getElementById('callPhone').value = varPhone;
			document.getElementById('callPrefix').value = varPrefix;
			if(!ie) {
				myForm.setAttribute("onsubmit", "return checkCallback.send('callForm');");
				document.getElementById('callPhone').setAttribute("onfocus", "checkCallback.change(this, true);");
				document.getElementById('callPhone').setAttribute("onblur", "checkCallback.change(this, false);");
				document.getElementById('callPhone').setAttribute("onchange", "checkCallback.change(this, 'writing');");
				document.getElementById('callPrefix').setAttribute("onfocus", "checkCallback.change(this, true);");
				document.getElementById('callPrefix').setAttribute("onblur", "checkCallback.change(this, false);");
				document.getElementById('callPrefix').setAttribute("onchange", "checkCallback.change(this, 'writing');");
			} else {
				myForm.onsubmit = function() {return checkCallback.send('callForm'); };
				document.getElementById('callPhone').onfocus = function() { checkCallback.change(this, true); };
				document.getElementById('callPhone').onblur = function() { checkCallback.change(this, false); };
				document.getElementById('callPhone').onchange = function() { checkCallback.change(this, 'writing'); };
				document.getElementById('callPrefix').onfocus = function() { checkCallback.change(this, true); };
				document.getElementById('callPrefix').onblur = function() { checkCallback.change(this, false); };
				document.getElementById('callPrefix').onchange = function() { checkCallback.change(this, 'writing'); };
			}
		}
	},
	change: function(myInput, status){
		var validi = "0123456789+";
		if(status == true && (myInput.value == "" || myInput.value == varPhone || myInput.value == varPrefix)){
			myInput.value = "";
		} else if(status == false && (myInput.value == "")){
			if(myInput.id == 'callPhone'){
				myInput.value = varPhone;
			} else {
				myInput.value = varPrefix;
			}
		} else if(status == 'writing'){
			var myValue = "";
			var myNewValue = "";
			myValue = myInput.value.replace(/\ /g, "");
			myValue = myValue.replace(/\./g, "");
			myValue = myValue.replace(/\-/g, "");
			for(var i = 0; i < myValue.length; i++ ){
				if( validi.indexOf( myValue.charAt(i) ) != -1 ){
					myNewValue = myNewValue + "" + myValue.charAt(i);
				}
			}
			myInput.value = myNewValue;
		}
	}
}

var newsletterSub = {
	options:{
		myform: "",
		myUrl:""
	},
	send: function(){
		var testo_err = varCallError+'\n\n';
		var mancato_ins = false;
		var thisForm = document.getElementById(newsletterSub.options.myForm);
		if(thisForm){
			if (thisForm['qwerty'].value == 'email@email.it' || thisForm['qwerty'].value == "") {
				testo_err = testo_err + '<strong>Email</strong>\n';
				mancato_ins = true; 
			} else {
				if(!checkValue(thisForm['qwerty'].value, "mail")){
					testo_err = testo_err + '<strong>Email</strong>\n';
					mancato_ins = true;
				}
			}
			if (mancato_ins == true) {
				var ie = false;
				if ((/MSIE (\d+\.\d+);/.test(navigator.userAgent))){
					ie = true;
				}
				if(!ie){
					jAlert(testo_err, 'Newsletter', function(){
						thisForm['qwerty'].value = "";
						thisForm['qwerty'].focus();
					});
				} else {
					testo_err = testo_err.replace('<strong>', '').replace('</strong>', '');
					alert(testo_err);
					thisForm['qwerty'].value = "";
					thisForm['qwerty'].focus();
				}
				return false;
			}
			thisForm.setAttribute("action", newsletterSub.options.myUrl);
			return true;
		} else {
			alert(form +" non esiste.");
		}
	},
	init: function(form, url){
		newsletterSub.options.myForm = form;
		newsletterSub.options.myUrl = url;
		var thisForm = document.getElementById(form);
		if(thisForm){
			var ie = false;
			if ((/MSIE (\d+\.\d+);/.test(navigator.userAgent))){
				ie = true;
			}
			if(!ie) {
				thisForm.setAttribute("onsubmit", "return newsletterSub.send();");
			} else {
				thisForm.onsubmit = function() {return newsletterSub.send(); };
			}
		}
	}
}

function checkValue(string, type){
	if(type == undefined || type == "number"){
		var validi = "0123456789";
		var myNumberNew = string;
		myNumberNew = myNumberNew.replace(/\ /g, "");
		myNumberNew = myNumberNew.replace(/\+/g, "");
		myNumberNew = myNumberNew.replace(/\./g, "");
		myNumberNew = myNumberNew.replace(/\-/g, "");
		if(myNumberNew == ''){
			return false;
		}
		for(var i = 0; i < myNumberNew.length; i++ ){
			if( validi.indexOf( myNumberNew.charAt(i) ) == -1 ){
				return false;
			}
		}
	} else if(type == "prefix") {
		var validi = "0123456789+";
		var myNumberNew = string;
		myNumberNew = myNumberNew.replace(/\ /g, "");
		myNumberNew = myNumberNew.replace(/\./g, "");
		myNumberNew = myNumberNew.replace(/\-/g, "");
		if(myNumberNew == ''){
			return false;
		}
		for(var i = 0; i < myNumberNew.length; i++ ){
			if( validi.indexOf( myNumberNew.charAt(i) ) == -1 ){
				return false;
			}
		}
	} else if(type == "mail") {
		if (string.length > 9){
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(string)) {
				return false;
			}
		} else {
			return false;
		}
	} else if(type == "text") {
		var filter = /^([a-zA-Z\ \'])/;
		if (!filter.test(string)) {
			return false;
		}
	}
	return true;
}

function localTime(myId, timeNow, engMode) {
	if(engMode == undefined) engMode = false;
	var addTime = '';
	var addTimeNext = '';
	var timeResetNow = new Date();
	var mySplitData = timeNow.split(":");
	if(document.currenttimeItaly === undefined){
		timeResetNow.setHours(mySplitData[0]);
		timeResetNow.setMinutes(mySplitData[1]);
		timeResetNow.setSeconds(mySplitData[2]);
		document.currenttimeItaly = timeResetNow.getTime();
	}else{
		document.currenttimeItaly  += 1000;
	}
	timeResetNow.setTime(document.currenttimeItaly);
	var hours_passed = timeResetNow.getHours();
	if(hours_passed < 10) hours_passed = "0" + hours_passed;
	var minutes_passed = timeResetNow.getMinutes();
	if(minutes_passed < 10)	minutes_passed = "0" + minutes_passed;
	var seconds_passed = timeResetNow.getSeconds();
	if(seconds_passed < 10)	seconds_passed = "0" + seconds_passed;
	if(engMode){
		if((hours_passed*1) > 12) {
			hours_passed = (hours_passed*1) - 12;
			addTime = '<br /><em class="right">pm</em>';
		} else {
			addTime = '<br /><em class="right">am</em>';	
		}
		addTimeNext = ', true';
	}
	document.getElementById(myId).innerHTML = hours_passed + ":" + minutes_passed + "<em>:" + seconds_passed + "</em>" + addTime;
	setTimeout('localTime("'+myId+'", "'+timeResetNow+'"'+ addTimeNext +')', 1000);
}

function minimizeOfferBox(){
	jq("#claim").css({'background':'url("/images/bgClaimHomeMin.gif") repeat-x center bottom #6C0000', 'padding-bottom':'135px'});
	jq("#boxOffersHome ul").height(95);
	jq("#boxOffersHome").height(117);
}

// FUNZIONI PER LA MAPPA V3
var i, infoBox;
i = 1;
var myZindex = 0;
var changeZoom = false;
/*
function setMarkers_old(mapId, optiones, zoom, mapType, showCursor, multiple, showBox, openBox) {
	if (multiple == undefined) multiple = false;
	var multipleCategory = "";
	if(multiple != false && multiple !== true){
		multipleCategory = multiple;
		multiple = true;
	}
	if (showBox == undefined) showBox = false;
	if (openBox == undefined) openBox = false;
	if (showBox || openBox != false) infoBox = new BFInfoWindow();
	var myMarker = new Array();
	myMarker['iconsize'] = "30,30";
	myMarker['iconhancor'] = "0,15";
	for (names in optiones) myMarker[names] = optiones[names];
	var latlng = new google.maps.LatLng(myMarker['lat'], myMarker['lon']);
	if(mapType == undefined) mapType = "ROADMAP"; //ROADMAP - SATELLITE - HYBRID - TERRAIN 
	if(showCursor == undefined) showCursor = false;
    var myOptions = {
		disableDefaultUI: showCursor,
		zoom: zoom,
		center: latlng,
		mapTypeId: google.maps.MapTypeId[mapType]
    };
	
    var maps = new google.maps.Map(document.getElementById(mapId), myOptions);
	
	var markerBounds = new google.maps.LatLngBounds();
	
	var myLatLng = new google.maps.LatLng(myMarker['lat'], myMarker['lon']);
	
	if (multiple){
		if(multipleCategory != "") multipleCategory = "?sectionId="+ multipleCategory;
		downloadUrl("/assets/interestPoint.php"+ multipleCategory, function(data, responseCode) {

  			var markers_def = data.documentElement.getElementsByTagName("marker");
			for (var i_def=0; i_def<markers_def.length; i_def++) {
				
				markerBounds.extend(new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))));
				
				if(openBox != false && openBox == markers_def[i_def].getAttribute("id")){
					var marker = new google.maps.Marker({
						position: new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))),
						map: maps,
						icon: '/images/iconMarkerBig.png',
						zIndex: 20000000000
					});
					openInfoBox(marker, base_64.decode(markers_def[i_def].getAttribute("ballon")), maps);
				} else if(openBox != false && openBox != markers_def[i_def].getAttribute("id")){
					var marker = new google.maps.Marker({
						position: new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))),
						map: maps,
						title: markers_def[i_def].getAttribute("name"),
						icon: markers_def[i_def].getAttribute("idImg"),
						zIndex: myZindex + 1
					});
					attachURL(marker, markers_def[i_def].getAttribute("url"));
				} else if(openBox == false){
					var marker = new google.maps.Marker({
						position: new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))),
						map: maps,
						icon: markers_def[i_def].getAttribute("idImg"),
						zIndex: myZindex + 1
					});
					
					google.maps.event.addListener(marker, "mouseover", function() {
						this.setZIndex(myZindex + 1);
						myZindex = myZindex + 1;
					});
	
					if(markers_def[i_def].getAttribute("url") != "") {
						if(showBox) attachInfoBox(marker, base_64.decode(markers_def[i_def].getAttribute("ballon")), maps, markers_def[i_def].getAttribute("url"));
						attachURL(marker, markers_def[i_def].getAttribute("url"));
					} else {
						if(showBox) attachInfoBox(marker, base_64.decode(markers_def[i_def].getAttribute("ballon")), maps);
					}
					myZindex++;
				}
			}
			if(openBox == false){
				if(markers_def.length > 1){
					markerBounds.extend(new google.maps.LatLng(myMarker['lat'], myMarker['lon']));
					maps.fitBounds(markerBounds);
				}
				google.maps.event.addListener(maps, 'zoom_changed', function() {
					if(changeZoom == false){
						if(markers_def.length < 2 && maps.getZoom() > 13) maps.setZoom(13);
						changeZoom = true;
					} 
				});
			}
		});
	} else {
		var marker = new google.maps.Marker({
			position: myLatLng,
			map: maps,
			icon: myMarker['icon']
		});
	}
	var markerHotel = new google.maps.Marker({
		position: new google.maps.LatLng(myMarker['lat'], myMarker['lon']),
		map: maps,
		title: "Annia Park Hotel",
		icon:'/images/iconHotel.png',
		zIndex: myZindex
	});
	
}
*/
function setMarkers(mapId, optiones, zoom, mapType, showCursor, multiple, showBox, openBox) {
	if (multiple == undefined) multiple = false;
	var multipleCategory = "";
	if(multiple != false && multiple !== true){
		multipleCategory = multiple;
		multiple = true;
	}
	if (showBox == undefined) showBox = false;
	if (openBox == undefined) openBox = false;
	if (showBox || openBox != false) infoBox = new BFInfoWindow();
	var myMarker = new Array();
	myMarker['iconsize'] = "30,30";
	myMarker['iconhancor'] = "0,15";
	for (names in optiones) myMarker[names] = optiones[names];
	var latlng = new google.maps.LatLng(myMarker['lat'], myMarker['lon']);
	if(mapType == undefined) mapType = "ROADMAP"; //ROADMAP - SATELLITE - HYBRID - TERRAIN 
	if(showCursor == undefined) showCursor = false;
    var myOptions = {
		disableDefaultUI: showCursor,
    	mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		zoom: zoom,
		center: latlng,
		mapTypeId: google.maps.MapTypeId[mapType]
    };
	
    var maps = new google.maps.Map(document.getElementById(mapId), myOptions);
	var markerBounds = new google.maps.LatLngBounds();
	var myLatLng = new google.maps.LatLng(myMarker['lat'], myMarker['lon']);
	
	if (multiple){
		if(multipleCategory != "") multipleCategory = "?sectionId="+ multipleCategory;
		downloadUrl("/assets/interestPoint.php"+ multipleCategory, function(data, responseCode) {

  			var markers_def = data.documentElement.getElementsByTagName("marker");
			for (var i_def=0; i_def<markers_def.length; i_def++) {
				
				markerBounds.extend(new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))));
				
				if(openBox != false && openBox == markers_def[i_def].getAttribute("id")){
					var marker = new google.maps.Marker({
						position: new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))),
						map: maps,
						icon: '/images/blank.gif',
						zIndex: 20000000000
					});
					openInfoBox(marker, base_64.decode(markers_def[i_def].getAttribute("ballon")), maps);
				} else if(openBox != false && openBox != markers_def[i_def].getAttribute("id")){
					var marker = new google.maps.Marker({
						position: new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))),
						map: maps,
						title: markers_def[i_def].getAttribute("name"),
						icon: markers_def[i_def].getAttribute("idImg"),
						zIndex: myZindex + 1
					});
					attachURL(marker, markers_def[i_def].getAttribute("url"));
				} else if(openBox == false){
					var marker = new google.maps.Marker({
						position: new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))),
						map: maps,
						icon: markers_def[i_def].getAttribute("idImg"),
						zIndex: myZindex + 1
					});
					
					google.maps.event.addListener(marker, "mouseover", function() {
						this.setZIndex(myZindex + 1);
						myZindex = myZindex + 1;
					});
	
					if(markers_def[i_def].getAttribute("url") != "") {
						if(showBox) attachInfoBox(marker, base_64.decode(markers_def[i_def].getAttribute("ballon")), maps, markers_def[i_def].getAttribute("url"), markers_def[i_def].getAttribute("idImg"));
						attachURL(marker, markers_def[i_def].getAttribute("url"));
					} else {
						if(showBox) attachInfoBox(marker, base_64.decode(markers_def[i_def].getAttribute("ballon")), maps, 'javascript:;', markers_def[i_def].getAttribute("idImg"));
					}
					myZindex++;
				}
			}
			if(openBox == false){
				if(markers_def.length > 1){
					markerBounds.extend(new google.maps.LatLng(myMarker['lat'], myMarker['lon']));
					maps.fitBounds(markerBounds);
				}
				google.maps.event.addListener(maps, 'zoom_changed', function() {
					if(changeZoom == false){
						if(markers_def.length < 2 && maps.getZoom() > 13) maps.setZoom(13);
						changeZoom = true;
					} 
				});
			}
		});
	} else {
		var marker = new google.maps.Marker({
			position: myLatLng,
			map: maps,
			icon: myMarker['icon']
		});

	}
	var markerHotel = new google.maps.Marker({
		position: new google.maps.LatLng(45.50666082233497, 12.332300841808319),
		map: maps,
		title: "Annia Park Hotel",
		icon:'/images/iconHotel.png',
		zIndex: myZindex
	});
	
}
/*
var infowindow;
function attachURL(marker, url) {
	google.maps.event.addListener(marker, "click", function() {
		location.href = url;
	});
}
function attachInfoBox(marker, text, myMap, url) {
	google.maps.event.addListener(marker, "mouseover", function() {
		myZindex = myZindex + 1;
		this.setZIndex(myZindex);
		infoBox.setContent(text);
		infoBox.setUrl(url);
		infoBox.open(myMap, this);
		this.setIcon('/images/iconMarkerBig.png');
	});
	google.maps.event.addListener(marker, "mouseout", function() {
		this.setIcon('/images/iconMarker.png');
		setTimeout('infoBox.close()', 100);
	});
}
function openInfoBox(marker, text, myMap) {
	var myLatLan = marker.getPosition();
	myMap.setCenter(myLatLan);
	infoBox.setContent(text);
	infoBox.open(myMap, marker);
}
*/
var infowindow;
function attachURL(marker, url) {
	google.maps.event.addListener(marker, "click", function() {
		location.href = url;
	});
}
function attachInfoBox(marker, text, myMap, url, icon) {
	google.maps.event.addListener(marker, "mouseover", function() {
		myZindex = myZindex + 1;
		this.setZIndex(myZindex);
		infoBox.setContent(text);
		if(url != 'javascript:;') infoBox.setUrl(url);
		infoBox.open(myMap, this);
		this.setIcon('/images/iconMarkerHover.png');
	});
	google.maps.event.addListener(marker, "mouseout", function() {
		infoBox.close();
		this.setIcon(icon);
		//setTimeout("infoBox.close()", 100);
	});
}
function openInfoBox(marker, text, myMap) {
	var myLatLan = marker.getPosition();
	myMap.setCenter(myLatLan);
	infoBox.setContent(text);
	infoBox.open(myMap, marker);
}

var setDirection = {
	options:{
		mapContainer: document.getElementById('mapBig'),
		dirContainer: document.getElementById('dirContainer'),
		dirService: "",
		dirRenderer: "",
		map: null
	},
	init: function (myText, from, to, direction, latLan){
		if(document.getElementById('ballon')){
			setDirection.options.dirService = new google.maps.DirectionsService();
			setDirection.options.dirRenderer = new google.maps.DirectionsRenderer();
			var myFormDirection, textDirection;
			if(direction == "FROM"){
				myFormDirection = '<form name="direction" action="javascript:;" method="get"><input id="from-input" type="hidden" value="'+ latLan +'" />';
				myFormDirection += '<input id="to-input" type="text" value="" class="inputE" />';
				myFormDirection += '<input class="inputB" onclick="setDirection.getDirections(document.getElementById(\'from-input\').value, document.getElementById(\'to-input\').value);" type="button" value=">" /></form>';
				textDirection = myText +'<br /><strong>'+ from +'</strong> - <a href="javascript:;" onclick="setDirection.init(\''+ myText +'\', \''+ from +'\', \''+ to +'\', \'TO\', \''+ latLan +'\');"><strong>'+ to +'</strong></a>'+ myFormDirection;
			} else {
				myFormDirection = '<form name="direction" action="javascript:;" method="get"><input id="from-input" type="text" value="" class="inputE" />';
				myFormDirection += '<input id="to-input" type="hidden" value="'+ latLan +'" />';
				myFormDirection += '<input class="inputB" onclick="setDirection.getDirections(document.getElementById(\'from-input\').value, document.getElementById(\'to-input\').value);" type="button" value=">" /></form>';
				textDirection = myText +'<br /><a href="javascript:;" onclick="setDirection.init(\''+ myText +'\', \''+ from +'\', \''+ to +'\', \'FROM\', \''+ latLan +'\');"><strong>'+ from +'</strong></a> - <strong>'+ to +'</strong>'+ myFormDirection;
			}
			document.getElementById('ballon').innerHTML = textDirection;
		}
	},
	getDirections: function(fromStr, toStr){
		var dirRequest = {
			origin: fromStr,
			destination: toStr,
			travelMode: google.maps.DirectionsTravelMode.DRIVING,
			unitSystem: google.maps.DirectionsUnitSystem.METRIC,
			provideRouteAlternatives: true
		};
		setDirection.options.dirService.route(dirRequest, setDirection.showDirections);
	},
	showDirections: function(dirResult, dirStatus) {
		if (dirStatus != google.maps.DirectionsStatus.OK) {
		  if(typeof(dirStatusError) != 'undefined') alert(dirStatusError +"\n(Google reports: "+ dirStatus +")");
		  return;
		}
		//if(infowindow) infowindow.close();
		jq('html,body').animate({scrollTop: jq('#mapBig').offset().top - 20}, 1000);
		setDirection.options.dirRenderer.setMap(null);
		setDirection.options.dirRenderer.setMap(maps);
		jq('#dirContainer').html('');
		setDirection.options.dirRenderer.setPanel(document.getElementById('dirContainer'));
		setDirection.options.dirRenderer.setDirections(dirResult);
	}

}
var infowindow;
function setPoint(mapId, optiones, zoom, mapType, showCursor) {
	var myMarker = new Array();
	myMarker['iconsize'] = "30,30";
	myMarker['iconhancor'] = "0,15";
	myMarker['infowindow'] = "";
	
	for (names in optiones) myMarker[names] = optiones[names];
	var latlng = new google.maps.LatLng(myMarker['lat'], myMarker['lon']);
	if(mapType == undefined) mapType = "ROADMAP"; //ROADMAP - SATELLITE - HYBRID - TERRAIN 
	if(showCursor == undefined) showCursor = false;
    var myOptions = {
		disableDefaultUI: showCursor,
		mapTypeControl: true,
    	mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		zoom: zoom,
		center: latlng,
		mapTypeId: google.maps.MapTypeId[mapType]
    };
    maps = new google.maps.Map(document.getElementById(mapId), myOptions);
	
	var myLatLng = new google.maps.LatLng(myMarker['lat'], myMarker['lon']);

	var marker = new google.maps.Marker({
		position: myLatLng,
		map: maps,
		icon: myMarker['icon'],
        zIndex: 10000
	});

	if(myMarker['infowindow'] != ""){
		infowindow = new google.maps.InfoWindow({
			content: myMarker['infowindow'],
			maxWidth: 350,
			position: myLatLng,
			zIndex: 100
		});
		infowindow.open(maps, infowindow);
		google.maps.event.addListener(marker, "click", function() {
			infowindow.open(maps, infowindow);
		});
	}
}

var base_64 = {
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		input = Base64._utf8_encode(input);
		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length) {
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) output = output + String.fromCharCode(chr2);
			if (enc4 != 64) output = output + String.fromCharCode(chr3);
		}
		output = Base64._utf8_decode(output);
		return output;
	},
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			} else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			} else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			} else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}

function createXmlHttpRequest(){
	try {
		if (typeof ActiveXObject != 'undefined') {
			return new ActiveXObject('Microsoft.XMLHTTP');
		} else if (window["XMLHttpRequest"]) {
			return new XMLHttpRequest();
		}
	} catch (e) {
		changeStatus(e);
	}
	return null;
}

function downloadUrl(url, callback) {
	var status = -1;
	var request = createXmlHttpRequest();
	if (!request) {
		return false;
	}
	
	request.onreadystatechange = function(){
		if (request.readyState == 4) {
			try {
				status = request.status;
			} catch (e) {
			}
			if (status == 200) {
				callback(request.responseXML, request.status);
				request.onreadystatechange = function() {};
			}
		}
	}
	request.open('GET', url, true);
	try {
		request.send(null);
	} catch (e) {
		changeStatus(e);
	}
}


(function($){$.alerts={verticalOffset:-75,horizontalOffset:0,repositionOnResize:true,overlayOpacity:.7,overlayColor:'#000',draggable:true,okButton:'&nbsp;OK&nbsp;',cancelButton:'&nbsp;Cancel&nbsp;',dialogClass:null,alert:function(message,title,callback){if(title==null)title='Alert';$.alerts._show(title,message,null,'alert',function(result){if(callback)callback(result);});},confirm:function(message,title,callback){if(title==null)title='Confirm';$.alerts._show(title,message,null,'confirm',function(result){if(callback)callback(result);});},prompt:function(message,value,title,callback){if(title==null)title='Prompt';$.alerts._show(title,message,value,'prompt',function(result){if(callback)callback(result);});},_show:function(title,msg,value,type,callback){$.alerts._hide();$.alerts._overlay('show');$("BODY").append('<div id="popup_container">'+'<h1 id="popup_title"></h1>'+'<div id="popup_content">'+'<div id="popup_message"></div>'+'</div>'+'</div>');if($.alerts.dialogClass)$("#popup_container").addClass($.alerts.dialogClass);var pos=($.browser.msie&&parseInt($.browser.version)<=6)?'absolute':'fixed';$("#popup_container").css({position:pos,zIndex:99999,padding:0,margin:0});$("#popup_title").text(title);$("#popup_content").addClass(type);$("#popup_message").text(msg);$("#popup_message").html($("#popup_message").text().replace(/\n/g,'<br />'));$("#popup_container").css({minWidth:$("#popup_container").outerWidth(),maxWidth:$("#popup_container").outerWidth()});$.alerts._reposition();$.alerts._maintainPosition(true);switch(type){case 'alert':$("#popup_message").after('<div id="popup_panel"><input type="button" value="'+$.alerts.okButton+'" id="popup_ok" /></div>');$("#popup_ok").click(function(){$.alerts._hide();callback(true);});$("#popup_ok").focus().keypress(function(e){if(e.keyCode==13||e.keyCode==27)$("#popup_ok").trigger('click');});break;case 'confirm':$("#popup_message").after('<div id="popup_panel"><input type="button" value="'+$.alerts.okButton+'" id="popup_ok" /> <input type="button" value="'+$.alerts.cancelButton+'" id="popup_cancel" /></div>');$("#popup_ok").click(function(){$.alerts._hide();if(callback)callback(true);});$("#popup_cancel").click(function(){$.alerts._hide();if(callback)callback(false);});$("#popup_ok").focus();$("#popup_ok, #popup_cancel").keypress(function(e){if(e.keyCode==13)$("#popup_ok").trigger('click');if(e.keyCode==27)$("#popup_cancel").trigger('click');});break;case 'prompt':$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="'+$.alerts.okButton+'" id="popup_ok" /> <input type="button" value="'+$.alerts.cancelButton+'" id="popup_cancel" /></div>');$("#popup_prompt").width($("#popup_message").width());$("#popup_ok").click(function(){var val=$("#popup_prompt").val();$.alerts._hide();if(callback)callback(val);});$("#popup_cancel").click(function(){$.alerts._hide();if(callback)callback(null);});$("#popup_prompt, #popup_ok, #popup_cancel").keypress(function(e){if(e.keyCode==13)$("#popup_ok").trigger('click');if(e.keyCode==27)$("#popup_cancel").trigger('click');});if(value)$("#popup_prompt").val(value);$("#popup_prompt").focus().select();break;}if($.alerts.draggable){try{$("#popup_container").draggable({handle:$("#popup_title")});$("#popup_title").css({cursor:'move'});}catch(e){}}},_hide:function(){$("#popup_container").remove();$.alerts._overlay('hide');$.alerts._maintainPosition(false);},_overlay:function(status){switch(status){case 'show':$.alerts._overlay('hide');$("BODY").append('<div id="popup_overlay"></div>');$("#popup_overlay").css({position:'absolute',zIndex:99998,top:'0px',left:'0px',width:'100%',height:$(document).height(),background:$.alerts.overlayColor,opacity:$.alerts.overlayOpacity});break;case 'hide':$("#popup_overlay").remove();break;}},_reposition:function(){var top=(($(window).height()/2)-($("#popup_container").outerHeight()/2))+$.alerts.verticalOffset;var left=(($(window).width()/2)-($("#popup_container").outerWidth()/2))+$.alerts.horizontalOffset;if(top<0)top=0;if(left<0)left=0;if($.browser.msie&&parseInt($.browser.version)<=6)top=top+$(window).scrollTop();$("#popup_container").css({top:top+'px',left:left+'px'});$("#popup_overlay").height($(document).height());},_maintainPosition:function(status){if($.alerts.repositionOnResize){switch(status){case true:$(window).bind('resize',$.alerts._reposition);break;case false:$(window).unbind('resize',$.alerts._reposition);break;}}}};jAlert=function(message,title,callback){$.alerts.alert(message,title,callback);};jConfirm=function(message,title,callback){$.alerts.confirm(message,title,callback);};jPrompt=function(message,value,title,callback){$.alerts.prompt(message,value,title,callback);};})(jQuery);