

function OpenWindow(url, w, h, attr)
{
	var m_attr = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes";
	var x,y;

	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	if (attr)
	{
		m_attr = attr;
	}	
	window.open(url, "", m_attr+",width="+w+",height="+h+",left="+Math.round((x-w)/2)+",top="+Math.round((y-h)/2));
}

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 = "?print=1";
	if (loc.indexOf("?")>0) {
		pri = "&print=1";
	}
	OpenWindow(loc+pri, 600, 400);
}

function SendPage(id) {
	var loc = "/layouts/sendpage.aspx?pageid="+id;
	OpenWindow(loc, 350, 280, "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=no,resizable=no");
}

function CheckForm(form)
{
	if (form.from.value == "" || form.to.value == "")
	{
		if (form.from.value == "")
		{
			document.getElementById('error1').style.display = "inline";
		}
		if (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 ValidateMail(email, loginID, returnID)
{
	var RegExp = /^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.[a-z]{2,6}$/i;
	if (RegExp.test(email) == true)
	{
		document.forms[0].action = "/forms/forgotpass.aspx?lid=" + loginID + "&rid=" + returnID;
		document.forms[0].submit();
	}
	else
	{
		document.getElementById("errornouser").style.display = 'inline';
	}
}

function Subscribe()
{
	document.getElementById("errorname").style.display = 'none';
	document.getElementById("erroremail").style.display = 'none';
	var checked = false;

	var RegExp = /^.+@[^\.].*\.[a-z]{2,}$/i;
	if (document.forms[0].name.value == "")
	{
		document.getElementById("errorname").style.display = '';
		document.forms[0].name.focus();
		return false;
	}
	if (RegExp.test(document.forms[0].email.value) != true)
	{
		document.getElementById("erroremail").style.display = '';
		document.forms[0].email.focus();
		return false;
	}
	for (i=0; i<document.forms[0].getElementsByTagName("input").length; i++)
	{
		if (document.forms[0].getElementsByTagName("input")[i].type == "checkbox")
		{
			if (document.forms[0].getElementsByTagName("input")[i].checked == true)
			{
				checked = true;
			}
		}
		if (checked)
		{
			return true;
		}
	}
	return false;
}

function Update()
{
	document.getElementById("errorname").style.display = 'none';
	document.getElementById("erroremail").style.display = 'none';
	var checked = false;

	var RegExp = /^.+@[^\.].*\.[a-z]{2,}$/i;
	if (document.forms[0].name.value == "")
	{
		document.getElementById("errorname").style.display = '';
		document.forms[0].name.focus();
		return false;
	}
	if (RegExp.test(document.forms[0].email.value) != true)
	{
		document.getElementById("erroremail").style.display = '';
		document.forms[0].email.focus();
		return false;
	}
	return true;
}
