var popUpWin = false;  
var browsertype=false;
if((navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)>=3)) browsertype=true;
if((navigator.appName=="Microsoft Internet Explorer")&&(parseInt(navigator.appVersion)>=4)) browsertype=true;

function e (z, h, w, b, g) {
	document.write('<div style="width:'+w+';height:'+h+';background:white url(http://images.cafepress.com/image/'+z+'_400x400.jpg) no-repeat center center;"><img border="'+b+'" class="imageborder" src="/content/marketplace/img/'+(g?'zoom':'spacer')+'.gif" width="'+w+'" height="'+h+'"></div>')
}

function objectdata(hsize,vsize,hilite,original,messge)
{if(browsertype)
{		this.messge=messge;
		this.simg=new Image(hsize,vsize);
		this.simg.src=hilite;
		this.rimg=new Image(hsize,vsize);
		this.rimg.src=original;
}}
/**
 ** changeDropDownValueSelected - finds a match to newIndexValue among the option values and sets the
 **									matching value to be the selected option
 ** Params:
 ** dropDownId - id of select drop down
 ** newSelectValue - new selected option value
**/
function changeDropDownValueSelected(dropDownId, newSelectValue) {
	var selectDropDown = document.getElementById(dropDownId);
	for(i=0; i < selectDropDown.options.length; i++) {
		var optionVal = selectDropDown.options[i].value;
		if (optionVal == newSelectValue) {
			selectDropDown.options[i].selected = true;
			return;
		}
	}
}
/**
 ** sets a global variable 'thumbnailPerspective' if it exists on the page
 **/
function setThumbnailPerspective(perspectiveValue) {
	if (thumbnailPerspective != undefined) {
		thumbnailPerspective = perspectiveValue;
	}
}

/**
 ** getColorAndViewLarger - used in prod_detail pages to get the current 
 ** chosen color value in the dropDown and pass this to launchHelp so that the proper
 ** colored product will be shown
 ** Params:
 ** dropDownId - id of select drop down
 ** theUrl - see launchHelp
 ** newFeatuers - see launchHelp
**/
function getColorAndViewLarger(dropDownId, theUrl, newFeatures) {
	//get value of color drop down
	var dropDown = document.getElementById(dropDownId);
	if (dropDown != undefined) {
		var colorNo = dropDown.options[dropDown.options.selectedIndex].value;
		theUrl = theUrl + '&colorNo=' + colorNo;
	}
	var appendStr = '&pr=F';
	if (thumbnailPerspective != undefined && thumbnailPerspective.toLowerCase() == 'back') {
		appendStr = '&pr=B';
	}
	theUrl = theUrl + appendStr;
	launchHelp(theUrl, newFeatures);
}
/**
 ** swapImgWithUrl() -- replaces target image src with given src string
 ** Params:
 **   ToImg - pass in the name of the target iamge
 **   NewImgUrl - pass in the new src URL to replace target image
 **/
 function swapImgWithUrl(ToImg, NewImgUrl)
 {
	if (document.images[ToImg] != undefined) {
		document.images[ToImg].src = NewImgUrl
	}
 }
 
/**
 ** swapImgsWithUrls() -- calls swapImgWithUrl for every element in the array
 ** Params:
 ** ToImgArray - array of target image names
 ** NewImgUrlArray - array of new src URL strings
 **/
 function swapImgsWithUrls(ToImgArray, NewImgUrlArray)
 {
	for(i=0; i < ToImgArray.length; i++) {
		swapImgWithUrl(ToImgArray[i], NewImgUrlArray[i])
	}
}
/**
 ** swapImg() -- swaps two images
 ** Params:
 **   ToImg - pass in the name of the target image
 **  FromImg - pass in the name of the original image
 **/
function swapimg(ToImg, FromImg)
{
	document.images[ToImg].src=document.images[FromImg].src
}

