﻿<!--//
//Flash Communication
function flashTalk(directive){
	var mainSWF = window.document.swfcontainer;
	switch(directive){
		case 'home':
			setCurrent(1);
			break;
		case 'products':
			setCurrent(2);
			break;
	}
	mainSWF.TGotoLabel('/container_mc/HTMLdirector_mc', directive);
}

//Cross Browser Object Retrieval
function getObject(objectID){
	if (document.all!=null){
		return document.all[objectID];
	} else if (document.getElementById){
		return document.getElementById(objectID);
	}
}

/* Gets Parameter Values from QueryString */
function getParamValue(paramName){
	paramName += "=";
	var paramLength=paramName.length;
	var start = -1;
	if (location.search.indexOf("?" + paramName) != -1){
		start = location.search.indexOf("?" + paramName) + 1;
	} else if (location.search.indexOf("&" + paramName) != -1){
		start = location.search.indexOf("&" + paramName) + 1;
	}
	if (start != -1){
		if (location.search.indexOf("&",start + 1) != -1){
			tempValue = location.search.substring(start + paramLength, location.search.indexOf("&",start + 1));
		}
		else {
			tempValue = location.search.substring(start + paramLength);
		}
		return tempValue;
	}
	else {
		return null;
	}
}

//Cross Browser Object click
function clickIt(elementToClick){
	try{
		elementToClick.click();
		}
	catch(e){
		var newEvent = document.createEvent("MouseEvents");
		newEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
		elementToClick.dispatchEvent(newEvent);
 		}
}
//Cross Browser Object get/set inner text
function setInnerText(elementToSet, textString){
	if (elementToSet.textContent != undefined)
		elementToSet.textContent = textString;
	else
		elementToSet.innerText = textString;
}
function getInnerText(elementToGet){
	if (elementToGet.textContent != undefined)
		return (elementToGet.textContent.toString());
	else
		return (elementToGet.innerText.toString());
}

/* DHTML POPUP SHOW/HIDE AND SHADOW GENERATION */
/*Popup Window Functions*/
var popUpWin;
var popDefWidth = 570;
var popDefHeight = 400;
var lastWidth;
var lastHeight;
var popZIndex = 25;

//Open URL in new window with fixed dimensions
function openWin(url, pixWidth, pixHeight, canScroll){
	var winFeatures = "width=" + pixWidth + ",height=" + pixHeight + "," + getCentered(pixWidth,pixHeight) + ",resizable=no,scrollbars=";
	if (canScroll){
		winFeatures += "yes";
	} else {
		winFeatures += "no";
	}
	if (popUpWin != null){
		if (popUpWin.closed){
			popUpWin = window.open(url, "popwin", winFeatures);
			popUpWin.focus();
		} else if ((lastWidth == pixWidth) && (lastHeight == pixHeight)){
			popUpWin.location.href = url;
			popUpWin.focus();
		} else {
			popUpWin.close();
			var timeDelay = 0;
			if (navigator.userAgent.indexOf("Safari") != -1){
				timeDelay = 1000;
			}
			var winWait = window.setTimeout('popUpWin = window.open("' + url + '", "popwin", "' + winFeatures + '");popUpWin.focus();', timeDelay);
		}	
	} else {
		popUpWin = window.open(url, "popwin", winFeatures);
		popUpWin.focus();
	}
	lastWidth = pixWidth;
	lastHeight = pixHeight;
}

//Get coordinates for centering window
function getCentered(popupWidth, popupHeight){
	var indentNetscapeWidth = 'screenX=' + getIndent(popupWidth, false);
	var indentNetscapeHeight = 'screenY=' + getIndent(popupHeight, true);
	var indentMSIEWidth = 'left=' + getIndent(popupWidth, false);
	var indentMSIEHeight = 'top=' + getIndent(popupHeight, true);
	var centerCoordinates = indentNetscapeWidth + ',' + indentNetscapeHeight + ',' + indentMSIEWidth + ',' + indentMSIEHeight;
	return centerCoordinates;
}

//Determine top and left margins for window
function getIndent (popupDimension, isHeight){
	if (isHeight){
		return ((screen.availHeight - popupDimension) / 2);
	} else {
		return ((screen.availWidth - popupDimension) / 2);
	}
}

//Determine top and left margins for window
function getDPopIndentold (popupDimension, isHeight){
	if (isHeight){
		return ((window.innerHeight - popupDimension) / 2);
	} else {
		return ((window.innerWidth - popupDimension) / 2);
	}
}
//Determine top and left margins for window
function getDPopIndent (popupDimension, isHeight){
                if (isHeight){
                                if (window.innerHeight)
                                                return ((window.innerHeight - popupDimension) / 2);
                                else if (window.document.documentElement && window.document.documentElement.clientHeight)
                                                return ((window.document.documentElement.clientHeight - popupDimension) /2 );
                                else if (window.document.body.clientHeight)
                                                return ((window.document.body.clientHeight - popupDimension) / 2);
                } else {
                                if (window.innerWidth)
                                                return ((window.innerWidth - popupDimension) / 2);
                                else if (window.document.documentElement && window.document.documentElement.clientWidth)
                                                return ((window.document.documentElement.clientWidth - popupDimension) / 2);
                                else if (window.document.body.clientWidth)
                                                return ((window.document.body.clientWidth - popupDimension) / 2);
                }
}

