function dim_win(){
    dimx = new Array();
    var width = document.documentElement.clientWidth;
    var height = document.documentElement.clientHeight;
    dimx [0]= width;
    dimx [1]= height;
    return dimx;
}
function getCookie(sNome) {
    var asCookies = document.cookie.split("; ");
    for (var iCnt = 0; iCnt < asCookies.length; iCnt++)
    {
      var asCookie = asCookies[iCnt].split("=");
      if (sNome == asCookie[0]) { 
        return (unescape(asCookie[1]));
      }
    }

    return("");
}

function vaiMail(form,indir) {
    var form = document.forms[form];
    var nome = form.nome.value;
    var cognome = form.cognome.value;
    var lamail = form.email.value;
    var rag = form.rag.value;
    var tel = form.tel.value;
    var citta = form.citta.value;
    var messag = form.messag.value;
    
    if ((nome=="") || (nome=="undefined")){
        alert('Il nome è un campo obbligatorio');
          form.nome.focus();
        return false;
    };
    if ((cognome=="") || (cognome=="undefined")){
        alert('Il cognome è un campo obbligatorio');
          form.cognome.focus();
        return false;
    };
    var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
    if (!email_reg_exp.test(lamail) || (lamail == "") || (lamail == "undefined")) {
        alert("Inserire un indirizzo email corretto.");
        form.lamail.select();
        return false;
    };
    if ((messag=="") || (messag=="undefined")){
        alert('Non hai inserito il testo');
          form.messag.focus();
        return false;
    };
    
    if (form.privacy.checked){
    }else{
        alert("Devi accettare il trattamento dei dati personali.");
        return false;
    };
    
    qstr = 'nome=' + escape(nome) + '&cognome=' + escape(cognome) + '&lamail=' + escape(lamail) + '&rag=' + escape(rag) + '&citta=' + escape(citta) + '&tel=' + escape(tel) + '&messag=' + escape(messag);
    var nomex = document.getElementById("nome");
    nomex.value  = "";
    var cognomex = document.getElementById("cognome");
    cognomex.value  = "";
    var lamailx = document.getElementById("email");
    lamailx.value  = "";
    var ragx = document.getElementById("rag");
    ragx.value  = "";
    var telx = document.getElementById("tel");
    telx.value  = "";
    var cittax = document.getElementById("citta");
    cittax.value  = "";
    var messagx = document.getElementById("messag");
    messagx.value  = "";
    xmlhttpPostMail(indir,qstr,"pagcont_ris");
}
function xmlhttpPostMail(strURL,qString,targetris) {
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
       self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageMail(self.xmlHttpReq.responseText,targetris);
        }
    }
    self.xmlHttpReq.send(qString);
}
function updatepageMail(str,ristrgt){
    document.getElementById(ristrgt).innerHTML = str;
}
/*login*/
function encrypt(pag) {
    var challengeword="";
    challengeword = getCookie("challenge");
    var usern = document.fmpas.usern.value ;
    var pw = document.fmpas.pass.value ;
    var pass = pw;
    
    if ((usern=="") || (usern=="undefined")){
        alert('Inserire il nome utente');
        document.fmpas.usern.focus();
        return false;
    };
    if ((pw=="") || (pw=="undefined")){
        alert('Inserire la password');
        document.fmpas.pass.focus();
        return false;
    };
    
    if (pw) {
       pw = hex_md5 (pw) ;
       pw = pw + challengeword;
       pw = hex_md5 (pw) ;
       document.fmpas.pass.value = '' ;
       document.fmpas.md5ed.value = pw ;
       
       qstr = 'usern=' + escape(usern) + '&pass=' + escape(pass) + '&md5ed=' + escape(pw);
       
       xmlhttpPostLogin(pag,qstr,"pagcont_ris");
       /*document.fmpas.action=pag;
       document.fmpas.submit();*/
    }
}
function xmlhttpPostLogin(strURL,qString,targetris) {
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
       self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            if(self.xmlHttpReq.responseText=="ok"){
                window.location.href = "area/indice.php";
            }else{    
                updatepageMail(self.xmlHttpReq.responseText,targetris);
            }
        }
    }
    self.xmlHttpReq.send(qString);
}
/*end login*/
/*lavori*/
function vaiadd(){
    var doc = document.formaddlav;
    var nomex= doc.nome.value;
    var kwpx= doc.kwp.value;
    if (nomex=="" || nomex=="undefined"){
        alert("Inserire il nome.");
        doc.nomex.focus();
        return false;
    };
    if (kwpx=="" || kwpx=="undefined"){
        alert("Inserire la potenza totale.");
        doc.kwp.focus();
        return false;
    };
    
document.formaddlav.action='add.php';
document.formaddlav.submit();
return true;
}
function vaiedit(indir){
    var doc = document.formeditlav;
    var nomex= doc.nome.value;
    var kwpx= doc.kwp.value;
    if (nomex=="" || nomex=="undefined"){
        alert("Inserire il nome.");
        doc.nome.focus();
        return false;
    };
    if (kwpx=="" || kwpx=="undefined"){
        alert("Inserire la potenza totale.");
        doc.kwp.focus();
        return false;
    };
    xmlhttpPostLav(indir);
return true;
}
function xmlhttpPostLav(strURL) {
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
       self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageLav(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystringLav());
}
function getquerystringLav() {
    var form     = document.forms['formeditlav'];
    var nome = form.nome.value;
    var ubi = form.ubi.value;
    
    var impianti = form.impianti.value;
    var kwp = form.kwp.value;
    var tipo = form.tipo.value;
    var moduli = form.moduli.value;
    
    var id_lav = form.id_lav.value;
    var id_cat = form.id_cat.value;
    var start = form.start.value;
    qstr = 'id_lav=' + escape(id_lav) + '&id_cat=' + escape(id_cat) + '&start=' + escape(start) + '&nome=' + escape(nome) + '&ubi=' + escape(ubi) + '&impianti=' + escape(impianti) + '&kwp=' + escape(kwp) + '&tipo=' + escape(tipo) + '&moduli=' + escape(moduli);
    return qstr;
}
function updatepageLav(str){
    document.getElementById("edit_lav_ris").innerHTML = str;
}
function del_dati(thetarg){
    var eltarg = document.getElementById(thetarg);
    eltarg.innerHTML  = "";
}
function clear_data(thetarg){
    timerID=setTimeout("del_dati('edit_lav_ris')",3000);
}
function check_n_img(pag){
    var n_img = document.getElementById("n_img").value;
    if(n_img > 0){
        alert("Attenzione!!\nMax 1 immagine");
    }else{
        window.open(pag,'_self');
    }
    
}
function vai_upimg(){
    var doc = document.form_up_img;
    var u_img = doc.u_img.value;
    if (u_img=="" || u_img=="undefined"){
        alert("Inserire l'immagine.");
        doc.u_img.focus();
        return false;
    };
    document.form_up_img.action='upimg.php';
    document.form_up_img.submit();
    return true;
}

