/**
 * JavaScript cookie management.
 *
 * @author Christian Hansen <chrsen@fundanemt.com>
 * @version 1.0
 * @copyright Christian Hansen
 *
 * Cookie management is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Cookie management is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Fundanemt CMS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 **/

    /*
     * get value of the cookie named name
     * @param string name - the name for the cookie
     * @return string|boolean - the value of the cookie or false if none was found.
     */
    function getCookie(name) {

        var cookieArray = document.cookie.split(name+"=");
        if(cookieArray.length > 1) {
            return unescape(cookieArray[1].split(";")[0]);
        } else {
            return false;
        }//else

    }//getCookie


    /*
     * set or update a cookie
     * @param string name - the name for the cookie
     * @param string value - the value of the cookie
     * @param string expire - the date of expiration - in the format of String.toGMTString();
     * @param string path - the path in which the cookie may be read.
     * @param string domain - the cookie domain
     * @param boolean secure - if true the cookie is secure.
     * @return string|boolean - the value of the cookie or false if none was found.
     */
    function setCookie(name,value,expires,path,domain,secure) {

        if(arguments.length < 2) {
            return false;
        }//if

        var cookie = name+"="+escape(value);
        if(arguments.length >2) cookie += "; expires=" + expires;
        if(arguments.length >3) cookie += "; path=" + path;
        if(arguments.length >4) cookie += "; domain=" + domain;
        if(arguments.length >5) cookie += "; secure=" + secure;
        document.cookie = cookie;

        if(getCookie(name)) {
            return true;
        } else {
            return false;
        }//else

    }//setCookie


    /*
     * delete the cookie named name
     * @param string name - the name for the cookie
     * @return string|boolean - the value of the cookie or false if none was found.
     */
    function deleteCookie(name) {

        if(arguments.length != 1) return false;

        var expire = new Date(1970,1,1);
        var tmp = setCookie(name,"",expire.toGMTString());
        if(getCookie(name)) {
            return false;
        } else {
            return true;
        }

    }//deleteCookie



function returnToSender() {
    var l = parseInt(getCookie("historycount")) + 1;
    deleteCookie("historycount");
    //alert(l);
    history.go(-l);
}//returnToSender


function jollyBeGood() {
    if(getCookie("historycount")) setCookie("historycount",(parseInt(getCookie("historycount")) + 1));
    else setCookie("historycount",1); 
}