﻿var _Browser = {};
function DetectBrowser() {
    var ua = navigator.userAgent.toLowerCase();

    var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
    /(webkit)[ \/]([\w.]+)/.exec(ua) ||
    /(opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) ||
    /(msie) ([\w.]+)/.exec(ua) ||
    !/compatible/.test(ua) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(ua) ||
    [];

    var browser = match[1]
    if (browser == "mozilla" && ua.indexOf("safari") == -1) {
        _Browser.FF = true;
        _Browser.IsIE = false;
        _Browser.IsChrome = false;
        _Browser.UnKnown = false;
    }
    else if (browser == "msie") {
        _Browser.FF = false;
        _Browser.IsIE = true;
        _Browser.IsChrome = false;
        _Browser.UnKnown = false;        
        _Browser.IsIE6 = typeof (_isIE6) != 'undefined' && _isIE6 == true;
    }
    else if (browser == "chrome") {
        _Browser.FF = false;
        _Browser.IsIE = false;
        _Browser.IsChrome = true;
        _Browser.UnKnown = false;
    }
    else {
        _Browser.FF = false;
        _Browser.IsIE = false;
        _Browser.IsChrome = false;
        _Browser.UnKnown = true;
    }
}
DetectBrowser();

function ChangeSearchType(obj) {
    TurnSearchTypesOff();
    obj.parentNode.className = "active";

    var position = "hp";
    var queryInputObj = null;
    var query = null;

    queryInputObj = document.getElementById("q" + position);
    if (queryInputObj == null) {
        position = "hdr";
        queryInputObj = document.getElementById("q" + position);
    }

    if (queryInputObj != null) {
        query = queryInputObj.value;

        var url = obj.getAttribute("url");
        if (url.indexOf("http://isearch.avg.com") > -1) { // Reset to Web Search
            document.getElementById("searchForm_" + position).action = "/search";
            document.getElementById("searchBtn" + position).onclick = function () {
                var position = "hp";
                var queryInputObj = null;
                var query = null;

                queryInputObj = document.getElementById("q" + position);
                if (queryInputObj == null) {
                    position = "hdr";
                    queryInputObj = document.getElementById("q" + position);
                }

                document.getElementById("searchForm_" + position).submit();
                /*
                if (queryInputObj != null) {
                    if (document.getElementById("q" + position).value != '') {
                        document.getElementById("searchForm_" + position).submit();
                    }
                    else {
                        queryInputObj.focus();
                    }
                }*/
            }

            document.getElementById("searchForm_" + position).submit();
            /*
            if (query != null && query != "" && window.location.href.indexOf("q=" + query + "&") == -1)
                document.getElementById("searchForm_" + position).submit();
            else
                queryInputObj.focus();*/

            return false;
        }

        if (obj.href != 'javascript:void(0);') {
            obj.href = url + "&q=" + encodeURI(query);
            return true;
        }
        else {
            queryInputObj.focus();
            return false;
        }
        /*
        if (query != null && query != "") { //There is a query in the search box            
            obj.href = url + "&q=" + encodeURI(query);
            return true;
        }
        else { //search box is empty
            queryInputObj.focus();
            document.getElementById("searchForm_" + position).action = url;
            document.getElementById("searchBtn" + position).onclick = function () {
                var position = "hp";
                var queryInputObj = null;
                var query = null;

                queryInputObj = document.getElementById("q" + position);
                if (queryInputObj == null) {
                    position = "hdr";
                    queryInputObj = document.getElementById("q" + position);
                }

                if (queryInputObj != null) {
                    query = queryInputObj.value;
                    if (query != null && query != "") {
                        window.location.href = document.getElementById("searchForm_" + position).action + "&q=" + encodeURI(query);
                        return false;
                    }
                    else {
                        queryInputObj.focus();
                    }
                }
            }

            return false; //To disable the href search
        }*/
    }
}

