// ----------------------------------------------------------------------
// LOCATION CONTROL VARIABLES
// ----------------------------------------------------------------------
LOCATION_NAME = 0;
LOCATION_LISTNUMBER = 1;
LOCATION_HASTIPS = 2;
LOCATION_HASRECIPES = 3;
LOCATION_HASNEWS = 4;

gnLocMax = 0;
var gsLocMatrix = new Array(100);
//                              have their own:        tip? recipes? news?
gsLocMatrix[gnLocMax++] = new Array("middletown", "2", true, true, true);
gsLocMatrix[gnLocMax++] = new Array("wakefield", "3", true, true, true);
gsLocMatrix[gnLocMax++] = new Array("westerly", "4", true, true, true);
gsLocMatrix[gnLocMax++] = new Array("cottagegrove", "5", true, true, true);
gsLocMatrix[gnLocMax++] = new Array("fortcollins", "6", true, true, true);
gsLocMatrix[gnLocMax++] = new Array("delavan", "7", true, true, true);
gsLocMatrix[gnLocMax++] = new Array("madison", "10", true, true, true);
gsLocMatrix[gnLocMax++] = new Array("germantown", "9", false, true, true);
gsLocMatrix[gnLocMax++] = new Array("rockville", "11", false, false, false);
gsLocMatrix[gnLocMax++] = new Array("lakewood", "12", false, false, false);
gsLocMatrix[gnLocMax++] = new Array("ormondbeach", "13", false, false, false);
//gsLocMatrix[gnLocMax++] = new Array("eastcobb", "14", false, false, false);
gsLocMatrix[gnLocMax++] = new Array("fishersville", "15", true, true, true);
gsLocMatrix[gnLocMax++] = new Array("lynchburg", "16", true, true, true);
gsLocMatrix[gnLocMax++] = new Array("cranston", "18", false, false, false);
gsLocMatrix[gnLocMax++] = new Array("york", "19", false, true, false);
// ----------------------------------------------------------------------
// NAVIGATION CONTROL VARIABLES
// ----------------------------------------------------------------------
gstTarget = "";
NAV_CATEGORY = 0;
NAV_PAGEHEAD = 1;
NAV_ALIAS = 2;
NAV_URL = 3;
NAV_WIDTH = 4;
NAV_IMGWIDTH =5;

gnNavMax=0;
var gstNavMatrix = new Array(100);
gstNavMatrix[gnNavMax++] = new Array("Healthy Info - Tips", "Healthy Information", "tips", "../publish/health_tips.shtml", "33%", "110");
gstNavMatrix[gnNavMax++] = new Array("Healthy Info - Recipes", "Healthy Information", "recipes", "../publish/health_recipes.shtml", "33%", "110");
gstNavMatrix[gnNavMax++] = new Array("Healthy Info - News", "Healthy Information", "news", "../publish/health_news.shtml", "33%", "110");

gstNavMatrix[gnNavMax++] = new Array("The Program - Nutrition", "The Program", "nutrition", "../publish/nutrition.shtml", "25%", "110");
gstNavMatrix[gnNavMax++] = new Array("The Program - Exercise", "The Program", "exercise", "../publish/exercise.shtml", "25%", "110");
gstNavMatrix[gnNavMax++] = new Array("The Program - Coaching", "The Program", "coaching", "../publish/coaching.shtml", "25%", "110");
gstNavMatrix[gnNavMax++] = new Array("The Program - Relaxation", "The Program", "relaxation", "../publish/relaxation.shtml", "25%", "110");

gstNavMatrix[gnNavMax++] = new Array("Locations - A to I", "Locations", "locations_ai", "../publish/locations_ai.shtml", "25%", "110");
gstNavMatrix[gnNavMax++] = new Array("Locations - J to R", "Locations", "locations_jr", "../publish/locations_jr.shtml", "25%", "110");
gstNavMatrix[gnNavMax++] = new Array("Locations - S to Z", "Locations", "locations_sz", "../publish/locations_sz.shtml", "25%", "110");
gstNavMatrix[gnNavMax++] = new Array("Locations - International", "Locations", "locations_intl", "../publish/locations_intl.shtml", "25%", "110");