//Close popup and redirect parent to URL
function closeAndGo(url){
	var newWin;
	if (window.opener != null){
		if (window.opener.closed){
			newWin = window.open(url,'newwin','width=' + screen.availWidth + ',height=' + screen.availHeight + ',toolbar=yes,status=yes,directories=yes,location=yes,menubar=yes,personalbar=yes,resizable=yes,scrollbars=yes');
			newWin.focus();
		} else {
			window.opener.location.href = url;
			window.opener.focus();
		}
	} else {
		newWin = window.open(url,'newwin','width=' + screen.availWidth + ',height=' + screen.availHeight + ',toolbar=yes,status=yes,directories=yes,location=yes,menubar=yes,personalbar=yes,resizable=yes,scrollbars=yes');
		newWin.focus();
	}
	window.close();
}

function popWin(theURL){
	openWin(theURL, popDefWidth, popDefHeight);
}

//Get coordinates for centering DHTML Popup
function getDPopCoords(popupWidth, popupHeight){
	var centerCoordinates = getDPopIndent(popupWidth, false) + ',' + getDPopIndent(popupHeight, true);
	return centerCoordinates;
}

function initShadow(popID, pTop, pRight, pBottom, pLeft){
	var divPop = getObject(popID);
	var divShadow = getObject(popID + "Shadow");
	if (pTop == null){
		pTop = 3;
	}
	if (pRight == null){
		pRight = 3;
	}
	if (pBottom == null){
		pBottom = 2;
	}
	if (pLeft == null){
		pLeft = 3;
	}
	divShadow.style.width = (parseInt(divPop.style.width) + pLeft + pRight) + "px";
	if (parseInt(divPop.style.top) != 0){
		divShadow.style.height = (parseInt(divPop.style.height) + pTop + pBottom) + "px";
		divShadow.style.top = (parseInt(divPop.style.top) + 5) + "px";
	} else {
		divShadow.style.height = (parseInt(divPop.style.height) + pTop + pBottom + 5) + "px";
		divShadow.style.top = (parseInt(divPop.style.top)) + "px";
	}		
	divShadow.style.left = (parseInt(divPop.style.left) - 5) + "px";
}

function centerDPop(popID){
	var divPop = getObject(popID);
	var anchorDIV = getObject("page");
	var coords = new String();
	coords = getDPopCoords(parseInt(divPop.style.width), parseInt(divPop.style.height)).toString().split(",");
	//alert("Screen Width/Height:\t\t\t" + window.innerWidth + "," + window.innerHeight + "\nDIVPop Width/Height:\t\t\t" + parseInt(divPop.style.width) + "," + parseInt(divPop.style.height) + "\nCoords(x,y):\t\t\t\t\t" + coords[0] + "," + coords[1] + "\noffsetLeft/offsetTop/scrollTop:\t\t" + anchorDIV.offsetLeft + "," + anchorDIV.offsetTop + "," + document.documentElement.scrollTop);
	divPop.style.left = Math.round(parseInt(coords[0]) - (anchorDIV.offsetLeft)) + "px";
	divPop.style.top = Math.round((parseInt(coords[1]) - anchorDIV.offsetTop) + document.documentElement.scrollTop) + "px";
}

var macSafari;

if (navigator.userAgent.indexOf("Macintosh") != -1){
	macSafari = true;
} else {
	macSafari = false;
}

function showDPop(popID, isCentered, pTop, pRight, pBottom, pLeft){
	if (macSafari){
		if (location.href.indexOf("products.aspx") != -1){
			showDIVv("safarifix1");
			showDIVv("safarifix2");
			hideDIVv("flashcontainer1");
			hideDIVv("flashcontainer2");
		} else {
			showDIVv("safarifix");
			hideDIVv("flashcontainer");
		}
	}

	for (var i = 0; i < document.forms[0].elements.length; i++){
		if (document.forms[0].elements[i].type == "select-one"){
			document.forms[0].elements[i].style.visibility = "hidden";
		}
	}
	if (isCentered || isCentered == null){
		centerDPop(popID);
	}
	popZIndex += 2;
	showDIV(popID, popZIndex);
	initShadow(popID, pTop, pRight, pBottom, pLeft);
	showDIV(popID + "Shadow", popZIndex - 1);
}

function hideDPop(popID){
	if (macSafari){
		if (location.href.indexOf("products.aspx") != -1){
			showDIVv("flashcontainer1");
			showDIVv("flashcontainer2");
			hideDIVv("safarifix1");
			hideDIVv("safarifix2");
		} else {
			showDIVv("flashcontainer");
			hideDIVv("safarifix");
		}
	}
	for (var i = 0; i < document.forms[0].elements.length; i++){
		if (document.forms[0].elements[i].type == "select-one"){
			document.forms[0].elements[i].style.visibility = "visible";
		}
	}
	hideDIV(popID + "Shadow");
	hideDIV(popID);
}

function showDIV(divID, z){
	var divPop = getObject(divID);
	if (divPop != null){
		divPop.style.zIndex = z;
		divPop.style.display = "block";
	}
}

function hideDIV(divID){
	var divPop = getObject(divID);
	if (divPop != null){
		divPop.style.display = "none";
	}
}

function showDIVv(divID){
	var divPop = getObject(divID);
	if (divPop != null){
		divPop.style.visibility = "visible";
	}
}

function hideDIVv(divID){
	var divPop = getObject(divID);
	if (divPop != null){
		divPop.style.visibility = "hidden";
	}
}

