
var RecaptchaOptions = {
    theme : 'white',
    lang : 'it'

 };


function menu_toggleInizio(elementID) {
	aperto = elementID;
	menu_toggle(elementID);
}

function menu_toggle(elementID){
	if(elementID) {
		for (var i = 1; i <= num_elementi_menu; i++) {
		var tg = document.getElementById('submenu_'+i).style
		tg.display = 'none'
		}
		var target1 = document.getElementById(elementID)
		if (target1.style.display == 'none') {
			target1.style.display = 'block'
		} else {
			target1.style.display = 'none'
		}
	}
}

function menu_restoreMenu(elementID) {
	for (var i = 1; i <= num_elementi_menu; i++) {
		var tg = document.getElementById('submenu_'+i).style
		if(tg!=aperto) {
			tg.display = 'none';
		}
	}
	if(aperto==0) {
		menu_toggle (elementID);
	}
	else  {
		menu_toggle (aperto);
	}
}

function menu_restore(elementID){
	if(elementID!=aperto) {
		if(ripristino!=0) {
			window.clearTimeout(ripristino);
		}
		ripristino = window.setTimeout("menu_restoreMenu('"+elementID+"')",3000);
	}
}

function menu_restoreEnter(elementID){
	if(elementID!=aperto) {
		if(ripristino!=0) {
			window.clearTimeout(ripristino);
		}
		menu_restoreMenu (elementID)
	}
}

function toggle1(elementID){
	var attivo = elementID.substr(elementID.length-1, 1)
//	alert(attivo)

	for (var i = 1; i <= 4; i++) {
		var tg = document.getElementById('contenuto'+i).style;
		tg.display = 'none';

		var NomeLabel = 'label'+i
		document.getElementById(NomeLabel).src="imgs/base/label_"+i+"_off.gif";
	}

	var LabelDaCambiare = document.getElementById('label'+attivo)
	LabelDaCambiare.src = "imgs/base/label_"+attivo+"_on.gif";

var target1 = document.getElementById(elementID)
if (target1.style.display == 'none') {
	target1.style.display = 'block'
	} else {
	target1.style.display = 'none'
	}
}

function apriPopUp(url,stampa,lar,alt,nome) {
	if(stampa) {
		larghPopUp = larghPopUpStampa;
		altPopUp   = altPopUpBase;
	}
	else {
		larghPopUp = larghPopUpBase;
		altPopUp   = altPopUpBase;
	}
	if(alt) {
		altPopUp = alt;
	}
	if(lar) {
		larghPopUp = lar;
	}
        if(nome==undefined) {
            nome = 'velanet_popup';
        }
	finestra= window.open(url,nome,'width='+larghPopUp+',height='+altPopUp+',status=yes,titlebar=no,menubar=yes,hotkeys=no,scrollbars=yes,resizable=yes');
}

function valida_invio_newsletter() {
    if(!verificaEmail($('realname').value)) {
        alert("Inserisci un indirizzo email valido");
        return false;
    }
    else {
        return true;
    }
}

function verificaEmail(testo) {
	var chiocciola="@";
	var punto=".";
	var lch=testo.indexOf(chiocciola);
	var lstr=testo.length;
	var lpunto=testo.indexOf(punto);
	if (lch==-1){
		return false;
	}
	if (lch<2 || lch==lstr){
		return false;
	}
	if (lpunto <1  || lpunto==lstr){
	    return false;
	}
	if (testo.indexOf(chiocciola,(lch+1))!=-1){
	    return false;
 	}
	if (testo.substring(lch-1,lch)==punto || testo.substring(lch+1,lch+2)==punto){
	    return false;
 	}
	if (testo.indexOf(punto,(lch+2))==-1){
	    return false;
	}
	if (testo.indexOf(" ")!=-1){
    	return false;
	}
	return true;
}

function controllaLuogo() {
	errori = 0
	messaggio = "";
	if(document.getElementById("tipo") && document.getElementById("tipo").selectedIndex==0) {
        errori +=1;
        messaggio += "Non è stato indicato il tipo di luogo\n";
	}
	if(errori>0)
		alert(messaggio);
	else {
        document.getElementById("velanet").style.cursor="wait";
        mostraProgress();
        document.getElementById("luogo").submit();
    }
}

function segnalaPorto(campo) {
	if(campo) {
		agg='?campo='+campo;
	}
	else {
		agg='';
	}
    apriPopUp('/lib/segnalaPorto.php'+agg,true);
}

