

function validateHeaderEmail(email) {
var emailReg = /^([\w-+\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(emailReg.test(email) && email.length > 0 && email.length < 51) {
return true; 
} else {
return false; 
}
}
function validateHeaderPassword(pw) {
if(pw.length > 0 ) {
return true; 
} else {
return false; 
}
}
function ajaxMinicart(highlightData, notAvailable) {
jQuery.ajax({
url: 'https://www.bruna.nl/INTERSHOP/web/WFS/Bruna-B2C-Site/nl_NL/-/EUR/ViewCart-MiniCart',
type: 'POST',
dataType: 'html',
success : function(data) {
$j("#minicart").html(data);
if(highlightData) {
for(var i = 0; i < highlightData.length; i++) {
$j(".minicart_" + highlightData[i].productSKU).addClass("highlight");
}
}
if(notAvailable) {
var errorMsg = '<p class="login__error">niet meer leverbaar';
for(var i = 0; i < notAvailable.length; i++) {
errorMsg += "<br/>- " + notAvailable[i].productName;
}
errorMsg += "<hr/></p>";
$(errorMsg).insertAfter($j("#minicart hr").first());
}
$j(".minicart BUTTON.close").click(function() {
$j("#minicart").addClass("hidden");
$("body").off("click.minicart");
});
} 
});
}
$j(document).ready(function() {
if ($j('.header .header__text-ubr .text-ubr').length != 0) {
var list = $j(".header .header__text-ubr .text-ubr").toArray();
var elemlength = list.length;
var randomnum = Math.floor(Math.random()*elemlength);
var randomitem = list[randomnum];
$j(randomitem).find(".ubrimage").each(function() {
$j(this).attr("src",$j(randomitem).attr("data-deferredubr"));
});
$j(randomitem).css("display", "block");
}
$j("input[id=header-email]").keypress(function(e) {
if (e.which == 13)
{
var b = validateHeaderEmail($j("input[id=header-email]").val());
var p = validateHeaderPassword($j("input[id=header-password]").val());
if (b == true) {
$j("input[id=header-email]").parent("DIV.form-group").removeClass("has-error"); 
if (validateHeaderPassword($j("input[id=header-password]").val())) $j(".login .login__error").hide();
} else {
$j("input[id=header-email]").parent("DIV.form-group").addClass("has-error"); 
$j(".login .login__error").show();
}
if (p == true) {
$j("input[id=header-password]").parent("DIV.form-group").removeClass("has-error");
if (validateHeaderEmail($j("input[id=header-email]").val())) $j(".login .login__error").hide();
} else {
$j("input[id=header-password]").parent("DIV.form-group").addClass("has-error"); 
$j(".login .login__error").show();
} 
}
});
$j("input[id=header-email]").change(
function(e) {
var b = validateHeaderEmail($j(this).val());
if (b == true) {
$j(this).parent("DIV.form-group").removeClass("has-error"); 
if (validateHeaderPassword($j("input[id=header-password]").val())) $j(".login .login__error").hide();
} else {
$j(this).parent("DIV.form-group").addClass("has-error"); 
$j(".login .login__error").show();
} 
return false; 
}
);
$j("input[id=header-password]").change(
function(e) {
var p = validateHeaderPassword($j(this).val());
if (p == true) {
$j(this).parent("DIV.form-group").removeClass("has-error");
if (validateHeaderEmail($j("input[id=header-email]").val())) $j(".login .login__error").hide();
} else {
$j(this).parent("DIV.form-group").addClass("has-error"); 
$j(".login .login__error").show();
}
return false;
}
);
// When clicking on the link the onblur moves the link while the onclick event is published on the
//location where link was rendered before.
$("div.login a.login__forgotten, div.login__new-customer a, button[type=submit]").mousedown(function(e) {e.preventDefault();});
$j(".login__button-group BUTTON").click(function() {
if (!(validateHeaderEmail($j("input[id=header-email]").val()) && validateHeaderPassword($j("input[id=header-password]").val()))) return false;
});
$j(".header__shopping-cart #shopping-cart").click(function() {
ajaxMinicart();
}); 
$j("UL.menu__list LI.menu__list__item ").each(function() {
if($j(this).children("DIV.list__item__flyout").length != 0) {
$j(this).children("a").removeAttr("href");
}
});
});