// Common Javascript library for UKMIX (www.ukmix.org)
// (c) 2000-2001 Lars Janssen

// This script must be called from the HEAD section
// because it creates a stylesheet link


// SWAP IMAGES
var imgs = new Array();

// These images are used in the header on every page
imgs[imgs.length] = '/logos/h_home_over.gif'
imgs[imgs.length] = '/logos/h_sites_over.gif'
imgs[imgs.length] = '/logos/h_reviews_over.gif'
imgs[imgs.length] = '/logos/h_forums_over.gif'
imgs[imgs.length] = '/logos/h_articles_over.gif'
imgs[imgs.length] = '/logos/h_fanbase_over.gif'
imgs[imgs.length] = '/logos/h_aboutus_over.gif'


function preloadImages() {
	var loadImgs = new Array();
	for (var i = 0; i < imgs.length; i++) {
		loadImgs[i] = new Image();
		loadImgs[i].src = imgs[i];
	}
}

function swapImage(strName, strSrc) {
	//	Search for image by name in images collection
	for (i = 0; i < document.images.length; i++) {
		if (document.images[i].name == strName) {
			document.images[i].src = strSrc;
			return;
		}
	}

	//	If the above search failed, search for image by name in entire collection
	for (i = 0; i < document.all.length; i++) {
		if (document.all[i].name == strName) {
			document.all[i].src = strSrc;
			return;
		}
	}
}

// FRAMES & LINKS HANDLING

// Check that UKMIX isn't framed in another site
if (top.frames.length != 0) {
	top.location.href = window.location.href;
}

// Create absolute link when called from certain domains
// (is this still needed?)
var absUrl = '';
if (location.href.indexOf('pairlist') >= 0) {
	absUrl = 'http://www.ukmix.org';
}


// BROWSER DETECTION

//	Determine what kind of browser is being used
//	Legacy rubbish, use by date: end 2003
var browName = navigator.appName;
var browVer = parseInt(navigator.appVersion);
var useDynamic = false;
if (browName== 'Microsoft Internet Explorer' && browVer >= 4) {
	useDynamic = true;
}

//	Legacy rubbish, use by date: end 2003
//	Warn Netscape 4.x of discontinued support
function checkNetscapeVersion()
{
	if (browName == 'Netscape' && browVer == 4)
	{
		document.write
		(
				'<table bgcolor="#FFFF99"><tr><td><font size="-1">'
			+	'Sorry, UKMIX does not support Netscape 4.x series browsers anymore.<br /> '
			+	'This is owing to a lack of demand combined with the many bugs and problems '
			+	'for which this browser is notorious. We are committed to open standards and '
			+	'will support all browsers that work reasonably well and comply reasonably well '
			+	'to the standards, including Mozilla, Netscape 6.x, Opera and Internet Explorer.'
			+	'</font></td></tr></table>\n'
		);
	}
}


// STYLESHEET OUTPUT
//	Legacy rubbish, use by date: end 2003

//	Create stylesheet links for browsers that can handle it
if (browName == 'Netscape' && browVer == 4) {
	document.write ('<link href="' + absUrl + '/includes/style-n4.css" rel="stylesheet" type="text/css">\n');
}
else if (browVer >= 4) {
	document.write ('<link href="' + absUrl + '/includes/style.css" rel="stylesheet" type="text/css">\n');
}


// FORMS EFFECTS - TEXT BOXES & BUTTONS

// Textboxes Focus ON
function highlightBox(thisObject) {
	if (!useDynamic) return;
	thisObject.style.borderColor='#00A5E0';
}

// Textboxes Focus OFF
function unHighlightBox(thisObject) {
	if (!useDynamic) return;
	thisObject.style.borderColor='#7F7F7F';
}

// Buttons Focus ON
function highlightButton(thisObject) {
	if (!useDynamic) return;
		thisObject.style.backgroundColor='#205AA7';
}

// Buttons Focus OFF
function unHighlightButton(thisObject) {
	if (!useDynamic) return;
	thisObject.style.backgroundColor='#00A5E0';
}


// GENERAL FUNCTIONS

// Open a pop-up window and return a reference to it
function openWin(url, width, height) { 

	var windowName = 'buttons';
	var params = 'toolbar=0,';
	params += 'location=0,';
	params += 'directories=0,';
	params += 'status=0,';
	params += 'menubar=0,';
	params += 'scrollbars=1,';
	params += 'resizable=0,';
	params += 'left=100,screenX=100,';
	params += 'top=100,screenY=100,';
	params += 'width=' + width + ',';
	params += 'height=' + height;

	var win = window.open(url, windowName, params);
	win.opener.name = 'opener';

	return win;

}


// Insert an OPTION into a SELECT list
function insertOption(selectList, insertPos, insertText, insertValue, insertDefault, insertSelected) {

	if (browName == 'Microsoft Internet Explorer') {
		var newOption = document.createElement("OPTION");
		newOption.text = insertText;
		newOption.value = insertValue;
		selectList.options.add (newOption, insertPos);
	}
	else {
		for (var k = selectList.length; k > insertPos; k--) {
			selectList[k] = new Option (
				selectList[k-1].text,
				selectList[k-1].value
			);
		}
	
		selectList[insertPos] = new Option(
			insertText,
			insertValue,
			insertDefault,
			insertSelected
		);
	}
}



// FORUMS STUFF

function focusTextField (form) {
	if ((typeof form != 'object') || (typeof form.elements != 'object')) {
		return false;
	}

	var elements = form.elements;
	for (var i = 0; i < elements.length; i++) {
		if ((elements[i].type != 'text') && (elements[i].type != 'password')
			&& (elements[i].type != 'textarea')) {
			continue;
		}
		if (elements[i].name == 'helpbox') {
			continue;
		}

		//// BEGIN: subject field exception (on reply/edit/quote)
		// - this section can be safely removed
		if ((location.pathname.indexOf('posting.php') >= 0)
			&& (location.search.indexOf('mode=newtopic') == -1)) {
			if (elements[i].name == 'subject') {
				continue;
			}
			if (elements[i].name == 'message') {
				elements[i].focus();
				break;
			}				
		}
		//// END: subject field exception

		if (elements[i].value == '') {
			elements[i].focus();
			break;
		}
	}
	return true;
}


