jQuery(document).ready(function() {
	$('#password-modal-heading').prepend('<div class="MOheader" id="MOmyHeader" ><p style="text-align:center"><input type="button" style="background:#308a0a;width:100%;height:50px;color:#ffffff;" class ="btn btn-primary" id="my_button" value="Login with Pimax Passport" onclick="move()"></p><p style="margin-bottom:15px;font-size:20px;text-align:center;"><b id="subtextArea">Or Login Via</b></p></div>');
	$('#customer_login').prepend('<div class="MOheader" id="MOmyHeader" ><p style="text-align:center"><input type="button" style="background:#308a0a;width:100%;height:50px;color:#ffffff;" class ="btn btn-primary" id="my_button" value="Login with Pimax Passport" onclick="move()"></p><p style="margin-bottom:15px;font-size:20px;text-align:center;"><b id="subtextArea">Or Login Via</b></p></div>');
var Hash_String = window.location.search;
const Hash_Param = new URLSearchParams(Hash_String);
if(Hash_Param.has('hash')){
console.log('In setting hash');document.cookie = "storefront_digest=" + Hash_Param.get('hash') +"; path=/";
	var shop_name = 	window.location.hostname;
window.location.href="https://"+shop_name;
}
$('a[href^="/account/logout"]').on("click", function() {
$.ajax( $(this).attr('href') )
.done(function() {
document.cookie = "storefront_digest=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
window.location.reload();});
return false;
});
 var cartValue =  mo_getCookie("cart");
 if (typeof cartValue !== 'undefined'){
   createCookie("cart",cartValue,15);
 }});
function move(){
	var shop_name = 	window.location.hostname;
var queryString = window.location.search;
console.log(queryString);
var checkout_url = "?redirect_endpoint=/account";
const urlParams = new URLSearchParams(queryString);
if (urlParams.has("checkout_url")) {
      if(urlParams.get("checkout_url").includes("checkouts")) {
        checkout_url = `?redirect_endpoint=${urlParams
          .get("checkout_url")
          .replace(`https://${window.location.host}`, "")}`;
      }
    }
    else if (urlParams.has("return_url")) {
      if(urlParams.get("return_url").includes("checkouts")) {
        checkout_url = `?redirect_endpoint=${urlParams
          .get("return_url")
          .replace(`https://${window.location.host}`, "")}`;
      }
    }else{
checkout_url = "?redirect_endpoint=/account";
}
    	  location.href = `https://store.xecurify.com/moas/broker/login/shopify/${shop_name}/account${checkout_url}`;
}
function mo_getCookie(cookieName) {
    let cookie = {};
    document.cookie.split(";").forEach(function(el) {
      let [key,value] = el.split("=");
      cookie[key.trim()] = value;
    })
    return cookie[cookieName];
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    else {
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}
