jQuery(document).ready(function($){
    $('.lightbox-link').fancybox();
    $('#bookingform').submit(function(){
        if (!$('#bookingform #agreed').attr('checked') ) {
            alert ("Please make sure you agree with the terms & conditions!" );
        } 
    });
    $('#bookingform').validate({
		messages: {
			agreed: {
				required: '*'
			}
		}
	});
    
    $('.depot-location').click(function(){
       var id = $(this).find('.depotId').val();
       $("#depot-map").load('/index.php?task=loadMap&num='+id);
    });

    $('.depot-location').mouseover(function(){
        $(this).addClass('depot-hovered');
    });
    $('.depot-location').mouseout(function(){
        $(this).removeClass('depot-hovered');
    });
    $('#pdate').datepicker({minDate: new Date(), dateFormat: 'dd-mm-yy', onClose: function(dateText, inst){
        var dateResult = dateText.split('-');
        $( "#rdate" ).datepicker( "option", "minDate", new Date(dateResult[2], (dateResult[1]-1), dateResult[0]));
    }});
    $('#rdate').datepicker({dateFormat: 'dd-mm-yy'});

    $('#searchMemberForm').submit(function(){
        $('#memberResults').load('index.php', {task:'searchMember', criteria:$('#criteria').val(), value:$('#searchValue').val()});
        return false;
    });

    $('.copyDetailButton').live('click', function(){
        var customerId = $(this).parent().parent().attr('id');
        $.post('index.php', {task:'getCustomerDetails', custId:customerId}, function(data){
            if (data!='') {
                var result = $.parseJSON(data);
				console.log(result);
                $('#fname').val(result.fname);
                $('#lname').val(result.lname);
                $('#compname').val(result.compname);
                $('#dummy2').val(result.dummy2);
                $('#phone').val(result.phone);
                $('#fax').val(result.fax);
                $('#email').val(result.email);
                $('#address').val(result.address);
                $('#city').val(result.city);
                $('#state').val(result.state);
                $('#zip').val(result.zip);
            }
        });
        return false;
    });

    $('#paymentType').change(function(){
        if ($(this).val() == 'Credit Card - Prepaid') {
            $('#submitBtn').val('Secure Payment >>');
        } else {
            $('#submitBtn').val('Submit');
        }
    });
    $('.promo').cycle({
        fx:     'fade',
        timeout: 3000
    });
});

function validateForm() {
    if ($('#bin').val() == '') {
        alert('Bin Size is required!');
        return false;
    }
}

function CopyBillingToDelivery() {
    if(document.form1.same_as_billing.checked==true){
        document.form1.D_new_address.value = document.form1.address.value;
        document.form1.D_new_city.value = document.form1.city.value;
        document.form1.D_new_state.value = document.form1.state.value;
        //document.form1.D_new_zipcode.value = document.form1.zip.value;
        return false;
    }
}

function CopyDeliveryToReturn() {
    if(document.form1.same_as_delivery.checked==true){
        document.form1.R_new_address.value = document.form1.D_new_address.value;
        document.form1.R_new_city.value = document.form1.D_new_city.value;
        document.form1.R_new_state.value = document.form1.D_new_state.value;
        document.form1.R_new_zipcode.value = document.form1.D_new_zipcode.value;
        return false;
    }
}