gstNavMatrix[gnNavMax++] = new Array("Order - Supplements", "Ordering Section", "supplements", "../publish/order_supplements.shtml", "50%", "85");
gstNavMatrix[gnNavMax++] = new Array("Order - Products", "Ordering Section", "products", "../publish/order_products.shtml", "50%", "75");
// ----------------------------------------------------------------------
// GetParameter
// ----------------------------------------------------------------------	
function GetParameter(stParamString, stParam)
{	
	stValue="";
	if (stParamString.indexOf(stParam)>-1) {
		stValue = stParamString.substr(stParamString.indexOf(stParam)+stParam.length+1,3);
	} 
	return stValue;	
}
// ----------------------------------------------------------------------
// GetLocation
// ----------------------------------------------------------------------	
function GetLocation()
{
	stLocation="";

	stLocTemp = GetCookieValue("Location");
	for (nLoc=0; nLoc<gnLocMax; nLoc++){
		if (stLocTemp==gsLocMatrix[nLoc][LOCATION_NAME]){
			stLocation = stLocTemp;
			break;
		}
	}

	return stLocation;	
}

function ShowEmail()
{
	stLocation=GetLocation();
	if (stLocation=="") {
		stLocation="info";
	}
	document.writeln('<A href="mailto:'+stLocation+'@healthyinspirations.us">' +stLocation+'@healthyinspirations.us</A>' );
}

// ----------------------------------------------------------------------
// GetLocMatrixID
// ----------------------------------------------------------------------	
function GetLocMatrixID(stLocTemp)
{
	nLocMatrixID=-1;
	//stLocTemp = GetCookieValue("Location");
	for (nLoc=0; nLoc<gnLocMax; nLoc++){
		if (stLocTemp==gsLocMatrix[nLoc][LOCATION_NAME]){
			nLocMatrixID = nLoc;
			break;
		}
	}
	return nLocMatrixID;	
}

// ----------------------------------------------------------------------
// GetLocationListNumber
// ----------------------------------------------------------------------	
function GetLocationListNumber(stFormLoc)
{
	var stLocListNum="1"; // corporate's list number is the default

	for (nLoc=0; nLoc<gnLocMax; nLoc++){
		if (stFormLoc==gsLocMatrix[nLoc][LOCATION_NAME]){
			stLocListNum = gsLocMatrix[nLoc][LOCATION_LISTNUMBER];
			break;
		}
	}

	return stLocListNum;	
}

// ----------------------------------------------------------------------
// GetCookieValue
// ----------------------------------------------------------------------	
function GetCookieValue(stCookieName)
{
	thisCookie = document.cookie.split("; ");
	for(i=0; i<thisCookie.length; i++){
		if (stCookieName==thisCookie[i].split("=")[0]){
		  return thisCookie[i].split("=")[1];
		}
	}
	return "";	
}
// ----------------------------------------------------------------------
// SetCookieValue
// ----------------------------------------------------------------------	
function SetCookieValue(stCookieName, stCookieValue)
{	
	document.cookie = stCookieName + "=" + stCookieValue +";expires=" ;
}
// ----------------------------------------------------------------------
// PersistCookieValue
// ----------------------------------------------------------------------	
function PersistCookieValue(stCookieName, stCookieValue)
{	
	var nextyear = new Date();
	nextyear.setFullYear(nextyear.getFullYear()+1);
	document.cookie = stCookieName + "=" + stCookieValue +"; expires=" + nextyear.toGMTString();
}

// ----------------------------------------------------------------------
// GetCategoryParent
// ----------------------------------------------------------------------	
function GetCategoryParent(stCatName)
{	
	stParent="";
	if (stCatName.indexOf(" - ")>0) {
		stParent = stCatName.substr(0,stCatName.indexOf(" - "));
	} 
	return stParent;	
}

