﻿YAHOO.namespace("CSAjax");
YAHOO.CSAjax.Connection = function () {

    var StartRequest = function (type, url, callbackObj, jsArg) {
        YAHOO.util.Connect.asyncRequest(type, url, callbackObj, jsArg);
    };

    return {

        Get: function (url, callbackObj) {
            StartRequest("GET", url, callbackObj, null);
        },

        Post: function (url, callbackObj, jsData, preventJSON) {
            try {
                if (!preventJSON && YAHOO.env.ua.gecko == 0) {
                    var jsArg = { "jsString": YAHOO.lang.JSON.stringify(jsData) };
                    StartRequest("POST", url, callbackObj, YAHOO.lang.JSON.stringify(jsArg));
                }
                else {
                    var jsArg = null;
                    YAHOO.util.Connect.resetDefaultHeaders();
                    YAHOO.util.Connect.setDefaultPostHeader(false);
                    YAHOO.util.Connect.initHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                    jsArg = "jsString=" + YAHOO.lang.JSON.stringify(jsData);
                    StartRequest("POST", url, callbackObj, jsArg);
                }
            }
            catch (e) {
                //Do something{}
            }
        }
    }
} ();


YAHOO.namespace("CSUtils");
YAHOO.CSUtils.Utils = function () {
    var m_oYEVNT = YAHOO.util.Event, //Contains Event Fxns
        m_oYDOM = YAHOO.util.Dom, //Contains DOM Manip Fxns
        m_oConnect = YAHOO.CSAjax.Connection, //Ajax connection manager
        m_oValidators = {
            "alpha": /^[a-zA-Z\s]*$/,
            "phone": /^(\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}([\s]?(x{1}|ext[.]?)[\s]?\d{2,6})?$/,
            "alpha num plus (max 50)": /^["'\-,\.#\/\\\w\s\d\$]*$/,
            "zip": /^\d{5}([- ]?\d{4})?$/,
            "email": /^[a-zA-Z0-9\-][a-zA-Z0-9\._%\-\+]*@[\-a-zA-Z0-9]+(\.[\-a-zA-Z0-9]+)*\.([cC][oO][mM]|[eE][dD][uU]|[iI][nN][fF][oO]|[gG][oO][vV]|[iI][nN][tT]|[mM][iI][lL]|[nN][eE][tT]|[oO][rR][gG]|[bB][iI][zZ]|[nN][aA][mM][eE]|[mM][uU][sS][eE][uU][mM]|[cC][oO]{2}[pP]|[aA][eE][rR][oO]|[pP][rR][oO]|[a-zA-Z]{2})$/,
            "date": /^(10|11|12|[0]?\d)\/(30|31|(0|1|2)?\d)\/(\d{2}|\d{4})$/,
            "comments": /^[^\^]*$/
        },
        m_oOptions = {
            "CStatesAbbrev": [{ key: -1, value: "set state" }, { key: 1, value: "AL" }, { key: 2, value: "AK" }, { key: 3, value: "AZ" }, { key: 4, value: "AR" }, { key: 5, value: "CA" }, { key: 6, value: "CO" }, { key: 7, value: "CT" }, { key: 8, value: "DE" }, { key: 9, value: "DC" }, { key: 10, value: "FL" }, { key: 11, value: "GA" }, { key: 12, value: "HI" }, { key: 13, value: "ID" }, { key: 14, value: "IL" }, { key: 15, value: "IN" }, { key: 16, value: "IA" }, { key: 17, value: "KS" }, { key: 18, value: "KY" }, { key: 19, value: "LA" }, { key: 20, value: "ME" }, { key: 21, value: "MD" }, { key: 22, value: "MA" }, { key: 23, value: "MI" }, { key: 24, value: "MN" }, { key: 25, value: "MS" }, { key: 26, value: "MO" }, { key: 27, value: "MT" }, { key: 28, value: "NE" }, { key: 29, value: "NV" }, { key: 30, value: "NH" }, { key: 31, value: "NJ" }, { key: 32, value: "NM" }, { key: 33, value: "NY" }, { key: 34, value: "NC" }, { key: 35, value: "ND" }, { key: 36, value: "OH" }, { key: 37, value: "OK" }, { key: 38, value: "OR" }, { key: 39, value: "PA" }, { key: 40, value: "PR" }, { key: 41, value: "RI" }, { key: 42, value: "SC" }, { key: 43, value: "SD" }, { key: 44, value: "TN" }, { key: 45, value: "TX" }, { key: 46, value: "UT" }, { key: 47, value: "VT" }, { key: 48, value: "VI" }, { key: 49, value: "VA" }, { key: 50, value: "WA" }, { key: 51, value: "WV" }, { key: 52, value: "WI" }, { key: 53, value: "WY"}],
            "CFrequency": [{ key: 0, value: "Never" }, { key: 1, value: "Daily" }, { key: 2, value: "Weekly" }, { key: 3, value: "Bi-Weekly" }, { key: 4, value: "Monthly"}]
        };

    var EQUALTO = 0, GT = 1, LT = 2;

    /* 
    *  Called by the function CreateElement. Adds the options to the dropdown
    * 
    *  @param {object} element  - The dropdown element
    *  @param {object} options  - Dropdown options
    *  @param {string} dispText - Text to be selected on dropdown
    */
    var AddOptions = function (element, options, dispText) {
        var oOption = null;
        for (iOptionIdx in options) {
            oOption = document.createElement("option");
            oOption.value = options[iOptionIdx].key;
            oOption.text = options[iOptionIdx].value;
            element.options.add(oOption);
            if (options[iOptionIdx].value == dispText) element.selectedIndex = options[iOptionIdx].key + "";
        }
    },

    PreFetchImg = function (contID) {
        var oImg = YAHOO.CSUtils.Utils.CreateElement("img");
        m_oYDOM.setAttribute(oImg, "src", m_oBGImgs[contID].images[m_oBGImgs[contID].imgCtr].src);
    },

    CreatePopUpHTML = function () {
        var oMsk = CSUtils.CreateElement("div", "PopOver_c", null, null, null, "mask");
        oMsk.appendChild(CSUtils.CreateElement("div", "PopOver", null, null, null, "frmContainer"));
        document.body.appendChild(oMsk);
    },

    PopWrapper = function (elem) {
        var divAll = null;

        //Create Popin
        divAll = YAHOO.CSUtils.Utils.CreateElement("div", null, null, null, null, "PPAll")
        divAll.appendChild(YAHOO.CSUtils.Utils.CreateElement("div", null, null, null, null, "PPTop"));
        var divMid = YAHOO.CSUtils.Utils.CreateElement("div", "CSCntnt", null, null, null, "PPMid clearfix");
        divMid.appendChild(elem);
        divAll.appendChild(divMid);
        divAll.appendChild(YAHOO.CSUtils.Utils.CreateElement("div", null, null, null, null, "PPBtm"));
        m_oYDOM.get("PopOver").appendChild(divAll);
        var iVwHt = m_oYDOM.getViewportHeight() - 100,
            iElemH = m_oYDOM.getRegion("CSCntnt").bottom - m_oYDOM.getRegion("CSCntnt").top;
        m_oYDOM.setStyle(m_oYDOM.get("PopOver"), "margin-top", "-" + (iVwHt / 2) + "px");
        if (iElemH >= iVwHt) {
            var divCntnt = m_oYDOM.get("CSCntnt");
            m_oYDOM.setStyle(divCntnt, "height", iVwHt + "px");
            m_oYDOM.setStyle(divCntnt, "overflow", "auto");
        }
    },

    /***********************Callback functions ************************/
     CBPOPSuccess = function (o) {
         var oRetInfo = YAHOO.lang.JSON.parse(o.responseText);

         var oDiv = YAHOO.CSUtils.Utils.CreateElement("div");
         oDiv.innerHTML = oRetInfo.html;
         YAHOO.CSUtils.Utils.CreatePopUpWizard(oDiv);

         if (oRetInfo.js && oRetInfo.js != "")
             eval(oRetInfo.js);
     },

     CBPOPFailure = function (o) {
         alert("Failure");
     };

    return {
        /* 
        *  Name of the cookie to look for a value for
        * 
        *  @param {string} cookieName - Name of cookie to retrieve
        */
        GetCookieVal: function (cookieName) {
            try { var sCookie = document.cookie.match('(^|;) ?' + cookieName + '=([^;]*)(;|$)'); }
            catch (e) { }

            if (sCookie) return (unescape(sCookie[2]));
            return null;
        },

        /* 
        *  Deletes a cookie
        * 
        *  @param {string} cookieName - Name of cookie to delete
        */
        DeleteCookie: function (cookieName) {
            try {
                var dtNow = new Date();                 //Current date & time
                dtNow.setTime(dtNow.getTime() - 1);     //1 second ago
                SetCookie(cookieName, "noval", dtNow);  //Overwrite cookie
            }
            catch (e) { }
        },

        /* 
        *  Sets a cookie
        * 
        *  @param {string} cookieName       - Name of cookie
        *  @param {string} cookieVal        - Value of cookie (will be stored escaped)
        *  @param {Date} cookieExpiration   - Expiration date (one year from now if left empty)
        */
        SetCookie: function (cookieName, cookieVal, cookieExpiration) {
            try {
                var sCookie = cookieName + "=" + escape(cookieVal);

                if (!cookieExpiration) {
                    var dtNow = new Date();
                    dtNow.setFullYear(dtNow.getFullYear() + 1); //1 from now
                    cookieExpiration = dtNow;
                }

                sCookie += "; expires=" + cookieExpiration.toGMTString();
                sCookie += "; path=" + escape("/");

                document.cookie = sCookie;
            } catch (e) { }
        },

        GetOptions: function () {
            return m_oOptions;
        },

        /* 
        *  Creates element with passed attributes  
        * 
        *  @param {string} eTag            - tag type
        *  @param {string} eId             - Id for the new element
        *  @param {string} dispText        - display text
        *  @param {string} eValue          - value attribute (ignored if options is null)
        *  @param {string} eHref           - href attribute
        *  @param {string} eClass          - class name
        *  @param {string} style           - style attribute
        *  @param {object} options         - Item Collection for dropdown
        *  @param {string} eventType       - event type
        *  @param {function} hndlrFunction - Click event handler function
        *  @param {object} scope           - Scope for Listener 
        *  @param {string} src             - src attribute 
        *  @param {string} alt             - alt attribute   
        */
        CreateElement: function (eTag, eId, dispText, eValue, eHref, eClass, style, options, eventType, hndlrFunction, scope, src, alt) {
            var oEle = document.createElement(eTag);
            if (eId) {
                m_oYDOM.setAttribute(oEle, "id", eId);
                m_oYDOM.setAttribute(oEle, "name", eId); //Support for IE6
            }
            if (dispText) oEle.innerHTML = dispText;
            if (eValue) m_oYDOM.setAttribute(oEle, "value", eValue);
            if (eHref) m_oYDOM.setAttribute(oEle, "href", eHref);
            if (eClass) m_oYDOM.setAttribute(oEle, "class", eClass);
            if (style) m_oYDOM.setAttribute(oEle, "style", style);
            if (options) {
                eValue = eValue == "" ? "0" : eValue;
                AddOptions(oEle, m_oOptions[options], m_oOptions[options][eValue].value);
            }
            if (hndlrFunction && eventType) m_oYEVNT.addListener(oEle, eventType, hndlrFunction, scope == null ? oEle : scope, true);
            if (src) m_oYDOM.setAttribute(oEle, "src", src);
            if (alt) m_oYDOM.setAttribute(oEle, "alt", alt);
            return oEle;
        },

        DisablePop: function () {
            //Remove mask
            var oMask = m_oYDOM.get("PopOver_c")
            m_oYDOM.addClass(oMask, "DfltHidden");
        },

        CreateIFrame: function (id, src, height, width) {
            var oIFrame = this.CreateElement("iframe", id);
            m_oYDOM.setAttribute(oIFrame, "scrolling", "auto");
            m_oYDOM.setAttribute(oIFrame, "frameborder", "0");
            if (src) m_oYDOM.setAttribute(oIFrame, "src", src);
            m_oYDOM.setAttribute(oIFrame, "width", width);
            m_oYDOM.setAttribute(oIFrame, "height", height);
            m_oYDOM.setAttribute(oIFrame, "allowtransparency", false);
            return oIFrame;
        },

        AddFrameCont: function (iframe, content) {
            if (!iframe) return;
            var oDoc = iframe.contentWindow.document;
            oDoc.open();
            oDoc.write(content);
            oDoc.close();
        },

        /* 
        *  Creates a popup, and adds eventhandlers to disable it. If src is passed, cretes a popup
        *     with an IFrame pointing to src
        * 
        *  @param {string} src - Url        
        */
        CreatePopUpWizard: function (element) {
            if (!element) return;

            var oPopUpMask = m_oYDOM.get("PopOver_c");
            if (oPopUpMask == null) CreatePopUpHTML();

            m_oYDOM.removeClass(oPopUpMask, "DfltHidden"); //Unhide the the container.

            var oPopUp = m_oYDOM.get("PopOver")
            oPopUp.innerHTML = ""; //Clear existing fields            

            //Create close button 
            oPopUp.appendChild(this.CreateElement("a", "csclose", "<span>Close Window</span>", null, null, "CSSprite"));

            PopWrapper(element);

            //Close Email PopUp listener, this element is created above by us.
            var oClosePop = m_oYDOM.get("csclose");
            m_oYEVNT.addListener(oClosePop, "click", this.DisablePop);
        },

        cspw: function (url) {

            if (YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie < 7) return;

            if (!url || url.length == 0) return;

            // IFrame to external link
            if (url.indexOf("http") > -1) {
                this.CreatePopUpWizard(this.CreateIFrame("popFrame", url, "600px", "100%"));
                return;
            }

            //Make an ajax call which returns html to be popped-up
            var oCallBack =
            {
                success: CBPOPSuccess,
                failure: CBPOPFailure
            };
            m_oConnect.Get(url, oCallBack);
        },

        csstpw: function (url) {
            this.cspw(url);
        },

        /* 
        *  It validates the input of the field with the validation expression
        *     and assigns corresponding classes.
        * 
        *  @param {object} inputElement - The input element 
        *  @param {string} regExp - regular expression for validation 
        */
        ValidateField: function (inputElement, validate) {
            m_oYDOM.removeClass(inputElement, "Success");
            m_oYDOM.removeClass(inputElement, "Error");

            var oInputValue = inputElement.value;

            //If the value is empty return
            if (oInputValue == null || oInputValue.length == 0) return;

            if (oInputValue.match(m_oValidators[validate]) == null) {
                //Validation Failed
                m_oYDOM.addClass(inputElement, "Error");
            }
            else {
                //Validation Success
                m_oYDOM.addClass(inputElement, "Success");
            }
        },

        /* 
        *  Validates all the input fields and builds output object 
        * 
        *  @param {object} fields - Json object with all fields
        *  @param {string} fldPreFix - prefix to be added to the field name to get the input element's ID 
        */
        ValidateAllFields: function (fields, fldPreFix) {
            var IsRequired = false, IsSuccess = true, IsEmptySelect = false, m_oOut = { fields: {} };

            for (field in fields) {
                IsRequired = fields[field].required;
                oElement = m_oYDOM.get(fldPreFix + field);
                IsEmptySelect = fields[field].type == "select" && oElement.value == "-1";

                //Check Validation (which would have occurred on blur
                if (oElement.className.indexOf("Error") > -1)
                    IsSuccess = false;

                //Check Required fields
                else if (IsRequired && (oElement.value == "" || IsEmptySelect)) {
                    m_oYDOM.addClass(oElement, "Error");
                    IsSuccess = false;
                }

                //Build ouput object if successfully validated
                if (IsSuccess && !IsEmptySelect) {
                    m_oOut.fields[field] = { value: oElement.value, dbCol: fields[field].dbCol };
                }
            }
            if (IsSuccess) return m_oOut.fields;
            return null;
        },

        CleanResponse: function (response) {
            response = response.replace('<?xml version="1.0" encoding="utf-8"?>', "").replace('</string>', "").replace('<string xmlns="http://www.dfadmin.com/">', "");
            if (!YAHOO.lang.JSON.isSafe(response)) return response;

            var oJSResp = YAHOO.lang.JSON.parse(response);
            if (oJSResp.d) {
                if (YAHOO.lang.JSON.isSafe(oJSResp.d))
                    oJSResp = YAHOO.lang.JSON.parse(oJSResp.d);
                else
                    oJSResp = oJSResp.d;
            }
            return oJSResp;
        },

        /*
        * This utility function is used to create a consistent Year Make Model SubModel text.
        * 
        * Parameters:
        *   year            - Item is used to create YMMMS String 
        *    mk              - Item is used to create YMMMS String 
        *   mdl             - Item is used to create YMMMS String 
        *   dflt            - Item is used to indicate if it has YMMS created or not 
        */
        YMMSText: function (year, mk, mdl, smdl, dflt) {
            var sYMMS = "";
            if (year && year > 0) sYMMS = " " + year.toString();
            if (mk && mk.length > 0) sYMMS += " " + mk;
            if (mdl && mdl.length > 0) sYMMS += " " + mdl;
            if (smdl && smdl.length > 0) sYMMS += " " + smdl;
            if (sYMMS.length == 0) return dflt;
            return sYMMS.trim();
        },

        /*
        * This utility function is used to create a consistent Year Make Model SubModel text
        *   with a maximum character count.
        * 
        * Parameters:
        *   year            - Item is used to create YMMMS String 
        *    mk             - Item is used to create YMMMS String 
        *   mdl             - Item is used to create YMMMS String 
        *   dflt            - Item is used to indicate if it has YMMS created or not
        *   maxChars        - Max length of the YMMS text
        */
        YMMSTextMax: function (year, mk, mdl, smdl, dflt, maxChars) {

            //Year Make Model SubModel
            var sYMMS = this.YMMSText(year, mk, mdl, smdl, dflt);
            if (sYMMS.length <= maxChars) return sYMMS;

            //Year Make Model
            sYMMS = this.YMMSText(year, mk, mdl, null, dflt);
            if (sYMMS.length <= maxChars) return sYMMS;

            //Make Model
            sYMMS = this.YMMSText(null, mk, mdl, null, dflt);
            if (sYMMS.length <= maxChars) return sYMMS;

            //Year Model
            sYMMS = this.YMMSText(year, null, mdl, null, dflt);
            if (sYMMS.length <= maxChars) return sYMMS;

            //Model
            if (mdl && mdl.length <= maxChars) return mdl;

            return dflt;
        },

        /*
        *This utility function is used to make money more readable. 
        * Parameters:
        * sValueToBeautify     - Make Price more readable with $ sign 
        */
        Convert2PrettyString: function (sValueToBeautify) {

            var oRegExp = /(^[-]?\d+$)|(^[-]?\d*[\.]\d{1,2}$)/; //find if it is any integer or float(2 precision) like 0.12, .12, or 12.23
            if (!oRegExp.test(sValueToBeautify)) return "";
            sValueToBeautify = sValueToBeautify.split(".")[0];
            oRegExp = /(-?[0-9]+)([0-9]{3})/;
            while (oRegExp.test(sValueToBeautify)) {
                //replace original string with first group match,a comma, then second group match
                sValueToBeautify = sValueToBeautify.replace(oRegExp, '$1,$2');
            }
            return '$' + sValueToBeautify;
        },

        /*
        *This utility function is used to parse moneny into normal number. 
        * Parameters:
        * sDollarNumb     - it probably contain $ or , 
        */
        Currency2Numb: function (sDollarNumb) {
            if (!sDollarNumb || sDollarNumb == "") return 0;

            var iNumber = sDollarNumb.replace(/(\$|,)/gi, '');
            //check if iNumber is integer or float
            if (!(/(^[-]?\d+$)|(^[-]?\d*[\.]\d{1,2}$)/).test(iNumber))
                iNumber = 0;
            return iNumber;
        },

        /*
        * Description: Creates a menu and subscribes to its events.
        * 
        * Returns: 
        *   n/a
        * 
        * Parameters:
        *   menuID   - ID of the menu that needs to be rendered
        */
        CSCreateMainNavMenu: function (menuID) {
            var oMenu = new YAHOO.widget.MenuBar(menuID, { autosubmenudisplay: true, keepopen: true });

            //Stay visible after clicking on the menu bar root element
            oMenu.subscribe("click", function (eventType, eventArgs) {
                var oSubMenu = eventArgs[1].cfg.getProperty("submenu");
                if (oSubMenu && !oSubMenu.cfg.getProperty("visible"))
                    oSubMenu.show();
            });

            //CSS Hooks
            oMenu.subscribe("beforeShow", this.MenuCSHdrFtr);
            oMenu.render();
        },

        /*
        * Description: Assumes that in the current operating context, 
        *   the keyword this is a reference to a yi-menu object.  This function
        *   preprends our CSHd and appends our CSFt divs as CSS hooks
        *   *if* this menu is not scrolled.  If it is, we do not.
        *
        *   In the case where we are scrolled, we replace the reserved CSS hook
        *   classes with "XXX".
        * 
        * Returns: 
        *   n/a
        * 
        * Parameters:
        *   eventType   - Name of the event that triggered this callback
        *   eventArgs   - Event arguments (empty in at least beforeShow and show
        */
        MenuCSHdrFtr: function (eventType, eventArgs) {
            var menuID = this.id, menuBD = null;
            try { menuBD = m_oYDOM.getElementsByClassName("bd", "div", menuID)[0]; } catch (err) { }
            if (!menuBD) return;


            //Remove CS curvy corners holder if this is scrolled
            if (m_oYDOM.hasClass(menuBD, "yui-menu-body-scrolled")) {

                try { m_oYDOM.replaceClass(m_oYDOM.getElementsByClassName("CShd", "div", menuID)[0], "CShd", "XXX"); }
                catch (err) { }
                try { m_oYDOM.replaceClass(m_oYDOM.getElementsByClassName("CSft", "div", menuID)[0], "CSft", "XXX"); }
                catch (err) { }
                return;
            }

            //Create/insert CShd
            var oCssHook = m_oYDOM.getElementsByClassName("CShd", "div", menuID)[0];
            if (!oCssHook) oCssHook = m_oYDOM.getElementsByClassName("XXX", "div", menuID)[0];
            if (!oCssHook) {
                oDiv = document.createElement("div");
                sDivID = m_oYDOM.generateId(oDiv, "Hdr");
                oDiv.id = sDivID;
                oDiv.className = "CShd";
                m_oYDOM.insertBefore(oDiv, menuBD);
            }
            else { m_oYDOM.replaceClass(oCssHook, "XXX", "CShd"); }

            //Create/insert CSft
            oCssHook = m_oYDOM.getElementsByClassName("CSft", "div", menuID)[0];
            if (!oCssHook) oCssHook = m_oYDOM.getElementsByClassName("XXX", "div", menuID)[0];
            if (!oCssHook) {
                oDiv = document.createElement("div");
                sDivID = m_oYDOM.generateId(oDiv, "Ftr");
                oDiv.id = sDivID;
                oDiv.className = "CSft";
                m_oYDOM.insertAfter(oDiv, menuBD);
            }
            else { m_oYDOM.replaceClass(oCssHook, "XXX", "CSft"); }
        },

        /*
        *This utility function is used to encode query string.
        *escape function does not properly encode the '+' and '/' character 
        *these characters need to be converted manually
        http://www.permadi.com/tutorial/urlEncoding/
        */
        EncodeString: function (sEncoding) {
            if (!sEncoding || sEncoding.length == 0) return sEncoding;

            var sEncoded = escape(sEncoding);
            if (sEncoded.indexOf('+') > -1)
                sEncoded = sEncoded.replace(/[+]/, "%2B");

            if (sEncoded.indexOf('/') > -1)
                sEncoded = sEncoded.replace(/[\/]/g, "%2F");
            return sEncoded;
        },

        /* 
        * Decodes the URL string 
        */
        DecodeURL: function (sURL) {
            return unescape(sURL).replace(/[+]/g, " ");
        },

        /*
        *This utility function is used to decode paramValue. 
        * Parameters:
        * paramValue        - Value has encoded value and junk sign '+'
        */
        GetDecodedParamValue: function (paramValue) {
            if (YAHOO.lang.isNull(paramValue)) return paramValue;
            return unescape(paramValue.replace(/[+]/g, " "));
        },

        /* Client-side access to querystring name=value pairs
        * Version 1.3
        * 28 May 2008
        *
        * License (Simplified BSD):
        * http://adamv.com/dev/javascript/qslicense.txt
        */
        Querystring: function (qs) { // optionally pass a querystring to parse
            this.params = {};

            if (qs == null) qs = location.search.substring(1, location.search.length);
            if (qs.length == 0) return;

            // Turn <plus> back to <space>
            // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
            qs = qs.replace(/\+/g, ' ');
            var args = qs.split('&'); // parse out name/value pairs separated via &

            // split out each name=value pair
            for (var i = 0; i < args.length; i++) {
                var pair = args[i].split('=');
                var name = decodeURIComponent(pair[0]).toLowerCase();

                var value = (pair.length == 2) ? decodeURIComponent(pair[1]) : name;

                this.params[name] = value;
            }
        },

        /*
        *   This utility function creates key value pairs suitable for a querystring GET request
        *
        *   Parameters:
        *       qs              - if set, we will use this QueryString object
        *       paramName        - As a new key for new querystring
        *       paramKey         - key in querystring
        *       isSimple         - decide whether or not to call GetDecodedParamValue
        *       preventQuotes   - Set to have the value returned with quotes around it
        */
        GetParam: function (paramName, paramKey, isSimple, preventQuotes) {
            return this.GetParam(new Querystring(), paramName, paramKey, isSimple, preventQuotes);
        },

        /*
        *   This utility function creates key value pairs suitable for a querystring GET request
        *
        *   Parameters:
        *       qs              - if set, we will use this QueryString object
        *       paramName        - As a new key for new querystring
        *       paramKey         - key in querystring
        *       isSimple         - decide whether or not to call GetDecodedParamValue
        *       preventQuotes   - Set to have the value returned with quotes around it
        */
        GetParam: function (qs, paramName, paramKey, isSimple, preventQuotes) {
            if (!qs) qs = new Querystring();
            return paramName + "=" + this.QSVal(qs, paramKey, isSimple, preventQuotes) + "&";
        },

        /*
        *   This utility function is used to get the value of a QS parameter
        * 
        *   Parameters:
        *       qs              - if set, we will use this QueryString object
        *       paramKey        - key in querystring
        *       isSimple        - decide whether or not to call GetDecodedParamValue
        *       preventQuotes   - Set to have the value returned with quotes around it
        */
        QSVal: function (qs, paramKey, isSimple, preventQuotes) {
            if (!qs) qs = new Querystring();
            var sParamValue = qs.get(paramKey.toLowerCase(), null);

            if (!isSimple) {
                sParamValue = this.GetDecodedParamValue(sParamValue);
            }

            if (!YAHOO.lang.isNull(sParamValue) && !preventQuotes)
                sParamValue = "\"" + escape(sParamValue) + "\"";

            return sParamValue;
        },

        YFromViewPort: function (inputEle) {
            var iWinOffset = null;
            try {
                if (window) iWinOffset = window.pageYOffset;
                if (iWinOffset == null || iWinOffset == undefined) {
                    if (document.documentElement && document.documentElement.clientHeight)
                        iWinOffset = document.documentElement.scrollTop;
                    else iWinOffset = document.body.scrollTop;
                }
            }
            catch (err) { }
            return m_oYDOM.getY(inputEle) - +iWinOffset;
        },

        BGRttrInit: function (contID) {
            if (!m_oBGImgs || !m_oBGImgs[contID]) return;

            //Get image list
            var oImgs = m_oBGImgs[contID].images;
            if (oImgs.length == 0) return;

            //Locals
            var iCtr = m_oBGImgs[contID].imgCtr,
                sImgUrl = oImgs[iCtr].src,
                sNavUrl = oImgs[iCtr].navUrl;

            //Remove the previous click settings
            m_oYEVNT.removeListener("DlrBG", "click");
            m_oYDOM.setStyle(m_oYDOM.get("DlrBG"), "cursor", "auto");

            //Set BG
            m_oYDOM.setStyle(m_oYDOM.get(contID), "background-image", "url(" + sImgUrl + ")");

            //Load click event if URL is valid
            if (sNavUrl != null && sNavUrl.length > 1) {
                m_oYDOM.setStyle(m_oYDOM.get("DlrBG"), "cursor", "pointer");
                m_oYEVNT.addListener("DlrBG", "click", function () { window.location = sNavUrl; });
            }

            //Prefetch the next image while the rotator is waiting for timeout
            if (oImgs.length > 1) {
                setTimeout(function () { YAHOO.CSUtils.Utils.BGRttrInit(contID); }, m_oBGImgs[contID].timeOut);
                if (iCtr == oImgs.length - 1) m_oBGImgs[contID].imgCtr = 0;
                else m_oBGImgs[contID].imgCtr++;
                PreFetchImg(contID);
            }
        },

        /**********************Prototype Functions***********************/
        CSStrCompareTo: function (s) {
            var sThis = this.toLowerCase();
            s = s.toString().toLowerCase();
            if (sThis === s)
                return EQUALTO;
            else if (sThis < s)
                return LT;

            return GT;
        },

        CSNumCompareTo: function (s) {
            s = s - 0;
            if (this == s)
                return EQUALTO;
            else if (this < s)
                return LT;

            return GT;
        },

        CSDateCompareTo: function (s) {
            var dtThis = Date.parse(this);
            s = Date.parse(s)
            if (dtThis == s)
                return EQUALTO;
            else if (dtThis < s)
                return LT;

            return GT;
        },

        /* false = 0 and true = 1 so, false < true and true > false */
        CSBooleanCompareTo: function (s) {
            s = Boolean(s);
            if (this == s)
                return EQUALTO;
            else if (this < s)
                return LT;

            return GT;
        },

        Trim: function () { return this.replace(/^\s+|\s+$/g, ""); },

        LTrim: function () { return this.replace(/^\s+/, ""); },

        RTrim: function () { return this.replace(/\s+$/, ""); },

        GetVal: function (key, default_) {
            var value = this.params[key];
            return (value != null) ? value : default_;
        },

        QSContains: function (key) {
            var value = this.params[key];
            return (value != null);
        },

        swapImg: function (id, url) {
            var elm = document.getElementById(id);
            elm.src = url;
        }
    }
} ();

/**********************Prototype Declarations***********************/
String.prototype.CSCompareTo = YAHOO.CSUtils.Utils.CSStrCompareTo;
Number.prototype.CSCompareTo = YAHOO.CSUtils.Utils.CSNumCompareTo;
Date.prototype.CSCompareTo = YAHOO.CSUtils.Utils.CSDateCompareTo;
Boolean.prototype.CSCompareTo = YAHOO.CSUtils.Utils.CSBooleanCompareTo;
String.prototype.trim = YAHOO.CSUtils.Utils.Trim;
String.prototype.ltrim = YAHOO.CSUtils.Utils.LTrim;
String.prototype.rtrim = YAHOO.CSUtils.Utils.RTrim;
Querystring = YAHOO.CSUtils.Utils.Querystring;
Querystring.prototype.get = YAHOO.CSUtils.Utils.GetVal;
Querystring.prototype.contains = YAHOO.CSUtils.Utils.QSContains;

/****************** Backward Compatibility Support *****************/
QSVal = YAHOO.CSUtils.Utils.QSVal;
GetDecodedParamValue = YAHOO.CSUtils.Utils.GetDecodedParamValue;
DecodeURL = YAHOO.CSUtils.Utils.DecodeURL;
EncodeString = YAHOO.CSUtils.Utils.EncodeString;
Currency2Numb = YAHOO.CSUtils.Utils.Currency2Numb;
Convert2PrettyString = YAHOO.CSUtils.Utils.Convert2PrettyString;
YMMSTextMax = YAHOO.CSUtils.Utils.YMMSTextMax;
YMMSText = YAHOO.CSUtils.Utils.YMMSText;
CSUtils = YAHOO.CSUtils.Utils;

