﻿//Global variables...
var g_sValidateFormErrorColor = "#ffffcc"; // "#ffcc66"; // "#33cc66";
var g_sValidateFormClearColor = "#ffffff";
var g_bValidateFirstTimePopup = new Boolean(true);
var g_iJsErrorEmailCount = 0;

//General functions...

//General classes...
/*
function ftnAjaxHttpRequestSynchronousPostBackJsonResult1(oFrmLayout1) 
{
    //Parameters' cleanup...
    //oFrmLayout1 = ...

    //Initailize variables...
    var oJsonResult = new Object;
    var bAjaxPostbackSuccess = false;
    var bAjaxPostbackError = false;
    var sPostQuery = "";

    //Reset form elements (validation)...
    ftnValidateFormClear();

    //03/08/2010 - Added "manualclickevent" variable so we can tell if the button, link, etc. was manually clicked and not non-related something (unknown/random data) was send to us... (For example, "Enter" key was pressed from a textbox that didn't call this function)...
    //#sPostQuery = "&manualclickevent=true" + oFrmLayout1.serialize();
    sPostQuery = oFrmLayout1.serialize();

    $(document).ready(function () {
        $.ajax({
            type: "POST",
            async: false, //This need to be synchronous so the client can wait for a webserver response...
            url: oFrmLayout1.attr("action"),
            data: sPostQuery,  
            //contentType: "application/json; charset=utf-8",
            datatype: "json",
            beforeSend: function (oXmlHttpRequest, oSetting) 
            {
                ftnBlockAndGreyOutScreen(true, "600", "50", "Processing your request");
            },
            complete: function (oXmlHttpRequest, sTextStatus) 
            {
                ftnBlockAndGreyOutScreen(false, "0", "0", "");
            },
            success: function (oData, sTextStatus, oXmlHttpRequest) 
            {
                //#alert("Success");
                oJsonResult = oData;
                bAjaxPostbackSuccess = true;
            },
            error: function (oXmlHttpRequest, sTextStatus, oErrorThrown) 
            {
                //#alert("Fail");
                bAjaxPostbackError = true;
            }
        });
    });

    if (bAjaxPostbackError == true) 
    {
        ftnBlockAndGreyOutScreen(true, "600", "50", "Oops! &nbsp;Something went wrong while processing your request.<br /><br /><a href='#' onclick='ftnBlockAndGreyOutScreen(false,0,0,\"\");return false;'>Click to cancel</a>");
    }
    else if (bAjaxPostbackSuccess == true) 
    {
        ftnValidateFormErrorCheck(oJsonResult.sFormElementId, oJsonResult.sErrorMsg);
    }

    return oJsonResult;
}
*/
function ftnBlockAndGreyOutScreen(bDisplay, sWidth, sHeight, sMessage) 
{
    var iGreyOutScreenOpacity = 70;

    if ($('#BlockAndGreyOutScreen').length == 0) {
        $('body').append('<div id="BlockAndGreyOutScreen"><div id="BlockAndGreyOutScreenPromptMessage"></div></div>');

        $('#BlockAndGreyOutScreen')
            .css('z-index', '5000')
            .css('position', 'absolute')
            .css('top', '0px')
            .css('left', '0px')
            .css('background-color', '#000000')
            /* http://www.quirksmode.org/css/opacity.html */
            .css('opacity', '.' + iGreyOutScreenOpacity + '')  /* Works for some web-browsers... */
            .css('-moz-opacity', '.' + iGreyOutScreenOpacity + '')  /* Works for Gecko web-browsers... (Mozilla, SeaMonkey, Firefox, etc.)... */
            .css('-webkit-opacity', '.' + iGreyOutScreenOpacity + '')  /* Works for web-browsers using webkit... (Safari, Chrome, etc.)... */
            .css('-ms-filter', 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + iGreyOutScreenOpacity + ')')  /* Works for IE-8... */
            .css('filter', 'alpha(opacity=' + iGreyOutScreenOpacity + ')')  /* Works for IE-5 to IE-7... */
            //.css('overflow', 'hidden')  //Supposely to hide the scroll-bar...
            .css('display', 'none');

        $('#BlockAndGreyOutScreenPromptMessage')
            .css('position', 'absolute')
            .css('top', '0px')
            .css('left', '0px')
            .css('border', 'solid 3px #aaaaaa')
            .css('background-color', '#ffffff')
            .css('width', sWidth + 'px')  //01/28/2010 - The width is needed for proper location/alignment of popup-prompt-msg-box...
            .css('height', sHeight + 'px')  //01/28/2010 - The height is needed for proper location/alignment of popup-prompt-msg-box...
            .css('padding', '25px 50px 25px 50px')
            .css('vertical-align', 'middle')
            .css('text-align', 'center')
            .css('color', '#000000')
            .css('font-family', 'Arial, Verdana, sans-serif')
	        .css('font-size', '18px')
	        .css('font-style', 'normal')
	        .css('font-variant', 'normal')
	        .css('font-weight', 'bold')
            .css('display', 'block')
    }

    //============================================================
    //Adjust both popup-prompt-msg-box and grey-out-screen...
    //============================================================
    //Set the prompt-box location...
    ftnBlockAndGreyOutScreen_WindowScreenSizeMeasurement();

    //For active resizing...
    $(window).resize(function () {
        ftnBlockAndGreyOutScreen_WindowScreenSizeMeasurement();
    });
    //============================================================

    if (bDisplay == true) {
        $('#BlockAndGreyOutScreenPromptMessage').html(sMessage);
        $('#BlockAndGreyOutScreen').css('display', 'block');
    } else {
        $('#BlockAndGreyOutScreen').css('display', 'none');
    }
}
function ftnBlockAndGreyOutScreen_WindowScreenSizeMeasurement() 
{
    var iWebpageWidth = $('body').attr('clientWidth');  //$(document).width();  //$(window).width();
    var iWebpageHeight = $('body').attr('clientHeight');  //$(document).height();  //$(window).height();
    var iPopupDivWidth = $('#BlockAndGreyOutScreenPromptMessage').width();
    var iPopupDivHeight = $('#BlockAndGreyOutScreenPromptMessage').height();
    var iPopupDivScrollLeft = parseInt(document.documentElement.scrollLeft, 10);
    var iPopupDivScrollTop = parseInt(document.documentElement.scrollTop, 10);
    var iClientWidth = parseInt(document.documentElement.clientWidth, 10);
    var iClientHeight = parseInt(document.documentElement.clientHeight, 10);
    var iPositionLeft = ((iClientWidth - iPopupDivWidth) / 2) + iPopupDivScrollLeft;
    var iPositionHeight = ((iClientHeight - iPopupDivHeight) / 2) + iPopupDivScrollTop;

    //#http://efreedom.com/Question/1-1593050/Can-Get-IEs-Width-Without-Scrollbar...
    //#JQuery's $(document).width() show horizontial bar in IE, so $('body').attr('clientWidth') took care of this problem...
    //#Documentation from Mozilla Developer Center said "clientWidth is the inner width of an element in pixels. It includes padding but not the vertical scrollbar (if present, if rendered), border or margin"...
    //#Documentation from MSDN said "Retrieves the width of the object including padding, but not including margin, border, or scroll bar."...

    //Reset webpage's width & height (due to window resizing or whatever)...
    //TODO - Detect IE and adjust the width/height        
    $('#BlockAndGreyOutScreen').css('width', '' + iWebpageWidth + 'px');  /* IE is the only web-browser that show scrollbar [a bug of some sort in IE])... */
    $('#BlockAndGreyOutScreen').css('height', '' + iWebpageHeight + 'px');  /* IE is the only web-browser that show scrollbar [a bug of some sort in IE])... */

    //Set the property of the popup prompt msg...
    $('#BlockAndGreyOutScreenPromptMessage').css('left', iPositionLeft + 'px');
    $('#BlockAndGreyOutScreenPromptMessage').css('top', iPositionHeight + 'px');
}
function ftnExpandOrCollapseDiv1(sId) {  //This tag doesn't remember every expanded div(s) on every post-back, alternative function is found below...
    //Notice: The ID on all div tag must have unique name for every expanding/collapsing div(s)...
    var oGetElementById1 = document.getElementById(String(sId) + String("1"));
    var oGetElementById2 = document.getElementById(String(sId) + String("2"));
    var oDisplay1 = oGetElementById1.style.display;

    if (oDisplay1 == '') {
        oGetElementById1.style.display = 'block';
    } else if (oDisplay1 == 'block') {
        oGetElementById1.style.display = 'none';
    } else if (oDisplay1 == 'none') {
        oGetElementById1.style.display = 'block';
    }

    if (oGetElementById2.innerHTML == '-') {
        oGetElementById2.innerHTML = '+';
    } else if (oGetElementById2.innerHTML == '+') {
        oGetElementById2.innerHTML = '-';
    }
}
function ftnExpandOrCollapseDiv2(sId, sAction) {
    //Notice: The ID on all div tag must have unique name for every expanding/collapsing div(s)...
    var oDivDataPlus = document.getElementById(String(sId) + String("Plus"));
    var oDivDataHidden = document.getElementById(String(sId) + String("Hidden"));
    var oDivDataMinus = document.getElementById(String(sId) + String("Minus"));

    var oDisplay1 = oDivDataPlus.style.display;

    if (sAction == "E") {
        oDivDataPlus.style.display = 'none';
        oDivDataHidden.style.display = 'inline';
        oDivDataMinus.style.display = 'inline-block';
    } else if (sAction == "C") {
        oDivDataPlus.style.display = 'inline-block';
        oDivDataHidden.style.display = 'none';
        oDivDataMinus.style.display = 'none';
    }
}
function ftnJavascriptErrorDotNetEmailer(sMsg, sUrl, sLinenumber) {
    /* http://stephenwalther.com/blog/archive/2010/03/26/using-jquery-to-insert-a-new-database-record.aspx */
    //Notice #1: Do not use "$(document).ready(function() { .... });" because it prevent javascript from working...
    var sHttpOrHttps = "";
    var sHttpHost = "";
    var oObjectArray = {};
    var sJsonData = "";

    // Block sending of any further emails if javascript errors is in infinite loop while web events or browser is running...
    if (g_iJsErrorEmailCount < 10) {
        //#$(document).ready(function() {
        g_iJsErrorEmailCount++;

        sHttpOrHttps = window.location.protocol;
        sHttpHost = window.location.hostname;

        /*
        if (sHttpHost != "www.dealpack.com") {
        if (sHttpHost == "localhost") {
        //#sHttpHost = c_sHttpHost + ":" + window.location.port;
        sHttpHost = window.location.host;
        sHttpOrHttps = window.location.protocol;
        } else {
        sHttpHost = "test.dealpack.com";
        }
        }
        */

        //Build JSON string....
        oObjectArray["sApplicationId"] = "73891401";
        oObjectArray["sJsMsg"] = String(sMsg);
        oObjectArray["sJsUrl"] = String(sUrl);
        oObjectArray["sJsLineNo"] = String(sLinenumber);
        sJsonData = JSON.stringify(oObjectArray);

        /*
        1) sTextStatus 
        * timeout - when your specified timeout is exceeded...
        * error - http error, like 404...
        * notmodified - when requestd resource was not modified since last request...
        * parsererror - when an xml/json response is bad...
        2) oXmlHttpRequest.readyState
        * 1 - loading...
        * 2 - loaded...
        * 3 - interactive...
        * 4 - complete...
        */
        $.ajax({
            type: "POST",
            async: true, /*false, //This need to be synchronous to the client can wait for a webserver response...*/
            url: sHttpOrHttps + "//" + sHttpHost + "/websrvc/DealerSiteAjaxAccessForInternalUseOnly.asmx/JavascriptErrorNotification",
            data: sJsonData,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (oData, sTextStatus, oXmlHttpRequest) {
                //#alert(oData.d);
                //#alert("AjaxStatus: " + sTextStatus + "\nReadyState - " + oXmlHttpRequest.readyState + "\nStatus: " + oXmlHttpRequest.status + "\nStatusText: " + oXmlHttpRequest.statusText + "\nResponseText: " + oXmlHttpRequest.responseText);
                //#alert("AJAX Success: " + sTextStatus);
            },
            error: function (oXmlHttpRequest, sTextStatus, oErrorThrown) {
                //#alert("AjaxStatus: " + sTextStatus + "\nReadyState - " + oXmlHttpRequest.readyState + "\nStatus: " + oXmlHttpRequest.status + "\nStatusText: " + oXmlHttpRequest.statusText + "\nResponseText: " + oXmlHttpRequest.responseText);
                //#alert("AJAX Error: " + sTextStatus);
            }
            //complete: function(oXmlHttpRequest, sTextStatus) {  //Debug only...
            //    //sTextStatus --> success, notmodified, error, timeout, or parseerror (This is an AJAX events)...
            //    //##alert("AjaxStatus: " + sTextStatus + "\nReadyState - " + oXmlHttpRequest.readyState + "\nTimeout: " + oXMLHttpRequest.timeout + "\nStatus: " + oXmlHttpRequest.status + "\nStatusText: " + oXmlHttpRequest.statusText + "\nResponseText: " + oXmlHttpRequest.responseText);
            //    alert("AjaxStatus: " + sTextStatus + "\nReadyState - " + oXmlHttpRequest.readyState + "\nStatus: " + oXmlHttpRequest.status + "\nStatusText: " + oXmlHttpRequest.statusText + "\nResponseText: " + oXmlHttpRequest.responseText);
            //}
        });
        //#});
    }

    return true;
}
function ftnJavascriptErrorInitialize()
{
    //=================================================
    //Non-Ajax errors...
    //=================================================
    //Notice #1: Do not use the parathesis, '()' after the word, 'errorNotifyByEmail' as 'errorNotifyByEmail()' because it cause javascript to raise an error without calling the 'errorNotifyByEmail' function...
    //Notice #2: Do not use "window.onerror = function() { .... }" because it prevent "window.onerror()" from working...
    //Notice #3: Decided not to use JQUERY "$(window).error(function(msg, url, line){...}" because if there's a JQUERY error then there's a good chance this "window.onerror" won't fire...
    //Notice #4: Also, it was noticed that JQUERY library seems to be broken and it can't do "$(window).error(...)" as it can with "$(window).load(...)"...
    window.onerror = ftnJavascriptErrorNotification;

    //How To Debug --> (In order to raise javascript error) --> Add this script (see below) to *.aspx webpage after "window.onload()" event handler...
    /*
    <script type='text/javascript'>
    ftn();  //Undefined function...
    </script>
    */
    //=================================================

    //=================================================
    //ASP.NET Ajax errors...
    //=================================================
    //http://weblogs.asp.net/scottgu/archive/2006/10/29/Tip_2F00_Trick_3A00_-Handling-Errors-with-the-UpdatePanel-control-using-ASP.NET-AJAX.aspx
    //http://msmvps.com/blogs/luisabreu/archive/2006/10/29/UpdatePanel_3A00_-having-fun-with-errors.aspx
    //http://www.webreference.com/programming/asp/ASPNet-Exception-Handling/

    //Notice #1: This does not go to this "http(s)://???.bookitout.com/websrvc/DealerSiteAjaxAccessForInternalUseOnly.asmx/JavascriptErrorEmail" webservice, instead 
    //           it goes to ASP.NET's code-behind exception error handler that send an ASP.NET error email...
    $(document).ready(function() {
        if (Sys != undefined) {
            var prm = Sys.WebForms.PageRequestManager.getInstance();

            //#prm.add_endRequest(function() {
            //#  //Script here....
            //#});
            prm.add_endRequest(function() { ftnJavascriptErrorAspNetBeginRequest() });
            //Debug only...
            //#prm.add_beginRequest(function() {
            //#    alert("Javascript Error Handler --> Begin Request Handler Called...");
            //#});
        }
    });

    //How To Debug --> (In order to raise javascript error) --> Add this script (see below) to *.aspx webpage after "window.onload()" event handler...
    /*
    <script type='text/javascript' runat='server'>
    void GenerateError(object sender, EventArgs e) 
    {
    try 
    {
    int x = 5;
    int y = 0;
    int result = (x / y);
    } 
    catch (Exception ex) 
    {
    throw ex;
    }
    }
    </script>
    <asp:ScriptManager runat='server' ID='ScriptManager1'></asp:ScriptManager>
    <asp:UpdatePanel runat='server' ID='UpdatePanel1'>
    <ContentTemplate>
    <asp:Button ID="Button1" runat='server' Text='Raise Error...' OnClick="GenerateError" />
    </ContentTemplate>
    </asp:UpdatePanel>
    */

    //=================================================
    //JQuery Javascript/Ajax errors...
    //=================================================
    //http://www.thefutureoftheweb.com/blog/hidden-ajax-errors-in-jquery

    //Debug only...
    //Notice #1: This raise error to Firebug only...
    /*
    $(document).ajaxError(function() {
        if (window.console && window.console.error) {
            console.error(arguments);
        }
    });
    */

    //TODO - Grab JQuery javascript error and send an email...  (12/03/2010 - Right now can't find anything from Google surfing. :-( )...
    //??? =     ftnJavascriptErrorDotNetEmailer(sMsg, sUrl, sLinenumber);
    //=================================================
}
function ftnJavascriptErrorAspNetBeginRequest(sender, args) {
    //Notice #1: This does not go to this "http(s)://???.dealpack.com/websrvc/DealerSiteAjaxAccessForInternalUseOnly.asmx/JavascriptErrorEmail" webservice, instead
    //           it goes to ASP.NET's code-behind exception error handler that send an ASP.NET error email...
    if (args != undefined) {
        if (args.get_error() != undefined) {
            args.set_errorHandled(true);
            //Debug only...
            //#alert("Javascript Error Handler --> End Request Handler Called...");
            //#alert(args.get_error().description);
        }
    }
}
function ftnJavascriptErrorNotification(sMsg, sUrl, sLinenumber) 
{
    ftnJavascriptErrorDotNetEmailer(sMsg, sUrl, sLinenumber);

    return true;
}
function ftnThrobblerAnimation() {
    //http://malsup.com/jquery/block/
    //http://stackoverflow.com/questions/1580028/asp-net-ajax-using-jquery-blockui-in-two-places-can-i-unblock-a-specific-div
    //http://forums.asp.net/t/1570281.aspx
    //http://http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=384

    //http://http://www.dotnetcurry.com/ShowArticle.aspx?ID=227
    $(document).ready(function () {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        //var iWebpageWidth = $('body').attr('clientWidth');  //$(document).width();  //$(window).width();
        //var iWebpageHeight = $('body').attr('clientHeight');  //$(document).height();  //$(window).height();

        // Unblock the form when a partial postback ends.
        prm.add_endRequest(function () {
            ftnThrobblerAnimationEnd1();
        });
        prm.add_beginRequest(function () {
            ftnThrobblerAnimationBegin1();
        });
    });
}
function ftnThrobblerAnimationBegin1() {
    var sPathName = window.location.pathname;
    var iDirFolderCount = (sPathName.split("/").length - 1);
    var x = 0;
    var sRelativeDirPath = "";
    var sDivScript = "";

    iDirFolderCount -= 1;  //Remove Session ID from URL directory path...
    iDirFolderCount -= 1;  //Remove a slash before the "w1", "w2", etc. directory...

    for (x = 0; x < iDirFolderCount; x++) {
        sRelativeDirPath = sRelativeDirPath + "../";
    }

    //$('body').block({ css: { width: '32px', height: '32px' }, message: "<div class='divBlockUiInnerLayout1'><div>" });
    //$('body').block({ overlayCSS: { backgroundColor: '#ffffff', width: String(iWebpageWidth) + 'px', height: String(iWebpageHeight) + 'px' }, css: { width: '32px', height: '32px' }, message: "<div class='divBlockUiInnerLayout1'><div>" });
    //#$('body').block({ overlayCSS: { backgroundColor: '#ffffff', width: '100%', height: '100%' }, css: { width: '32px', height: '32px' }, message: '<div style="background-image:url(\'' + sRelativeDirPath + 'images1/blockui/blockui-loader1.gif\');background-position:0px 0px;background-repeat:no-repeat;height:100%;width:100%;"><div>' });
    ftnBlockAndGreyOutScreen(true, "600", "50", "Processing your request");
}
function ftnThrobblerAnimationEnd1() {
    //#$('body').unblock();
    ftnBlockAndGreyOutScreen(false, "0", "0", "");
}
function ftnValidateFormClear()
{
    //05/18/2011 - Discontinued...
    /*
    $('input[type="text"]').css({ "background-color": g_sValidateFormClearColor });  //textboxes...
    $('input[type=password]').css({ "background-color": g_sValidateFormClearColor });  //textboxes...
    $('input[type=search]').css({ "background-color": g_sValidateFormClearColor });  //textboxes...
    $('input[type=select]').css({ "background-color": g_sValidateFormClearColor });  //textboxes...
    $('input[type=value]').css({ "background-color": g_sValidateFormClearColor });  //textboxes...
    $('select').css({ "background-color": g_sValidateFormClearColor });  //drop-down selections...
    $('textarea').css({ "background-color": g_sValidateFormClearColor });  //text-areas...

    //============================================================================================================
    //02/03/2011 - Noticed - if radio-button or checkboxes, better use the "spanHtmlFormValidation_<<html form id>>" instead, make the webpage look more nicer this way...
    //#$('input[type=radio]').css({ "background-color": g_sValidateFormClearColor });  //radio-buttons...
    //#$('input[type=checkbox]').css({ "background-color": g_sValidateFormClearColor });  //checkboxes...
  //  $('#[id^=spanHtmlFormValidation_]').css({ "background-color": "transparent" });  //span-wrapper around radio-button or check-boxes...
    $('#[id^=spanHtmlFormValidation_]').css({ "background-color": "transparent" });  //span-wrapper around radio-button or check-boxes...

    * $('#[id^=spanHtmlFormValidation_]') filter takes care of any "spanHtmlFormValidation_...." id tags... * * http://stackoverflow.com/questions/2707265/jquery-select-all-inputs-with-unique-id-regex-wildcard-selectors *
    * $('[id$=_txtSymbol]') filter takes care of any "...._txtSymbol" id tags... * * http://www.west-wind.com/weblog/posts/42319.aspx *
    //============================================================================================================
    
    ftnValidateFormPopupMsg('', '');
    */
}
function ftnValidateFormErrorCheck(sFormElementId, sErrorMsg)
{
    /*
    //05/18/2011 - Discontinued...
    if (sFormElementId.length > 0) {
        //04/14/2011 - Since Contact-Us's phone are broken down into 3 textboxes, so we need an another way to do this...
        if (sFormElementId == "txtContactUsPhone3") {
            $('#txtContactUsPhone1').css({ "background-color": g_sValidateFormErrorColor }); //Any html element objects...
            $('#txtContactUsPhone2').css({ "background-color": g_sValidateFormErrorColor }); //Any html element objects...
            $('#txtContactUsPhone3').css({ "background-color": g_sValidateFormErrorColor }); //Any html element objects...
        } else {
            //03/11/2011 - Don't background-color the html button...
            //02/03/2011 - Noticed - if radio-button or checkboxes, better use the "spanHtmlForm_<<html form id>>" instead, make the webpage look more nicer this way...
            if (sFormElementId.substring(0, 3) != "btn") {
                $('#' + sFormElementId).css({ "background-color": g_sValidateFormErrorColor }); //Any html element objects...
            }
        }
        ftnValidateFormPopupMsg(sFormElementId, sErrorMsg);
    }
    */
}
function ftnValidateFormPopupMsg(sFrmElementId, sTxtMsg) {
    //06/02/2011 - The use of "$('body').append('...');" crashed IE7 and under due to a lousy feature in IE (but feature was then changed in IE8), but a workaround is to use "$(document).ready(function(){});" script to delay the activation of this script until IE finish loading the webpage...
    $(document).ready(function () {
        //Create javascript objects...
        if ($('#ValidateFormMsg').length == 0) {
            $('body').append('<div id="ValidateFormMsg"><div id="ValidateFormMsgContent"></div></div>');    
        }

        var msg = document.getElementById('ValidateFormMsg');
        var msgcontent = document.getElementById('ValidateFormMsgContent');
        var targetdiv = document.getElementById(sFrmElementId);

        //To clear the pop-up message if not needed...
        if ((sFrmElementId.length == 0) && (sTxtMsg.length == 0)) {
            //g_bValidateFirstTimePopup = true;
            msgcontent.innerHTML = "";
            msg.style.display = 'none';
            return;  //This exit the function...
        }
        msgcontent.innerHTML = sTxtMsg.replace("'","`") + "<br /><div style=\"padding-top:2px;text-align:center;\"><a href=\"#\" class=\"aValidate1\" onclick=\"ftnValidateFormPopupMsg('', '');\">Close</a></div>";
        msg.style.display = 'block';
        msg.style.zIndex = '2100';

        var msgheight = msg.offsetHeight;
        //05/14/2010 - Cannot use this focus() feature cuz we want to point the pop-up div to a 2nd form object (textbox, drop-down selection, etc.) while the 1st form object is "yellow" highlighted as the original error...
        //#targetdiv.focus();
        var targetheight = targetdiv.offsetHeight;
        var targetwidth = targetdiv.offsetWidth;
        var topposition = ftnValidateFormPopupTopPosition(targetdiv) - ((msgheight - targetheight) / 2);
        var leftposition = ftnValidateFormPopupLeftPosition(targetdiv) + targetwidth + 3;
        if (g_bValidateFirstTimePopup == true) {
            g_bValidateFirstTimePopup = false;
            leftposition = leftposition + 9;
        }
        msg.style.top = topposition + 'px';
        msg.style.left = leftposition + 'px';
    });
}
function ftnValidateFormPopupLeftPosition(oFrmElementId) {
    // calculate the position of the element in relation to the left of the browser //
    var left = 0;
    if (oFrmElementId.offsetParent) {
        while (1) {
            left += oFrmElementId.offsetLeft;
            if (!oFrmElementId.offsetParent) {
                break;
            }
            oFrmElementId = oFrmElementId.offsetParent;
        }
    } else if (oFrmElementId.x) {
        left += oFrmElementId.x;
    }
    return left;
}
function ftnValidateFormPopupTopPosition(oFrmElementId) {
    // calculate the position of the element in relation to the top of the browser window //
    var top = 0;
    if (oFrmElementId.offsetParent) {
        while (1) {
            top += oFrmElementId.offsetTop;
            if (!oFrmElementId.offsetParent) {
                break;
            }
            oFrmElementId = oFrmElementId.offsetParent;
        }
    } else if (oFrmElementId.y) {
        top += oFrmElementId.y;
    }
    return top;
}

//Initialize the scripts on all webpages..
$(window).load(function () {
    ftnJavascriptErrorInitialize();
    ftnThrobblerAnimation();  //This function works better in "window.onload()" event than it is with "$(document).ready({})", so that's what we gonna do this time, I think it had to do with the way the BlockUI component works internally (can't run until webpage finish loading)..
});

