// ----------------------------------------------------------------------
// NAVIGATION ROUTINES
// ----------------------------------------------------------------------
gnInventoryMax = 0;
INVENTORY_ID = 0; 
INVENTORY_ONHAND = 1; 
INVENTORY_AVAILABILITY = 2;
gnInventoryMax = 0; 
var gsInventory = new Array(100); 

// ----------------------------------------------------------------------
// GetAvailability
// ----------------------------------------------------------------------	
function GetAvailability(stInventoryID)
{
	if ( stInventoryID.indexOf("_")>=0 ) {
		stInventoryID = stInventoryID.substr(stInventoryID.indexOf("_")+1);
		//alert(stInventoryID);
	}

	stAvailability='<font color="#CC0000">PLEASE CALL</font>';

	for (nItem=0; nItem<gnInventoryMax; nItem++){
		if (stInventoryID==gsInventory[nItem][INVENTORY_ID]){
			nOnHand = gsInventory[nItem][INVENTORY_ONHAND];
			stAvailTemp = gsInventory[nItem][INVENTORY_AVAILABILITY];
			if (stAvailTemp!="") {
				stAvailability = '<font color="#9900CC">'+stAvailTemp+'</font>';
			}
			if (nOnHand>0) {
				stAvailability = '<font color="#009900">IN STOCK</font>';
			}
			break;
		}
	}
	return stAvailability;	
}



// ----------------------------------------------------------
// FUNCTION: SetItemPage
// ----------------------------------------------------------
function SetItemPage(stLink)
{
		SetCookieValue("ItemPage", stLink);
		//alert("cookie set to:"+stLink);
		window.location=stLink;
}
// ----------------------------------------------------------
// FUNCTION: GetItemPage
// ----------------------------------------------------------
function GetItemPage(stDefault)
{
		stLink=GetCookieValue("ItemPage");
		if (stLink==""){
			stLink=stDefault;
		}
		//alert("stLink:"+stLink);
		window.location=stLink;
}
// ----------------------------------------------------------
// FUNCTION: WriteCartButton
// ----------------------------------------------------------
function WriteCartButton(stProduct, stProdData, stOrderForm)
{
	stCart = GetCookieValue("Cart");
	if (stCart==null){
		stCart="Cart: ";
	}
	if ( stCart.indexOf(stProdData) >=0) {
		document.write("<IMG NAME='BTN_" +stProduct+ "' SRC='../images/client/btn_cart_on.gif' ALT='Remove from Shopping Cart' BORDER='0'>");
	}
	else {
		document.write("<IMG NAME='BTN_" +stProduct+ "' SRC='../images/client/btn_cart_off.gif' ALT='Add to Shopping Cart' BORDER='0'>");
	}
}	
// ----------------------------------------------------------
// FUNCTION: UpdateCart
// ----------------------------------------------------------
function UpdateCart(stProduct, stProdData, stOrderForm)
{
	stCart = GetCookieValue("Cart");
	if (stCart==null){
		stCart="Cart: ";
	}
	if ( stCart.indexOf(stProdData)>=0) {
		stCart=stCart.replace(stProdData, "");
		
		//alert('del['+stCart+']');
		document.cookie = "Cart=" + stCart +";expires=" ;
		temp = "document.BTN_"+stProduct+".src='../images/client/btn_cart_off.gif'";
		//alert('temp['+temp+']');
		eval(temp);
	}
	else {
		//alert('add['+stCart+']');
		document.cookie = "Cart=" + stCart + " " + stProdData +";expires=" ;
		temp = "document.BTN_"+stProduct+".src='../images/client/btn_cart_on.gif'";
		eval(temp);
		if (stOrderForm != "") {
			window.location = stOrderForm;
		}
	}
}
// ----------------------------------------------------------------------
// 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();
}

