﻿$(document).ready(function() {
	// Show hidden elements
	$("ul#newsscroll").show();
	$("#banner").show();
	$("#sponsorlogos").show();
	$("body").css("visibility", "visible");

	// Navigation submenus
	$("#navlist li").hover(function() {
		$(this).find("ul:first").stop(true, true).delay(110).slideDown(300);
	}, function() {
		$(this).find("ul:first").stop(true, true).delay(110).slideUp(300);
	});


	// Start Ticker
	$("ul#newsscroll").liScroll({travelocity: 0.05});


	// News Accordian
	$("h1.accordian").click(function() {
		$(this).next("div.accordiantext").stop(true, true).animate({ opacity: "toggle", height: "toggle" }, 500);
	});


	// Cycle through banners
	$("#banner").cycle({
		timeout: 8000,
		speed:   1200
	});


	// Cycle through sponsor logos
	$("#sponsorlogos").cycle({
		timeout: 8000,
		speed:   1200
	});


	// Tooltips
	$(".helplink").hover(function(e) {
	    $(this).next("p").css('top', e.pageY + 10 );
        $(this).next("p").css('left', e.pageX + 20 );
		$(this).next("p").stop(true, true).delay(110).fadeIn(300);
	}, function() {
		$(this).next("p").stop(true, true).delay(110).fadeOut(300);
	});


	// Validate exhibitor login
	$("#manuallogin").submit(function() {
		if ($("#exhiblogin").val().length < 1)
		{
			alert ("You must enter your user name before logging in.");
			return false;
		}

		if ($("#exhibpw").val().length < 1)
		{
			alert ("You must enter your password before logging in.");
			return false;
		}

		$.post("exhibitor_login.asp", 
			$("#manuallogin").serialize(),
			function(data) {
				if (data != "0") {
					$("#manuallogin").fadeOut(100);
					$("#exhibitorloggedin").fadeIn(300);
					t = data.split("|");
					$("#exhibName").html(t[0]);
					if (t[1] === "2012") {
						$("#bk").hide();
						$("#em").show();
					} else {
						$("#em").hide();
						$("#bk").show();
					}
				} else {
					alert ("The login details are incorrect, please try again.");
				}
			});
		return false;
	});
	
	$("#frmmanuallogin").submit(function() {
		if ($("#emlogin").val().length < 1)
		{
			alert ("You must enter your user name before logging in.");
			return false;
		}

		if ($("#empw").val().length < 1)
		{
			alert ("You must enter your password before logging in.");
			return false;
		}

		$.post("exhibitor_login2.asp", 
			$("#frmmanuallogin").serialize(),
			function(data) {
				if (data != "0") {
					window.location = "exhibitor_manual.asp";
				} else {
					alert ("The login details are incorrect, please try again.");
				}
			});
		return false;
	});
	
	$("#manuallogout").submit(function() {
		$.post("exhibitor_logout.asp", function() {
			$("#exhibitorloggedin").hide();
			$("#manuallogin").show();
		});
		window.location.href = "index.asp";
		return false;
	});

	// Populate booking form if currently logged in
	if ($("#exhibid").val() > 0)
	{
		$.post("get_exhibitor.asp", 
		{ id: $("#exhibid").val() },
		function(data)
		{
			if (data == "rnf") { return false; }
			jQuery.map(data.previous_exhibitor_data, function(i, j)
			{
				$("#" + j).val(i);
			});
		}, 
		"json");
	}


	// Validate booking form
	$("#booking_form").submit(function() {

		if ($("#trading_name").val().length == 0)
		{
			alert ("You must enter your Trading Name before submitting the form.");
			$("#trading_name").focus();
			return false;
		}

		if ($("#azindex").val().length == 0)
		{
			alert ("You must enter the A-Z index letter you would like to be listed under before submitting the form.");
			$("#azindex").focus();
			return false;
		}

		if ($("#c_address").val().length == 0)
		{
			alert ("You must enter your Correspondence Address before submitting the form.");
			$("#c_address").focus();
			return false;
		}

		if ($("#c_telephone").val().length == 0)
		{
			alert ("You must enter your Correspondence Telephone before submitting the form.");
			$("#c_telephone").focus();
			return false;
		}

		if ($("#c_email").val().length == 0)
		{
			alert ("You must enter your Correspondence Email before submitting the form.");
			$("#c_email").focus();
			return false;
		}

		if ($("#c_email").val().indexOf("@") == -1 || $("#c_email").val().lastIndexOf(".") == -1)
		{
			alert ("The entered email address does not appear to be valid. Please correct it before submitting the form.")
			$("#c_email").focus();
			return false;
		}

		if (!$("input[name='product_group']:checked").val())
		{
			alert ("You must select a Product Group before submitting the form.");
			$("#product_group_christmas").focus();
			return false;
		}

		if (!$("input[name='current_stand']:checked").val())
		{
			alert ("You must indicate whether you wish to reserve your current stand and position before submitting the form.");
			$("#current_stand_yes").focus();
			return false;
		}
		
		if (!$("input[name='stand_type']:checked").val())
		{
			alert ("You must choose the Stand Type you would like before submitting the form.");
			$("#stand_type_space").focus();
			return false;
		}
		
		if (!$("#digital_signature:checked").val())
		{
			alert ("You must sign the form before submitting it.");
			$("#digital_signature").focus();
			return false;
		}
	});
	
});

