﻿//---- ------------------------------------------------------------------------------- ---
//
// Created by: Mauro Faccin 
// Company: Mediana s.r.l. 
// Website: www.mediana.com
// November, 11, 2009
//
//---- ------------------------------------------------------------------------------- ---


//---- Naive Solution for the persistence of selection about the UPPER nav links ---------
// Aims of the function:
// It highlights the current page-link in the upper navigation bar, if one is selected.
//
// The function recognizes the current page by the current path showed by the browser, 
// then it compares with each one which is hardcoded inside itself.

function ChangeColorForPage() {
    var sPath = window.location.pathname;

    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

    switch (sPage) {
        case 'HomePage.aspx':
            ChangeColor(1);
            break
        case 'UserAdministrationPage.aspx':
            ChangeColor(2);
            break
        case 'RichiestaInformazioni.aspx':
            ChangeColor(3);
            break
    }
}

function ChangeColor(choiceNum) {
    elem1 = document.getElementById("NavLinkUp1");
    if (elem1 != null) {
        elem1.style.color = '#840000';
        /* set the hover effect */
        elem1.onmouseover = function() {
                                            this.style.color = 'white';
                                        }
        elem1.onmouseout = function()  {
                                            if (choiceNum != 1) {
                                                                    this.style.color = '#840000';
                                                                 }
                                        }
    }
    elem2 = document.getElementById("ctl00_ctl00_NavLinkUp2");
    if (elem2 != null) {
        elem2.style.color = '#840000';
        /* set the hover effect */
        elem2.onmouseover = function() {
                                        this.style.color = 'white';
                                        }
        elem2.onmouseout = function() {
                                        if (choiceNum != 2) {
                                                                this.style.color = '#840000';
                                                            }
                                       }
    }
    /* The 3rd link (Request Info) were hidden in masterpage */
    /*
    elem3 = document.getElementById("NavLinkUp3");
    if (elem3 != null) {
        elem3.style.color = '#840000';
        elem3.onmouseover = function() {
                                        this.style.color = 'white';
                                        }	
        elem3.onmouseout = function() {
                                        if (choiceNum != 3) {
                                                            this.style.color = '#840000';
                                                            }
                                        }	
    }
    */
    elem4 = document.getElementById("ctl00_ctl00_NavLinkUp4");
    if (elem4 != null) {
        elem4.style.color = '#840000';
        /* set the hover effect */
        elem4.onmouseover = function() {
                                         this.style.color = 'white';
                                       }
        elem4.onmouseout = function() {
                                         this.style.color = '#840000';
                                      }
    }

    switch (choiceNum) {
        case 1:
            elem1.style.color = 'white';
            break
        case 2:
            elem2.style.color = 'white';
            break
        case 3:
            elem3.style.color = 'white';
            break
        case 4:
            elem4.style.color = 'white';
            break
    }
}



//---- Naive Solution for the persistence of selection about the LEFT navigation menu ----
// Aims of the function:
// 1. it holds in evidence the current section (i.e. subsite) if one is selected when
// browsing its pages
// 2. it hides the subsite's list of pages when a section isn't selected; 
// when the user is the home page, for example 
//
// The function recognizes the current section from the page address, 
// so it hardcodes data as tag ID, label and the pathname of the sections

function HighlightLeftMenuSection() {
//    var sPath = window.location.pathname;

//    var ParentElement = document.getElementById("ctl00_ctl00_PlaceHolderLeftNavBar_PlaceHolderLeftNavBar_CurrentNav");

//    var ChildrenArray = ParentElement.getElementsByTagName('TR');

//    if (ChildrenArray.length <= 0) {
//        // there isn't any node for scanning
//        return
//    }

//    for (var i = 0; i < ChildrenArray.length; i++) {
//        var tagTitle = ChildrenArray.item(i).getAttribute('title');
//        if (tagTitle == "Energia Elettrica") {
//            ChildrenArray.item(i).style.backgroundColor = "#CECECE";
//            return
//        }
//        if (tagTitle == "Gas") {
//            ChildrenArray.item(i).style.backgroundColor = "#CECECE";
//            return
//        }
//    }
}


function InStr(String1, String2) {
    var a = 0;

    if (String1 == null || String2 == null)
        return (false);

    String1 = String1.toLowerCase();
    String2 = String2.toLowerCase();

    a = String1.indexOf(String2);
    if (a == -1)
        return 0;
    else
        return a + 1;
}


//---- -----------------------------------------------------------------------------------