function TurnSearchTypesOff() {
    var lis = document.getElementById("HeaderLinks").getElementsByTagName("li");
    for (var i = 0; i < lis.length; i++) {
        if (lis[i].className != "more")
            lis[i].className = "";
    }
}


/////Deprecated, Use setUrlSideNav(obj)  Yuval Pinkas Nov 20 2011
//function SideNav_Click(obj) {
//    debugger;
//    var position = "hp";
//    var queryInputObj = null;
//    var query = null;    
//    
//    queryInputObj = document.getElementById("q" + position);
//    if (queryInputObj == null) {
//        position = "hdr";
//        queryInputObj = document.getElementById("q" + position);
//    }
//    
//    if (queryInputObj != null) {
//        query = queryInputObj.value;
//        if (obj.href != 'javascript:void(0);') {
//            obj.href = obj.href.indexOf("&q=") == -1 ? obj.href : obj.href.substr(0, obj.href.indexOf("&q="));
//            obj.href = obj.href + "&q=" + encodeURI(query);
//            return true;
//        }
//        else {
//            queryInputObj.focus();
//            return false;
//        }
//    }
//}


function setUrlSideNav(obj) {

    var position = "hp";
    var queryInputObj = null;
    var query = null;
    queryInputObj = document.getElementById("q" + position);
    if (queryInputObj == null) {
        position = "hdr";
        queryInputObj = document.getElementById("q" + position);
    }

    if (queryInputObj != null) {
        query = queryInputObj.value;
        if (obj.href != 'javascript:void(0);') {
            obj.href = obj.href.indexOf("&q=") == -1 ? obj.href : obj.href.substr(0, obj.href.indexOf("&q="));
            obj.href = obj.href + "&q=" + encodeURI(query);
        }
        else {
            queryInputObj.focus();
        }
    }

}


function GetHP() {
    var _IEInstallationFolderName = "AVG Secure Search";
    var homePage = "";
    if (typeof window.toolbarhomeAPI != "undefined") {
        var xpcom = window.toolbarhomeAPI;
        homePage = xpcom.wrappedJSObject.GetHomePage();
    }
    else {
        //IE
        try {
            var sh = new ActiveXObject('ScriptHelper.ScriptHelperApi');
            var bOK = sh.SelectToolbar(_IEInstallationFolderName);
            if (bOK == true) {
                homePage = sh.CurrentHP;
            }
        }
        catch (e) { }
    }
    
    if (homePage == "") {
        homePage = GetHPFromCookie(); 
    }
    return homePage;
}

function GetHPFromCookie() {
    var allCookies = document.cookie.split(';');
    for (i = 0; i < allCookies.length; i++) {
        currCookie = allCookies[i].split('=');
        cookieName = currCookie[0].replace(/^\s+|\s+$/g, '');

        if (cookieName == "aHomePageValue" && currCookie.length > 1) {            
            return unescape(currCookie[1].replace(/^\s+|\s+$/g, ''));
        }
    }

    return "";
}

function SetHPCookie(homepage) {
    var expireDate = new Date();
    expireDate.setDate(expireDate.getDate() + 365);


    document.cookie = "aHomePageValue=" + escape(homepage) +
                      ";expires=" + expireDate.toGMTString() +
                      ";domain=avg.com";
}

function DisplaySetHomepageBtn(btnId) {

//    document.getElementById(btnId).style.display = 'inline-block';
//    return;
    if (document.getElementById(btnId)) {
        //TODO remove this part when we have graphics for FF & CHROME
        if (_Browser.IsChrome) {
            document.getElementById(btnId).style.display = 'none';
            return;
        }
                
        if (_Browser.FF && (typeof window.toolbarhomeAPI == "undefined")) {
            document.getElementById(btnId).style.display = 'none';
            return;
        }

        var hp = (GetHP());        
        if (hp.indexOf("avg.com") == -1) {
            document.getElementById(btnId).style.display = 'inline-block';
        }
        else {
            document.getElementById(btnId).style.display = 'none';
        }
    }
}