// Image rating animation & submission
function setHover(index, ratingType)
	{
	var userStarImg = new Image();
	var groupStarImg = new Image();
	var blankStarImg = new Image();
	switch(ratingType){
		case "dip_rules":
			userStarImg.src = "/images/star_blue_white.gif";
			groupStarImg.src = "/images/star_orange_white.gif";
			blankStarImg.src = "/images/star_gray_white.gif";
			break;
		case "products":
			userStarImg.src = "/images/blue_star.gif";
			groupStarImg.src = "/images/gold_star.gif";
			blankStarImg.src = "/images/empty_star.gif";
			break;
		default:
			userStarImg.src = "/images/blue_star.gif";
			groupStarImg.src = "/images/gold_star.gif";
			blankStarImg.src = "/images/empty_star.gif";
			break;
	}
	var objSelectedThumbnail = getObject("txtSelectedThumbnail");
	var objUserRating = getObject("artUserRating");
	var objRatingIndicator = getObject("artRatingIndicator");
	currentRating = 0;
	for (loopIndex=0; loopIndex <= 4; loopIndex++)
		if (document.images["starImage" + loopIndex.toString()].src.indexOf(groupStarImg.src) != -1)
			currentRating = loopIndex+1; 
	if ((getInnerText(objUserRating) == "") && (objSelectedThumbnail.value.length > 0))
		{
		document.images["starImage" + (index - 1).toString()].style.cursor = "pointer";
		for (loopIndex=0; loopIndex <= 4; loopIndex++)
			{
			if (loopIndex+1 <= index) document.images["starImage" + loopIndex.toString()].src = userStarImg.src; 
			if (loopIndex+1 > index) document.images["starImage" + loopIndex.toString()].src = blankStarImg.src; 
			}
		setInnerText(objRatingIndicator, ratingIndicator[parseInt(index) - 1]);
		objRatingIndicator.style.display = ""; //show it
		}
	}

function unsetHover(index, ratingType)
	{
	var userStarImg = new Image();
	var groupStarImg = new Image();
	var blankStarImg = new Image();
	switch(ratingType){
		case "dip_rules":
			userStarImg.src = "/images/star_blue_white.gif";
			groupStarImg.src = "/images/star_orange_white.gif";
			blankStarImg.src = "/images/star_gray_white.gif";
			break;
		case "products":
			userStarImg.src = "/images/blue_star.gif";
			groupStarImg.src = "/images/gold_star.gif";
			blankStarImg.src = "/images/empty_star.gif";
			break;
		default:
			userStarImg.src = "/images/blue_star.gif";
			groupStarImg.src = "/images/gold_star.gif";
			blankStarImg.src = "/images/empty_star.gif";
			break;
	}
	var objSelectedThumbnail = getObject("txtSelectedThumbnail");
	var objUserRating = getObject("artUserRating");
	var objRatingIndicator = getObject("artRatingIndicator");
	if ((getInnerText(objUserRating) == "") && (objSelectedThumbnail.value.length > 0))
		{
		document.images["starImage" + (index - 1).toString()].style.cursor = "auto";
		for (loopIndex=0; loopIndex <= 4; loopIndex++)
			{
			if (loopIndex+1 <= currentRating) document.images["starImage" + loopIndex.toString()].src = groupStarImg.src; 
			if (loopIndex+1 > currentRating) document.images["starImage" + loopIndex.toString()].src = blankStarImg.src; 
			}
		setInnerText(objRatingIndicator, "");
		objRatingIndicator.style.display = "none";
		}
	}

function setRating(index, submit)
	{
	var objSelectedThumbnail = getObject("txtSelectedThumbnail");
	var objMember = getObject("txtMemberId")
	var objRatingIndicator = getObject("artRatingIndicator");
	var objRatingLabel = getObject("artRatingLabel");
	var txtUserRating = getObject("ctlRating_txtUserRating");
	var objUserRating = getObject("artUserRating");
	if (objSelectedThumbnail.value.length > 0)
		{
		if (submit)
			{
			if (objMember != undefined)
				submitRating(objMember.value, index);
			else
				submitRating(userId, index);
			document.images["starImage" + (index - 1).toString()].style.cursor = "auto";
			for (loopIndex=0; loopIndex <= 4; loopIndex++)
				{
				if (loopIndex+1 <= index) document.images["starImage" + loopIndex.toString()].src = "/images/blue_star.gif"; 
				if (loopIndex+1 > index) document.images["starImage" + loopIndex.toString()].src = "/images/empty_star.gif"; 
				}
			setInnerText(objRatingLabel, "  Thank you  ");
			objRatingLabel.style.display = ""; //show it
			setInnerText(objRatingIndicator, "");
			objRatingIndicator.style.display = "none";
			if (txtUserRating != undefined)
				txtUserRating.value = index;
			setInnerText(objUserRating, index.toString);
			}
		}
	}
