var current = 1;

var INT6X = {
	"INT60" : "INT60",
	"INT61" : "INT61",
	"INT62" : "INT62",
	"INT63" : "INT63",
	"INT64" : "INT64",
	"INT65" : "INT65"
}
var NAT6X = {
	"NAT60" : "NAT60",
	"NAT61" : "NAT61",
	"NAT62" : "NAT62",
	"NAT63" : "NAT63",
	"NAT64" : "NAT64",
	"NAT65" : "NAT65"
}
var LVXX = {
	"LV26" : "LV26",
	"LV24" : "LV24",
	"LV23" : "LV23",
	"LV22" : "LV22",
	"LV21" : "LV21",
	"LV11" : "LV11"
}


$(document).ready(function() {

	// remove card holder
	$('div.remove-holder').children('a').click(function() {
		$(this).parent('div').parent('div').remove();
		return false;
	})

	// handle card types radio buttons
	$("input[name='card_type']").click(function() {
		$('div.card-holders').show();
		$('div.card-holders a.hint-trigger,div.card-holders div.hint-wrap,div.card-holders div.hint-container').hide();
		$(".card-codes").removeOption(/./);

		if ($("input[name='card_type']:checked").val() == 1)
		{
            $("#total_limit").rules("remove", "required");
            $("#total_limit").removeClass("error");

			$("div.card-holders .card-codes").addOption(LVXX, false);
			$('div.card-holders div.limit').hide();
			
			$('div.card-holders a.debet').show();

			$('#total_limit').attr("disabled", true);
		}
		else 
		{
		    $("#total_limit").rules("add", "required");

			$('div.card-holders div.limit').show();

			$('#total_limit').removeAttr("disabled");

			if ($("input[name='card_type']:checked").val() == 2)
			{
				$("div.card-holders .card-codes").addOption(NAT6X, false);
				$('div.card-holders a.credit').show();
			}
			else if ($("input[name='card_type']:checked").val() == 3)
			{
				$("div.card-holders .card-codes").addOption(INT6X, false);
				$('div.card-holders a.routex').show();
			}            
		}
	});


	$('#send_mail').click(function() {
		if ($('#send_mail').attr('checked'))
		{
		    $("#bill_email").rules("remove", "required");
			$(this).siblings('.hint-wrap').children('.hint-container').css('display','block');
		}
		else 
		{
		    $("#bill_email").rules("add", "required");
			$(this).siblings('.hint-wrap').children('.hint-container').css('display','none');
		}
	});

	// toggle fields info box
	$('.hint-trigger').click(function() {
		$(this).next('.hint-wrap').css('display', 'inline');
		$(this).next('.hint-wrap').children('.hint-container').toggle();
		return false;
	});

	$('.hint-container').click(function() {
		$(this).hide();
	})

    // validate signup form on keyup and submit
	$('#application-form').validate({
		rules: {
			company_name: "required",
            representative: "required",
            reg_no: {
                required: true,
                digits: true,
                minlength: 11,
                maxlength: 11
            },
            legal_adress: "required",
            legal_adress_post_code: {
                required: true,
                digits: true,
                minlength: 4,
                maxlength: 4
            },
            postal_adress: "required",
            postal_adress_post_code: {
                required: true,
                digits: true,
                minlength: 4,
                maxlength: 4
            },
			phone: {
                required: true,
                digits: true,
                minlength: 8,
                maxlength: 8
            },
            fax: {
                required: false,
                digits: true,
                minlength: 8,
                maxlength: 8
            },
			email: {
				required: false,
				email: true
			},
			holder_name1: "required",
			card_code1: "required",
			total_limit: {
				required: true,
				digits: true
			},
			bill_email: {
				required: true,
				email: true
			}
		}
	});

});

