// Timeless Candy Source Java Files		6/09/2006
// Written by Richard Kuether

// This script controls the page buttons to indicate product type
// section to the user

// Active web page buttons refer to the following URL's:
//	          Home  = 'http://timelesscandy.com/'
//	     Nav Button = 'http://timelesscandy.com/xxx.html'
//	Product Buttons = 'http://timelesscandy.com/sectionpages/xxx.html'
//	  Shopping Cart = 'https://order.store.yahoo.net/.....'


// These variables control the Enable/Disable status of the page buttons
// Nav buttons
var bHome=bContact=bPayment=bShipping=bReturn=bPrivacy=bShopping = 0;

// Product buttons
var bWhatsNew=bCandy=bGummi=bGum=bJerky=bLollipop=bMisc=bNonChoc=bNostalgic=0;
var bNovelty=bNuts=bPopular=bSeason=bSweetTart=bTaffy=0;
var prod = 0;

// Determine the active page and set the approriate button variable
function chkButtons()
{
	var s = document.location.href;		// get page filename
//	alert("chkButtons s="+s);			// test

	if (s.indexOf('order.store.yahoo.net') != -1)	// shopping cart page
		{
		bShopping = 1;					// activate shopping cart button
		return;							// all done
		}

 	if ((s.indexOf('products') != -1) ||		// product page -or-
		  (s.indexOf('out-of-stock') != -1))	// out-of-stock page
		{
		prod = 1;								// indicates a product page
		s = document.referrer;					// get the refering page
//		alert("chkButtons referrer s="+s);		// test
		if (s.indexOf('sectionpages') == -1)	// not called from section page
			{									// get pagename from cookie
			s = getCookie('timelesspage');		// get the cookie
//			alert("chkButtons getCookie s="+s);	// test
			if (s == null)						// no cookie
				return;							// bail out without setting button
			}
		}
	
// 's' should be the pagename for either the Home page, a Nav button
// or a Product button

	var i=s.indexOf('.htm');				// find .html OR .htm extention
	for (i ;i>0 ;i--)						// search string backwards for last "/"
		{if (s.charAt(i) == '/'){break;}	// found character
		}
	var f=s.substring(++i,i+7)				// get the first 7 chars of filename
//	alert("chkButtons f="+f);				// test
		  
	switch (f)						// set the active page button
		{
		case "http://":
		case "index.h": 
		case "home.ht": bHome=1;		break;
		case "contact": bContact=1;		break;
		case "payment": bPayment=1;		break;
		case "shippin": bShipping=1;	break;
		case "return-": bReturn=1;		break;
		case "privacy": bPrivacy=1;		break;
		case "WhatsNe": bWhatsNew=1;	break;
		case "CandyBa": bCandy=1;		break;
		case "GummiCa": bGummi=1;		break;
		case "GumMint": bGum=1;			break;
		case "JerkyMe": bJerky=1;		break;
		case "Lollipo": bLollipop=1;	break;
		case "Miscell": bMisc=1;		break;
		case "Non-Cho": bNonChoc=1;		break;
		case "Nostalg": bNostalgic=1;	break;
		case "Novelty": bNovelty=1;		break;
		case "NutsSee": bNuts=1;		break;
		case "Popular": bPopular=1;		break;
		case "Christm":
		case "Valenti":
		case "Hallowe":
		case "EasterC": 
		case "Seasona": bSeason=1;		break;
		case "SweeTar": bSweetTart=1;	break;
		case "TaffyCh": bTaffy=1;		break;
		}

// This take care of a product being called from the Home page
	if (bHome && prod) bHome=0;			// reset home button
	
// Now set a cookie for future reference
	var curCookie = "timelesspage=" + escape(s) + "; path=/" ;	// build cookie string
	document.cookie = curCookie;				// set the cookie
}

// Disable button mouse functions and replace image
function disableButton (imgid, pic)
{
//	alert("diableButton imgid="+imgid+"  pic="+pic);	//test
	FP_swapImg(1,0,imgid, pic);
	var i = document.getElementById(imgid);
	i.onmouseover = null; i.onmouseout = null; i.onmousedown = null; i.onmouseup = null;
	document.write ('<div id="'+imgid+'" onmouseover=null onmouseout=null onmousedown=null onmouseup=null><\/div>');
}

// Get a browser cookie
function getCookie(name)
{
	var dc = document.cookie;
//	alert("getCookie document.cookie="+document.cookie);	//test
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);	// locate cookie
	if (begin == -1)						// cookie not found
		{
		begin = dc.indexOf(prefix);			// check if it's the 1st cookie
		if (begin != 0) return null;		// no cookie found, return 'null'
		} else								// found the cookie
		begin += 2;							// bump the begining point
	
	var end = dc.indexOf(";", begin);		// find the end of the cookie
	if (end == -1)							// must be the last cookie
		end = dc.length;					// set the ending point

// Return the cookie string
	return unescape(dc.substring(begin + prefix.length, end));
}



// ------------------------------------------------------------
// The following functions are produced by MS Frontpage

function FP_swapImg() {
	var doc=document,args=arguments,elm,n;
//	alert("FP_swapImg doc="+doc+"  args="+args);	// test
	doc.$imgSwaps=new Array();
	for(n=2; n<args.length;	n+=2) {
		elm=FP_getObjectByID(args[n]);
		if(elm) {
			doc.$imgSwaps[doc.$imgSwaps.length]=elm;
			elm.$src=elm.src;
			elm.src=args[n+1];
		}
	}
}

function FP_preloadImgs() {
	var d=document,a=arguments;
//	alert("FP_preloadImgs d="+d+"  a="a);	// test
	if(!d.FP_imgs) d.FP_imgs=new Array();
	for(var i=0; i<a.length; i++) {
		d.FP_imgs[i]=new Image;
		d.FP_imgs[i].src=a[i];
	}
}

function FP_getObjectByID(id,o) {
//	alert("FP_getObjectByID id="+id+"  o="+o);
	var c,el,els,f,m,n;
	if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
	else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
	if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
		for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
	f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
	for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
	return null;
}

//  End of File