function GetParent(stName)
{	
	stParent=stName;
	if (stName.indexOf(" - ")>0) {
		stParent = stName.substr(0,stName.indexOf(" - "));
	} 
	return stParent;	
}
function GetChild(stName)
{	
	stChild=stName;
	if (stName.indexOf(" - ")>0) {
		stChild = stName.substr(stName.indexOf(" - ")+3);
	} 
	return stChild;	
}
function GetParameter(stParamString, stParam)
{	
	stValue="";
	stParamString=stParamString.toUpperCase();
	if (stParamString.indexOf(stParam)>-1) {
		stValue = stParamString.substr(stParamString.indexOf(stParam)+stParam.length+1,3);
	} 
	return stValue;	
}
// ----------------------------------------------------------------------
// 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;	
}

// ----------------------------------------------------------------------
// GetCatHeading
// ----------------------------------------------------------------------	
function GetDocHeading(stDocName)
{	
	stHeading=stDocName;
	if (stDocName.indexOf(" - ")>0) {
		stHeading = stDocName.substr(0,stDocName.indexOf(" - "));
	} 
	else {
		if (stDocName.indexOf(" (")>0) {
			stHeading = stDocName.substr(0,stDocName.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.write('<div align="center"><font class="arthead">'+ gstNavMatrix[n][NAV_PAGEHEAD] +'</font></div>');
			//document.write('<img src="../images/spacer.gif" height=25 width=1>');
			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)
{
	// 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>');
	}	
}

// ----------------------------------------------------------------------
// 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/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="#444444" bordercolordark="#444444">');
	document.writeln('<TR valign="top"><TD height="300" >');

	// begin inner table and row
	document.writeln('<table width="95%" border="0" align="center"><tr><td>');	
	
}	

// ----------------------------------------------------------------------
// End_PageTabs()
// ----------------------------------------------------------------------
function End_PageTabs()
{
  	// end of inner table
  	document.writeln('</TD></TR></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(0,0);
	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++) {
		
		// write cell for small picture
		document.writeln('<tr><td colspan=2 align=center><img src="' + gstSmPic[n] +'" alt="YMCA Camp Mohawk in Litchfield, Connecticut (CT) offers both girls overnight camping and day camping with activities including horseback riding, swimming, sailing, tennis, and other sports. It is the experience that lasts a lifetime!" border="0"></td></tr>');
		
		// write cell(s) for Caption and Enlarge Button (optional, only if LgPic exists)
		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>');
		}
		// spacer row
		document.writeln('<tr><td colspan=2><img src="../images/spacer.gif" height=1 width=7></td>');
	}
	document.writeln('</TABLE>');
}

// ----------------------------------------------------------------------
// ShowPicturesNew()
// ----------------------------------------------------------------------
function ShowPicturesNew(nMaxAcross) {
	stCapWidth=gnPicWidthMax-75;
	nAcrossCount=0;
	if (nMaxAcross<=1){
		document.writeln('<TABLE cellSpacing=1 cellPadding=2 border=0 align=right><tr>');
		nMaxAcross=1; 
	}
	else {
		document.writeln('<TABLE cellSpacing=1 cellPadding=2 border=0 align=center><tr>');
	}
	for (n = 0; n<gnSmPicMax; n++) {
		
		// start a new row??
		nAcrossCount++;
		if (nAcrossCount>nMaxAcross){ 
			document.writeln('</tr><tr>');
			nAcrossCount=1;
		}		
		
		// write cell for small picture
		document.writeln('<td><TABLE width='+ gnPicWidthMax +' cellSpacing=0 cellPadding=0 border=0 align=right>');

		document.writeln('<tr><td colspan=2 align=center><img src="' + gstSmPic[n] +'" alt="YMCA Camp Mohawk in Litchfield, Connecticut (CT) offers both girls overnight camping and day camping with activities including horseback riding, swimming, sailing, tennis, and other sports. It is the experience that lasts a lifetime!" border="0"></td></tr>');
		
		// write cell(s) for Caption and Enlarge Button (optional, only if LgPic exists)
		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>');
		}
		// spacer row
		document.writeln('<tr><td colspan=2><img src="../images/spacer.gif" height=1 width=7></td>');
		document.writeln('</TABLE><td>');
		
		
	}
	document.writeln('</tr></TABLE>');
}


