﻿/********Image Zomming Dark*************/
function GxMS_ShowImagePanel(imgUrl) {
    try {
        var options = SP.UI.$create_DialogOptions();
        options.allowMaximize = false;
        options.autoSize = true;
        options.url = imgUrl;
        SP.UI.ModalDialog.showModalDialog(options);
    }
    catch (err) {
        txt = "There was an error on this page 'GxMS_ShowImagePanel'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }

}
/********End Image Zomming Dark background*************/

/*************************************** CQWP XSL Functions ******************************************************/

/********CQWP GxMSGridBaseView Open/Close Description Functions*************/
/********Open/Close ALL Descriptions with Red Box around*************/
function displayDesSelected(tblID, Display, NewDisplay, ImgOpen, ImgClose, borderStyle) {
    try {
        
        var tbl = document.getElementById(tblID);
        var trs = tbl.getElementsByTagName('TR');
        var IDiv2 = 1;
        for (var i = 0; i < trs.length; i++) {
            if (trs[i].style.display == Display) {
                if (Display == "none") {
                    trs[i - 1].style.fontWeight = 'bold';
                    trs[i - 1].className = 'trSelected';
                    trs[i - 1].firstChild.style.borderRight = borderStyle;
                    trs[i - 1].lastChild.style.borderLeft = borderStyle;
                    trs[i].lastChild.style.borderLeft = borderStyle;
                }
                else {
                    trs[i - 1].style.fontWeight = 'normal';
                    trs[i - 1].className = 'trNoSelected';
                    trs[i - 1].firstChild.style.borderRight = "none";
                    trs[i - 1].lastChild.style.borderLeft = "none";
                    trs[i].lastChild.style.borderLeft = "none";
                    trs[i].style.display = 'none';
                }
                if (NewDisplay == 'block')
                    trs[i].style.display = '';
                else
                    trs[i].style.display = 'none';
                var imgs = trs[i - 1].getElementsByTagName("Img");
                for (j = 0; j < imgs.length; j++) {
                    if (imgs[j].name == ImgOpen)
                        imgs[j].style.display = Display;
                    if (imgs[j].name == ImgClose)
                        imgs[j].style.display = NewDisplay;
                }
            }
            else {
                if (i > 0) {
                    if (Display == 'block') {
                        if (IDiv2 == 0) {
                            trs[i - 1].style.fontWeight = 'normal';
                            trs[i - 1].className = 'trNoSelected';
                            trs[i - 1].firstChild.style.borderRight = "none";
                            trs[i - 1].lastChild.style.borderLeft = "none";
                            trs[i].lastChild.style.borderLeft = "none";
                            trs[i].style.display = 'none';
                            IDiv2 = 1;
                            var imgs = trs[i - 1].getElementsByTagName("Img");
                            for (j = 0; j < imgs.length; j++) {
                                if (imgs[j].name == ImgOpen)
                                    imgs[j].style.display = Display;
                                if (imgs[j].name == ImgClose)
                                    imgs[j].style.display = NewDisplay;
                            }
                        }
                        else {
                            IDiv2 = 0;
                        }
                    }
                }
            }

        }

    }
    catch (err) {
        txt = "There was an error on this page 'displayDesSelected'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}

/********End Open/Close ALL Descriptions with Red Box around*************/

/********Open/Close ALL Descriptions*************/
function displayDes(tblID, Display, NewDisplay, ImgOpen, ImgClose) {
    try {
        // debugger;        
        var tbl = document.getElementById(tblID);
        var trs = tbl.getElementsByTagName('TR');
        for (var i = 0; i < trs.length; i++) {
            //Show Description            
            if (trs[i].style.display == Display) {
                //Set Font Weight Bold To Line That Has Description
                if (Display == "none") {
                    trs[i - 1].style.fontWeight = 'bold';
                }
                else {
                    trs[i - 1].style.fontWeight = 'normal';
                    trs[i].style.display = 'none';
                }
                if (NewDisplay == 'block') {
                    // Not Write Block To Display Style
                    trs[i].style.display = '';
                }
                else {
                    trs[i].style.display = 'none';
                }
                //Change Image Of Open Close Description
                var imgs = trs[i - 1].getElementsByTagName("Img");
                for (j = 0; j < imgs.length; j++) {
                    if (imgs[j].name == ImgOpen)
                        imgs[j].style.display = Display;
                    if (imgs[j].name == ImgClose)
                        imgs[j].style.display = NewDisplay;
                }
            }
            //Hide Description
            else {
                //Start With Second TR Not TH
                if (i > 0) {
                    if (Display == 'block') {
                        //If Description Line                       
                        if (trs[i].name == 'TRDescription') {
                            trs[i - 1].style.fontWeight = 'normal';
                            trs[i].style.display = 'none';
                            var imgs = trs[i - 1].getElementsByTagName("Img");
                            for (j = 0; j < imgs.length; j++) {
                                if (imgs[j].name == ImgOpen)
                                    imgs[j].style.display = Display;
                                if (imgs[j].name == ImgClose)
                                    imgs[j].style.display = NewDisplay;
                            }
                        }
                    }
                }
            }

        }

    }
    catch (err) {
        txt = "There was an error on this page.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/********End Open/Close ALL Descriptions*************/
/********Open/Close ALL Descriptions by jQuery*************/
function displayDesJQuery(tblID, Display, NewDisplay, ImgOpen, ImgClose) {
    try {

        var currTbl = "#" + tblID;
        if (NewDisplay == 'block');
        {
            $(currTbl).find('.TRDesc').show();
            $(currTbl).find('img[name$="ImgGridViewOpen"]').hide();
            $(currTbl).find('img[name$="ImgGridViewClose"]').show();
        }
        if (NewDisplay == 'none') {
            $(currTbl).find('.TRDesc').hide();
            $(currTbl).find('img[name$="ImgGridViewClose"]').hide();
            $(currTbl).find('img[name$="ImgGridViewOpen"]').show();
        }
    }
    catch (err) {
        txt = "There was an error on this page.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/********End Open/Close ALL Descriptions by jQuery**************/


/********Open/Close Item Description function*************/
function displayCurrDescription(idImgOpen, idImgClose, currDesc, currTR) {

    try {
       
        var imgOpen = document.getElementById(idImgOpen);
        var imgClose = document.getElementById(idImgClose);
        var divMore = document.getElementById(currDesc);
        var trCurrent = document.getElementById(currTR);

        if (imgOpen != null) {

            if (imgOpen.style.display == 'block' || imgOpen.style.display == '') {
                imgOpen.style.display = 'none';
                if (imgClose != null)
                    imgClose.style.display = '';
                if (currTR != null) {

                    if (divMore != null)
                        divMore.style.display = '';
                    if (trCurrent != null)
                        trCurrent.style.fontWeight = 'bold';
                }
                else {
                    if (divMore != null)
                        divMore.style.display = 'block';
                }
            }
            else {

                imgOpen.style.display = '';
                if (imgClose != null)
                    imgClose.style.display = 'none';
                if (divMore != null)
                    divMore.style.display = 'none';
                if (trCurrent != null && currTR != null)
                    trCurrent.style.fontWeight = 'normal';
            }
        }
    }
    catch (err) {
        txt = "There was an error on this page 'displayCurrDescription'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/********End Open/Close Item Description function*************/

/********Open/Close Item Description function with RED Box around it*************/
function displayCurrDescriptionSelected(idImgOpen, idImgClose, currDesc, currTR, borderStyle) {

    try {
        
        var imgOpen = document.getElementById(idImgOpen);
        var imgClose = document.getElementById(idImgClose);
        var divMore = document.getElementById(currDesc);
        var trCurrent = document.getElementById(currTR);


        if (imgOpen != null) {

            if (imgOpen.style.display == 'block' || imgOpen.style.display == '') {
                imgOpen.style.display = 'none';
                if (imgClose != null)
                    imgClose.style.display = '';
                if (divMore != null)
                    divMore.style.display = '';
                if (trCurrent != null) {
                    trCurrent.style.fontWeight = 'bold';
                    trCurrent.className = 'trSelected';
                    document.getElementById(currTR).firstChild.style.borderRight = borderStyle;
                    document.getElementById(currTR).lastChild.style.borderLeft = borderStyle;
                    document.getElementById(currDesc).lastChild.style.borderLeft = borderStyle;
                }
            }
            else {

                imgOpen.style.display = '';
                if (imgClose != null)
                    imgClose.style.display = 'none';
                if (divMore != null)
                    divMore.style.display = 'none';
                if (trCurrent != null) {
                    trCurrent.style.fontWeight = 'normal';
                    trCurrent.className = 'trNoSelected';
                    document.getElementById(currTR).firstChild.style.borderRight = "none";
                    document.getElementById(currTR).lastChild.style.borderLeft = "none";
                    document.getElementById(currDesc).lastChild.style.borderLeft = "none";
                }
            }
        }
    }
    catch (err) {
        txt = "There was an error on this page 'displayCurrDescriptionSelected'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/********End Display Item Description function with RED Box around it*************/

/********End CQWP GxMSGridBaseView Open/Close Description Functions*************/


/********CQWP GxMSGridBaseView Print Description Function*************/
/********Print Item Description*************/
function PBtn_onclick(ContentToPrint) {
    try {
        var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
        disp_setting += "scrollbars=yes,width=850, height=600, left=100, top=25";
        var PHMC = document.getElementById(ContentToPrint);

        if (PHMC != null) {

            var content_vlue = PHMC.innerHTML;
            var docprint = window.open("", "", disp_setting);
            docprint.document.open();
            docprint.document.write('<html><head><title>GxMS Friendly Print</title>');
            docprint.document.write('<link rel="stylesheet" type="text/css" href="/Style%20Library/CustomToPrint.css');
            docprint.document.write('</head><body onLoad="self.print()"><center>');
            docprint.document.write(content_vlue);
            docprint.document.write('</center></body></html>');
            if (navigator.appName != "Microsoft Internet Explorer") {
                docprint.document.close();
            }
            else {
                docprint.location.reload(false);
            }
            docprint.focus();
        }
        else {
            window.print();
        }
    }
    catch (err) {
        txt = "There was an error on this page 'PBtn_onclick'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/********End Print Item Description*************/
/********End CQWP GxMSGridBaseView Print Description Function*************/
/*************************************** END CQWP XSL Functions ******************************************************/


/********Print content(with id "main-contentGxMS") and logo of page*************/
function FPBtn_onclick() {
    try {
        var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
        disp_setting += "scrollbars=yes,width=850, height=600, left=100, top=25";
        var PHMC = document.getElementById("main-contentGxMS");
        var HD = document.getElementById("logo");

        if (PHMC != null) {

            var content_vlue = PHMC.innerHTML;
            var header_vlue = HD.innerHTML;
            var docprint = window.open("", "", disp_setting);
            docprint.document.open();
            docprint.document.write('<html><head><title>GxMS Friendly Print</title>');
            docprint.document.write('<link rel="stylesheet" type="text/css" href="/Style%20Library/CustomToPrint.css');
            docprint.document.write('</head><body onLoad="self.print()">');
            docprint.document.write('<div><center>');
            docprint.document.write(header_vlue);
            docprint.document.write('</center></div>');
            docprint.document.write('<center>');
            docprint.document.write(content_vlue);
            docprint.document.write('</center></body></html>');
            if (navigator.appName != "Microsoft Internet Explorer") {
                docprint.document.close();
            }
            else {
                docprint.location.reload(false);
            }
            docprint.focus();
        }
        else {
            window.print();
        }
    }
    catch (err) {
        txt = "There was an error on this page 'FPBtn_onclick'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/********End Print content and logo of page*************/

/********Check if field over the max length*************/
function ismaxlength(field, maxChars, strError, strSymbol) {

    if (field.value.length > maxChars) {
        field.value = field.value.substring(0, maxChars)
        alert(strError + " " + maxChars + " " + strSymbol);
    }
}
/********End Check if field over the max length*************/

/*******QuickNavh*************/

var g_bIE4 = document.all && !document.getElementsByTagName;

var g_strImgChannelOpenHTML = "openArrow";
var g_strImgChannelClosedHTML = "closeArrow";
var g_strToggleIDSuffix = 'x';
var g_strToggleIDImgSuffix = 'imgx';
function toggleLayer(nID, sCloseOpenId, AltTextOpen, AltTextClose) {

    try {
        var pLayer;
        var pToggle;
        var pImgToggle;

        if (g_bIE4) {
            pLayer = document.all.item(nID);
            pToggle = document.all.item(sCloseOpenId + g_strToggleIDSuffix);
            pImgToggle = document.all.item(sCloseOpenId + g_strToggleIDImgSuffix);
        }
        else {

            pLayer = document.getElementById(nID);
            pToggle = document.getElementById(sCloseOpenId + g_strToggleIDSuffix);
            pImgToggle = document.getElementById(sCloseOpenId + g_strToggleIDImgSuffix);
            //alert(pToggle);
            //alert(nID);

        }

        if (pLayer.style.display != 'none' && pLayer.className != 'hideNode') {
            pLayer.className = 'hideList';
            pLayer.style.display = 'none';
            pToggle.className = g_strImgChannelOpenHTML;
            pImgToggle.setAttribute('alt', AltTextOpen);

        }
        else {

            if (pLayer.className == 'hideNode') {
                pLayer.className = 'hideList';
            }
            pLayer.style.display = 'block';
            pToggle.className = g_strImgChannelClosedHTML;
            pImgToggle.setAttribute('alt', AltTextClose);
        }
    }
    catch (err) {
        txt = "There was an error on this page 'toggleLayer'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}


/*******End QuickNavh*************/

/*******Open Dialog to show Video or Image from Media Gallery*************/

function ShowGalleryViewerMedia(MediaImageUrl, MediaEmbeddedCode, ImageWidth, ImageHeight, sWebId, sListId, sItemID, PanelLeft, PanelRight) {
    try {


        var options = SP.UI.$create_DialogOptions();
        options.allowMaximize = false;
        options.autoSize = true;
        MediaEmbeddedCode = escape(MediaEmbeddedCode);
        //MediaEmbeddedCode = MediaEmbeddedCode.toString().replace("&", "ampersandChar");
        var urlParam = "MediaImageUrl=" + MediaImageUrl + "&MediaEmbeddedCode=" + MediaEmbeddedCode + "&sWebId=" + sWebId + "&sListId=" + sListId + "&sItemID=" + sItemID;
        urlParam += "&ImageWidth=" + ImageWidth + "&ImageHeight=" + ImageHeight;
        options.url = location.protocol + '//' + location.host + "/Pages/ShowMedia.aspx?" + urlParam;
        SP.UI.ModalDialog.showModalDialog(options);
    }
    catch (err) {
        txt = "There was an error on this page 'ShowGalleryViewerMedia'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}

/*******End Open Dialog to show Video or Image from Media Gallery*************/

/*******Show Video or Image from Media Gallery*************/
function ShowMediaForDialog(MediaImageUrl, MediaEmbeddedCode, ImageWidth, ImageHeight, sWebId, sListId, sItemID) {
    try {
        
        var divEmbed = document.getElementById("divEmbed");
        var imgCtrl = document.getElementById("imgCtlDP");        
        if (MediaEmbeddedCode != "") {
            if (divEmbed != null) {
                MediaEmbeddedCode = unescape(MediaEmbeddedCode);
                //MediaEmbeddedCode = MediaEmbeddedCode.toString().replace("ampersandChar", "&");
                MediaEmbeddedCode = MediaEmbeddedCode.toString().replace("&lt;", "<");
                MediaEmbeddedCode = MediaEmbeddedCode.toString().replace("&gt;", ">");
                MediaEmbeddedCode = MediaEmbeddedCode.toString().replace("&amp;", "&");
                MediaEmbeddedCode = MediaEmbeddedCode.toString().replace("&quot;", "\"");               

                divEmbed.innerHTML = MediaEmbeddedCode;
                imgCtrl.style.display = "none";
                divEmbed.style.display = "block";
            }
        }
        else {

            if (imgCtrl != null) {
                imgCtrl.width = ImageWidth;
                imgCtrl.height = ImageHeight;  
                if (typeof (imgCtrl.src) != "undefined")
                    imgCtrl.src = MediaImageUrl;
                else
                    imgCtrl.innerHTML = MediaImageUrl;
                divEmbed.style.display = "none";
                imgCtrl.style.display = "block";
            }
        }

        Display_Internal_Content(sWebId, sListId, sItemID);
    }

    catch (err) {
        txt = "There was an error on this page 'ShowMediaForDialog'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/*******Show Video or Image from Media Gallery*************/


/*******Display item content *************/
function Display_Internal_Content(sWebId, sListId, sItemID) {

    try {
        DisplaywpRegistrationComment(sWebId, sListId, sItemID);
        DisplaywpRatings(sWebId, sListId, sItemID);
        DisplaywpCommentsViewer(sWebId, sListId, sItemID);

    }

    catch (err) {
        txt = "There was an error on this page 'Display_Internal_Content'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}

/*******End Display item content *************/

/*******Display item comments *************/
function DisplaywpCommentsViewer(sWebId, sListId, sItemID) {
    try {
        //wpCommentsViewer

        var hcvWebId = document.getElementById("cvhiddenWebId");
        if (hcvWebId != null)
            hcvWebId.value = sWebId;
        var hcvLisId = document.getElementById("cvhiddenListId");
        if (hcvLisId != null)
            hcvLisId.value = sListId;
        var hcvItemId = document.getElementById("cvhiddenItemId");
        if (hcvItemId != null)
            hcvItemId.value = sItemID;

        var btncvTriger = document.getElementsByName("btncvTriger")[0];

        if (btncvTriger != null)
            btncvTriger.click();
    }
    catch (err) {
        txt = "There was an error on this page 'DisplaywpCommentsViewer'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/*******End Display item comments *************/

/*******Display item rating *************/
function DisplaywpRatings(sWebId, sListId, sItemID) {
    try {
        //wpRatings
        var hraWebId = document.getElementById("rahiddenWebId");
        if (hraWebId != null)
            hraWebId.value = sWebId;
        var hraLisId = document.getElementById("rahiddenListId");
        if (hraLisId != null)
            hraLisId.value = sListId;
        var hraItemId = document.getElementById("rahiddenItemId");
        if (hraItemId != null)
            hraItemId.value = sItemID;
        var btnraTriger = document.getElementsByName("btnraTriger")[0];
        if (btnraTriger != null)
            btnraTriger.click();
    }
    catch (err) {
        txt = "There was an error on this page 'DisplaywpRatings'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/*******End Display item rating *************/

/*******Display item registration *************/
function DisplaywpRegistrationComment(sWebId, sListId, sItemID) {
    try {
        //wpRegistrationComment
        var hWebId = document.getElementById("rghiddenWebId");
        if (hWebId != null)
            hWebId.value = sWebId;
        var hLisId = document.getElementById("rghiddenListId");
        if (hLisId != null)
            hLisId.value = sListId;
        var hItemId = document.getElementById("rghiddenItemId");
        if (hItemId != null)
            hItemId.value = sItemID;
    }
    catch (err) {
        txt = "There was an error on this page 'DisplaywpRegistrationComment'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/*******End Display item registration *************/

/*******For Event calendar - display title of event*************/
function DisplayEventDetails(EventArgs, fieldsDelimiter, eventsDelimiter) {

    var argsArray = EventArgs.split(fieldsDelimiter);
    var eventsTitles = argsArray[0].split(eventsDelimiter);
    var eventsDates = argsArray[1].split(eventsDelimiter);
    var message = " - - Calendar client events - -\n\n";

    for (i = 0; i < eventsTitles.length; i++)
        message += "event name:" + eventsTitles[i] + "   event date: " + eventsDates[i] + "\n";
    alert(message);
}

/*******End For Event calendar - display title of event*************/
/******** jQuery Calendar **********/
function onLoadEvents() {
  try {
        setDatePicker();
        getCurrentDateEventCalendar()
      }
catch (err) {
    txt = "There was an error on this page 'onLoadEvents'.\n\n";
    txt += "Error description: " + err.description + "\n\n";
    txt += "Click OK to continue.\n\n";
    alert(txt);
    }

}

/*EventCalendar*/
function getCurrentDateEventCalendar() {    
    try {
            var gMonth = new gregmontharr('ינואר', 'פברואר', 'מרץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אוגוסט', 'ספטמבר', 'אוקטובר', 'נובמבר', 'דצמבר');

            if ($("html").attr("lang") == "en-us") {                
                gMonth = new gregmontharr("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
            }

            if ($("html").attr("lang") == "ar-il") {
                gMonth = new gregmontharr('كانون الثاني', 'شباط', 'آذار', 'نيسان', 'أيار', 'حزيران', 'تموز', 'آب', 'أيلول', ' تشرين الأول', 'تشرين الثاني', 'كانون الأول');
            }

            var myDate = new Date();
            $('.rcMain').append("<div id=\"CurrDate\" class=\"rcBigCurrentDate\"></div>");
            $('#CurrDate').append("<div id=\"dayCurr\" class=\"rcCurrentDay\">" + myDate.getDate() + "</div>");
            $('#CurrDate').append("<div id=\"MonthCurr\" class=\"rcCurrentMonth\">" + gMonth[myDate.getMonth()] + " " + myDate.getFullYear() + "</div>");

     }
    catch (err) {
        txt = "There was an error on this page 'getCurrentDateEventCalendar'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
    
}
function gregmontharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) {
    this[0] = m0; this[1] = m1; this[2] = m2; this[3] = m3;
    this[4] = m4; this[5] = m5; this[6] = m6; this[7] = m7;
    this[8] = m8; this[9] = m9; this[10] = m10; this[11] = m11;
}
/*End EventCalendar*/
//----------------------------------------------------------------------------------------------
/*START Date Picker*/
function setDatePicker() {
    try {

        if ($('#MSOSPWebPartManager_DisplayModeName').val() == 'Browse') {
            //check Language
            var strAltText = "בחר תאריך מתוך לוח השנה";

            if ($("html").attr("lang") == "en-us") {
                strAltText = "Choose a date from the Calender";
            }
            if ($("html").attr("lang") == "ar-il") {
                strAltText = "حدد تاريخ";
            }

            var index = 1;
            //  if (navigator.appName == "Microsoft Internet Explorer")
            $(".ms-dtinput:has(img)").remove();

            if ($(".ms-dtinput").length > 0) {
                $(".ms-dtinput").each(function (i) {
                    var DatePicker = "DatePicker" + i;
                    var DatePickerContainer = "DatePickerContainer" + i
                    if (i > 0)
                        index = i - 1;
                    $(this).after("<td id='" + DatePickerContainer + "' class='ms-dtinput tdDatePicker'><A  onclick=ShowDatePicker('" + DatePicker + "','DatePicker" + index + "') ><IMG id=FromCalculatedPublishDate src='/SiteCollectionImages/CALENDAR.GIF' border='0' alt='" + strAltText + "' title='" + strAltText + "'class='imgDatePicker'></IMG></A><div id='" + DatePicker + "'  style='position:absolute;display:none;' class='datepicker' type='text'></div></td>");

                });

                $(".datepicker").datepicker({
                    onSelect: function (dateText, inst) {
                        var PickerID = $(this).attr("id");
                        PickerID = PickerID.substring(10);
                        var NewID = "DatePickerContainer" + PickerID;
                        $("td[id='" + NewID + "']").prev().find("input").val(dateText);
                        $(this).css("display", "none");
                    }
                });
            }
            if (navigator.appName != "Microsoft Internet Explorer") {
                $("input$[id$=dtcFromUpdatedDate]").css("margin", "-10px 39px 0px 0px");
                $("td.dtcFromCalculatedPublishDate input").css("margin-right", "33px");
            }
            $("#ui-datepicker-div").remove();
        }
    }
catch (err) {
    txt = "There was an error on this page 'setDatePicker'.\n\n";
    txt += "Error description: " + err.description + "\n\n";
    txt += "Click OK to continue.\n\n";
    alert(txt);
    }
}

function ShowDatePicker(id, idToHide) {
   try {
        if ($("div [id='" + id + "']").css("display") == "none") {
            $("div [id='" + id + "']").css("display", "block");

            if ($("div [id='" + id + "']").css("display") == "block") {
                $("div [id='" + idToHide + "']").css("display", "none")
            }
        }
        else {
            $("div [id='" + id + "']").css("display", "none");

        }

    }
    catch (err) {
        txt = "There was an error on this page 'ShowDatePicker'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}

/*END Date Picker*/
/******** End jQuery Calendar **********/
/********SDC TAG*************/

function dcsVar() {
    var dCurrent = new Date();
    WT.tz = dCurrent.getTimezoneOffset() / 60 * -1;
    if (WT.tz == 0) {
        WT.tz = "0";
    }
    WT.bh = dCurrent.getHours();
    WT.ul = navigator.appName == "Netscape" ? navigator.language : navigator.userLanguage;
    if (typeof (screen) == "object") {
        WT.cd = navigator.appName == "Netscape" ? screen.pixelDepth : screen.colorDepth;
        WT.sr = screen.width + "x" + screen.height;
    }
    if (typeof (navigator.javaEnabled()) == "boolean") {
        WT.jo = navigator.javaEnabled() ? "Yes" : "No";
    }
    if (document.title) {
        WT.ti = document.title;
    }
    WT.js = "Yes";
    if (typeof (gVersion) != "undefined") {
        WT.jv = gVersion;
    }
    DCS.dcsdat = dCurrent.getTime();
    DCS.dcssip = window.location.hostname;
    DCS.dcsuri = window.location.pathname;
    if (window.location.search) {
        DCS.dcsqry = window.location.search;
    }
    if ((window.document.referrer != "") && (window.document.referrer != "-")) {
        if (!(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) < 4)) {
            DCS.dcsref = window.document.referrer;
        }
    }
}

function A(N, V) {
    return "&" + N + "=" + dcsEscape(V);
}

function dcsEscape(S) {
    if (typeof (RE) != "undefined") {
        var retStr = new String(S);
        for (R in RE) {
            retStr = retStr.replace(RE[R], R);
        }
        return retStr;
    }
    else {
        return escape(S);
    }
}

function dcsCreateImage(dcsSrc) {
    if (document.images) {
        gImages[gIndex] = new Image;
        gImages[gIndex].src = dcsSrc;
        gIndex++;
    }
    else {
        document.write('<IMG BORDER="0" NAME="DCSIMG" WIDTH="1" HEIGHT="1" SRC="' + dcsSrc + '">');
    }
}

function dcsMeta() {
    var myDocumentElements;
    if (document.all) {
        myDocumentElements = document.all.tags("meta");
    }
    else if (document.documentElement) {
        myDocumentElements = document.getElementsByTagName("meta");
    }
    if (typeof (myDocumentElements) != "undefined") {
        for (var i = 1; i <= myDocumentElements.length; i++) {
            myMeta = myDocumentElements.item(i - 1);
            if (myMeta.name) {
                if (myMeta.name.indexOf('WT.') == 0) {
                    WT[myMeta.name.substring(3)] = myMeta.content;
                }
                else if (myMeta.name.indexOf('DCSext.') == 0) {
                    DCSext[myMeta.name.substring(7)] = myMeta.content;
                }
                else if (myMeta.name.indexOf('DCS.') == 0) {
                    DCS[myMeta.name.substring(4)] = myMeta.content;
                }
            }
        }
    }
}

function dcsTag() {
    var P = "http" + (window.location.protocol.indexOf('https:') == 0 ? 's' : '') + "://" + gDomain + (gDcsId == "" ? '' : '/' + gDcsId) + "/dcs.gif?";
    for (N in DCS) {
        if (DCS[N]) {
            P += A(N, DCS[N]);
        }
    }
    for (N in WT) {
        if (WT[N]) {
            P += A("WT." + N, WT[N]);
        }
    }
    for (N in DCSext) {
        if (DCSext[N]) {
            P += A(N, DCSext[N]);
        }
    }
    if (P.length > 2048 && navigator.userAgent.indexOf('MSIE') >= 0) {
        P = P.substring(0, 2040) + "&WT.tu=1";
    }
    dcsCreateImage(P);
}

/********END SDC TAG*************/

/*********CheckBoxItemTemplate**********/
function onCheckBoxClick(chk, RadComboBox) {
    try {
        var combo = $find(RadComboBox);

        //holds the text of all checked items
        var text = "";

        //get the collection of all items
        var items = combo.get_items();

        var ctlid = RadComboBox.replace(chk, '');

        //enumerate all items

        for (var i = 1; i < items.get_count(); i++) {

            var chk1 = $get(chk + "_i" + i + "_chk1");
            if (chk1 == null) {

                chk1 = $get(ctlid + chk + "_i" + i + "_chk1");
            }

            if (chk1 != null) {
                if (chk1.checked) {

                    var item = items.getItem(i);
                    text += item.get_text() + ",";
                }
                else {
                    chk1 = $get(chk + "_i0" + "_chk1");
                    if (chk1 == null) {

                        chk1 = $get(ctlid + chk + "_i0" + "_chk1");
                    }
                    //remove select all
                    chk1.checked = false;
                }
            }
        }
        //remove the last comma from the string
        text = removeLastComma(text);

        if (text.length > 0) {
            //set the text of the combobox
            combo.set_text(text);


        }
        else {
            //all checkboxes are unchecked
            //so reset the controls 
            combo.set_text("");


        }
    }
    catch (err) {
        txt = "There was an error on this page 'onCheckBoxClick'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
function CheckBoxClickAll(chk, RadComboBox) {

    try {
        var combo = $find(RadComboBox);

        var ctlid = RadComboBox.replace(chk, '');

        //holds the text of all checked items
        var text = "";
        //holds the values of all checked items
        var values = "";
        //get the collection of all items
        var items = combo.get_items();
        //enumerate all items
        var chk1 = $get(chk + "_i0" + "_chk1");
        var bCheckAll;
        if (chk1 == null) {

            chk1 = $get(ctlid + chk + "_i0" + "_chk1");
        }

        if (chk1 != null) {
            bCheckAll = chk1.checked;
            if (chk1.checked) {

                var item = items.getItem(0);
                text += item.get_text();
            }
            for (var i = 1; i < items.get_count(); i++) {

                chk1 = $get(chk + "_i" + i + "_chk1");
                if (chk1 == null) {

                    chk1 = $get(ctlid + chk + "_i" + i + "_chk1");
                }
                if (chk1 != null)
                    chk1.checked = bCheckAll
            }
        }

        if (text.length > 0) {
            //set the text of the combobox
            combo.set_text(text);

        }
        else {
            //all checkboxes are unchecked
            //so reset the controls 
            combo.set_text("");

        }
    }
    catch (err) {
        txt = "There was an error on this page 'CheckBoxClickAll'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}

 //this method removes the ending comma from a string
function removeLastComma(str) {
    try {
        return str.replace(/,$/, "");
    }
    catch (err) {
        txt = "There was an error on this page 'removeLastComma'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }

}
function StopPropagation(e) {
    try {
        //cancel bubbling
        e.cancelBubble = true;
        if (e.stopPropagation) {
            e.stopPropagation();
        }

    }
    catch (err) {
        txt = "There was an error on this page 'StopPropagation'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }

}

/*********End CheckBoxItemTemplate**********/
//Remove first and last Paging Image Seperator
function FixPagingImageSep() {
    try {

        SepFirst = $('.resultsPagingImageSep:first')
        if (SepFirst != null)
         { SepFirst.css({ display: "none" }); }
        Seplast = $('.resultsPagingImageSep:last')
        if (Seplast != null) { Seplast.css({ display: "none" }); }

    }
    catch (err) {
        txt = "There was an error on this page 'FixPagingImageSep'.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }

}

/******** Display Open\Close Mega Menu by jQuery**************/
function MegaMenu() {

    try {
        
        $(document).ready(function () {
            $("ul#topnav li").hover(function () {
                //Add background color + image on hovered list item  
                $(this).find("div").show();
                //Show the subnav
            }, function () {
                //on hover out...  
                $(this).css({ 'background': 'none' });
                //Ditch the background  
                $(this).find("div").hide();
                //Hide the subnav
            });



            //show sub div on key press
            $("ul#topnav li").keydown(function (e) {
                var code = (e.keyCode ? e.keyCode : e.which);
                //down arrow     
                if (code == 40) {
                    $("ul#topnav li div.sub").hide();
                    $(this).find("div").show();
                }
                //esc
                if (code == 27) {
                    $("ul#topnav li div.sub").hide();
                }
            });
        });

    }
    catch (err) {
        txt = "There was an error on this page.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}
/******** End Display Open\Close Mega Menu by jQuery**************/
