function chk_select(t) {
    var Country = document.getElementById(t);
    var url = 'ajax/localizza_appt.php';
    var pars = 'action='+t+'&p='+ Country.value + '&rnd='+Math.random();
    var netAjax = new Ajax.Request( url, { method: 'get', parameters: pars, asynchronous: false, onComplete: evalResponse });
}

function evalResponse(originalRequest) {
    eval(originalRequest.responseText);
}

function hideAlert(t) {
	document.getElementById(t).style.display = 'none';
}

function chkAptForm() {
	var chk = true;
	if(document.getElementById('Country').value == 0) {
		document.getElementById('CountryAlert').style.display = 'block';
		chk = false;
	}
	if(document.getElementById('Region').value == 0) {
		document.getElementById('RegionAlert').style.display = 'block';
		chk = false;
	}
	if(document.getElementById('City').value == 0) {
		document.getElementById('CityAlert').style.display = 'block';
		chk = false;
	}
	if(chk)
		return true;
	else
		return false;
}

function go_other(l, c, r, o) {
    var url = "http://www.voiaganto."+l+"/"+c+"/"+r+"/"+o;
    location.href = url;
}

function gotop(){
    var L1 = document.findtop.vgsData.value;
    L1 = L1.toLowerCase();
    //var L2 = document.findtop.vgsDest.value;

    var cdx = {'à':'a','á':'a','ù':'u','ú':'u','ü':'u','ò':'o','Ó':'O','ó':'o','è':'e','é':'e','ì':'i','í':'i','ñ':'n'};

    for (j in cdx) {
        var re = new RegExp(j, "g");
        L1=L1.replace(re, cdx[j]);
    }

    var re = /\'/g;
    L1=L1.replace(re, "_");

    var re = /[^a-z0-9-_\s]+/g;
    L1=L1.replace(re, "");  
    var re = /\s+/g;
    L1=L1.replace(re, "_");  
    var re = /_$/;
    L1=L1.replace(re, "");
    var re = /^_/;
    L1=L1.replace(re, "");
    //var url = "http://www.voiaganto.it/finder/" + L1 +"-find"+ L2 + ".html";
    var url = "http://www.voiaganto.it/finder/" + L1 +"-find.html";
    location.href = url;
}

function new_gotop(){
    var L1 = document.findtop.submit();
}

function gofoot(){
    var L1 = document.findfoot.vgsData.value;
    L1 = L1.toLowerCase();

    //var L2 = document.findfoot.vgsDest.value;
    var cdx = {'à':'a','á':'a','ù':'u','ú':'u','ü':'u','ò':'o','Ó':'O','ó':'o','è':'e','é':'e','ì':'i','í':'i','ñ':'n'};

    for (j in cdx) {
        var re = new RegExp(j, "g");
        L1=L1.replace(re, cdx[j]);
    }

    var re = /\'/g;
    L1=L1.replace(re, "_");

    var re = /[^a-z0-9-_\s]+/g;
    L1=L1.replace(re, "");
    var re = /\s+/g;
    L1=L1.replace(re, "_");
    var re = /_$/;
    L1=L1.replace(re, "");
    var re = /^_/;
    L1=L1.replace(re, "");

    var url = "http://www.voiaganto.it/finder/" + L1 +"-find.html";
    location.href = url;
}


function test() {
    if (document.getElementById('pageGreat') && document.getElementById('mainRightBox')) {
        var myHead = document.getElementById('pageGreat');
        var myBody = document.getElementById('mainRightBox');
        myBody.appendChild(myHead);
    }
}

function test1() {
    if (document.getElementById('firstBanner') && document.getElementById('mainTopBanner')) {
        var myHead1 = document.getElementById('firstBanner');
        var myBody1 = document.getElementById('mainTopBanner');
        myBody1.appendChild(myHead1);
    }
}


function test2() {
    if (document.getElementById('secondBanner') && document.getElementById('mainColBanner')) {
        var myHead2 = document.getElementById('secondBanner');
        var myBody2 = document.getElementById('mainColBanner');
        myBody2.appendChild(myHead2);
    }
}


function sj_addEvent(elm, evType, fn, useCapture) {
    if (elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    } else if (elm.attachEvent) {
        var r = elm.attachEvent("on"+evType, fn);
        return r;
    }
}

function startList() {
    if (document.all&&document.getElementById) {
        if (navRoot = document.getElementById("graphicMenu40")) {
            for (i=0; i<navRoot.childNodes.length; i++) {
                node = navRoot.childNodes[i];
                if (node.nodeName=="LI") {
                    node.onmouseover=function() {
                        this.className+=" over";
                    }
                    node.onmouseout=function() {
                        this.className=this.className.replace(" over", "");
                    }
                }
            }
        }
    }
}

function startList2() {
    if (document.all&&document.getElementById) {
        if (navRoot = document.getElementById("graphicMenu48")) {
            for (i=0; i<navRoot.childNodes.length; i++) {
                node = navRoot.childNodes[i];
                if (node.nodeName=="LI") {
                    node.onmouseover=function() {
                        this.className+=" over";
                    }
                    node.onmouseout=function() {
                        this.className=this.className.replace(" over", "");
                    }
                }
            }
        }
    }
}

