/**
	* Function to get an element by it's ID parameter in both IE and Mozilla based browsers.
	*/
function acceptConditions()
{
	return getElement("accept_field_0").checked ? true : alert('You must accept the terms and conditions to continue');
}
	
function getElement(id)
{
	if(document.all)
	{
		return document.all[id];
	}
	else if(document.getElementById)
	{
		return document.getElementById(id);
	}
	else
	{
		for(iLayer = 1; iLayer < document.layers.length; iLayer++)
		{
			if(document.layers[iLayer].id == id)
			{
				return document.layers[iLayer];
			}
		}
	}
	return null;
}

/**
	* Set an input value
	*/
function setValue(id, value)
{
	var obj = getElement(id);
	obj.value = value;
}

/**
	* Submits a form with the specified ID, action and optional validate function
	*/
function submitForm(form_id, form_action, validate)
{
	// Set default value for validate if no argument is passed
	$("#submit_button").disabled = true;
	var validate = (validate == null) ? true : validate();
	if (validate)
	{
		var form = getElement(form_id);
		try
		{
			if(form_action != "")
			{
				form.elements.action.value = form_action;
			}
			form.submit();
		}
		catch(error)
		{
			alert("There was an error:\n\n"+error.description);
		}
	}
}

/**
	* Hide or show a block level element
	*/
function toggleVisible(id)
{
	var obj = getElement(id);
	if(obj.style.display == "block")
	{
		obj.style.display = "none";
	}
	else if(obj.style.display == "none")
	{
		obj.style.display = "block";
	}
	else
	{
		obj.style.display = "block";
	}
}

/**
	* Goto the specified URL
	*/
function gotoUrl(url)
{
	document.location.href=url;
}

function showMenu(id)
{
	$(document).ready(function(){
		/*
		var class_name = ($("#"+id+" dt a").attr("class"));
		$("#"+id+" dt a").removeClass();
		$("#"+id+" dt a").addClass(class_name+"_current");
		*/
		//$("#"+id+" dd").slideDown("slow");
		$("#"+id+" dd").show();
	});
}

// Nick Jones, Feb 2008
// Reveals a number of hidden objects on page dependent on Select Box option
// function showSelect(id of Select Box, id prefix to Reveal - eg "attendee" will reveal "attendeeXX", "attendeeXX+1" up to option value, transition selects the effect - either show/hide immediately or slideUp/slideDown (default slide))
function showSelect(select_id, hidden_id, transition)
{
	if (!transition) transition = "slide";
	var select_box = getElement(select_id);
	try
	{
		var num = parseInt(select_box.options[select_box.selectedIndex].value);
		// Show chosen number of hidden objects
		for( var i=1 ; i<=num ; i++ )
		{
			transition == "slide" ? $("#"+hidden_id+i).slideDown(800) : $("#"+hidden_id+i).show();
		}
		// Hide the rest of them if they are visible
		var max = select_box.options[select_box.options.length-1].value;
		for( var i=num+1 ; i<=max ; i++ )
		{
			transition == "slide" ? $("#"+hidden_id+i).slideUp(800) : $("#"+hidden_id+i).hide();
		}
	}
	catch(error)
	{
		alert("There was an error:\n\n"+error.description);
	}
}

// Updates HTML object content based on given source (eg form item), target ID, event and any value to blank the field
function updateText(textbox_id, target_id, e, blank)
{
	if (e)
	{
		var key = (window.event) ? event.keyCode : e.keyCode;
	}
	else
	{
		var key = 0;
	}	
	
	switch(key)
	{
		case 9:
		case 16:
// 			break;
		case 13:
			//alert("input#"+textbox_id+".text_field");
			//tmp = jQuery.inArray("input#"+textbox_id+".text_field", $(":text"));
			//tmp = $(":text"); //[].focus();;
		default:
// 			if ( typeof(textbox_id) == "string") $(target_id).html(textbox_id);
			if ( (element = getElement(textbox_id)) ? element.value : 0 )
			{
				switch(element.type)
				{
					case "select-one":
						if (!element.selectedIndex || element.options[element.selectedIndex].text == blank)
						{
							$(target_id).html("");
						}
						else
						{
							$(target_id).html(element.options[element.selectedIndex].text);
						}
						break;
					default:
						(typeof(blank) != 'undefined' && element.value == blank) ? $(target_id).html("") : $(target_id).html(element.value);
						break;
				}
			}
			break;
	}
	
}

function showVisibleSlide(id,focus)
{
	var obj = $("#"+id);
	obj.animate( { height: "show", opacity: "show" }, 200, function() {
		if ( focus ) $("#"+focus).focus();
	} );
}


function hideVisibleSlide(id,focus)
{
	var obj = $("#"+id);
	obj.animate( { height: "hide", opacity: "hide" }, 200, function() {
		if ( focus ) $("#"+focus).focus();
	} );
}

function toggleVisibleSlide(id,focus)
{
	var obj = $("#"+id);
	if ( obj[0].style.display == "none" )
	{
		showVisibleSlide(id,focus);
	}
	else
	{
		hideVisibleSlide(id,focus);
	}
}


// Takes text as input and converts all formatting to HTML formatting
function displayParagraph(text)
{
	return (text) ? text.replace(/\n/g,"<br />") : "";
}

function showTab(tabgroupName, tabName) {
	var tabGroup = getElement(tabgroupName);
	var menuItems = tabGroup.getElementsByTagName("ul")[0].getElementsByTagName("li");
	for (var i=0; i<menuItems.length ; i++ ) {
		if (menuItems[i].id == (tabName + "_tab")) {
			getElement(menuItems[i].id.substring(0,menuItems[i].id.length-4)).style.display = "";
			menuItems[i].className += " current";
		} else {
			getElement(menuItems[i].id.substring(0,menuItems[i].id.length-4)).style.display = "none";
			var curPos = menuItems[i].className.indexOf("current");
			if (curPos != -1) {
				var className = menuItems[i].className;
				menuItems[i].className =  className.substring(0,curPos-1);
				if (className.length > curPos + 7) menuItems[i].className += className.substring(curPos+7,className.length);
			}
		}
	}
}

function hideEditProfile(id)
{
	$("#"+id+"_edit").animate( { opacity: "hide", paddingTop: 0, paddingBottom: 0 }, 100, function() {
		$("#"+id+"_view").animate( { opacity: "show" }, 100 );
	});
}

function edit(section_id,focus_id)
{
	$("#"+section_id+"_view").animate( { opacity: "hide", paddingTop: 0, paddingBottom: 0 }, 100, function() {
		$("#"+section_id+"_edit").animate( { opacity: "show" }, 100, function() {
			getElement(focus_id).focus();
		});
	});
}

function go(folder)
{
	var department = $("#department_field").val();
	var day = $("#day_field").val();
	var path = window.location.pathname;
	if (department != -1 && day != -1) window.location.href = "http://archive.a4uexpo.com" + folder + department + "/" + day + "/";
}

function goList()
{
	params = new Array();
	if ($("#order_field").val() != 0) params.push("o");
	if ($("#sort_field").val()) params.push("s="+$("#sort_field").val());
	window.location.href = "http://archive.a4uexpo.com/london/exhibitor_list.php?" + params.join("&");
}

// Takes any string and converts it into a form that can be used in SEO-optimised URLs, eg converts "It's Not Working" to "its-not-working"
function SEOEncode(string)
{
	return string.toLowerCase().replace(/'/g,"").replace(/ /g,"-").replace(/\(/g,"").replace(/\)/g,"");
}