// *************************** jQuery Initialisation **************************** //

$(document).ready(function() {


	// add the menus to the DOM
	for(key in menu) {
		var str = '<div class="subMenu">';
		var subMenu = menu[key];
		for(subKey in subMenu) {
			str += '<div><a href="' + subMenu[subKey] + '">' + subKey + '</a></div>';
		}
		str += '</div>';
		$("#" + key).append(str);
	}

	// show and hide the sub-menus on hover 
	$("#priNav .menu").hover( function () {
		$(this).find(".subMenu").show();
		t = $(this).find("img").attr("title"); // hide the images title as was
		$(this).find("img").attr("title", ""); // causing mouseout probs in safari
	}, function () {
		$(this).find(".subMenu").hide();
		$(this).find("img").attr("title", t); // restore the image title
	} );
	// add a hover class - because ie doesn't support 
	// css :hover styles on anything other than an anchor
	$("#priNav .menu .subMenu div").hover( function () {
//		alert($(this).html());
		$(this).addClass("hover");
	}, function () {
		$(this).removeClass("hover");
	} );

  // mouse over images
  $('#priNav img').imghover();

    // add id's to all the titles
  // and put them in the drop down
  var counter = 1;
  $(".scenario").each( function() {
    $(this).attr('id',counter);
    $("#scenario_nav select").append('<option value="' + counter + '">' + $(this).html() + '</option>');
    counter++;
  });

  // jump to the new section
  $("#scenario_nav select").change( function() {
    top.location = 'storage_scenarios.asp#'+ $(this).val();
  });

});


// *************************** Validation Functions **************************** //

function validateEmail(email_address) {
	if (/\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_address)){
		return true;
	}
	return false;
}

function validateDate(theDate) {
	var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
	var errorMessage = 'Please enter valid date as dd/mm/yy\nThe date must be a real date. (Watch out for leap years).';
	if ((theDate.match(RegExPattern)) || theDate == "") {
		return true;
	} else {
		alert(errorMessage);
			return false;
	}
}

function validateNumber(theNumber) {
	if (!theNumber.toString().match(/^[-]?\d*\.?\d*$/)) {
		return false;
	} else {
		return true;
	}
}


// *************************** General Functions **************************** //

function verifyHuman(formName) {
	document[formName].h_formValidated.value = 'true'
}

function printPage() {
	if (window.print) {
		window.print()
	} else {
		alert("Sorry, your browser doesn't support this feature.");
	}
}

function Left(str, n) {
	return str.substring(0, n);
}

function Right(str, n) {
	len = str.length;
	return str.substring(len -n, len);
}


function sendData(updateURL) {
  $.get(updateURL, function(data){
		return data;
  });
}


// *************************** Intialisation Function **************************** //

function init() {
	// on load initialisations here
	// preloadImages();
}
window.onload = init;