/**
** simulateClickSwatch -- used in prod_detail pages to simulate onclick of swatch images 
** with id=imageIdPrepend_<<chosenVal in dropdown>>
** Params:
**	imageIdPrepend -- the string to prepend to the id string e.g. imageColor_
**  dropDownId -- id of the select dropDown element
**/
function simulateClickSwatch(imageIdPrepend, dropDownId) {
	var dropDown = document.getElementById(dropDownId)
	//get the value selected
	var chosenVal = dropDown.options[dropDown.options.selectedIndex].value
	var imgId = imageIdPrepend + chosenVal;
	eval($('#' + imgId + ' > a').attr('href'));
}
/**
** getURLParam -- get url parameter value
**/
function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
   var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
   var aQueryString = strQueryString.split("&");
   for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
   }
}
return strReturn;
}

if (browsertype){
var object=new Array();

}

function hilite(name)
{if(browsertype)
{//window.status=object[name].messge;
document[name].src=object[name].simg.src;}}

function original(name)
{if(browsertype)
{//window.status="";
document[name].src=object[name].rimg.src;}}

/**
 * launchHelp -> use to pop up all help windows
 **/
function launchHelp(newURL, newFeatures)
{
  if ((navigator.appName=='Microsoft Internet Explorer') && (window.HelpWindow)) HelpWindow.close();
  HelpWindow = open(newURL, "HelpWindow", newFeatures + ",screenX=0,left=0,screenY=0,top=0,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,status=0,toolbar=0,scroll=1");
  if (HelpWindow.opener == null) HelpWindow.opener = window;
  HelpWindow.focus();
}

function CheckPopup() {
	if (popUpWin) {
		popUpWin.close();
	};
};

/**
 ** launchWin()
 **     use to launch all popup windows besides help
 **/
function launchWin(href, target, params)
{
  var features = params + ',screenX=0,left=0,screenY=0,top=0,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,status=0,toolbar=0';
  popWin = window.open(href, target, features);
  if (popWin.focus) popWin.focus();
}

//survey code
function openExitSurvey(SurveyURL) {
	if (ShowSurvey) { document.cookie = "ExitSurvey=1;path=/"; ExitSurveyWin = window.open(SurveyURL,'ExitSurveyWin','height=450,width=400",screenX=0,left=0,screenY=0,top=0,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,status=0,toolbar=0,scroll=1,scrollbars=1'); }


}






//-- CSS Rounded Corners START

function RoundChecker(){
if(!document.getElementById || !document.createElement)
    return(false);
var b=navigator.userAgent.toLowerCase();
if(b.indexOf("msie 5")>0 && b.indexOf("opera")==-1)
    return(false);
return(true);
}

function Round(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
    AddTop(v[i],bk,color,size);
    AddBottom(v[i],bk,color,size);
    }
}

function RoundedTop(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddTop(v[i],bk,color,size);
}

function RoundedBottom(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddBottom(v[i],bk,color,size);
}

function AddTop(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rbottom";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.appendChild(d,el.firstChild);
}

function getElementsBySelector(selector){
var i;
var s=[];
var selid="";
var selclass="";
var tag=selector;
var objlist=[];
if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    return(document.getElementById(fs[1]).getElementsByTagName(s[1]));
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    objlist.push(document.getElementById(selid));
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className==selclass){
        objlist.push(v[i]);
        }
    }
return(objlist);
}

//-- CSS Rounded Corners END





function getCPCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; }
  else { begin += 2; }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) { end = dc.length; }
  return unescape(dc.substring(begin + prefix.length, end));
}

//-- Function loadLongExampleWindow -- ajagtiani, 9/15/04
//-- loads the window for the long example popup in section_edit.aspx
function loadLongExampleWindow(url) {
	launchHelp(url,"height=380,width=550,scrollbars=1");
}

//-- Function loadShortExampleWindow - ajagtiani, 9/15/04
//--   Loads the short Example popup window in section_edit.aspx
function loadShortExampleWindow(url) {
	launchHelp(url,"height=480,width=430,scrollbars=1");
}