function submitRating(userId, ratingValue)
	{
	var ajaxRequest = false;
	try 
		{request = new XMLHttpRequest();} 
	catch (trymicrosoft) {
		try 
			{request = new ActiveXObject("Msxml2.XMLHTTP");} 
		catch (othermicrosoft) {
			try 
				{request = new ActiveXObject("Microsoft.XMLHTTP");} 
			catch (failed) 
				{request = false;}
			}
		}
	if (request)
		{
		var objSelectedThumbnail = getObject("txtSelectedThumbnail");
		var strSoapBody = "";
		strSoapBody = strSoapBody + '<?xml version="1.0" encoding="utf-8"?>';
		strSoapBody = strSoapBody + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/">';
		strSoapBody = strSoapBody + '<soap:Body>';
		strSoapBody = strSoapBody + '<RateAnImage xmlns="http://tempuri.org/SkoalBrotherhood/image_rating">';
		strSoapBody = strSoapBody + '<intUserId>' + userId + '</intUserId>';
		strSoapBody = strSoapBody + '<strSiteRelativeImagePath>' + objSelectedThumbnail.value + '</strSiteRelativeImagePath>';
		strSoapBody = strSoapBody + '<intRating>' + ratingValue + '</intRating>';
		strSoapBody = strSoapBody + '</RateAnImage>';
		strSoapBody = strSoapBody + '</soap:Body>';
		strSoapBody = strSoapBody + '</soap:Envelope>';
	    request.open("POST", "image_rating.asmx", false);
	    request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
	    request.setRequestHeader("Content-Length", strSoapBody.length.toString());
		request.setRequestHeader("SOAPAction", "http://tempuri.org/SkoalBrotherhood/image_rating/RateAnImage");
	    request.send(strSoapBody);
		while (request.readyState != 4)
			request.waitForResponse(1000);	    
		if (request.status != 200)
			submitRatingByPostback(ratingValue);
		else
			{
			if (request.responseXML.getElementsByTagName("RateAnImageResponse").length > 0)
				{
				if (parseInt(request.responseXML.getElementsByTagName("RateAnImageResponse")[0].text) < 0)
					submitRatingByPostback(ratingValue);
				}
			else
				submitRatingByPostback(ratingValue);
			}		
		}
	else
		submitRatingByPostback(ratingValue);
	}

function resetRating()
	{
	var objRatingLabel = getObject("artRatingLabel");
	var objRatingIndicator = getObject("artRatingIndicator");
	var objUserRating = getObject("artUserRating");
	var objTxtUserRating = getObject("ctlRating_txtUserRating");
	setInnerText(objRatingLabel, "Rate this photo");
	objRatingLabel.style.display = ""; //show it		
	setInnerText(objRatingIndicator, "");
	objRatingIndicator.style.display = "none";
	for (loopIndex=0; loopIndex <= 4; loopIndex++)
		{
		if (loopIndex+1 <= parseInt(getInnerText(objUserRating))) document.images["starImage" + loopIndex.toString()].src = "/images/gold_star.gif"; 
		if (loopIndex+1 > parseInt(getInnerText(objUserRating))) document.images["starImage" + loopIndex.toString()].src = "/images/empty_star.gif"; 
		}
	setInnerText(objUserRating, "");
	objTxtUserRating.value = "";
	}
	
function submitRatingByPostback(ratingValue)
	{
	var txtUserRating = getObject("ctlRating_txtUserRating");
	var btnSubmit_rating = getObject("ctlRating_btnSubmit_rating");
	if ((txtUserRating != undefined) && (btnSubmit_rating != undefined))
		{
		txtUserRating.value = ratingValue;
		btnSubmit_rating.click();
		}
	}

/* TABBED CONTENT - ROLLOVERS AND CONTENT SWAPS */
var currentTab;
var maxTabs;
var tabsOn;
var tabsOff;
var tabWait;

function tabInit(){
	currentTab = 1;
	maxTabs = tabNames.length;
	tabsOn = new Array(maxTabs);
	tabsOff = new Array(maxTabs);
	
	for (var i = 0; i < maxTabs; i++){
		tabsOn[i] = new Image();
		tabsOn[i].src = "images/tab_" + tabNames[i] + "_on.gif";
		tabsOff[i] = new Image();
		tabsOff[i].src = "images/tab_" + tabNames[i] + ".gif";
	}
	tabWait = setInterval("tablight(currentTab)", 100);
}

function tablight(tabNum){
	if (document.images){
		if (document.images["tab" + tabNum]){
			clearInterval(tabWait);
			document.images["tab" + tabNum].src = tabsOn[tabNum - 1].src;
		}
	}
}

function tabdim(tabNum){
	if (document.images){
		if (tabNum != currentTab){
			document.images["tab" + tabNum].src = tabsOff[tabNum - 1].src;
		}
	}
}

function tabselect(tabNum){
	if (tabNum != currentTab){
		var oldTab = getObject("tabcontent" + currentTab);
		var newTab = getObject("tabcontent" + tabNum);
		var tempTabNum = currentTab;
		currentTab = tabNum;
		oldTab.style.display = "none";
		newTab.style.display = "block";
		tabdim(tempTabNum);
	}
}

/* RATINGS SYSTEM */
var objectIDs;
var currentRating;
var newRating;
var ratingText;
var starOn;
var starOff;
var starOver;
	
function starLight(starNum, ratingID){
	if (document.images){
		var ratingLevel = getObject("starstext" + ratingID);
		ratingLevel.innerHTML = ratingText[starNum - 1];
		newRating = starNum;
		for (var i = 1; i <= starNum; i++){
			document.images["star" + i + ratingID].src = starOver.src;
		}
		for (var i = starNum + 1; i <= 5; i++){
			document.images["star" + i + ratingID].src = starOff.src;
		}
	}
}

function starDim(starNum, ratingID){
	if (document.images){
		var ratingLevel = getObject("starstext" + ratingID);
		ratingLevel.innerHTML = ratingText[currentRating[ratingID] - 1];
		for (var i = 1; i <= currentRating[ratingID]; i++){
			document.images["star" + i + ratingID].src = starOn.src;
		}
		for (var i = currentRating[ratingID] + 1; i <= 5; i++){
			document.images["star" + i + ratingID].src = starOff.src;
		}
	}
}

function starSave(starNum, ratingID){
	currentRating[ratingID] = starNum;
	newRating[ratingID] = 0;
	starDim(starNum, ratingID);
}

function starInit(objectID, starNum, ratingID){
	objectIDs[ratingID] = objectID;
	starSave(starNum, ratingID);
}

