// Custom functions for the free trial app

$(document).ready(function(){
	setup_validation("#freetrial_enquiry");
	
	hide_phone_fields();
	
});

function setup_validation(selector) {
	
	// Trigger the validation for the free trial form
  $(selector).validate();
	
	// Add the required attribute to all labels for an item (in case we want to make them bold)
	// This isn't great because it's not degradable - so if you want it 100% usable, make sure you add the class manually
	$(selector + " :input.required").each(function() {
		if ($(this).attr("id")) {
			$("label[for=" + $(this).attr("id") + "]").addClass("required");
		}
	});
	
	// Make it so that selected elements are given a class so they can be styled if needed
	$(selector + " :input")
	.addClass("inactive-item")
	.focus(function() {
		$(this).removeClass("inactive-item");
		$(this).addClass("active-item");
	})
	.blur(function() {
		$(this).removeClass("active-item");
		$(this).addClass("inactive-item");
	})
}


function hide_phone_fields() {
	$("#available_numbers .region_numbers").each(function() {
		$(this).hide();
	});
	$("#region").change(function() {
		$("#available_numbers .region_numbers").each(function() {
			$(this).hide('fast');
		});
		rid = $(this).val();
		$("#region_" + rid).show('fast');
	});
}



