/******************************************************************* actiniccore.js */
/***********************************************************************
* setCookie			Generic Set Cookie routine
* Input: sName	Name of cookie to create
*			sValue		Value to assign to the cookie
*			sExpire		Cookie expiry date/time (optional)
* Returns:			null
************************************************************************/
function setCookie(sName, sValue, sExpire)
{
	var sCookie = sName + "=" + escape(sValue) +"; path=/";		// construct the cookie
	if (sExpire) {
		sCookie += "; expires=" + sExpire.toGMTString();				// add expiry date if present
	}
	document.cookie = sCookie;																// store the cookie
	return null;
}

/***********************************************************************
* getCookie			Generic Get Cookie routine
* Input: sName	Name of cookie to retrieve
* Returns:			Requested cookie or null if not found
************************************************************************/
function getCookie(sName)
{
	var sCookiecrumbs = document.cookie.split("; "); 					// break cookie into crumbs array
	var sNextcrumb
	for (var i=0; i < sCookiecrumbs.length; i++) {
		sNextcrumb = sCookiecrumbs[i].split("=");								// break into name and value
		if (sNextcrumb[0] == sName) {														// if name matches
			return unescape(sNextcrumb[1]); 											// return value
		}
	}
	return null;
}

/***********************************************************************
* saveReferrer 	Saves the referrer to a Cookie
* Input: 				nothing
* Returns:			null
************************************************************************/
function saveReferrer()
{
	var bSetCookie = false;
	if (parent.frames.length == 0) {												// No FrameSet
		bSetCookie = true;
	} else {																								// FrameSet in use
		var bCatalogFrameSet = false;
		for (var nFrameId = parent.frames.length; nFrameId > 0; nFrameId--) {
			if (parent.frames[nFrameId - 1].name == 'CatalogBody') {	// Catalog FrameSet used
				bCatalogFrameSet = true;
				break;
			}
		}
		if (bCatalogFrameSet)	{																// Catalog FrameSet
			if (window.name=='CatalogBody') {										// and this is the CatalogBody frame
				bSetCookie = true;
			}
		}	else {																							// Not Catalog FrameSet
			bSetCookie = true;
		}
	}
	if (bSetCookie)	{
		var sUrl = document.URL;
		var nHashPos = sUrl.lastIndexOf("#");									// Look for URL anchor
		if (nHashPos > 0)	{																		// if it exists
			sUrl = sUrl.substring(0,nHashPos);									// then remove it
		}
		setCookie("ACTINIC_REFERRER", sUrl);									// Emulates HTTP_REFERER
	}
	return null;
}

saveReferrer();																						// For v6 only, should be in templates for v7

/***********************************************************************
* CreateArray	creates an array with n elements
* Input: n	-	number of elements
* Returns:		the created array
************************************************************************/
function CreateArray(n)
{
	this.length = n;
	for (var i=1; i <= n; i++) {														// for all ns
		this[i] = new Section();															// create a section structure
	}
	return this;
}

/***********************************************************************
* Section	-	creates the section structure for raw section lists
* Input: 				nothing
* Returns:				nothing
************************************************************************/
function Section()
{
	this.sURL = null;
	this.sName = null;
	this.sImage = null;
	this.nImageWidth = null;
	this.nImageHeight= null;
	this.nSectionId	= null;
	this.pChild = null;
}

/***********************************************************************
* SwapImage 		-	swaps an image to the alternative
* Input: sName 	-	name of the image
*			sAltImage-	filename of the alternative image
************************************************************************/

function SwapImage(sName, sAltImage)
{
	var nCount = 0;
	document.aSource = new Array; 													// array for images
	if (document[sName] != null) {													// if image name exists
		document.aSource[nCount++] = document[sName];					// store image
		if(null == document[sName].sOldSrc) {
			document[sName].sOldSrc = document[sName].src;			// store image source
		}
		document[sName].src = sAltImage; 											// change image source to alternative
	}
}

/***********************************************************************
* RestoreImage 		restores an image to the original
* Input: 					nothing
* Returns:				nothing
************************************************************************/

function RestoreImage()
{
	var nCount, aSource = document.aSource;
	if (aSource != null) { 																	// if array of images exists
		for(nCount=0; nCount < aSource.length; nCount++) {		// restore all images
			if ((aSource[nCount] != null) &&
				(aSource[nCount].sOldSrc != null)) {							// if we stored something for this image
				aSource[nCount].src = aSource[nCount].sOldSrc;		// restore the original image
			}
		}
	}
}

/***********************************************************************
* PreloadImages		-	restores an image to the original
* Input: 					nothing
* Returns:				nothing
************************************************************************/

function PreloadImages()
{
	if(document.images) {
		if(!document.Preloaded) { 														// preload array defined?
			document.Preloaded = new Array();										// no, define it
		}
		var nCounter , nLen = document.Preloaded.length, saArguments = PreloadImages.arguments;
		for(nCounter = 0; nCounter < saArguments.length; nCounter++) {	// iterate through arguments
			document.Preloaded[nLen] = new Image;
			document.Preloaded[nLen++].src = saArguments[nCounter];
		}
	}
}

