/* <![CDATA[ */
function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}
document.title = document.title.replace(/ >/g, "");
document.title = document.title.replace(/, All Items/g, "");
document.title = document.title.replace(/\./g, "");

if (location.href.match(/clickd=size/)||location.href.match(/clickd=shopbysize/)) {
	document.getElementById('othersizescontainer').style.display='block';
}

if (document.getElementById("productGrid")){
		if (document.getElementById("productGrid").getElementsByTagName('h2')){
		document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML=document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML.replace(/Products &gt;[\s]/g, "");
		document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML=document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML.replace(/, All Items/g, "");
		document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML=document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML.replace(/\./g, "");
		document.cookie = 'productGridURL='+escape(location.href)+escape(formrequested)+'; domain=knitzees.com; path=/';
				
		document.cookie = 'productGridTitle='+escape(document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML)+'; domain=knitzees.com; path=/';

		landingh2suffix="";
		
		document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML="<a href='/'>Home</a> &nbsp;>&nbsp; "+document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML+landingh2suffix;
	}
	if (document.getElementById("topfilters_container") && !document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML.match(/Search Results/) && !document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML.match(/Specials/) && !document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML.match(/Halloween/) && !document.getElementById("productGrid").getElementsByTagName('h2')[0].innerHTML.match(/New Arrivals/)){
		document.getElementById("topfilters_container").style.display="block"; //need this to turn on topfilters container-- its off unless productGrid is present
		
		
				//code in here to decide which color background to display and display it.
				if (document.getElementById("customListId4")) {
			switch (document.getElementById("customListId4").options[document.getElementById("customListId4").selectedIndex].text) {
				case "Boys":
					document.write('<style>#topfilters select#customListId2, #topfilters select#customListId3, #topfilters select#customListId4, #topfilters select#customListId5 , #topOptions .myrow .option select{background-color: #deeaf9;}</style>');
					break;
				case "Girls":
					document.write('<style>#topfilters select#customListId2, #topfilters select#customListId3, #topfilters select#customListId4, #topfilters select#customListId5 , #topOptions .myrow .option select{background-color: #fcdce9;}</style>');				
					break;
				case "Unisex":
					document.write('<style>#topfilters select#customListId2, #topfilters select#customListId3, #topfilters select#customListId4, #topfilters select#customListId5 , #topOptions .myrow .option select{background-color: #EBF3D6;}</style>');				
					break;					
				default:
					document.write('<style>#topfilters select#customListId2, #topfilters select#customListId3, #topfilters select#customListId4, #topfilters select#customListId5 , #topOptions .myrow .option select{background-color: #ffffac;}</style>');
					break;
				
			}
		}
		
		if (document.getElementById("customListId5")) {
			
			switch (document.getElementById("customListId5").options[document.getElementById("customListId5").selectedIndex].text) {
				case "Baby Sweaters":
					document.getElementById("topfilters_photo").src="/design/images/baby-sweaters.jpg";
					document.getElementById("topfilters_photo").alt="baby sweaters";
					document.getElementById("topfilters_photo").style.display="block";
					break;
				case "Blankets":
					document.getElementById("topfilters_photo").src="/design/images/blankets-category.jpg";
					document.getElementById("topfilters_photo").style.display="block";
					break;
				case "Baby Hats":
					document.getElementById("topfilters_photo").src="/design/images/baby-hats.jpg";
					document.getElementById("topfilters_photo").alt="baby hats";
					document.getElementById("topfilters_photo").style.display="block";
					break;
				case "Mittens":
					document.getElementById("topfilters_photo").src="/design/images/mittens_category.jpg";
					document.getElementById("topfilters_photo").style.display="block";
					break;
				case "Booties":
					document.getElementById("topfilters_photo").src="/design/images/booties_category.jpg"; 
					document.getElementById("topfilters_photo").style.display="block";
					break;		
				case "Puppets":
					document.getElementById("topfilters_photo").src="/design/images/finger-puppets.jpg"; 
					document.getElementById("topfilters_photo").style.display="block";
					break;
				case "Summer Clothes":
					document.getElementById("topfilters_photo").src="/design/images/summer-clothes.jpg"; 
					document.getElementById("topfilters_photo").style.display="block";
					break;
				case "Onesies":
					document.getElementById("topfilters_photo").src="/design/images/onesies.jpg"; 
					document.getElementById("topfilters_photo").style.display="block";
					break;
				default:
					if(document.getElementById("customListId2").selectedIndex == "1"){
						document.getElementById("topfilters_photo").src="/design/images/newborn-baby-gifts.jpg";
						document.getElementById("topfilters_photo").alt="newborn baby gifts are great for baby showers";
					document.getElementById("topfilters_photo").style.display="block";
					} else if(document.getElementById("customListId4").options[document.getElementById("customListId4").selectedIndex].text == "Boys")
					{document.getElementById("topfilters_photo").src="/design/images/boys_category.jpg"; 
					document.getElementById("topfilters_photo").style.display="block";
					} else if(document.getElementById("customListId4").options[document.getElementById("customListId4").selectedIndex].text == "Unisex")
					{document.getElementById("topfilters_photo").src="/design/images/unisex-category.jpg"; 
					document.getElementById("topfilters_photo").style.display="block";
					} else if(document.getElementById("customListId4").options[document.getElementById("customListId4").selectedIndex].text == "Girls")
					{document.getElementById("topfilters_photo").src="/design/images/girls-category.jpg"; 
					document.getElementById("topfilters_photo").style.display="block";
					}
					break;
				
			}
			if (location.href.match(/clickd=shopbysize/)) {
					document.getElementById("topfilters_photo").src="/design/images/shopbysizehelp.gif";
					document.getElementById("topfilters_photo").style.display="block";
					document.write('<style>#topfilters #widgetCustomProductList2 .top{color: #CA006A;}</style>');
			}
		}
		
		//remove --- and -default entries from custom product lists and make blank
		if (document.getElementById("customListId2")){
			document.getElementById("customListId2")[0].text = "";

			//remove periods from size list.  periods were put there to fix alphabetical vs. numeric sorting
			for (var i = 0; i<document.getElementById("customListId2").length; i++) {
				document.getElementById("customListId2")[i].text = document.getElementById("customListId2")[i].text.replace(/\./g, "");
			}
		}
		if (document.getElementById("customListId3")){
			document.getElementById("customListId3")[0].text = "";
		}		
		if (document.getElementById("customListId4")){
			document.getElementById("customListId4")[0].text = "";
		}		
		if (document.getElementById("customListId5")){
			document.getElementById("customListId5")[0].text = "";
		}		
	}

//commenting this out during custom products list problem
	if (document.getElementsByTagName('form')){
		for (var formsno = 0; formsno<document.getElementsByTagName('form').length; formsno++) {
			if (document.getElementsByTagName('form')[formsno].name.match(/custom_product_lists/) && document.ds_sort_products) {
				document.getElementsByTagName('form')[formsno].innerHTML = "<input name='sortBy' type='hidden' value='" + document.getElementsByName('ds_sort_products')[0].sortBy.options[document.getElementsByName('ds_sort_products')[0].sortBy.selectedIndex].value + "'>" + document.getElementsByTagName('form')[formsno].innerHTML;
			}
		}
	}
}

