//-----------------------------------------------------------------------------
// Copyright (c)2005-2007, Summerleaze Computer Services
// $Revision: 1.1 $
//-----------------------------------------------------------------------------

var errors = 0;
var debug  = 1;

var classname = "";
var submitting = false;

var tickerMouseOver = false;
var tickerReplaced  = false;
var tickerMaxSpeed = 2;
var tickerSpeed = 0;
var tickerWidth = 0;

/*
tickerPreload("images/ticker/timeline.jpg");
tickerPreload("images/ticker/timeline_over.jpg");
tickerPreload("images/ticker/academy.jpg");
tickerPreload("images/ticker/academy_over.jpg");
tickerPreload("images/ticker/gloves.jpg");
tickerPreload("images/ticker/gloves_over.jpg");
tickerPreload("images/ticker/keepers.jpg");
tickerPreload("images/ticker/keepers_over.jpg");
tickerPreload("images/ticker/download.jpg");
tickerPreload("images/ticker/download_over.jpg");
tickerPreload("images/ticker/contact.jpg");
tickerPreload("images/ticker/contact_over.jpg");
tickerPreload("images/ticker/buy.jpg");
tickerPreload("images/ticker/buy_over.jpg");
tickerPreload("images/ticker/glovecuts.jpg");
tickerPreload("images/ticker/glovecuts_over.jpg");
tickerPreload("images/ticker/palm.jpg");
tickerPreload("images/ticker/palm_over.jpg");
*/

$(document).ready(function() {
	$('.hidden').hide();

	$('.tickerbox').mouseover(function(e) {
		tickerMouseOver = true;
		var img = $(this).find('img');
		img.attr('src', img.attr('src').replace(/(\w+).jpg/, "$1_over.jpg"));
	});

	$('.tickerbox').mouseout(function(e) {
		tickerMouseOver = false;
		var img = $(this).find('img');
		img.attr('src', img.attr('src').replace(/(\w+)_over.jpg/, "$1.jpg"));
	});

	initTicker('#ticker-main');

	//$('.news-story:gt(0)').hide();
	//updateNews('.news-story');

	//$('.ticker').initTicker();
	setInterval(dispatch, 50);
});

//-----------------------------------------------------------------------------
// Only want 1 timer running, so use a 'dispatcher'

var ticks = 0;
function dispatch() {
	updateTicker('#ticker-main');
	if(++ticks % 100 == 0) {
		// Every 5 seconds
		//updateNews('.news-story');
		ticks = 0;
	}
}

//-----------------------------------------------------------------------------
// News Functions...
function updateNews(el) {
	$(el).hide();
	var v = $(el).data('visible') || 0;

	if(v > $(el).length-1) v = 0;

	displayNews(el,v);

	$(el).data('visible', v+1);
	//setInterval(function() {updateNews(el);}, 5000);
}

function displayNews(el,v) {
	var story = $(el+':eq('+v+')');
	story.fadeIn('slow');

	var txt = story.find('p')[0].innerHTML;
	if(debug) $('#debug')[0].innerHTML += "NEWS: "+el+':eq('+v+') : '+txt+"<br />";
}

/*
function newsLoop(id) {
	var obj = document.getElementById(id);
	var img = obj.getElementsByTagName('img')[0];

	obj.lastChild.nodeValue = news[i][0];
	obj.href = news[i][1];
	img.src  = news[i][2];

	// Update the news story...
	j = 0;
	ticker = setInterval("addCharacter('"+news[i][3]+"','"+id+"','stop-press',"+news[i][4]+")", 50);

	if(++i >= news.length) i = 0;
}

function addCharacter(story, main, id, delay) {
	var div = document.getElementById(id).getElementsByTagName('div')[0];

	div.innerHTML = story.substr(0,j) + '_';
	if(++j > story.length) {
		div.innerHTML = story;
		clearInterval(ticker);
		timer = setTimeout("newsLoop('"+main+"')", delay);
	}
}
*/








