/**************************************************
 SI_previewAuthor/SI_previewComment() v1.0
 
 http://www.shauninman.com/
 **************************************************/
var HOST = 'jasonsantamaria.com';
var SI_authorDefault='';
function SI_previewAuthor(e) {
        var p = document.getElementById('SI_previewAuthor');
        var a = e.form.author.value;
        var u = e.form.url.value;
        if (SI_authorDefault=='') { SI_authorDefault = p.innerHTML; }
        p.innerHTML = (!SI_empty(a))?a:SI_authorDefault; 
        p.href = (!SI_empty(u))?u:'#';
        p.title = u;
        }
function SI_previewComment(e) { document.getElementById('SI_previewComment').innerHTML = '<p>'+e.value.replace(/(\n|\r)/g,'<br />').replace(/(<br \/>){2,}/gi,'<'+'/p><p>')+'<'+'/p>'; }

/**************************************************
 SI_isValidEmail()
 
 Returns true if the value passed is a valid email 
 address. Duh.
 **************************************************/
function SI_isValidEmail(email) { return (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)?true:false; }

/**************************************************
 SI_empty()
 
 Similar to the php function empty()
 Returns true if val contains an empty string
 or contains only whitespace.
 ie. spaces or returns
 **************************************************/
function SI_empty(val) { var empty = /^\s*$/; return empty.test(val); }

/**************************************************
 SI_handleErrors/SI_clearErrors()
 
 Used to present the user feedback.
 The first index of the SI_errors array is presented
 in paragraph form. The remaining indexes are output
 in an unordered list.
 **************************************************/
var SI_errors = new Array();
function SI_handleErrors() {
        var d = document;
        errorMsg = '<p>'+SI_errors[0]+'<'+'/p><ul>';
        for (var i=1; i<SI_errors.length; i++) {
                errorMsg += '<li>'+SI_errors[i]+'<'+'/li>';
                }
        errorMsg += '<'+'/ul>';
        d.getElementById('container-errors').innerHTML = errorMsg;
        SI_clearErrors();
        }
function SI_clearErrors() { SI_errors = new Array(); }


/**************************************************
 SI_prescreenComments() (MT 2.64+)
 
 Called from the comment form's onsubmit handler and
 makes sure that author, email, and comments all have
 values and that the email provided is valid.
 **************************************************/
function SI_prescreenComments(f) {
        var d = document;
        if (!d.getElementById) return true;

        var a = f.author.value;
        var e = f.email.value;
        var t = f.text.value;

        // Error message for missing author name
        if (SI_empty(a)) { SI_errors[SI_errors.length] = 'Please enter your name.';  }

        // Error message for missing email address
        if (SI_empty(e)) { SI_errors[SI_errors.length] = 'Please enter your email address.'; }

        // Error message for invalid email address
        else if (!SI_isValidEmail(e)) { SI_errors[SI_errors.length] = 'Your email address doesn&#8217;t appear to valid. Please double check it.'; }

        // Error message for missing comment
        if (SI_empty(t)) { SI_errors[SI_errors.length] = 'What exactly were you trying to post? Please enter a comment.'; }

        // Yay! No errors!
        if (!SI_errors.length) {
                SI_clearErrors();
                return true;
                }
        // Nay! Try again!
        else {
                // Error message lead-in.
                var failed = ['Your comment could not be submitted for the following reasons:'];
                SI_errors = failed.concat(SI_errors);
                SI_handleErrors();

                // Cancel form submission
                return false;
                }
        }


/**************************************************
 SI_rememberMe()

 I don't need to explain myself to you.
 **************************************************/
function SI_rememberMe(f) {

        var a = f.author.value;
        var e = f.email.value;
        var u = f.url.value;
        var c = f.bakecookie[0].checked;

        if (c) {
                var now = new Date(); fixDate(now); now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
                if (!SI_empty(a)) setCookie('mtcmtauth', a, now, '/', HOST, '');
                if (!SI_empty(e)) setCookie('mtcmtmail', e, now, '/', HOST, '');
                if (!SI_empty(u)) setCookie('mtcmthome', u, now, '/', HOST, '');
                }
        else {
                deleteCookie('mtcmtmail', '/', HOST);
                deleteCookie('mtcmthome', '/', HOST);
                deleteCookie('mtcmtauth', '/', HOST);
                }
        }

// MT DEFAULT CODE
// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") +
        (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    now = now.toGMTString();
    if (f.author != undefined)
       setCookie('mtcmtauth', f.author.value, now, '/', '', '');
    if (f.email != undefined)
       setCookie('mtcmtmail', f.email.value, now, '/', '', '');
    if (f.url != undefined)
       setCookie('mtcmthome', f.url.value, now, '/', '', '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '/', '');
    deleteCookie('mtcmthome', '/', '');
    deleteCookie('mtcmtauth', '/', '');
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}

function hideDocumentElement(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'none';
}

function showDocumentElement(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'block';
}

var commenter_name;

function individualArchivesOnLoad(commenter_name) {

    hideDocumentElement('trackbacks-info');



    if (document.comments_form) {
        if (!commenter_name && (document.comments_form.email != undefined) &&
            (mtcmtmail = getCookie("mtcmtmail")))
            document.comments_form.email.value = mtcmtmail;
        if (!commenter_name && (document.comments_form.author != undefined) &&
            (mtcmtauth = getCookie("mtcmtauth")))
            document.comments_form.author.value = mtcmtauth;
        if (document.comments_form.url != undefined && 
            (mtcmthome = getCookie("mtcmthome")))
            document.comments_form.url.value = mtcmthome;
        if (document.comments_form["bakecookie"]) {
            if (mtcmtauth || mtcmthome) {
                document.comments_form.bakecookie.checked = true;
            } else {
                document.comments_form.bakecookie.checked = false;
            }
        }
    }
}

function writeTypeKeyGreeting(commenter_name, entry_id) {

}


