// "Vpb" component for Joomla! 1.0.x - Version 1.1.0
// Copyright (c) 2006 - 2007 Webagain.net - http://www.webagain.net
// This code cannot be redistributed without permission from http://www.webagain.net
// Authors: Luca Scarpa
// Project page at http://www.webagain.net
// ***Last update: Nov 01th, 2007***

var myMessageOpacity = null;
var myMessageSlide = null;
var favorites = new Array();
var details = null;
var menudetails = null;
var fxboxiti = null;
var map = null;
var geocoder = null;

function message(){
	var div = $$('.message')[0];
	myMessageOpacity = new Fx.Style(div, 'opacity', {duration: 1000});
	if(div.innerHTML!=''){
		myMessageOpacity.set(0);
		myMessageOpacity.start(0,1);
		setTimeout(function(){ myMessageOpacity.start(1,0); },1500);
		setTimeout(function(){ div.innerHTML='';div.setStyles('height:0px; margin-bottom:0px');},2500);
	}
}

function showMessage(message){
	var div = $$('.message')[0];
	div.setStyles('height:; margin-bottom:');
	myMessageOpacity.set(0);
	div.innerHTML=message;
	myMessageOpacity.start(0,1);
	setTimeout(function(){ myMessageOpacity.start(1,0); },1500);
	setTimeout(function(){ div.innerHTML=''; div.setStyles('height:0px; margin-bottom:0px');},2500);
}

function openclosebottom(task,id,a,formname,effect){
	var form = null;
	var goodEmail=true;
	var text = '';
	var name = '';
	var email = '';
	var emailfriend = '';
	var vImageCodP = '';
	var subscribe = '';
	
	if(a==null){
		form = eval('document.'+formname);
		goodEmail = form.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if((form.email.value.indexOf(";")>=0)||(form.email.value.indexOf(",")>=0)||(form.email.value.indexOf(" ")>=0)) goodEmail=false;
		if(form.name.value==''){
			alert(lang_vpb['CUSTOMER_NAMEMISSIN']);
			return;
		} else if(form.email.value == '') {
			alert(lang_vpb['CUSTOMER_EMAILERROR']);
			return;
		} else if(!goodEmail) {
			alert(lang_vpb['CUSTOMER_TEXTMISSIN']);
			return;
		} else if(((formname=='formContact')||(formname=='formFriend'))&&(form.text.value == '')) {
			alert(lang_vpb['CUSTOMER_EMAILFRIENDMISSIN']);
			return;
		}	
		
		if(task=='sendMailFriend'){
			if(form.emailfriend.value == ''){
				alert(lang_vpb['CUSTOMER_TEXTMISSIN']);
				return;
			}	else {	
				emailfriend = form.emailfriend.value;
			}
		}
		email = form.email.value;
		if((formname=='formContact')||(formname=='formFriend')){
			vImageCodP = form.vImageCodP.value;
			text = form.text.value;
		} else {
			if(form.subscribe[0].checked == true)
				subscribe = form.subscribe[0].value;
			else subscribe = form.subscribe[1].value;
		}
		name = form.name.value;
	} 

	if($('ajaxMap')) {
		new Fx.Style('ajaxMap', 'opacity', {duration: 1000}).start(1,0).chain(function(){ menudetails.slideOut();});
	} else {
		if(!effect)	menudetails.slideOut();
	}
		
	var tempAjax = new Ajax(url, {
		method: 'post', 
		update: $('detailsmainmenu-content'), 
		evalScripts:true,
		onComplete: function(){ 
			var color = $$('.menu');
			if(a!=null){
				for(var z=0; z<color.length; z++){
					color[z].removeClass('selected');
				}
				a.addClass('selected');
			}

			menudetails.slideIn(); 
		},
		postBody: Object.toQueryString({
			task: task,
			no_html: '1',
			id: id,
			text: text,
			vImageCodP: vImageCodP,
			name: name,
			emailfriend: emailfriend,
			email: email,
			subscribe: subscribe
		})
	});
	
	if($('ajaxMap')) {
		setTimeout(function(){ tempAjax.request(); },1500);
	} else {
		setTimeout(function(){ tempAjax.request(); },500);
	}
}

function addToFavorites(id){
	new Ajax(url, {method: 'post', evalScripts:true,
	postBody: Object.toQueryString({
		task: 'addToFavorites',
		no_html: '1',
		id: id
	})}).request();
}

function showBoxItinerary(id,message){
	if(message==null) message='';
	new Ajax(url, {method: 'post', 
	evalScripts:true,
	update: 'itinerarybox',
	onComplete: function(){ 
		fxboxiti.slideIn(); 
	},
	postBody: Object.toQueryString({
		task: 'showItineraryBox',
		message: message,
		no_html: '1',
		id: id
	})}).request();
}


/* SEZIONE RELATIVA ALLA GESTIONE DI GOOGLE */
function gload() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		geocoder = new GClientGeocoder();
	}
}

function addMarker(lat,lng,html) {
	// Creo il punto
	var point = new GLatLng(lat,lng);
	// Creo il marker		
	var marker = new GMarker(point);
	// Aggiungo gli eventi
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});

	map.addOverlay(marker);
	
}

function reloadpage(){
	var distance = '';
	var count = 0;
	
	if(document.vpb_filter.cityid.value==0){
		alert(lang_vpb['CHECKFORM_BEFORECITY']);
		document.vpb_filter.subcatid.options[0].selected=true;
		return false;
	}
	
	if(document.vpb_filter.distancetocenter) distance = document.vpb_filter.distancetocenter.value;
	else distance = 0;
				
	new Ajax(url, {method: 'post', update: $('vpb_list'), evalScripts:true,
	postBody: Object.toQueryString({
		task: 'ajaxlist',
		no_html: '1',
		cityid: document.vpb_filter.cityid.value,
		subcatid: document.vpb_filter.subcatid.value,
		distancetocenter: distance
	})}).request();
}