omw_override_selectBoxIt = true;
function callbackShoppingCart( cart ) {

	if ($(".numItens").length > 0) $(".numItens").html(cart.totalItems)
	if ($(".totalInCart").length > 0) $(".totalInCart").html(cart.totalPrice)
	
	
	
	// resume cart
	if ($("#omw_resume_cart").length > 0) {
		var cartUrl = cart.options.url;
		var cartTrad = cart.options.trad;
		
		var html ='<ol id="mini-cart-list" class="mini-products-list">';
		$.each(cart.items, function() {
			
			html +='<li class="item odd">';
			html +='<a class="product-image" title="'+(this.descricao)+'" href="'+this.url+'">';
			html +='<img width="50" height="50" alt="'+(this.descricao)+'" src="'+this.imagem+'"></a>';
			html +='</a>';
			html +='<div class="product-details">'
			
			html +='<p class="product-name">';
			html +='<a href="'+this.url+'">'+(this.descricao)+'</a>'
			html +='</p><strong>'+this.qtd+'</strong>x<span class="price">'+this.valor+'</span>'
			
			
			html +='</div>';
			html +='</li>';
			
		});
		html +="</ol>";
		
		html +='<div class="actions">'
		html +='<button class="button btn-inline" onclick="location.href=\'/'+cartUrl+'\'" title="'+cartTrad+'" type="button"><span>'
		html +='<span>'+cartTrad+'</span>'
		html +='</span></button></div>'
		
		$("#omw_resume_cart").html(html);
	}	
	
}



