Date.format = 'dd/mm/yyyy';

$(document).ready(function(){



	// Activate PNG transparency fix for IE
	$(document).pngFix();
	
	// Hide the loading indicator on the question build page
// 	$("#loading").hide();


//	$("#navigation").bg([15,15,0,0]);
//	$("#wrapper").bg([0,0,15,15]);
//	$("#order_summary").bg([5,5,5,5]);

	// Activate datepicker on #quiz_start_date
// 	$("input#quiz_start_date").datePicker({
// 		clickInput: true,
// 		startDate: (new Date()).asString(),
// 		endDate: '31/12/2020'
//     });

	// Subject Selection
	$(".subject").change(function() 
	{
		var quiz_round = this.id.replace("subject_", "");
		// alert("Submit Drop Down: " + quiz_round);
		$("#searchText_" + quiz_round).val(""); 
		$("#self_build2").submit(); 
		
	});

	$(".searchText").change(function() 
	{
		var quiz_round = this.id.replace("searchText_", "");
		// alert("Submit Search: " + quiz_round);
		$("#subject_" + quiz_round).val(""); 
		$("#self_build2").submit(); 
		
	});
	



	// Extend tabs

	$(function() {
		var $tabs = $('#tabs').tabs();
		$(".ui-tabs-panel form fieldset").each(function(i){
		  var totalSize = $(".ui-tabs-panel").size() - 1;
		  if (i != totalSize) {
			  next = i + 2;
			  $(this).append("<a href='#' class='next-tab mover' rel='" + next + "'><img width='16' height='16' alt='' src='/_public/graphics/arrow_right.png'/>Next Round &#187;</a>");
		  }
		});
		$('.next-tab, .prev-tab').click(function() { 
			   $tabs.tabs('select', $(this).attr("rel"));
			   return false;
		   });
	});


	
	// 05/10/2009 11:36 SMK: Think this might be causing some errors

	$("#order_confirm").validate();
		
	
	// New answer sheet and poster stuff
	$("#answer_sheet_button").click(function() {
		document.answer_sheet.choosen_answer_sheet_id.value = $('#answer_sheet_list input:radio:checked').val();
	});


	$("#poster_button").click(function() {
		document.poster.choosen_poster_id.value = $('#poster_list input:radio:checked').val();
	});

	// UI blocker for the public creator
	$("#build").submit(function() {
		$.blockUI({
		message: '<div class="loading"><h4>Please wait while we load your questions from our database...</h4></div>', 
		css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: .5, 
			color: '#fff' 
		} });
    });

	// UI blocker for the corporate creator question count check
	$("#multi_choice").submit(function() {
		$.blockUI({
		message: '<div class="loading"><h4>Please wait while we check our database to see how many questions are available to you based on the choices you made...</h4></div>', 
		css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: .5, 
			color: '#fff' 
		} });
    });



	// Multi-choice reload same screen with length options available
	// $(".length_restrictions").change(function() {
	$(":input[@name='length_restrictions']").change(function() {
		document.multi_choice.action = "/multi_choice.htm";
		document.multi_choice.submit();
	});


	// Multi-choice continue to summary screen
	$("#multi_choice_btn").click(function() {
		document.multi_choice.action = "/question_summary.htm";
		document.multi_choice.submit();
	});

	// Multi-choice continue to demo summary screen
	$("#multi_choice_demo_btn").click(function() {
		document.multi_choice.action = "/question_summary_demo.htm";
		document.multi_choice.submit();
	});

	// Multi-choice continue to Place and Order
	$("#place_order_button").click(function() {
		document.question_summary_demo.action = "/start.htm?auth_logout=y";
		document.question_summary_demo.submit();
	});

	// Calculate the total questions for the Multi-choice creator
	$("input[name^='required_']").sum("keyup", "#total_questions");


	// Question Summary continue to List
	$("#question_summary_button").click(function() {
		document.question_summary.action = "/question_list.htm";
		document.question_summary.submit();


		$.blockUI({
		message: '<div class="loading"><h4>Please wait while we generate your quiz question database ready for you to purchase...</h4></div>', 
		css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: .5, 
			color: '#fff' 
		} });




	});

	// Question Summary Search Again
	$("#search_again_button").click(function() {
		document.question_summary.action = "/multi_choice.htm";
		document.question_summary.submit();


	});


	// Question List continue to order confirm
	$("#order_confirm_btn").click(function() {
		document.question_list.action = "/order_confirm.htm";
		document.question_list.submit();
	});



	// Question List Search Again
	$("#search_again_button2").click(function() {
		document.question_list.action = "/multi_choice.htm";
		document.question_list.submit();


	});




});




