//**********************
//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"; 

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 && window.goback.length) 
	{
		sStr = curPage;
		i = sStr.lastIndexOf("/");
		if (i > 0) sStr = sStr.substring(0, i+1);
		curPage = goback.toLowerCase();
		if (curPage.indexOf(sStr) == 0)	curPage = "";
		//update my_detail
		i = curPage.lastIndexOf('.asp?pid=');
		if (i <= 0) i = curPage.lastIndexOf('.asp?file=');
		if (i > 0 && my_detail.indexOf('.asp') < 0) 
		{
			i = curPage.lastIndexOf('/', i);
			sStr = curPage.substring(i + 1, curPage.length);
			i = sStr.indexOf('?');
			sStr = sStr.substring(0, i);
			my_detail = sStr + '?file=' + my_detail;		
		}
	}
	i = curPage.lastIndexOf("?");
	if (i > 0) 
	{
		myid = '&' + curPage.substring(i+1, curPage.length);
		curPage = curPage.substring(0, i);
		i = myid.lastIndexOf('&id=');
		if ( i < 0) 
			myid = '';
		else 
		{
			if (i > 0) myid = myid.substring(i, myid.length);
			i = myid.indexOf('#', 1)
			if (i > 0) myid = myid.substring(0, i);	
			i = myid.indexOf('&', 1)
			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.indexOf('http') < 0 && my_initial.indexOf('://') < 0 && curPage.length)
	{
		alert('To properly preview the page: \n\nEdit "header.js" file to Prefix "my_initial" variable with a full domain URL.');
	}
	else if (!window.parent || (!window.parent.sitename && !window.parent.fixHTMLArea)) 
	//Do not load initial.asp if parent has it already.
	{
		document.write('<' + 'script language="JavaScript" src="' +
			page + '"></' + 'script>\r\n');
	}
}

if (window.parent && window.parent.sitename && !window.parent.fixHTMLArea) 
{
//Simply redefine some functions to call those on the parent window.
	eval("var sessionid = window.parent.sessionid;");
	eval("var cart = window.parent.cart;");
	eval("function quickcart(sParams) {window.parent.quickcart(sParams, window)}");
	eval("function insertstatic(sURL) {window.parent.insertstatic(sURL, window)}");
	eval("function insertpage(sURL) {window.parent.insertpage(sURL, window)}");
	eval("function submitform(sForm, sURL) {window.parent.submitform(sForm, sURL, window)}");
}

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;
}	