//--	Function loadHelpWindow - ajagtiani, 9/15/04
//--	loads help window for section_edit.aspx
function loadHelpWindow(url) {
	launchHelp(url,"height=300,width=400,scrollbars=1");
}

//returns the style of the DIV with the given divname
function getDivStyle(divname) {
 var style;
 if (isDOM) { style = document.getElementById(divname).style; }
 else { style = isIE ? document.all[divname].style
                     : document.layers[divname]; } // NS4
 return style;
}

// annoying detail: IE and NS6 store elt.top and elt.left as strings.
//Moves the given element by the given (X,Y) offset
function moveBy(elt,deltaX,deltaY) {
 elt.left = parseInt(elt.left) + deltaX;
 elt.top = parseInt(elt.top) + deltaY;
}

  //Toggles the visibility of the element with the given name
//If visible, make hidden. If hidden, make visible.
function toggleVisibility(divname,show) {
 var divstyle = document.getElementById(divname).style;
 if (show == 2) {
	divstyle.display='inline';
 } else if (show == 1) {
 	divstyle.display='block';
 } else if (show == 0) {
 	divstyle.display='none';
 }
}

//moveDiv() - moves a DIV to a specified location on an event
function moveDiv(e,divName) {
	var productListDiv = document.getElementById(divName);
	var x,y;

	//If IE, use e.client(x,y) + document.documentBody.scroll(Left/Top), else use e.pageX for Mozilla/Netscape where e is an Event object
	if(!document.all) {
		x = e.pageX;
		y = e.pageY;
	} else {
		x = e.clientX + document.documentElement.scrollLeft;
		y = e.clientY + document.documentElement.scrollTop;
	}

	//add spacing between mouse location and top of DIV location to prevent onmouseout from being executed
	x= x + 15;
	productListDiv.style.top = y + "px";
	productListDiv.style.left = x + "px";
}

//hideDiv() - hide all the products
function hideDiv(divName) {
	var div = document.getElementById(divName);
	div.style.display="none";
	div.innerHTML="";
}

//getType - used with product dropdown box
function getType(thisform) {
	if (thisform.type.options[thisform.type.selectedIndex].value != "") {
		thisform.action = "/"+thisform.s.value;
		thisform.submit();
	}
}

function showhideDiv(divname,disp) {
	document.getElementById(divname).style.display=disp;
}

// IE5 on Mac doesn't like Array.push and therefore
// also doesn't like string.split?
function splitStringToArray(stringToSplit,splitOnChar)
{
	var arr = new Array();
	var idx = 0;
	var start = -1;
	while(idx < stringToSplit.length && idx != -1)
	{
		start++;
		idx = stringToSplit.indexOf(splitOnChar,start);
		if(idx == -1)
		{
			idx = stringToSplit.length;
		}
		arr[arr.length] = stringToSplit.substring(start,idx);
		start = idx;
	}
	return arr;
}

//used to validate birthdate->year field
function validateYear(cntr)
{
	var txt = document.getElementById(cntr);
	if(txt)
	{
		var year = txt.value;
		var currDate=new Date();
		if(year.length != 4 || !isInteger(year) || year < 1900 || year > currDate.getFullYear())
		{
			alert('Year field is not valid. Please enter a valid year in the range: 1900 - ' + currDate.getFullYear());
			txt.select();
			return false;
		}
	} 
}

//used to validate if the supplied text is an integer
function isInteger(text)
{
	var n = text.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
	return n.length > 0 && !(/[^0-9]/).test(n);

}
function setVisibility(id,vis)
{
	var e = document.getElementById(id);
	if ( e != null) {
		e.style.display = vis;
	}
}

function _updateCartItemCount() {
	$('#cartItemCount').html( window.cafepress.cartItemCount.toString() + ' item' + (window.cafepress.cartItemCount == 1 ? '' : 's') );
}

function updateCartLabel() {
    $('#cartLabel').html( window.cafepress.cartLabel );
}

