﻿// visualizza un popUp nella posizione del controllo indicato 
//Costanti Opzioni per le liste entità
var XSLT_ENABLEPAGING = 1;
var XSLT_SHOWRAWDATA = 2;
var XSLT_ENTITYPERMISSION = 4;
var XSLT_ALLPERMISSION = 8;
var XSLT_SHOWINFO = 16;
var XSLT_SHOWQUERYSTRINGINXSLTPARAM = 32;
var XSLT_MODEINSERT = 64
var XSLT_MODEUPDATE = 128
var XSLT_MODEDETAIL = 256

var CHAR_ALPHANUMERIC = 'abcdefghilmnopqrstuvzwyjkxABCDEFGHILMNOPQRSTUVZWYJKX1234567890'
var CHAR_NOTPERMITTED = '<>/\*|'
function baseFilter() {
    return "{}"
}
CULTURE = 'IT-it';
/* debug config */
ENABLEPAGING = true;
ENTITYPERMISSION = false;
SHOWALLPERMISSION = true;
SHOWINFO = false;
SHOWRAWDATA = false;

SHOWQUERYSTRINGINXSLTPARAM = false;
/**/


var iWS = new Array(); // variabile per la memorizzazione dei servizi attivi sulla pagina
iWS.count = 0;
var iObject = new Array(); ; // variabile per la memorizzazione degli oggetti sulla pginas
iObject.count = 0;

function gXsltOptions() {
    return (ENABLEPAGING ? XSLT_ENABLEPAGING : 0)
		+ (SHOWRAWDATA ? XSLT_SHOWRAWDATA : 0)
		+ (ENTITYPERMISSION ? XSLT_ENTITYPERMISSION : 0)
		+ (SHOWALLPERMISSION ? XSLT_ALLPERMISSION : 0)
		+ (SHOWINFO ? XSLT_SHOWINFO : 0)
		+ (SHOWQUERYSTRINGINXSLTPARAM ? XSLT_SHOWQUERYSTRINGINXSLTPARAM : 0)
}


