$(document).ready(function(){
if(typeof eval($("#ccForm").validate) == 'function'){
  	$("#ccForm").validate({
  		rules: {
  			bsp_pay_card_cvv: {
  				required: true,
  				rangelength: [3, 5]
  
  			} /*,
  			bsp_pay_zip: {
  				required: true,
  				rangelength: [5, 10]
  			}*/
  		}
  	});
	}
						   
/*
	$('#ccForm').submit(function(){
		$('input.error, select.error', this).removeClass('error');
		$('span.error', this).remove();
	
		
		$('.required', this).each(function(){
			if ( $(this).is('input') )
			{
				if ( '' == $(this).val() )
				{
					$(this).addClass('error');
				}
			};
			if ( $(this).is('select') )
			{
				if ( '' == $(':selected', this).val() )
				{
					$(this).addClass('error');
				}
			};
		});

		if ( $('#bsp_pay_card_number').val().length != 16 || isNaN(parseInt($('#bsp_pay_card_number').val())) ) 
		{
			$('#bsp_pay_card_number').addClass('error');
//			$('<span class="error">Credit card number must be 16 characters and all numbers</span>')
//			.insertAfter('#bsp_pay_card_number');
		}
		if ( $('#bsp_pay_card_cvv').val().length != 3 ) $('#bsp_pay_card_cvv').addClass('error');
		if ( $('#bsp_pay_zip').val().length < 5 ) $('#bsp_pay_zip').addClass('error');

		if ( $('.error', this).length > 0 ) 
		{
			$('<span class="error">Please complete all fields marked in red below.</span>').insertAfter('#ccForm h3');
			window.location = '#top'; 
			return false;
		}
	});
*/
	
	// populate form
	if ( $('#cc_state').length == 1 ) 
	{
		$('#bsp_pay_state option[value=' + $('#cc_state').val()  + ']').attr('selected', 'selected');
		$('.toggleCC:first').click();
	}
	if ( $('#cc_country').length == 1 ) $('#bsp_pay_card_country option[value=' + $('#cc_country').val()  + ']').attr('selected', 'selected');
	if ( $('#cc_type').length == 1 ) $('#bsp_pay_card_type option[value=' + $('#cc_type').val()  + ']').attr('selected', 'selected');
	if ( $('#cc_month').length == 1 ) $('#bsp_pay_card_expiration_month option[value=' + $('#cc_month').val()  + ']').attr('selected', 'selected');
	if ( $('#cc_year').length == 1 ) $('#bsp_pay_card_expiration_year option[value=' + $('#cc_year').val()  + ']').attr('selected', 'selected');

});