function updateHeader() {

    updateCartLabel();
    
	_updateCartItemCount();
	
	$('#signin').html( window.cafepress.signedIn ? 
		'<a href="../../50Pages/WWY_files/%27%20+%20window.cafepress.secureWww%20+%20%27/cp/members/login.aspx?logout=yes" rel="nofollow">Sign Out</a>' :
		'<a href="../../50Pages/WWY_files/%27%20+%20window.cafepress.secureWww%20+%20%27/cp/members/login.aspx?passthru=yes" rel="nofollow">Sign In</a>' );
	$('#custom').html('<a id="custom" href="http://' + window.cafepress.www + '/cp/customize/">Make Custom T-Shirts and More</a>');
	$('#startselling').html('<a id="startselling" href="http://' + window.cafepress.www + '/cp/info/sell/learn">Sell T-Shirts</a>');

	var youraccount = (window.cafepress.userName != '')?window.cafepress.userName+"'s Account":(window.cafepress.signedIn ?'Your Account':'Your Account');
	$('#youraccount').html( '<a href="../../50Pages/WWY_files/%27%20+%20window.cafepress.secureWww%20+%20%27/cp/members/login.aspx?passthru=yes&goto=/cp/members/index.aspx" rel="nofollow">'+ youraccount +'</a>' );
	if(!window.cafepress.signedIn)
		$('#youraccount').hide();
        _initializeSelectedHeaderCurrency();

	setupIntlHeaderLogo();
	updateSearch();
	
}

function updateMembersHeader() {
        var youraccount = (window.cafepress.userName != '')?window.cafepress.userName+"'s Account":(window.cafepress.signedIn ?'Your Account':'Your Account');
        $('#youraccount').html( '<a href="../../50Pages/WWY_files/%27%20+%20window.cafepress.secureWww%20+%20%27/cp/members/login.aspx?passthru=yes" rel="nofollow">'+ youraccount +'</a>' );
        updateCartLabel();
	_updateCartItemCount();
	_initializeSelectedHeaderCurrency();
	setupIntlHeaderLogo();
}




function cssClassByCountryCode(countryCode) {
    var className = "";

    switch (countryCode) {
        case 'AU': className = "au"; break;
        case 'CA': className = "ca"; break;
        case 'GB':
        case 'UK': className = "uk"; break;
        default: className = ""; break;
    }
    
    return className;
}

function getWWWDomainByCountryCode( countryCode )
{
    return getHostNameByCountryCode("www", countryCode);
}

function parseSubdomainFromHostname( hostName ) {
	var splitHostName = hostName.split(".");
	//first one is assumed to be subdomain
	return splitHostName[0];
}

function getHostNameByCountryCode( subDomain, countryCode )
{
        var subDomainHostName = subDomain + "."
	switch ( countryCode ) {
			case 'AU': subDomainHostName += window.cafepress.domain_au; break;
			case 'CA': subDomainHostName += window.cafepress.domain_ca; break;
			case 'UK' :
			case 'EU':
			case 'GB': subDomainHostName += window.cafepress.domain_uk; break;
			default: subDomainHostName += window.cafepress.domain_us; break;
	}
	return subDomainHostName;
}

function getCookie(name) {
	var dc = document.cookie;
	if (dc == null) {
		return "-1";
	}
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return "-1";
	} else begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function getPIDString(connector) {
	var pid = getCookie('cppid');
	if (pid != -1)
		return connector + 'pid=' + pid;
	return '';
}


/***
 ** stringToAppend has format key=value
 **/
 
function appendToQueryString(queryString, stringToAppend) {
    var newQueryString = '';
    
    if (queryString.substring(0,1) == '?') {
    	newQueryString = queryString.substring(1);
    	var data = queryString.split(',');
    	if (data.length > 0) {
    		newQueryString = '?' + newQueryString + '&' + stringToAppend;
    	} 
    } 
    if (newQueryString == '') {
    	newQueryString = '?' + stringToAppend;
    }
    return newQueryString;
}