function SetHP(btnId) {    
    var homepageToSet = "http://isearch.avg.com/?" + location.search.substring(1);
    
    if (_Browser.FF) {
        if (typeof window.toolbarhomeAPI != "undefined") {
            var _partnerIdentifier = "avg";
            var xpcom = window.toolbarhomeAPI;
            resultJSON = xpcom.wrappedJSObject.SetHomePage(_partnerIdentifier);
        }
        else {
            //TODO call function to show FF homepage change graphics
            SetHPCookie(homepageToSet);
        }

    } else if (_Browser.IsIE) {
        var resultJSON = "";
        try {
            var _IEInstallationFolderName = "AVG Secure Search";
            var sh = new ActiveXObject('ScriptHelper.ScriptHelperApi');
            var bOK = sh.SelectToolbar(_IEInstallationFolderName);
            if (bOK == true) {
                resultJSON = sh.SetHomepage();
                if (typeof JSON != 'undefined')
                {
                    resultJSON = JSON.parse(resultJSON);
                }
                else {                    
                    if (resultJSON.indexOf("Success") != -1) {
                        resultJSON = {};
                        resultJSON.Success = true;
                    }
                }
            }
        }
        catch (e) { }

        if (resultJSON.Success) {
            //TODO call function to show IE success message            
        }
        else {            
            SetHPCookie(homepageToSet);
            //setting HP throgh IE dialog
            document.body.style.behavior = 'url(#default#homepage)';
            document.body.setHomePage(homepageToSet);
        }        
    } else if (_Browser.IsChrome) {
        SetHPCookie(homepageToSet);
        //TODO call dialog to explain Chrome HP setting
    }

    //hiding both buttons
    DisplaySetHomepageBtn("SetHPBtnHeaderNav");
    DisplaySetHomepageBtn("SetHPBtn");  
}


/*---------------- Jquery from p2h ------------------*/
window.ie = jQuery.browser.msie && jQuery.browser.version < 7 ? true : false;
$(function () {
    DetectBrowser(); 
    addClass({
        tagName: 'a.lang',
        classAdd: 'active-drop',
        addToParent: true
    });
    //if (window.ie) DD_belatedPNG.fix('.png');
    initOc({
        listOc: '.container ul.menu',
        linkMore: 'a.less',
        visibleEleaments: 5,
        closeClass: 'closed',
        textOpen: typeof lessLabel != "undefined" ? lessLabel : 'Less',
        textClose: typeof moreLabel != "undefined" ? moreLabel : 'More'
    });
    clientScript();
});

function clientScript() {
    var w = $(document).width() - 1;
    var h = $('.pop').height() + 15;
    //h = h > 335 ? h : 335;
    var title = $('h5').html();
    if (title) {
        title = title.replace(/<.+>|<.+>.+<\/>/gi, '');
        if (title.length > 42) {
            $('.pop').css('width', '550px');
            w = 550;
        }
    }
}


function initOc(opt) {
   
    var defaultOptions = {
        listOc: 'ul.accordion',
        linkMore: 'a.more',
        visibleEleaments: 5,
        closeClass: 'closed',
        textOpen: 'Less',
        textClose: 'More'
    }
    if (!opt) opt = defaultOptions;

    $(opt.listOc).each(function () {
        var list = $(this);
        var link = list.find(opt.linkMore);
        list.children().filter(':gt(' + (opt.visibleEleaments - 1) + ')').not(link.parent()).not('.google-links').css({ 'opacity': 0, 'display': 'none' });
        link.text(opt.textClose).parent().addClass(opt.closeClass);
        link.click(function () {
            if ($(this).parent().hasClass(opt.closeClass)) {
                $(this).text(opt.textOpen).parent().removeClass(opt.closeClass);
                if (_Browser.IsIE6) $(this).text(opt.textOpen).parent().css('margin-top', '0px');
                list.children().slideDown(300);
                list.children().animate({ opacity: 1 }, { queue: false, duration: 1000 })
            }
            else {
                $(this).text(opt.textClose).parent().addClass(opt.closeClass);
                if (_Browser.IsIE6) $(this).text(opt.textClose).parent().css('margin-top', '-30px');
                var cached = list.children().filter(':gt(' + (opt.visibleEleaments - 1) + ')').not(link.parent()).not('.google-links');
                cached.slideUp(500);
                cached.animate({ opacity: 0 }, { queue: false, duration: 300 })
            }
            return false;
        });
    });
    if (_Browser.IsIE6) $('li.closed').css('margin-top', '-30px');
}

