var HOST = 'www.diet-blog.com';

// D.C.P. - Comment Text
function ReloadTextDiv() {
document.getElementById('TextDisplay').innerHTML = '<p>'+document.getElementById('text').value.replace(/(\r\n|\n)/g,'<br />').replace(/(<br \/>){2,}/gi,'<'+'/p><p>')+'<'+'/p>';
}

//Returns a selection of text
function getSel()
{
	var txt = '';
	if (window.getSelection) {txt = window.getSelection();}
	else if (document.getSelection) {txt = document.getSelection();}
	else if (document.selection){txt = document.selection.createRange().text;}
	else return "";
	
	return txt;
}

//Allows quoting of comments
function qt(comment) {
	var txt = getSel();
	var kids = document.getElementById("c"+comment).childNodes;
	var li = document.getElementById("c"+comment).parentNode.childNodes;
	var auth="";
	var tx="";
	
	for (j = 0; j < li.length; j++) {
		if (li[j].nodeName == "B") {
			auth = li[j].innerHTML;
			
			if (li[j].firstChild.nodeType == 1)
				auth = li[j].firstChild.innerHTML;
		}
	}
	
	if (txt.toString().length > 0){
		tx = txt.toString();
	} else {
		for (j = 0; j < kids.length; j++) {
			if (kids[j].nodeName=="P" && kids[j].innerHTML)	{
				tx = kids[j].innerHTML.substring(0,350);
				break;
			}
		//	if (kids[j].nodeType==3)	{
		//		tx = kids[j].nodeValue.substring(0,350);
		//		break;
		//	}
		}
	}
	
	tx = tx.replace(/<br>/g, "");
	tx = tx.replace(/<p>/g, "");
	tx = tx.replace(/<\/p>/g, "");
	
	var cf=document.getElementById("text");
	cf.value +="<blockquote><b>" + auth + "</b> said:<br>" + tx + "[...]</blockquote>\n";
	ReloadTextDiv();
	
	return true;
}

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

// Comment Hover technique for IE
sfHover = function() {

	var sfEls = document.getElementsByTagName("DIV");
	
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].className == "c") {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

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