/**
 * cvfind.js: General Javascript Library for VirtueMart Frontpage
 *
 * @package    VirtueMart
 * @subpackage Javascript Library
 * @authors    Max Milbers, Abhishek Das
 * @copyright  Copyright (c) 2014-2018 VirtueMart Team. All rights reserved.
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
var Virtuemart=window.Virtuemart||{};!function(u){Virtuemart.findContainers=function(t){var e,r=u(t.currentTarget).closest(".product-field-display"),n=r.length&&0<r.closest(".product-listing").length?"product-item":"vm-productdetails",i=Virtuemart.containerSelector;return r.closest(".product-comparison-page").length&&(n="compare-item-inner"),u(document).find("."+n).length||(n="product-container"),r.length?(Virtuemart.container=r,Virtuemart.containerSelector="."+n,(e=Virtuemart.container.closest(Virtuemart.containerSelector)).length||(Virtuemart.containerSelector=i||Virtuemart.containerSelector,n=Virtuemart.containerSelector.substring(1),(e=Virtuemart.container.closest(n)).length)?(Virtuemart.container=e,r):(console.log("CV: Could not find product-container "+i,r),!1)):(console.log("CV: Could not find parent container product-field-display"),!1)},Virtuemart.cvFind=function(t){t.preventDefault();var e=[],r=Virtuemart.findContainers(t),n=!1;u(r).find(".cvselection:checked").each(function(){e[e.length]=u(this).val(),n=!0}),n||u(r).find(".cvselection").each(function(){e[e.length]=u(this).val()});var a=0,o=0,c=0;for(u(this).prop("url",t.data.variants[0][0]),i=0;i<e.length;a++){for(a=0;a<t.data.variants.length;a++)for(o=c=0;o<=e.length&&e[o]==t.data.variants[a][o+1];o++)if(++c==e.length-i){var l=t.data.variants[a][0].replace(/amp;/g,"");return u(this).attr("url",l),u(this).val(l),u(this).data("reload")?(Virtuemart.isUpdatingContent=!0,window.top.location.href=l,!1):l}i++}return!1},Virtuemart.avFind=function(t){t.preventDefault();var e=Virtuemart.findContainers(t),r=!1,n=!1;return console.log(e),u(e).find(".avselection:checked").each(function(){n=!0,void 0!==(r=u(this).attr("url"))&&!1!==r||(r=u(this).val()),u(this).val(r)}),n||u(e).find(".avselection").each(function(){void 0!==(r=u(this).attr("url"))&&!1!==r||(r=u(this).val()),u(this).val(r)}),r}}(jQuery);