function ieHover() { hoverForIE6('#nav li', 'hover') }

function addClass(_options) {
    var _tagName = _options.tagName;
    var _classAdd = _options.classAdd;
    var _addToParent = false || _options.addToParent;
    var _el = $('body').find(_tagName);

    _el.each(function () {
        var _this = $(this);
        _this.click(function () {
            if (_addToParent) {
                if (_this.parent().hasClass(_classAdd)) {
                    _this.parent().removeClass(_classAdd);
                }
                else {
                    _this.parent().addClass(_classAdd);
                }
            }
            else {
                if (_this.hasClass(_classAdd)) {
                    _this.removeClass(_classAdd);
                }
                else {
                    _this.addClass(_classAdd);
                }
            }
            return false;
        });
    });
}

// IE 6 hover plugin
eval(function (p, a, c, k, e, r) { e = function (c) { return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) r[e(c)] = k[c] || e(c); k = [function (e) { return r[e] } ]; e = function () { return '\\w+' }; c = 1 }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p } ('9 u=k(){9 g=/^([^#.>`]*)(#|\\.|\\>|\\`)(.+)$/;k u(a,b){9 c=a.J(/\\s*\\,\\s*/);9 d=[];n(9 i=0;i<c.l;i++){d=d.v(o(c[i],b))};6 d};k o(a,b,c){a=a.z(" ","`");9 d=a.r(g);9 e,5,m,7,i,h;9 f=[];4(d==8){d=[a,a]};4(d[1]==""){d[1]="*"};4(c==8){c="`"};4(b==8){b=E};K(d[2]){w"#":7=d[3].r(g);4(7==8){7=[8,d[3]]};e=E.L(7[1]);4(e==8||(d[1]!="*"&&!x(e,d[1]))){6 f};4(7.l==2){f.A(e);6 f};6 o(7[3],e,7[2]);w".":4(c!=">"){5=p(b,d[1])}y{5=b.B};n(i=0,h=5.l;i<h;i++){e=5[i];4(e.C!=1){q};7=d[3].r(g);4(7!=8){4(e.j==8||e.j.r("(\\\\s|^)"+7[1]+"(\\\\s|$)")==8){q};m=o(7[3],e,7[2]);f=f.v(m)}y 4(e.j!=8&&e.j.r("(\\\\s|^)"+d[3]+"(\\\\s|$)")!=8){f.A(e)}};6 f;w">":4(c!=">"){5=p(b,d[1])}y{5=b.B};n(i=0,h=5.l;i<h;i++){e=5[i];4(e.C!=1){q};4(!x(e,d[1])){q};m=o(d[3],e,">");f=f.v(m)};6 f;w"`":5=p(b,d[1]);n(i=0,h=5.l;i<h;i++){e=5[i];m=o(d[3],e,"`");f=f.v(m)};6 f;M:4(c!=">"){5=p(b,d[1])}y{5=b.B};n(i=0,h=5.l;i<h;i++){e=5[i];4(e.C!=1){q};4(!x(e,d[1])){q};f.A(e)};6 f}};k p(a,b){4(b=="*"&&a.F!=8){6 a.F};6 a.p(b)};k x(a,b){4(b=="*"){6 N};6 a.O.G().z("P:","")==b.G()};6 u}();k Q(a,b){9 c=u(a);n(9 i=0;i<c.l;i++){c[i].R=k(){4(t.j.H(b)==-1){t.j+=" "+b}};c[i].S=k(){4(t.j.H(b)!=-1){t.j=t.j.z(b,"")}}}}4(D.I&&!D.T){D.I("U",V)}', 58, 58, '||||if|listNodes|return|subselector|null|var||||||||limit||className|function|length|listSubNodes|for|doParse|getElementsByTagName|continue|match||this|parseSelector|concat|case|matchNodeNames|else|replace|push|childNodes|nodeType|window|document|all|toLowerCase|indexOf|attachEvent|split|switch|getElementById|default|true|nodeName|html|hoverForIE6|onmouseover|onmouseout|opera|onload|ieHover'.split('|'), 0, {}))