//-----------------------------------------------------------------------------
// Ticker Functions...

function initTicker(id)
{
	var ticker = $(id);

	ticker.find('.tickerbox').each(function(i) {
		var offset = 10+i*160;
		//if(debug) $('#debug')[0].innerHTML += "init[" + i + "]: " + offset + "<br />";
		$(this).css("left", offset + "px").css("top", "10px");
		if ($(this).is(":last-child")) {
			ticker.data('tickerWidth', $(this).css("left").replace(/(.+)px/, "$1") - 160);
		}
	});
	//tickerWidth = ticker.data('tickerWidth');
	ticker.data('tickerSpeed', 0);
	ticker.data('tickerMaxSpeed', 2);
}

function updateTicker(id)
{
	var ticker = $(id);

	ticker.find('.tickerbox').each(function(i) {
		//var current = obj.style.left.length == 0 ? obj.offsetLeft : obj.style.left.replace(/(.+)px/, "$1");
		var current = $(this).css("left").replace(/(.+)px/, "$1");
		//if(debug) $('#debug')[0].innerHTML += "update[" + i + "]: " + current + "<br />";

		if(tickerMouseOver) {
			if(tickerSpeed > 0) {
				--tickerSpeed;
			}
		}
		else {
			if(tickerSpeed < tickerMaxSpeed) {
				++tickerSpeed;
			}
		}

  	if(current < $(this).width()*-1) {
  		//current = tickerWidth;
  		current = ticker.data('tickerWidth');
  	}
  	$(this).css("left", current - tickerSpeed + "px");
	});
}

function tickerPreload(url) {
  //alert("Preloading: " + url);
  var i = new Image();
  i.src = url;
  return i;
}

//-----------------------------------------------------------------------------
// Mouseover Functions...

/*
function _over(el) {
	el.src = el.src.replace(/(\w+).jpg/, "$1_over.jpg");
}

function _out(el) {
	el.src = el.src.replace(/(\w+)_over.jpg/, "$1.jpg");
}
*/

function _over(el, img) {
	var obj = el;

	if (!img) img = "$1_over.jpg";
	if(typeof(el) == "string") {
		obj = document.getElementById(el);
	}
	obj.src = obj.src.replace(/(\w+).jpg/, img);
}

function _out(el, img) {
	var obj = el;
	var regex = /(\w+).jpg/;

	if (!img) {
		img = "$1.jpg";
		regex = /(\w+)_over.jpg/;
	}
	if(typeof(el) == "string") {
		obj = document.getElementById(el);
	}
	obj.src = obj.src.replace(regex, img);
}

function scrollRight(el) {
	var content = el.parentNode.getElementsByTagName('div')[0];

	//new Effect.Move(content, { x: 60, y: -30 });
	//alert(content.nodeName + ': ' + content.style.left);
}

//-----------------------------------------------------------------------------
// Image Loop

