function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
        output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function changeLanguage(lang)
{
    var cl = location.href;
    window.location = '/changeLanguage.php?lang=' + lang + '&referer=' + URLEncode(cl);
}


function changecss(theClass,element,value)
{
    var cssRules;

    if (document.all)
    {
        cssRules = 'rules';
    }
    else if (document.getElementById)
    {
        cssRules = 'cssRules';
    }

    for (var S = 0; S < document.styleSheets.length; S++)
    {
        for (var R = 0; R < document.styleSheets[S][cssRules].length; R++)
        {
            if (document.styleSheets[S][cssRules][R].selectorText == theClass)
            {
                document.styleSheets[S][cssRules][R].style[element] = value;
            }
        }
    }
}

function bodyInit()
{
    if (navigator.appVersion.indexOf("Win")!=-1)
    {
    }

    if (navigator.appVersion.indexOf("Mac")!=-1)
    {
    }

    if (navigator.appVersion.indexOf("X11")!=-1 || navigator.appVersion.indexOf("Linux")!=-1)
    {
        changecss(".menuVerticale .entries div", "fontSize", "17px");
    }

    var selTi = document.getElementById('selectTipologia');
    if (selTi != null)
    {
        document.getElementById('divSelect' + selTi.value).style.display = 'inline';
    }

    mostraPrezzoSelezionato();
}

function changeTipologia(val)
{
    document.getElementById('divSelectVI').style.display = 'none';
    document.getElementById('divSelectVG').style.display = 'none';
    document.getElementById('divSelectVN').style.display = 'none';
    document.getElementById('divSelect' + val).style.display = 'inline';
    mostraPrezzoSelezionato();
}

function mostraPrezzoSelezionato()
{
    var langStr = new Array();
    langStr['IT'] = new Array('Quota individuale di partecipazione', 'Quota individuale di partecipazione Superior', 'Supplemento camera singola', 'Stagionalit&agrave;', '<a href="mailto:info@fulviatour.com" style="color: #333">Richiedi il tuo preventivo a Fulvia Tour, clicca qui</a>!', '<a href="mailto:info@fulviatour.com" style="color: #333">Richiedi la disponibilit&agrave; a Fulvia Tour, clicca qui</a>!');
    langStr['EN'] = new Array('Individual price', 'Individual price Superior Tour', 'Single room surcharge', 'Season', '<a href="mailto:info@fulviatour.com" style="color: #333">Ask Fulvia Tour for your estimation, click here</a>!', '<a href="mailto:info@fulviatour.com" style="color: #333">Ask Fulvia Tour for the availability, click here</a>!');
    langStr['DE'] = new Array('Preis pro Person', 'Preis pro Person Superior Tour', 'Einzelzimmerzuschlag', 'Jahreszeiten', '<a href="mailto:info@fulviatour.com" style="color: #333">Ask Fulvia Tour for your estimation, click here</a>!', '<a href="mailto:info@fulviatour.com" style="color: #333">Ask Fulvia Tour for the availability, click here</a>!');
    var selTi = document.getElementById('selectTipologia');
    if (selTi != null)
    {
        if (isAgenzia)
        {
                switch (selTi.value)
                {
                    case 'VI':
                        {
                            var idSel = document.getElementById('selectVINumero').value;
                            var tagContent = document.getElementById('contenitorePrezzo');
        tagContent.innerHTML = "<strong style='color: #444; font-size: 11px'>" + langStr[linguaSelezionata][0] + ": &euro; " + listinoDatiVI[idSel][2] + "<br/>" + langStr[linguaSelezionata][1] + ": &euro; " + listinoDatiVI[idSel][3] + "<br/><br/>" + langStr[linguaSelezionata][2] + ": &euro; "+listinoDatiVI[idSel][4]+"</strong><br/>" + langStr[linguaSelezionata][5];
                        }
                        break;
                    case 'VG':
                        {
                            var idSel = document.getElementById('selectVGNumero').value;
                            var tagContent = document.getElementById('contenitorePrezzo');
        tagContent.innerHTML = "<strong style='color: #444; font-size: 11px'>" + langStr[linguaSelezionata][0] + ": &euro; " + listinoDatiVG[idSel][2] + "<br/>" + langStr[linguaSelezionata][1] + ": &euro; " + listinoDatiVG[idSel][3] + "<br/><br/>" + langStr[linguaSelezionata][2] + ": &euro; "+listinoDatiVG[idSel][4]+"</strong><br/>" + langStr[linguaSelezionata][4];
                        }
                        break;
                    case 'VN':
                        {
                            var idSel = document.getElementById('selectVNDataPartenza').value;
                            var tagContent = document.getElementById('contenitorePrezzo');
        tagContent.innerHTML = "<strong style='color: #444; font-size: 11px'>" + langStr[linguaSelezionata][3] + ": " + listinoDatiVN[idSel][0] + "<br/>" + langStr[linguaSelezionata][0] + ": &euro; " + listinoDatiVN[idSel][2] + "<br/><br/>" + langStr[linguaSelezionata][2] + ": &euro; "+listinoDatiVN[idSel][3]+"</strong><br/>" + langStr[linguaSelezionata][5];
                        }
                        break;
                }
        }
        else
        {
                switch (selTi.value)
                {
                    case 'VI':
                        {
                            var idSel = document.getElementById('selectVINumero').value;
                            var tagContent = document.getElementById('contenitorePrezzo');
        tagContent.innerHTML = "<strong style='color: #444; font-size: 11px'>" + langStr[linguaSelezionata][0] + ": &euro; " + listinoDatiVI[idSel][0] + "<br/>" + langStr[linguaSelezionata][1] + ": &euro; " + listinoDatiVI[idSel][1] + "<br/><br/>" + langStr[linguaSelezionata][2] + ": &euro; "+listinoDatiVI[idSel][4]+"</strong><br/>" + langStr[linguaSelezionata][5];
                        }
                        break;
                    case 'VG':
                        {
                            var idSel = document.getElementById('selectVGNumero').value;
                            var tagContent = document.getElementById('contenitorePrezzo');
        tagContent.innerHTML = "<strong style='color: #444; font-size: 11px'>" + langStr[linguaSelezionata][0] + ": &euro; " + listinoDatiVG[idSel][0] + "<br/>" + langStr[linguaSelezionata][1] + ": &euro; " + listinoDatiVG[idSel][1] + "<br/><br/>" + langStr[linguaSelezionata][2] + ": &euro; "+listinoDatiVG[idSel][4]+"</strong><br/>" + langStr[linguaSelezionata][4];
                        }
                        break;
                    case 'VN':
                        {
                            var idSel = document.getElementById('selectVNDataPartenza').value;
                            var tagContent = document.getElementById('contenitorePrezzo');
        tagContent.innerHTML = "<strong style='color: #444; font-size: 11px'>" + langStr[linguaSelezionata][3] + ": " + listinoDatiVN[idSel][0] + "<br/>" + langStr[linguaSelezionata][0] + ": &euro; " + listinoDatiVN[idSel][1] + "<br/><br/>" + langStr[linguaSelezionata][2] + ": &euro; "+listinoDatiVN[idSel][3]+"</strong><br/>" + langStr[linguaSelezionata][5];
                        }
                        break;
                }
        }
    }
}
