/* shared.js
 *
 * Think Computer Web Site
 * JavaScript Library
 * Copyright © 2001-2002 Think Computer Corporation. All Rights Reserved.
 */

// Rollovers

netscape = navigator.appName == "Netscape";
netscape4 = netscape && parseInt(navigator.appVersion) <= 4;
ie = navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4;
hover = netscape || ie;

function preload(img)
{
	var a = new Image();
	a.src = img;
	return a;
}

// Confirmation Dialogs

function deleteRecord(phpself, id)
{
	if (confirm("Are you sure you want to delete this record?")) {
		window.location = phpself + '?delete=1&' + id;
	}
}

function deleteRecords(formName)
{
	if (confirm("Are you sure you want to delete the selected records?")) {
		document.forms[formName].button.value = 'delete';
		document.forms[formName].submit();
	}
}

function approveRecords(formName)
{
	if (confirm("Are you sure you want to approve the selected records?")) {
		document.forms[formName].button.value = 'approve';
		document.forms[formName].submit();
	}
}

function confirmRecords(formName)
{
	if (confirm("Are you sure you want to confirm the selected records?")) {
		document.forms[formName].button.value = 'confirm';
		document.forms[formName].submit();
	}
}

function cancelRecords(formName)
{
	if (confirm("Are you sure you want to cancel the selected accounts?")) {
		document.forms[formName].button.value = 'cancel';
		document.forms[formName].submit();
	}
}

function soldRecords(formName)
{
	if (confirm("Are you sure you want to mark these as sold?")) {
		document.forms[formName].button.value = 'sold';
		document.forms[formName].submit();
	}
}

function inviteFriends(formName)
{
	if (confirm("Are you sure you want to invite the selected members to be on your friend list?")) {
		document.forms[formName].button.value = 'invite';
		document.forms[formName].submit();
	}
}

// Pop-Up Windows

function openWindow(path, name, width, height, format)
{
	window.open(path, name, "width=" + width + ",height=" + height + format);
}

// List Boxes

function changeSequence(list, to)
{
	var index = list.selectedIndex;
	var total = list.options.length - 1;
	if (index == -1) return false;
	if (to == +1 && index == total) return false;
	if (to == -1 && index == 0) return false;
	var items = new Array;
	var values = new Array;

	for (i = 0; i <= total; i++) {
		items[i] = list.options[i].text;
		values[i] = list.options[i].value;
	}

	for (i = 0; i <= total; i++) {
		list.options[i] = new Option(items[i], values[i]);
	}
	list.options[index + to] = new Option(items[index], values[index], 0, 1);
	list.options[index] = new Option(items[index + to], values[index + to]);

	list.focus();
}

function selectAll(list)
{
	for (i = 0; i <= list.options.length - 1; i++) { 
		list.options[i].selected = true; 
	}
}

// Arrows

if (hover) {
	arrowgray	= preload('/shared/icons/arrowgray.gif');
	arrowpurple	= preload('/shared/icons/arrowpurple.gif');
	arrowgreen	= preload('/shared/icons/arrowgreen.gif');
	arrowred	= preload('/shared/icons/arrowred.gif');
}

function turnPurple(formName, imageName, hiddenName, id)
{
	if (hover) {
		if (document.forms[formName].elements[hiddenName + '[' + id + ']'].value == id) {
			document[imageName + id].src = arrowgray.src;
			document.forms[formName].elements[hiddenName + '[' + id + ']'].value = '';
		} else {
			document[imageName + id].src = arrowpurple.src;
			document.forms[formName].elements[hiddenName + '[' + id + ']'].value = id;
		}
	}
}

function turnColor(formName, imageName, hiddenName, color)
{
	if (hover) {
		stringLength = hiddenName.length;
		elementArray = document.forms[formName].elements;
		for (i = 0; i < elementArray.length; i++) {
			if (elementArray[i].name.substr(0, stringLength) == hiddenName) {
				openBracket = elementArray[i].name.search('\\[');
				closeBracket = elementArray[i].name.search('\\]');
				arrayIndex = elementArray[i].name.substring(openBracket + 1, closeBracket);
				if (elementArray[i].value == arrayIndex) {
					eval('document[imageName + arrayIndex].src = arrow' + color + '.src');
				}
			}
		}
	}
}

function actionPurple(formName, imageName, hiddenName, id, action)
{
	if (hover) {
		if (document.forms[formName].elements[hiddenName + '[' + id + ']'].value == id) {
			document[imageName + id].src = arrowgray.src;
			document.forms[formName].elements[hiddenName + '[' + id + ']'].value = '';
		} else {
			document[imageName + id].src = arrowpurple.src;
			document.forms[formName].elements[hiddenName + '[' + id + ']'].value = id;
		}
		eval(action);
	}
}

function selectAllArrows(formName, imageName, hiddenName)
{
	if (hover) {
		stringLength = hiddenName.length;
		elementArray = document.forms[formName].elements;
		for (i = 0; i < elementArray.length; i++) {
			if (elementArray[i].name.substr(0, stringLength) == hiddenName) {
				openBracket = elementArray[i].name.search('\\[');
				closeBracket = elementArray[i].name.search('\\]');
				arrayIndex = elementArray[i].name.substring(openBracket + 1, closeBracket);
				document[imageName + arrayIndex].src = arrowpurple.src;
				document.forms[formName].elements[hiddenName + '[' + arrayIndex + ']'].value = arrayIndex;
			}
		}
	}
}