function checkForm(loginStatus){
	    var status=true;
    	var pattern = /^[A-Z0-9._%-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,6}$/i;
		var postcode=/[1-9]\d{5}(?!\d)/;
	    if($('#firstname').val().length<3 ||$('#firstname').val().length>32 ){
			     $('#firstname').next().html('First Name must be greater than 3 and less than 32 characters!');
				  status=false;
			}
			else{
				$('#firstname').next().html('');
				}
		if($('#lastname').val().length<3 ||$('#lastname').val().length>32){
			       $('#lastname').next().html('Last Name must be greater than 3 and less than 32 characters!');
				    status=false;
		  } 
		  else{
			  $('#lastname').next().html('');
			  }
		 
           
		  if($('#telephone').val().length<3 ||$('#firstname').val().length>32){
			  $('#telephone').next().html('Telephone must be greater than 3 and less than 32 characters!');
			   status=false;
		  }
		  else{
			   $('#telephone').next().html('');
			  }
           
	  if($('#address_1').val().length<3||$('#address_1').val().length>128){
		      $('#address_1').next().html('Address  must be greater than 3 and less than 128 characters!');
			  status=false;
		  }
	  else{
		  $('#address_1').next().html('');
 		  }
		  if($('#city').val().length<3||$('#city').val().length>128){
			  $('#city').next().html('City must be greater than 3 and less than 128 characters!');
			  status=false;
			  }
	      else{
		       $('#city').next().html('');
			   
 		   }	
		   if($('#postcode').val().length<1){
		       $('#postcode').next().html('Post Code does not appear to be valid!');
		       status=false;
		   }
		   else{
		     $('#postcode').next().html('');
		   }
		 if($('#zone_id').val()=='FALSE'){

			  $('#zone_id').next().html('Please select a region / state!'); 
			   status=false;
		 }
		 else{
			  $('#zone_id').next().html(''); 
			 }
             
            if(!loginStatus){	  	

			      if($('#pass').val().length<3||$('#pass').val().length>128){

					$('#pass').next().html('Password must be greater than 3 and less than 128 characters!'); 
					 status=false;
				 }
				 else{
				   $('#pass').next().html(''); 
				 }
				 
				 if($('#confirm').val().length<3||$('#confirm').val().length>128){		 
					 $('#confirm').next().html('confirm password must be greater than 3 and less than 128 characters'); 
					 status=false;
				 }
				 else{
				   $('#confirm').next().html(' ');
				 }
				 if($('#pass').val()!=$('#confirm').val()){
				   $('#confirm').next().html('Confirm password is incorrect!'); 
					 status=false;
				 }
				 else{
				   $('#confirm').next().html();
				 }
							
		

     }
    if($('#chinabank').attr('checked')){
		var patterns= /^[0-9]{1,}$/;
    var cardname= /^[A-Za-z\s]+$/;
	  if($('#cc_number').val().length!=16 ){//卡号不是16位
			     $('#cc_number').next().html('Not a correct credit cart number!');
				  status=false;
			}
			
	 else {
			
			 if(!$('#cc_number').val().match(patterns) )//卡号不全是数字
			 {
			      $('#cc_number').next().html('Only number!No space!');
				    status=false; 
		     }
		    else//正确
			 {
			 
		 	     $('#cc_number').next().html('');
			 
		     }

		  }
		
	
	 if($('#cc_cvv2').val().length!=3 )//验证码不是三位
	        {
			     $('#cc_cvv2').next().html('Not a correct Card Security Code!');
				  status=false;
			}
			
	  else  {  
				
				if(!$('#cc_cvv2').val().match(patterns) )//验证码不是数字
				
				  {
			      $('#cc_cvv2').next().html('Only number');
				    status=false; 
		           }
		      else{//正确
			 
			   $('#cc_cvv2').next().html('');
			 
		          }
		
		
		  }	
		  
		
		 if(!$('#cc_owner').val().match(cardname)){//持卡人姓名填写不符合规定
			      $('#cc_owner').next().html('Only english letters and space!');
				    status=false; 
		  }
		  else{//正确
			 $('#cc_owner').next().html('');
			 
		  } 

    }

	 if(!loginStatus){
				  if(!$('#email').val().match(pattern) ){
			      $('#email').next().html('E-Mail Address does not appear to be valid!');
				    status=false; 
		  }
		  else{
			 $.ajax({
					type: 'post',
					url: 'index.php?route=account/create/checkEmail',
					dataType: 'json',
					async:false,
					data: $('#checkoutMsg :input'),
					success: function (data) {
						 $('#rel').attr('value',data.success);				
			      }
				  });
			  var result=$('#rel').val();
			  
			  if(result=="true"){
				  
			    $('#email').next().html(' ');
			  }
		      else{
				   
			   $('#email').next().html('E-mail is also registered');
			    status=false; 
			  }

		  }	

     }
	
	  if(status){
		  if(!loginStatus){
		   $.ajax({
					type: 'post',
					url: 'index.php?route=account/create/regist'
			});
	     }
		   checkFormSubmit();
		}
		else{
				
			return;
		}		

}

 function checkFormSubmit(){
	 
	       if($('#chinabank').attr('checked')){
                  chinabankSubmit();
		   }else{
			   $('#pay_form').submit();
		   }
		 
 }
 function chinabankSubmit(){
    $('#submit').hide();
	              $.ajax({
						type: 'POST',
						url: 'index.php?route=checkout/guest_step_3/index',
						data: $('#checkoutMsg :input'),
						dataType: 'json',
						beforeSend: function() {							
											$('#info').remove();
											$('#chinabank_pay').before('<div class="wait" id="info" style="width:480px;"><img src="catalog/view/theme/default/image/loading_1.gif" alt="" />Please wait! </div>');
										},
						success: function(data) {
											if(data.status){
											   $('#info').html(data.error);;
											}else{
																  
											   if(data.success){
												  window.location.href=data.url;	
												}else{
												  $('#info').html(data.error_info);
												}

												$('#submit').show(); 
											}

											/*
											if(data.status){
											   $('#info').html(data.error);;
											}
											else{
												$('#chinabank_pay').append(data.amount);
												  $.ajax({
														type: 'POST',
														url: 'index.php?route=payment/chinabank/send',
														data: $('#chinabank_pay :input'),
														dataType: 'json',		
														success: function(data) {
																  
																   if(data.success){
																	  window.location.href=data.url;	
																	}	
																	else{
																		
																	  $('#info').html(data.error_info);;
																	}
																	$('#submit').show(); 
																}
																
															
													});
											}
											*/
								  
								}
								
							
					});
 
 
 }

