﻿function CopyToClipBoard() {
    var oIP = document.getElementById('ilMioIP');  //$get('hIP');   
    window.clipboardData.setData("Text", oIP.value);
}

function invia() {

    var iButton = document.getElementById('iButton').value;
    switch (parseInt(iButton)) {
        case 1:
        case 2:
            SendMail(iButton);
            break;
        case 3:
            var sParSuggerimento = document.getElementById('TestoSuggerimento').value + '|' + document.getElementById('Firma').value + '|' + IP_CLIENT;
            query(iButton, sParSuggerimento, document.getElementById('InviaDiv'));
            break;
        default:
            alert('sono in default' + iButton);
    }
}


function SendMail(index) {
    var sParEmail;
    switch (parseInt(index)) {
        case 8:
            sParEmail = 'info@ilmioip.it|' + document.getElementById('ToEmail').value + '|ND|ND|ilMioIp.it|www.ilmioip.it - Procedura Ripristino PassWord|ND_TESTO_ND|www.ilmioip.it|ND'
            break;
        case 9:
            sParEmail = 'info@ilmioip.it|' + document.getElementById("email1").value + '|ND|ND|ilMioIp.it|www.ilmioip.it - Clicca per COMPLETARE la registrazione|ND_TESTO_ND|www.ilmioip.it|ND|' + document.getElementById("Pass1").value + '|' + document.getElementById("nome").value + '|' + document.getElementById("cognome").value;
            //alert(sParEmail);
            break;    
        default:
            sParEmail = document.getElementById('FromEmail').value + '|' + document.getElementById('ToEmail').value + '|' + document.getElementById('CcEmail').value + '|ND|ilMioIp.it|' + document.getElementById('OggettoEmail').value + '|' + document.getElementById('Testo').innerHTML + '|' + document.getElementById('Firma').value + '|ND';
            break;
    }
    var oInviaDiv = document.getElementById('InviaDiv');
    //alert(oInviaDiv.innerHTML);
    query(index, sParEmail, oInviaDiv);
}


function SelectIP(oIPAddress) {
    //document.getElementById('InfoCopy').style.display = 'none';
    //oIPDiv.style.display='none';
    //var oIPAddress = document.getElementById('IPADDRESS');sendMail
    //oIPAddress.style.display='block';
    var text_val = eval("oIPAddress");
    text_val.focus();
    text_val.select();
}


function setFOcus(oIPDiv) {
    var text_val = eval("oIPDiv");
    text_val.focus();
    text_val.select();
}
function TBoxToPic(oIP) {

    document.getElementById('InfoCopy').style.display = 'block';
    oIP.style.display = 'none';
    document.getElementById('IPADDRESS_Pic').style.display = 'block';
}


function Preferiti() {
    var url = "http://ilmioip.it";
    var titolo = "ilMioIP - Scopri l'indirizzo il tuo indirizzo IP";
    window.external.AddFavorite(url, titolo);
}
function openBox(iTipo) {
    var oLabelBox = document.getElementById('LabelBox')
    var oSUGGERIMENTO = document.getElementById('SUGGERIMENTO');
    var oOggettoEmail = document.getElementById('OggettoEmail');
    var oMailHeader = document.getElementById('MailHeader');
    var oSendMail = document.getElementById('box');
    oSendMail.style.display = 'block';
    var oToEmail = document.getElementById('ToEmail')
    var oIntestazioneBox = document.getElementById('IntestazioneBox');
    var oTesto = document.getElementById('Testo');
    var oInviaDiv = document.getElementById('InviaDiv');
    oInviaDiv.innerHTML = '<input type="button" id="Invia" value="INVIA" onclick="invia()" />';
    var oFirma = document.getElementById('Firma');
    document.getElementById('iButton').value = iTipo;
    switch (iTipo) {
        case 1: //Segnala ilMioIP.it ad un amico
            if (bSmartPhone == 1) {
                oLabelBox.style.backgroundColor = '#333333';
                oInviaDiv.style.top = '198px';
                oFirma.style.top = '200px';
            }
            else
                oLabelBox.style.background = 'url(/images/bck_segnala.png) top center no-repeat';

            oSUGGERIMENTO.style.display = 'none';
            oMailHeader.style.display = 'block';
            if (bSmartPhone == 1)
                oIntestazioneBox.innerHTML = "<p>SEGNALA ILMIOIP.IT.</p>";
            else
                oIntestazioneBox.innerHTML = "<p>SEGNALA ILMIOIP.IT AD UN AMICO.</p>";
            oOggettoEmail.value = "Ti segnalo il sito www.ilmioip.it"
            oTesto.style.display = 'block';
            oTesto.innerHTML = 'Se vuoi conoscere il tuo indirizzo IP<br />vai su <a href="http://www.ilmioip.it">www.ilmioip.it</a>.';
            oToEmail.focus();
            break;
        case 2: // Segnala l'IP ad un amico.
            if (bSmartPhone == 1) {
                oLabelBox.style.backgroundColor = '#14913F';
                oInviaDiv.style.top = '198px';
                oFirma.style.top = '200px';
            }
            else
                oLabelBox.style.background = 'url(/images/bck_segnalaIP.png) top center no-repeat';

            oSUGGERIMENTO.style.display = 'none';
            oMailHeader.style.display = 'block';
            oIntestazioneBox.innerHTML = "<p>INVIA l'IP AD UN AMICO.</p>";
            oOggettoEmail.value = "Il mio IP è: " + IP_CLIENT;
            oTesto.style.display = 'block';
            oTesto.innerHTML = 'Il mio indirizzo IP è ' + IP_CLIENT + '<br />Te l\'ho inviato dal sito <a href="http://www.ilmioip.it">www.ilmioip.it</a>.';
            oToEmail.focus();
            break;
        case 3: // Lascia un tuo suggerimento
            if (bSmartPhone == 1) {
                oLabelBox.style.backgroundColor = '#996699';
                oFrasePrima = document.getElementById('FrasePrima');
                oFrasePrima.innerHTML = 'LASCIA QUI IL TUO COMMENTO.';
                oInviaDiv.style.top = '128px';
                oFirma.style.top = '130px';
            }
            else
                oLabelBox.style.background = 'url(/images/bck_suggerimento.png) top center no-repeat';
            oTestoSuggerimento = document.getElementById('TestoSuggerimento');

            oSUGGERIMENTO.style.display = 'block';
            oMailHeader.style.display = 'none';
            oTesto.style.display = 'none';
            oIntestazioneBox.innerHTML = "<p>LASCIA UN SUGGERIMENTO.</p>";
            oTestoSuggerimento.focus();
            break;
    }
    //Nifty("div#LabelBox", "fixed-height");


}


function logOut() {
    document.getElementById('myPost').value = 'logOut;';
    document.pageForm.submit();
}

function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}
function Right(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}

function bCaratteriOK(myfield, e, aChars) {
    var key;
    var keychar;
    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;
    keychar = String.fromCharCode(key);
    if (key == 46 && myfield.value.split('.').length>3)  //massimo 3 punti
        RET = false;
    else
        if (((aChars).indexOf(keychar) > -1) || key == 8 || key == 9) {
        RET = true;
        if (myfield.value.length>0)
            if (key == 46 && myfield.value.substr(myfield.value.length-1)=='.' )
                RET = false;

    }
    else
        RET = false;

        if (key == 13)
            return true;
        else {
            if (RET == false) {
                alert('Carattere non permesso!')
                return false;
            }
            else
                return true;
        }       
}
    
    
 