if (document.getElementById("productDetail")){
	document.getElementById("mysidebar").style.display="none";
	//document.getElementById("delayalert").style.display="block";
	document.getElementById("nosizehelp").style.display="block";
	if (document.getElementById("productDetail").getElementsByTagName('h2')){
			document.cookie= 'productDetailURL='+escape(location.href)+'; domain=knitzees.com; path=/';
			document.cookie= 'productDetailTitle='+escape(document.getElementById("productDetail").getElementsByTagName('h2')[0].innerHTML)+'; domain=knitzees.com; path=/';
			productGridURL = get_cookie("productGridURL");
			productGridTitle = get_cookie("productGridTitle");
			breadcrumbinsert = "";
			if (productGridURL && productGridTitle) {
				breadcrumbinsert = "<a href="+productGridURL+"> "+productGridTitle+" </A> > ";
			}
			document.getElementById("productDetail").getElementsByTagName('h2')[0].innerHTML = "<a href='/'>Home</A> &nbsp;>&nbsp; " + breadcrumbinsert + document.getElementById("productDetail").getElementsByTagName('h2')[0].innerHTML;
	}
	if (document.getElementById("extraDetails")){
		document.getElementById("extraDetails").innerHTML = document.getElementById("extraDetails").innerHTML.replace(/&nbsp;\(Required\)/g, "");
	}
	//add argument onto URLs in related products display so that we can recognize it and remove breadcrumbcookies
	if (document.getElementById("productsRelated")){
		if (document.getElementById("productsRelated").getElementsByTagName("a")){
			for (var i = 0; i < document.getElementById("productsRelated").getElementsByTagName("a").length; i++){
							document.getElementById("productsRelated").getElementsByTagName("a")[i].href=document.getElementById("productsRelated").getElementsByTagName("a")[i].href+"?clickd=erasebreadcrumbcookies";
							//alert(document.getElementById("productsRelated").getElementsByTagName("a")[i].href);
			}
		}
	}
}
//populate the subject field with the last item viewed as indicated by the cookie
if (document.getElementById("CUSTOMSUBJECT")){
	if (get_cookie("productDetailTitle")){
		document.getElementById("CUSTOMSUBJECT").defaultValue=get_cookie("productDetailTitle");
	
	
		if (document.getElementById("pageContent").getElementsByTagName('h2')){
			productGridURL = get_cookie("productGridURL");
			productGridTitle = get_cookie("productGridTitle");	
			productDetailURL = get_cookie("productDetailURL");
			productDetailTitle = get_cookie("productDetailTitle");
			breadcrumbinsert = "";
			if (productGridURL && productGridTitle) {
//				breadcrumbinsert = "<a href="+productGridURL+"> "+productGridTitle+" </A> > ";
			}
			if (productDetailURL && productDetailTitle) {
				breadcrumbinsert = breadcrumbinsert + "<a href="+productDetailURL+"> "+productDetailTitle+" </A> > ";
			}
			document.getElementById("pageContent").getElementsByTagName('h2')[0].innerHTML = breadcrumbinsert + document.getElementById("pageContent").getElementsByTagName('h2')[0].innerHTML;	
		}
	}
}

