﻿// STORE CUSTOMER METHODS
function SetStoreCustomerID(guid)
{
    createCookie("MarketpathStoreFrontCustomerID", guid, 10);
}
function SetStoreCustomerOrderID(guid)
{
    createCookie("MarketpathStoreFrontCustomerOrderID",guid,14);
}
function SetRedirectURL(strRedirectURL)
{
    createCookie("MarketpathStoreFrontRedirectURL",strRedirectURL,14);
}
function SignIn(strURL)
{
    window.location.href = strURL + "signin";
}

function MyAccount(strURL)
{
    window.location.href = strURL + "myaccount";
}
function MPStoreFrontLogout()
{
    eraseCookie("MarketpathStoreFrontCustomerID");
    window.location.reload();
}

function MPStoreFrontEraseOrder()
{
    eraseCookie("MarketpathStoreFrontCustomerOrderID");
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function formatCurrency(strValue)
{
      strValue = strValue.toString().replace(/\$|\,/g,'');
      dblValue = parseFloat(strValue);

      blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
      dblValue = Math.floor(dblValue*100+0.50000000001);
      intCents = dblValue%100;
      strCents = intCents.toString();
      dblValue = Math.floor(dblValue/100).toString();
      if(intCents<10)
            strCents = "0" + strCents;
      for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
            dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
            dblValue.substring(dblValue.length-(4*i+3));
      return ('$' + dblValue + '.' + strCents);
}

function ShowWishListDropDown()
{
    var dd = getElementById("MPCartSummaryWishListDropDownExpanded");
    
    if (dd)
    {
        if (dd.style.display == "none")
            dd.style.display = "block";
        else
            dd.style.display = "none";
    }
}