function intlClick(link) {
	var connector = '&';
	if (link.href.indexOf('?') < 0)
		connector = '?';
	link.href += getPIDString(connector);
}

function constructOriginCountryFlagLink( countryCode ) {
    // place holder to generate the flag image and the message
    var content = "";

    switch (window.cafepress.originCountryCode) {
        case 'AU': content = "Shopping from Australia? "; break;
        case 'CA': content = "Shopping from Canada? "; break;
        case 'GB': content = "Shopping from the UK? "; break;
        case 'US': content = "Shopping from the US? "; break;
        default: content = ""; break;
    }
    
    return content; 
}

function updateSearch() {
	if($('#q').val() != '') {
		$('#searchBarForm input[name="q"]').attr("value",$('#q').val());
	}
	if($('#c').val() != '') {
		$('#searchBarForm input[name="c"]').attr("value",$('#c').val());
	}

	try {
		if (varPageType == "HomePage") {
			$('#searchBarForm input[name="q"]').attr("value",'');
			$('#searchBarForm input[name="c"]').attr("value",'666');
		}
	} catch (err) {
		// nothing to do.
	}
}


function initializeTabbedHeader() {
	$('ul#globalRetailNav li').click(function(){
	     $('ul#globalRetailNav li').each(function(i) { 
		 $(this).removeClass('selected'); 
		 
	     });
	     $(this).addClass('selected'); 
	});
	
	$('ul#subNavMenu li').click(function(){
	     $('ul#globalRetailNav li').each(function(i) { 
		 $(this).removeClass('current'); 
	     });
	     $(this).addClass('current'); 
	});
	
	
}

function IsDefined(element)
{
   return element != undefined;
}

function initializeSubNavHeader() {
	var pageType;
		try {
			pageType = varPageType;
		}
	catch (e) {}
	if (pageType != "HomePage" ) {
		highlightSubNav();
		highlightGlobalNav();
	}
	
}

function highlightSubNav()
{
        var subnode = $('#s-'+ window.cpsearch.rootSearchCategory);
	subnode.css('display','block');
	subnode.show();
	$('ul li:first-child').css('border-top', '0'); /* Force style for IE6 */
	if (IsDefined($('#c-' + window.cpsearch.searchCategory).attr("id")))
	{
	    $('#c-' + window.cpsearch.searchCategory).addClass("current");
	}
	else
	{
	  if(IsDefined($('#ct-'+ window.cpsearch.searchCategory).attr("id")))
	  {
	   	$('#ct-'+ window.cpsearch.searchCategory).find("a").css('font-weight','bold');
	   	$('#ct-'+ window.cpsearch.searchCategory).parent().parent().addClass('current');
	  }
	}
}

function highlightGlobalNav()
{
        
	if(IsDefined(window.cpsearch.searchCategory) && window.cpsearch.searchCategory != "666"){
	     var rootnode = $('#r-'+ window.cpsearch.rootSearchCategory);
			rootnode.addClass('selected');

	     if(IsDefined($('#globalRetailNav li.selected').attr('class')))
	     {
		if($('#globalRetailNav li.selected').attr('class').indexOf('firstnavitem') == 0)
		   $('#globalRetailNav li.selected a').css('background-position','0px  -64px');
		else if($('#globalRetailNav li.selected').attr('class').indexOf('lastnavitem') == 0)
		   $('#globalRetailNav li.selected a').css('background-position','right  -64px');
		else
		   $('#globalRetailNav li.selected a').css('background-position','-34px  -64px');
	      }
       }
}

function _initializeSelectedHeaderCurrency() {
	$(".intlMenuLink").hide();
	
	var elId = 'us';
	switch (window.cafepress.currencyCode) {
		case 'AUD': elId = 'aus'; break;
		case 'CAD': elId = 'can'; break;
		case 'GBP': elId = 'uk'; break;
		case 'EUR': elId = 'eur'; break;
	}
	$('a#' + elId).css('display', 'block');
}