/***********************************************************************
* ShowPopUp		-	creates pop up window
* Input: sUrl		-	URL o page to display
*			nWidth	-	Width of window
*			nHeight	-	Height of window
* Returns:				nothing
************************************************************************/
function ShowPopUp(sUrl, nWidth, nHeight)
{
	window.open(sUrl, 'ActPopup', 'width=' + nWidth + ',height=' + nHeight + ',scrollbars, resizable');
}

/******************************************************************* actinicextras.js */
/***********************************************************************
* getCartItem		-	Gets the Actinic Cart Value & No of Items
*
* Input: nIndex	-	Cart item index to retrieve
*							1 = TOTAL_VALUE
*							3 = CART_COUNT
* Returns:				Requested cart item or 0 (zero) if not found
************************************************************************/
function getCartItem(nIndex)
{
	var act_cart= getCookie("CART_CONTENT")
	var sTemp =(act_cart != null) ? sTemp=act_cart.split("\t"):0;
	return (sTemp.length > 0) ? sTemp[nIndex] : 0;
}
	
/***********************************************************************
* win	- calls up the WUP window
* Input: 				nothing
* Returns:				nothing
************************************************************************/
function win()
{
	var sMsg = window.open("paycash1.htm","","height = 507, width = 400, left = 378, top = 40");
}

/***********************************************************************
* GotoAnchor - JS for jumping to an anchor - some user agents don't handle
*					anchors correctly if BASE HREF is present
* Input: 				sAnchor
* Returns:				nothing
************************************************************************/
function GotoAnchor(sAnchor)
{
	window.location.hash = sAnchor;
}

/******************************************************************* SS Custom Js Code */
function GetExpandList(sections, homeLink) {
	var returnString= '';

	returnString+='  <ul>';
	if(sections != null) {
		for (var i = 1; i <= sections.length; i++) { 
			if(sections[i].pChild && sections[i].pChild.length > 0) {
				returnString+='    <li><a href="javascript:;" onclick="SS_ExpandMe(\''+sections[i].nSectionId+'\')">'+sections[i].sName+'</a>';
				returnString+='<ul style="display:none;" id="'+sections[i].nSectionId+'">';
				
				for(var j=1; j<=sections[i].pChild.length; j++) {
					returnString+='  <li><a href="'+sections[i].pChild[j].sURL+'">'+sections[i].pChild[j].sName+'</a></li>';
				}
				returnString+='  </ul></li>';
			} else {
				returnString+='  <li><a href="'+sections[i].sURL+'">'+sections[i].sName+'</a></li>';
			}
		}
	}
	returnString+='  </ul>';
	return returnString;
}

var preText = "";
var postText = "";
var noItemText = "";
var itemTpl = "<a href='{URL}'>{NAME}</a><br />";
var nameWidth = 0;

function SS_TopSectionList(sectionList,preText,postText,noItemText,itemTpl,nameWidth) {
	var returnString = preText;
	if(sectionList==null)
		return noItemText;
	
	var itemText;
	for (var i = 1; i <= sectionList.length; i++) {
		itemText = itemTpl;
		itemText = itemText.replace("{URL}",sectionList[i].sURL);
		if(nameWidth!=0)
			itemText = itemText.replace("{NAME}",sectionList[i].sName.substring(0,nameWidth));
		else
			itemText = itemText.replace("{NAME}",sectionList[i].sName);
		itemText = itemText.replace("{IMAGE}",sectionList[i].sImage);
		itemText = itemText.replace("{ID}",sectionList[i].nSectionId);
		itemText = itemText.replace("{IMAGE_WIDTH}",sectionList[i].nImageWidth);
		itemText = itemText.replace("{IMAGE_HEIGHT}",sectionList[i].nImageHeight);
		
		returnString += itemText;
	}

	returnString += postText;
	return returnString;
}

function SS_ExpandNavList(sections, homeLink) {
	return  GetExpandList(sections, homeLink);
}

function SS_ExpandMe(obj){
	var el="";
	if(section_tree != null) {
		for (var i = 1; i <= section_tree.length; i++) { 
			if(el = document.getElementById(section_tree[i].nSectionId)){
				el.style.display = "none";
			}
		}
	}
	if(document.getElementById){
		el = document.getElementById(obj);
		el.style.display = "block";
	}
}

function GetLeftNav(pSectionArray, HomeLink) {
	var returnString = '';
	if(pSectionArray != null) {
		for (var i = 1; i <= pSectionArray.length; i++) { 
			returnString+='<a href="'+pSectionArray[i].sURL+'">'+pSectionArray[i].sName+'</a>          <br />';
		}
	}

	return returnString;
	/*
	if(typeof(document.forms[1]) != 'object')
		return GetTopNav(pSectionArray, HomeLink);
		
	if(typeof(document.forms[1].SID) != 'object') {
		return GetTopNav(pSectionArray, HomeLink);
	}	else {
		return GetSubNav(pSectionArray, HomeLink);
	}
	*/
}
