﻿function prendiElementoDaId(id_elemento) {
    var elemento;
    if (document.getElementById)
        elemento = document.getElementById(id_elemento);
    else
        elemento = document.all[id_elemento];
    return elemento;
}

function indicazioni(lingua) {
    window.open("http://maps.google.it/maps?saddr=" + prendiElementoDaId('partenza').value.replace(/ /gi, "+") + "&daddr=" + prendiElementoDaId('destinazione').value.replace(/ /gi, "+") + "&hl="+lingua+"&tab=wl");
}

function resetta() {
    prendiElementoDaId('partenza').value='';
    prendiElementoDaId('destinazione').value='';
}

function KeyCheck(ev) {

    var key;
    ev = ev || event;
    key = ev.keyCode;

    if (key == 13) {

        indicazioni();

    }
}

function richiesta(lingua) {

    prendiElementoDaId('but_invio').disabled = true;
    prendiElementoDaId('caricamento').style.visibility = "visible";

    var ragione_sociale = prendiElementoDaId('ragione_sociale').value;
    var indirizzo = prendiElementoDaId('indirizzo').value;
    var cap = prendiElementoDaId('cap').value;
    var email = prendiElementoDaId('email').value;
    var telefono = prendiElementoDaId('telefono').value;
    var contatto = prendiElementoDaId('contatto').value;
    var cappartenza = prendiElementoDaId('cappartenza').value;
    var partenza = prendiElementoDaId('partenza1').value;
    var capdestinazione = prendiElementoDaId('capdestinazione').value;
    var destinazione = prendiElementoDaId('destinazione1').value;
    var tipologia = prendiElementoDaId('tipologia').value;
    var colli = prendiElementoDaId('colli').value;
    var kg = prendiElementoDaId('kg').value;
    var tipocolli = prendiElementoDaId('tipocolli').options[parseInt(prendiElementoDaId('tipocolli').selectedIndex)].value;
    var note = prendiElementoDaId('note').value;



    $("#invia_richiesta").load("invia_richiesta.aspx", { lang: lingua, ragione_sociale: ragione_sociale, indirizzo: indirizzo, cap: cap,
        email: email, telefono: telefono, contatto: contatto, cappartenza: cappartenza, partenza: partenza,
        capdestinazione: capdestinazione, destinazione: destinazione, tipologia: tipologia, colli: colli,
        kg: kg, tipocolli: tipocolli, note: note
    }, function () { });

}

function stampa_data_ITA() {

    var data_att = new Date();
    var ora = data_att.getHours();
    var minuti = data_att.getMinutes();
    var secondi = data_att.getSeconds();
    var giorno = data_att.getDay();
    var mese = data_att.getMonth();
    var date = data_att.getDate();
    var year = data_att.getYear();
    if (minuti < 10) minuti = "0" + minuti;
    if (secondi < 10) secondi = "0" + secondi;
    if (year < 1900) year = year + 1900;
    if (ora < 10) ora = "0" + ora;
    if (giorno == 0) giorno = "Domenica";
    if (giorno == 1) giorno = "Lunedì";
    if (giorno == 2) giorno = "Martedì";
    if (giorno == 3) giorno = "Mercoledì";
    if (giorno == 4) giorno = "Giovedì";
    if (giorno == 5) giorno = "Venerdì";
    if (giorno == 6) giorno = "Sabato";
    if (mese == 0) mese = "Gennaio";
    if (mese == 1) mese = "Febbraio";
    if (mese == 2) mese = "Marzo";
    if (mese == 3) mese = "Aprile";
    if (mese == 4) mese = "Maggio";
    if (mese == 5) mese = "Giugno";
    if (mese == 6) mese = "Luglio";
    if (mese == 7) mese = "Agosto";
    if (mese == 8) mese = "Settembre";
    if (mese == 9) mese = "Ottobre";
    if (mese == 10) mese = "Novembre";
    if (mese == 11) mese = "Dicembre";

    prendiElementoDaId("ora").innerHTML = ora + ":" + minuti;
    prendiElementoDaId("data").innerHTML = giorno + " " + date + " " + mese;

    setTimeout("stampa_data_ITA()", 5000);
}

function stampa_data_ENG() {

    var data_att = new Date();
    var ora = data_att.getHours();
    var minuti = data_att.getMinutes();
    var secondi = data_att.getSeconds();
    var giorno = data_att.getDay();
    var mese = data_att.getMonth();
    var date = data_att.getDate();
    var year = data_att.getYear();
    var simbolo = "";

    if(date=='1' || date=='21')
    {
        date=date+"st";
        }
     else  if(date=='2' || date=='22'){
         date=date+"nd";
         }
     else if (date == '3' || date == '23') {
         date = date + "rd";
         } 
          else {
              date = date + "th";
         } 

    if (minuti < 10) minuti = "0" + minuti;
    if (secondi < 10) secondi = "0" + secondi;
    if (year < 1900) year = year + 1900;
    if (ora < 10) ora = "0" + ora;
    if (giorno == 0) giorno = "Sunday";
    if (giorno == 1) giorno = "Monday";
    if (giorno == 2) giorno = "Tuesday";
    if (giorno == 3) giorno = "Wednesday";
    if (giorno == 4) giorno = "Thursday";
    if (giorno == 5) giorno = "Friday";
    if (giorno == 6) giorno = "Saturday";
    if (mese == 0) mese = "January";
    if (mese == 1) mese = "Febraury";
    if (mese == 2) mese = "March";
    if (mese == 3) mese = "April";
    if (mese == 4) mese = "May";
    if (mese == 5) mese = "June";
    if (mese == 6) mese = "July";
    if (mese == 7) mese = "August";
    if (mese == 8) mese = "September";
    if (mese == 9) mese = "October";
    if (mese == 10) mese = "November";
    if (mese == 11) mese = "December";

    if(ora=='00'){
        ora='12';
        simbolo='am';
        }
    else if (parseInt(ora) > 0 && parseInt(ora) < 12) {
        simbolo='am';
        }
    else if (ora == '12') {
        simbolo='pm';
        }
    else if (parseInt(ora) > 12) {
        ora = String(parseInt(ora) - 12);
        if (parseInt(ora) < 10) {
            ora = '0' + ora;
            }
        simbolo='pm';
        }

    prendiElementoDaId("ora").innerHTML = ora + ":" + minuti +" "+simbolo;
    prendiElementoDaId("data").innerHTML = giorno + ", " + date + " " + mese;

    setTimeout("stampa_data_ENG()", 5000);
} 
