﻿// Copyright (C) 2007 AvantLogic Corporation
var webSiteUrl;

function maButtonIsDisabled(button)
{
	return button.className == "buttonDisabled";
}

function maDropCookie(name, value, days)
{
	var date = new Date();
	date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
	var cookie = name + "=" + value + ";expires=" + date.toGMTString() + ";path=/";
	document.cookie = cookie;
}

function maOnKeyPress(e) 
{ 
	var key = window.event ? window.event.keyCode : e.which;
	// Disable Enter key so it won't post.
	return key != 13;
}

function maOnRollover(over, button, name)
{
	if (maButtonIsDisabled(button))
		return;
	var state = over ? 2 : 1;
	button.src = '../Images/' + name + state + ".gif";
}

function maPt(e)
{
	var left = 0;
	var top = 0;
	while (e) {
		left += e.offsetLeft;
		top += e.offsetTop;
		e = e.offsetParent;
	}
	var pt = new Object();
	pt.x = left;
	pt.y = top;
	return pt;
}

function maQuickHelpShow(p, content, x, y, info)
{
	var id = info ? 'QuickInfo' : 'QuickHelp';
	var e = document.getElementById(id);
	if (!e)
		return;
	if (x === 0)
		x = 20;
	if (y === 0)
		y = 16;
	e.style.visibility = 'visible';
	var pt = maPt(p);
	e.style.left=(pt.x + x) + 'px';
	e.style.top=(pt.y + y) + 'px';
	e.style.width = info ? '296px' : '250px';
	e.innerHTML = content;
}

function maQuickHelpHide(info)
{
	var id = info ? 'QuickInfo' : 'QuickHelp';
	var e = document.getElementById(id);
	if (e)
	    e.style.visibility = 'hidden';
}

function maTransferToMenuItem(item)
{
	maTransferToPage(item.Value);
}

function maTransferToPage(url)
{
	if (typeof url == "undefined")
		return;
	window.location = webSiteUrl + url.substr(1);
}

function maWindow(u)
{
    var url = webSiteUrl + u.substr(1);
    maWindowSized(url, 550, 350, "wnd");
}

function maWindowSized(url, w, h, n)
{
	var width = w;
	var height = h;
	var left = parseInt((screen.availWidth / 2) - (width / 2),10);
	var top = parseInt((screen.availHeight / 2) - (height / 2),10);
	var childWindow = window.open(url, n,
		"resizable" +
		",scrollbars" +
		",height=" + height +
		",width=" + width +
		",top=" + top +
		",left=" + left +
		",screenX=" + left +
		",screenY=" + top);
	if (childWindow === null)
		alert("A popup blocker prevented the requested window from opening.");
	else
		childWindow.focus();
}
