﻿/********************************************************************************************************/
/*      page load                                                                                       */
/********************************************************************************************************/




function initialize(){

    var checkSelector = document.getElementById('chg_immagine');
    if (checkSelector) {

        // rende visibile il selettore delle immagini nell'header: in assenza di javascript non sarà presente
        document.getElementById('chg_immagine').style.visibility = 'visible';
            

        // legge l'ultima immagine memorizzata nel cookie
        var Check = get_cookie('HeaderImage');
        if (Check) {
            changeImageHeader(get_cookie('HeaderImage'));
        }

    }
       
   
}





/********************************************************************************************************/
/*      VARI                                                                                            */
/********************************************************************************************************/


function OpenPrintPage(url) {
    var w = 600;
    var h = 400;
    var l = Math.floor((screen.width - w) / 2);
    var t = Math.floor((screen.height - h) / 2);

    //pulisci precedente impostazione del carattere
    url = url.replace('?enlarge=big', '');
    url = url.replace('?enlarge=medium', '');
    url = url.replace('?enlarge=small', '');
    url = url.replace('&enlarge=big', '');
    url = url.replace('&enlarge=medium', '');
    url = url.replace('&enlarge=small', '');

    //scelta carattere separatore corretto
    var sep = '?';
    if (url.indexOf('aspx?') > 0 || url.indexOf('aspx/?') > 0) {
        sep = '&amp;'
    }

    window.open(url + sep + "print=yes", "_blank", "width=" + w + ", height=" + h + ", left=" + l + ", top=" + t + ", scrollbars=1,resizable=1; ");
}


function PrintPage() {
    window.print();
}




function changeImageHeader(changer) {

    headerObj = document.getElementById('header');
    imageObj = headerObj.getElementsByTagName('img');


    if (changer.toString().length > 2) {
        position = changer.toString().substr(0, 1);
        url = changer.toString().substr(1, changer.toString().length);
        imageObj[0].src = url;
        var Href = "javascript:changeImageHeader(" + position + ");";
        checkActive(Href);
        createCookie('HeaderImage', changer, 2);
    }

    else {

        newUrl = ImmaginiTestata[changer];
        imageObj[0].src = newUrl;
        //document.getElementById('chg_immagine').parentNode.src = newUrl;
        var Href = "javascript:changeImageHeader(" + changer + ");";
        checkActive(Href);
        num = changer;
        createCookie('HeaderImage', changer + newUrl, 2);
    }
}




function checkActive(Href) {
    var b = document.getElementById('chg_immagine');
    var a = b.getElementsByTagName('a')
    for (var i = 0; i < a.length; i++) {
        var classN = new String(a[i].className);
        var classAttr = classN.split(' ');
        a[i].className = classAttr[0];
        if (a[i].href == Href) {
            a[i].className = classAttr[0] + " " + "active";

        }
    }
}









/********************************************************************************************************/
/*      COOKIE                                                                                          */
/********************************************************************************************************/

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}



function get_cookie(cookie_name) {


        var valore = readCookie(cookie_name);

    

        if (valore) {


//            //explorer
//            var result = valore.toString().substring(cookie_name.toString().length + 1, valore.toString().lenght);

//            var num = parseInt(valore.length - cookie_name.toString().length + 1)

//            //tutti i Browser!

//            var result1 = valore.toString().substr(1,valore.toString().length)

            if (valore.toString())
                return valore.toString();

        }
       

     



    
  
    return null;
}





function eraseCookie(name) {
	createCookie(name,"",-1);
}

function EnlargeChar(dimension)
 {

   

}







/********************************************************************************************************/
/*      Ricerca                                                                                        */
/********************************************************************************************************/

// apre il pannello e avvia la ricerca
function showPanel() {

    try {
        if (loadingPanel != null) {
            loadingPanel.show();
        }
    }
    catch (ex) { }

}


// apre il pannello 'clessidra'
function showPanelAndSearch() {

    try {
        if (loadingPanel != null) {
            loadingPanel.show();
        }
    }
    catch (ex) { }

}


function resetField(obj, textToReset) {
    if (obj.value.length == 0) {
        obj.value = textToReset;
        return;
    }

    textToReset = textToReset.toLowerCase();
    var textToTest = obj.value.toLowerCase();

    if (textToTest == textToReset) {
        obj.value = "";
    }
}









/********************************************************************************************************/
/*      in prova                                                                                        */
/********************************************************************************************************/


function txtKeyPress(myfield, e, loginButtonId) {
    alert('ciao');
/*
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13) {
        var LoginButton = document.getElementById(loginButtonId);
        if (LoginButton == undefined)
            return true;
        else {
            LoginButton.click();
            return false;
        }
    } else return true;
    */
}




// restituisce l'url della root dell'applicazione
function getRootURL() {
    var baseURL = location.href;
    var rootURL = baseURL.substring(0, baseURL.indexOf('/', 7));

    // if the root url is localhost, don't add the directory as cassani doesn't use it
    if (baseURL.indexOf('localhost') == -1) {
        return rootURL + "/";
    } else {
        return rootURL + baseURL.substring(baseURL.indexOf('/', 8), baseURL.indexOf('/', baseURL.indexOf('/', 8) + 1)) + "/";
    }
}







/********************************************************************************************************/
/*      Tracking Google Analitycs                                                                       */
/********************************************************************************************************/

function setCustomVar(userGroup) {

    // _setCustomVar(1, 'Member Type', 'Premium', 1)
    // 1: This custom var is set to slot #1.  Required parameter.
    // 'Member Type': The name of the custom variable.  Required parameter.
    // 'Premium': The value of the custom variable.  Required parameter.
    // 1: Sets the scope to visitor-level.  Optional parameter.

    // questa informazione viene salvata nel cookie ___utmv

    _gaq.push(['_setCustomVar', 1, 'Gruppo', '' + userGroup + '']);
    _gaq.push(['_trackPageview']);

//    pageTracker._setCustomVar(
//      1,                        // Required - This custom var is set to slot #1
//      "Gruppo",                 // Required - The top-level name for your online content categories
//      '"' + userGroup + '"',    // Required - Sets the value of "Section" to "Life & Style" for this particular aricle
//      1                         // Optional - Sets the scope to page-level
//    );

}




function clessidra() {
    window.setTimeout("clessidraWAIT()", 1000);
}

function clessidraWAIT() {
    if (loadingPanel != null) { loadingPanel.show(); }
}