function setupIntlHeaderLogo() {
	$('#intlHeaderLogo').empty().append([
		'<a href="http://', window.cafepress.www, '" title="CafePress.com" class="logo">',
			'<img src="/content/global/img/cafepress_au.gif" width="162" height="80" alt="CafePress Australia" title="CafePress Australia" id="logoAU" />',
			'<img src="/content/global/img/cafepress_ca.gif" width="132" height="80" alt="CafePress Canada" title="CafePress Canada" id="logoCA" />',
			'<img src="/content/global/img/cafepress_uk.gif" width="148" height="80" alt="CafePress United Kingdom" title="CafePress United Kingdom" id="logoUK" />',
			'<img src="/content/global/img/cafepress.gif" width="132" height="77" alt="CafePress.com" title="CafePress.com" id="logoUS" />',
		'</a>'
	].join(''));
 
	var selectedCountry = window.cafepress.countryCode;
	$(".logo > img").hide();
	if( selectedCountry == 'AU' ) { $("#logoAU").show(); }
	else if( selectedCountry == 'CA' ) { $("#logoCA").show(); }
	else if( selectedCountry == 'GB' ) { $("#logoUK").show(); }
	else if( selectedCountry == 'US' ) { $("#logoUS").show(); }
	else { $("#logoUS").show(); }
}

function writeInternationalSitesHeader() {
	var pathName = escape(document.URL);
	var content = [
		'<ul id="intldropdown" style="display:none;">',
			'<li id="dropdownAUS"><a href="http://', 
				window.cafepress.www, '/cp/international/currency.aspx?currency=AUD&pathname=', 
				pathName, 
				'" rel="nofollow">AUD</a></li>',
			'<li id="dropdownCAN"><a href="http://', 
				window.cafepress.www, 
				'/cp/international/currency.aspx?currency=CAD&pathname=', 
				pathName, 
				'" rel="nofollow">CAD</a></li>',
			'<li id="dropdownUK"><a href="http://', 
				window.cafepress.www, 
				'/cp/international/currency.aspx?currency=GBP&pathname=', 
				pathName, 
				'" rel="nofollow">GBP</a></li>',
			'<li id="dropdownEUR"><a href="http://',
				window.cafepress.www,
				'/cp/international/currency.aspx?currency=EUR&pathname=',
				pathName,
				'" rel="nofollow">EUR</a></li>',
			'<li id="dropdownUS" class="lastintl"><a href="http://', 
				window.cafepress.www, 
				'/cp/international/currency.aspx?currency=USD&pathname=', 
				pathName, 
				'" rel="nofollow">USD</a></li>',
		'</ul>' ];
	document.write(content.join(''));
}

/**
 * i.e cafepress.com => domainName then this function will return "cafepress.com'
 *     www.cafepress.com => will return "www"
 */
function parseHostnameFromDomainName(domainName) {
    if( domainName )
    {
        var arr = domainName.split('.');
        if( arr.length > 2 )
        {
            return arr[1];
        }else if( arr.length == 2 )
        {
            return arr[0];
        }else
        {
            return "";
        }
    } else
    {
        return "";
    }
}

function boldSelectedCountry() {
	var selectedCountry = window.cafepress.countryCode
	;
	if (selectedCountry == "AU") { $("#footerAUS").css('font-weight', 'bold'); }
	if (selectedCountry == "CA") { $("#footerCAN").css('font-weight', 'bold'); }
	if (selectedCountry == "GB") { $("#footerUK").css('font-weight', 'bold'); }
	if (selectedCountry == "US") { $("#footerUS").css('font-weight', 'bold'); }
}

var footerAlreadyWritten = false;