function ratingsInit(objectID, starNum, ratingID){
	objectIDs = new Array();
	currentRating = new Array();
	newRating = new Array();
	ratingText = ["Nice try", "So-so", "Average Joe", "Yeah, man", "Instant Hall of Famer"];

	starOn = new Image();
	starOff = new Image();
	starOver = new Image();

	starOn.src = "images/star_orange.gif";
	starOff.src = "images/star_gray.gif";
	starOver.src = "images/star_blue.gif";
	
	starInit(objectID, starNum, ratingID);
}

/* PRODUCT DETAIL DISPLAY */
function displayProduct(catID, prodID, prodName, prodCopy, initial){
	showProductsPriceReset(false);
	var skoalEdgeDisplay = getObject("skoaledge");
	var productDisplay = getObject("productdisplay");
	if ((catID == 2) && (prodID == 12)){
		skoalEdgeDisplay.style.display = "block";
		productDisplay.style.display = "none";
	} else {
		if (document.images){
			document.images["prodimage"].src = "/images/products/lg_can_" + prodName + ".jpg";
			document.images["prodtitle"].src = "/images/products/ttl_" + prodName + ".gif";
			var copy = getObject("proddesc");
			var tag = "[IMAGE]";
			if (prodCopy.indexOf(tag) != -1){
				copy.innerHTML = prodCopy.substring(0, prodCopy.indexOf(tag));
				copy.innerHTML += '<a href="soapbox.aspx"><img src="/images/products/straight_pouches_vwall.gif"  alt="Hear from guys who\'ve tried it." width="112" height="80" border="0" align="right" /></a>';
				copy.innerHTML += prodCopy.substring(prodCopy.indexOf(tag) + tag.length);
			} else {
				copy.innerHTML = prodCopy;
			}
			skoalEdgeDisplay.style.display = "none";
			productDisplay.style.display = "block";
		}
	}
	document.forms[0].categoryid.value = catID;
	document.forms[0].productid.value = prodID;
	changeProductFrames(catID, prodID);
}

function changeProductFrames(catID, prodID){
	if ((catID == null) || (prodID == null)){
		catID = document.forms[0].categoryid.value;
		prodID = document.forms[0].productid.value;
	}
	
	var theURL = "/products_testimonials.aspx?cat=" + catID + "&prod=" + prodID;

	if (frames["iframe_testimonials"] != null){
		frames["iframe_testimonials"].location.href = theURL;
	} else if (getObject("iframe_testimonials") != null){
		var htmlFrame = getObject("iframe_testimonials");
		htmlFrame.src = theURL;
	}
	
	theURL = "/products_ratings.aspx?cat=" + catID + "&prod=" + prodID;
	
	if (frames["iframe_ratings"] != null){
		frames["iframe_ratings"].location.href = theURL;
	} else if (getObject("iframe_ratings") != null){
		var htmlFrame = getObject("iframe_ratings");
		htmlFrame.src = theURL;
	}
}

function showProductsPriceReset(showIt){
		var trHolder = getObject("testratingholder");
	if (showIt){
		trHolder.style.backgroundColor = "#FFFFFF";
		hideDIVv("testratingsection");
		hideDIV("skoaledge");
		hideDIV("productdisplay");
		showDIV("pricereset", 0);
	} else {
		trHolder.style.backgroundColor = "#000000";
		showDIVv("testratingsection");
		hideDIV("pricereset");
	}
}

/* PROMO DISPLAY */
var SidePromos = new Array();
var promoPrefix = "/images/promo_";
var promoSuffix = ".jpg";
var tmpPromo;

tmpPromo = new Object();
tmpPromo.alt = "If You'd Like To Know, Ask The Pro";
tmpPromo.href = "ask_the_pro.aspx";
tmpPromo.id = "ask_pro";
SidePromos.push(tmpPromo);

tmpPromo = new Object();
tmpPromo.alt = "Dip Rules!";
tmpPromo.href = "dip_rules.aspx";
tmpPromo.id = "dip_rules";
SidePromos.push(tmpPromo);

tmpPromo = new Object();
tmpPromo.alt = "Scroll Through Old Skoal";
tmpPromo.href = "old_skoal.aspx";
tmpPromo.id = "old_skoal";
SidePromos.push(tmpPromo);

tmpPromo = new Object();
tmpPromo.alt = "Rate Your Skoal";
tmpPromo.href = "products.aspx";
tmpPromo.qstring = "ratings=true";
tmpPromo.id = "product_rating";
SidePromos.push(tmpPromo);

tmpPromo = new Object();
tmpPromo.alt = "Every Style Has Its Own Style";
tmpPromo.href = "products.aspx";
tmpPromo.id = "products";
SidePromos.push(tmpPromo);

tmpPromo = new Object();
tmpPromo.alt = "Welcome To The Brotherhood";
tmpPromo.href = "brotherhood.aspx";
tmpPromo.id = "welcome";
SidePromos.push(tmpPromo);

tmpPromo = new Object();
tmpPromo.alt = "What's Your Story?";
tmpPromo.href = "whats_your_story.aspx";
tmpPromo.id = "your_story";
SidePromos.push(tmpPromo);

tmpPromo = new Object();
tmpPromo.alt = "New Long Cut Wintergreen";
tmpPromo.href = "products.aspx";
tmpPromo.id = "product_edge";
SidePromos.push(tmpPromo);

