var newWindowVar = new Array();

function directSelect(name)
{
	var sel = document.forms[0].elements[elementId(name)];
	gotoURL(sel.options[sel.selectedIndex].value);
}

function gotoURL(url)
{
	if (document.getElementById("baseTarget")) {
		parent.location.href = url;
	} else {
		window.location.href = url;
	}
}

function directSubmitSelect(name)
{
	var sel = document.forms[0].elements[elementId(name)];
	document.forms[0].id.value = sel.options[sel.selectedIndex].value;
	submit();
}

function newWindow(url, scroll, name)
{
	var options = "location=no,menubar=no,toolbar=no,status=no";
	if (!name) {
		name = "newWindow";
	}
	if (!scroll) {
		options += ",scrollbars=no, resizable=no";
	} else {
		options += ",scrollbars=yes, resizable=yes";
	}
	options += ",height=" + Math.max(window.outerHeight - 60, 300);
	options += ",width=" + Math.max(window.outerWidth - 60, 300);

	newWindowVar[name] = window.open(url, name, options);
	newWindowVar[name].focus();
}

function newSizedWindow(url, width, height, scroll, name)
{
	var options = "location=no,menubar=no,toolbar=no,status=no";
	if (!name) {
		name = "newWindow";
	}
	if (scroll==false) {
		options += ",scrollbars=no,resizable=no";
	} else if (scroll==2) {
		options += ",scrollbars=yes,resizable=no";
	} else if (scroll==3) {
		options += ",scrollbars=no,resizable=yes";
	} else {
		options += ",scrollbars=yes,resizable=yes";
	}
	options += ",height=" + height;
	options += ",width=" + width;
	options += ",left=" + (screen.availWidth - width) / 2;
	options += ",top=" + (screen.availHeight - height) / 2;

	newWindowVar[name] = window.open(url, name, options);
	newWindowVar[name].focus();
}

function closeWindow(name)
{
	if (!name) {
		name = "newWindow";
	}
	if (newWindowVar[name] != null) {
		newWindowVar[name].close();
	}
}

function submit()
{
	// brwoser bug
	if (document.forms[0].onsubmit)	{
		document.forms[0].onsubmit();
	}

	document.forms[0].submit();
}

function imageId(name)
{
	for (i = 0 ; i < document.images.length ; i++) {
		if (document.images[i].name == name) {
			return i;
		}
	}
	return -1;
}

function elementId(name)
{
	var elements = document.forms[0].elements;
	for (i = 0 ; i < elements.length ; i++) {
		if (elements[i].name == name) {
			return i;
		}
	}
	return -1;
}

function setImg(name, path)
{
	document.images[imageId(name)].src = path;
}

function changeImg(name, type)
{
	var id = imageId(name);
	var u = document.images[id].src;

	u = u.substring(0, u.length - 5) + type + u.substring(u.length - 4, u.length);
	document.images[id].src = u;
}

function js_documentHeight()
{
	if (window.innerHeight) {
		return window.innerHeight;
	} else {
		return document.body.offsetHeight;
	}
}

function askLink(question, link)
{
	if (window.confirm(question)) {
		window.location.href = link;
	}
}