/**
* DD_belatedPNG: Adds IE6 support: PNG images for CSS background-image and HTML <IMG/>.
* Author: Drew Diller
* Email: drew.diller@gmail.com
* URL: http://www.dillerdesign.com/experiment/DD_belatedPNG/
* Version: 0.0.8a
* Licensed under the MIT License: http://dillerdesign.com/experiment/DD_belatedPNG/#license
*
* Example usage:
* DD_belatedPNG.fix('.png_bg'); // argument is a CSS selector
* DD_belatedPNG.fixPng( someNode ); // argument is an HTMLDomElement
**/
//var DD_belatedPNG = { ns: "DD_belatedPNG", imgSize: {}, delay: 10, nodesFixed: 0, createVmlNameSpace: function () { if (document.namespaces && !document.namespaces[this.ns]) { document.namespaces.add(this.ns, "urn:schemas-microsoft-com:vml") } }, createVmlStyleSheet: function () { var b, a; b = document.createElement("style"); b.setAttribute("media", "screen"); document.documentElement.firstChild.insertBefore(b, document.documentElement.firstChild.firstChild); if (b.styleSheet) { b = b.styleSheet; b.addRule(this.ns + "\\:*", "{behavior:url(#default#VML)}"); b.addRule(this.ns + "\\:shape", "position:absolute;"); b.addRule("img." + this.ns + "_sizeFinder", "behavior:none; border:none; position:absolute; z-index:-1; top:-10000px; visibility:hidden;"); this.screenStyleSheet = b; a = document.createElement("style"); a.setAttribute("media", "print"); document.documentElement.firstChild.insertBefore(a, document.documentElement.firstChild.firstChild); a = a.styleSheet; a.addRule(this.ns + "\\:*", "{display: none !important;}"); a.addRule("img." + this.ns + "_sizeFinder", "{display: none !important;}") } }, readPropertyChange: function () { var b, c, a; b = event.srcElement; if (!b.vmlInitiated) { return } if (event.propertyName.search("background") != -1 || event.propertyName.search("border") != -1) { DD_belatedPNG.applyVML(b) } if (event.propertyName == "style.display") { c = (b.currentStyle.display == "none") ? "none" : "block"; for (a in b.vml) { if (b.vml.hasOwnProperty(a)) { b.vml[a].shape.style.display = c } } } if (event.propertyName.search("filter") != -1) { DD_belatedPNG.vmlOpacity(b) } }, vmlOpacity: function (b) { if (b.currentStyle.filter.search("lpha") != -1) { var a = b.currentStyle.filter; a = parseInt(a.substring(a.lastIndexOf("=") + 1, a.lastIndexOf(")")), 10) / 100; b.vml.color.shape.style.filter = b.currentStyle.filter; b.vml.image.fill.opacity = a } }, handlePseudoHover: function (a) { setTimeout(function () { DD_belatedPNG.applyVML(a) }, 1) }, fix: function (a) { if (this.screenStyleSheet) { var c, b; c = a.split(","); for (b = 0; b < c.length; b++) { this.screenStyleSheet.addRule(c[b], "behavior:expression(DD_belatedPNG.fixPng(this))") } } }, applyVML: function (a) { a.runtimeStyle.cssText = ""; this.vmlFill(a); this.vmlOffsets(a); this.vmlOpacity(a); if (a.isImg) { this.copyImageBorders(a) } }, attachHandlers: function (i) { var d, c, g, e, b, f; d = this; c = { resize: "vmlOffsets", move: "vmlOffsets" }; if (i.nodeName == "A") { e = { mouseleave: "handlePseudoHover", mouseenter: "handlePseudoHover", focus: "handlePseudoHover", blur: "handlePseudoHover" }; for (b in e) { if (e.hasOwnProperty(b)) { c[b] = e[b] } } } for (f in c) { if (c.hasOwnProperty(f)) { g = function () { d[c[f]](i) }; i.attachEvent("on" + f, g) } } i.attachEvent("onpropertychange", this.readPropertyChange) }, giveLayout: function (a) { a.style.zoom = 1; if (a.currentStyle.position == "static") { a.style.position = "relative" } }, copyImageBorders: function (b) { var c, a; c = { borderStyle: true, borderWidth: true, borderColor: true }; for (a in c) { if (c.hasOwnProperty(a)) { b.vml.color.shape.style[a] = b.currentStyle[a] } } }, vmlFill: function (e) { if (!e.currentStyle) { return } else { var d, f, g, b, a, c; d = e.currentStyle } for (b in e.vml) { if (e.vml.hasOwnProperty(b)) { e.vml[b].shape.style.zIndex = d.zIndex } } e.runtimeStyle.backgroundColor = ""; e.runtimeStyle.backgroundImage = ""; f = true; if (d.backgroundImage != "none" || e.isImg) { if (!e.isImg) { e.vmlBg = d.backgroundImage; e.vmlBg = e.vmlBg.substr(5, e.vmlBg.lastIndexOf('")') - 5) } else { e.vmlBg = e.src } g = this; if (!g.imgSize[e.vmlBg]) { a = document.createElement("img"); g.imgSize[e.vmlBg] = a; a.className = g.ns + "_sizeFinder"; a.runtimeStyle.cssText = "behavior:none; position:absolute; left:-10000px; top:-10000px; border:none; margin:0; padding:0;"; c = function () { this.width = this.offsetWidth; this.height = this.offsetHeight; g.vmlOffsets(e) }; a.attachEvent("onload", c); a.src = e.vmlBg; a.removeAttribute("width"); a.removeAttribute("height"); document.body.insertBefore(a, document.body.firstChild) } e.vml.image.fill.src = e.vmlBg; f = false } e.vml.image.fill.on = !f; e.vml.image.fill.color = "none"; e.vml.color.shape.style.backgroundColor = d.backgroundColor; e.runtimeStyle.backgroundImage = "none"; e.runtimeStyle.backgroundColor = "transparent" }, vmlOffsets: function (d) { var h, n, a, e, g, m, f, l, j, i, k; h = d.currentStyle; n = { W: d.clientWidth + 1, H: d.clientHeight + 1, w: this.imgSize[d.vmlBg].width, h: this.imgSize[d.vmlBg].height, L: d.offsetLeft, T: d.offsetTop, bLW: d.clientLeft, bTW: d.clientTop }; a = (n.L + n.bLW == 1) ? 1 : 0; e = function (b, p, q, c, s, u) { b.coordsize = c + "," + s; b.coordorigin = u + "," + u; b.path = "m0,0l" + c + ",0l" + c + "," + s + "l0," + s + " xe"; b.style.width = c + "px"; b.style.height = s + "px"; b.style.left = p + "px"; b.style.top = q + "px" }; e(d.vml.color.shape, (n.L + (d.isImg ? 0 : n.bLW)), (n.T + (d.isImg ? 0 : n.bTW)), (n.W - 1), (n.H - 1), 0); e(d.vml.image.shape, (n.L + n.bLW), (n.T + n.bTW), (n.W), (n.H), 1); g = { X: 0, Y: 0 }; if (d.isImg) { g.X = parseInt(h.paddingLeft, 10) + 1; g.Y = parseInt(h.paddingTop, 10) + 1 } else { for (j in g) { if (g.hasOwnProperty(j)) { this.figurePercentage(g, n, j, h["backgroundPosition" + j]) } } } d.vml.image.fill.position = (g.X / n.W) + "," + (g.Y / n.H); m = h.backgroundRepeat; f = { T: 1, R: n.W + a, B: n.H, L: 1 + a }; l = { X: { b1: "L", b2: "R", d: "W" }, Y: { b1: "T", b2: "B", d: "H"} }; if (m != "repeat" || d.isImg) { i = { T: (g.Y), R: (g.X + n.w), B: (g.Y + n.h), L: (g.X) }; if (m.search("repeat-") != -1) { k = m.split("repeat-")[1].toUpperCase(); i[l[k].b1] = 1; i[l[k].b2] = n[l[k].d] } if (i.B > n.H) { i.B = n.H } d.vml.image.shape.style.clip = "rect(" + i.T + "px " + (i.R + a) + "px " + i.B + "px " + (i.L + a) + "px)" } else { d.vml.image.shape.style.clip = "rect(" + f.T + "px " + f.R + "px " + f.B + "px " + f.L + "px)" } }, figurePercentage: function (d, c, f, a) { var b, e; e = true; b = (f == "X"); switch (a) { case "left": case "top": d[f] = 0; break; case "center": d[f] = 0.5; break; case "right": case "bottom": d[f] = 1; break; default: if (a.search("%") != -1) { d[f] = parseInt(a, 10) / 100 } else { e = false } } d[f] = Math.ceil(e ? ((c[b ? "W" : "H"] * d[f]) - (c[b ? "w" : "h"] * d[f])) : parseInt(a, 10)); if (d[f] % 2 === 0) { d[f]++ } return d[f] }, fixPng: function (c) { c.style.behavior = "none"; var g, b, f, a, d; if (c.nodeName == "BODY" || c.nodeName == "TD" || c.nodeName == "TR") { return } c.isImg = false; if (c.nodeName == "IMG") { if (c.src.toLowerCase().search(/\.png$/) != -1) { c.isImg = true; c.style.visibility = "hidden" } else { return } } else { if (c.currentStyle.backgroundImage.toLowerCase().search(".png") == -1) { return } } g = DD_belatedPNG; c.vml = { color: {}, image: {} }; b = { shape: {}, fill: {} }; for (a in c.vml) { if (c.vml.hasOwnProperty(a)) { for (d in b) { if (b.hasOwnProperty(d)) { f = g.ns + ":" + d; c.vml[a][d] = document.createElement(f) } } c.vml[a].shape.stroked = false; c.vml[a].shape.appendChild(c.vml[a].fill); c.parentNode.insertBefore(c.vml[a].shape, c) } } c.vml.image.shape.fillcolor = "none"; c.vml.image.fill.type = "tile"; c.vml.color.fill.on = false; g.attachHandlers(c); g.giveLayout(c); g.giveLayout(c.offsetParent); c.vmlInitiated = true; g.applyVML(c) } }; try { document.execCommand("BackgroundImageCache", false, true) } catch (r) { } DD_belatedPNG.createVmlNameSpace(); DD_belatedPNG.createVmlStyleSheet();