tmpPromo = new Object();
tmpPromo.alt = "Straight Pouches - Damn Straight.";
tmpPromo.href = "soapbox.aspx";
tmpPromo.id = "straight_pouches";
SidePromos.push(tmpPromo);
/*
tmpPromo = new Object();
tmpPromo.alt = "Win a Chance to Party at the Playboy Mansion";
tmpPromo.href = "/playboypromo/default.aspx";
tmpPromo.id = "playboy_sweeps";
SidePromos.push(tmpPromo);

tmpPromo = new Object();
tmpPromo.alt = "Straight Pouches - Damn Straight. Get a coupon now";
tmpPromo.href = "savings.aspx";
tmpPromo.id = "product_savings_straight_pouches";
SidePromos.push(tmpPromo);
*/
savingsPromo = new Object();
savingsPromo.alt = "Print Your Coupon Now";
savingsPromo.href = "savings.aspx";
savingsPromo.id = "savings";

function isInArray(theValue, theArray){
	for (var i = 0; i < theArray.length; i++){
		if (theValue == theArray[i]){
			return true;
		}
	}
	return false;
}

function getIndex(theValue, theArray){
	for (var i = 0; i < theArray.length; i++){
		if (theValue == theArray[i]){
			return i;
		}
	}
	return -1;
}

function writePromo(promo, isLastPromo){
	var fullHref = promo.href;
	if (promo.qstring != null){
		fullHref += '?' + promo.qstring;
	}
	var output = '<a href="' + fullHref + '"><img src="' + promoPrefix + promo.id + promoSuffix + '" width="152" height="149" alt="' + promo.alt + '" border="0"';
	if (isLastPromo){
		output += ' style="margin-bottom:0px;"></a>';
	} else {
		output += '></a><br />';
	}
	return output;
}

function getPromos(maxPromos){
	var foundPromo;
	var foundIndex;
	var tmpPromo;
	var promoIndex;
	var displayedPromos = new Array();
	var j;
	var output = "";
	
	if ((location.href.indexOf("products.aspx") != -1) || (location.href.indexOf("articles.aspx") != -1)){
		var qualityIndex = Math.ceil(Math.random() * 11);
		output += '<img src="images/promo_quality' + qualityIndex + '.jpg" width="152" height="181" alt="" border="0"><br />';
	}
	
	if (location.href.indexOf("products.aspx") != -1){
//		output += writePromo(savingsPromo, false);
	}
		
	for (var i = 1; i <= maxPromos; i++){
		foundPromo = false;
		while(!foundPromo){
			do {
				promoIndex = Math.floor(Math.random() * SidePromos.length);
			} while(isInArray(promoIndex, displayedPromos));
			tmpPromo = SidePromos[promoIndex];
			if (location.href.indexOf(tmpPromo.href) == -1){
				output += writePromo(tmpPromo, (i == maxPromos));
				foundPromo = true;
				displayedPromos.push(promoIndex);
			}
		}
	}
	return output;
}

function renderPromos(){
	var promoDIV = getObject("promos");
	if (promoDIV != null){
		var promoHeight = 159;
		var numPromos;
		var contentHeight;
		var scrollContent = getObject("scrollcontent");
		if (scrollContent.offsetHeight){
			contentHeight = scrollContent.offsetHeight;
		} else if (scrollContent.style.pixelHeight){
			contentHeight = scrollContent.style.pixelHeight;
		}
		if ((location.href.indexOf("products.aspx") != -1) || (location.href.indexOf("articles.aspx") != -1)){
			contentHeight -= 191;
		}
		numPromos = Math.floor(contentHeight / promoHeight);
		if (location.href.indexOf("products.aspx") != -1){
			numPromos--;
		}
		if (numPromos > SidePromos.length){
			numPromos = SidePromos.length;
			for (var i = 0; i < SidePromos.length; i++){
				tmpPromo = SidePromos[i];
				if (location.href.indexOf(tmpPromo.href) != -1){
					numPromos--;
				}
			}
		}
		promoDIV.innerHTML = getPromos(numPromos);
	}
}

/* BROFILE ICON SELECTION */
var icons;
var iconsOn;
var iconsOff;
var currentIcons;
var savedIcons;
var iconTypes = ["dt", "int"];

function iconsLight(iconNum, iconType){
	if (document.images){
		document.body.style.cursor='pointer';
		document.images["icon" + iconType + iconNum].src = iconsOn[iconType][iconNum - 1].src;
	}
}

function iconsDim(iconNum, iconType){
	if (document.images){
		document.body.style.cursor='default';
		if (!isInArray(iconNum, currentIcons[iconType])){
			document.images["icon" + iconType + iconNum].src = iconsOff[iconType][iconNum - 1].src;
		}
	}
}

function iconsSelect(iconNum, iconType){
	//alert(iconNum + " | " + iconType + " | " + currentIcons[iconType]);
	if (document.images){
		if (iconNum != 0){
			if (currentIcons[iconType].length == 1){
				var tmpNum = currentIcons[iconType][0];
				currentIcons[iconType][0] = iconNum;
				if (tmpNum != 0){
					iconsDim(tmpNum, iconType);
				}
				iconsLight(iconNum, iconType);
			} else {
				if (isInArray(iconNum, currentIcons[iconType])){
					currentIcons[iconType][getIndex(iconNum, currentIcons[iconType])] = 0;
					iconsDim(iconNum, iconType);
					if (iconType == "int"){
						var holder = getObject("div" + iconType + iconNum);
						holder.className = "";
					}
				} else if (isInArray(0, currentIcons[iconType])){
					currentIcons[iconType][getIndex(0, currentIcons[iconType])] = iconNum;
					iconsLight(iconNum, iconType);
					if (iconType == "int"){
						var holder = getObject("div" + iconType + iconNum);
						holder.className = "icon_selected";
					}
				}
			}
		}
	}
}

