
function doSearch(fld, target) 
{
	location.href= target + '?search=' + encodeURI(eval("document.forms[0]." + fld).value);
}


function doKeySearch(evt, fld, target) 
{	
	if (evt.keyCode==13) 
	{	
		window.document.forms[0].action = target + '?search=' + eval("document.forms[0]."+fld).value;	
		evt.returnValue = null;
		evt.cancelBubble = true;
		
		doSearch(fld, target);		
	}
	return false;
}


function OpenWindow(url, w, h, attr)
{
	var m_attr = "toolbar=1,location=0,directories=0,status=0,menubar=yes,scrollbars=yes,resizable=yes";
	if (attr)
	{
		m_attr = attr;
	}	
	window.open(url, "", m_attr+",width="+w+",height="+h);
}

function PreviewImage(imageid, w, h, autoresize)
{
	OpenWindow("/Forms/PreviewImage.aspx?imageid="+imageid+"&autoresize="+autoresize, w, h, "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=yes,resizable=yes");
}

function PrintPage() {
	var loc = location.href;
	if (loc.indexOf("#")>0) {
		loc = loc.substring(0, loc.indexOf("#"));
	}
	var pri = "?p=1";
	if (loc.indexOf("?")>0) {
		pri = "&p=1";
	}
	OpenWindow(loc+pri, 760, 400);
}

function SendPage(path, id, hash) {
	var loc = path + "?pageid=" + id + "&hash=" + hash;
	OpenWindow(loc, 350, 290, "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=no,resizable=no");
}

function CheckForm(form)
{
	if (form.from.value == "" || form.to.value == "" || !isValidEmail(form.to.value))
	{
		if (form.from.value == "")
		{
			document.getElementById('error1').style.display = "inline";
		}
		if (form.to.value == "" || !isValidEmail(form.to.value))
		{
			document.getElementById('error2').style.display = "inline";
		}
		return false;
	}
	else
	{
		return true;
	}
}

function SetPostAction(val)
{
	var sUrl = val;
	if (sUrl.indexOf("/")<0) {
		sUrl = "/forms/"+sUrl;
	}
	if (sUrl.indexOf(".aspx")<0) {
		sUrl = sUrl + ".aspx";
	}
	//var ctl = document.all["postaction"];
	//ctl.value = val;
	document.forms[0].action = sUrl;
}

function ForumPost(r, act, o) {
	var isValid = true;
	var sFormTarget = "/Forms/ForumPost.aspx";
	var frm = document.forms(0);
	frm.action = sFormTarget;
	var oe = o.elements;
	HideError2(oe["author"]);
	HideError2(oe["title"]);
	HideError2(oe["text"]);
	if (oe["author"].value=="") {ShowError2(oe["author"]);isValid = false;}
	if (oe["title"].value=="") {ShowError2(oe["title"]);isValid = false;}
	if (oe["text"].value=="") {ShowError2(oe["text"]);isValid = false;}
	if (isValid) {
		o.submit();
		return true;
	}
	return false;
}

function ShowError2(elem) {
	elem.style.border = "1px solid #FF0000";
	elem.style.backgroundColor = "#F2F2F2";
}

function HideError2(elem) {
	elem.style.border = "1px solid #7AB2CC";
	elem.style.backgroundColor = "#FFFFFF";
}

function ShowError(oID) {
	document.getElementById("error"+oID).style.display = "inline";
}

function HideError(oID) {
	document.getElementById("error"+oID).style.display = "none";
}

function isValidEmail(emailAddress) {
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return re.test(emailAddress);
}

//=====================================
// Utilities
//=====================================

function QS(name) {
	var tmp = unescape( location.search.substring(1) );
	var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");
	if ( i >= 0 ) {
		tmp = tmp.substring( name.length+i+1 );
		i = tmp.indexOf("&");
		return( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));
	}
	return("");
}

