function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

var s = "";

function showCart(which, store) {
	if(s != store) hideCart();
	toggle('cartCallout');
	obj = document.getElementById("cartCallout");
	obj2 = document.getElementById(which);
	obj3 = document.getElementById("store");
	temp = getposOffset(obj2, "top") + 8;
	temp2 = getposOffset(obj2, "left") - 295;
	obj.style.top = temp + "px";
	obj.style.left = temp2 + "px";
	s = store;
	obj3.innerHTML = store + " Store";
}

function hideCart() {
	obj = document.getElementById("cartCallout");
	obj.style.display = h = "none";
}

var h = "none";

function toggle(theDiv) {
     var elem = document.getElementById(theDiv);
     elem.style.display = (h == "none")?"block":"none";
	 h = elem.style.display;
}

function showTip(which) {
	if(!document.getElementById("tip")) {
		var body = document.getElementsByTagName("body")[0];
		var d = document.createElement('div');
	
		body.appendChild(d);
		d.setAttribute("id", "tip");
	}
	obj = document.getElementById("tip");
	curobj = document.getElementById(which);
	temp = getposOffset(curobj, "top") + 29;
	temp2 = getposOffset(curobj, "left");	
	
	obj.style.display = "block";
	obj.style.top = temp + "px";
	obj.style.left = temp2 + "px";
	obj.innerHTML = '<img src="/content/presentation/www/images/' + which + '.png" alt="" />';	
}

function hideTip() {
	document.getElementById("tip").style.display = "none";
}

var tabStores = {
	makeRequest:function(url)
	{
        var httpRequest;
		url = "/content/includes/www/stores_tab_" + url + ".html";
		
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');                
            }
        } else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        httpRequest.onreadystatechange = function() { tabStores.displayStore(httpRequest); };
        httpRequest.open('GET', url, true);
        httpRequest.send(null);
    },	
	displayStore:function(httpRequest)
	{
		if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
                var obj = document.getElementById("storesTabs");
				obj.innerHTML = httpRequest.responseText;				
            } else {
                //
            }
        }		
	}

}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function onMAClose() { setMyAccountCloseHook(function(){location.reload();}); }
addLoadEvent(onMAClose);