// ----------------------------------------------------------------------
// GetCatHeading
// ----------------------------------------------------------------------	
function GetCatHeading(stCatName)
{	
	stHeading=stCatName;
	if (stCatName.indexOf(" - ")>0) {
		stHeading = stCatName.substr(0,stCatName.indexOf(" - "));
	} 
	else {
		if (stCatName.indexOf(" [")>0) {
			stHeading = stCatName.substr(0,stCatName.indexOf(" ["));
		}
	}
	return stHeading;	
}

// ----------------------------------------------------------------------
// GetLocalURL
// ----------------------------------------------------------------------	
function GetLocalURL(stLocation, stURL)
{	
	stLocURL=stURL;
	stCompare = stURL;
	
	if (stLocation=="") {
		return stLocURL;
	}
	
	// Centers do NOT currently support a "Locations" Item
	if (stCompare.indexOf("location")>0) {
		stLocURL=""
		return stLocURL;
	}
	// ALL Centers should have an About Us Page and Success Stories Page
	if (stCompare.indexOf("aboutus")>=0) {
		stLocURL = stCompare.substr(0,stCompare.indexOf("aboutus"))+stLocation+"_aboutus.shtml";
		return stLocURL;
	}
	if (stCompare.indexOf("success_")>=0) {
		stLocURL = stCompare.substr(0,stCompare.indexOf("success_"))+stLocation+stCompare.substr(stCompare.indexOf("success_")+7);
		return stLocURL;
	}
	
	// Centers CONDITIONALLY have an Healthy TIP RECIPES, and NEWs Pages
	nMatrixID = GetLocMatrixID(stLocation);
	if ( stCompare.indexOf("health_tips")>=0 && gsLocMatrix[nMatrixID][LOCATION_HASTIPS] ) {
		stLocURL = stCompare.substr(0,stCompare.indexOf("health_"))+stLocation+stCompare.substr(stCompare.indexOf("health_")+6);
		return stLocURL;
	}
	if ( stCompare.indexOf("health_recipes")>=0 && gsLocMatrix[nMatrixID][LOCATION_HASRECIPES] ) {
		stLocURL = stCompare.substr(0,stCompare.indexOf("health_"))+stLocation+stCompare.substr(stCompare.indexOf("health_")+6);
		return stLocURL;
	}
	if ( stCompare.indexOf("health_news")>=0 && gsLocMatrix[nMatrixID][LOCATION_HASNEWS] ) {
		stLocURL = stCompare.substr(0,stCompare.indexOf("health_"))+stLocation+stCompare.substr(stCompare.indexOf("health_")+6);
		return stLocURL;
	}	
	
	return stLocURL;	
}		

// ----------------------------------------------------------------------
// Write_Tabbed_PageHead
// ----------------------------------------------------------------------
function Write_Tabbed_PageHead(stParent)
{
	for (n=0; n<gnNavMax; n++){
		if(gstNavMatrix[n][NAV_CATEGORY].indexOf(stParent)==0){
			document.writeln('<div align="center"><font class="arthead">'+ gstNavMatrix[n][NAV_PAGEHEAD] +'</font></div>');
			break;
		}
	}
}

// ----------------------------------------------------------------------
// Begin_PageTabs
// ----------------------------------------------------------------------
function Begin_PageTabs(stCatCompare)
{
	// begin outer table
	document.writeln('<TABLE width="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD>');
	
	// begin tabs table
	document.writeln('<span class="Tabs">');
	document.writeln('<TABLE width="100%" align="left" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR>');
    
	// alert(gstParent);
	
	for (n=0; n<gnNavMax; n++){
		if(gstNavMatrix[n][NAV_CATEGORY].indexOf(gstParent)==0){
			if (stCatCompare.indexOf(gstNavMatrix[n][NAV_CATEGORY])==0){         
				Add_PageTab(gstNavMatrix[n][NAV_ALIAS], "", gstNavMatrix[n][NAV_WIDTH], gstNavMatrix[n][NAV_IMGWIDTH]);
			}
			else {
				Add_PageTab(gstNavMatrix[n][NAV_ALIAS], GetLocalURL(gstLocation, gstNavMatrix[n][NAV_URL]), gstNavMatrix[n][NAV_WIDTH], gstNavMatrix[n][NAV_IMGWIDTH]);
			} 
		}
	}
	Begin_PageTabBody();              
}