$(document).ready(function() {

	//////////////////////////////
    // CURRENCIES
    //////////////////////////////
    if ($("#omw-moneyManager").length>0) {
		$("#omw-moneyManager").click(function() {
			$("#omw-moneyPanel").toggle();
		} );
		$("#omw-moneyPanel").bind( "clickoutside", function(event){
				var target = $(event.target).attr("id") || "body";
				if (target != "omw-moneyManager" && target!="selectedMoney") $("#omw-moneyPanel").fadeOut("fast");
		});
	}

	//////////////////////////////
    // ZOOM IMAGE GALERIES
    //////////////////////////////
    $("a[rel^='prettyPhoto']").prettyPhoto({autoplay_slideshow: false, overlay_gallery: false, social_tools:false, deeplinking: false, theme:'pp_default', slideshow:5000});


    //////////////////////////////
    // BANNER ROTATOR
	//////////////////////////////
	$('.banner-rotator').bannerRotator({
			effect:'fade',
			navButtons:'large',
			thumbnails:'bullet',
			playButton:false,
			timer:'none',
			tooltip:'none',
			cpanelAlign:'bottomRight',
			responsive:true
			
	});


    //////////////////////////////
    // BEGIN: OMW FORM METATAGS HANDLER
	//////////////////////////////
    $.validator.messages.required = "";
	$.validator.messages.number = "";
	$.validator.messages.email = "";
	$.validator.messages.remote = "";
	$.validator.messages.equalTo = "";
	

	 $("#form_debito_direto").validate({
			  errorClass:"errorValidation",
			  errorElement:"span",
			  focusInvalid: true,
			  highlight: function(element, errorClass, validClass) {
					$(element).addClass("errorClass");	 
			  },
			  unhighlight: function(element, errorClass, validClass) {
					$(element).removeClass("errorClass");
			  },
			  
			  submitHandler: function(form) { 
					

			  		$.ajax({
					        url: '../ajax.requests.php',
					        type: 'POST',
					        data: "action=activateSepa&number="+$("#smscode").val(),
							dataType:"json",
					        success: function (response) {
					     //        	swal({
						    //         	title:"",
										// text: "Este email já se encontra subcrito... Introduza um novo email.",
										// type: "warning",
										// confirmButtonText: "Ok"});

										swal({   
											title: "",   
											text: "Introduza o código de autorização que recebeu no seu telemóvel:<br><input id='sepaauth' maxlength=6 type='text' style=' display: table !important;margin: 0 auto;text-align: center;width: 102px;margin-top:25px' value=''><br>",   
											type: "warning",   
											showCancelButton: true,   
											confirmButtonColor: "#1871E9 !important",  
											cancelButtonText: "Cancelar",   
											confirmButtonText: "Confirmar", 
											html:true,  
											closeOnConfirm: false }, 
											function(status){ 
												if (status) {
														$.ajax({
														        url: '../ajax.requests.php',
														        type: 'POST',
														        data: "action=validateSepa&auth=" + $("#sepaauth").val()+"&" + $(form).serialize(),
																dataType:"json",
														        success: function (response2) {
														        	if (response2.status=="1") {
														        			swal({
																            	title:"",
																				text: "<b>A sua adesão ao pagamento por débito direto foi efetuado com sucesso</b>.<br>Irá receber no seu email o comprovativo desta adesão.",
																				html:true,
																				type: "success",
																				confirmButtonText: "Ok"},
																				function(){
																					location.href="/";
																				});



														        	}
														        	else {
														        		swal({
																            	title:"",
																				text: "<b>Código de autorização inválido</b><br>Para autorizar o débito direto introduza o código recebido no seu telemóvel.",
																				html:true,
																				type: "error",
																				confirmButtonText: "Ok"});
														        	}
														        },
														        error: function () {
					       
															        }
															    }); 
												} // end status
											});
								
					        },
					        error: function () {
					       
					        }
					    }); 


					// swal({   
					// 	title: "",   
					// 	text: "Introduza o código de autorização<br><input maxlength=6 type='text' style=' display: table !important;margin: 0 auto;text-align: center;width: 102px;margin-top:25px' value=''><br>",   
					// 	type: "warning",   
					// 	showCancelButton: true,   
					// 	confirmButtonColor: "#1871E9 !important",  
					// 	cancelButtonText: "Cancelar",   
					// 	confirmButtonText: "Confirmar", 
					// 	html:true,  
					// 	closeOnConfirm: false }, 
					// 	function(){ 
							
					// 	});

					return
				
			  }
		});


	$("form.omw_form").each(function() {
		
		 $(this).validate({
			  errorClass:"errorValidation",
			  errorElement:"span",
			  focusInvalid: true,
			  highlight: function(element, errorClass, validClass) {
					$(element).addClass("errorClass");	 
			  },
			  unhighlight: function(element, errorClass, validClass) {
					$(element).removeClass("errorClass");
			  },
			  
			  submitHandler: function(form) { 
					var humanValidator= $(form).children().find("input[id='humanValidator']").attr("rel").split(",");
					var value1 = parseInt(humanValidator[0]);
					var value2 = parseInt(humanValidator[1]);
					var response = parseInt($(form).children().find("input[id='humanValidator']").val());
					
					if ( value1 + value2 == response ) {
						$(form).find("input.submitbtn").fadeOut("fast", function() {
							$(form).append("<img src='http://www.omeuwebsite.com/images/indicator.gif'>");
							form.submit();
						})
						
						
						return;
					}
					else {
						$(form).children().find("input[id='humanValidator']").focus()
						return false;
					}
				
			  }
		});
	});
	// END: OMW FORM METATAGS HANDLER
	
	// BEGIN: OMW BRANDS HANDLER
	if ($("#omw-brands-slider").length  > 0) {
		var logoSlider = $('#omw-brands-slider').bxSlider({
				  pager:true,
				  controls:false,
				  auto:true,
				  minSlides: 5,
				  maxSlides: 5,
				  slideWidth: 100,
				  autoStart:true
		});
	}
	// END: OMW BRANDS HANDLER
	
	
	//////////////////////////////
    // CUSTOM
	//////////////////////////////
    //$(".leftColumn").equalHeights($(".maincontent").height() - 300); 
    
    
	 $('ul.mlddm > li > ul > li > ul').parent().children("a").addClass("hsub")
	 $('ul.mlddm > li > ul > li > ul > li > ul').parent().children("a").addClass("hsub")
	 
	 // MARCA O MENU PRINCIPAL COM CURRENT
	 $('ul.mlddm .current').parent().parent().parent().children("a").addClass("current")
	 //$('ul.mlddm .current').parent().parent().parent().parent().parent().children("a").addClass("current")

	function isValidEmailAddress(emailAddress) {
		var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
		return pattern.test(emailAddress);
	};

	$(".newsletterBox form").submit(function(e){
        e.preventDefault();
        if( !isValidEmailAddress( $(this).find("[name='email']").val() ) ) {
        	swal({
            	title:"",
				text: "Por favor introduza um email válido...",
				type: "warning",
				confirmButtonText: "Ok"
			});
        }else{
	        $.ajax({
		        url: 'newsletterAjax.php',
		        type: 'POST',
		        data: { email: $(this).find("[name='email']").val()} ,
		        success: function (response) {
		            if(response=="0"){
		            	swal({
			            	title:"",
							text: "Este email já se encontra subcrito... Introduza um novo email.",
							type: "warning",
							confirmButtonText: "Ok"
						});
		            }else if(response=="1"){
		            	swal({
			            	title:"",
							text: "Obrigado por subscrever as nossas newsletters!",
							type: "success",
							confirmButtonText: "Ok"
						});
		            }
		        },
		        error: function () {
		            swal({
		            	title:"",
						text: "Não foi possível subscrever o seu email... Tente novamente.",
						type: "error",
						confirmButtonText: "Ok"
					});
		        }
		    }); 
	    }
    });

    	
});	

