$(function() {
	
	//
	//	Maintenance progression
	//
	
	$('#strBtn').click(function() {
		$(this).hide();
		current = $('#current').val();
		$('#strLoad').show();
		
		$.ajax({
			url: "maintenance/inc/newStream.php",
			data: "current="+current,
			type: "GET",
			dataType: 'html', 
			success: function(data) {
						$('#updStream tbody').append(data);
					}
		});
		
		current++;
		$('#current').val(current);
		$('#strLoad').hide();
		
		$(this).show();
	});
	
	//
	//	Once-off progression
	//
	
	$('#onceOffBtn').click(function() {
		$(this).hide();
		current = $('#currentOnceOff').val();
		$('#onceOffLoad').show();
		
		$.ajax({
			url: "maintenance/inc/newOnceOff.php",
			data: "currentOnceOff="+current,
			type: "GET",
			dataType: 'html', 
			success: function(data) {
						$('#mainOnceOff tbody').append(data);
					}
		});
		
		current++;
		$('#currentOnceOff').val(current);
		$('#onceOffLoad').hide();
		
		$(this).show();
	});
	
	function showVehicle(){
		$("#vehicleDisplay").toggle('blind');
	};
	
	$("#enableVehicle").click(function() {
		showVehicle();
	});
	
	function showOnceOff(){
		$("#onceOffDisplay").toggle('blind');
		$('#onceOffBtn').click();
	};
	
	$("#enableOnceOff").click(function() {
		showOnceOff();
	});
	
	function showContactForm(){
		$("#contactForm").toggle('blind');
	};
	
	$("#whoFor").click(function() {
		showContactForm();
	});
	
	function showAdminBox(){
		$("#adminBox").toggle('blind');
	};
	
	$("#adminButton").click(function() {
		showAdminBox();
	});
	
	// Help side
	$("#contactRefIcon").mouseover(function(){
		$("#infoContactRef").toggle('fade');
	});
	$("#contactRefIcon").mouseout(function(){
		$("#infoContactRef").toggle('fade');
	});	

	$("#claimantNameIcon").mouseover(function(){
		$("#infoClaimantName").toggle('fade');
	});
	$("#claimantNameIcon").mouseout(function(){
		$('#infoClaimantName').toggle('fade');
	});

	$("#dobIcon").mouseover(function(){
		$("#infoDOB").toggle('fade');
	});
	$("#dobIcon").mouseout(function(){
		$('#infoDOB').toggle('fade');
	});
	
	$("#claimantGenderIcon").mouseover(function(){
		$("#infoClaimantGender").toggle('fade');
	});
	$("#claimantGenderIcon").mouseout(function(){
		$('#infoClaimantGender').toggle('fade');
	});
	
	$("#claimantRaceIcon").mouseover(function(){
		$("#infoClaimantRace").toggle('fade');
	});
	$("#claimantRaceIcon").mouseout(function(){
		$('#infoClaimantRace').toggle('fade');
	});
	
	//	Hide certain elements
	$("#contactForm").hide();
	$(".hidden").hide();
	
	//	Mask inputs
	$('.number').numeric();
	$('.name').alpha({allow:" "});
});

function addStream(type)
{
	$(function() {
		$('#strBtn').click();
	});
}

/*
*	Validation of the maintenance page
*/

function validateMaintenancePage() {
	if (!checkClaimantName()) {
		document.getElementById("claimantName").focus();
		return false;
	}
	
	return true;
}

// Check that the contact name field is not blank
function checkClaimantName() {
	var name = document.getElementById("claimantName");
	
	if (checkEmpty(name.value)) {
		alert("Please enter the claimants name");
		name.style.backgroundColor = '#D40D22';
		return false;
	}
	
	name.style.backgroundColor = '#ebffcd';	// Make background color green if success
	return true;
}

// Check if a field is empty
function checkEmpty(value) {
	if (value.length == 0) {							// If the value does not consist of any characters
		return true;									// report that it is blank
	}
	return false;
}
