hairnet = function()
	{
	return false;
	}

hidetabs = function(front)
	{
	if(front=='click')
		{
		document.getElementById('info').style.display='none';
		document.getElementById('infopack').style.display='none';
		}
	//get the tabs and hide them (apart from the first one)
	var divs = document.getElementsByTagName('div');
	for(i=0;i<divs.length;i++)
		{
		if(divs[i].className=='tab')
			{
			divs[i].style.display='none';
			}
		}
	}

deselect = function()
	{
	var tabs = document.getElementById('buttons');
	var links = tabs.getElementsByTagName('a');
	for(x=0;x<links.length;x++)
		{
		links[x].className='';
		}
	}

nextlink = function()
	{
	if(document.getElementById('content'))
		{
		var content = document.getElementById('content');
		var links = content.getElementsByTagName('a');
		for(x=0;x<links.length;x++)
			{
			if(links[x].className=='next')
				{
				links[x].onclick = function()
					{
					//hide all of the tabs
					hidetabs('click');
					//deselect all of the buttons
					deselect();
					//add class name to the link we've clicked
					this.className = "selected";
					//get the links from the href attribute
					var tabname = this.title;
					tabname = tabname.replace('next:','');
					//display the relevant tab
					document.getElementById(tabname).style.display='block';
					//highlight the relevant button
					var buttonsholder = document.getElementById('buttons');
					var links = buttonsholder.getElementsByTagName('a');
					for(i=0;i<links.length;i++)
						{
						if(links[i].title==tabname)
							{
							links[i].className = 'selected';
							}
						}
					//stop the link
					return false;
					}
				}
			}
		}
	}


tabs = function()
	{
	//first, check if we're on a page with tabs - indicated by a UL with an ID of 'buttons'
	if(document.getElementById('buttons'))
		{
		hidetabs('start');
		//now we loop through the buttons		
		var tabs = document.getElementById('buttons');
		var links = tabs.getElementsByTagName('a');
		for(x=0;x<links.length;x++)
			{
			links[x].onclick = function()
				{
				//hide all of the tabs
				hidetabs('click');
				//deselect all of the buttons
				deselect();
				//add class name to the link we've clicked
				this.className = "selected";
				//get the links from the title attribute
				tabname = this.title;
				//display the relevant tab
				document.getElementById(tabname).style.display='block';
				//stop the link
				return false;
				}
			}
		}
	}


menu = function()
	{
	tabs();
	nextlink();
	if (document.all&&document.getElementById)
		{
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++)
			{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI")
				{
				node.onmouseover=function()
					{
					this.className+=" over";
					}
				node.onmouseout=function()
					{
					this.className=this.className.replace(" over", "");
					}
				}
			}
		}
	}

function jumpMenu(targ,selObj,restore){
	
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  
  if (restore) selObj.selectedIndex=0;
  
}

function toggleDropdown(id) {
	if(document.getElementById(id).style.display=='none'){
		document.getElementById(id).style.display='block';
	} else {
		document.getElementById(id).style.display='none';
	}
}

window.onload = menu;