function writeInternationalCurrencyFooter(showCurrencyInFooter) {
	if (footerAlreadyWritten) {
		return;
	}
	
	var hostname = parseHostnameFromDomainName(window.cafepress.domain);
	var wwwurl = 'www.';
	var pathName = escape(document.URL);
	var selectedCountry = window.cafepress.countryCode;
	var selectedCurrency = window.cafepress.currencyCode;
	var pid = getPIDString('\/?');

	var currencyContent = [
		'<br/><br/>',
		'<ul id="currencyFooter">',
			'<li class="bold">Currency: </li>',
			'<li id="footerAUD"><a href="http://',
			    window.cafepress.www, '/cp/international/currency.aspx?currency=AUD&pathname=',
			    pathName,
			    '" rel="nofollow">AUD</a></li>',
			'<li id="footerCAD"><a href="http://',
			    window.cafepress.www,
			    '/cp/international/currency.aspx?currency=CAD&pathname=',
			    pathName,
			    '" rel="nofollow">CAD</a></li>',
			'<li id="footerGBP"><a href="http://',
			    window.cafepress.www,
			    '/cp/international/currency.aspx?currency=GBP&pathname=',
			    pathName,
			    '" rel="nofollow">GBP</a></li>',
			'<li id="footerEUR"><a href="http://',
			    window.cafepress.www,
			    '/cp/international/currency.aspx?currency=EUR&pathname=',
			    pathName,
			    '" rel="nofollow">EUR</a></li>',
			'<li id="footerUSD"><a href="http://',
			    window.cafepress.www,
			    '/cp/international/currency.aspx?currency=USD&pathname=',
			    pathName,
			    '" rel="nofollow">USD</a></li>',
		'</ul>',
		'<br/>'];

	var usdContent = 'All prices shown are in USD.';
	var content = '';
	if (showCurrencyInFooter) {
		content += currencyContent.join('');
	} else {
		content += '<br/><br/>' + usdContent;
	}
	document.write(content);
	footerAlreadyWritten = true;

	if (showCurrencyInFooter) {
		if (selectedCurrency == "AUD") { $("#footerAUD").css('font-weight', 'bold'); }
		if (selectedCurrency == "CAD") { $("#footerCAD").css('font-weight', 'bold'); }
		if (selectedCurrency == "GBP") { $("#footerGBP").css('font-weight', 'bold'); }
		if (selectedCurrency == "EUR") { $("#footerEUR").css('font-weight', 'bold'); }
		if (selectedCurrency == "USD") { $("#footerUSD").css('font-weight', 'bold'); }
	}
}

function initializePremiumShopHeader() {
	var selectedCurrency = window.cafepress.currencyCode;
	
	$(".intlPremMenuLink").css('display','none');
	if (selectedCurrency == 'AUD') { $("a.aud").css('display', 'block'); }
	else if (selectedCurrency == 'CAD') { $("a.cad").css('display', 'block'); }
	else if (selectedCurrency == 'GBP') { $("a.gbp").css('display', 'block'); }
	else if (selectedCurrency == 'EUR') { $("a.eur").css('display', 'block'); }
	else { $("a.usd").css('display', 'block'); }
}

function writePremiumShopHeader() {
	var pathName = escape(document.URL);

	document.write( [
		'<a class="aud intlPremMenuLink">AUD<div id="intlArrowDown"></div></a>',
		'<a class="cad intlPremMenuLink">CAD<div id="intlArrowDown"></div></a>',
		'<a class="gbp intlPremMenuLink">GBP<div id="intlArrowDown"></div></a>',
		'<a class="eur intlPremMenuLink">EUR<div id="intlArrowDown"></div></a>',
		'<a class="usd intlPremMenuLink">USD<div id="intlArrowDown"></div></a>',
		'<ul id="intlCurrencyDropdown" style="display:none;">',
		'<li class="aud"><a href="http://', window.cafepress.www, '/cp/international/currency.aspx?currency=AUD&pathname=' + pathName + '" rel="nofollow">AUD</a></li>',
		'<li class="cad"><a href="http://', window.cafepress.www, '/cp/international/currency.aspx?currency=CAD&pathname=' + pathName + '" rel="nofollow">CAD</a></li>',
		'<li class="gbp"><a href="http://', window.cafepress.www, '/cp/international/currency.aspx?currency=GBP&pathname=' + pathName + '" rel="nofollow">GBP</a></li>',
		'<li class="eur"><a href="http://', window.cafepress.www, '/cp/international/currency.aspx?currency=EUR&pathname=' + pathName + '" rel="nofollow">EUR</a></li>',
		'<li class="usd lastintl"><a href="http://', window.cafepress.www, '/cp/international/currency.aspx?currency=USD&pathname=' + pathName + '" rel="nofollow">USD</a></li>',
		'</ul>' ].join('')
	);
}