String.format = function() {
    if (arguments.length == 0)
        return null;
    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

function nullIf(value, compare, valetoreturn) {
    return (value == compare) ? null : (valetoreturn == null) ? value : valetoreturn
}
function movePopUp(popUpId, objTarget) {
    hidePopUp(popUpId);
    p = $get(popUpId).cloneNode(true);
    //aggiungo il nuovo contenuto
    while (objTarget.firstChild) {
        objTarget.removeChild(element.firstChild);
    }

    objTarget.appendChild(p);
    //objTarget.innerHMTL = p.innerHMTL;
    p.style.display = 'block';
}
function validateInput(val) {
    if (val == '') { return true }
    var exp = new RegExp("^[^<>|{}]+$"); // qualsiasi cosa che non contiene <>|{}
    if (!exp.test(val)) {
        alert("La stringa non deve contenere i seguenti caratteri <>|{}");
        return false
    }
    return true
}
function showPopUp(popUpId, objTarget) {
    p = $get(popUpId);
    objTarget.appendChild(p);
    p.style.display = 'block';
    var obj = document.getElementById('background_' + popUpId)
    if (obj != null) { obj.style.display = 'block' }
}
function showPopUp(popUpId) {
    p = $get(popUpId);
    p.style.display = 'block';
    var obj = document.getElementById('background_' + popUpId)
    if (obj != null) { obj.style.display = 'block' }
}
function hidePopUp(popUpId) {
    p = $get(popUpId);
    p.style.display = 'none';
    document.body.appendChild(p);
    var obj = document.getElementById('background_' + popUpId)
    if (obj != null) { obj.style.display = 'none' }
}
function ShowHide(id) {
    obj = document.getElementById(id);
    if (obj.style.display == 'none') { obj.style.display = 'block' } else { obj.style.display = 'none' }
}
function setFocus(objId) {
    p = $get(objId);
    p.select();
    try { p.focus(); } catch (e) { }
}
//usato per la funzione selection per il multi select in vari riboselection
function multipleSelection(objCheck, idHiddenTarget) {
    var hid = $get(idHiddenTarget);
    if (hid == null) {
        hid = document.createElement('input');
        hid.id = idHiddenTarget;
        hid.type = 'hidden';
        document.body.appendChild(hid);
    }
    if (objCheck.checked) {
        hid.value = hid.value + objCheck.value + ','
        if (hid.onchange != null) { hid.onchange(); }
    } else {
        hid.value = hid.value.replace(objCheck.value + ',', '');
    }
}
//usato per la funzione selection per il multi select in vari riboselection
function checkAll(id, num_check, value) {
    for (var i = 1; i <= num_check; i++) {
        o = document.getElementById(id + i);
        if (o != null) { o.checked = value; o.onclick(); }
    }

}
function getElementsByKey(node, searchKey, tag) {
    var classElements = new Array();
    if (node == null) {
        alert('alert:node is null, node change to document,fix for performance.Search key was:"' + searchKey + '"');
        node = document
    }
    if (tag == null) { tag = '*' }
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var searchArr = searchKey.split(",");
    var searchLen = searchArr.length;
    for (ii = 0, j = 0; ii < searchLen; ii++) {
        var pattern = new RegExp("(^|,)" + searchArr[ii] + "(,|$)");
        for (i = 0; i < elsLen; i++) {
            if (els[i].getAttribute('keys') != null) {
                if (pattern.test(els[i].getAttribute('keys'))) {
                    classElements[j] = els[i];
                    j++;
                }
            }
        }
    }
    return classElements;
}

function SwitchTrueFalse(id, value) {
    //ritorno l'id dell'immagine da cambiare
    var imgx = $get(id);
    var reg = new RegExp("false.png");
    src = imgx.getAttribute("src");
    if (reg.test(src))
    { imgx.setAttribute("src", src.replace("false", value == null ? "true" : value)) }
    else
    { imgx.setAttribute("src", src.replace("true", value == null ? "false" : value)) }

}
/* SYNC CALL */
var xmlhttp = false;
/*@cc_on@*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
    try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
        xmlhttp = false;
    }
}
@end@*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
        xmlhttp = new XMLHttpRequest();
    } catch (e) {
        xmlhttp = false;
    }
}
if (!xmlhttp && window.createRequest) {
    try {
        xmlhttp = window.createRequest();
    } catch (e) {
        xmlhttp = false;
    }
}
function executeUrlSynch(url) {
    xmlhttp.open("GET", url, false);
    xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { } }
    xmlhttp.send(null);
    if (!xmlhttp.getResponseHeader("Date")) {
        var cached = xmlhttp;
        xmlhttp = (typeof (XMLHttpRequest) != "undefined") ?
			    new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
        var ifModifiedSince = cached.getResponseHeader("Last-Modified");
        ifModifiedSince = (ifModifiedSince) ?
			      ifModifiedSince : new Date(0); // January 1, 1970
        xmlhttp.open("GET", url, false);
        xmlhttp.setRequestHeader("If-Modified-Since", ifModifiedSince);
        xmlhttp.send("");
        if (xmlhttp.status == 304) {
            xmlhttp = cached;
        }
    }
}
function executeUrlAndRedirect(url, redirect) {
    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { }
    }
    xmlhttp.send(null);
    window.location = redirect;
}
function executeUrl(url) {
    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { }
    }
    xmlhttp.send(null)
}


sfHover = function() {
    var nav = $get("nav")
    if (nav != null) {
        var sfEls = nav.getElementsByTagName("LI");
    }
    if (sfEls != null) {
        for (var i = 0; i < sfEls.length; i++) {
            sfEls[i].onmouseover = function() {
                this.className += " sfhover";
                if (document.getElementById("sermonLists")) {
                    document.getElementById("sermonLists").style.visibility = "hidden";
                }
            }
            sfEls[i].onmouseout = function() {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
                if (document.getElementById("sermonLists")) {
                    document.getElementById("sermonLists").style.visibility = "visible";
                }
            }
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