// jQuery bits...
$(function()
{

	$("input[name='use_billing_address']").click(
		function ()
		{
		
			var fields = Array("cust_del_name", "cust_del_addr1", "cust_del_addr2", "cust_del_addr3", "cust_del_addr4", "cust_del_country", "cust_del_postcode");
			
			for(var i=0; i<=fields.length; i++) {
			
				if($(this).attr("checked")) {
				
					$("input[name='" + fields[i] + "'], select[name='" + fields[i] + "']").removeClass("invalid");
					$("input[name='" + fields[i] + "'], select[name='" + fields[i] + "']").attr("disabled", true);
				
				} else {
				
					$("input[name='" + fields[i] + "'], select[name='" + fields[i] + "']").attr("disabled", false);
				
				}
			
			}
		
		});
	
	$("form").submit(function() 
		{
			var fields = $(this).find(".mand");
			var invalid_count = 0;
			var formoutput = $(this).find(".formoutput");
			var invalid_email = false;
			var show_invalid_email_warning = true;
			var cmsg = "The highlighted email address you provided does not seem to be correct. Would you like to continue anyway?";
			if($(formoutput).css("display") !== "none") {
				if(formoutput.length > 0) $(formoutput).fadeOut(500);
			}
			for(i=0; i<fields.length; i++) {
				$(fields[i]).removeClass("invalid");
				if(fields[i].type == "checkbox") {
					$(fields[i]).parent().css("border", "none");
				}
			}
			for(i=0; i<fields.length; i++) {
				if(!$(fields[i]).attr("disabled")) {
					switch(fields[i].type) {
						case "select-one":
						case "select-multiple":
							if(fields[i].selectedIndex == 0) {
								$(fields[i]).addClass("invalid");
								invalid_count++;
							}
							break;
						case "checkbox":
							if(!fields[i].checked) {
								$(fields[i]).parent().css("border", "1px solid #FF0000");
								invalid_count++;
							}
							break;
						case "text":
						case "textarea":
						case "password":
							if(!fields[i].value) {
								$(fields[i]).addClass("invalid");
								invalid_count++;
							} else {
								var name = $(fields[i]).attr("name");
								if(name.indexOf("email") >= 0) {
									var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,4}){1,2}$/;
									if(emailRegxp.test(fields[i].value) == false) {
										invalid_email = true;
										if(show_invalid_email_warning) {
											$(fields[i]).addClass("invalid");
										}
									}
								}
							}
							break;
					}
				}
			}
			if( !invalid_count ) {
				if(invalid_email && show_invalid_email_warning) {
					if(!confirm(cmsg)) { 
						return false;
					}
				}
				return true;
			} else {
				if(formoutput.length > 0) {
					$(formoutput).css("font-size", "0.9em");
					$(formoutput).css("color", "#ff0000");
					$(formoutput).css("font-weight", "bold");
					$(formoutput).text("Please ensure the highlighted fields are complete before proceeding.");
					$(formoutput).fadeIn(500);
				} else {
					alert("Please ensure the highlighted fields are complete before proceeding.");
				}
				return false;
			}
		}
	);

	$("form#ticket_allocations .use_main_address").click(
		function ()
		{
		
			var alloc_num = $(this).attr("id");
			alloc_num = alloc_num.substr(3);
			
			if($(this).attr("checked")) {
			
				$("#addr1_"+alloc_num).val($("#addr1_1").val());
				$("#addr2_"+alloc_num).val($("#addr2_1").val());
				$("#addr3_"+alloc_num).val($("#addr3_1").val());
				$("#addr4_"+alloc_num).val($("#addr4_1").val());
				$("#post_code_"+alloc_num).val($("#post_code_1").val());
				$("#country_"+alloc_num).val($("#country_1").val());
				$("#telephone_"+alloc_num).val($("#telephone_1").val());
			
			} else {
			
				$("#addr1_"+alloc_num).val("");
				$("#addr2_"+alloc_num).val("");
				$("#addr3_"+alloc_num).val("");
				$("#addr4_"+alloc_num).val("");
				$("#post_code_"+alloc_num).val("");
				$("#country_"+alloc_num).val("United Kingdom");
				$("#telephone_"+alloc_num).val("");
			
			}
		
		});

	$("#booking-form .booking-stage").each(
		function (pos)
		{
			if(pos > 0) $(this).hide();
		});
	
	if($("#booking-form .tabs li.selected").length == 0) {
		$("#booking-form .tabs li:first").addClass("selected");
	}
	
	$("#booking-form .tabs a").click(
		function ()
		{
			var url = $(this).attr("href");
			if($(url).length && $(this).hasClass("noswitch") == false) {
				$("#booking-form .booking-stage").hide();
				$("#booking-form .content > " + url).show();
				$("#booking-form .tabs li").removeClass("selected");
				$(this).parent("li").addClass("selected");
			}
		});
	
	$("#booking-form .attendee").hide();
	$("#booking-form .attendee").each(
		function (e)
		{
			e++;
			var attendee_count = $("#booking-form input.attendee_count:checked").val();
			parseInt(attendee_count);
			if(attendee_count >= e) {
				$(this).show();
			} else {
				$(this).find("input").attr("disabled", true);
				$(this).find("select").attr("disabled", true);
			}
		});
	$("#booking-form input.attendee_count").click(
		function ()
		{
			var attendee_count = parseInt($(this).val());
			$("#booking-form .attendee").hide();
			$("#booking-form .attendee").find("input").attr("disabled", true);
			$("#booking-form .attendee").find("select").attr("disabled", true);
			for(var i=0; i<=attendee_count-1; i++) {
				$("#booking-form .attendee:eq("+i+")").show();
				$("#booking-form .attendee:eq("+i+")").find("input").attr("disabled", false);
				$("#booking-form .attendee:eq("+i+")").find("select").attr("disabled", false);
			}
		});
	$(".option-select input[name='pcar_id']:checked, .option-select input[name='hotel_id']:checked").parent().parent().parent().addClass("selected");
	$(".option-select input[name='pcar_id'], .option-select input[name='hotel_id']").click(
		function ()
		{
			$(".option-select .option").removeClass("selected");
			var thisParentOption = $(this).parent().parent().parent();
			$(thisParentOption).addClass("selected");
		});
	
	$("#num_rooms").change(
		function ()
		{
		
			$("#travelBookingForm").submit();
		
		});
	
	
	$(".name_field").focus(function(){$(this).val("");});
	
	
	$("input[name='use_lead']").click(
		function ()
		{
			var Fields = Array("email", "name", "addr1", "addr2", "addr3", "addr4", "postcode", "tel");
			for(var i=0; i<=Fields.length; i++) {
				var fieldName = Fields[i];
				if(fieldName !== "email") fieldName = "bil_"+fieldName;
				if($(this).attr("checked")) {
					$("input[name='cust_"+fieldName+"']").val($("input[name='lead_"+Fields[i]+"']").val());
				} else {
					$("input[name='cust_"+fieldName+"']").val("");
				}
			}
		});
	
	
	function rotator ()
	{
		
		var wait_time = 6000; // miliseconds (1s = 1000ms)
		var currItem = 0;
		var numItems = $("#featured .rally").length;
		
		$("#featured .rally:eq(0)").css("display", "block");
		$("#featured .rally:gt(0)").css("display", "none");
	
		window.setInterval(doRotate, wait_time);
		
		function doRotate()
		{
	
			$("#featured .rally:eq("+currItem+")").fadeOut("slow");
			if(currItem < (numItems-1)) {
				currItem++
			} else {
				currItem = 0;
			}
			$("#featured .rally:eq("+currItem+")").fadeIn("slow");
			
		}
		
	}
	
	rotator();
	

});