function vaiadd_cat(){
    var doc = document.formaddcat;
    var nomex= doc.nome.value;
    if (nomex=="" || nomex=="undefined"){
        alert("Inserire il nome.");
        doc.nomex.focus();
        return false;
    };
    document.formaddcat.action='add_cat.php';
    document.formaddcat.submit();
    return true;
}
function vaiedit_cat(){
    var doc = document.formeditcat;
    var nomex= doc.nome.value;
    if (nomex=="" || nomex=="undefined"){
        alert("Inserire il nome.");
        doc.nomex.focus();
        return false;
    };
    document.formeditcat.action='scheda_cat.php';
    document.formeditcat.submit();
    return true;
}
/*end lavori*/
/*banners*/
var allHTMLTags = new Array();
function getElementByClass(theClass) {
    var allClass = new Array();
    var allHTMLTags=document.getElementsByTagName("*");
    for (i=0; i<allHTMLTags.length; i++) {
        if (allHTMLTags[i].className==theClass) {
            allClass.push(allHTMLTags[i]);
        }
    }
    return allClass;
}
function altro_banners(){
    
    var input_old_idfixed = document.getElementById("idfixed_altro_start").value;
    var input_old_id = document.getElementById("id_altro_start");
    var old_id = input_old_id.value;
    var new_id = parseInt(old_id) - 1;
    if(new_id < 0){
        new_id = input_old_idfixed;
    }
    input_old_id.value = new_id;
    
    /*arrClass = getElementByClass("img_altro_start");
    
    opacityTweenOut = new OpacityTween(arrClass[old_id],'', 100, 0, 1);
    opacityTweenIn = new OpacityTween(arrClass[new_id],'', 0, 100, 1);
    opacityTweenOut.start();
    opacityTweenIn.start();*/
    
    
    arrClass = glow.dom.get(".img_altro_start");
    
    glow.dom.get(arrClass).css("opacity", 0);
    
    glow.dom.get(arrClass[old_id]).css("opacity", 1);
    
    glow.anim.fadeOut(glow.dom.get(arrClass[old_id]), 1);
    glow.anim.fadeIn(glow.dom.get(arrClass[new_id]), 1);
    
      
}
var intval=""
function start_Int(){
    if(intval==""){
        intval=window.setInterval("altro_banners()",4000);
    }else{
        //stop_Int();
    }
    /*if(glow.dom.get("#stato_altro_start").val()==0){
        intval=window.setInterval("altro_banners()",4000);
        glow.dom.get("#stato_altro_start").val(1);
    }else{
        stop_Int();
    }*/
}
function stop_Int(){
    /*glow.dom.get("#stato_altro_start").val(0);*/
    if(intval!=""){
        window.clearInterval(intval);
        intval="";
    }
}

