﻿var ResHelper =
{
    Style: { Width: null, ArrowAlign: null },
    DropDownList: null,
    AddResource: null,
    Resource: [],
    ElementRef: null,
    Side: 0,
    CallOutDiv: '<div id="callOutMessage" style="z-index:11001"><table class="exclaimPop exclaimPop_popup_table" id="ctl00_popupTable" style="VISIBILITY: visible; POSITION: absolute;" cellSpacing="0" cellPadding="0" width="260" border="0" zIndex="1000"><TBODY><TR class="exclaimPop_popup_table_row"><TD class="exclaimPop_callout_cell"><TABLE class="exclaimPop_callout_table" cellSpacing="0" cellPadding="0" border="0"><TBODY><TR class="exclaimPop_callout_table_row"><TD class="exclaimPop_callout_arrow_cell"><DIV class="exclaimPop_innerdiv"><DIV style="WIDTH: 14px"></DIV><DIV style="WIDTH: 13px"></DIV><DIV style="WIDTH: 12px"></DIV><DIV style="WIDTH: 11px"></DIV><DIV style="WIDTH: 10px"></DIV><DIV style="WIDTH: 9px"></DIV><DIV style="WIDTH: 8px"></DIV><DIV style="WIDTH: 7px"></DIV><DIV style="WIDTH: 6px"></DIV><DIV style="WIDTH: 5px"></DIV><DIV style="WIDTH: 4px"></DIV><DIV style="WIDTH: 3px"></DIV><DIV style="WIDTH: 2px"></DIV><DIV style="WIDTH: 1px"></DIV></DIV></TD></TR></TBODY></TABLE></TD><TD class="exclaimPop_icon_cell"><IMG src="Images/alert01.gif"  border="0" /></TD><TD class="exclaimPop_error_message_cell"></TD><TD class="exclaimPop_close_button_cell"><DIV class="exclaimPop_innerdiv"><IMG id="closeAlert" src="Images/closeAlert.gif" /></DIV></TD></TR></TBODY></table></div>',
    CallOutTopDiv: '<div id="callOutMessage" style="z-index:11001"><div class="calloutUpY"><img src="../images/calloutImage.gif" /> </div> <table class="exclaimPop exclaimPop_popup_table" id="ctl00_popupTable" style="VISIBILITY: visible; POSITION: absolute;" cellSpacing="0" cellPadding="0" width="260" border="0" zIndex="1000"><TBODY><TR class="exclaimPop_popup_table_row"><TD class="exclaimPop_icon_cell"><IMG src="Images/alert01.gif"  border="0" /></TD><TD class="exclaimPop_error_message_cell"></TD><TD class="exclaimPop_close_button_cell"><DIV class="exclaimPop_innerdiv"><IMG id="closeAlert" src="Images/closeAlert.gif" /></DIV></TD></TR></TBODY></table></div>',
    TipsDiv: '<div id="TipsMessage" style="z-index:11001"><table class="exclaimPop exclaimPop_popup_table" id="ctl00_popupTable" style="VISIBILITY: visible; POSITION: absolute;" cellSpacing="0" cellPadding="0" width="260" border="0" zIndex="1000"><TBODY><TR class="exclaimPop_popup_table_row"><TD class="exclaimPop_icon_cell">&nbsp;</TD><TD class="exclaimPop_error_message_cell"></TD><TD class="exclaimPop_close_button_cell"><DIV class="exclaimPop_innerdiv"></DIV></TD></TR></TBODY></table></div>',
    ModalDiv: '<div id="fadedModalContent" class="fadedContent"></div>',
    ContentContainer: '<div id="Res__divCntCont" class="browsePopup"></div>',
    AdditionalModalDiv: '<div id="additionalfadedModalContent" class="fadedContent1"></div>',
    AdditionalContentContainer: '<div id="AdditionalRes__divCntCont" class="browsePopup1"></div>',
    SavedContainer: null,
    ShowInfoMessage: function(msg, ReferenceElementID, timeoutinSeconds) {
        this.ShowExceptionMessage(msg, ReferenceElementID, timeoutinSeconds);
        $('TD.exclaimPop_icon_cell').html("&nbsp;");
        $('div.calloutUpY').html("&nbsp;");
        $('#closeAlert').hide();
    },
    ShowSaveProgressMessage: function(saveButtonID, SaveContainerID) {
        var ele = ResHelper.GetElementByIdName(saveButtonID);
        if (ele) {
            $(ele).hide();
            if (SaveContainerID)
            { $("#" + SaveContainerID).html("<span class='saveProcessingContainer' id='SaveProcessMsg'>Processing…</span>"); }
            else { $("#SaveMessageContainer").html("<span class='saveProcessingContainer' id='SaveProcessMsg'>Processing…</span>"); }
        }
    },
    ShowSaveErrorMessage: function(saveButtonID, SaveContainerID) {
        $("#SaveProcessMsg").remove();
        if (saveButtonID) {
            var ele = ResHelper.GetElementByIdName(saveButtonID);
            if (ele) {
                //$(ele).parent().html($(ele).parent().html() + "<span style='color:red;font-weight:regular'id='SaveSuccessMsg'>Error occurred!!<br>Your submission was not successful.</span>");
                if (SaveContainerID) { $("#" + SaveContainerID).html("<span class='saveMessageContainer' id='SaveSuccessMsg'></span>"); }
                else
                { $("#SaveMessageContainer").html("<span class='saveMessageContainer' id='SaveSuccessMsg'></span>"); }
                setTimeout("ResHelper.HideSaveSuccessMessage('" + saveButtonID + "')", 2000);
            }
        }
    },

    ShowSaveSuccessMessage: function(saveButtonID, SaveContainerID) {
        var ele = ResHelper.GetElementByIdName(saveButtonID);
        if (ele) {
            $("#SaveProcessMsg").remove();
            if (SaveContainerID) { $("#" + SaveContainerID).html("<span class='saveMessageContainer posMsg' id='SaveSuccessMsg'>Your changes have been saved.</span>"); }
            else
            { $("#SaveMessageContainer").html("<span class='saveMessageContainer posMsg' id='SaveSuccessMsg'>Your changes have been saved.</span>"); }
            setTimeout("ResHelper.HideSaveSuccessMessage('" + saveButtonID + "')", 2000);
        }
    },
    HideSaveSuccessMessage: function(saveButtonID) {
        var ele = ResHelper.GetElementByIdName(saveButtonID);
        if (ele) {
            $("#SaveSuccessMsg").remove();
            $(ele).show();
        }
    },
    SetExceptionMessage: function(msg) {
        var msgEle = $("#callOutMessage .exclaimPop_error_message_cell");
        msgEle[0].innerHTML += "<B>" + msg + "</B>";
    },
    ShowTips: function(msg, ReferenceElementID, timeoutinSeconds) {
        if ($((document).ready)) {
            if (ReferenceElementID) {
                var referenceElement = this.GetElementByIdName(ReferenceElementID);
                if (referenceElement) {
                    this.ElementRef = referenceElement;
                }
            }
            if (this.ElementRef) {
                var elementLoc = Sys.UI.DomElement.getLocation(this.ElementRef);
                var coor = this.GetPageCoordinates();
                var eleWdth = 260;
                if (this.Style.Width) {
                    eleWdth = parseInt(this.Style.Width);
                }
                if (elementLoc.x + this.ElementRef.offsetWidth + eleWdth >= coor.width) {
                    this.Style.ArrowAlign = "Top";
                    var wd = eleWdth;
                    if ((elementLoc.x + eleWdth) > coor.width) {
                        wd = wd - ((elementLoc.x + eleWdth) - coor.width);
                    }
                    this.Style.Width = wd;
                }
                else {
                    this.Style.ArrowAlign = "Top";
                }
                var eleCallout = $(this.TipsDiv);
                $('#TipsMessage').remove();
                eleCallout.appendTo(document.body);

                $('#ctl00_popupTable').css("width", this.Style.Width);
                $(this.ElementRef).mouseout(function() {
                    $("#TipsMessage").hide("slow");
                    $("#TipsMessage").remove();

                });
                $("#TipsMessage").mouseout(function() {
                    $("#TipsMessage").hide("slow");
                    $("#TipsMessage").remove();

                });

                var msgEle = $("#TipsMessage .exclaimPop_error_message_cell");
                msgEle[0].innerHTML += "<div style='margin-bottom:5px;text-align: left;font-weight: bold;font-size: 13px;margin-top:10px;border-top-style: none !important;border-bottom-style: none !important;border-right-style: none !important;border-left-style: none !important;'>Tips</div><div style='border-bottom: thin dotted ;border-top-style: none !important;border-left-style: none !important;border-right-style: none !important;'>&nbsp;</div>" + "<br /><B>" + msg + "</B><br /><br /><br />";

                var elementLocWidth = this.ElementRef.offsetWidth;
                var xPos;
                var yPos
                if (this.Style.ArrowAlign === "Top") {
                    xPos = elementLoc.x + 15;
                    yPos = elementLoc.y + 10;
                }
                else {
                    xPos = elementLoc.x + elementLocWidth;
                    yPos = elementLoc.y;
                }
                Sys.UI.DomElement.setLocation(eleCallout[0], xPos, yPos);
                if (navigator.appVersion.indexOf('MSIE 6') > -1) { this.ShowHideDropDownsById(0); }

                if (timeoutinSeconds && !(isNaN(timeoutinSeconds))) {
                    timeoutinSeconds = timeoutinSeconds * 1000;
                    setTimeout("$('#TipsMessage').remove()", timeoutinSeconds);
                }
            }
        }
    },
    ShowExceptionMessage: function(msg, ReferenceElementID, timeoutinSeconds) {
        if ($((document).ready)) {
            if (ReferenceElementID) {
                var referenceElement = this.GetElementByIdName(ReferenceElementID);
                if (referenceElement) {
                    this.ElementRef = referenceElement;
                }
            }
            if (this.ElementRef) {
                var elementLoc = Sys.UI.DomElement.getLocation(this.ElementRef);
                var coor = this.GetPageCoordinates();
                var eleWdth = 260;
                if (this.Style.Width) {
                    eleWdth = parseInt(this.Style.Width);
                }
                if (elementLoc.x + this.ElementRef.offsetWidth + eleWdth >= coor.width) {
                    this.Style.ArrowAlign = "Top";
                    var wd = eleWdth;
                    if ((elementLoc.x + eleWdth) > coor.width);
                    {
                        wd = wd - ((elementLoc.x + eleWdth) - coor.width);
                    }
                    this.Style.Width = wd;
                }
                else {
                    this.Style.ArrowAlign = null;
                }
                if (this.Style.ArrowAlign === "Top")
                { var eleCallout = $(this.CallOutTopDiv); }
                else { var eleCallout = $(this.CallOutTopDiv); }

                $('#callOutMessage').remove();
                eleCallout.appendTo(document.body);
                if (navigator.appVersion.indexOf('MSIE 6') > -1) { $('.calloutUpY').attr("className", "calloutUpYIE6"); }

                $('#ctl00_popupTable').css("width", this.Style.Width);
                $(".exclaimPop_innerdiv").click(function() {
                    $('#callOutMessage').remove();
                });
                this.SetExceptionMessage(msg);
                var elementLocWidth = this.ElementRef.offsetWidth;
                var xPos;
                var yPos
                if (this.Style.ArrowAlign === "Top") {
                    xPos = elementLoc.x - 10;
                    yPos = elementLoc.y + 15;
                }
                else {
                    xPos = elementLoc.x + elementLocWidth;
                    yPos = elementLoc.y;
                }
                Sys.UI.DomElement.setLocation(eleCallout[0], xPos, yPos);
                if (navigator.appVersion.indexOf('MSIE 6') > -1) { this.ShowHideDropDownsById(0); }
                if (!(isNaN(timeoutinSeconds))) {
                    timeoutinSeconds = timeoutinSeconds * 1000;
                    if (timeoutinSeconds > 0) { setTimeout("ResHelper.RemoveCallOut()", timeoutinSeconds); }
                }
                else {
                    setTimeout("ResHelper.RemoveCallOut()", 3000);
                }
            }
        }
    },
    RaiseException: function(msg, ReferenceElementID, timeoutinSeconds) {
        if ($((document).ready)) {
            if (ReferenceElementID) {
                var referenceElement = this.GetElementByIdName(ReferenceElementID);
                if (referenceElement) {
                    this.ElementRef = referenceElement;
                }
            }
            if (this.ElementRef) {
                var elementLoc = Sys.UI.DomElement.getLocation(this.ElementRef);
                var coor = this.GetPageCoordinates();
                var eleWdth = 260;
                if (this.Style.Width) {
                    eleWdth = parseInt(this.Style.Width);
                }
                if (elementLoc.x + this.ElementRef.offsetWidth + eleWdth > coor.width) {
                    this.Style.ArrowAlign = "Top";
                    var wd = eleWdth;
                    if ((elementLoc.x + eleWdth) > coor.width) {
                        wd = wd - ((elementLoc.x + eleWdth) - coor.width);
                    }
                    this.Style.Width = wd;
                }
                else {
                    this.Style.ArrowAlign = null;
                }
                if (this.Style.ArrowAlign === "Top")
                { var eleCallout = $(this.CallOutTopDiv); }
                else { var eleCallout = $(this.CallOutDiv); }

                $('#callOutMessage').remove();
                eleCallout.appendTo(document.body);
                if (navigator.appVersion.indexOf('MSIE 6') > -1) { $('.calloutUpY').attr("className", "calloutUpYIE6"); }
                $('#ctl00_popupTable').css("width", this.Style.Width);
                $(".exclaimPop_innerdiv").click(function() {
                    $('#callOutMessage').remove();
                });
                this.SetMessage(msg);
                var elementLocWidth = this.ElementRef.offsetWidth;
                var xPos;
                var yPos
                if (this.Style.ArrowAlign === "Top") {
                    xPos = elementLoc.x - 10;
                    yPos = elementLoc.y + 15;
                }
                else {
                    xPos = elementLoc.x + elementLocWidth;
                    yPos = elementLoc.y;
                }
                if (navigator.appVersion.indexOf('MSIE 6') > -1) { this.ShowHideDropDownsById(0); }
                Sys.UI.DomElement.setLocation(eleCallout[0], xPos, yPos);
                if (!(isNaN(timeoutinSeconds))) {
                    timeoutinSeconds = timeoutinSeconds * 1000;
                    if (timeoutinSeconds > 0) { setTimeout("ResHelper.RemoveCallOut()", timeoutinSeconds); }
                }
                else {
                    setTimeout("ResHelper.RemoveCallOut()", 3000);
                }
            }
        }
    },
    SetMessage: function(msg) {
        var msgEle = $("#callOutMessage .exclaimPop_error_message_cell");
        var msgIDs = msg.split(',');
        for (var cntr = 0; cntr < msgIDs.length; cntr++) {
            for (var er in this.Resource) {
                if (this.Resource[er].id === msgIDs[cntr]) {
                    msgEle[0].innerHTML += "<B>" + this.Resource[er].msg + "</B><BR /><BR />";
                    break;
                }
            }
        }
    },
    GetMessages: function() {
        $(document).ready(function() {
            if ((ResHelper.Resource) && (ResHelper.Resource.length < 5)) {
                var dt = new Date(); var rs = 'Res'; var tm = dt.toTimeString(); $.getJSON("asyncMultiFileUpload.aspx", { TM: tm, jsonData: rs }, function(data) { ResHelper.Resource = data; });
            }
        });
    },
    RemoveCallOut: function() { $('#callOutMessage').remove(); this.Style.ArrowAlign = null; this.Style.Width = null; if (navigator.appVersion.indexOf('MSIE 6') > -1) { this.ShowHideDropDownsById(1); } },
    AppendResource: function() {
        for (var er in this.AddResource) {
            this.Resource.push(this.AddResource[er]);
        }
    },
    RemoveTips: function() {
        $("#TipsMessage").hide("slow");
        $("#TipsMessage").remove();
    },
    GetElementByIdName: function(elementName) {
        var element;
        elements = $("*");
        var elementObject;
        for (var i = 0; i < elements.length; i++) {
            var idName = elements[i].id.toUpperCase();
            if (idName == elementName) {
                elementObject = elements[i];
                break;
            }
            var aridName = idName.split('_');
            elementName = elementName.toUpperCase();
            var thisidName = aridName[aridName.length - 1];
            if (idName.indexOf('CLIENTSTATE') > -1) {
                thisidName = aridName[aridName.length - 2];
            }

            if (thisidName == elementName) {
                elementObject = elements[i];
                break;
            }
        }
        return elementObject;
    },
    ShowModalLayer: function() {
        var elementBounds = Sys.UI.DomElement.getBounds($("form")[0]);
        //var hw = this.GetPageSize();
        var eleModal = $(this.ModalDiv);
        $('#fadedModalContent').remove();
        //$(eleModal).css("height", hw[1]);
        //$(eleModal).css("width", hw[0]);
        $(eleModal).css("height", elementBounds.height);
        $(eleModal).css("width", elementBounds.width);
        eleModal.appendTo(document.body);
        var appVer = navigator.appVersion;
        /*IE 6.0 check */
        if (appVer.indexOf('MSIE 6') > -1) { this.ShowDropDowns(0); }
    },
    HideModalLayer: function() {
        $('#fadedModalContent').fadeOut();
        $('#fadedModalContent').remove();
    },
    ShowModalContainer: function(contentHTML) {
        $('#Res__divCntCont').remove();
        this.ShowModalLayer();
        var elu = $(this.ContentContainer);
        $(elu).html(contentHTML);
        var ltop = 0;
        var lleft = 0;

        var windowTop = $(window).height() / 2;
        var windowLeft = $(window).width() / 2;
        //set vertical and horizontal values for different pop-ups.
        if ($(elu).html().indexOf('VirtualTourDiv') > -1 || $(elu).html().indexOf('UpdateSelectionPopUpInner') > -1) {
            ltop = windowTop - 200;
            lleft = windowLeft - 272;
        }
        else if ($(elu).html().indexOf('AutoSignUpUnselectedPopUpInner') > -1) {
            ltop = windowTop - 100;
            lleft = windowLeft - 202;
        }
        else if ($(elu).html().indexOf('UnAutoSignUpPopUpInner') > -1) {
            ltop = 230;
            lleft = 400;
        }
        else if ($(elu).html().indexOf('AutoSignUpPopUpInner') > -1) {
            ltop = windowTop - 120;
            lleft = windowLeft - 232;
        }
        else if ($(elu).html().indexOf('ChangeAssurancePlanPopUpInner') > -1) {
            ltop = windowTop - 200;
            lleft = windowLeft - 202;
        }

        else if ($(elu).html().indexOf('BrochuresDiv') > -1) {
            ltop = windowTop - 200;
            lleft = windowLeft - 300;
        }
        else if ($(elu).html().indexOf('ListingPhotosDiv') > -1) {
            ltop = windowTop - 275;
            lleft = windowLeft - 367;
        }
        else if ($(elu).html().indexOf('OpenHouseDiv') > -1) {
            ltop = windowTop - 300;
            lleft = windowLeft - 320;
        }
        else if ($(elu).html().indexOf('WebsiteRedirectPopUp') > -1) {
            ltop = 200;
            lleft = 270;
        }
        else if ($(elu).html().indexOf('ConfirmDeletePopUp') > -1) {
            ltop = 330;
            lleft = 400;
        }
        else if ($(elu).html().indexOf('PaymentPopUpInner') > -1) {
            ltop = 330;
            lleft = 400;
        }
        else if ($(elu).html().indexOf('ApprovedPopUpInner') > -1) {
            ltop = 330;
            lleft = 400;
        }
        else if ($(elu).html().indexOf('PendingPopUpInner') > -1) {
            ltop = 330;
            lleft = 400;
        }
        else if ($(elu).html().indexOf('AutoRenewPopUpInner') > -1) {
            ltop = 330;
            lleft = 400;
        }
        else if ($(elu).html().indexOf('AutoRenewApprovedPopUpInner') > -1) {
            ltop = 330;
            lleft = 400;
        }
        //browser compatibility.

        if ($.browser.msie == true || $.browser.mozilla == true) {
            $(elu).css("top", document.documentElement.scrollTop + ltop);
            $(elu).css("left", document.documentElement.scrollLeft + lleft);
        }
        else {
            $(elu).css("top", document.body.scrollTop + ltop);
            $(elu).css("left", document.body.scrollLeft + lleft);
        }
        $("form").append(elu);
        $('#Res__divCntCont').show("fast");
        //        $('#Res__divCntCont')[0].scrollIntoView();

    },
    HideModalContainer: function() {
        //$('#Res__divCntCont').remove();
        //$('#Res__divCntCont').remove();
        $('#Res__divCntCont').hide("fast");
        $('#fadedModalContent').hide("slow");
        //$('#fadedModalContent').remove();

    },
    ShowAdditionalModalContainer: function(contentHTML) {
        this.ShowAdditionalModalLayer();
        var additionalelu = $(this.AdditionalContentContainer);
        $(additionalelu).html(contentHTML);
        $("form").append(additionalelu);
        var pagesize = this.GetPageSize();
        var top = (pagesize[3] - $(additionalelu).height()) / 2;
        var left = (pagesize[2] - $(additionalelu).width()) / 2;
        $(additionalelu).css("left", left);
        $(additionalelu).css("top", top);
    },

    ShowAdditionalModalLayer: function() {
        var elementBounds = Sys.UI.DomElement.getBounds($("form")[0]);
        var neweleModal = $(this.AdditionalModalDiv);
        $(neweleModal).css("height", elementBounds.height);
        $(neweleModal).css("width", elementBounds.width);
        neweleModal.appendTo(document.body);
        var appVer = navigator.appVersion;
        /*IE 6.0 check */
        if (appVer.indexOf('MSIE 6') > -1)
        { this.ShowDropDowns(0); }
    },

    HideAdditionalModalContainer: function() {
        $('#AdditionalRes__divCntCont').fadeOut(1000);
        $('#AdditionalRes__divCntCont').remove();
        $('#additionalfadedModalContent').fadeOut(1000);
        $('#additionalfadedModalContent').remove();
    },

    HideAllContainers: function() {
        this.HideAdditionalModalContainer();
        this.HideModalContainer();
    },
    SaveContainer: function() {
        this.SavedContainer = $('#Res__divCntCont');
    },
    ShowSavedContainer: function() {
        this.ShowModalContainer(this.SavedContainer[0].innerHTML);
    },
    ShowHideDropDowns: function(flag) {
        if (flag === 0) {
            $("SELECT").css("visibility", "hidden");
        }
        else if (flag === 1) {
            $("SELECT").css("visibility", "visible");
        }
    },
    ShowHideDropDownsById: function(flag) {
        if (navigator.appVersion.indexOf('MSIE 6') > -1) {
            var idList;
            if (this.DropDownList) {
                idList = this.DropDownList.split(',');
                for (var cntr = 0; cntr < idList.length; cntr++) {
                    if (idList[cntr] != "") {
                        var ctrl = this.GetElementByIdName(idList[cntr]);
                        if (ctrl) {
                            if (flag === 0) {
                                $(ctrl).css("visibility", "hidden");
                            }
                            else if (flag === 1) {
                                $(ctrl).css("visibility", "visible");
                            }
                        }
                    }
                }
            }
        }
    },

    GetPageCoordinates: function() {
        return Sys.UI.DomElement.getBounds($("form")[0]);
    },
    GetPageSize: function() {
        var xScroll, yScroll;
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = document.body.scrollWidth;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
        var windowWidth, windowHeight;
        if (self.innerHeight) { // all except Explorer
            windowWidth = self.innerWidth;
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }
        // for small pages with total height less then height of the viewport
        if (yScroll < windowHeight) {
            pageHeight = windowHeight;
        } else {
            pageHeight = yScroll;
        }

        pageHeight = pageHeight + 'px';

        // for small pages with total width less then width of the viewport
        if (xScroll < windowWidth) {
            pageWidth = windowWidth;
        } else {
            pageWidth = xScroll;
        }

        pageWidth = pageWidth + 'px';

        arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
        return arrayPageSize;
    },
    ShowDropDowns: function(flag) {
        if (document.getElementsByTagName('*')) {
            var elements = document.getElementsByTagName('SELECT');
            for (var icounter = 0; icounter < elements.length; icounter++) {
                if (elements[icounter].tagName == 'SELECT') {
                    if (flag == 0)
                        elements[icounter].style.visibility = 'hidden';
                    else
                        elements[icounter].style.visibility = 'visible';
                }
                else
                    continue;
            }
        }
    },

    RedirectToErrorPage: function() {
        window.location.href = "http://" + window.location.host + "/PortalAdmin/ErrorPage.aspx";
    },
    RedirectToSessionTimeOutPage: function() {
        window.location.href = window.location.href; // "Timeout.aspx";
    },
    GetExceptionMessage: function(error) {
        try {
            return error.get_message();
        }
        catch (ex) {
            try {
                //xhr object
                return error.responseText;
            }
            catch (ex1) {
                return "";
            }
        }
    },

    HandleServiceException: function(error) {
        if (error != null) {
            var objtype = typeof error;
            if (objtype == 'object') {
                if (error.get_message() == "ServiceException") {
                    this.RedirectToErrorPage();
                }
                else if (error.get_message().indexOf("Authentication failed") > -1) {
                    //this.RedirectToSessionTimeOutPage();
                }
            }
            else if (objtype == 'string') {
                if (error.toString().indexOf("ServiceException") > -1) {
                    this.RedirectToErrorPage();
                }
            }
        }
    },

    //TO DO
    IsException: function(msg) {
        if (msg.indexOf("ServiceException") > -1) {
            return true;

        }
        else if (msg.indexOf("Authentication failed") > -1) {
            return true;
        }
        else {
            return false;
        }
    },

    IsBusinessException: function(error) {
        if (error != null) {
            var objtype = typeof error;
            if (objtype == 'object') {
                if (error.get_message() == "ServiceException") {
                    return false;
                }
                else if (error.get_message().indexOf("Authentication failed") > -1) {
                    //this.RedirectToSessionTimeOutPage();
                }
            } else if (objtype == 'string') {
                if (error.toString().indexOf("ServiceException") > -1) {
                    return false;
                }
            }
        }
        return true;
    },

    //Regular expressions validation
    /* Verify unsigned integer
    *        ignoring leading and trailing spaces
    * Return boolean
    */
    ValidateUnsignedInteger: function(str) {
        var regEx = new RegExp();
        regEx.compile("^[0-9]+$");
        str = str.replace(/^\s+|\s+$/g, '');
        return regEx.test(str);
    },
    IsDecimal: function(s) {
        var isDecimal_re = /^\s*(\+|-)?((\d+(\.\d+)?)|(\.\d+))\s*$/;
        return String(s).search(isDecimal_re) != -1;
    },
    //Currency Formatter
    /*<!-- The JavaScript Source!! http://javascript.internet.com -->
    This script accepts a number or string and formats it like U.S. currency. 
    Adds the dollar sign, rounds to two places past the decimal, adds place holding zeros, 
    and commas where appropriate. e.g $457,456.00    
    */
    FormatCurrency: function(num) {
        num = num.toString().replace(/\$|\,/g, '');
        if (isNaN(num))
            num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num * 100 + 0.50000000001);
        cents = num % 100;
        num = Math.floor(num / 100).toString();
        if (cents < 10)
            cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + ',' +
            num.substring(num.length - (4 * i + 3));
        return (((sign) ? '' : '-') + '$' + num + '.' + cents);
    }
}

