$( document ).ready( function() {

$("body").addClass("jscript");
$('#dates_pickup').datepick({dateFormat: 'dd/mm/yy'});
$('#dates_dropoff').datepick({dateFormat: 'dd/mm/yy'});

$.radioCheckboxGroup("usage");
$.radioCheckboxGroup("employtype");
$.radioCheckboxGroup("accident");
$.radioCheckboxGroup("insurance");
$.radioCheckboxGroup("licence");
$.radioCheckboxGroup("mental");
$.radioCheckboxGroup("conviction");



extLinks();
roundCorners();

// validate signup form on keyup and submit
	$("#reservationForm").validate({
            rules: {
			 usage: {
				required: true,
				minlength: 1
			},
			employtype: {
				required: true,
				minlength: 1
			},
			
			accident: {
				required: true,
				minlength: 1
			},
			
			insurance: {
				required: true,
				minlength: 1
			},
			
			licence: {
				required: true,
				minlength: 1
			},
			
			mental: {
				required: true,
				minlength: 1
			},
			
			conviction: {
				required: true,
				minlength: 1
			}
			
		}
	});
	
////////////////////// Hide show company details //////////////////////

	var bususe = $("#bususe");
	var privateuse = $("#privateuse");
	var compdetail = $("#company_details").hide();

	var inital = bususe.is(":checked");
	var compdetailInputs = compdetail.find("input").attr("disabled", !inital);
	
	// show company details when usage selected
	bususe.click(function() {
	this.checked ? $("#company_details").show('slow') : 
$("#company_details").hide('slow');

    // uncheck private usage
compdetailInputs.attr("disabled", !this.checked);
	});
	
	// hide company details when private usage selected
	privateuse.click(function() {
		$("#company_details").hide('slow');
        compdetailInputs.attr("disabled" , this.checked);
	});

//////////////////////////////////////////////////////////////////////



////////////////////// Hide show employer details //////////////////////
	
	var employerDetails = $("#employer_details").hide();
	
	var showEmployerDetails = $("#employ_ftm,#employ_ftw,#employ_ptm,#employ_ret,#employ_unemployed,#employ_self,#employ_military,#employ_overseas");
	
	var hideEmployerDetails = $("#employ_student,#employ_housewife");
	
	var previousEmployers = $("#employ_ret,#employ_unemployed");

	var employerInital = showEmployerDetails.is(":checked");
	
	var employerDetailInputs = employerDetails.find("input").attr("disabled", !employerInital);
	

  // toggle employer details dependant on employement type selected
	showEmployerDetails.click(function() {
	
	this.checked ? $("#employer_details").show('slow') : 
$("#employer_details").hide('slow');

    // change text to 'previous employer'
    previousEmployers.is(":checked") ? $("#employer_details legend").text('Previous Employmer details') : 
$("#employer_details legend").text('Employmer details');

employerDetailInputs.attr("disabled", !this.checked);
	});
	
	// hide employer employer details dependant on employement type selected
	hideEmployerDetails.click(function() {
		$("#employer_details").hide('slow');
        employerDetailInputs.attr("disabled" , this.checked);
	});

//////////////////////////////////////////////////////////////////////


////////////////////// Hide show licence office details //////////////////////
	
	var officeDetails = $("#licence_office_detail").hide();
	
	var showofficeDetails = $("#license_nonbg");
	
	var hideofficeDetails = $("#license_newtype,#license_oldtype");
	
	var officeInital = showofficeDetails.is(":checked");
	
	var officeDetailInputs = officeDetails.find("input").attr("disabled", !officeInital);
	

  // toggle office details dependant on licence type selected
	showofficeDetails.click(function() {
	
	this.checked ? $("#licence_office_detail").show('slow') : 
$("#licence_office_detail").hide('slow');


officeDetailInputs.attr("disabled", !this.checked);
	});
	
	// hide office details dependant on licence type selected
	hideofficeDetails.click(function() {
		$("#licence_office_detail").hide('slow');
        officeDetailInputs.attr("disabled" , this.checked);
	});

//////////////////////////////////////////////////////////////////////


////////////////////// Hide show accident box //////////////////////

	var accyes = $("#accidentyes");
	var accno = $("#accidentno");
	var accdetail = $("#accident_details").hide();
	var accInital = accyes.is(":checked");
	var accdetailInputs = accdetail.find("input").attr("disabled", !accInital);
	
	// show accident details
	accyes.click(function() {
	this.checked ? $("#accident_details").show('slow') : $("#accident_details").hide('slow');

    // disable accident details
    accdetailInputs.attr("disabled", !this.checked);
	});
	
	// hide accident details
	accno.click(function() {
	$("#accident_details").hide('slow');
    accdetailInputs.attr("disabled" , this.checked);
	});
	
//////////////////////////////////////////////////////////////////////

////////////////////// Hide show insurance box //////////////////////

	var insuranceyes = $("#insuranceyes");
	var insuranceno = $("#insuranceno");
	var insurancedetail = $("#insurance_comment").hide();
	var insuranceInital = insuranceyes.is(":checked");
	var insurancedetailInputs = insurancedetail.find("textarea").attr("disabled", !insuranceInital);
	
	// show accident details
	insuranceyes.click(function() {
	this.checked ? $("#insurance_comment").show('slow') : $("#insurance_comment").hide('slow');

    // disable accident details
    insurancedetailInputs.attr("disabled", !this.checked);
	});
	
	// hide accident details
	insuranceno.click(function() {
	$("#insurance_comment").hide('slow');
    insurancedetailInputs.attr("disabled" , this.checked);
	});
	
//////////////////////////////////////////////////////////////////////

////////////////////// Hide show mental box //////////////////////

	var mentalyes = $("#mentalyes");
	var mentalno = $("#mentalno");
	var mentaldetail = $("#mental_comment").hide();
	var mentalInital = mentalyes.is(":checked");
	var mentaldetailInputs = mentaldetail.find("textarea").attr("disabled", !mentalInital);
	
	// show accident details
	mentalyes.click(function() {
	this.checked ? $("#mental_comment").show('slow') : $("#mental_comment").hide('slow');

    // disable accident details
    mentaldetailInputs.attr("disabled", !this.checked);
	});
	
	// hide accident details
	mentalno.click(function() {
	$("#mental_comment").hide('slow');
    mentaldetailInputs.attr("disabled" , this.checked);
	});
	
//////////////////////////////////////////////////////////////////////

////////////////////// Hide show conviction box //////////////////////

	var convictionyes = $("#convictionyes");
	var convictionno = $("#convictionno");
	var convictiondetail = $("#conviction_details").hide();
	var convictionInital = convictionyes.is(":checked");
	var convictiondetailInputs = convictiondetail.find("input").attr("disabled", !convictionInital);
	
	// show accident details
	convictionyes.click(function() {
	this.checked ? $("#conviction_details").show('slow') : $("#conviction_details").hide('slow');

    // disable accident details
    convictiondetailInputs.attr("disabled", !this.checked);
	});
	
	// hide accident details
	convictionno.click(function() {
	$("#conviction_details").hide('slow');
    convictiondetailInputs.attr("disabled" , this.checked);
	});
	
//////////////////////////////////////////////////////////////////////


});

// external links
function extLinks() {

	$( "a[@rel='external']" ).click( function(){
		window.open( this.href );
		return false;
	});
	
};



// curved background on feature panel
function roundCorners() {

$("div.roundBox").wrapInner('<div class="boxOut">'+ 
'<div class="bdy">'+ 
'<div class="r">'+ 
'<div class="mid">'+ 
'</div>'+ 
'</div>'+ 
'</div>'+ 
'</div>');


$('div.boxOut').prepend('<div class="hdr">'+
'<div class="r"></div>'+
'</div>')
.append('<div class="ftr">'+
'<div class="r"></div>'+
'</div>');


};