/*---------------- end of Jquery from p2h ------------------*/
/*---------------- Language Selector -----------------------*/
var langCalloutOpen = false;

function openCloseLangCallout() {
    document.onclick = closeLangList;
    window.onresize = closeLangList;
    var langCallout = document.getElementById("langCallout");
    if (langCallout.className.indexOf("invisible") != -1) {
        langCallout.className = "";
        langCalloutOpen = true;
    }
    else {
        langCallout.className = "invisible";
        langCalloutOpen = false;
    }

    if (_Browser.IsIE) {
        langCallout.style.left = (document.getElementById("openCloseLang").offsetLeft - 387).toString() + "px";
    }
    else {
        langCallout.style.left = (document.getElementById("openCloseLang").offsetLeft - 400).toString() + "px";
    }
    langCallout.style.top = (document.getElementById("openCloseLang").offsetTop + 20).toString() + "px";
}

function closeLangList() {
    if (!langCalloutOpen) return;
    document.getElementById("langCallout").className = "invisible"; ;
}

function onLoadBody() {
    if (document.getElementById("searchButton").offsetWidth > 75)
        document.getElementById("searchButton").style.width = "92px";
    else
        document.getElementById("searchButton").style.width = "66px";     
}

function stopPropagation(event) {
    if (event.bubbles == undefined)
        event.cancelBubble = true;
    else if (event.bubbles)
        event.stopPropagation();
}