function iconsShow(userid){
	if ((location.href.indexOf("update_profile.aspx") == -1) && (location.href.indexOf("brofile.aspx") == -1)){
		showDPop('icon_selector', false, 17, 30, 0, 35);
	} else {
		var iconPanel = getObject('iconwrapper');
		if (location.href.indexOf("update_profile.aspx") != -1){
			iconPanel.className = "profileversion";
		} else {
			iconPanel.className = "brofileversion";
		}
		showDIV('icon_selector', 1);
	}
	iconsInit(userid);
}

function iconsInit(userid){
	var iconPanelLink = getObject("iconPanelLink");
	iconPanelLink.onclick = function (){
		return false;
	}
	savedIcons = new Array(iconTypes.length);
	iconsLoadAJAX(userid);
}

function iconsSetup(iconsXML){
	if (document.images){
		var fileTypes = [".jpg", ".gif"];
		icons = new Array(iconTypes.length);
		iconsOn = new Array(iconTypes.length);
		iconsOff = new Array(iconTypes.length);
		currentIcons = new Array(iconTypes.length);
		
		currentIcons["dt"] = [0];
		currentIcons["int"] = [0, 0, 0];

		savedIcons["dt"] = [getXMLNodeValue(iconsXML, "CanNumber")];
		savedIcons["int"] = getXMLNodeValues(iconsXML, "Interests");
		
		var imgSrc;
		var imgName;
		
		for (var j = 0; j < iconTypes.length; j++){
			icons[iconTypes[j]] = new Array();
			iconsOn[iconTypes[j]] = new Array();
			iconsOff[iconTypes[j]] = new Array();
			for (var i = 0; i < document.images.length; i++){
				imgName = document.images[i].name;
				if (imgName.indexOf("icon" + iconTypes[j]) == 0){
					icons[iconTypes[j]][icons[iconTypes[j]].length] = document.images[i];
					icons[iconTypes[j]][icons[iconTypes[j]].length - 1].id = parseInt(imgName.substring(("icon" + iconTypes[j]).length));
					icons[iconTypes[j]][icons[iconTypes[j]].length - 1].iconType = iconTypes[j];
					
					imgSrc = icons[iconTypes[j]][icons[iconTypes[j]].length - 1].src;
					imgSrc = imgSrc.substring(0, imgSrc.indexOf(fileTypes[j]));
					
					iconsOn[iconTypes[j]][iconsOn[iconTypes[j]].length] = new Image();
					iconsOn[iconTypes[j]][iconsOn[iconTypes[j]].length - 1].src = imgSrc + "_over" + fileTypes[j];
					
					iconsOff[iconTypes[j]][iconsOff[iconTypes[j]].length] = new Image();
					iconsOff[iconTypes[j]][iconsOff[iconTypes[j]].length - 1].src = imgSrc + fileTypes[j];
					
					icons[iconTypes[j]][icons[iconTypes[j]].length - 1].onmouseover = function(){
						iconsLight(this.id, this.iconType);
					}
					
					icons[iconTypes[j]][icons[iconTypes[j]].length - 1].onmouseout = function(){
						iconsDim(this.id, this.iconType);
					}
					
					icons[iconTypes[j]][icons[iconTypes[j]].length - 1].onclick = function(){
						iconsSelect(this.id, this.iconType);
					}
				}
			}
			for (var k = 0; k < savedIcons[iconTypes[j]].length; k++){
				iconsSelect(savedIcons[iconTypes[j]][k], iconTypes[j]);
			}
		}
	}
}

function compareNumbers(a, b){
	return a - b;
}

function iconsSave(userid){
	currentIcons["int"] = currentIcons["int"].sort(compareNumbers);
	var interests = currentIcons["int"].toString();
	var diptype = currentIcons["dt"].toString();
	iconsSaveAJAX(userid, diptype, interests);
	
	var imgObj = getObject("ctlHeader_UserCans_interests1_imgDipType");
	if ((imgObj != null) && (currentIcons["dt"][0] != 0)){
		imgObj.src = iconsOff["dt"][currentIcons["dt"][0] - 1].src;
	}
	for (var i = 0; i < currentIcons["int"].length; i++){
		imgObj = getObject("ctlHeader_UserCans_interests1_imgInterest" + (i + 1));
		if (imgObj != null){
			if (currentIcons["int"][i] != 0){
				imgObj.style.display = "inline";
				imgObj.src = iconsOff["int"][currentIcons["int"][i] - 1].src;
			} else {
				imgObj.style.display = "none";
			}
		}
	}
	imgObj = getObject("btnPersonalize");
	if (imgObj != null){
		imgObj.style.display = "none";
	}
	iconsClose();
}

var iconRequest;

// URL for Getting new Icons/ajax/RatingWebService.asmx/getCanInterest  pARAMETER userID only
/* AJAX SAVE ICONS */
function iconsSaveAJAX(userid, diptype, interests){
	iconRequest = getAJAXRequest();
	if (!iconRequest) {
		//force postback somehow
	} else {
		var url = '/ajax/RatingWebService.asmx/UpdateCanInterest'
		var SendData ;
		SendData='userID='+ userid + '&CanNumber=' + diptype + '&Interests=' + interests
		iconRequest.open('POST', url, false);
		iconRequest.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
		iconRequest.send(SendData);
	}
}

function iconsLoadAJAX(userid){
	iconRequest = getAJAXRequest();
	if (!iconRequest) {
		//force postback somehow
	} else {
		var url = '/ajax/RatingWebService.asmx/getCanInterest?userID='+ userid;
		iconRequest.onreadystatechange = iconsLoad_CallBack;
		iconRequest.open('GET', url, true);
		iconRequest.send(null);
	}
}

