//parseUri function is loaded in the javascripts/header.js
var protocol = parseUri(location.href).protocol;
var host = parseUri(location.href).host;
var cdomain =  protocol + "://" + host;
var path = parseUri(location.href).path;
var query = parseUri(location.href).query;
var relative = path + "?" + query;

if (protocol == "https") 
{
	window.location="http://" + host + relative;
}

//check for the exchange promotion cookie if not set redirect to the promo page
//getCookie function is loaded in the javascripts/header.js
var mc2805 = getCookie('2805_promo');
if (!mc2805 && (path == "/marketplace/storefront/_store_espx_store_2805_sub_330.html" || path == "/marketplace/storefront/_store_espx_store_2805_storetab_on.html" || path == "/marketplace/storefront/_store_espx_store_2805.html") )
{
	window.location="/marketplace/storefront/_item_promotion_espx_store_2805_sub__storetab_on.html";
}
if (path == "/marketplace/storefront/_item_promotion_espx_store_2805_sub__storetab_on.html" || path == "/marketplace/storefront/_item_promotion_espx_store_2805.html")
{
	document.cookie = "2805_promo=set;domain=" + host
}
//check for the edm promotion cookie if not set redirect to the promo page
var mc2803 = getCookie('2803_promo');
if (!mc2803 && (path == "/marketplace/storefront/_store_espx_store_2803_sub_325.html" || path == "/marketplace/storefront/_store_espx_store_2803_sub_338.html"  || path == "/marketplace/storefront/_store_espx_store_2803_storetab_on.html" || path == "/marketplace/storefront/_store_espx_store_2803.html") )
{
	window.location="/marketplace/storefront/_item_promotion_espx_store_2803_sub__storetab_on.html";
}
if (path == "/marketplace/storefront/_item_promotion_espx_store_2803_sub__storetab_on.html" || path == "/marketplace/storefront/_item_promotion_espx_store_2803.html")
{
	document.cookie = "2803_promo=set;domain=" + host
}


window.setTimeout(function(){
	var pat = /eas_un=([^;]+)/;
	var m = pat.exec(document.cookie);
	if(!m){
		document.getElementById('mh-link2').innerHTML="<span id='show_login' style='padding-right:25px;'><a href='/no_style/www2logon.espx?diid="+relative+"'>Log In</a></span>";
	}
	else
	{
		var un= unescape(m[1]);
		document.getElementById('mh-link2').innerHTML="<span id='show_login' style='padding-right:25px;'>Logged in as "+un+"  &nbsp;[&nbsp;<a href='/logoff.esp'>Log Off</a>&nbsp;]</span>";
	}
	//http://reports.etelos.com/store_hit.php?sid=XXX&mid=XXX&uid=XXX
	var qs = parseUri(location.href).path;
	//alert("qs: "+ qs);
	
	m = /store_([0-9]{4})/.exec(qs);
	if(!m) return;
	var storeId = m[1];
	
	var uid = '';
	m = /eas_uuid=([a-z0-9]{32})/.exec(document.cookie);
	if(m) uid = m[1];
	/*	
	var subId = '';
	m = /sub_([0-9]{4})/.exec(qs);
	if(m) subId = m[1];
	*/
	data = "sid="+storeId+"&mid=98&uid="+uid;
	new Ajax.Request('http://reports.etelos.com/store_hit.php?'+data,{
		method:'get',
		onSuccess:function(xhr,meta){}
	});
}, 100);

