﻿function onTabMouseOver(tab)
{ tab.className = "tabh"; }

function onTabMouseLeave(tab)
{ tab.className = "tabd"; }

function onTabMouseClick(url)
{ document.location = url; }

function removeHtmlTags(html) {
    var matchTag = /<(?:.|\s)*?>/g;
    return html.replace(matchTag, "");
}

function addCookie(name, value, expireInDays) {
    var expireOn = new Date();
    expireOn.setDate(expireOn.getDate() + expireInDays);
    document.cookie = name + "=" + escape(value) + ((expireInDays == null) ? "" : ";expires=" + expireOn.toGMTString());
}

function getCookieValue(name) {
    if (document.cookie.length > 0) {
        start=document.cookie.indexOf(name + "=");
        if (start != -1) {
            start=start+name.length+1;
            end=document.cookie.indexOf(";",start);
            if (end == -1) 
                end=document.cookie.length;
            return unescape(document.cookie.substring(start,end));
        }
    }
    return "";
}

function getQSValue(param) {
    param = param.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + param + "=([^&#]*)";
    var regex = new RegExp(regexS);
    
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

function json2string(strObject) {
    var c, i, l, s = '', v, p;
    switch (typeof strObject) {
        case 'object':
            if (strObject) {
                if (strObject.length && typeof strObject.length == 'number') {
                    for (i = 0; i < strObject.length; ++i) {
                        v = json2string(strObject[i]);
                        if (s) {
                            s += ',';
                        }
                        s += v;
                    }
                    return '[' + s + ']';
                } else if (typeof strObject.toString != 'undefined') {
                    for (i in strObject) {
                        v = strObject[i];
                        if (typeof v != 'undefined' && typeof v != 'function') {
                            v = json2string(v);
                            if (s) {
                                s += ',';
                            }
                            s += json2string(i) + ':' + v;
                        }
                    }
                    return '{' + s + '}';
                }
            }
            return 'null';
        case 'number':
            return isFinite(strObject) ? String(strObject) : 'null';
        case 'string':
            l = strObject.length;
            s = '"';
            for (i = 0; i < l; i += 1) {
                c = strObject.charAt(i);
                if (c >= ' ') {
                    if (c == '\\' || c == '"') {
                        s += '\\';
                    }
                    s += c;
                } else {
                    switch (c) {
                        case '\b':
                            s += '\\b';
                            break;
                        case '\f':
                            s += '\\f';
                            break;
                        case '\n':
                            s += '\\n';
                            break;
                        case '\r':
                            s += '\\r';
                            break;
                        case '\t':
                            s += '\\t';
                            break;
                        default:
                            c = c.charCodeAt();
                            s += '\\u00' + Math.floor(c / 16).toString(16) +
       (c % 16).toString(16);
                    }
                }
            }
            return s + '"';
        case 'boolean':
            return String(strObject);
        default:
            return 'null';
    }
}

function getRestUrl(u) {
    var r = new String();
    r = u;
    r = r.replace(/ /gi, "-");
    r = r.toLowerCase();
    return r;
}

function shareVia(o, s, title, msg) {
    var p = "";
    var url = new String();

    if (o == "e") {
        p = "email";
        window.open("mailto:?subject=" + encodeURIComponent(title) + "&body=" + encodeURIComponent(msg));
    }
    else if (o == "t") {
        url = "http://twitter.com/home?status=" + encodeURI(msg);
        p = "twitter";
    }
    else if (o == "f") {
        url = "http://www.facebook.com/share.php?u=" + s + "&t=" + msg;
        p = "facebook";
    }
    else if (o == "g") {
        url = "http://www.google.com/buzz/post?url=" + s + "&type=small-count";
        p = "Google Buzz";
    }
    else if (o == "l") {
        url = "http://www.linkedin.com/shareArticle?mini=true&url=" + s + "&title=" + encodeURI(title) + "&source=" + encodeURI("DivotDog (Beta) - A Golfer's Best Friend");
        p = "LinkedIn";
    }
    else if (o == "s") {
        url = "http://www.stumbleupon.com/submit?url=" + s + "&title=" + encodeURI(title);
        p = "StumbleUpon";
    }
    else if (o == "p") {
        url = "http://posterous.com/share?linkto=" + s + "&title=" + encodeURI(title) + "&selection=" + encodeURI(msg);
        p = "Posterous";
    }
    else if (o == "d") {
        url = "http://delicious.com/post?url=" + s + "&title=" + encodeURI(title) + "";
        p = "Delicious";
    }

    if (url.length > 0) window.open(url, "_blank");
}