function invioSegnalaPorto(campo) {
	errori = 0
	messaggio = "";
	if(document.getElementById("porti_luoghi_1") && !verificaElemento('porti_','luoghi')) {
		errori +=1;
		messaggio += "Non è stato indicato il mare di appartenenza\n";
	}
	if(document.getElementById("nazione").value.length==0) {
		errori +=1;
		messaggio += "Non è stata inserita la nazione\n";
	}
	if(document.getElementById("regione").value.length==0) {
		errori +=1;
		messaggio += "Non è stata inserita la regione\n";
	}
	if(document.getElementById("porto").value.length==0) {
		errori +=1;
		messaggio += "Non è stata inserito il porto\n";
	}
	if(document.getElementById("campo").value.length>0) {
            campo = document.getElementById("campo").value;
        }
        if(campo!=undefined) {
		if(window.opener.document.getElementById(campo+"_luoghi_1").selectedIndex==0) {
			window.opener.document.getElementById(campo+"_luoghi_1").selectedIndex = document.getElementById("porti_luoghi_1").selectedIndex;
		}
		window.opener.document.getElementById(campo+'_testo').value=document.getElementById("porto").value;
		window.opener.document.getElementById(campo+'_label').innerHTML=document.getElementById("porto").value;
	}
	if(window.opener.document.getElementById('segnalazione')) {
		window.opener.document.getElementById('segnalazione').value = 1;
	}
	if(errori>0)
		alert(messaggio);
	else {
        mostraProgress();
		document.getElementById("segnalaporto").submit();
    }
}

//Uso standard : onkeypress="controllaMaxCaratteri(this,180);"
function controllaMaxCaratteri(elemento,numax) {
    stringa = elemento.value;
    if (document.getElementById('caratteriusati')) {
        document.getElementById('caratteriusati').innerHTML = stringa.length;
    }
    if(stringa.length>(numax-1)) {
        errore="Il testo contenuto nel campo \'"+elemento.name+"\' e' troppo lungo.\nIl numero massimo di caratteri per il campo e' "+numax+"; hai inserito "+(stringa.length+2)+" caratteri";
        alert(errore);
        elemento.value = stringa.substr(0,numax-2);
    }
}

function img(url) {
	finestra= window.open('/lib/img.php?url='+url,'velanet_popup','width='+larghPopUpBase+',height='+altPopUpBase+',status=yes,titlebar=no,menubar=yes,hotkeys=no,scrollbars=yes,resizable=yes');
}

function dimRicerca() {
	tab = document.getElementById('frame');
	tab.height = window.innerHeight - 270;
	tab.contentDocument.base.target="_top";
	self.document.base.target="_top";
}

function apriTab(num,sub) {
    totale = getElementsByTagAndClassName('div', 'contenutoTab').length;
    if(totale>0) {
        //log("totale "+totale)
        if(!sub) {
            sub = 1;
        }
        apriSubTab(num,sub);
        addElementClass('tab'+num,'attivo');
        showElement('area'+num);
        mappaCentra();
        for(k=1;k<=totale;k++) {
            log('nascondi '+k+'-'+totale);
            if(k!=num) {
                if($('tab'+k)) {
                    hideElement('area'+k);
                    removeElementClass('tab'+k,'attivo');
                }
            }
        }
        ScrollTo('tab'+num);

    }
}
function apriSubTab(genitore,elemento) {
    log("sub area"+genitore);
    totSub = 10;
    a = getElementsByTagAndClassName('div', 'contenutoSubTab','area'+genitore).length;
    log('nascondi '+genitore+'_'+elemento+'-'+totSub);
    if(totSub>0 ) {
        el = $('areaSub'+genitore+''+elemento);
        /*log('areaSub'+genitore+''+elemento);
        log(el);*/
        while(!el) {
            if(elemento>totSub) {
                return;
            }
            elemento++;
            el = $('areaSub'+genitore+''+elemento);
            /*log('areaSub'+genitore+''+elemento);*/
        }
        /*log('apri ' +'areaSub'+genitore+''+elemento)*/
        e = getElement('areaSub'+genitore+''+elemento);
        if(e) {
            showElement('areaSub'+genitore+''+elemento);
            addElementClass('subTab'+genitore+''+elemento,'attivoSub');
            for(s=1;s<=totSub;s++) {
                if(s!=elemento) {
                    hideElement('areaSub'+genitore+''+s);
                    if($('subTab'+genitore+''+s) && hasElementClass('subTab'+genitore+''+s,'attivoSub')) {
                        removeElementClass('subTab'+genitore+''+s,'attivoSub');
                    }
                }
            }
        }
    }
}

function aggiornaOrigine() {
    if(self.opener) {
        self.opener.document.location.href =self.opener.document.location.href;
    }
}


//
//  Configurationl
//
if(Object.extend) {
    LightboxOptions = Object.extend({
        fileLoadingImage:        '/imgs/lightbox/loading.gif',
        fileBottomNavCloseImage: '/imgs/chiudi.gif',

        overlayOpacity: 0.8,   // controls transparency of shadow overlay

        animate: true,         // toggles resizing animations
        resizeSpeed: 7,        // controls the speed of the image resizing animations (1=slowest and 10=fastest)

        borderSize: 10,         //if you adjust the padding in the CSS, you will need to update this variable

        // When grouping images this is used to write: Image # of #.
        // Change it for non-english localization
        labelImage: "Immagine",
        labelOf: "su"
    }, window.LightboxOptions || {});
}