// ----------------------------------------------------------------------
// Add_PageTab()
// ----------------------------------------------------------------------
function Add_PageTab(stItem, stLink, stWidth, stImgWidth)
{
	//		stLocURL = GetLocalURL(gstLocation, "health_tips.shtml");
	// write a tab  
    if(stLink==""){
		document.writeln('<TD><IMG SRC="../images/client/tab_left_sel.gif" WIDTH="12" HEIGHT="21" BORDER=0></TD>'); 
    	document.writeln('<TD width="'+stWidth+'" align="center" background="../images/client/tab_ctr_sel.gif"><IMG SRC="../images/client/tab_link_'+stItem+'_sel.gif" WIDTH="'+stImgWidth+'" HEIGHT="21" BORDER=0></TD>');
		document.writeln('<TD><IMG SRC="../images/client/tab_right_sel.gif" WIDTH="16" HEIGHT="21" BORDER=0></TD>');
	}
	else{
		document.writeln('<TD><IMG SRC="../images/client/tab_left_unsel.gif" WIDTH="12" HEIGHT="21" BORDER=0></TD>'); 
    	document.writeln('<TD width="'+stWidth+'" align="center" background="../images/client/tab_ctr_unsel.gif">');
	 	document.writeln('<a href="'+stLink+'" target="'+gstTarget+'"><IMG SRC="../images/client/tab_link_'+stItem+'_unsel.gif" WIDTH="'+stImgWidth+'" HEIGHT="21" BORDER=0></a></TD>');
		document.writeln('<TD><IMG SRC="../images/client/tab_right_unsel.gif" WIDTH="16" HEIGHT="21" BORDER=0></TD>');
	}	
}

// ----------------------------------------------------------------------
// Add_PageFooterLink()
// ----------------------------------------------------------------------
function Add_PageFooterLink(stItem, stLink, stWidth)
{
	// write link  
    if(stLink==""){
    	document.writeln('<TD nowrap class="navlnk1"><font size=-1>&nbsp;&nbsp;'+stItem+'</font>&nbsp;&nbsp;</TD>');
	}
	else{
    	document.writeln('<TD nowrap class="navlnk2"><font size=-1>&nbsp;&nbsp;');
		document.writeln('<a href="'+stLink+'" target="'+gstTarget+'">'+stItem+'</a></font>&nbsp;&nbsp;</TD>');
	}	
}

// ----------------------------------------------------------------------
// Begin_PageTabBody()
// ----------------------------------------------------------------------
function Begin_PageTabBody()
{
	// end tabs table 
    document.writeln('</TR></TABLE></span></TD>');
	
	// right spacer and end tabs row
	document.write('<td rowspan="2"><img src="../images/client/pic_spacer.gif" alt="" width="1" height="10" border="0">');
	document.writeln('</td></TR>');
	
	// begin border row and table
	document.writeln('<TR valign="top"><TD>'); 
	document.writeln('<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#999999" bordercolordark="#666666">');
	document.writeln('<TR valign="top"><TD height="300" >');

	// begin inner table and row
	//document.writeln('<table width="95%" border="0" align="center"><tr><td>');	
	document.writeln('<table width="95%" border="0" align="center">');	
	
}	

