// Added by Guy on 25/7/11, this is  corection hack for the first step of the check out, it does two things
// 1 unchecks the same billing adress and shows the billing adress block
// checks for empty adress filed on submit, stops submition and adds a waring block at the top of the page.
$("document").ready(function(){						
if( $('form#block-customerinfo') ){
	
	 //$('#hndl-show-billing-address').trigger('click');
	 $("#hndl-show-billing-address").removeAttr("checked");
	 $('#block-billing-address').css("display","block");
	 
	 $("form#block-customerinfo").submit(function(event){
												
		if( !$('[name=shipping_address[address]]').val() || ($('#block-billing-address').css("display")=='block' && !$('[name=billing_address[address]]').val()) )
			{	
			event.preventDefault();
			if($(".error_message:contains('Please fill in your address')").length==0){
			$("form#block-customerinfo input[value=process_customer_info]").after($("<div id='message-block' class='error_block' name='error_block'><span class='error_flag'>Error: </span><span class='error_message'>Please fill in your address</span></div>"));
				  }
				    var target_offset = $("#error_block").offset();
      			  var target_top = target_offset.top;

			//$.ajex('https://www.a51.ca/skateshop/checkout/#error_block');
			$('html, body').animate({scrollTop:target_top}, 500);

			//$('[name=shipping_address[address]]').after('Please fill in your adress');
			}
		else{$("form#block-customerinfo").trigger("submit");}
												  });
	 }
	 
						});
