File: D:/HostingSpaces/TDijk1/erp-apps.eu/wwwroot/ERPApps/media/system/js/toolary-cart.js
comfor = window.comfor || {};
comfor.cart = window.comfor.cart || {};
comfor.cart.changeUnit = function () {
$('.count-up').click(function(){
var textbox = $(this).parents('.count-form-control').find('input[type="text"]');
comfor.cart.updateUnits(textbox, 1);
});
$('.count-down').click(function(){
var textbox = $(this).parents('.count-form-control').find('input[type="text"]');
comfor.cart.updateUnits(textbox, -1);
});
$('.UnitCountControl input[type="text"]').change(function(){
var textbox = $(this);
comfor.cart.updateUnits(textbox, 0);
});
};
comfor.cart.updateTimeout = null;
comfor.cart.updateUnits = function(textbox, difference) {
// clear timeout
clearTimeout(comfor.cart.updateTimeout);
// update value
var value = parseInt(textbox.val(), 10);
if (value <= 0 && difference < 0)
return false;
value += difference;
textbox.val(value);
comfor.cart.updateTimeout = setTimeout(function () {
// run update on the shopping cart using the "Recalculate" button
textbox.parents('.count-form-control').find('.UpdateButton').trigger('click');
}, 500);
};
comfor.cart.registredCustomer = function () {
$('.registred-customer').click(function(){
var box = $('.cart-login');
var box2 = $('.cart-forgotten-password');
var height = box.find('.row').height();
box.css("height",height);
if(box2.hasClass('open')){
comfor.cart.removeOpen(box);
comfor.cart.removeOpen(box2);
}
else{
if(box.hasClass('open')){
comfor.cart.removeOpen(box);
comfor.cart.removeOpen(box2);
}else{
box.addClass('open');
comfor.cart.loginScroll();
}
}
});
if($('.cart-login').find('.error-message').length > 0){
var box = $('.cart-login');
var height = box.find('.row').height();
box.css("height",height);
box.addClass('open');
}
if(window.location.hash == "#login"){
var box = $('.cart-login');
var height = box.find('.row').height();
box.css("height",height);
box.addClass('open');
comfor.cart.loginScroll();
}
};
comfor.cart.forgottenPassword = function () {
$('#show-forgotten').removeAttr('href');
$('#show-forgotten').click(function(){
var box = $('.cart-forgotten-password');
var height = box.find('.row').height();
box.css("height",height);
if(box.hasClass('open')){
comfor.cart.removeOpen(box);
}else{
box.addClass('open');
comfor.cart.removeOpen($('.cart-login'));
}
});
if($('.cart-forgotten-password').find('.error-message').length > 0){
var box = $('.cart-forgotten-password');
var height = box.find('.row').height();
box.css("height",height);
box.addClass('open');
}
if($('.cart-forgotten-password').find('.confirmation-message').length > 0){
var box = $('.cart-forgotten-password');
var height = box.find('.row').height();
box.css("height",height);
box.addClass('open');
}
};
comfor.cart.hideForgotten = function () {
$('#hide-forgotten').removeAttr('href');
$('#hide-forgotten').click(function(){
comfor.cart.removeOpen($('.cart-forgotten-password'));
$('.cart-login').css("height",$('.cart-login').find('.row').height());
$('.cart-login').addClass('open');
});
};
comfor.cart.resizeBoxes = function () {
var box = $('.cart-forgotten-password.open');
var height = box.find('.row').height();
box.css("height",height);
var box2 = $('.cart-login.open');
var height = box2.find('.row').height();
box2.css("height",height);
};
comfor.cart.loginScroll = function () {
var box = $('#login');
$('html, body').animate({
scrollTop: box.offset().top - 20
}, 500);
};
comfor.cart.removeOpen = function (box){
box.removeClass('open');
box.css("height","0px");
};
comfor.cart.isCompany = function () {
if($('.company-fields').hasClass('open')){
$('.company-fields input').removeAttr("disabled");
}else{
$('.company-fields input').attr("disabled","disabled");
}
$('.isCompany input[type="checkbox"]').change(function(){
if($(this).hasClass('checked')){
$(this).removeClass('checked');
$('.company-fields').removeClass('open');
$('.company-fields input').attr("disabled","disabled");
$('.company-fields input').attr("value","");
}else{
$(this).addClass('checked');
$('.company-fields').addClass('open');
$('.company-fields input').removeAttr("disabled");
}
});
if($('.isCompany input[type="checkbox"]').is(':checked')){
$('.isCompany input[type="checkbox"]').addClass('checked');
$('.company-fields').addClass('open');
$('.company-fields input').removeAttr("disabled");
}
};
comfor.cart.isCompanyAjax = function() {
if($('.company-fields').hasClass('open')){
$('.company-fields input').removeAttr("disabled");
}else{
$('.company-fields input').attr("disabled","disabled");
}
if($('.isCompany input[type="checkbox"]').is(':checked')){
$('.company-fields input').removeAttr("disabled");
}else{
$('.company-fields input').attr("disabled","disabled");
}
};
comfor.cart.initSelect = function () {
if($('.select-box').length>0){
$('.select-box select').selectric({});
}
};
comfor.cart.validate = function () {
$('.pux-valid-email').change(function(){
pux.validate.email($(this));
});
$('.pux-valid-required').change(function(){
pux.validate.required($(this));
});
$('.pux-valid-maxMinlength').change(function(){
pux.validate.maxMinlength($(this));
});
$('.pux-valid-maxlength').change(function(){
pux.validate.maxlength($(this));
});
$('.pux-valid-number').change(function(){
pux.validate.number($(this));
});
$('.pux-valid-phone').change(function(){
comfor.cart.validate.phoneNumber($(this));
});
$('.pux-valid-email').focusout(function(){
pux.validate.email($(this));
});
$('.pux-valid-required').focusout(function(){
pux.validate.required($(this));
});
$('.pux-valid-maxMinlength').focusout(function(){
pux.validate.maxMinlength($(this));
});
$('.pux-valid-maxlength').focusout(function(){
pux.validate.maxlength($(this));
});
$('.pux-valid-number').focusout(function(){
pux.validate.number($(this));
});
$('.pux-valid-phone').focusout(function(){
comfor.cart.validate.phoneNumber($(this));
});
$('.pux-valid-ico').focusout(function(){
pux.validate.ICO($(this));
});
$('.pux-valid-dic').focusout(function(){
pux.validate.DIC($(this));
});
};
comfor.cart.validate.phoneNumber = function (element) {
var input = element.find('input');
var val = pux.validate.methods.elementValue(input);
var pattern = /^(\(?(420)\)?)?([ .-]?)([0-9]{3})\3([0-9]{3})\3([0-9]{3})$/;
var type = pattern.test(val);
pux.validate.methods.showSpan(element, type, "phone");
};
comfor.cart.validateReady = function () {
if($('.pux-valid-email input').length>0){
$('.pux-valid-email').each(function(){
if($(this).find('input').val().length>0){
pux.validate.email($(this));
}
});
}
if($('.pux-valid-required input').length>0){
$('.pux-valid-required').each(function(){
if($(this).find('input').val().length>0){
pux.validate.required($(this));
}
});
}
if($('.pux-valid-maxMinlength input').length>0){
$('.pux-valid-maxMinlength').each(function(){
if($(this).find('input').val().length>0){
pux.validate.maxMinlength($(this));
}
});
}
if($('.pux-valid-maxlength input').length>0){
$('.pux-valid-maxlength').each(function(){
if($(this).find('input').val().length>0){
pux.validate.maxlength($(this));
}
});
}
if($('.pux-valid-number input').length>0){
$('.pux-valid-number').each(function(){
if($(this).find('input').val().length>0){
pux.validate.number($(this));
}
});
}
if($('.pux-valid-phone input').length>0){
$('.pux-valid-phone').each(function(){
if($(this).find('input').val().length>0){
comfor.cart.validate.phoneNumber($(this));
}
});
}
if($('.pux-valid-ico input').length>0){
$('.pux-valid-ico').each(function(){
if($(this).find('input').val().length>0){
pux.validate.ICO($(this));
}
});
}
if($('.pux-valid-dic input').length>0){
$('.pux-valid-dic').each(function(){
if($(this).find('input').val().length>0){
pux.validate.DIC($(this));
}
});
}
};
comfor.cart.validateAjax = function () {
pux.validate.hideKenticoError();
if($('.pux-valid-email input').length>0){
$('.pux-valid-email').each(function(){
pux.validate.email($(this));
});
}
if($('.pux-valid-required input').length>0){
$('.pux-valid-required').each(function(){
pux.validate.required($(this));
});
}
if($('.pux-valid-maxMinlength input').length>0){
$('.pux-valid-maxMinlength').each(function(){
pux.validate.maxMinlength($(this));
});
}
if($('.pux-valid-maxlength input').length>0){
$('.pux-valid-maxlength').each(function(){
if($(this).find('input').val().length>0){
pux.validate.maxlength($(this));
}
});
}
if($('.pux-valid-number input').length>0){
$('.pux-valid-number').each(function(){
pux.validate.number($(this));
});
}
if($('.pux-valid-phone input').length>0){
$('.pux-valid-phone').each(function(){
comfor.cart.validate.phoneNumber($(this));
});
}
if($('.pux-valid-ico input').length>0){
$('.pux-valid-ico').each(function(){
if($(this).find('input').val().length>0){
pux.validate.ICO($(this));
}
});
}
if($('.pux-valid-dic input').length>0){
$('.pux-valid-dic').each(function(){
if($(this).find('input').val().length>0){
pux.validate.DIC($(this));
}
});
}
};
comfor.cart.validBtn = function (){
$('.valid-btn').click(function(){
var isCompany = $('.isCompany input[type="checkbox"]').is(':checked');
if(isCompany){
var icoValid = $('.pux-valid-ico').find('.notValid').length<1;
var dicValid = $('.pux-valid-dic').find('.notValid').length<1;
var icoLength = $('.pux-valid-ico').find('input').val().length>0;
var dicLength = $('.pux-valid-dic').find('input').val().length>0;
if ($('.no-dph input[type="checkbox"]').is(':checked')){ dicValid = true; dicLength = true;}
//console.log(isCompany + " | " + icoValid + " | " + dicValid);
if(icoValid && dicValid && icoLength && dicLength){
return true;
} else{
alert("Musíte vyplnit údaje pro firmu");
return false;
}
}
});
};
comfor.cart.init = function () {
comfor.cart.changeUnit();
comfor.cart.registredCustomer();
comfor.cart.hideForgotten();
comfor.cart.forgottenPassword();
comfor.cart.isCompany();
comfor.cart.initSelect();
comfor.cart.validate();
comfor.cart.validateReady();
comfor.cart.validBtn();
};
comfor.cart.load = function () {
};
comfor.cart.resize = function () {
comfor.cart.resizeBoxes();
};
comfor.cart.scroll = function () {
};
comfor.cart.beforeAjax = function () {
};
comfor.cart.ajax = function () {
comfor.cart.changeUnit();
comfor.cart.registredCustomer();
comfor.cart.hideForgotten();
comfor.cart.forgottenPassword();
comfor.cart.isCompany();
comfor.cart.isCompanyAjax();
comfor.cart.initSelect();
comfor.cart.validate();
comfor.cart.validateAjax();
comfor.cart.validBtn();
};