var news =
[
	["EDUARDO - WORLD CUP SOUTH AFRICA 2010", "http://www.youtube.com/watch?v=FVGySTo5SxA", "_blank",        "images/news/eduardo.jpg",	 "Genoa signs HO SOCCER sponsored goalkeeper EDUARDO from Braga, after showing he was one of the best keepers at the 2010 FIFA World Cup South Africa, where Eduardo only conceded once, in Portugals 1-0 defeat by Spain.", 5000],
	["GHOTTA 'HYBRID' TECHNOLOGY",            "ghotta.php",                                 "_self",         "images/news/ghotta.jpg",   "For 2010 HO SOCCER introduces the new GHOTTA glove range with Hybrid palm technology. GHOTTA utilizes a unique one piece glove cut, offering a better fit that improves the art of catching the ball.", 5000],
	["CONNOR ROBERTS",                        "players.php?id=roberts",                     "_self",         "images/news/roberts1.jpg", "HO SOCCER are happy to sign exciting young EVERTON F.C keeper Connor Roberts for the new season.", 5000],
	["JULIO CESAR",                           "players.php?id=cesar",                       "_self",         "images/news/cesar.jpg",    "Brazillian keeper Julio Cesar will wear HO SOCCER whilst playing for Benfica for the 2010/11 season", 5000],
	["DUDU AOUATE",                           "clothing.php?id=jersey_legend",              "_self",         "images/news/aouate.jpg",   "HO SOCCER keeper Dudu Aouate of RCD Mallorca wearing the NEW Legend keeper set.", 5000],
	["MATT MURRAY",                           "players.php?id=murray",                      "_self",         "images/news/murray1.jpg",  "Wolvers keeper Matt Murray will wear HO SOCCER gloves for the 2010/11 season", 5000],
	["QUIM and EDUARDO",                      "players.php?id=quim",                        "_self",         "images/news/quim.jpg",     "Portugese National team keepers Quim and Eduardo both agree to wear HO SOCCER gloves for the new season.", 5000],
	["CALCIO ITALIA",                         "calcio.php",                                 "_self",         "images/news/roma.jpg",     "Calcio Italia, top quality hand made pro boots will be available in the UK from July 09", 5000],
	["HELTON DA SILVA",                       "players.php?id=helton",                      "_self",         "images/news/helton.jpg",   "Helton Da Silva of F.C Porto and Brazil will continue to wear HO SOCCER gloves for the 2010/11 season", 5000],
	["CHRIS DUNN",                            "players.php?id=dunn",                        "_self",         "images/news/dunn.jpg",     "HO SOCCER sign young Northampton Town shot stopper Chris Dunn", 5000],
	["GLOVE CUTS GUIDE",                      "glovecuts.php",                              "_self",         "images/cuts/guide.jpg",    "HO SOCCER Gloves use a number of EXCLUSIVE glove cuts. See our Glove Cuts Guide for details", 5000]
];

//	["RYAN ALLSOP",      "players.php?id=allsop",    "images/news/allsop.jpg",     "HO SOCCER would like to congratulate Ryan Allsop on being picked to play in the recent England U17 game against Estonia."],
//	["CARL IKEME",       "players.php?id=ikeme",     "images/news/ikeme.jpg",      "HO SOCCER are happy to anounce that star Wolves keeper Carl Ikeme has agreed to wear their gloves."]
//	["JASON BROWN",      "players.php?id=brown",     "images/news/brown1.jpg",		 "Blackburn keeper Jason Brown signs with HO SOCCER for the 2009/10 season", 5000],
//	["ARMANDO RIVEIRO",            "players.php?id=armando",        "images/news/armando.jpg",    "Armando of Athletic Club De Bilbao has agreed terms to wear HO SOCCER gloves", 5000],
//	["CASPER ANKERGREN",           "players.php?id=ankergren",      "images/news/ankergren1.jpg", "HO SOCCER is proud to announce the signing of Leeds United star goalkeeper Casper Ankergren.", 5000],

var imgs =
[
	["PRO MEGA PRIDE",             "gloves.php?id=pro_mega_pride", "images/news/pro_mega_pride.jpg"],
	["HELTON - FC PORTO & BRAZIL", "players.php?id=helton",        "images/news/helton2.jpg"],
	["HO SOCCER PATENTS",          "gloves.php?id=elite_pro_rf",   "images/news/patents.jpg"],
	["MAX JOHNSON, NEWCASTLE",     "players.php?id=johnson",       "images/news/johnson.jpg"]
];

// 	["PRO MEGA BLACK/GOLD", "promegagold.php", "images/news/black-gold.jpg"]
//	["KONTROL 2009", "gloves.php?id=kontrol", "images/news/kontrol.jpg"],

