//return the filename and extension of the current page(and any querystring params which uniquely identify pages in some CMS apps)
    function fbGetPageName(){
        var pagePath = window.location.pathname;
        var pageName = pagePath.substring(pagePath.lastIndexOf('/') + 1);
        return (pageName);
    }
    function fbSetCookie(cookieName,cookieVal,numDays) {
        var expirydate=new Date();
        expirydate.setDate(expirydate.getDate()+numDays); 
        document.cookie=cookieName+ "=" +escape(cookieVal)+
        ((numDays==null) ? "" : ";expires="+expirydate.toGMTString())
    }
    
    function fbGetCookie(cookieName) {
        var strCookie = document.cookie.split("; ");
        for (i=0; i < strCookie.length; i++) {
            if (cookieName == strCookie[i].split("=")[0]){
                return strCookie[i].split("=")[1];
            }
        }
        return "";    
    }
    //check to see if cookie value has string within it (delimited parsing of values)
    function fbStringInCookie(cookieName, pageName,delimiter) {
        var cookieInfo = fbGetCookie(cookieName);
        if (cookieInfo != "") {
            var strCookie = cookieInfo.split(delimiter);
            for (i=0; i < strCookie.length; i++) {
                if (pageName == strCookie[i]){ //page exists in cookie
                    return 1;
                }
            }
        }
            return 0;    
    }
    //This function will be called when the form is submited
    function ajaxSaveFeedback(pFrmAjaxFeedback) {
        http("POST","/home/_ajaxSaveData.cfm",ajaxFeedbackResponse, pFrmAjaxFeedback);
    }
    //this function will be called after the AJAX process is completed.
    function ajaxFeedbackResponse(obj)
    {
        document.getElementById("fbFormElements").innerHTML = "Thank you for your feedback!";
        var cookieInfo = fbGetCookie("pageFeedback");
        cookieInfo = cookieInfo + fbGetPageName() + "*";
        fbSetCookie("pageFeedback",cookieInfo,1); //expires in 1 day, whereupon you can re-submit feedback
        
    }
    
    //if javascript is enabled, and the page is set up properly, this should execute after the page loads
    //will only execute if javascript is enabled, and replace the controls with javascript enabled ones.
    function initFeedbackForm() {
        if (fbStringInCookie("pageFeedback",fbGetPageName(),'*')){ //page already rated, display thank you message
            document.getElementById("fbFormElements").innerHTML = "This page has already been rated. Thank you for your feedback!";
        } else { //page not rated, user can submit feedback
            document.getElementById("fbBtnSpace").innerHTML ="<input type='button' value='Submit' onMouseDown='ajaxSaveFeedback(this.form);' id='fbBtnSubmit'; />";
        }
    }