function calculatePrice(obj){
          var arr=obj.value.split('_');
		  var priceValue=arr[0];
		  var listPrice=arr[1];
		  var realPrice=arr[2];
		  var save=arr[3];
		  var subPrice=arr[4];
		  var size=arr[5];
		  var framePrice=0;
		  var optionArr=obj.id.split('*');
          $('.fpricechar').each(function(){
			    var idArr=this.id.split(' ');
				var idStr=idArr.join('_');
		            if(idStr==(optionArr[2])){
					           $(this).show();
					}else{
					            $(this).hide();
					}
		  
		  
		  });
           if($('#frame_id').length>0){
			      var frameId=$('#frame_id').val();
				  var framePriceInputId=optionArr[2]+'_'+frameId;
				  framePrice=$('#'+framePriceInputId).val();
				  var framePirceArr=$('#'+framePriceInputId).attr('name').split('_');
                  $('#frameOption').attr('value',framePirceArr[1]+'_'+framePirceArr[2])
				  $('#framePriceText').html('Frame Price:'+framePirceArr[0]);
		   
		   }else{
		          framePrice=0;
		   }
		  $('#listprice').html('List Painting Price:<span class="lp_p">'+listPrice+'</span>');
		  $('#realPrice').html('Painting Price:'+realPrice);
		  $('#lpsize').html('Painting Size:'+size+' inches');
		  $('#lpsave').html('Save:'+subPrice+'('+save+')');
		  var totalPrice=parseFloat(framePrice)+parseFloat(priceValue);
		  $.ajax({
			type: 'post',
			url: 'index.php?route=product/product/formatCurrency',
			dataType: 'html',
			data: 'price='+totalPrice,
			success: function (data) {	
		         $('#pinfo_tprice').html('Total Price:'+data);
				 $('#option_id').remove();
				 $('#checkout').append('<input type="hidden" name="option['+optionArr[0]+']" value="'+optionArr[1]+'" id="option_id">');
			}			
		});



} 

function addFrame(frameId){
	$('#art_content').hide();
	var price=0;
	var key=0;
	$('.radio').each(function(){
	        if(this.checked){
			        var arr=this.value.split('_');
					var idArr=this.id.split('*');
			        price=arr[0];
					key=idArr[2];
			}
	
	});
    $.ajax({
			type: 'post',
			url: 'index.php?route=product/product/addFrame',
			dataType: 'json',
			data: 'id='+frameId+'&price='+price+'&product_id='+$('#product_id').val()+'&key='+key,
		    beforeSend:function(){
				 $('#frametab').hide();
				$('#load').show();
			},
			success: function (data) {
			
				$('#framePrice').attr('value',data.price);
				$('#framename').html('Frame Name:'+data.name+'<span id="remove_f"><a onclick="removeFrame()">Remove Frame</a></span>');
                $('#framePriceText').html('Frame Price:'+data.priceText);
			    $('#pinfo_tprice').html('Total Price:'+data.total);
				$('#frame_id').remove();
				$('#checkout').append('<input type="hidden" name="frame_id" value="'+data.id+'" id="frame_id">');

				 $('#frame_option_id').remove();
				 $('#checkout').append('<input type="hidden" name="frameOption" value="'+data.option_id+'_'+data.option_value_id+'" id="frameOption">');
				$('#frameP').show();
				$('#remove_f').show();
				$('#load').hide();
				showFramePic(data);
			}			
		});
}

function showFramePic(data){
           $('#left_1').html('<img src="'+data.left_1+'">');
		   $('#top').attr('style',' width:'+data.width+'px;height:38px;background: url("'+data.top+'") repeat scroll 0% 0% transparent;');
		   $('#right_1').html('<img src="'+data.right_1+'">');
		   $('#left_2').attr('style',' height:'+data.height+'px;width:38px;background: url("'+data.left_2+'") repeat scroll 0% 0% transparent;');
		   $('#pimg').html('<img src="'+data.product_image+'">');
		   $('#right_2').attr('style','height:'+data.height+'px;width:38px; background: url("'+data.right_2+'") repeat scroll 0% 0% transparent;');
		   $('#left_3').html('<img src="'+data.left_3+'">');
		   $('#bottom').attr('style',' width:'+data.width+'px;height:38px;background: url("'+data.bottom+'") repeat scroll 0% 0% transparent;');
		   $('#right_3').html('<img src="'+data.right_3+'">');
		   $('#frametab').show();

}

function removeFrame(){
	       var price=0;
			$('.radio').each(function(){
					if(this.checked){
							var arr=this.value.split('_');
							price=arr[2];
					}
			
			});
			$('#pinfo_tprice').html('Total Price:'+price);
            $('#frame_id').remove();
			$('#frame_option_id').remove();
            $('#frameP').hide();
			$('#remove_f').hide();
			$('#frametab').hide();
			$('#art_content').show();


}

