// encrypt.js
var lineFeed="\n";
var doubleQuote='"';
var clearMessage=new Number(5000);


// cookies.js
var expDays=30;
var exp=new Date();
exp.setTime(exp.getTime()+(expDays*24*60*60*1000));
function getCookieVal(B){var A=document.cookie.indexOf(";",B);if(A==-1){A=document.cookie.length}return unescape(document.cookie.substring(B,A))}
function GetCookie(D){var B=D+"=";var F=B.length;var A=document.cookie.length;var E=0;while(E<A){var C=E+F;if(document.cookie.substring(E,C)==B){return getCookieVal(C)}E=document.cookie.indexOf(" ",E)+1;if(E==0){break}}return null}
function SetCookie(C,E){var A=SetCookie.arguments;var H=SetCookie.arguments.length;var B=(H>2)?A[2]:null;var G=(H>3)?A[3]:null;var D=(H>4)?A[4]:null;var F=(H>5)?A[5]:false;document.cookie=C+"="+escape(E)+((B==null)?"":("; expires="+B.toGMTString()))+((G==null)?"":("; path="+G))+((D==null)?"":("; domain="+D))+((F==true)?"; secure":"")}
function DeleteCookie(A){var C=new Date();C.setTime(C.getTime()-1);var B=GetCookie(A);document.cookie=A+"="+B+"; expires="+C.toGMTString()}

// paging.js
var defaultSort, defaultContentsFormat, contentsFormat, tableWidth, numColumns, getPerPage, numPerPage, contentsElements, showDefaultSort,
    detailedSortInfo, showPagingModes, viewAll, sortBy, sortHighLow, pageLinkPrefix, rowpad, columnpad, storename, columnSeparatorColor,
    rowSeparatorColor, listModeBG1, listModeBG2, sortLinkSeparator, sortLinkPrefix, modeLinkSeparator, pageLinkSeparator, globalPageNum, globalViewallthistime,
    currentItem, currentItemImage, numArrowDivs, showListMode, addToCartImage, showBrandSort, strikePrice, showWrapMode, showQuantity, listModeShowImages;
var pageItems = new Array();
var oldSortBy = "";

var getPerPage = GetCookie('getPerPage');
if(!getPerPage) getPerPage = 20;


function pagingItem(id, code, name, img, listimg, price, saleprice, options, abstr, orderable, brand, mappricing, linktype, link) {
	if (!window.items) window.items = new Array();
	this.id=id.toLowerCase();
	this.code=code;
	this.name=name;
	this.img=img;
	this.listimg=listimg;
	this.price=round_decimals(price,2);
	this.saleprice=round_decimals(saleprice,2);
	if(saleprice) this.useprice=round_decimals(saleprice,2); else this.useprice=round_decimals(price,2);
	this.options=options;
	this.abstr=abstr;
	this.orderable=orderable;
	this.brand=brand;
	this.mappricing=mappricing;
	this.linktype=linktype;
	this.link=link;
	this.sortby="name";
	this.defaultsort=window.items.length;
	window.items[window.items.length] = this;
}

/* round_decimals, pad_with_zeros, FIND, pagingSegment, sortArray */