function populateSWF(swf,geoid,nome_div,width,height){
	if (geoid == "6")
		height = "320";

    var shtml = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"";
    shtml += " codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\"";
    shtml += "  width=\""+width+"\" height=\""+height+"\" id=\"mapps\" align=\"middle\">";
    shtml += " <param name=movie value=\"/maps/" + swf + ".swf?filexml=/xml.php?cont=" + geoid + "\">";
    shtml += " <param name=quality value=high>";
    shtml += " <param name=\"wmode\" value=\"transparent\">";
    shtml += " <param name=bgcolor value=#FFFFFF>";
    shtml += " <embed src=\"/maps/" + swf + ".swf?filexml=/xml.php?cont=" + geoid + "\" quality=high bgcolor=#FFFFFF width=\""+width+"\" height=\""+height+"\" name=\"Mappa\" align=\"middle\"";
    shtml += "  type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" WMODE=\"transparent\"></embed>";
    shtml += "     </object>"

    var md = document;
    var d = md.getElementById(nome_div);
    d.innerHTML = shtml;

}



    function BannerClass(advBox) {
    
        this.rdm = 0;
        this.yOffset = 0;
        this.xOffset = 0;
        this.advContainer = null;
        this.showBanner   = showBanner;
        this.reloadBanner = reloadBanner;
        
        if (document.getElementById(advBox)) {

            this.advContainer = document.getElementById(advBox);
            this.xOffset      = this.advContainer.offsetLeft;
            this.yOffset      = this.advContainer.offsetTop;
            this.nextOffset   = this.advContainer.offsetParent;
            this.rdm = new String (Math.random()); 
            this.rdm = this.rdm.substring(2,11);

            while (this.nextOffset != null) {
                this.xOffset   += this.nextOffset.offsetLeft;
                this.yOffset   += this.nextOffset.offsetTop;
                this.nextOffset = this.nextOffset.offsetParent;
            }
        } else {
            this.advContainer = null;
            alert("ATTENZIONE!\nBOX " + advBox + " NON DEFINITO!")
        }

        function reloadBanner(advBox) {
            if (document.getElementById(advBox)) {
                var myDiv = document.getElementById(advBox);
                myDiv.style.top  = this.yOffset + 'px';
                myDiv.style.left = this.xOffset + 'px';
            }
        }

        function showBanner(pos, random1) {

            if (this.advContainer != null) {
                switch (pos) {
                    case 'tHome':
                        document.write('<div id="tHome" style="width: 100%;text-align: center;position: absolute;top: ' + this.yOffset + 'px;left:0px;">');
                        document.write('<scr'+'ipt language="JavaScript" src="http://ad.it.doubleclick.net/adj/3696.voiaganto.it/hp-728x90;dcopt=ist;' + window.wlrcmd + (window.wlrcmd!=''?';':'') + 'sz=728x90;tile=1;ord=' + random1 +""+ rnd + '?" type="text/javascript"></scr'+'ipt>');
                        //document.write('<di' + 'v>');
                        break;
                    case 'rHome':
                        document.write('<div id="rHome" style="width: 300;text-align: center;position: absolute;top: ' + this.yOffset + 'px;left: ' + this.xOffset + 'px;" >');
                        document.write('<scr'+'ipt language="JavaScript" src="http://ad.it.doubleclick.net/adj/3696.voiaganto.it/hp-300x250;' + window.wlrcmd + (window.wlrcmd!=''?';':'') + ';sz=300x250;tile=1;ord=' + random + this.rdm + '" type="text/javascript"></scr'+'ipt>');
                        //document.write('</div>');
                        break;
                }
            }
        }
    }


    function moveBanner() {
        var RBX = new BannerClass('rightBanner'); 
        RBX.reloadBanner('rHome');     
    }


function submitFormMappa() {
    document.form_mappa_opz.submit();
}


sj_addEvent(window, 'load', test);
sj_addEvent(window, 'load', test1);
sj_addEvent(window, 'load', test2);
sj_addEvent(window, 'load', startList);
sj_addEvent(window, 'load', startList2);


function highlightText( testo, ricerca, startTag, endTag) {
  if ((!startTag) || (!endTag)) {
    startTag = "<font style='background-color:yellow;'>";
    endTag = "</font>";
  }
  var newText = "";
  var i = -1;
  var lcSearchTerm = ricerca.toLowerCase();
  var lcBodyText = testo.toLowerCase();
    
  while (testo.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += testo;
      testo = "";
    } else {
      // skip anything inside an HTML tag
      if (testo.lastIndexOf(">", i) >= testo.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += testo.substring(0, i) + startTag + testo.substr(i, ricerca.length) + endTag;
          testo = testo.substr(i + ricerca.length);
          lcBodyText = testo.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}

