var root="";

function ApriPopup(idElem,lingua,stampa){
	window.open(root + '/News_popup.aspx?idElemento=' + idElem + '&lingua=' + lingua + '&stampa=' + stampa,'News','width=600,height=400,scrollbars=yes,toolbar=no,statusbar=no,resizable=yes');
	return false;
}
function InviaAmico(idElem,lingua){
	window.open(root + '/InviaAmico_popup.aspx?idElemento=' + idElem + '&lingua=' + lingua,'InviaAmico','width=600,height=450,scrollbars=yes,toolbar=no,statusbar=no,resizable=yes');
	return false;
}
function ValidaCategorie(oSrc, args){
	args.IsValid=false;
	var input=document.getElementsByTagName("input");
	for (i=0;i<input.length;i++) {
		if (input[i].id.substring(0,21)=="Template_chkCategorie") {
			if (input[i].checked) args.IsValid=true;
		}
	}
}
function digitaNomeForm() {
    var name = prompt("Inserisci il nome del form da duplicare: ");
    var el = document.getElementById("nomeFormDuplicato");
    if (name!=null && name!="" && name!="undefined") {
        el.value = name;
    }
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

document.onmousemove=sM;
document.onmouseup=sU;
var stD=false;
var mX,sMr;
function sD(e){
document.onmousedown=function(){return false;};
document.onselectstart=new Function ("return false");
sMr=document.getElementById("sM");
sMr.style.left=mX-1;
sMr.style.top=document.body.scrollTop;
sMr.style.height=document.body.clientHeight+"px";
sMr.style.display="block";
stD=true;
}
function sU(){
if(stD==false)return;
stD=false;
sMr.style.display="none";
el=document.getElementById("sL");
if(mX-3<50)mX=53;
else if(mX-3>500)mX=503;
el.style.width=mX-20+"px";
document.onselectstart=new Function("return true");
document.onmousedown=function(){return true;};
}
function sM(e){
if(window.event)mX=event.clientX;
else mX=e.pageX;
if(stD==true){
if(mX-1>49&&mX-1<501){sMr.style.left=mX-1;}
}
}
function NewWindow(url, w, h) 
{

// If you place Thumb.aspx in a different directory that your root image directory,
// you will need to add the image directory to url below, like:
// url = "/rootImageDirectory/" + url + ".jpg"

  //url = "fotogallery/" + url ;//+ ".jpg"
  //alert(url);
  if (w > screen.width || h > screen.width)
  {
    if (w > screen.width && h <= screen.height)
    {
      var nw = screen.width - 70;
      var nh = parseInt(h) + 36
    }
    if (h > screen.height && w <= screen.width)
    {
      var nh = screen.height - 70;
      var nw = parseInt(w) + 36
    }
    if (w > screen.width && h > screen.height)
    {
      var nh = screen.height - 70;
      var nw = screen.width - 70;
    }

    window.open(url,"_blank","width=" + nw + ",height=" + nh + ",left=0,top=0,scrollbars=yes,resizable=yes");

  }
  else
  {
    var nh = parseInt(h) + 25;
    var nw = parseInt(w) + 25;
    window.open(url,"_blank","width=" + nw + ",height=" + nh + ",scrollbars=no,resizable=no");
  }
  return false;
}

function attivaDisattivaTxtBoxAltro(IDCheckList,IDTextBoxAltro,n_check_altro) {
    var CheckAltroAnteprima = document.getElementById("AnteprimaForm_" + IDCheckList + "_" + n_check_altro);
    var textboxAltroAnteprima = document.getElementById("AnteprimaForm_" + IDTextBoxAltro);
    var CheckAltro = document.getElementById("Template__ctl2_" + IDCheckList + "_" + n_check_altro);
    var textboxAltro = document.getElementById("Template__ctl2_" + IDTextBoxAltro);
    if (CheckAltro != null) {
        if (CheckAltro.checked){
        	    textboxAltro.disabled = false;
        }
        else {
	        textboxAltro.disabled = true;
	        textboxAltro.value = "";
	    }
	}
	else if (CheckAltroAnteprima != null) {
        if (CheckAltroAnteprima.checked){
    	        textboxAltroAnteprima.disabled = false;
        }
        else {
	        textboxAltroAnteprima.disabled = true;
	        textboxAltroAnteprima.value = "";
	    }
	}
}

function attivaDisattivaInserimentoNRighe() {
    var Check = document.getElementById("chkMultiRows");
    var Text = document.getElementById("txtRows");
    if (Check.checked){
        Text.disabled = false;
    }
    else {
        Text.value = ""
        Text.disabled = true;
    }
}
function IsNumeric(ObjVal,ErrMsgToDsply)
{
return /^\d+$/.test(ObjVal) ? true : alert(ErrMsgToDsply),false;
}
function selectAllCheckboxList(listID,destCount) {
    var i
    for (i = 0; i < destCount; i++){
        var item = document.getElementById("Template_ModuloInvioSMS_CheckList_LD_" + listID + "_" + i);
        if (item.disabled == false){
	        item.checked = true ;
	    }
	}
	attivaDisativaPulsanteVerificaTesto();
}
function deselectAllCheckboxList(listID,destCount) {
    var i
    for (i = 0; i < destCount; i++){
        var item = document.getElementById("Template_ModuloInvioSMS_CheckList_LD_" + listID + "_" + i);
	        item.checked = false ;
	}
	attivaDisativaPulsanteVerificaTesto();
}
function attivaDisativaPulsanteVerificaTesto() {
    var testo = document.getElementById("Template_ModuloInvioSMS_txbTestoSMS");
    var pulsante = document.getElementById("Template_ModuloInvioSMS_btnVerificaTestoSMS");
    if (testo.value != "") {
        pulsante.disabled = false;
    }
    else {
        pulsante.disabled = true;
    }
}
function conteggioCaratteriRimanenti(numCar) {
    var testo = document.getElementById("Template_ModuloInvioSMS_txbTestoSMS");
    if (testo == null) {
        testo = document.getElementById("AUC_TabellaMod_Oggetto");
    }
    var caratteri = testo.value;
    var label = document.getElementById("Template_ModuloInvioSMS_txbNumCarTesto");
    if (label == null) {
        label = document.getElementById("AUC_TabellaMod_NumCarOggetto");
    }
    label.value = (numCar - caratteri.length)
    if (label.value < 0) {
        alert("Il numero di caratteri inseriti \u00E8 superiore al consentito.");
    }
}
function confermaInvioSMS() {
    var conferma=confirm("Conferma invio sms");
    var conf = document.getElementById("Template_ModuloInvioSMS_confermaInvio");
    if (conferma==true){
        conf.value = true;
    }
    else {
        conf.value = false;
        alert("Invio fermato");
    }
}

function NascondiAlbero() {
    var livelli;

    livelli = document.getElementsByTagName("div");
    for (i = 0; i < livelli.length; i++) {
        if (livelli[i].id.indexOf("divCategorieNewsletter") != -1) {
            livelli[i].className = "nascondiCat";
        }
    }
}
var isNS4 = (navigator.appName == "Netscape") ? 1 : 0;

function Espandi(oggetto, sub_nomeHREF, sub_nomeDIV, sub_nomeIMG, css_Espandi, css_Comprimi) {

    var NomeOggetto, NomeOggetto2, NomeOggetto3, Oggetto2, Oggetto3

    //oggetto HREF
    NomeOggetto = oggetto.id
    //eseguo il replace per operare sul DIV
    NomeOggetto2 = NomeOggetto.replace(sub_nomeHREF, sub_nomeDIV)
    //eseguo il replace per operare sul IMG
    NomeOggetto3 = NomeOggetto.replace(sub_nomeHREF, sub_nomeIMG)

    //oggetto DIV
    Oggetto2 = document.getElementById(NomeOggetto2)
    //oggetto IMG
    Oggetto3 = document.getElementById(NomeOggetto3)

    //imposto le proprietà desiderate per gli oggetti
    if (Oggetto2.className == css_Espandi) {
        Oggetto2.className = css_Comprimi
        Oggetto3.src = "/images/blueup.gif"
        Oggetto3.alt = "Espandi"

    } else {
        Oggetto2.className = css_Espandi
        Oggetto3.src = "/images/bluedrop.gif"
        Oggetto3.alt = "Comprimi"
    }
}

function getElementLeft(elm) {
    var x = 0;

    //set x to elm’s offsetLeft
    x = elm.offsetLeft;

    //set elm to its offsetParent
    elm = elm.offsetParent;

    //use while loop to check if elm is null
    // if not then add current elm’s offsetLeft to x
    //offsetTop to y and set elm to its offsetParent

    while (elm != null) {
        x = parseInt(x) + parseInt(elm.offsetLeft);
        elm = elm.offsetParent;
    }
    return x;
}

function getElementTop(elm) {
    var y = 0;

    //set x to elm’s offsetLeft
    y = elm.offsetTop;

    //set elm to its offsetParent
    elm = elm.offsetParent;

    //use while loop to check if elm is null
    // if not then add current elm’s offsetLeft to x
    //offsetTop to y and set elm to its offsetParent

    while (elm != null) {
        y = parseInt(y) + parseInt(elm.offsetTop);
        elm = elm.offsetParent;
    }

    return y;
}
function Out() {
    document.getElementById("imgboxZoom").style.visibility = 'hidden';
}
function Large(obj, imgPath) {
    var imgbox = document.getElementById("imgboxZoom");
    var title = document.createElement("div");
    var imgx = document.createElement("img");
    var img = document.createElement("img");
    var offSetTop = 45; // offset verticale dell' ingrandimento immagine
    var offSetLeft = 20; // offset orizzontale dell' ingrandimento immagine
    var tP = 3; // padding del titolo
    var iL = 500; // larghezza immagine articolo
    var iH = 500; // altezza immagine articolo
    var xL = 22; // larghezza icona X chiusura ingrandimento immagine
    var xH = 22; // altezza icona X chiusura ingrandimento immagine

    imgbox.style.visibility = 'visible';
    imgbox.style.height = iH + xH + 'px';
    imgbox.style.width = iL + 'px';
    
    img.src = imgPath;
    img.style.width = iL + 'px';
    img.style.height = iH + 'px';
    imgx.src = root + "/images/chiudi_imgArt.png";
    imgx.setAttribute('style', 'float:right;');
    imgx.style.styleFloat = 'right';
    imgx.style.width = xL + 'px';
    imgx.style.height = xH + 'px';
    imgx.style.display = 'block';
    imgx.style.padding = '0px';
    imgx.style.margin = '0px';
    imgx.style.cursor = 'hand';
    title.setAttribute('style', 'float:left;');
    title.style.styleFloat = 'left';
    title.style.display = 'block';
    title.style.width = iL - xL - (tP * 2) + 'px';
    title.innerHTML = imgPath.substring(imgPath.lastIndexOf("/") + 1, imgPath.lastIndexOf("."));
    title.style.padding = tP + 'px';
    title.style.background = '#eeeeee';
    title.style.color = '#000000';
    title.style.margin = '0px';
    // for (i in title.style) alert(i+' - ' +title.style[i]);
    if (img.addEventListener) {
        imgx.addEventListener('click', Out, false);
    } else {
        imgx.attachEvent('onclick', Out);
    }
    imgbox.innerHTML = '';
    imgbox.appendChild(title);
    imgbox.appendChild(imgx);
    imgbox.appendChild(img);
    imgbox.style.left = (getElementLeft(obj) + offSetLeft) + 'px';
    imgbox.style.top = (getElementTop(obj) + offSetTop) + 'px';
}
// FUNZIONI aggiunte in occasione delle Implementazioni Accessibilità P.A.
// Data: dicembre 2010
// riguardano l' utilizzo del WeManager per selezionare le immagini
// e riguardano l' utilizzo del nuovo CKeditor
// rifImmagine = ID dell' asp:TextBox contenente l' url dell' immagine
function selezionaImmagine(rifImmagine) {
    window.open('WebFileManager/editor.aspx?path=' + root + '/UserFile/Image&sort=Name', 'SelezionaImmagine' + rifImmagine, 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function aggiornaImmagine(rifImmagine) {
    document.getElementById('AUC_tabellaMod_' + rifImmagine + '_Prew').src = document.getElementById('AUC_tabellaMod_' + rifImmagine).value;
}