ResHelper.GetMessages();

function showPopupDiv(IconObj, divId) {
    if (document.getElementById(divId).innerHTML != '')
        toggle(divId, 0);
    document.getElementById(divId).style.left = findPosX(IconObj)- 100 + 'px';
    document.getElementById(divId).style.top = findPosY(IconObj)+ 20 + 'px';
}
function closepopupLayer() {
    toggle('popupLayer', 1);
}
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj = obj.offsetParent;
        }
    } else if (obj.x) {
        curleft += obj.x;
    }
    return curleft;
}
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj = obj.offsetParent;
        }
    } else if (obj.y) {
        curtop += obj.y;
    }
    return curtop;
}

function getObj(name) {
    if (document.getElementById) {
        this.obj = $get(name);
        this.style = $get(name).style;
    }
    else if (document.all) {
        this.obj = document.all[name];
        this.style = document.all[name].style;
    }
    else if (document.layers) {
        this.obj = document.layers[name];
        this.style = document.layers[name];
    }
}
var DHTML = (document.getElementById || document.all || document.layers);
function toggle(div, flag) {

    if (!DHTML) return;
    var x = new getObj(div);
    x.style.display = (flag) ? 'none' : 'block'
    x.style.visibility = (flag) ? 'hidden' : 'visible';
}