var intvaldos=""
function start_Intdos(){

    /*if(document.getElementById("stato_altro_start")){
        alert("ciao");
        if(document.getElementById("stato_altro_start").value==0){
            intvaldos=window.setInterval("altro_banners()",4000);
            document.getElementById("stato_altro_start").value==1;
        }else{
            //stop_Intdos();
        }
        
    }*/
}
function stop_Intdos(){
    /*f(intvaldos!=""){
        window.clearInterval(intvaldos);
        intvaldos="";
    }*/
}


/*end banners*/
/*testi*/
function vaiedittesti(indir){
    var doc = document.formedittext;
    /*var thetextox= doc.thetexto.value;
    if (thetextox=="" || thetextox=="undefined"){
        alert("Inserire il testo.");
        doc.thetexto.focus();
        return false;
    };*/
    //xmlhttpPostTesti(indir);
    
    /*var thetextox= htmlDecode(document.formedittext.thetexto.value);
    
    if (htmlDecode(document.formedittext.thetexto.value)=="" || htmlDecode(document.formedittext.thetexto.value)=="undefined"){
        alert("Inserire il testo.");
        //doc.thetexto.focus();
        return false;
    };
    */
    updateRTEs();
    //alert(htmlDecode(document.formedittext.thetexto.value));
    xmlhttpPostTesti(indir);
    return true;
}
function xmlhttpPostTesti(strURL) {
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
       self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageTesti(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystringTesti());
}
function getquerystringTesti() {
    var form     = document.forms['formedittext'];
    var thetexto = htmlDecode(form.thetexto.value);
    var id_text = form.id_text.value;
    qstr = 'id_text=' + escape(id_text) + '&thetexto=' + escape(thetexto);
    return qstr;
}
function updatepageTesti(str){
    document.getElementById("edit_lav_ris").innerHTML = str;
}
/*testi*/
/*news*/
function vaiaddnews(){
    var doc = document.formaddnews;
    var titolox= doc.titolo.value;
    var textox= doc.texto.value;
    
    if (titolox=="" || titolox=="undefined"){
        alert("Titolo obbligatorio.");
        doc.titolo.focus();
        return false;
    };
    if (textox=="" || textox=="undefined"){
        alert("Testo obbligatorio.");
        doc.texto.focus();
        return false;
    };
    /*alert("ciao");*/
    document.formaddnews.action='add.php';
    document.formaddnews.submit();
    return true;
}
function vaieditnews(indir){
    var doc = document.formeditnews;
    var titolox= doc.titolo.value;
    var textox= doc.texto.value;
    if (titolox=="" || titolox=="undefined"){
        alert("Titolo obbligatorio.");
        doc.titolo.focus();
        return false;
    };
    if (textox=="" || textox=="undefined"){
        alert("Testo obbligatorio.");
        doc.texto.focus();
        return false;
    };
    xmlhttpPostNews(indir);
    return true;
}
function xmlhttpPostNews(strURL) {
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
        self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageNews(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystringNews());
}
function getquerystringNews() {
    var form     = document.forms['formeditnews'];
    var titolo = form.titolo.value;
    var texto = form.texto.value;
    var id_news = form.id_news.value;
    var start = form.start.value;
    qstr = 'id_news=' + escape(id_news) + '&start=' + escape(start) + '&titolo=' + escape(titolo) + '&texto=' + escape(texto);
    return qstr;
}
function updatepageNews(str){
    document.getElementById("edit_lav_ris").innerHTML = str;
}
/*end news*/
function mask_Fade_Out(){
    glow.anim.fadeOut(glow.dom.get("#mask_dx"),0.5,
        {
            onComplete: function(){
                glow.dom.get("#mask_sx").css("display", "none");
                glow.dom.get("#mask_dx").css("display", "none");
                glow.dom.get("#mask_sx").css("opacity", 0.8);
                glow.dom.get("#mask_dx").css("opacity", 1);
            }
        }  
    );
}
function remove_highlight_menu(arr_mn,laclass){
    glow.dom.get(arr_mn).removeClass(laclass);
}
