var loading = 1;

function openPicture(imageName,imageWidth,imageHeight,alt,posLeft,posTop) {
    newWindow = window.open('',"newWindow","width="+imageWidth+",height="+imageHeight+",left="+posLeft+",top="+posTop);
    newWindow.document.open();
    newWindow.document.write('<html><HEAD><title>Starnetwork S.r.l. - Zoom</title></HEAD><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
    newWindow.document.write('<img src="'+imageName+'" width="'+imageWidth+'" height="'+imageHeight+'" alt="'+alt+'">');
    newWindow.document.write('</body></html>');
    newWindow.document.close();
    newWindow.focus();
}

function conferma(messaggio, url) {
    if (confirm(messaggio)) {
        document.location.href = url;
    }
    return false;
}

function hide_error() {
    if (loading == 1) {
        alert('Si e\' verificato un errore imprevisto nel caricamento della lista, prego riprovare.');
        div = document.getElementById('layerName');
        div.style.visibility = 'hidden';
        frames["ifaddlista"].location.href = 'about:blank';
    }
}

function hide_ok(numeri) {
    if (typeof numeri != 'undefined' && numeri != null && numeri.length > 0) {
        loading = 0;
        txt = document.getElementById('number');

        if (txt.value != '') txt.value = txt.value + "\n";

        for (numero in numeri) {
            txt.value = txt.value + numeri[numero] + "\n";
        }
    } else {
        loading = 0;
        alert('Lista vuota!');
    }
    div = document.getElementById('layerName');
    div.style.visibility = 'hidden';
    frames["ifaddlista"].location.href = 'about:blank';
}

function addlista(el) {
    sel = document.getElementById('liste');
    lista = sel[sel.selectedIndex].value;

    if (lista > 0) {
        div = document.getElementById('layerName');
        jorel = document.getElementById(el);
        tmppos = getAbsolutePos(jorel);
        div.style.left = tmppos.x + jorel.offsetWidth/10;
        div.style.top = tmppos.y + jorel.offsetHeight/3;

        loading = 1;
        div.innerHTML = '<span class="titoli"><font color=#CC0000>Attendere, caricamento in corso...</font></span>';
        frames["ifaddlista"].location.href = '/sms.php?action=showlista&value='+lista;
        div.style.visibility = 'visible';
        setTimeout('hide_error()', 10000);
    }
}

function getAbsolutePos(el) {
    var r = { x: el.offsetLeft, y: el.offsetTop };
    if (el.offsetParent) {
        var tmp = getAbsolutePos(el.offsetParent);
        r.x += tmp.x;
        r.y += tmp.y;
    }
    return r;
};

var lunghezza = 0;

function contachar(area) {
    quanti = document.getElementById('quanti');
    attuali = area.value.length;
    if (attuali > 160) {
        area.value = area.value.substring(0,160);
        quanti.value = 0;
    } else {
        quanti.value = 160-area.value.length;
    }
}

function unsupported(el) {
    alert('Funzione non supportata con l\'invio via SIM Card personale.');
    if (el) {
        d = document.getElementById(el);
        d.checked = true;
    }
}

function conferma_dreport(el) {
    alert('Attenzione!\nLa conferma di consegna, se si usa la propria SIM\nper inviare gli SMS, ha un costo che sara\' addebitato\ndal proprio gestore.');
}

function showstatus(id) {
    alert('Funzione in manutenzione, ci scusiamo per il disagio. (' + id + ')');
}