function ricercaLink(sezione) {
    if(sezione=='it') {
        $('categoria_www').selectedIndex = 0;
    }
    if(sezione=='www') {
        $('categoria_it').selectedIndex = 0;
    }
    $('formlink').submit()
}

function aggiornaGenitore() {
    self.opener.document.location.href = self.opener.document.location.href;
}

function mostraBlocchi(sel) {
    //sel = $('ricerca').options[$('ricerca').selectedIndex].value;
    $('selezionato').value = sel;
    f = getElementsByTagAndClassName("*","blocco_velaitalia") ;
    for(k=0;k<f.length;k++){
        if(f[k].id=="ricerca_"+sel) {
            showElement(f[k]);
        }
        else {
            hideElement(f[k]);
        }
    }
    f = getElementsByTagAndClassName("*","elemento_menu") ;
    for(k=0;k<f.length;k++){
        if(f[k].id==sel) {
            setStyle(f[k],{"border-right":"none"})
            addElementClass(f[k],"sfondo_"+sel);
        }
        else {
            setStyle(f[k],{"border-right":"1px solid grey"})
            removeElementClass(f[k],"sfondo_"+f[k].id);
        }
    }
    showElement('bottone_cerca_velaitalia');
}

function rounded_velaitalia_1() {
    Rounded('elemento_menu', 10, 10);//, 5, 0)
}
function nc_velaitalia_1() {
    f = getElementsByTagAndClassName("*","elemento_menu") ;
    s = "li#"+f[0].id;
    for(k=1;k<f.length;k++) {
        //log("li#"+f[k].id);
        s +=",li#"+f[k].id;
    }
    Nifty(s,"left normal");
    s = "div#generale";
    for(k=0;k<f.length;k++) {
        s +=",div#ricerca_"+f[k].id;
    }
    Nifty(s,"right big");
}
function cc_velaitalia_1() {
    var settings = {
       tl: { radius: 5 },
       tr: { radius: 0 },
       bl: { radius: 5 },
       br: { radius: 0 },
       antiAlias: true
     }
    f = getElementsByTagAndClassName("*","elemento_menu") ;
    for(k=0;k<f.length;k++) {
        curvyCorners(settings, $(f[k].id));
    }
}

function cc_velaitalia_blocco(elem) {
    var settings = {
       tl: { radius: 0 },
       tr: { radius: 5 },
       bl: { radius: 0 },
       br: { radius: 5 },
       antiAlias: true
     }
    curvyCorners(settings, $(elem));
}

function ricercaMultipla() {
    //sel = $('ricerca').options[$('ricerca').selectedIndex].value;
    sel = $('selezionato').value;
    f = getElementsByTagAndClassName("*","blocco_velaitalia") ;
    if(sel=='operatori') {
        $('ricerca_multipla').action="/link/index.php";
    }
    else if(sel=='noleggio') {
        $('ricerca_multipla').action="/noleggio/ricerca.php/noleggio_1/aziende_1";
    }
    else if(sel=='imbarchi') {
        $('ricerca_multipla').action="/crociere/index.php";
    }
    else if(sel=='corsi') {
        $('ricerca_multipla').action="/corsi/index.php";
    }
    else if(sel=='usate') {
        $('ricerca_multipla').action="/boatonsale/ricerca.php/usate_1/aziende_1";
    }
    else if(sel=='nuove') {
        $('ricerca_multipla').action="/boatonsale/ricerca.php/nuove_1/aziende_1";
    }
    else if(sel=='prodotti') {
        $('ricerca_multipla').action="/operatori/prodotti.php";
    }
    else {
        alert("E' necessario selezionare un'area di ricerca")
        return;
    }

    for(k=0;k<f.length;k++){
        if(f[k].id!="ricerca_"+sel) {
           removeElement(f[k]);
        }
    }
    $('ricerca_multipla').submit();
}


function gt(url,lingua) {
    base='http://translate.googleusercontent.com/translate_c?hl=en&sl=it&tl='+lingua+'&u=';
    if(parent.frames[0]) {
        fin=parent.frames[0];
    }
    else {
        fin=window;
    }
    fin=window;
    if(lingua=='it') {
        top.location = url;
    }
    else {
        top.location = base+url;
    }
}
function mostraProgress() {
	d = getViewportDimensions();
    v = getViewportPosition();
	e = {"w":getStyle($('progress'),'width').replace("px",""),"h":getStyle($('progress'),'height').replace("px","")};
	setElementPosition('progress', {"x":(d.w-e.w)/2,"y":v.y+(d.h-e.h)/2});
	showElement('progress');

}
