	$(function(){
		$('#dialogwin').dialog({
			width:980,
			height:600,
			autoOpen: false,
			modal: true,
			position:'top',
			bgiframe: true,
			title: this.title
		});
		$('.testlink').click(function(){
			$('#dialogwin').load(this.href, function(){
				$('#dialogwin').dialog('open');
			});
			return false;
		});
		$('.pageload').click(function(){
			$.ajax({
				url: this.href,
				success: function( html ) {
					$('#testcontent').html(html);
				}
			});
			return false;
		});
		$('.testsave').click(function(){
			var name = $(this).attr('name');
			var rel = $(this).attr('rel');
			$('#'+name).hide();
			$('#'+rel).show();
			$.ajax({
				url: this.href,
				type: 'POST',
				data: $('#testform').serialize(),
				success: function(data) {
					//alert(data );
					if (data != "demo") {
						if (!IsValidInt(data)) {
							//alert( data );
							
							//alert("System Warning.\n\nThe system has found an error where your Answers are not being recorded.  If you continue then it is likely you will not pass this test.\n\nTo remedy, please try the following.\n\n1: Logoff, Close and Restart your Browser and then try again.\n2: Logoff and try another Internet Browser such as Chrome or Firefox\n3: Try another PC\n\nNote: You will not lose any test credit / attempts due to this error.");
							//$.ajax({
								//url: '/tests/error_log/testsave',
								//type: 'POST'
							//});
						}
					}
  				}
			});
			return false;
		});
		function IsValidInt(s) {
			var valid = false;
    		if (s != null && s != "" && !isNaN(s)) {
        		valid = parseInt(s, 10) == s;
    		}
    		return valid;
		}
	});