﻿$(document).ready(function() {

	// Fields change colour when they're focused on
	$(".forms input.field, .forms select.field").change(function() {
		$(this).addClass("done");
	});

	// Selected state effect on radio button lists
	$(".multiple-choice input[type=radio], .multiple-choice label").live("click", function() {
		var row = $(this).parent().parent();
		row.siblings().removeClass("selected");
		row.addClass("selected");
	});
	$(".multiple-choice input[type=radio]:checked").trigger('click');

	// Print button
	$(".print img").click(function() {
		window.print();
	});

		// Print button
	$(".pvsearch").click(function() {
		goStep1();
	});
	
	
	$(".intro input").keypress(function(e){
	
	if(e.which == 13)
	{ goStep1(); }
	 
	});
	

	
	// Image rollovers
	$("a.rollover:not(:disabled)").hover(function() {
		$(this).find("img").attr("src", $(this).find("img").attr("src").replace(".gif", "-hi.gif").replace(".jpg", "-hi.jpg"));
	}, function() {
		$(this).find("img").attr("src", $(this).find("img").attr("src").replace("-hi.gif", ".gif").replace("-hi.jpg", ".jpg"));
	});

	$("input.rollover:not(:disabled), img.rollover:not(:disabled)").hover(function() {
		$(this).attr("src", $(this).attr("src").replace(".gif", "-hi.gif").replace(".jpg", "-hi.jpg"));
	}, function() {
		$(this).attr("src", $(this).attr("src").replace("-hi.gif", ".gif").replace("-hi.jpg", ".jpg"));
	});

	// Auto-jump for credit card number type fields
	$(".auto-jump").live("keyup", function(e) {
		var code = (e.keyCode ? e.keyCode : e.which);
		var key = String.fromCharCode(code);
		var regex = /[0-9A-Za-z]|\./;
		if (regex.test(key)) {
			if ($(this).val().length >= 4) {
				if(!$(this).hasClass("done"))
					$(this).addClass("done");
				$(this).next("input[type=text]:first").trigger("focus");
			}
		}
	});

});

// Plate switching functionality
function bindPlateEdit() {
	$(".plate").bind("click", function() { showPlateEdit(); return false; });
	$(".enter-vin, .enter-plate").bind("click", function() { $(".rego, .vin").toggle();  return false; });
}

function showPlateEdit() {
	$(".static-plate").hide();
	$(".plate input").show().focus().bind("blur", function() { hidePlateEdit(); });
	$(".rego .search-plate, .vin .search-plate").show();
	$(".plate").unbind("click");
}

function hidePlateEdit() {
	$(".plate input").hide().unbind("blur");
	$(".static-plate").show().html($(".plate input").val().length > 0 ? $(".plate input").val() : $(".static-plate").html());
	$(".plate").bind("click", function() { showPlateEdit(); });
}

function bindVinEdit() {
$(".vin .vin-no").bind("click", function() { $(".vin input").show(); });
}

function goStep1() {

	if (($("#vinNo").val() =='') && ($("#plateNo").val() == '')) {
	alert("Please enter your registration number or VIN");
	showPlateEdit();
	return false;
	}
	
	if (($("#plateNo").val() =='') && ($("#vinNo").val().length < 17)) {
	alert("Please enter your 17 digit VIN number");
	return false;
	}
	
	if (($("#vinNo").val().length == 17) && ($("#plateNo").val() == "")){
	 location.href = "step1.aspx?plateorvin=" + $("#vinNo").val();
	 }
	 
	if ($("#plateNo").val().length != 0) {
	location.href = "step1.aspx?plateorvin=" + $("#plateNo").val();
	 }
	  
}


