// Last edit: Tue, 19 Apr 16 13:36:40 -0400
var rfsn_ajax={x:function(){if("undefined"!==typeof XMLHttpRequest)return new XMLHttpRequest;for(var e="MSXML2.XmlHttp.6.0 MSXML2.XmlHttp.5.0 MSXML2.XmlHttp.4.0 MSXML2.XmlHttp.3.0 MSXML2.XmlHttp.2.0 Microsoft.XmlHttp".split(" "),b,c=0;c<e.length;c++)try{b=new ActiveXObject(e[c]);break}catch(k){}return b},send:function(e,b,c,k,g){void 0===g&&(g=!0);var d=rfsn_ajax.x();d.open(c,e,g);d.onreadystatechange=function(){4==d.readyState&&b(d.responseText)};"POST"==c&&d.setRequestHeader("Content-type","application/x-www-form-urlencoded");
d.send(k)},get:function(e,b,c,k){var g=[],d;for(d in b)g.push(encodeURIComponent(d)+"="+encodeURIComponent(b[d]));rfsn_ajax.send(e+(g.length?"?"+g.join("&"):""),c,"GET",null,k)},post:function(e,b,c,k){var g=[],d;for(d in b)g.push(encodeURIComponent(d)+"="+encodeURIComponent(b[d]));rfsn_ajax.send(e,c,"POST",g.join("&"),k)}};
function load_script(e,b){var c=document.createElement("script");c.type="text/javascript";c.readyState?c.onreadystatechange=function(){if("loaded"==c.readyState||"complete"==c.readyState)c.onreadystatechange=null,b()}:c.onload=function(){b()};c.src=e;document.getElementsByTagName("head")[0].appendChild(c)}
function RFSNTracker(){this.is_ready=!1;this.log_count=1;var e={},b={is_loaded:!1,ls_enabled:!1,verbose:!1},c=function(){var a=window.location.href,a=-1!=a.search(/^https?\:\/\//)?a.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i,""):a.match(/^([^\/?#]+)(?:[\/?#]|$)/i,"");return a[1]};this.init=function(){b.shop=this.get_qs("shop",!0);b.public_key=this.get_qs("pk",!0);b.client_id=this.get_qs("client_id",!0);var a=this.get_qs("custom_key",!0);b.custom_key=a?a:"rfsn";if(b.is_loaded)if(b.xdomain_enabled=
0<=b.xdomains.indexOf(c()),b.xdomain_enabled&&2===b.version&&"undefined"===typeof xdLocalStorage)load_script(b.base_url+"js/xdLocalStorage.min.js?v="+Math.floor(100*Math.random()),function(){xdLocalStorage.init({iframeUrl:b.base_url+"tracker/v3/xdomain/"+b.public_key+".html",initCallback:function(){_rfsn_tracker.init()}});_rfsn_tracker.log("XDomain support enabled.")});else{this.log("Tracker has been initiated.");this.is_ready=!0;"undefined"===typeof jQuery&&load_script("//ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js",
function(){$=jQuery.noConflict(!0)});try{localStorage.setItem("test","test"),localStorage.removeItem("test"),b.ls_enabled=!0}catch(h){b.ls_enabled=!1,d(1)}""!==this.get_qs("rf_test")&&alert("Success! Your Refersion click was tracked, please continue with your test order.");this.fingerprint_click();this.fingerprint_cart();1<b.version&&this.cookie_change_listener()}else this.log("Setting for tracker did not load properly.","error")};this.cookie_change_listener=function(){var a=this,b=setInterval(function(){""!=
a.get_cookie("cart")&&"undefined"!=typeof a.get_cookie("cart")&&a.get_cookie("cart")!=localStorage.getItem("current_cart")&&(a.fingerprint_cart(),clearInterval(b))},1E3)};this.log=function(a,h){if(b.verbose){switch(h){case "error":console.error("Refersion ["+this.log_count+"]: "+a);break;case "warn":console.warn("Refersion ["+this.log_count+"]: "+a);break;default:console.log("Refersion ["+this.log_count+"]: "+a)}this.log_count++}};this.load_settings=function(a){for(var h in a)b[h]=a[h];"undefined"!==
typeof localStorage.tracking_version&&(b.version=localStorage.tracking_version)};this.get_qs=function(a,b){a=a.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var f=new RegExp("[\\?&]"+a+"=([^&#]*)"),c="";if(b){for(var d=document.getElementsByTagName("script"),e=0;e<=d.length;e++)if(d[e].src.match(/(refersion\.com.|s3\.amazonaws\.com.refersion)[^\/]*(\/\d*\/tracking|pixel)/ig)){c=d[e].src;break}f=f.exec(c)}else f=f.exec(location.search);return null===f?"":decodeURIComponent(f[1].replace(/\+/g," "))};
var k=function(){var a=document.cookie,b=0,f={};"function"!==typeof String.prototype.trimLeft&&(String.prototype.trimLeft=function(){return this.replace(/^\s+/,"")});"function"!==typeof String.prototype.trimRight&&(String.prototype.trimRight=function(){return this.replace(/\s+$/,"")});"function"!==typeof Array.prototype.map&&(Array.prototype.map=function(a,b){for(var h=0,f=this.length,c=[];h<f;h++)h in this&&(c[h]=a.call(b,this[h]));return c});document.cookie.match(/^\s*\$Version=(?:"1"|1);\s*(.*)/)&&
(a=RegExp.$1,b=1);0===b?a.split(/[,;]/).map(function(a){var b=a.split(/=/,2);a=decodeURIComponent(b[0].trimLeft());b=1<b.length?decodeURIComponent(b[1].trimRight()):null;f[a]=b}):a.match(/(?:^|\s+)([!#$%&'*+\-.0-9A-Z^`a-z|~]+)=([!#$%&'*+\-.0-9A-Z^`a-z|~]*|"(?:[\x20-\x7E\x80\xFF]|\\[\x00-\x7F])*")(?=\s*[,;]|$)/g).map(function(a,b){var h='"'===b.charAt(0)?b.substr(1,-1).replace(/\\(.)/g,"$1"):b;f[a]=h});return f};this.get_cookie=function(a){return k()[a]};var g=function(a,b){var f=new Image;f.onload=
function(){};f.setAttribute("style","float: right;");f.setAttribute("class",b);f.setAttribute("alt","");f.src=a;document.body.appendChild(f)},d=function(a){b.version=a;b.ls_enabled&&localStorage.setItem("tracking_version",a)};this.get_setting=function(a){return b[a]||void 0};this.get_version=function(){return parseFloat(b.version)};this.is_settings_loaded=function(){return b.is_loaded||!1};var l=function(){b.xdomain_enabled&&"undefined"!=typeof xdLocalStorage&&(xdLocalStorage.getItem("rfsn_ci",function(a){parseInt(localStorage.rfsn_ci||
0)>parseInt(a.value||0)&&("undefined"!==typeof localStorage.rfsn_aid&&xdLocalStorage.setItem("rfsn_aid",localStorage.rfsn_aid),"undefined"!==typeof localStorage.rfsn_ci&&xdLocalStorage.setItem("rfsn_ci",localStorage.rfsn_ci),"undefined"!==typeof localStorage.rfsn_cs&&xdLocalStorage.setItem("rfsn_cs",localStorage.rfsn_cs),"undefined"!==typeof localStorage.tracking_version&&xdLocalStorage.setItem("tracking_version",localStorage.tracking_version),"undefined"!==typeof localStorage.current_cart&&xdLocalStorage.setItem("current_cart",
localStorage.current_cart))}),_rfsn_tracker.log("localStorage Pushed"))},m=function(){b.xdomain_enabled&&"undefined"!=typeof xdLocalStorage&&(xdLocalStorage.getItem("rfsn_ci",function(a){parseInt(localStorage.rfsn_ci||0)<=parseInt(a.value||0)&&(xdLocalStorage.getItem("rfsn_aid",function(a){a.value&&"undefined"!==typeof a.value&&(localStorage.rfsn_aid=a.value)}),xdLocalStorage.getItem("rfsn_ci",function(a){a.value&&"undefined"!==typeof a.value&&(localStorage.rfsn_ci=a.value)}),xdLocalStorage.getItem("rfsn_cs",
function(a){a.value&&"undefined"!==typeof a.value&&(localStorage.rfsn_cs=a.value)}),xdLocalStorage.getItem("tracking_version",function(a){a.value&&"undefined"!==typeof a.value&&(localStorage.tracking_version=a.value)}),xdLocalStorage.getItem("current_cart",function(a){a.value&&"undefined"!==typeof a.value&&(localStorage.current_cart=a.value)}))}),_rfsn_tracker.log("localStorage Pulled"))};this.check_action_timeout=function(a){var b=(new Date).getTime();a=localStorage.getItem("current_rfsn_"+a);return 60<
(b-a)/1E3||!a};this.set_action_mark=function(a){var b=(new Date).getTime();localStorage.getItem("current_rfsn_"+a)&&!this.check_action_timeout(a)||localStorage.setItem("current_rfsn_"+a,b)};this.fingerprint_click=function(){"function"==typeof Fingerprint2?(new Fingerprint2).get(function(a){if("undefined"==typeof a||""==a||"undefined"==a)a="";_rfsn_tracker.click(a)}):_rfsn_tracker.click("")};this.click=function(a){if(""==this.get_qs("rfsn")&&""==this.get_qs(b.custom_key)||!this.check_action_timeout("click"))"undefined"!==
typeof e.click&&60>=e.click&&this.log("Click tracking on timeout. ("+e.click+")");else switch(this.log("Click track attempt:"),b.version){case 1:var c=b.base_url+"p"+location.search+"&krfsn_k="+b.custom_key+"&rfsn_fp="+a+"&d="+(new Date).getTime();g(c,"rfsn_pixel_click_legacy");this.log("Tracker [v1] [Custom] click tracked @ "+c);this.set_action_mark("click");break;case 2:m(),c=b.base_url+"t/v2"+location.search+"&rfsn_k="+b.custom_key+"&rfsn_fp="+a+"&rfsn_lp="+escape(document.URL)+"&rfsn_r="+escape(document.referrer)+
"&d="+(new Date).getTime(),rfsn_ajax.get(c,{},function(a){a=JSON.parse(a);!isNaN(a.cid)&&0<a.cid?(a.aid&&localStorage.setItem("rfsn_aid",a.aid),a.cs&&localStorage.setItem("rfsn_cs",a.cs),a.cid&&localStorage.setItem("rfsn_ci",a.cid),l(),_rfsn_tracker.log("Tracker [v2] [Custom] click tracked @ "+c),_rfsn_tracker.set_action_mark("click")):(d("1.0"),l(),_rfsn_tracker.log("Tracker [v2] click tracked blocked. Trying legacy approach.","warn"),_rfsn_tracker.fingerprint_click())})}};this.fingerprint_cart=
function(){"function"==typeof Fingerprint2?(new Fingerprint2).get(function(a){if("undefined"==typeof a||""==a||"undefined"==a)a="";_rfsn_tracker.cart(a)}):_rfsn_tracker.cart("")};this.cart=function(a){if(this.check_action_timeout("cart"))switch(this.log("Cart map attempt:"),b.version){case 1:if(""!=this.get_cookie("cart")&&"undefined"!==typeof this.get_cookie("cart")){var c=b.base_url+"tracker/shopify?shop="+b.shop+"&i=NULL&sci="+this.get_cookie("cart")+"&rfsn_fp="+a+"&d="+(new Date).getTime();g(c,
"rfsn_pixel_cookie_legacy");this.log("Tracker [v1] [Standard] cart tracked @ "+c);this.set_action_mark("cart")}break;case 2:null!==localStorage.getItem("rfsn_ci")&&""!=this.get_cookie("cart")&&"undefined"!==typeof this.get_cookie("cart")&&this.get_cookie("cart")!=localStorage.getItem("current_cart")&&(c=b.base_url+"tracker/shopify/v2?shop="+b.shop+"&rci="+localStorage.getItem("rfsn_ci")+"&raid="+localStorage.getItem("rfsn_aid")+"&sci="+this.get_cookie("cart")+"&rfsn_fp="+a+"&d="+(new Date).getTime(),
rfsn_ajax.get(c,{},function(a){"TRUE"==a&&(localStorage.setItem("current_cart",_rfsn_tracker.get_cookie("cart")),_rfsn_tracker.log("Tracker [v2] [Custom] cart tracked @ "+c),l(),_rfsn_tracker.set_action_mark("cart"))}),this.log("AJAX item tracked."))}};this.get_qs("pk",!0)?load_script("https://s3.amazonaws.com/refersion_client/"+this.get_qs("client_id",!0)+"/tracking/"+this.get_qs("pk",!0)+".js?shop="+this.get_qs("shop",!0),function(){_rfsn_tracker.init()}):this.log("Error: Missing public key.","error")}
var _rfsn_tracker=_rfsn_tracker||new RFSNTracker;