//**********************
//Must include this on each storefront page using
//<script language="JavaScript" src="header.js"></script>
//To Do:	
//	1) Modify my_track and create an entry on the Franchise Control Panel for each franchise site;
//	2) Modify my_initial if the storefront pages reside on a different domain or folder.
//**********************

var my_track = "mall";
var my_initial = "initial.asp"; 
var my_detail = "detail.htm"; //used when online template wizard is not present or in-active
//var my_detail = "front.asp?file=detail.htm"; //used when online template wizard is active

var myStyle = 
	'&linecolor=' + escape('#AAAAAA') + 
	'&menu=category' + 
	'&body=bodyblue' + 
	'&bold=bodyheading' + 
	'&hlcolor=' + escape('#88C4FF') + 
	'&bgcolor=' + escape('#E0FFE0') + 
	'&hdcolor=' + escape('#B0B0B0') + 
	'&idcolor=' + escape('#FFFFFF') + 
	'&header=bodywhite' + 
	'&rowcolor=' + escape('#E0FFE0') + 
	'&row=bodyblack' + 
	'&label=bodyblue' + 
	'&heading=heading' + 
	'&detail=' + escape(my_detail) + 
	'&popup=yes';

InitialHeader(false);
function InitialHeader(bRefresh)
{
var i, sStr, page, curPage = "" + window.location, myid = "";
	curPage = curPage.toLowerCase();
	if (curPage.indexOf('.asp') > 0 && window.goback != null) 
	{
		sStr = curPage;
		i = sStr.lastIndexOf("/");
		if (i > 0) sStr = sStr.substring(0, i+1);
		curPage = goback.toLowerCase();
		if (curPage.indexOf(sStr) == 0)	curPage = "";
	}
	i = curPage.lastIndexOf("?");
	if (i > 0) 
	{
		myid = curPage.substring(i+1, curPage.length);
		curPage = curPage.substring(0, i);
		i = myid.indexOf("&rnd=");
		if (i > 0) myid = myid.substring(0, i);
	}
	i = curPage.lastIndexOf("/");
	if (i > 7) 
		curPage = curPage.substring(0, i+1);
	else if (curPage.length && i < 0) 
		curPage += '/';
		
	page = my_initial + "?track=" + my_track + "+" + escape(curPage);
	if (window.sessionid)
		page += "&id=" + sessionid;
	else if (myid.length)
		page += "&" + myid;

	if (bRefresh)
		page += '&rnd=' + Math.round(Math.random()*100000); 
	
	if (curPage.length && curPage.indexOf('http') < 0 && my_initial.indexOf('://') < 0)
	{
		alert('To properly preview the page: \n\nEdit "header.js" file to Prefix "my_initial" variable with a full domain URL.');
	}
	else	
	{
		document.write('<' + 'script language="JavaScript" src="' +
			page + '"></' + 'script>\r\n');
	}
}

var myStyle0 = '?' + myStyle.substring(1, myStyle.length);
function setStyle(sField, sValue)
{
var thisStyle = myStyle;
var i, j, sStr;
	i = thisStyle.indexOf('&' + sField + '=');
	if (i >= 0)
	{
		j = thisStyle.indexOf('&', i + 1);
		if (j == 0) j = thisStyle.length;
		sStr = thisStyle.substring(i, j);
		thisStyle = thisStyle.replace(sStr, '&' + sField + '=' + escape(sValue));		
	}
	else
		thisStyle += '&' + sField + '=' + escape(sValue);
	return thisStyle;
}	

