/**
* @fileoverview
* <p>General Tools.</p>
* <p>Now contains a modified version of Douglas Crockford's json.js that doesn't
* mess with the DOM's prototype methods
* http://www.json.org/js.html</p>
* @author Dav Glass <dav.glass@yahoo.com>
* @version 1.0
* @requires YAHOO
* @requires YAHOO.util.Dom
* @requires YAHOO.util.Event
*
* @constructor
* @class General Tools.
*/
YAHOO.Tools = function() {
    keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    /**
    * Moved all regexes to the top level object to cache them.
    * @type Object
    */
    regExs = {
        quotes: /\x22/g,
        startspace: /^\s+/g,
        endspace: /\s+$/g,
        striptags: /<\/?[^>]+>/gi,
        hasbr: /<br/i,
        hasp: /<p>/i,
        rbr: /<br>/gi,
        rbr2: /<br\/>/gi,
        rendp: /<\/p>/gi,
        rp: /<p>/gi,
        base64: /[^A-Za-z0-9\+\/\=]/g,
        syntaxCheck: /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/
    }

    jsonCodes = {
        '\b': '\\b',
        '\t': '\\t',
        '\n': '\\n',
        '\f': '\\f',
        '\r': '\\r',
        '"' : '\\"',
        '\\': '\\\\'
    }
    return {
        version: '1.0'
    }
}();



/**
* Set a cookie.
* @param {String} name The name of the cookie to be set
* @param {String} value The value of the cookie
* @param {String} expires A valid Javascript Date object
* @param {String} path The path of the cookie (Deaults to /)
* @param {String} domain The domain to attach the cookie to
* @param {Booleen} secure Booleen True or False
*/
YAHOO.Tools.setCookie = function(name, value, expires, path, domain, secure) {
     var argv = arguments;
     var argc = arguments.length;
     var expires = (argc > 2) ? argv[2] : null;
     var path = (argc > 3) ? argv[3] : '/';
     var domain = (argc > 4) ? argv[4] : null;
     var secure = (argc > 5) ? argv[5] : false;
     document.cookie = name + "=" + escape (value) +
       ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
       ((path == null) ? "" : ("; path=" + path)) +
       ((domain == null) ? "" : ("; domain=" + domain)) +
       ((secure == true) ? "; secure" : "");
}

/**
* Get the value of a cookie.
* @param {String} name The name of the cookie to get
*/
YAHOO.Tools.getCookie = function(name) {
    var dc = document.cookie;
    var prefix = name + '=';
    var begin = dc.indexOf('; ' + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(';', begin); 
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
/**
* Delete a cookie
* @param {String} name The name of the cookie to delete.
*/
YAHOO.Tools.deleteCookie = function(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + '=' + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
    }
}



/*
* Try to catch the developers that use the wrong case 8-)
*/
YAHOO.tools = YAHOO.Tools;
YAHOO.TOOLS = YAHOO.Tools;
YAHOO.util.Dom.create = YAHOO.Tools.create;
