// 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';
}

function showAnonymousForm() {
    showDocumentElement('comments-form');

}


var commenter_name;
var commenter_blog_ids;
var is_preview;
var mtcmtmail;
var mtcmtauth;
var mtcmthome;

function individualArchivesOnLoad(commenter_name) {



    hideDocumentElement('trackbacks-info');


    
    // comments are allowed but registration not required
    if ( commenter_name &&
         ( !commenter_id
        || commenter_blog_ids.indexOf("'1'") > -1))
    {
        hideDocumentElement('comment-form-name');
        hideDocumentElement('comment-form-email');
    } else if (is_preview) {
        delayShowCaptcha();
    } else {
    }
    


    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 writeCommenterGreeting(commenter_name, entry_id, blog_id, commenter_id, commenter_url) {

    if (commenter_name)
    {
        var url;
        url = 'http://www.cityjitsu.org.uk/cgi-bin/mt/plugins/UserProfiles/mt-userprofiles.cgi?__mode=edit_userprofile&blog_id=' + blog_id;
        if (entry_id) {
            url += '&entry_id=' + entry_id;
        } else {
            url += '&static=1';
        }
        var content = '<span id="commenter-image"></span> Welcome, ';
        if (url) {
            content += '<strong>' + commenter_name + '</strong> (<a href="' + url + '">Edit Profile</a>)';
        } else {
            content += commenter_name;
        }
        content += '. Thank you for signing in. (<a href="http://www.cityjitsu.org.uk/cgi-bin/mt/mt-comments.cgi?__mode=handle_sign_in&amp;static=1&amp;logout=1&entry_id=' + entry_id + '">sign out</a>)';
        document.write(content);
        getImage();
    } else if (commenter_name) {
            document.write('You do not have permission to comment on this blog. (<a href="http://www.cityjitsu.org.uk/cgi-bin/mt/mt-comments.cgi?__mode=handle_sign_in&amp;static=1&amp;logout=1&entry_id=' + entry_id + '">sign out</a>)');
    } else {

        document.write('<a href="http://www.cityjitsu.org.uk/cgi-bin/mt/mt-comments.cgi?__mode=login&entry_id=' + entry_id + '&blog_id=' + blog_id + '&static=1">Sign in or create a member\'s account' + '</a>' + ' to automatically fill in the comments form with your details.');

    }

}

function getImage(){

var commenter_img = getCookie('commenter_img');
if (commenter_img == 'none') {
    return false; 
}
if (commenter_img) {
 	var img_div = document.getElementById('commenter-image');
	img_div.innerHTML = '<img src="' + commenter_img + '" />';
	return false;
}



}



if ('www.cityjitsu.org.uk' != 'www.cityjitsu.org.uk') {
    document.write('<script src="http://www.cityjitsu.org.uk/cgi-bin/mt/mt-comments.cgi?__mode=cmtr_name_js"></script>');
} else {
    commenter_name = getCookie('commenter_name');
    ids = getCookie('commenter_id').split(':');
    commenter_id = ids[0];
    commenter_blog_ids = ids[1];
    commenter_url = getCookie('commenter_url');
}



// Random encryption key feature by Andrew Moulden, Site Engineering Ltd
// This code is freeware provided these four comment lines remain intact
// A wizard to generate this code is at http://www.jottings.com/obfuscator/

var __MTTBLINK__;
var __MTTBID__;
function obfuscator(coded, key, mode, path, hidden) {
	shift = coded.length;
	link = "";
	
	for(i=0;i<coded.length;i++) {
		if (key.indexOf(coded.charAt(i))==-1) {
			ltr = coded.charAt(i);link+=(ltr);
		} else {
			ltr = (key.indexOf(coded.charAt(i)) - shift + key.length) % key.length;
			link += (key.charAt(ltr));
		}
	}
	if(mode == 'hidden_input') {
		document.write('<input type="hidden" name="CCode" value="' + link + '" />');
	} else if(mode == '__MTTBLINK__') {
		__MTTBLINK__ = path + link;
		if(hidden) return;
		document.write(link);
	} else if(mode == '__MTTBID__') {
		__MTTBID__ = link;
		if(hidden) return;
		document.write(link);
	}
}

// Comment Text
// Comment Text
function ReloadTextDiv() {
var thisisgood=document.getElementById('comment_template');
if (thisisgood.selectedIndex == -1) return;
var opt = thisisgood.options[thisisgood.selectedIndex];
var thisgoodtext = '';
if (opt && opt.value) thisgoodtext="<strong>["+opt.value+"]</strong> ";
document.getElementById('TextDisplay').innerHTML = '<p>'+thisgoodtext+document.getElementById('comment-text').value.replace(/(\r\n|\n)/g,'<br />').replace(/(<br \/>){2,}/gi,'<'+'/p><p>')+'<'+'/p>';
}

function ThisIsGood() {
var thisisgood=document.getElementById('comment_template');
if (thisisgood.selectedIndex == -1) return;
var opt = thisisgood.options[thisisgood.selectedIndex];
if (opt && opt.value) document.getElementById('comment-text').value = '<strong>['+opt.value+']</strong>'+document.getElementById('comment-text').value;
ReloadTextDiv();
}



// End Dynamic Comment Preview

function akst_share(id, url, title) {
	var form = document.getElementById('akst_form');
	var post_id = document.getElementById('akst_post_id');
	
	if (form.style.display == 'block' && post_id.value == id) {
		form.style.display = 'none';
		return;
	}
	
	var link = $('akst_link_' + id);
	var offset = PlobPosition.PlobcumulativeOffset(link);

	document.getElementById('akst_delicious').href = akst_share_url("http://del.icio.us/post?url={url}&title={title}", url, title);
	document.getElementById('akst_digg').href = akst_share_url("http://digg.com/submit?phase=2&url={url}&title={title}", url, title);
	document.getElementById('akst_furl').href = akst_share_url("http://furl.net/storeIt.jsp?u={url}&t={title}", url, title);
	document.getElementById('akst_netscape').href = akst_share_url(" http://www.netscape.com/submit/?U={url}&T={title}", url, title);
	document.getElementById('akst_yahoo_myweb').href = akst_share_url("http://myweb2.search.yahoo.com/myresults/bookmarklet?u={url}&t={title}", url, title);
	document.getElementById('akst_stumbleupon').href = akst_share_url("http://www.stumbleupon.com/submit?url={url}&title={title}", url, title);
	document.getElementById('akst_google_bmarks').href = akst_share_url("http://www.google.com/bookmarks/mark?op=edit&bkmk={url}&title={title}", url, title);
	document.getElementById('akst_technorati').href = akst_share_url("http://www.technorati.com/faves?add={url}", url, title);
	document.getElementById('akst_blinklist').href = akst_share_url("http://blinklist.com/index.php?Action=Blink/addblink.php&Url={url}&Title={title}", url, title);
	document.getElementById('akst_newsvine').href = akst_share_url("http://www.newsvine.com/_wine/save?u={url}&h={title}", url, title);
	document.getElementById('akst_magnolia').href = akst_share_url("http://ma.gnolia.com/bookmarklet/add?url={url}&title={title}", url, title);
	document.getElementById('akst_reddit').href = akst_share_url("http://reddit.com/submit?url={url}&title={title}", url, title);
	document.getElementById('akst_windows_live').href = akst_share_url("https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url={url}&title={title}&top=1", url, title);
	document.getElementById('akst_tailrank').href = akst_share_url("http://tailrank.com/share/?link_href={url}&title={title}", url, title);
    document.getElementById('akst_facebook').href = akst_share_url("http://www.facebook.com/sharer.php?u={url}&t={title}", url, title);

	form.style.left = offset[0] + 'px';
	form.style.top = (offset[1] + link.offsetHeight + 3) + 'px';
	form.style.display = 'block';
}

function akst_share_url(base, url, title) {
	base = base.replace('{url}', url);
	return base.replace('{title}', title);
}

