/* $hg: main.js,v r81 2010-12-22 00:50:09 -0800 kyau $ */


function toggle(id, img) {
    var e = document.getElementById(id);
    var img = document.getElementById(img);
    e.style.display = e.style.display == "block" ? "none" : "block";
    img.src = img.src == "http://privatebox.org/img/icons/16_16/plus-small.png" ? "/img/icons/16_16/minus-small.png" : "/img/icons/16_16/plus-small.png";
}
function safe_onFocus(obj) {
    if (obj.value == "Type blog entry here..." ||
        obj.value == "Type your comment here..." ||
        obj.value == "Blog Title" ||
        obj.value == "Category" ||
        obj.value == "Tags" ||
        obj.value == "What's your name?" ||
        obj.value == "Type your comment here...") {
        obj.style.background = "#131313";
        obj.value = "";
    } else {
        obj.style.background = "#131313";
    }
}
function showStatus(status, color) {
    var tmp = "";
    color = typeof(color) != "undefined" ? color : 1;
    if (color == 1) {
        tmp = "green";
    } else {
        tmp = "red";
    }
    var e = document.getElementById('toolbarStatus');
    e.innerHTML = "<span class=\"h3\"><span class=\"" + tmp + "\"><span class=\"bluegray\">&#xff1a;</span> " + status + "</span></span>";
    e.style.display = "inline";
}
function hideStatus() {
    var e = document.getElementById("toolbarStatus");
    e.innerHTML = "";
    e.style.display = "none";
}
function highlight() {
    this.className = "highlight";
}
function dehighlight() {
    this.className = "";
}
function countMe(obj, count, max) {
    var e = document.getElementById(count);
    var l = obj.value.length;
    if (l < max && l >= (max * .9)) {
        e.value = l;
        e.style.color = "#96190e";
    } else if (l > max) {
        e.value = "-" + (l - max);
        e.style.color = "#96190e";
    } else if (l == 0) {
        e.value = l;
        e.style.color = "#777";
    } else {
        e.value = l;
        e.style.color = "#9acd32";
    }
    return l;
}
function init() {
    var element = document.getElementById("t_doc");
    if (element != null) {
        var rows = element.getElementsByTagName("tr");
        for (i=0;i<rows.length;i++) {
            rows[i].onmouseover = highlight;
            rows[i].onmouseout = dehighlight;
        }
    }
    if (document.f_blogentry != null) {
        document.f_blogentry.title.onfocus =  function(){safe_onFocus(this);};
        document.f_blogentry.title.onblur =  function(){this.style.background="#1c1c1c";};
        document.f_blogentry.title.onkeyup = function(){countMe(this,"titleCount",255);}
        document.f_blogentry.category.onfocus =  function(){safe_onFocus(this);};
        document.f_blogentry.category.onblur =  function(){this.style.background="#1c1c1c";};
        document.f_blogentry.tags.onfocus =  function(){safe_onFocus(this);};
        document.f_blogentry.tags.onblur =  function(){this.style.background="#1c1c1c";};
        document.f_blogentry.entry.onfocus =  function(){safe_onFocus(this);};
        document.f_blogentry.entry.onblur =  function(){this.style.background="#1c1c1c";};
        document.f_blogentry.entry.onkeyup = function(){countMe(this,"entryCount",4294967295);};
        countMe(document.f_blogentry.title,"titleCount",255);
        countMe(document.f_blogentry.entry,"entryCount",4294967295);
    }
    else if (document.f_editdraft != null) {
        document.f_editdraft.title.onfocus =  function(){safe_onFocus(this);};
        document.f_editdraft.title.onblur =  function(){this.style.background="#1c1c1c";};
        document.f_editdraft.title.onkeyup = function(){countMe(this,"titleCount",255);}
        document.f_editdraft.category.onfocus =  function(){safe_onFocus(this);};
        document.f_editdraft.category.onblur =  function(){this.style.background="#1c1c1c";};
        document.f_editdraft.tags.onfocus =  function(){safe_onFocus(this);};
        document.f_editdraft.tags.onblur =  function(){this.style.background="#1c1c1c";};
        document.f_editdraft.entry.onfocus =  function(){safe_onFocus(this);};
        document.f_editdraft.entry.onblur =  function(){this.style.background="#1c1c1c";};
        document.f_editdraft.entry.onkeyup = function(){countMe(this,"entryCount",4294967295);};
        countMe(document.f_editdraft.title,"titleCount",255);
        countMe(document.f_editdraft.entry,"entryCount",4294967295);
    }
    else if (document.b_comment != null) {
        document.b_comment.username.onfocus = function(){safe_onFocus(this);};
        document.b_comment.username.onblur = function(){this.style.background="#1c1c1c";};
        document.b_comment.entry.onfocus = function(){safe_onFocus(this);};
        document.b_comment.entry.onblur = function(){this.style.background="#1c1c1c";};
        document.b_comment.entry.onkeyup = function(){countMe(this,"entryCount",65535);};
        countMe(document.b_comment.entry,"entryCount",65535);
    }
    else if (document.f_homepage != null) {
        document.f_homepage.q.onfocus = function(){this.style.background="#1c1c1c";this.style.border="1px dashed #6d8eda";};
        document.f_homepage.q.onblur = function(){this.style.background="#131313";this.style.border="1px dashed #696969";};
        document.forms['f_homepage'].elements['q'].focus();
    }
}
window.onload = init;

