﻿/**
Javascript uses to zoom on the text
*/
function getStyle(el, styleProp) {

    var x = document.getElementById(el);


    if (x.currentStyle) {
        var y = eval('x.currentStyle.' + styleProp);
    }
    else if (window.getComputedStyle || document.defaultView.getComputedStyle != null) {

        switch (styleProp) {
            case 'fontSize':
                styleProp = "font-size";
                break;
        }
        if (window.getComputedStyle) {
            var y = window.getComputedStyle(x, null).getPropertyValue(styleProp);
        }
        else {
            var y = document.defaultView.getComputedStyle(x, "").getPropertyValue(styleProp);
        }
    }

    return y;

}

function zoom(typezoom) {
    fontsize = parseInt(getStyle("body", "fontSize").replace("px", ""));
    body_tag = document.getElementById("body");

//    taille_width = parseInt(getStyle("inputsearch", "width").replace("px", ""));
//    input_search = document.getElementById("inputsearch");

    if (typezoom == "+") {
        if (fontsize < 14) {
//            if (taille_width > 40 && fontsize < 13) {
//                input_search.style.width = (taille_width - 40) + "px";
//            }

            body_tag.style.fontSize = (fontsize + 1) + "px";

//            if ((fontsize + 1) >= 14) {

//                document.getElementById("search").style.display = "none";
//                document.getElementById("avancee").innerHTML = "+";
//            }

            SetCookie("length", (fontsize + 1), 15);
        }



    }
    else {
        if (fontsize > 9) {
//            if (fontsize <= 13) {
//                input_search.style.width = (taille_width + 40) + "px";
//            }

            body_tag.style.fontSize = (fontsize - 1) + "px";

//            if ((fontsize + 1) < 16) {
//                document.getElementById("search").style.display = "inline";
//                document.getElementById("avancee").innerHTML = "+ avanc&eacute;e";
//            }
            SetCookie("length", (fontsize - 1), 15);
        }

    }


}


function SetCookie(nom, valeur, jours) {
    var expDate = new Date()

    expDate.setTime(expDate.getTime() + (jours * 24 * 3600 * 1000))

    document.cookie = nom + "=" + escape(valeur) + ";expires=" + expDate.toGMTString()
}


function GetCookie(nom) {
    var arg = nom + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}


function startpage() {
    var hidden = document.getElementById('Default_HiddenFieldCurrentUrl');
    if (hidden != null) {
        hidden.value = window.location;
    }
    else {
        hidden = document.getElementById('HiddenFieldCurrentUrl');
        if (hidden != null) {
            hidden.value = window.location;
        }
    }
   
    ShowMenu();

    if (GetCookie("length")) {
        body_tag = document.getElementById("body");
        if (body_tag != null) {
            body_tag.style.fontSize = (GetCookie("length")) + "px";
        }
        

        if (GetCookie("length") >= 14) {

            document.getElementById("search").style.display = "none";
            document.getElementById("avancee").innerHTML = "+";
        }

//        input_search = document.getElementById("inputsearch");
        taille_width = 120 - ((GetCookie("length") - 11) * 40);
        if (taille_width < 40) {
            taille_width = 40;
        }

//        input_search.style.width = (taille_width) + "px";
    }

}

function ShowMenu(id, id2) {

    var d = document.getElementById(id);
    var a = document.getElementById(id2);
    for (var i = 0; i <= 9; i++) {
        if (document.getElementById('smenu' + i)) { document.getElementById('smenu' + i).style.display = 'none'; document.getElementById('title' + i).style.background = 'none'; }

    }
    if (d) {
        d.style.display = 'block'; a.style.backgroundImage = 'url("/Assets/Images/menu_bg_on.gif")';

        /* needed for IE 7 */
        if (navigator.appVersion.indexOf("MSIE") != -1) {
            temp = navigator.appVersion.split("MSIE")
            version = parseFloat(temp[1])
            if (version == 7) {
                if (GetCookie("length") > 11) {
                    d.style.marginTop = "-2px";
                }
                else {
                    d.style.marginTop = "0px";
                }
            }
        }
    }
}


window.onload = startpage;