String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

/**
 * change browser location to ${subdomain}.${window.cafepress.domain}/${uri}
 * e.g shop.cafepress.com/mug
 * where shop is subdomain
 *       cafepress.com is window.cafepress.domain
 *       mug will be the uri
 */
function goToSubDomain(isSecure, subdomain, uri) {
    protocol = (isSecure) ? "https" : "http";
    url = protocol + "://" + subdomain.trim() + "." + window.cafepress.domain + "/" + uri.trim();
    window.location.href = url
}

/**
 * Remove non-numberic chars from textbox
 */
function removeNonNumbers(mytextbox) {
    var myNumbers = "0123456789";
    var w = "";
    for (i = 0; i < mytextbox.value.length; i++) {
        x = mytextbox.value.charAt(i);
        if (myNumbers.indexOf(x, 0) != -1) {
            w += x;
        }
    }
    mytextbox.value = w;
}

function initializeleftNavigation(obj) {
	jQuery("#accnode" + obj.currentCategory).addClass("selectedProduct");
	$("#navigation").accordion({ alwaysOpen: false, active: $("#acc" + obj.selectedParentCategory), autoheight: false, header: 'div.acc1', clearStyle: true });
	$.each(obj.accordionList, function(n, node) { $("#ul-acc" + node).accordion({ alwaysOpen: false, active: $("#acc" + obj.selectedCategory), autoheight: false, header: 'div.acc' + node, clearStyle: true }); });

	if (obj.selectedCategory === obj.rootId)
		obj.accordionIdList.accordion("activate", -1);

	jQuery("#navigation a.ui-link").click(function() {
		window.location = this.href;
	});
}

function addTopicParamToURLFor(divid, topic)
{
	if(topic)
	{
		var oldVal = $('#'+divid +' a').attr('href');
		if (oldVal)
		{
			var indexQ = oldVal.indexOf('?');
			var prefix = "&";
			if (indexQ < 0)
			{
				prefix="?";
			}
			$('#'+divid +' a').attr('href', oldVal + prefix + "topic=" + topic);
	   	}
	}
}


var divsToUpdate = new Array();
function registerDivIdToReplaceInDev(divid)
{
    index  = divsToUpdate.length;
    divsToUpdate[index] = $('#'+divid);
}

function updateRegisteredDivsForSubDomain()
{
   /*$(document).ready(function() {
   	if(window.cafepress.domain.indexOf(".dev") > -1)
       updateDivs(divsToUpdate);
   });*/
   if(window.cafepress.domain.indexOf(".dev") > -1)
   	updateDivs(divsToUpdate);
}
function updateDivs(list)
{
   jQuery.each(list,function(n, node) 
   {
	if (node.html()) {
	node.html(node.html().replace(/cafepress.com.au/gi, window.cafepress.domain_au));
	node.html(node.html().replace(/cafepress.com/gi, window.cafepress.domain_us));
	node.html(node.html().replace(/cafepress.ca/gi, window.cafepress.domain_ca));
	node.html(node.html().replace(/cafepress.co.uk/gi, window.cafepress.domain_uk));
	node.html(node.html().replace(/cafepress.gb/gi, window.cafepress.domain_uk));
	}
   });
	

}