if (document.getElementById("viewCart")){
	document.getElementById("mysidebar").style.display="none";

	if (document.getElementById("viewCart").getElementsByTagName('h2')){
		productGridURL = get_cookie("productGridURL");
		productGridTitle = get_cookie("productGridTitle");	
		productDetailURL = get_cookie("productDetailURL");
		productDetailTitle = get_cookie("productDetailTitle");
		breadcrumbinsert = "";
		if (productGridURL && productGridTitle) {
			breadcrumbinsert = "<a href="+productGridURL+"> "+productGridTitle+" </A> > ";
		}
		if (productDetailURL && productDetailTitle) {
			breadcrumbinsert = breadcrumbinsert + "<a href="+productDetailURL+"> "+productDetailTitle+" </A> > ";
		}
		document.getElementById("viewCart").getElementsByTagName('h2')[0].innerHTML = "<a href='/'>Home</A> &nbsp;>&nbsp; " + breadcrumbinsert + document.getElementById("viewCart").getElementsByTagName('h2')[0].innerHTML;

		//document.getElementById("viewCart").getElementsByTagName('h2')[0].innerHTML = document.getElementById("viewCart").getElementsByTagName('h2')[0].innerHTML + '<div id="pageError" style="font-size:1.2em;background-color:#f8f9c0;margin-top:15px;">Shipping Alert: Your order will leave our warehouse Monday June 14.</div>';			
	}
	
	if (productGridURL && document.getElementById("cartButtons")){
		continueReplace = "javascript:goThere(productGridURL)";
		document.getElementById("cartButtons").innerHTML = document.getElementById("cartButtons").innerHTML.replace(/javascript:goThere\('http:\/\/www\.knitzees\.com\/cart\.php'\);/g, "javascript:goThere(productGridURL)");
		document.getElementById("cartButtons").innerHTML = document.getElementById("cartButtons").innerHTML.replace(/- Or -/g, "");
	}
	
	if (document.getElementById("cartAmounts")){
		document.getElementById("cartAmounts").innerHTML = document.getElementById("cartAmounts").innerHTML + "<div id='cartAmountsCheckout'><a href='javascript:checkout();'></a></div>";
		}
	//add argument onto URLs in crossSell display so that we can recognize it and remove breadcrumbcookies
	if (document.getElementById("crossSell")){
		if (document.getElementById("crossSell").getElementsByTagName("a")){
			for (var i = 0; i < document.getElementById("crossSell").getElementsByTagName("a").length; i++){
							document.getElementById("crossSell").getElementsByTagName("a")[i].href=document.getElementById("crossSell").getElementsByTagName("a")[i].href+"?clickd=erasebreadcrumbcookies";
							//alert(document.getElementById("crossSell").getElementsByTagName("a")[i].href);
			}
		}
	}
}	

/* ]]> */