function round_decimals(original_number, decimals) {
	var result1 = original_number * Math.pow(10, decimals)
	var result2 = Math.round(result1)
	var result3 = result2 / Math.pow(10, decimals)
	return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {
	var value_string = rounded_value.toString()
	var decimal_location = value_string.indexOf(".")
	if (decimal_location == -1) {
		decimal_part_length = 0
		value_string += decimal_places > 0 ? "." : ""
	}
	else {
		decimal_part_length = value_string.length - decimal_location - 1
	}
	var pad_total = decimal_places - decimal_part_length
	if (pad_total > 0) {
		for (var counter = 1; counter <= pad_total; counter++) 
			value_string += "0"
		}
	return value_string
}

function FIND(item) {
	if (document.getElementById) return(document.getElementById(item));
	if (document.all) return(document.all[item]);
	return(false);
};

function pagingSegment(theArray,pageNum) {
	var newArray = new Array();
	var pageOffset = (pageNum-1)*numPerPage;
	var pageTotal = theArray.length - pageOffset;
	pageTotal = (pageTotal > numPerPage) ? numPerPage : pageTotal;
	for(i=0; i<pageTotal; i++) {
		newArray[i] = theArray[i + pageOffset];
	}
	return newArray;
};

function sortArray(theArray, loBound, hiBound){
	var pivot, loSwap, hiSwap, temp;

	// Two items to sort
	if (hiBound - loBound == 1)
	{
		if (theArray[loBound].sortby > theArray[hiBound].sortby)
		{
			temp = theArray[loBound];
			theArray[loBound] = theArray[hiBound];
			theArray[hiBound] = temp;
		}
		return;
	}

	// Three or more items to sort
	pivot = theArray[parseInt((loBound + hiBound) / 2)];
	theArray[parseInt((loBound + hiBound) / 2)] = theArray[loBound];
	theArray[loBound] = pivot;
	loSwap = loBound + 1;
	hiSwap = hiBound;

	do {
		while (loSwap <= hiSwap && theArray[loSwap].sortby <= pivot.sortby)
			loSwap++;
		while (theArray[hiSwap].sortby > pivot.sortby)
			hiSwap--;
		if (loSwap < hiSwap)
		{
			temp = theArray[loSwap];
			theArray[loSwap] = theArray[hiSwap];
			theArray[hiSwap] = temp;
		}
	} while (loSwap < hiSwap);

	theArray[loBound] = theArray[hiSwap];
	theArray[hiSwap] = pivot;

	// 2 or more items in first section
	if (loBound < hiSwap - 1)
		sortArray(theArray, loBound, hiSwap - 1);

	// 2 or more items in second section
	if (hiSwap + 1 < hiBound)
		sortArray(theArray, hiSwap + 1, hiBound);
};




/* changeClass, writePageLinks, writeItemXofX, writePageXofX */
function changeClass(which,theclass) {
	try {
		which.className = which.className.replace(/[evw]cell(?:-on)?/, "");
		which.className += " " + theclass;
	} catch (err) {}
}

function writePageLinks( viewallThisTime, pageNum, setPages) {
	if(setPages) numPages = setPages;
	if(numPages > 1) {
		var pageLinks = pageLinkPrefix;
		for(i=1; i<=numPages; i++) {
			if(i == pageNum && !viewallThisTime)
				pageLinks += "<span class=chosen>" + i + "</span>";
			else
				pageLinks += "<a href=#top onclick=javascript:writePage(" + i + ",false)>" + i + "</a>";
			if(i % 18 == 0)
				//pageLinks += "<!--br-->";
				pageLinks += "<span class=sep>" + pageLinkSeparator + "</span>";
			else if(i < numPages)
				pageLinks += "<span class=sep>" + pageLinkSeparator + "</span>";
		}
		if(viewAll) {
			pageLinks += "<span class=sep>" + pageLinkSeparator + "</span>";
			if(viewallThisTime)
				pageLinks += "&middot; <span class=chosen><span class=viewAll>View All</span></span>";
			else
				pageLinks += "&middot; <a href=#top onclick=javascript:changeSortAndPage(sortBy,false,0,true)><span class=viewAll>View All</span></a>";
		}
	
		var thePageDiv = FIND("pagelinks");
		if(thePageDiv) thePageDiv.innerHTML = pageLinks;
		thePageDiv = FIND("pagelinks2");
		if(thePageDiv) thePageDiv.innerHTML = pageLinks;
	}
};

function writeItemXofX(viewallthistime,pageNum) {
	var currentItemLow = ((pageNum - 1) * numPerPage + 1);
	var currentItemHigh = pageNum * numPerPage;
	var numItems = window.items.length;

	if((currentItemLow <= numItems) && (numItems <= currentItemHigh)) {
		currentItemHigh = numItems;
	}
	var theString = "";
	if(currentItemLow == currentItemHigh) {
		theString += "showing product <span class=prodNums>" + currentItemLow + "</span> of " + numItems ;
	} else if(viewallthistime) {
		theString += "showing products <span class=prodNums>1-" + numItems + "</span> of " + numItems ;
	} else {
		theString += "showing products <span class=prodNums>" + currentItemLow + "-" + currentItemHigh + "</span> of " + numItems ;
	}
	
	var theItemDiv = FIND("itemof");
	if(theItemDiv) theItemDiv.innerHTML = theString;
	theItemDiv = FIND("itemof2");
	if(theItemDiv) theItemDiv.innerHTML = theString;
};

function writePageXofX(viewallthistime,pageNum) {
	var localContent = "";
	if(viewallthistime)
		localContent += "Viewing all items";
	else
		localContent += "Page " + pageNum + " of " + numPages;

	if(detailedSortInfo) {
		if(sortBy == "default")
			localContent += " (default sort)";
		else {
			localContent += " <span class=detailedsortinfo>(sorted by " + sortBy;
			if(sortHighLow) localContent += " high to low)"; else localContent += " low to high)</span>";
		}
	}

	var pageofDiv = FIND("pageof");
	if(pageofDiv) pageofDiv.innerHTML = localContent;
	pageofDiv = FIND("pageof2");
	if(pageofDiv) pageofDiv.innerHTML = localContent;
};


/* writeArrows, writeUpDownArrow */
function writeUpDownArrow(divname) {
	if(divname) {
		localContent = "";
		if(sortHighLow) localContent += " " + upArrow; else localContent += " " + downArrow;
		divname.innerHTML = localContent;
	}
}

function writeArrows(viewallthistime,pageNum) {
	var localContent;
	var leftArrowString = "", rightArrowString = "";
	var upDownArrowDiv  = FIND(sortBy + "arrowdiv");
	var upDownArrowDiv2 = FIND(sortBy + "arrowdiv2");
	if(viewallthistime) {
		writeUpDownArrow(upDownArrowDiv);
		writeUpDownArrow(upDownArrowDiv2);
		leftArrowString += leftArrowG;
		rightArrowString += rightArrowG;
		for(i=1; i<=numArrowDivs; i++) {
			localDiv = FIND("rightArrowDiv" + i);
			if(localDiv) localDiv.innerHTML = rightArrowString;
			localDiv = FIND("leftArrowDiv" + i);
			if(localDiv) localDiv.innerHTML = leftArrowString;
		}
	} else {
		writeUpDownArrow(upDownArrowDiv);
		writeUpDownArrow(upDownArrowDiv2);
		if(numPages == 1) {
			leftArrowString += leftArrowG;
			rightArrowString += rightArrowG;
		} else if(pageNum == 1) {
			leftArrowString += leftArrowG;
			rightArrowString += "<a href='#paging' onClick=javascript:writePage(2);window.location='#paging';return false;>" + rightArrow + "</a>";
		} else if (pageNum == numPages) {
			leftArrowString += "<a href='#paging' onClick=javascript:writePage(" + (numPages - 1) + ");window.location='#paging';return false;>" +  leftArrow + "</a>";
			rightArrowString += rightArrowG;
		} else {
			leftArrowString += "<a href='#paging' onClick=javascript:writePage(" + (pageNum - 1) + ");window.location='#paging';return false;>" + leftArrow + "</a>"
			rightArrowString += "<a href='#paging' onClick=javascript:writePage(" + (pageNum + 1) + "); window.location='#paging';return false;>" + rightArrow + "</a>";
		}
		for(i=1; i<=numArrowDivs; i++) {
			localDiv = FIND("rightArrowDiv" + i);
			if(localDiv) localDiv.innerHTML = rightArrowString;
			localDiv = FIND("leftArrowDiv" + i);
			if(localDiv) localDiv.innerHTML = leftArrowString;
		}
	}
};


/* pagingQuantity, pagingAddtoCart, pagingPrice */
function pagingPrice(localItem) {
	var onsale = (localItem.saleprice && localItem.saleprice != 0);
	var usemap = localItem.mappricing;
	var localContent = "";
	if(localItem.price != 0) {
		if(usemap && !onsale)
			localContent += mapPricing(localItem);
		else {
			localContent += "<div class=price" + ((!onsale)? "-bold" : "") + ">" + regularPriceText + " ";
			if(onsale && strikePrice) localContent += "<s>";
			localContent += "$" + localItem.price;
			if(onsale && strikePrice) localContent += "</s>";
			localContent += "</div>";
		}
	}
	if(onsale && usemap) localContent += mapPricing(localItem);
	if(onsale && !usemap) localContent += "<div class=saleprice>" + salePriceText + " <b>$" + localItem.saleprice + "</b></div><div class='you-save'>(Save: $" + parseFloat(localItem.price - localItem.saleprice).toFixed(2) + "  - " + parseInt(((localItem.price - localItem.saleprice) * 100) / localItem.price) + "%)</div>";	
	return localContent;
}

function pagingQuantity(localItem) {
	var localContent = "";
	if(localItem.useprice != 0)
		if(localItem.orderable) {
			localContent += "<span class=qtytext>Quantity: ";
			localContent += "<input type=text name=vwquantity size=2 class=qtybox value=1>";
			localContent += "</span>";
		} else 
			localContent += "";	
	return localContent;
}

function pagingAddToCart(localItem) {
	var localContent = "";
	if(localItem.useprice != 0 && !localItem.mappricing)
		if(localItem.orderable) {
			if(localItem.options) {
				localContent += "<a href=" + ((localItem.linktype) ? localItem.link : localItem.id + '.html') + " class=moreoptions>Click to See Options and to Order</a>";				
			} else {
				localContent += "<form method=post action=http://order.store.yahoo.net/cgi-bin/wg-order?" + storename + ">";
				if(showQuantity) localContent += pagingQuantity(localItem);
				localContent += "<input type=hidden name=vwcatalog value=" + storename + ">";
				localContent += "<input type=hidden name=vwitem value=" + localItem.id + ">";
				if(addToCartImage != "") 
					localContent += addToCartImage;
				else
					localContent += "<input type=submit id=submit value='Add to Cart'>"
				localContent += "</form>";
			}
		} else 
			localContent += "<span class=outofstock>Out of Stock</span>";	
	return localContent;
}


/* paging vertical */

function writeVerticalInfo(currentRow, numRows) {
	var localContent = "";
	localContent += "<tr valign=top>";
	//VERTICAL - LOOP CELLS
	for(currentCol=0; currentCol<numColumns; currentCol++) {
		localContent += "<td width=" + 100 / numColumns + "% height=100% align=center";
		if(pageSegment[currentItem]) localContent += " onmouseover=try{changeClass(this,'vcell-on');}catch(err){} onmouseout=try{changeClass(this,'vcell');}catch(err){} class='vcell infoCell' id=vcell" + currentItem;
		localContent += ">";
		if(pageSegment[currentItem]) {
			localItem = pageSegment[currentItem];
			if(contentsElements.indexOf("quantity")) showQuantity = true;
			var elementArray = contentsElements.split("/");
			for(i=0;i<elementArray.length;i++) {
				switch(elementArray[i]) {
					case "name":
						if(localItem.name != "") localContent += "<div class=name><a href=" + ((localItem.linktype) ? localItem.link : localItem.id + '.html') + ">" + localItem.name + "</a></div>";
					break
					case "code":
						if(localItem.code != "") localContent += "<div class=code>" + localItem.code + "</div>";
					break
					case "price":
						localContent += pagingPrice(localItem);
					break
					case "abstract":
						if(localItem.abstr != "") localContent += "<div class=abstract>" + localItem.abstr + "</div>";
					break
					case "brand":
						if(localItem.brand != "") localContent += "<div class=brand>" + localItem.brand + "</div>";
					break
					case "order":
						localContent += pagingAddToCart(localItem);
					break
					case "quantity": break
					case "image": break
				}
			}
			currentItem++;
		} else {
			localContent += " ";
		}
		localContent += "</form></td>";
		// if(currentCol < (numColumns - 1)) 
		//	localContent += writeCellPadding(currentItem);
	}
	localContent += "</tr>";
	if(currentRow < (numRows - 1))
		localContent += writeRowPadding((numColumns + (3 * (numColumns - 1))));
	return localContent;
};

function writeVerticalImage(currentRow, numRows) {
	var localContent = "";
	localContent += "<tr valign=bottom>";
	for(currentCol=0; currentCol<numColumns; currentCol++) {
		localContent += "<td class=imgCell width=" + 100 / numColumns + "% height=100% align=center";
		if(pageSegment[currentItemImage]) localContent += "  onmouseover=try{changeClass(FIND('vcell" + currentItemImage + "'),'vcell-on');}catch(err){} onmouseout=try{changeClass(FIND('vcell" + currentItemImage + "'),'vcell');}catch(err){}";
		localContent += ">";
		if(pageSegment[currentItemImage]) {
			localItem = pageSegment[currentItemImage];
			localContent += "<a href=" + ((localItem.linktype) ? localItem.link : localItem.id + '.html') + ">" + localItem.img + "</a>";
			currentItemImage++;
		} else {
			localContent += " ";
		}
		localContent += "</td>";
		if(currentCol < (numColumns - 1)) 
			localContent += writeCellPadding(currentItemImage, 2);
	}
	localContent += "</tr>";
	return localContent;
};

function writeVertical(pageNum, viewallthistime) {
	var localContent = "";
	var numRows = Math.ceil(pageSegment.length / numColumns);
	currentItem=0; currentItemImage = 0;
	for(currentRow=0; currentRow<numRows; currentRow++) {
		if(pageSegment[currentItem]) {
			if(contentsElements.indexOf("image") != -1) 
				localContent += writeVerticalImage(currentRow, numRows);
			localContent += writeVerticalInfo(currentRow, numRows);
		}
	}
	return localContent;
};


/* paging Ell */
function writeEllInfoCell(currentRow, numRows) {
	var localContent = "";
	localContent += "<td width=" + 100 / numColumns + "% height=100% align=left onmouseover=try{changeClass(this,'ecell-on');}catch(err){} onmouseout=try{changeClass(this,'ecell');}catch(err){} class='ecell infoCell' id=ecell" + currentItem + ">"
	if(pageSegment[currentItem]) {
		localItem = pageSegment[currentItem];
		if(contentsElements.indexOf("quantity")) showQuantity = true;
		var elementArray = contentsElements.split("/");
		for(i=0;i<elementArray.length;i++) {
			switch(elementArray[i]) {
				case "name":
					if(localItem.name != "") localContent += "<div class=name><a href=" + ((localItem.linktype) ? localItem.link : localItem.id + '.html') + ">" + localItem.name + "</a></div>";
				break
				case "code":
					if(localItem.code != "") localContent += "<div class=code>" + localItem.code + "</div>";
				break
				case "price":
					localContent += pagingPrice(localItem);
				break
				case "abstract":
					if(localItem.abstr != "") localContent += "<div class=abstract>" + localItem.abstr + "</div>";
				break
				case "brand":
					if(localItem.brand != "") localContent += "<div class=brand>" + localItem.brand + "</div>";
				break
				case "order":
					localContent += pagingAddToCart(localItem);
				break
				case "quantity": break
				case "image": break
			}
		}
		currentItem++;
	} else {
		localContent += " ";
	}
	localContent += "</td>";
	return localContent;
};

function writeEllImageCell() {
	var localContent = "";
	localContent += "<td align=center onmouseover=changeClass(FIND('ecell" + currentItem + "'),'ecell-on'); onmouseout=changeClass(FIND('ecell" + currentItem + "'),'ecell'); class='imgCell'>"
	if(pageSegment[currentItem]) {
		localItem = pageSegment[currentItem];
		localContent += "<a href=" + ((localItem.linktype) ? localItem.link : localItem.id + '.html') + ">" + localItem.img + "</a>";
	} else {
		localContent += " ";
	}
	localContent += "</td>";
	return localContent;
};

function writeEll(pageNum, viewallthistime) {
	var localContent = "";
	var numRows = Math.ceil(pageSegment.length / numColumns);
	currentItem=0; currentItemImage = 0;
	for(currentRow=0; currentRow<numRows; currentRow++) {
		if(pageSegment[currentItem]) {
			localContent += "<tr valign=top>";
			for(currentCol=0; currentCol<numColumns; currentCol++) {
				if(pageSegment[currentItem]) {
					if(contentsElements.indexOf("image") != -1) 
						localContent += writeEllImageCell();
					localContent += writeEllInfoCell();
				} else {
					if(contentsElements.indexOf("image") != -1) 
						localContent += "<td> </td>";
					localContent += "<td> </td>";
				}
				if(currentCol < (numColumns - 1)) 
					localContent += writeCellPadding();
			}
			localContent += "</tr>";
			if(currentRow < (numRows - 1))
				localContent += writeRowPadding((numColumns * 2 + (3 * (numColumns - 1))));
		}
	}
	return localContent;
};


/* paging wrap */
function writeWrapCell(currentRow, numRows) {
	var localContent = "";
	localContent += "<td width=" + 100 / numColumns + "% height=100% align=left onmouseover=try{changeClass(this,'wcell-on');}catch(err){} onmouseout=try{changeClass(this,'wcell');}catch(err){} class='wcell infoCell'>"
	if(pageSegment[currentItem]) {
		localItem = pageSegment[currentItem];
		if(contentsElements.indexOf("quantity")) showQuantity = true;
		var elementArray = contentsElements.split("/");
		for(i=0;i<elementArray.length;i++) {
			switch(elementArray[i]) {
				case "image":
					localContent += "<div class=image><a href=" + ((localItem.linktype) ? localItem.link : localItem.id + '.html') + ">" + localItem.img + "</a></div>";
				break
				case "name":
					localContent += "<div class=name><a href=" + ((localItem.linktype) ? localItem.link : localItem.id + '.html') + ">" + localItem.name + "</a></div>";
				break
				case "code":
					if(localItem.code != "") localContent += "<div class=code>" + localItem.code + "</div>";
				break
				case "price":
					localContent += pagingPrice(localItem);
				break
				case "abstract":
					if(localItem.abstr != "") localContent += "<div class=abstract>" + localItem.abstr + "</div>";
				break
				case "brand":
					if(localItem.brand != "") localContent += "<div class=brand>" + localItem.brand + "</div>";
				break
				case "order":
					localContent += pagingAddToCart(localItem);
				break
				case "quantity": break;
			}
		}
		currentItem++;
	} else {
		localContent += " ";
	}
	localContent += "</td>";
	return localContent;
};

function writeWrap(pageNum, viewallthistime) {
	var localContent = "";
	var numRows = Math.ceil(pageSegment.length / numColumns);
	currentItem=0; currentItemImage = 0;
	for(currentRow=0; currentRow<numRows; currentRow++) {
		if(pageSegment[currentItem]) {
			localContent += "<tr valign=top>";
			for(currentCol=0; currentCol<numColumns; currentCol++) {
				if(pageSegment[currentItem])
					localContent += writeWrapCell();
				else
					localContent += "<td> </td>";
				if(currentCol < (numColumns - 1)) 
					localContent += writeCellPadding();
			}
			localContent += "</tr>";
			if(currentRow < (numRows - 1))
				localContent += writeRowPadding((numColumns * 2 + (3 * (numColumns - 1))));
		}
	}
	return localContent;
};


/* writePage, changeSortAndPage */
function writePage(pageNum, viewallthistime) {
	
		var localContent = "";
		if((numPerPage > -1) && !(viewallthistime)) pageSegment = pagingSegment(window.items,pageNum); else pageSegment = window.items;
		writePageLinks(viewallthistime,pageNum);
		writeItemXofX(viewallthistime,pageNum);
		writePageXofX(viewallthistime,pageNum);
		writeSortLinks("",viewallthistime);
		writeSortLinks("2",viewallthistime);
		writePagingModesLinks();
		writeArrows(viewallthistime,pageNum);
	
		var numRows = Math.ceil(pageSegment.length / numColumns);
		switch(contentsFormat.toUpperCase()) {
			case "LIST":
				localContent += writeAsList(viewallthistime,pageNum);
			break
			case "VERTICAL":
				localContent += "<table cellspacing=0 cellpadding=0 width=" + tableWidth + " border=0>";

				localContent += writeVertical(pageNum, viewallthistime);
				localContent += "</table>";
			break
			case "ELL":
				localContent += "<table cellspacing=0 cellpadding=0 width=" + tableWidth + " border=0>";
				localContent += writeEll(pageNum, viewallthistime);
				localContent += "</table>";
			break
			case "WRAP":
				localContent += "<table cellspacing=0 cellpadding=0 width=" + tableWidth + " border=0>";
				localContent += writeWrap(pageNum, viewallthistime);
				localContent += "</table>";
			break
			default:
				writeAsList(viewallthistime,pageNum);
		}	
	
		var theDiv = FIND("contents");
		theDiv.innerHTML = localContent;
				
		temp = document.location.href.split(".");
		temp2 = temp[temp.length - 2].split("/");
		var currentPageHTML = temp2[temp2.length - 1] + ".html";
		
		SetCookie('thePage', pageNum, exp);
		SetCookie('theSort', sortBy, exp);
		SetCookie('thePageName', currentPageHTML, exp);
		if(sortHighLow) SetCookie('highlow', "1", exp); else SetCookie('highlow', "0", exp);
		SetCookie('contentsformat', contentsFormat, exp);
		if(viewallthistime) SetCookie('viewall', "1", exp); else SetCookie('viewall', "0", exp);
		
		globalPageNum = pageNum;
		globalViewallthistime = viewallthistime;
		
		if (window.scDp2DrawCallback) { scDp2DrawCallback.run(); }
};

function changeSortAndPage(newSortBy, newHighLow, pageNum, viewallthistime)
{
	sortBy = newSortBy;
	sortHighLow = newHighLow;

	updateSortBy(window.items, sortBy);
	sortArray(window.items,0,window.items.length-1);
	if(sortHighLow) window.items.reverse();

	if(viewallthistime)
		writePage(pageNum, true);
	else
		writePage(pageNum, false);
};









function writeCellPadding(num, rowspan) {
	if(num) localnum = num; else localnum = currentItem;
	var localContent = '<td class="verticalSpacer"' + ((rowspan)? (' rowspan=' + rowspan) : '') + '></td>'
	return localContent;
}

function writeRowPadding(colspan) {
	var localContent = "<tr><td class='horizontalSpacer' colspan=" + colspan + "></td></tr>";
	return localContent;
}

function initPaging() {
	var pageNum, viewallthistime = false, highlowthistime = false;

	var readName = GetCookie('thePageName');
	var readPage = GetCookie('thePage');
	var getPerPage = GetCookie('getPerPage');
	var readSort = GetCookie('theSort');
	var readHighLow = GetCookie('highlow');
	var readContentsFormat = GetCookie('contentsformat');
	var readViewAll = GetCookie('viewall');
	if(readViewAll == "1") viewallthistime = true;
	
	if(getPerPage) {
		numPerPage = getPerPage;
	}

	if(readName || readSort || readContentsFormat) {
		temp = document.location.href.split(".");
		temp2 = temp[temp.length - 2].split("/");
		currentPageHTML = temp2[temp2.length - 1] + ".html";
		if(readName == currentPageHTML)
			(readPage == 0) ? pageNum = 1 : pageNum = parseInt(readPage);
		else
			pageNum = 1;
		readSort ? sortBy = readSort : sortBy = defaultSort;
		(readHighLow == 1 && readSort) ? highlowthistime = true : highlowthistime = false;
		(readContentsFormat == null) ? contentsFormat = defaultContentsFormat : contentsFormat = readContentsFormat;
	} else {
		pageNum = 1;
		sortBy = defaultSort;
		contentsFormat = defaultContentsFormat;
	}
	if(sortBy == "default")
		writePage(pageNum,viewallthistime);
	else
		changeSortAndPage(sortBy,highlowthistime,pageNum,viewallthistime);

		
};

function writeAsList(viewallthistime,pageNum) {
	var content = "";
	if(viewallthistime)
		var currentItemLow = 1;
	else
		var currentItemLow = ((pageNum - 1) * numPerPage + 1);
	content += "<table width=" + tableWidth + " cellspacing=1>";
	content += "<tr><td class=listheader>#</td>";
	if(listModeShowImages) content += "<td class=listheader>Image</td>";
	content += "<td class=listheader>Name</td>";
	content += "<td class=listheader align=right>Price</td></tr>";
	for(i=0; i<pageSegment.length; i++) {
		itemnow = pageSegment[i];
		if(itemnow) {
			content += "<tr valign=top bgcolor=";
			(i % 2 == 0) ? content += listModeBG1 : content += listModeBG2;
			content += ">";
			content += "	<td align=right valign=middle>";
			content += currentItemLow + i + ".";
			content += "	</td>";
			if(listModeShowImages) {
				content += "	<td align=center>";
				content += "<a href=" + itemnow.id + ".html>" + itemnow.listimg + "</a>";
				content += "	</td>";
			}
			content += "	<td width=\"100%\">";
			content += "		<a href=" + itemnow.id + ".html>" + itemnow.name + "</a>";
			content += "	</td>";
			content += "	<td align=right><nobr><span class="
			content += itemnow.saleprice == 0 ? "" : "sale";
			content += "price>";
			content += itemnow.useprice == 0 ? "" : "$" + itemnow.useprice;
			content += "</span></nobr>";
			content += "	</td>";
			content += "</tr>";
		}
	}
	content += "</table>";
	return content;
};

function updateSortBy(array, sortby) {
	/* find what value to sort the array by and store it to a variable local to each item */
	for(i=0; i<array.length; i++) {
		switch(sortby) {
			case "default" :
				array[i].sortby = array[i].defaultsort;
			break
			case "name" :
				array[i].sortby = array[i].name;
			break
			case "price" :
				array[i].sortby = parseFloat(array[i].useprice);
			break
			case "brand" :
				array[i].sortby = array[i].brand;
			break
			default : array[i].sortby = array[i].name;
		}
	}
};

function writeOneSortLink(linkid,linkname,sep,chosen,bot,viewallthistime) {
	var localContent = "";
	if(chosen) {
		localContent += "<a class=chosen href=#top onclick=javascript:changeSortAndPage(\"" + linkid + "\",";
		if(sortHighLow) localContent += "false"; else localContent += "true";
		localContent += ",1," + viewallthistime + ");>";
		localContent += linkname;
		localContent += "</a>";
	} else {
		localContent += "<a href=#top onclick=javascript:changeSortAndPage(\"" + linkid + "\",false,1," + viewallthistime + ");>";
		localContent += linkname;
		localContent += "</a>";
	}
	localContent += "<span id=" + linkid + "arrowdiv" + bot + "></span>";
	if(sep) localContent += sortLinkSeparator;
	return localContent;
}

function writeSortLinks(bot,viewallthistime) {
	var sortLinksDiv = FIND("sortlinks" + bot);
	if(sortLinksDiv) {
		var localContent = (window.sortLinkPrefix)? sortLinkPrefix : "";
		var priceSep = false;
		if(showBrandSort) priceSep = true;
		switch(sortBy) {
			case "name":
					if(showDefaultSort) localContent += writeOneSortLink("default","Default",true,false,bot,viewallthistime);
					localContent += writeOneSortLink("name","Name",true,true,bot,viewallthistime);
					localContent += writeOneSortLink("price","Price",priceSep,false,bot,viewallthistime);
					if(showBrandSort) localContent += writeOneSortLink("brand","Manufacturer",false,false,bot,viewallthistime);
			break
			case "price":
					if(showDefaultSort) localContent += writeOneSortLink("default","Default",true,false,bot,viewallthistime);
					localContent += writeOneSortLink("name","Name",true,false,bot,viewallthistime);
					localContent += writeOneSortLink("price","Price",priceSep,true,bot,viewallthistime);
					if(showBrandSort) localContent += writeOneSortLink("brand","Manufacturer",false,false,bot,viewallthistime);
			break
			case "brand":
					if(showDefaultSort) localContent += writeOneSortLink("default","Default",true,false,bot,viewallthistime);
					localContent += writeOneSortLink("name","Name",true,false,bot,viewallthistime);
					localContent += writeOneSortLink("price","Price",priceSep,false,bot,viewallthistime);
					if(showBrandSort) localContent += writeOneSortLink("brand","Manufacturer",false,true,bot,viewallthistime);
			break
			default:
					if(showDefaultSort) {
						localContent += "<a class=chosen href=#top>";
						localContent += "Default";
						localContent += "</a>";
						localContent += sortLinkSeparator;
					}
					localContent += writeOneSortLink("name","Name",true,false,bot,viewallthistime);
					localContent += writeOneSortLink("price","Price",priceSep,false,bot,viewallthistime);
					if(showBrandSort) localContent += writeOneSortLink("brand","Manufacturer",false,false,bot,viewallthistime);

		}
		localContent += writePerPage(GetCookie('getPerPage'));
		sortLinksDiv.innerHTML = localContent;
	}
};

function writePerPage(pNum) {
	var selectPerPage;
	selectPerPage = "&nbsp;| <select id=perPage onchange='changeNumPerPage(this.value);'>";
	selectPerPage += "<option value='20' "+(pNum == 20?"selected":"")+">20</option>";
	selectPerPage += "<option value='40' "+(pNum == 40?"selected":"")+">40</option>";
	selectPerPage += "<option value='60' "+(pNum == 60?"selected":"")+">60</option>";
	selectPerPage += "<option value='80' "+(pNum == 80?"selected":"")+">80</option>"
	selectPerPage += "</select> per page";
	return selectPerPage;
	
}

function changeNumPerPage(perNum)
{
	SetCookie('getPerPage', perNum, exp);
	writePage(1,false);
	numPages = Math.ceil(window.items.length / perNum);
	writePageLinks( false, 1, numPages);
	initPaging();
};


function changeFormat(newFormat) {
	contentsFormat = newFormat;
	writePage(globalPageNum, globalViewallthistime);
}

function makeMAPWin(ww, wh) {
	w1=window.open('','w1','width='+ww+',height='+wh+',status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
	w1.document.open();
	w1.document.write("<b>Price \"Too Low to Display\" Explained<\/b><br> In order to provide the best support from our manufacturer's and distributors, we have agreed to abide by their \"MAP\" or minimum-advertised-price policy. You can see this price by clicking the product name and then selecting the Add to Cart button on the product information page. <br><br>Please be assured that simply adding an item to your cart does not obligate you to buy it--you can always delete the item from your cart if you decide not to purchase it.<p align=\"center\"><a href=\"javascript:window.close();\">Close Window</a></p>");
	w1.document.focus();
};

function mapPricing(useItem) {
	var mapstring = "<span class=map>";
	mapstring += "<form method=post action=http://order.store.yahoo.com/cgi-bin/wg-order?" + storename + ">"
	mapstring += '<input id=mapinput type=submit value="Click for instant price quote" height="16" width="155" border=0>';
	mapstring += ' <a href="javascript:makeMAPWin(300,350);">(Why?)</a><br>';
	mapstring += "<input type=hidden name=vwcatalog value=" + storename + ">"
	mapstring += "<input type=hidden name=vwitem value=" + localItem.id + ">";
	if(addToCartImage != "")
		mapstring += addToCartImage;
	else
		mapstring += "<input type=submit id=submit value='Add to Cart'>"
	mapstring += "</form>";
	mapstring += "</span>";
	return mapstring;
}

function writePagingModesLinks() {
	if(showPagingModes) {
		var localContent  = "<div id=modes>";
		(contentsFormat != "VERTICAL") ? localContent += "<a href=#top onclick=\"javascript:changeFormat('VERTICAL');\">" : localContent += "<span class=chosen>";
		localContent += "Style 1";
		(contentsFormat != "VERTICAL") ? localContent += "</a>" : localContent += "</span>";
		localContent += "<span class=sep>" + modeLinkSeparator + "</span>";

		(contentsFormat != "ELL") ? localContent += "<a href=#top onclick=\"javascript:changeFormat('ELL');\">" : localContent += "<span class=chosen>";
		localContent += "Style 2";
		(contentsFormat != "ELL") ? localContent += "</a>" : localContent += "</span>";

		if(showWrapMode) {
			localContent += "<span class=sep>" + modeLinkSeparator + "</span>";
			(contentsFormat != "WRAP") ? localContent += "<a href=#top onclick=\"javascript:changeFormat('WRAP');\">" : localContent += "<span class=chosen>";
			localContent += "Style 3";
			(contentsFormat != "WRAP") ? localContent += "</a>" : localContent += "</span>";
		}

		if(showListMode) {
			localContent += "<span class=sep>" + modeLinkSeparator + "</span>";

			(contentsFormat != "LIST") ? localContent += "<a href=#top onclick=\"javascript:changeFormat('LIST');\">" : localContent += "<span class=chosen>";
			localContent += "List Mode";
			(contentsFormat != "LIST") ? localContent += "</a>" : localContent += "</span>";
		}

		localContent += "</div>";

		var listModeDiv = FIND("pagingmodes");
		if(listModeDiv) listModeDiv.innerHTML = localContent;
		listModeDiv = FIND("pagingmodes2");
		if(listModeDiv) listModeDiv.innerHTML = localContent;
	}
}
