// JavaScript Document

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function loadLastPage ()
{
	lastpage = getCookie("lastpage");

	if (lastpage == null)
		parent.main.location.replace("page.asp?2");
	
	else
		parent.main.location.replace(lastpage);
}

function setPage ()
{
	setCookie("lastpage", document.location);
}

function goEnter (field, evt) 
{
	var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
  
  	if (keyCode != 13)
    	return true;
  	else 
	{
    	document.subunsub.submit();
    	return false;
  	}
}

function checkGuestForm ()
{
	var bgcolor = "red";
	
	var name = document.getElementById("formname");
	var email = document.getElementById("formemail");
	var hometown = document.getElementById("formhometown");
	var comments = document.getElementById("formcomments");
	
	if (trim(name.value) == "")
	{
		//name.value = "Enter a name!"; 
		name.style.background = bgcolor;
		return false;
	}
	
	else if (trim(hometown.value) == "")
	{
		//hometown.value = "Enter your hometown!"; 
		hometown.style.background = bgcolor;
		return false;
	}
	
	else if (trim(email.value) == "")
	{
		//email.value = "Enter an email!"; 
		email.style.background = bgcolor;
		return false;
	}
		
	else if (trim(comments.value) == "")
	{
		//comments.value = "Enter some damn comments!"; 
		comments.style.background = bgcolor;
		return false;
	}
	else
		return true;
}

lastid = null
function colorField (id)
{
	highlight = "#BDD4E6";
	
	var field = document.getElementById(id);
	
	if (lastid)
		document.getElementById(lastid).style.background = "#ffffff";
		
	field.style.background = highlight;
	
	// clear the "Enter..." messages
	//var fieldvalue = field.value;
	
	//if (fieldvalue.substring(0, 5) == "Enter")
	//	field.value = "";
		
	lastid = id;
}
		
function trim(sInString) 
{
	sInString = sInString.replace( /^\s+/g, "" );
	return sInString.replace( /\s+$/g, "" );
}

// the smileys

function hyperlink()
{
	var linkname = prompt("Enter name of the link", "");
	var linkurl = prompt("Enter URL of the link", "http://");
	
	linkurl = linkurl.replace("http://", "");
	
	if (linkname == null || linkname == "")
		linkname = linkurl;
		
	if (linkurl == null || linkurl == "")
		return "";
	else
	{
		input = "<a href='http://" + linkurl + "'>" + linkname + "</a>";
		return input;
	}
}

function addimage()
{
	picurl = prompt("Enter URL of the image", "http://");
	
	if (picurl == null || picurl == "")
		return "";
	else
	{
		input = "<img src='" + picurl + "'>";
		return input;
	}
}

function boldtext()
{
	text = prompt("Enter text to be bolded", "");
		
	if (text == null || text == "")
		return "";
	else
	{
		input = '<b>' + text + '</b>';
		return input;
	}
}

function italictext()
{
	text = prompt("Enter text to be italicized", "");
		
	if (text == null || text == "")
		return "";
	else
	{
		input = '<i>' + text + '</i>';
		return input;
	}
}

function underlinetext()
{
	text = prompt("Enter text to be underlined", "");
		
	if (text == null || text == "")
		return "";
	else
	{
		input = '<u>' + text + '</u>';
		return input;
	}
}

function addtotextbox(text)
{
	var box = document.getElementById("formcomments");
	box.value += text;
	box.focus();
}

function cleartextbox()
{
	if (confirm("Are you sure?"))
	{
		var box = document.getElementById("formcomments");
		box.value = "";
		box.focus();
	}
}
