// Functions throws an error for empty labels
//window.onload=function(){
//    if(document.all&&navigator.appVersion.indexOf("MSIE")>-1&&navigator.appVersion.indexOf("Windows")>-1)
//
//    {
//        var a=document.getElementsByTagName("label");
//        for(var i=0,j=a.length;i<j;i++){
//            if(a[i].hasChildNodes&&a[i].childNodes.item(0).tagName=="IMG")
//
//            {
//                a[i].childNodes.item(0).forid=a[i].htmlFor;
//                a[i].childNodes.item(0).onclick=function(){
//                    var e=document.getElementById(e.target.forid);
//                    switch(e.type){
//                        case"radio":
//                            e.checked|=1;
//                            break;
//                        case"checkbox":
//                            e.checked=!e.checked;
//                            break;
//                        case"text":case"password":case"textarea":
//                            e.focus();
//                            break;
//                    }
//                }
//            }
//        }
//    }
//}
stuHover = function() {
    var browserVersion = navigator.appVersion;
    if (browserVersion.indexOf("MSIE 6.0") >= 0) {
        var cssRule;
        var newSelector;
        for (var i = 0; i < document.styleSheets.length; i++)
            for (var x = 0; x < document.styleSheets[i].rules.length; x++) {
            if (document.styleSheets[i].href.indexOf("domainNav.css" >= 0)) {
                cssRule = document.styleSheets[i].rules[x];
                if (cssRule.selectorText.indexOf("LI:hover") != -1) {
                    newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
                    document.styleSheets[i].addRule(newSelector, cssRule.style.cssText);
                }
            }
        }
        var items = new Array('navScience', 'navMedicine', 'navTechnology', 'navSociety', 'navCulture');
        for (var i = 0; i < items.length; i++) {
            IE6Fix(items[i]);
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", stuHover);
function IE6Fix(listItemId) {
    var getElm = $("." + listItemId + " li");
    for (var i = 0; i < getElm.length; i++) {
        getElm[i].onmouseover = function() {
            this.className += " iehover";
        }
        getElm[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" iehover\\b"), "");
        }
    }
}
function toggle() {
    var sert = document.getElementById("searchBtn");
    var ele = document.getElementById("toggleText");
    var text = document.getElementById("displayText");
    if (ele.style.display == "block") {
        ele.style.display = "none";
        text.style.width = "106px";
        ele.style.height = "25px";
        sert.style.height = "25px";
    }
    else {
        ele.style.display = "block";
        text.style.width = "106px";
        ele.style.width = "315px";
        ele.style.marginLeft = "106px";
        sert.style.height = "25px";
        sert.style.overflow = "hidden";
        ele.style.height = "25px";
    }
}
var ddsmoothmenu = {
    arrowimages: {
        down: ['downarrowclass', 'down.gif', 23],
        right: ['rightarrowclass', 'images/sub_trans.gif', 'images/sub1.gif']
    },
    transition: {
        overtime: 300,
        outtime: 300
    },
    shadow: {
        enable: false,
        offsetx: 5,
        offsety: 5
    },
    detectwebkit: navigator.userAgent.toLowerCase().indexOf("applewebkit") != -1,
    detectie6: document.all && !window.XMLHttpRequest,
    getajaxmenu: function($, setting) {
        var $menucontainer = $('#' + setting.contentsource[0])
        $menucontainer.html("Loading Menu...")
        $.ajax({
            url: setting.contentsource[1],
            async: true,
            error: function(ajaxrequest) {
                $menucontainer.html('Error fetching content. Server Response: ' + ajaxrequest.responseText)
            },
            success: function(content) {
                $menucontainer.html(content)
                ddsmoothmenu.buildmenu($, setting)
            }
        })
    },
    buildmenu: function($, setting) {
        var smoothmenu = ddsmoothmenu
        var $mainmenu = $("#" + setting.mainmenuid + ">ul")
        $mainmenu.parent().get(0).className = setting.classname || "ddsmoothmenu"
        $(".ulLeft .liFirst>a").addClass("firstLevelMenu");
        var $headers = $mainmenu.find("ul").parent()
        $headers.hover(function(e) {
            $(this).children('a:eq(0)').addClass('selected')
        }, function(e) {
            $(this).children('a:eq(0)').removeClass('selected')
        })
        $headers.each(function(i) {
            var $curobj = $(this).css({
                zIndex: 100 - i
            })
            var $subul = $(this).find('ul:eq(0)').css({
                display: 'block'
            })
            this._dimensions = {
                w: this.offsetWidth,
                h: this.offsetHeight,
                subulw: $subul.outerWidth(),
                subulh: $subul.outerHeight()
            }
            this.istopheader = $curobj.parents("ul").length == 1 ? true : false
            $subul.css({
                top: this.istopheader && setting.orientation != 'v' ? this._dimensions.h + "px" : 0
            })
            $curobj.children("a:eq(0)").css(this.istopheader ? {
                paddingRight: smoothmenu.arrowimages.down[2]
} : {}).append('<img src="' + (this.istopheader && setting.orientation != 'v' ? smoothmenu.arrowimages.down[1] : smoothmenu.arrowimages.right[1])
                + '" class="' + (this.istopheader && setting.orientation != 'v' ? smoothmenu.arrowimages.down[0] : smoothmenu.arrowimages.right[0])
                + '" style="border:0" />')
                if (smoothmenu.shadow.disable) {
                    this._shadowoffset = {
                        x: (this.istopheader ? $subul.offset().left + smoothmenu.shadow.offsetx : this._dimensions.w),
                        y: (this.istopheader ? $subul.offset().top + smoothmenu.shadow.offsety : $curobj.position().top)
                    }
                    if (this.istopheader)
                        $parentshadow = $(document.body)
                    else {
                        var $parentLi = $curobj.parents("li:eq(0)")
                        $parentshadow = $parentLi.get(0).$shadow
                    }
                    this.$shadow = $('<div class="ddshadow' + (this.istopheader ? ' toplevelshadow' : '') + '"></div>').prependTo($parentshadow).css({
                        left: this._shadowoffset.x + 'px',
                        top: this._shadowoffset.y + 'px'
                    })
                }
                $curobj.hover(function(e) {
                    var $targetul = $(this).children("ul:eq(0)")
                    $($targetul).parent(":first").children(":first").addClass("menuMouseOver");
                    $($targetul).parent(":first").children(":first").html($($targetul).parent(":first").children(":first").html().replace(smoothmenu.arrowimages.right[1], smoothmenu.arrowimages.right[2]));
                    this._offsets = {
                        left: $(this).offset().left,
                        top: $(this).offset().top
                    }
                    var menuleft = this.istopheader && setting.orientation != 'v' ? 0 : this._dimensions.w
                    menuleft = (this._offsets.left + menuleft + this._dimensions.subulw > $(window).width()) ? (this.istopheader && setting.orientation != 'v' ? -this._dimensions.subulw + this._dimensions.w : -this._dimensions.w) : menuleft
                    if ($targetul.queue().length <= 1) {
                        $targetul.css({
                            left: menuleft + "px",
                            width: this._dimensions.subulw + 'px'
                        }).animate({
                            height: 'show',
                            opacity: 'show'
                        }, ddsmoothmenu.transition.overtime)
                        if (smoothmenu.shadow.enable) {
                            var shadowleft = this.istopheader ? $targetul.offset().left + ddsmoothmenu.shadow.offsetx : menuleft
                            var shadowtop = this.istopheader ? $targetul.offset().top + smoothmenu.shadow.offsety : this._shadowoffset.y
                            if (!this.istopheader && ddsmoothmenu.detectwebkit) {
                                this.$shadow.css({
                                    opacity: 1
                                })
                            }
                            this.$shadow.css({
                                overflow: '',
                                width: this._dimensions.subulw + 'px',
                                left: shadowleft + 'px',
                                top: shadowtop + 'px'
                            }).animate({
                                height: this._dimensions.subulh + 'px'
                            }, ddsmoothmenu.transition.overtime)
                        }
                    }
                }, function(e) {
                    var $targetul = $(this).children("ul:eq(0)")
                    $($targetul).parent(":first").children(":first").removeClass("menuMouseOver");
                    $($targetul).parent(":first").children(":first").html($($targetul).parent(":first").children(":first").html().replace(smoothmenu.arrowimages.right[2], smoothmenu.arrowimages.right[1]));
                    $targetul.animate({
                        height: 'hide',
                        opacity: 'hide'
                    }, ddsmoothmenu.transition.outtime)
                    if (smoothmenu.shadow.enable) {
                        if (ddsmoothmenu.detectwebkit) {
                            this.$shadow.children('div:eq(0)').css({
                                opacity: 0
                            })
                        }
                        this.$shadow.css({
                            overflow: 'hidden'
                        }).animate({
                            height: 0
                        }, ddsmoothmenu.transition.outtime)
                    }
                })
            })
            $mainmenu.find("ul").css({
                display: 'none',
                visibility: 'visible'
            })
        },
        init: function(setting) {
            if (typeof setting.customtheme == "object" && setting.customtheme.length == 2) {
                var mainmenuid = '#' + setting.mainmenuid
                var mainselector = (setting.orientation == "v") ? mainmenuid : mainmenuid + ', ' + mainmenuid
                document.write('<style type="text/css">\n'
                + mainselector + ' ul li a {background:' + setting.customtheme[0] + ';}\n'
                + mainmenuid + ' ul li a:hover {background:' + setting.customtheme[1] + ';}\n'
                + '</style>')
            }
            this.shadow.enable = (document.all && !window.XMLHttpRequest) ? false : this.shadow.enable
            jQuery(document).ready(function($) {
                if (typeof setting.contentsource == "object") {
                    ddsmoothmenu.getajaxmenu($, setting)
                }
                else {
                    ddsmoothmenu.buildmenu($, setting)
                }
            })
        },
        changeArrow: function(imageObj) {
            imageObj.src = this.arrowimages.right[2];
        }
    }
    function toggleNav(nav_img, nav_sec) {
        var e = document.getElementById(nav_sec).style;

        if (nav_img.className == 'closed') {
            nav_img.className = '';
            // e.height='auto';
            if ($("div#" + nav_sec + " UL").length != 0) {
                $("div#" + nav_sec + " UL").slideToggle();
            }
            else {
                $("div#" + nav_sec + " div.togglerowCover").slideToggle();
            }
            // e.overflow='';
        } else {
            nav_img.className = 'closed';
            if ($("div#" + nav_sec + " UL").length != 0) {
                $("div#" + nav_sec + " UL").slideToggle();
            }
            else {
                $("div#" + nav_sec + " div.togglerowCover").slideToggle();
            }
            //e.overflow='hidden';
            //e.height='25px';  
        }
        padNav();
    }
    function toggleNavbyID(nav_img, nav_sec) {
        if (nav_img.className == 'closed') { nav_img.className = ''; $("div#info div#" + nav_sec).slideToggle(); } else { nav_img.className = 'closed'; $("div#info div#" + nav_sec).slideToggle(); }
        padNav();
    }
    function toggleNav_generic(elm, sub_elm) { var obj_elm = $(elm); if (obj_elm.parent().hasClass('closed')) { obj_elm.parent().parent().children(sub_elm).slideDown(1000); obj_elm.parent().removeClass('closed'); } else { obj_elm.parent().parent().children(sub_elm).slideUp(1000); obj_elm.parent().addClass('closed'); } }

    function toggleQuestion(nav_img, nav_sec) {
        var e = document.getElementById(nav_sec).style;

        if ($("div#" + nav_sec + " .qstArrow").is('.closed')) {
            //alert("hi");
            $("div#" + nav_sec + " .qstArrow").removeClass('closed');
            //nav_img.className='';
            // e.height='auto';
            $("div#" + nav_sec + " .divtoHide").slideToggle();
            // e.overflow='';
        } else {//alert("hi 22");
            $("div#" + nav_sec + " .qstArrow").addClass('closed');
            //nav_img.className='closed';
            $("div#" + nav_sec + " .divtoHide").slideToggle();
            //e.overflow='hidden';
            //e.height='25px';  
        }
        padNav();
    }

    function toggleNav_txt(nav_img, nav_sec) {
        var e = document.getElementById(nav_sec).style;
        if (nav_img.className == 'closed') {
            nav_img.className = '';
            e.height = 'auto';
            e.overflow = '';
            e.float = 'left';
        } else {
            nav_img.className = 'closed';
            e.overflow = 'hidden';
            e.height = '16px';
        }
        padNav();
    }
    function toggleNav_thfve(nav_img, nav_sec) {
        var e = document.getElementById(nav_sec).style;
        if (nav_img.className == 'closed') {
            nav_img.className = '';
            e.height = 'auto';
            e.overflow = '';
            e.float = 'left';
        } else {
            nav_img.className = 'closed';
            e.overflow = 'hidden';
            e.height = '35px';
        }
        padNav();
    }
    function toggle_visibility(id) {
        var e = document.getElementById(id);
        if (e.style.display == 'block') {
            e.style.display = 'none';
        } else
        { e.style.display = 'block'; }
    }
    function deactivate_menus() {
        $('.atlData').hide();
        $(this).parent().children('.altData').show();
        //$(this).parent().children('.altData').show();alert($(this).parent().className);
    }
    function padNav() {
        var a, b, n, blankSpace;
        if (n = document.getElementById('navBlankBottom')) {
            n.style.height = '1px';
            if (a = document.getElementById('leftNavigation')) {
                if (b = document.getElementById('leftColumn')) {
                    blankSpace = a.offsetHeight - b.offsetHeight;
                    n.style.height = blankSpace + 'px';
                }
            }
        }
    }
    function addOnloadEvent(fnc) {
        if (typeof window.addEventListener != "undefined") window.addEventListener("load", fnc, false);
        else if (typeof window.attachEvent != "undefined") window.attachEvent("onload", fnc);
        else {
            if (window.onload != null) {
                var oldOnload = window.onload;
                window.onload = function(e) {
                    oldOnload(e);
                    window[fnc]();
                };

            } else window.onload = fnc;
        }
    }


    /*-------------------------------------Custom Alert Boxes using ASP.NET AJAX Modal Popup control-------------------------------
    *   Author: Ashok S
    *   Created: 11/11/2009
    *   Last modified: 19/1/2010
    */

    var MODAL_POPUP_ID = "ModalPopupExtender1";
    var GENERIC_HEADER_TEXT = "Frontiers";

    /*frontiersAlert popup class definition
    *   Parameters:
    *               modalId - ClientID of the Modal Popup
    *               holderDivID - ID of the popup holder div
    */
    function frontiersAlert(modalId, holderDivID) {
        modalPopupID = modalId,
    alertHolderDIVID = holderDivID
    }

    /*Shows an alert popup equivalent to normal javascript alert
    *   Parameters:
    *               headerText - Popup header text
    *               alertMessage - Alert message text
    *               okButtonText - OK button text
    *               okCallbackFunction - Function to be executed on OK button click
    */
    frontiersAlert.prototype.alert = function(headerText, alertMessage, okButtonText, okCallbackFunction) {
        var alertDiv = $get(alertHolderDIVID);
        var strAlertBoxBuilder = new Sys.StringBuilder();

        strAlertBoxBuilder.append("<div style=\"margin: 0pt auto; display: block; width: 320px;\" rel=\"grey\" class=\"shadow\">");
        strAlertBoxBuilder.append("<div style=\"display: block;width: 300px; height: auto;\" rel=\"grey\" class=\"popupWrapp bbw10 w500pop \">");
        strAlertBoxBuilder.append("<div class=\"w100pc float_left\">");
        strAlertBoxBuilder.append("<h2>");
        strAlertBoxBuilder.append(headerText == null || headerText == "" ? GENERIC_HEADER_TEXT : headerText);
        strAlertBoxBuilder.append("</h2>");
        strAlertBoxBuilder.append("<div class=\"popupContent\">");

        //Popup content
        strAlertBoxBuilder.append(alertMessage);

        //OK button
        strAlertBoxBuilder.append("<div class=\"w100pc float_right mt25\">");
        strAlertBoxBuilder.append("<div class=\" float_right pr10 \">");
        strAlertBoxBuilder.append("<a id=\"aOK\" href=\"javascript:void(0)\" class=\"BLUE25 \" onclick=\"");
        strAlertBoxBuilder.append("closeFrontiersAlert('" + okCallbackFunction + "', '" + alertHolderDIVID + "', '" + modalPopupID + "')\">");
        strAlertBoxBuilder.append("<span>");
        strAlertBoxBuilder.append(okButtonText);
        strAlertBoxBuilder.append("</span></a>");
        strAlertBoxBuilder.append("</div>");

        //Close button
        //strAlertBoxBuilder.append("<div class=\"closeWindow\"><a href=\"javascript:void(0)\"><img border=\"0\" title=\"Close\" alt=\"Close\" src=\"_layouts/images/frontiers/closeIcon.gif\" onclick=\"");
        //strAlertBoxBuilder.append("closeFrontiersAlert('" + okCallbackFunction + "', '" + alertHolderDIVID + "', '" + modalPopupID + "')\"/>");
        //strAlertBoxBuilder.append("</a></div>");

        strAlertBoxBuilder.append("</div></div></div><div class=\"clear\"/></div></div>");
        alertDiv.innerHTML = strAlertBoxBuilder.toString();
        var modalPopupBehaviorCtrl = $find(modalPopupID);
        modalPopupBehaviorCtrl.set_PopupControlID(alertHolderDIVID);
        modalPopupBehaviorCtrl.initialize();
        modalPopupBehaviorCtrl.show();
        $get("aOK").focus();
    }

    function toggleEditBox(editBox, state, txtcmtBox) {

        toggleDisplayByClassName("commentbox", null, "div", "none");
        var ctrl = document.getElementById(editBox);
        var ctrltxt = document.getElementById(txtcmtBox);
        if (ctrltxt != null) {
            ctrltxt.value = "";
        }
        if (state == 1) {
            ctrl.style.display = "block";
        }
        else {
            ctrl.style.display = "none";
        }
        return false;
    }
    function getElementsByClass(searchClass, domNode, tagName) {
        if (domNode == null) domNode = document;
        if (tagName == null) tagName = '*';
        var el = new Array();
        var tags = domNode.getElementsByTagName(tagName);
        var tcl = " " + searchClass + " ";
        for (i = 0, j = 0; i < tags.length; i++) {
            var test = " " + tags[i].className + " ";
            if (test.indexOf(tcl) != -1)
                el[j++] = tags[i];
        }
        return el;
    }

    function toggleDisplayByClassName(searchClass, domNode, tagName, displayMode) {

        var divlist = getElementsByClass(searchClass, domNode, tagName);
        for (var i = 0; i < divlist.length; i++) {
            divlist[i].style.display = displayMode;
        }
    }

    /*Closes the Alert Box
    *  Parameters:
    *  modalPopupID - Client ID of the modal popup extender
    *  alertHolderDIVID - The main DIV that holds the alert pop up div
    *  okCallbackFunction - Function to be executed on OK button click
    */
    function closeFrontiersAlert(okCallbackFunction, alertHolderDIVID, modalPopupID) {
        var modalPopupBehaviorCtrl = $find(modalPopupID);
        modalPopupBehaviorCtrl.hide();
        if (okCallbackFunction != null && okCallbackFunction != "undefined" && okCallbackFunction != "") {
            eval(okCallbackFunction + "()");
        }
    }

    /*Performs action on the 'OK' click of confirm box
    *  Parameters:
    *  modalPopupID - Client ID of the modal popup extender
    *  alertHolderDIVID - The main DIV that holds the alert pop up div
    *  okCallbackFunction - Function to be executed on OK button click
    *  postbackControlID - Client ID of the control that will postback on the 'OK' click of the confirm popup
    */
    function closeFrontiersAlertOK(okCallbackFunction, alertHolderDIVID, modalPopupID, postbackControlID) {
        var modalPopupBehaviorCtrl = $find(modalPopupID);
        modalPopupBehaviorCtrl.hide();

        if (okCallbackFunction != null && okCallbackFunction != "undefined" && okCallbackFunction != "") {
            eval(okCallbackFunction + "()");
        }

        var postbackControl = $get(postbackControlID);
        var postbackControlType = postbackControl != null || postbackControl != "undefined" ? postbackControl.nodeName.toUpperCase() : "";

        //checking the control type and then do postback accordingly
        if (postbackControlType != "" && postbackControlType == "INPUT") {
            postbackControl.click();
        }
        else if (postbackControl != "" && postbackControlType == "A") {

            var postbackControlHref = unescape(postbackControl.href);
            eval(postbackControlHref);
        }
    }

    /*Shows an confirm popup equivalent to normal javascript confirm
    *   Parameters:
    *               headerText - Popup header text
    *               alertMessage - Alert message text
    *               okButtonText - OK button text
    *               okCallbackFunction - Function to be executed on OK button click
    *               linkButtonID - Client ID of the linkbutton that will postback on the 'OK' click of the confirm popup
    */
    frontiersAlert.prototype.confirm = function(headerText, alertMessage, okButtonText, cancelButtonText, linkButtonID, okCallbackFunction, cancelCallbackFunction) {
        var alertDiv = $get(alertHolderDIVID);
        var strAlertBoxBuilder = new Sys.StringBuilder();

        strAlertBoxBuilder.append("<div style=\"margin: 0pt auto; display: block; width: 320px;\" rel=\"grey\" class=\"shadow\">");
        strAlertBoxBuilder.append("<div style=\"display: block;width: 300px; height: auto;\" rel=\"grey\" class=\"popupWrapp bbw10 w500pop \">");
        strAlertBoxBuilder.append("<div class=\"w100pc float_left\">");
        strAlertBoxBuilder.append("<h2>");
        strAlertBoxBuilder.append(headerText == null || headerText == "" ? GENERIC_HEADER_TEXT : headerText);
        strAlertBoxBuilder.append("</h2>");
        strAlertBoxBuilder.append("<div class=\"popupContent\">");

        //Popup content
        strAlertBoxBuilder.append(alertMessage);

        //Cancel button
        strAlertBoxBuilder.append("<div class=\"w100pc float_right mt25\">");
        strAlertBoxBuilder.append("<div class=\" float_right pr10 \">");
        strAlertBoxBuilder.append("<a id=\"aCancel\" href=\"javascript:void(0)\" class=\"grey25 \" onclick=\"");
        strAlertBoxBuilder.append("closeFrontiersAlert('" + okCallbackFunction + "', '" + alertHolderDIVID + "', '" + modalPopupID + "')\"/>");
        strAlertBoxBuilder.append("<span>");
        strAlertBoxBuilder.append(cancelButtonText);
        strAlertBoxBuilder.append("</span></a>");
        strAlertBoxBuilder.append("</div>");

        //OK button
        strAlertBoxBuilder.append("<div class=\" float_right\">");
        strAlertBoxBuilder.append("<a id=\"aOK\" href=\"javascript:void(0)\" class=\"BLUE25 \" onclick=\"");
        strAlertBoxBuilder.append("return closeFrontiersAlertOK('" + okCallbackFunction + "', '" + alertHolderDIVID + "', '" + modalPopupID + "', '" + linkButtonID + "')\">");
        strAlertBoxBuilder.append("<span>");
        strAlertBoxBuilder.append(okButtonText);
        strAlertBoxBuilder.append("</span></a>");
        strAlertBoxBuilder.append("</div>");

        //Close button
       // strAlertBoxBuilder.append("<div class=\"closeWindow\"><a href=\"javascript:void(0)\"><img border=\"0\" title=\"Close\" alt=\"Close\" src=\"_layouts/images/frontiers/closeIcon.gif\" onclick=\"");
        //strAlertBoxBuilder.append("closeFrontiersAlert('" + okCallbackFunction + "', '" + alertHolderDIVID + "', '" + modalPopupID + "')\"/>");
        //strAlertBoxBuilder.append("</a></div>");

        strAlertBoxBuilder.append("</div></div></div><div class=\"clear\"/></div></div>");
        alertDiv.innerHTML = strAlertBoxBuilder.toString();
        var modalPopupBehaviorCtrl = $find(modalPopupID);
        modalPopupBehaviorCtrl.set_PopupControlID(alertHolderDIVID);
        modalPopupBehaviorCtrl.initialize();
        modalPopupBehaviorCtrl.show();
        $get("aCancel").focus();
        return false;
    }

    function decodeURL(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

    var pageoverlay = function(x) {
        var elm = "<div id='frontiersmodal-overlay' class='frontiersmodal-overlay' style='display:none;'></div>";
        $('#main_wrapper').append(elm);

        $('div#frontiersmodal-overlay').css("width", $(window).width());
        $('div#frontiersmodal-overlay').css("height", $(window).height());
        $('div#frontiersmodal-overlay').css("position", "fixed");
        $('div#frontiersmodal-overlay').css("background-color", "#111");
        if (x == '0') { $('div#frontiersmodal-overlay').css("cursor", "default"); } else { $('div#frontiersmodal-overlay').addClass("active"); }
        $('div#frontiersmodal-overlay').css("opacity", "0.5");
        $('div#frontiersmodal-overlay').css("z-index", "1001");
        $('div#frontiersmodal-overlay').css("top", "0");
        $('div#frontiersmodal-overlay').css("left", "0");
        $('div#frontiersmodal-overlay').fadeIn("slow");
    };
    
    
    $(document).ready(function() {
        $('.setfocus').addClass("grey_70");
        $('.setfocus').live('focus', function() {
            $(this).removeClass("grey_70").addClass("grey_90");
            if (this.value == this.defaultValue) {
                this.value = '';
            }
            if (this.value != this.defaultValue) {
                this.select();
            }
        });
        $('.setfocus').live('blur', function() {
            if ($.trim(this.value) == '') {
                $(this).removeClass("grey_90").addClass("grey_70");
                this.value = (this.defaultValue ? this.defaultValue : '');
            }
        });
    });

    $(document).ready(function() {

        var currentPosition = 0;
        var editPosition = 0;
        var temp_ml = 0;

        var slideWidth = 124;
        var slides = $('.slidetn');
        var numberOfSlides = slides.length;
        $('#totalNos').text(numberOfSlides);
        // Remove scrollbar in JS
        $('#slidesContainertn').css('overflow', 'hidden');

        // Wrap all .slides with #slideInner div
        slides
    .wrapAll('<div id="slideInnertn"></div>')
        // Float left to display horizontally, readjust .slides width
	.css({
	    'float': 'left',
	    'width': slideWidth
	});

        // Set #slideInner width equal to total width of all slides
        $('#slideInnertn').css('width', slideWidth * numberOfSlides);

        //    AssignIndex();
        if ($('#ctl00_ContentAreaMainContent_PostingDetails1_hdnImageIndex')) {
            // alert("AAAAAAAAAAAAAAAAAAAAAAAAAAAA");
            if ($('#ctl00_ContentAreaMainContent_PostingDetails1_hdnImageIndex').val() == "") {
                currentPosition = 0;
                //   alert("BBBBBBBBBBBBBBBBBBBb");

            }
            else {
                // debugger;
                //  alert("CCCCCCCCCCCCCCCCCCCCCCCCc");
                editPosition = $('#ctl00_ContentAreaMainContent_PostingDetails1_hdnImageIndex').val();
                // alert(editPosition);
                temp_ml = (editPosition - 1) * 124;
                if (document.getElementById('slideInnertn')) {
                    //   alert('hi');
                    document.getElementById('slideInnertn').style.marginLeft = "-" + temp_ml + "px";
                    $('#currentNo').text(editPosition);
                    //manageControls(editPosition);
                    currentPosition = editPosition - 1;
                }
            }
        }




        // Insert controls in the DOM
        $('#slideshowtn')
    .append('<span class="controltn" id="leftControltn">Clicking moves left</span>')
    .append('<span class="controltn" id="rightControltn">Clicking moves right</span>');





        // Hide left arrow control on first load
        manageControls(currentPosition);

        // Create event listeners for .controls clicks
        $('.controltn')
    .bind('click', function() {
        //debugger;
        // Determine new position

        currentPosition = ($(this).attr('id') == 'rightControltn') ? parseInt(currentPosition) + 1 : parseInt(currentPosition) - 1;
        $('#currentNo').text(currentPosition + 1);

        $('#ctl00_ContentAreaMainContent_PostingDetails1_hdnImageIndex').val(currentPosition + 1);

        // Hide / show controls
        manageControls(currentPosition);
        // Move slideInner using margin-left
        $('#slideInnertn').animate({
            'marginLeft': slideWidth * (-currentPosition)
        });
    });

        // manageControls: Hides and Shows controls depending on currentPosition
        function manageControls(position) {
            // Hide left arrow if position is first slide
            if (position == 0) { $('#leftControltn').hide() } else { $('#leftControltn').show() }
            // Hide right arrow if position is last slide
            if (position >= numberOfSlides - 1) { $('#rightControltn').hide() } else { $('#rightControltn').show() }
        }

    });

    //added by jacob

   /* $(".showPrivacy").click(function() {
        //$(this).removeClass("following").addClass("unfollow"); 
        // $("body").css("opacity","0.4");
        // $("body").css("filter","alpha(opacity=40)");
        if (($(window).width() - ($(window).width() - $(this).offset().left - 52)) > 600) {
            $('div#basicModalContent').css("left", "");
            $('div#basicModalContent').css("top", "");
            $('div#basicModalContent').css("right", "");
            if ($(this).hasClass("IAggreg")) {
                if ($.browser.msie && parseInt($.browser.version, 10) == 7) { $('div#basicModalContent').css("top", (($(this).offset().top + 30) + "px")); } else { $('div#basicModalContent').css("top", (($(this).offset().top + 12) + "px")); }
                $('div#basicModalContent').css("right", ($(window).width() - $(this).offset().left - 47 + "px"));
            }
            else {
                $('div#basicModalContent').css("top", (($(this).offset().top + 16) + "px"));
                $('div#basicModalContent').css("right", ($(window).width() - $(this).offset().left - 53 + "px"));
            }
        }
        else {
            if ($(this).hasClass("IAggreg")) { if ($.browser.msie && parseInt($.browser.version, 10) == 7) { $('div#basicModalContent').css("top", (($(this).offset().top + 30) + "px")); } else { $('div#basicModalContent').css("top", (($(this).offset().top + 12) + "px")); } }
            else { $('div#basicModalContent').css("top", (($(this).offset().top + 16) + "px")); }

            $('div#basicModalContent').css("left", ($(this).offset().left + "px"));

        }
        $('div#basicModalContent').css("position", "absolute");
        //$('div#basicModalContent').center();
        pageoverlay('0');
        $('div#basicModalContent').fadeIn("slow");


    }

						);
*/

    $(document).click(function(e) {


        if (($(e.target).is('a.profileImgSave span')) || ($(e.target).is('input.profileImgSave'))) { $('#popupScrlHolder').hide(); $('.imgareaselect-outer').hide(); }
        if ($(e.target).is("a.showPrivacy")) {
            // alert($(e.target).offset());
            var temptxt = "";
            temptxt = temptxt + "position:absolute;";
            //            alert(temptxt);
            //            temptxt = temptxt + ("top:" + ($(e.target).offset().top) + "px;");
            //            alert(temptxt);

            if (($(window).width() - ($(window).width() - $(e.target).offset().left - 52)) > 600) {
                //alert("first");
                if ($(e.target).hasClass("IAggreg")) {
                    if ($.browser.msie && parseInt($.browser.version, 10) == 7) {
                        temptxt = temptxt + ("top:" + ($(e.target).offset().top + 30) + "px;");
                    } else {
                       // alert("hello");
                        temptxt = temptxt + ("top:" + ($(e.target).offset().top + 12) + "px;");
                    }
                    temptxt = temptxt + "right:" + ($(window).width() - $(e.target).offset().left - 47) + "px;";
                }
                else {
                    //alert("hello 123 3  3 ");
                    temptxt = temptxt + ("top:" + ($(e.target).offset().top + 16) + "px;");
                    temptxt = temptxt + "right:" + ($(window).width() - $(e.target).offset().left - 39) + "px;";
                }
            }
            else {
                //alert("second");
                if ($(e.target).hasClass("IAggreg")) {
                    if ($.browser.msie && parseInt($.browser.version, 10) == 7) {
                        temptxt = temptxt + ("top:" + ($(e.target).offset().top + 30) + "px;");
                    } else {
                        temptxt = temptxt + ("top:" + ($(e.target).offset().top + 12) + "px;");
                    }
                } else {
                    temptxt = temptxt + ("top:" + ($(e.target).offset().top + 16) + "px;");
                }
                temptxt = temptxt + ("left:" + ($(e.target).offset().left) + "px;");
            }

            //temptxt = temptxt + ("top:" + ($(e.target).offset().top + 16) + "px");
            //$('div#basicModalContent').css("top", (($(e.target).offset().top + 16) + "px"));
            //temptxt = temptxt + "right:" + ($(window).width() - $(e.target).offset().left - 53) + "px;";  
            //$('div#basicModalContent').css("right", ($(window).width() - $(e.target).offset().left - 53 + "px"));

            //}

            // temptxt = temptxt + "right:" + ($(window).width() - $(e.target).offset().left - 38) + "px;";
            // }
            //  else {
            //      temptxt = temptxt + "left:" + ($(e.target).offset().left - 14) + "px;";
            //   }
            // alert(temptxt);
            pageoverlay('0');
            $(".hndStyle").val(temptxt);
            //            if ($('#basicmodalcontent').length > 0) {
            //                $('#basicmodalcontent').modal();
            //            }
        }




    });
    




    //$(document).ready(function() { if ($('textarea.autoext').length > 0) { $('textarea.autoext').elastic(); $('textarea.autoext').trigger('update'); } $(".btnFollow").hover(function() { $(".sbox").hide(); $(this).children('div.sbox').fadeIn(1100); }, function() { $(this).children('div.sbox').fadeOut(1100); setTimeout(function() { $('.scrlBlock').children().remove(); }, 1100); }); $(".btnFollow15").hover(function() { $(".sbox").hide(); $(this).parent('div.EventpeopleListing').css('overflow', 'visible'); $(this).children('div.sbox').fadeIn(1100); }, function() { $(this).children('div.sbox').fadeOut(1100); $(this).parent('div.EventpeopleListing').css('overflow', 'hidden'); }); $(".listIconholder").click(function() { $(".sbox").hide(); $(this).children('div.sbox').fadeIn("slow"); }); $(".listHolder").click(function() { $(this).children('div.sbox').fadeIn("slow"); }); $(".shareFeed").click(function() { pageoverlay('1'); $('div.boxwithShadowX').fadeIn("slow"); $('div.boxwithShadowX div.shareTxt textarea').focus(); $('div.boxwithShadowX').center(); }); $(".showPrivacy").click(function() { $('div.boxwithShadowX').css("top", ($(this).offset().top + "px")); if (($(window).width() - ($(window).width() - $(this).offset().left - 52)) > 600) { $('div.boxwithShadowX').css("left", ""); $('div.boxwithShadowX').css("right", ($(window).width() - $(this).offset().left - 52 + "px")); } else { $('div.boxwithShadowX').css("right", ""); $('div.boxwithShadowX').css("left", ($(this).offset().left + "px")); } $('div.boxwithShadowX').fadeIn("slow"); }); $(".addtoListlink").click(function() { $(".sbox").hide(); $(this).parent().children('div.sbox').fadeIn("slow"); }); $('#linktxt').live('focus', function() { $(this).parents("div.linkTxt").children('div.addBtn').addClass("greyAdd"); }); $('#linktxt').live('blur', function() { if ($.trim(this.value) == '') { $(this).parents("div.linkTxt").children('div.addBtn').removeClass("greyAdd"); } }); $('.write').live('focus', function() { $(this).parents("div.commentBox").children('div.commentAddWrap').children('div.addBtnComment').addClass("greyAdd"); }); $('.write').live('blur', function() { if (($.trim(this.value) == '') || ($.trim(this.value) == $.trim(this.defaultValue))) { $(this).parents("div.commentBox").children('div.commentAddWrap').children('div.addBtnComment').removeClass("greyAdd"); } }); });
    jQuery.fn.center = function() { this.css("position", "absolute"); this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px"); this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px"); return this; }
    jQuery.fn.cw_center = function() { this.css("position", "absolute"); this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px"); this.css("left", (($('#content_wrapper').width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px"); return this; }
    
    var pageoverlay = function(x){var elm = "<div id='frontiersmodal-overlay' class='frontiersmodal-overlay' style='display:none;'></div>"; $('#main_wrapper').append(elm); $('div#frontiersmodal-overlay').css("width", $(window).width()); $('div#frontiersmodal-overlay').css("height", $(window).height());$('div#frontiersmodal-overlay').css("position", "fixed"); $('div#frontiersmodal-overlay').css("background-color", "#111"); if (x == '0') { $('div#frontiersmodal-overlay').css("cursor", "wait"); } else { $('div#frontiersmodal-overlay').addClass("active"); }; $('div#frontiersmodal-overlay').css("opacity", "0.5"); $('div#frontiersmodal-overlay').css("z-index", "1001"); $('div#frontiersmodal-overlay').css("top", "0");$('div#frontiersmodal-overlay').css("left", "0"); $('div#frontiersmodal-overlay').fadeIn("slow");};

    //$(".btnFollow").hover(function() { $(".sbox").hide(); $(this).children('div.sbox').fadeIn(1100); }, function() { $(this).children('div.sbox').fadeOut(1100); setTimeout(function() { $('.scrlBlock').children().remove(); }, 1100); });
    //$(".btnFollow15").hover(function() { $(".sbox").hide(); $(this).parent('div.EventpeopleListing').css('overflow', 'visible'); $(this).children('div.sbox').fadeIn(1100); }, function() { $(this).children('div.sbox').fadeOut(1100); $(this).parent('div.EventpeopleListing').css('overflow', 'hidden'); });
    $(document).ready(function() { if ($('textarea.autoext').length > 0) { $('textarea.autoext').elastic(); $('textarea.autoext').trigger('update'); }; $(".listHolder").click(function() { $(this).children('div.sbox').fadeIn("slow"); }); $(".shareFeed").click(function() { $('div.boxwithShadowX').fadeIn("slow"); $('div.boxwithShadowX div.shareTxt textarea').focus(); $('div.boxwithShadowX').center(); }); $(".showPrivacy").click(function() { $('div.boxwithShadowX').css("top", ($(this).offset().top + "px")); if (($(window).width() - ($(window).width() - $(this).offset().left - 52)) > 600) { $('div.boxwithShadowX').css("left", ""); $('div.boxwithShadowX').css("right", ($(window).width() - $(this).offset().left - 52 + "px")); } else { $('div.boxwithShadowX').css("right", ""); $('div.boxwithShadowX').css("left", ($(this).offset().left + "px")); } $('div.boxwithShadowX').fadeIn("slow"); }); $(".addtoListlink").click(function() { $(".sbox").hide(); $(this).parent().children('div.sbox').fadeIn("slow"); }); $('#linktxt').live('focus', function() { $(this).parents("div.linkTxt").children('div.addBtn').addClass("greyAdd"); }); $('#linktxt').live('blur', function() { if ($.trim(this.value) == '') { $(this).parents("div.linkTxt").children('div.addBtn').removeClass("greyAdd"); } }); $('.write').live('focus', function() { $(this).parents("div.commentBox").children('div.commentAddWrap').children('div.addBtnComment').addClass("greyAdd"); }); $('.write').live('blur', function() { if (($.trim(this.value) == '') || ($.trim(this.value) == $.trim(this.defaultValue))) { $(this).parents("div.commentBox").children('div.commentAddWrap').children('div.addBtnComment').removeClass("greyAdd"); } }); });
    $(document).click(function(e) { if (!$(e.target).parents().andSelf().is('.listIconholder')) { $(".listIconholder .sbox").hide(); } if (!$(e.target).parents().andSelf().is('.listHolder')) { $(".listHolder .sbox").hide(); } if (!$(e.target).parents().andSelf().is('.addtoListWrapper')) { $(".addtoListWrapper .sbox").hide(); }; if ($(e.target).parents().is('li.notify')) { $("div#popupNotification").css("z-index", 9999999); $('div#popupNotification').css("right", ("-" + $('ul#tslNav_right li.last').width() + "px")); $("span.holderNotify").css("background-color", "#ffffff"); if ($(e.target).is('li.notify span.notifications span')) { $("div#popupNotification").toggle('slow'); $(e.target).parents('span.notifications').addClass("default act"); $(e.target).text("0"); } else if ($(e.target).is('li.notify span.notifications')) { $("div#popupNotification").toggle('slow'); $(e.target).addClass("default act"); $(e.target).children('span').text("0"); } else if ($(e.target).is('li.notify ')) { $("div#popupNotification").toggle('slow'); $(e.target).children("span.notifications").addClass("default act"); $(e.target).children('span.notifications span').text("0"); } } if (!$(e.target).parents().is('li.notify')) { $("div#popupNotification").hide('slow'); $("span.holderNotify").css("background-color", "#7d7d7d"); $('span.notifications').removeClass("act"); } });
    // comments and share popups overlap issue fix
    $(function() { if ($('div.bubbleInfo').length > 0) { var zIndexNo = 300; $('div.bubbleInfo').each(function() { $(this).css('zIndex', zIndexNo); zIndexNo -= 1; }); } });

    $(function() {var ZINumber = 444;$('div.phFull').each(function() {$(this).css('zIndex', ZINumber);ZINumber -= 1;});});