var cuts =
[
	["FLAT", "#EB7D00", "images/cuts/flat.jpg", "Traditional cut with a flat palm construction, offering a larger contact surface."],
	["NEGATIVE", "#007DC6", "images/cuts/negative.jpg", "This is a cut with internal seams, that provide a tighter fit and better contact with the ball. Also gussets are in latex, offering a larger grip area"],
	["SPECIAL NEGATIVE", "#007DC6", "images/cuts/negative_special.jpg", "This EXCLUSIVE cut is used in <a href=\"#\">ENIGMA gen 4</a>. Construction is same as negative cut but thumb has seperate piece design that assists the natural hand motion."],
	["R-NEGATIVE", "#EB7D00", "images/cuts/r_negative.jpg", "This EXCLUSIVE is similar to Negative Cut with internal seams, but also latex is rolled onto the tip of the fingers, offering extra traction around them."],
	["ROLLFINGER", "white", "images/cuts/rollfinger.jpg", "In this roll finger cut latex palm envelopes the fingers. This ensures constant ball contact and guarantees stability with the ball."],
];

var i = 0;
var j = 0;
var k = 0;
var l = 0;
var timer;
var ticker;
var loopDelay = 5000;

function cutsLoop(id) {
	var obj = document.getElementById(id);
	var img = obj.getElementsByTagName('img')[0];
	var h1  = obj.getElementsByTagName('h1')[0];
	var p   = obj.getElementsByTagName('p')[0];

	h1.innerHTML   = cuts[l][0];
	h1.style.color = cuts[l][1];
	img.src        = cuts[l][2];
	p.innerHTML    = cuts[l][3];

	if(++l >= cuts.length) l = 0;
	setTimeout("cutsLoop('"+id+"')", loopDelay);
}

function imageLoop(id) {
	var obj = document.getElementById(id);
	var img = obj.getElementsByTagName('img')[0];

	obj.lastChild.nodeValue = imgs[k][0];
	obj.href = imgs[k][1];
	img.src  = imgs[k][2];

	if(++k >= imgs.length) k = 0;
	setTimeout("imageLoop('"+id+"')", loopDelay);
}

function newsLoop(id) {
	var obj = document.getElementById(id);
	var img = obj.getElementsByTagName('img')[0];

	obj.lastChild.nodeValue = news[i][0];
	obj.href = news[i][1];
	obj.target = news[i][2];
	img.src  = news[i][3];

	// Update the news story...
	j = 0;
	ticker = setInterval("addCharacter('"+news[i][4]+"','"+id+"','stop-press',"+news[i][5]+")", 50);

	if(++i >= news.length) i = 0;
}

function addCharacter(story, main, id, delay) {
	var div = document.getElementById(id).getElementsByTagName('div')[0];

	div.innerHTML = story.substr(0,j) + '_';
	if(++j > story.length) {
		div.innerHTML = story;
		clearInterval(ticker);
		timer = setTimeout("newsLoop('"+main+"')", delay);
	}
}


//-----------------------------------------------------------------------------


//window.onload = initMenu;
function setBack(id, img) {
	var obj = document.getElementById(id);
	var oPic = new Image;

	oPic.src = img;
	alert(obj.clientHeight + " -=- " + oPic.height);

	obj.style.background = "url('" + img + "')";
	if(obj.height < oPic.height) {
		obj.style.height = opic.height;
	}
}