function getCategory_openCloseLang(obj) {

    var category = "languages_link_open";
    var parentLi = $(obj).parent();
    var liClass = $(parentLi).attr('class');
    if (liClass.indexOf("active-drop") === -1) {
        category = "languages_link_close";
    }
    return category;
}

$(document).ready(function () {

    $("a[category=languages_link_select]").each(function (index) {
        _lang = $(this).attr("label");
        SetLangsURL(this, _lang);
    });

});

function SetLangsURL(aObj, lang) {

    url = document.URL;
    //Before using the url the old analytics params must be removed:
    url = removeParameter(url, "act");
    url = removeParameter(url, "cat");
    url = removeParameter(url, "lbl");

    var currentLang = $.getUrlVar('cklang');

    if (typeof currentLang === "undefined") {
        var char = (url.indexOf('?') != -1) ? "&" : "?"
        aObj.href = url + char + "cklang=" + lang;
    }
    else {
        aObj.href = url.replace("cklang=" + currentLang, "cklang=" + lang);
    }

}


function removeParameter(url, parameter) {
    var urlparts = url.split('?');

    if (urlparts.length >= 2) {
        var urlBase = urlparts.shift(); //get first part, and remove from array
        var queryString = urlparts.join("?"); //join it back up

        var prefix = encodeURIComponent(parameter) + '=';
        var pars = queryString.split(/[&;]/g);
        for (var i = pars.length; i-- > 0; )               //reverse iteration as may be destructive
            if (pars[i].lastIndexOf(prefix, 0) !== -1)   //idiom for string.startsWith
                pars.splice(i, 1);
        url = urlBase + '?' + pars.join('&');
    }
    return url;
}




/*---------------- End of Language Selector -----------------------*/






//Deprecated by Yuval Pinkas Nov 23 2012
function SetMoreLangURL(aObj, lang) {
    if (aObj.href.indexOf("/?cklang=") != -1) {
        var url = document.URL;
        var ckLang = "cklang=";
        var cklangPos = url.indexOf(ckLang);
        if (cklangPos != -1) {
            var ampPos = url.indexOf("&", cklangPos);
            if (ampPos == -1) //cklang is the last param
                aObj.href = url.substring(0, cklangPos) + ckLang + lang;
            else
                aObj.href = url.substring(0, cklangPos) + ckLang + lang + url.substring(ampPos);
        }
        else {
            aObj.href = url + (url.indexOf("?") == -1 ? "?" : "&") + ckLang + lang;
        }
    }
}

function openFlyover(obj) {
    obj.getElementsByTagName("div")[0].className = "avgnotice open";
}

function closeFlyover(obj) {
    obj.className = "avgnotice";
}