function iconsLoad_CallBack(){
	if(iconRequest.readyState == 4){
		if(iconRequest.status != 200){
		//	alert("There was a problem loading icon selections from the server." );
		} else {
			iconsSetup(iconRequest.responseXML);
		}
	}
}

function hasSubKeys(cookieName){
    var ret=false;
    var cookie=unescape(hGetCookie(cookieName));
    var subKeys=cookie.split("&");
    if(subKeys.length>=2){
        ret=true;
    }else{
        var subKeys=cookie.split("=");
        if(subKeys.length>=1){
            ret=true;
        }
    }
    return ret;
}

function hGetCookie(cookie_name){
	var regexp=new RegExp(cookie_name +"=(.*?)(;|$)","i");
	var results=regexp.exec(document.cookie);
	if(results){
		return(unescape(results[1]));
	}else{
		return null;
	}
} 

function GetCookie(cookieName,keyName){
	var ret;
	var cookie=unescape(hGetCookie(cookieName));
	//alert(cookie);
	if(keyName && hasSubKeys(cookieName)==true){
		var cookieData=getCookieData(cookie);
		ret=cookieData[keyName];
	}else{
		ret=cookie;
	}
	return ret
}

function getCookieData(cookie){
	var ret=[];
	var subKeys=cookie.split("&");
	for (var i=0;i<subKeys.length;i++){
		//alert(subKeys[i]);
		var pos=subKeys[i].indexOf("=");
		if(pos!=0){
			//alert("cookieData["+subKeys[i].substring(0,pos)+']='+subKeys[i].substring(pos+1));
			ret[subKeys[i].substring(0,pos)]=subKeys[i].substring(pos+1);
		}
	}
	return ret;
}

function getXMLNodeValue(obj, tag){
	return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
}

function getXMLNodeValues(obj, tag){
	var values = new Array();
	var xmlNode = obj.getElementsByTagName("string");
	for (var i = 0; i < xmlNode.length; i++){
		values.push(xmlNode[i].firstChild.nodeValue);
		if (values[values.length - 1] == null){
			values[values.length - 1] = 0;
		}
	}
	return values;
}

function getAJAXRequest() {
	var request;
	try 
		{request = new XMLHttpRequest();} 
	catch (trymicrosoft) {
		try 
			{request = new ActiveXObject("Msxml2.XMLHTTP");} 
		catch (othermicrosoft) {
			try 
				{request = new ActiveXObject("Microsoft.XMLHTTP");} 
			catch (failed) 
				{request = false;}
		}
	}
	return request;
}

function iconsClose(){
	currentIcons["dt"] = [0];
	currentIcons["int"] = [0, 0, 0];
	for (var j = 0; j < iconTypes.length; j++){
		for (var i = 0; i < icons[iconTypes[j]].length; i++){
			iconsDim(i + 1, iconTypes[j]);
		}
	}
	if (location.href.indexOf("update_profile.aspx") == -1){
		var iconPanelLink = getObject("iconPanelLink");
		iconPanelLink.onclick = null;
	}
	hideDPop('icon_selector');
}


/* SUBNAV ROLLOVER AND HIGHLIGHTING */
var currentSS = 0;
var ssnavImages;
var ssnavOn;
var ssnavOff;

function ssnavLight(ssNum){
	if (document.images){
		document.images["ssnav" + ssNum].src = ssnavOn[ssNum - 1].src;
	}
}

function ssnavDim(ssNum){
	if (document.images){
		if (ssNum != currentSS){
			document.images["ssnav" + ssNum].src = ssnavOff[ssNum - 1].src;
		}
	}
}

function ssnavInit(){
	if ((location.href.indexOf("products.aspx") != -1) && (getParamValue("ratings") != null)){
		if (getParamValue("ratings").toLowerCase() == "true"){
			tabselect(2);
			tablight(2);
		}
	}
	renderPromos();
	if (document.images["ssnav1"]){
		var imgSrc;
		var imgName;
		var pageURL = location.href.substring(location.href.lastIndexOf("/") + 1, location.href.lastIndexOf("."));
		ssnavImages = new Array();
		ssnavOn = new Array();
		ssnavOff = new Array();
		for (var i = 0; i < document.images.length; i++){
			imgName = document.images[i].name;
			if (imgName.indexOf("ssnav") == 0){
				ssnavImages[ssnavImages.length] = document.images[i];
				ssnavImages[ssnavImages.length - 1].id = parseInt(imgName.substring(5));
				imgSrc = ssnavImages[ssnavImages.length - 1].src;
				imgSrc = imgSrc.substring(0, imgSrc.indexOf(".gif"));
				ssnavOn[ssnavOn.length] = new Image();
				ssnavOn[ssnavOn.length - 1].src = imgSrc + "_over.gif";
				ssnavOff[ssnavOff.length] = new Image();
				ssnavOff[ssnavOff.length - 1].src = imgSrc + ".gif";
				imgSrc = imgSrc.substring(imgSrc.lastIndexOf("/ss_") + 4);
				if (imgSrc.toLowerCase() == pageURL.toLowerCase()){
					currentSS = ssnavImages.length;
					ssnavLight(currentSS);
					document.images[imgName].onclick = function(){
						return false;
					}
				}
				ssnavImages[ssnavImages.length - 1].onmouseover = function(){
					ssnavLight(this.id);
				}
				ssnavImages[ssnavImages.length - 1].onmouseout = function(){
					ssnavDim(this.id);
				}
			}
		}
	}

}

window.onload=ssnavInit;
//-->