// Function included in code because including a JS src file seems to crash IE6...
function imgWindow(img,txt) {
	// Load a full size copy of the image so we can work out the correct size to use...
	var oPic = new Image;
	oPic.src = img.src;

	w = open("",'image','width=600,height=600,toolbar=no,scrollbars=no,resizable=yes');
	w.document.write("<HTML><HEAD><TITLE>:: ZOOM :: " + txt + "</TITLE></HEAD>");
	w.document.write("<SCRIPT type=\"text/javascript\">");
	w.document.write("function checksize(w,h) { ");
	w.document.write("	if (document.images[0].complete) {  ");
	w.document.write("		window.resizeTo(document.images[0].width+w, document.images[0].height+h); ");
	w.document.write("		window.focus();");
	w.document.write("	} ");
	w.document.write("	else { ");
	w.document.write("		setTimeout('checksize()',100);");
	w.document.write("	}");
	w.document.write("}");
	w.document.write("</SCRIPT>");
	w.document.write("<BODY onload='checksize(50,50)' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
	w.document.write("<IMG src='" + img.src + "' width=" + oPic.width/2 + " border=0>");
//	w.document.write("<IMG src='" + img.src + "' border=0>");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

// Function included in code because including a JS src file seems to crash IE6...
function imgPopup(img,txt) {
	w=open("",'image','width=600,height=600,toolbar=no,scrollbars=no,resizable=yes');
	w.document.write("<HTML><HEAD><TITLE>"+txt+"</TITLE></HEAD>");
	w.document.write("<SCRIPT type=\"text/javascript\">");
	w.document.write("function checksize(w,h) { ");
	w.document.write("	if (document.images[0].complete) {  ");
	w.document.write("		window.resizeTo(document.images[0].width+w, document.images[0].height+h); ");
	w.document.write("		window.focus();");
	w.document.write("	} ");
	w.document.write("	else { ");
	w.document.write("		setTimeout('checksize()',100);");
	w.document.write("	}");
	w.document.write("}");
	w.document.write("</SCRIPT>");
	w.document.write("<BODY onload='checksize(12,30)' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
	w.document.write("<BODY>");
	w.document.write("<IMG src='"+img+"' border=0>");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

function checksize(w,h) {
	if (document.images[0].complete) {
		window.resizeTo(document.images[0].width+w, document.images[0].height+h);
		window.focus();
	}
	else {
		setTimeout('checksize()',100);
	}
}

function openWindow(address,name) {
	window.open(address, name, "menubar=1,resizable=1");
}


/*
function imgWindow(txt,img) {
	w = open("",'image','width=600,height=600,toolbar=no,scrollbars=no,resizable=yes');
	w.document.write("<HTML><HEAD><TITLE>ZOOM :: " + txt + "</TITLE></HEAD>");
	w.document.write("<SCRIPT type=\"text/javascript\" src=\"functions.js\"></SCRIPT>");
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
	w.document.write("<IMG src='"+img+"' width=\"75%\" border=0>");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

function checksize() {
	if (document.images[0].complete) {
		window.resizeTo(document.images[0].width+50,document.images[0].height+50);
		window.focus();
	}
	else {
		setTimeout('checksize()',100);
	}
}
*/

function showpage(n) {
	var page = document.getElementById("page"+n);

	// Hide all the pages...
	var aPages = document.getElementsByTagName("div");
	for(var i=0; i<aPages.length; i++) {
		if (aPages[i].className == "page") {
			aPages[i].style.display = "none";
		}
	}
	page.style.display = "block";

/*
	// Add an arrow background to the selected button
	var j = 1;
	var aLinks = document.getElementsByTagName("a");
	for(var i=0; i<aLinks.length; i++) {
		//alert(i + ": " + aLinks[i].className + " - " + n);
		if (aLinks[i].className == "pagebutton") {
			alert(aLinks[i].className + " - " + aLinks[i].style.background);
			if(j==n) {
				aLinks[i].style.background = "url(images/arrow.gif) 100% 50% no-repeat";
			}
			else {
				aLinks[i].style.background = "";
			}
			++j;
		}
	}
*/
}

var current_player = 0;

function next_player() {
	++current_player;
	playermenu();
}

function prev_player() {
	--current_player;
	playermenu();
}

function playermenu() {
	var aPlayers = document.getElementsByTagName("li");
	var nPlayers = aPlayers.length - 1;

	if(current_player<0) current_player = 0;
	if(current_player>aPlayers.length-3) current_player = nPlayers-2;

	for(var i=0; i<aPlayers.length; i++) {
		aPlayers[i].style.display = "none";
		if(i>=current_player && i<current_player+3) {
			aPlayers[i].style.display = "block";
		}
	}
}

function showplayer(el) {
	var aPlayers = document.getElementsByTagName("li");

	// use first <li> if none is specified
	if(el == undefined) el = aPlayers[0];

	for(var i=0; i<aPlayers.length; i++) {
		// reset all the players photo's to B/W
		aPlayers[i].firstChild.src = aPlayers[i].firstChild.src.replace(/(\w+)_over.jpg/, "$1.jpg");
		if(el == aPlayers[i]) {
			// Build list of all the player pages
			var aPages = document.getElementById("player-pages").childNodes;

			// Hide them all
			for(var j=0; j<aPages.length; j++) {
				if(aPages[j].nodeName == "DIV") aPages[j].style.display = "none";
			}

			// Display the selected player's page
			var k = 0;
			for(var j=0; j<aPages.length; j++) {
				if(aPages[j].nodeName == "DIV") {
					if(k == i) {
						aPages[j].style.display = "block";
					}
					++k;
				}
			}
		}
	}
	// make selected player's photo colour
	el.firstChild.src = el.firstChild.src.replace(/(\w+).jpg/, "$1_over.jpg");
}



function setimg(o, i) {
	//alert(i);
	o.src = i;
}

function nav(v) {
	var view = document.getElementById('view');

	view.value = v;
	document.form.submit();
}

function doHover(el) {
	el.className = "nav_hover";
}

function noHover(el) {
	el.className = "";
}

function submitForm() {
	submitting = true;
	document.form.submit();
}

function backTo(page) {
	if (!submitting) {
		window.location = page.length > 0 ? page : "diary.php";
	}
	submitting = false;
}

function gotoPage(page) {
	window.location = page;
}

function showForm(form, params) {
	window.location = form + params;
}

function changeClass(el, sClass) {
	el.className = sClass;
}

function initMenu() {
	if (document.all && document.getElementById) {
		var navRoot = document.getElementById('dmenu');
		if (navRoot) {
			for(i=0; i<navRoot.childNodes.length; i++) {
				var node = navRoot.childNodes[i];
				if (node.nodeName == 'LI') {
					node.onmouseover = function() { this.className += ' over'; }
					node.onmouseout  = function() { this.className = this.className.replace(' over', ''); }
				}
			}
		}
	}
}

function menuOver(el) {
	for (i=0; i<el.childNodes.length; i++) {
		node = el.childNodes[i];
		if (node.nodeName=="LI") {
			node.className = "over";
		}
	}
}

function menuOut(el) {
	for (i=0; i<el.childNodes.length; i++) {
		node = el.childNodes[i];
		if (node.nodeName=="LI") {
			node.className = "";
		}
	}
}

function toggleMenu(el) {
	if (document.getElementById) {
		var mStyle = document.getElementById(el).style;
		if (mStyle.display == "block") {
			mStyle.display = "none";
		}
		else {
			mStyle.display = "block";
		}
		return false;
	}
	else {
		return true;
	}
}

function confirmChk(elem) {
	var chkbox = 0;

	// figure out which boxes are ticked
	for (var i=0; i<document.form.length; i++) {
		var el = document.form.elements[i];

		if (el.type == 'checkbox' && el.checked == true) {
			chkbox++;
		}
	}

	// Set value of a hidden input element - gives us a POST variable to trigger the operation
	switch(elem.name) {
		case 'delete':
			var msg = "Are you sure you want to delete the " +
				(chkbox == 1 ? "" : chkbox + " ") + "selected " +
				(chkbox == 1 ? "entry" : "entries");
			if (chkbox > 0 && confirm(msg)) {
				document.getElementById('operation').value = 'delete';
				submitForm();
			}
			break;
		case 'edit':
			document.getElementById('operation').value = 'edit';
			submitForm();
			break;
	}
}

function confirmDelete() {
	var chkbox = 0;
	var valid = true;

	for (var i=0; i<document.form.length; i++) {
		var el = document.form.elements[i];

		if (el.type == 'checkbox' && el.checked == true) {
			chkbox++;
		}
	}

	if (chkbox > 0 && confirm("Are you sure you want to delete the selected entries")) {
		// Set value of a hidden input element - gives us a POST variable to trigger the deletion(s)
		document.getElementById('delete').value = 'delete';
		submitForm();
	}
}

function confirmAcknowledge() {
	var chkbox = 0;
	var valid = true;

	for (var i=0; i<document.Form.length; i++) {
		var el = document.form.elements[i];

		if (el.type == 'checkbox' && el.checked == true) {
			chkbox++;
		}
	}

	if (chkbox > 0 && confirm("Are you sure you want to acknowledge the selected entries")) {
		// Set value of a hidden input element - gives us a POST variable to trigger the Acknowledgment(s)
		document.getElementById('acknowledge').value = 'acknowledge';
		submitForm();
	}
}

function sendEmail(el) {
	var email = prompt("Please enter the email address of the recipient(s)\n(seperate entries with a comma)");
	var isValid = false;

	if (email != null) {
		if (email.indexOf(',') != -1) {
			isValid = validateEmailList(email);
		}
		else {
			isValid = validateEmail(email);
		}
		if (isValid) {
			el.href += "?email=" + email;
		}
	}
}

function showTitle(elem) {
	var pattern = /^(\w+)_(\d+)$/

	if (pattern.test(elem.id)) {
		var name    = RegExp.$1;
		var journey = RegExp.$2;
	}
	else {
		alert("No Pattern Match!");
	}

	var limit = parseInt(document.getElementById('limit_'+elem.id).value);

	switch(name) {
	case 'total':
		var s = 'Passengers';
		break;
	case 'wheelchairs':
		var s = 'Passengers with Wheelchairs';
		break;
	case 'bicycles':
		var s = 'Passengers with Bicycles';
		break;
	}

	elem.title = isNaN(limit) ? '' : s + ' (Limit ' + limit + ')';
}

// Displays all the form's elements...
function showDOM() {
	for (var i=0; i<document.party.length; i++) {
		var el = document.party.elements[i];

		document.getElementById('debug').innerHTML += "el[" + i + "] => " + el.type + ", " + el.id + "<br />";
	}
}

// toggle the 'disabled' state for each argument
function toggleElement() {
	var state = (arguments[0].value.length == 0);
	for(i=1; i<arguments.length; i++) {
		document.getElementById(arguments[i]).disabled = state;
	}
}

function disableElement() {
	for(i=0; i<arguments.length; i++) {
		document.getElementById(arguments[i]).disabled = true;
	}
}

function enableElement() {
	for(i=0; i<arguments.length; i++) {
		document.getElementById(arguments[i]).disabled = false;
	}
}

//**************************************************************************************************
// Toggle the state of a panel
//**************************************************************************************************
function panelToggle(elem) {
	if (elem.className == "collapsed") {
		elem.className = "expanded";
	}
	else {
		elem.className = "collapsed";
	}
	// Expand / Collapse the list
	lists = document.getElementsByTagName('ul');
	if (lists.length > 0) {
		for (var i = 0; i < lists.length; i++) {
			el = lists[i];
			if (el.id == elem.name) {
				if (el.className == "collapsed") {
					el.className = "expanded";
				}
				else {
					el.className = "collapsed";
				}
			}
		}
	}
	divs = document.getElementsByTagName('div');
	if (divs.length > 0) {
		for (var i = 0; i < divs.length; i++) {
			el = divs[i];
			if (el.id == elem.name) {
				if (el.className == "collapsed") {
					el.className = "expanded";
				}
				else {
					el.className = "collapsed";
				}
			}
		}
	}
}


//**************************************************************************************************
// Useful Debugging Functions
//**************************************************************************************************

function showValue(el) {
	el.title = el.name + ' = ' + el.value;
}

function showClass(el) {
	el.title = el.id + ' = ' + el.className;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;

  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document;

  if(d.images){
  	if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
    for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){
    		d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
    	}
   }
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;

  document.MM_sr = new Array;

  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null) {
   	document.MM_sr[j++]=x;
   	if(!x.oSrc) x.oSrc=x.src;
   	x.src=a[i+2];
   }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}