

function OnFocus(Obj, Text, Enter) {
    if (Enter) {
        if (Obj.value == Text) {
            Obj.value = '';
            Obj.style.color = '#000';
        } else if (Obj.value == '') {
            Obj.value = Text;
            Obj.style.color = '#000';
        }
    } else {
        if (Obj.value == '') {
            Obj.value = Text;
            Obj.style.color = '#aaa';
        } else if (Obj.value == Text) {
            Obj.value = Text;
            Obj.style.color = '#aaa';
        }
    }
}
function SetPageTheme(El, Option, Value, Path){
	var links = document.getElementsByTagName('link');
	var found = null;
	var next = null;
    var i, a;
    var e = document.getElementById('theme');
    for (i = 0; i < e.childNodes.length; i++) {
        a = e.childNodes[i];
        if (a.tagName == 'A') {
            if (a == El) {
                //alert(a.innerHTML);
                a.className = 'selected';
            } else {
                a.className = '';
            }
        }
    }

    for (i = 0; i < links.length; i++) {
        link = links[i];
        var s = link.getAttribute('rel');
        if (s == 'stylesheet') {
            s = link.getAttribute('title');
            if (s == 'System.Themes.' + Option) {
                s = link.getAttribute('href');
                link.setAttribute('href', Path + 'Themes.' + Option + '.' + Value + '.css');
                break;
            }
        } else {
            alert('New Link Type: "' + s + '".');
        }
	}
}
function SetCookie(Name, Value, Days) {
    Days = Days || 30;
    var e = '';
	if (Days) {
		var date = new Date();
		date.setTime(date.getTime() + (Days*24*60*60*1000));
		e = '; expires=' + date.toGMTString();
	}
	document.cookie = Name + '=' + escape(Value) + e;
}
function GetCookie(Name) {
	var n = Name + '=';
	var c = document.cookie.split(';');
	for(var i=0; i < c.length; i++) {
		var e = c[i];
		while (e.charAt(0) == ' ') e = e.substring(1, e.length);
		if (e.indexOf(n) == 0) return e.substring(n.length, e.length);
	}
	return null;
}
function ShowDiv(Id) {
    var e = document.getElementById(Id);
    if (e.style.display == 'none') {
        e.style.display = 'block';
    } else {
        e.style.display = 'none';
    }
}
function Toggle(El, Id, CookieName) {
    CookieName = CookieName || '';
    var e = document.getElementById(Id);
    if (e.style.display == 'block') {
        e.style.display = 'none';
        El.innerText = 'click to expand';
        if (CookieName) SetCookie(CookieName, 1);
    } else {
        e.style.display = 'block';
        El.innerText = 'click to collapse';
        if (CookieName) SetCookie(CookieName, '');
    }
}
function ShowCommentForm(Id) {
    //alert(window.pageYOffset);
    //alert(document.body.scrollTop);
    //alert(Id);
    var f = document.getElementById('comment-form');
    if (f.style.display == 'block') HideCommentForm();
    if (Id != 0) {
        var e = document.getElementById('comment-' + Id);
        e.appendChild(f);
        f.style.marginLeft = '40px';
    } else {
        var e = document.getElementById('comments');
        f.style.marginLeft = '0px';
    }
    f.style.marginTop = '10px';
    f.style.display = 'block';
    f.save.disabled = true;
    f.content.innerText = '';
    f.content.focus();
    f.parent.value = Id;
    f.update.value = 0;
}
function ShowCommentEditForm(Id) {
    var f = document.getElementById('comment-form');
    if (f.style.display == 'block') HideCommentForm();
    var d = document.getElementById('comment-' + Id);
    var c = document.getElementById('comment-' + Id + '-content');

    c.style.display = 'none';
    d.appendChild(f);
    f.style.marginTop = '0px';
    f.style.display = 'block';
    f.save.disabled = true;
    f.content.innerText = c.innerText;
    f.content.focus();
    f.update.value = Id;
}
function HideCommentForm() {
    var p = document.getElementById('content');
    var f = document.getElementById('comment-form');
    var update = f.update.value;
    if (update != 0) {
        var c = document.getElementById('comment-' + update + '-content');
        c.style.display = 'block';
    }
    f.style.display = 'none';
    f.content.innerText = '';
    f.save.disabled = true;
    f.parent.value = 0;
    f.update.value = 0;
    p.appendChild(f);
}