// ----------------------------------------------------------------------
// End_PageTabs()
// ----------------------------------------------------------------------
function End_PageTabs(stCatCompare)
{
	// show bottom navigation ??
	if (stCatCompare != null){
		document.writeln('<TR><TD><TABLE width="100%" align="left" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR>');
		for (n=0; n<gnNavMax; n++){
			if(gstNavMatrix[n][NAV_CATEGORY].indexOf(gstParent)==0){
				if (stCatCompare.indexOf(gstNavMatrix[n][NAV_CATEGORY])==0){         
					Add_PageFooterLink(gstNavMatrix[n][NAV_CATEGORY], "", gstNavMatrix[n][NAV_WIDTH], gstNavMatrix[n][NAV_WIDTH]);
				}
				else {
					Add_PageFooterLink(gstNavMatrix[n][NAV_CATEGORY], GetLocalURL(gstLocation, gstNavMatrix[n][NAV_URL]), gstNavMatrix[n][NAV_WIDTH]);
				} 
			}
		}
		document.write('</TR><TR><td ><img src="../images/client/pic_spacer.gif" alt="" width="1" height="10" border="0">');
		document.writeln('</TR></TABLE></TD></TR>');
	}
  	// end bottom navigation
	
  	// end of inner table
  	//document.writeln('</TD></TR></TABLE>');
  	document.writeln('</TABLE>');
	
  	// end of border table
  	document.writeln('</TD></TR></TABLE>');
	
  	// end of outer table
  	document.writeln('</TD></TR></TABLE>');
}

// ----------------------------------------------------------
// FUNCTION: New_Window
// ----------------------------------------------------------
function New_Window(stHRef, stSize)
{
	winNew= window.open(stHRef, 'newWin', stSize);
	//winNew= window.open(stHRef, 'newWin', '');
	winNew.moveTo(10,10);
	winNew.focus();
	//winNew.document.writeln('<br>test');
	//winNew.print();
}
// ----------------------------------------------------------------------
// PICTURE CONTROL VARIABLES
// ----------------------------------------------------------------------
gnSmPicMax = 0;
gnLgPicMax = 0;
gnPicWidthMax = 0;
var gstSmPic = new Array(25);
var gstLgPic = new Array(25);
var gstLgSize = new Array(25);
var gstCaption = new Array(25);
gstPicMode="SMALL";

// ----------------------------------------------------------------------
// AddPicture()
// ----------------------------------------------------------------------
function AddPicture(stParam, stCaption, stWidth, stHeight){
	nWidth = (stWidth*1)+20;
	nHeight = (stHeight*1)+30;
	if(gstPicMode=="SMALL") {
		if (nWidth>gnPicWidthMax){
			gnPicWidthMax=nWidth;
		}
		gstSmPic[gnSmPicMax] = stParam;
		gstCaption[gnSmPicMax] = stCaption;
		gnSmPicMax++;
	}
	else {
		gstLgPic[gnLgPicMax] = stParam;
		gstLgSize[gnLgPicMax] = "width="+nWidth+",height="+nHeight;
		gnLgPicMax++;
	}
}
// ----------------------------------------------------------------------
// ShowPictures()
// ----------------------------------------------------------------------
function ShowPictures() {
	document.writeln('<TABLE width='+ gnPicWidthMax +' cellSpacing=1 cellPadding=2 border=0 align=right>');
	stCapWidth=gnPicWidthMax-75;
	for (n = 0; n<gnSmPicMax; n++) {
		document.writeln('<tr><td colspan=2 align=center><img src="' + gstSmPic[n] +'" border="0"></td></tr>');
		document.writeln('<tr><td width="'+ stCapWidth +'" class="text10" align=center>' + gstCaption[n] +'</td>');
		if (n<gnLgPicMax){
			stLgPic = gstLgPic[n];
			stLgSize = gstLgSize[n];
			document.writeln('<td width=75 valign=top><a href="javascript:New_Window(\''+ gstLgPic[n] +'\',\''+ gstLgSize[n] +'\')"><img src="../images/client/btn_enlarge.gif" ');
			document.writeln(' width=75 height=18 border=0 alt="enlarge this image"></a></td></tr>');
		}
		else {
			document.writeln('<td class="text10">&nbsp;</td></tr>');
		}
		document.writeln('<tr><td colspan=2><img src="../images/set1_maple/spacer.gif" height=1 width=7></td>');
	}
	document.writeln('</TABLE>');
}