/* <![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, "");

//get rid of absolute pathnames throughout pages
for (var i = 0; i < document.images.length; i++){
		document.images[i].src = document.images[i].src.replace(/http.*knitzees\.com/g, "");
		//alert (document.images[i].src);
}

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);
			}
		}
	}
	
	
	//section to fix product images
	var mbinclude="";  //code to substitute into beginning of description div
		mbinclude += "<div class=\"body\">";
		mbinclude += "<div id=\"mbaltphotos\" style=\"display:none;\">";
		//mbinclude += "<div id=\"mymainphoto\" style=\"padding-bottom: 10px; padding-top: 10px; margin-top: -44px;\"><img id=\"thephoto\" alt=\"\" src=\"\/design\/images\/cleardot.gif\" \/><\/div>";
		mbinclude += "<div id=\"mymainphoto\" style=\"padding-bottom: 10px;\"><img id=\"thephoto\" alt=\"\" src=\"\/design\/images\/cleardot.gif\" \/><\/div>";
		mbinclude += "<div id=\"mymainthumbnail\" style=\"padding-bottom: 20px;\">";
		mbinclude += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"\" align=\"left\" style=\"margin-bottom: 20px;\">";
		mbinclude += "    <tbody>";
		mbinclude += "        <tr>";
		mbinclude += "            <td width=\"95px\"><img id=\"mbthumb1\" alt=\"\" onmouseover=\"document.getElementById('thephoto').src=mbimages[1]\" src=\"\/design\/images\/cleardot.gif\" \/><\/td>";
		mbinclude += "            <td width=\"95px\"><img id=\"mbthumb2\" alt=\"\" onmouseover=\"document.getElementById('thephoto').src=mbimages[3]\" src=\"\/design\/images\/cleardot.gif\" \/><\/td>";
		mbinclude += "            <td><img id=\"mbthumb3\" alt=\"\" onmouseover=\"document.getElementById('thephoto').src=mbimages[5]\" src=\"\/design\/images\/cleardot.gif\" \/><\/td>";
		mbinclude += "        <\/tr>";
		mbinclude += "        <tr tbody=\"\">";
		mbinclude += "        <\/tr>";
		mbinclude += "    <\/tbody>";
		mbinclude += "<\/table>";
		mbinclude += "<\/div>";
		mbinclude += "<hr \/>";
		mbinclude += "<\/div>";
	//	get all images named with three numbers.jpg into an array for working with
	var mbimage = "";
	var mbimages = new Array();
	var j = 0;
	for (var i = 0; i < document.images.length; i++){
		if (document.images[i].src.match(/.*\/[\d][\d][\d]\.jpg/)) {
			mbimages[j] = document.images[i].src;
			//mbimage = mbimage + '\n' + document.images[i].src;
			j++;
		} 
	}	
	//alert(mbimages[7] + '\n');
	
	
	//get a count of the number of images in the productPhotos section so that we don't use cross-sell up-sell photos in the main photo thumbmails
	var mbimagecount = document.getElementById('productPhotos').innerHTML.match(/.*\/[\d][\d][\d]\.jpg/g).length;
	//alert (mbimagecount);
	
	//insert mbinclude text into the beginning of the product detail description area
	//first get IE version if IE
	var Browser = {
	Version: function() {
		var version = 999; // we assume a sane browser
		if (navigator.appVersion.indexOf("MSIE") != -1)
			version = parseFloat(navigator.appVersion.split("MSIE")[1]);
			return version;
		}
	}
	if (Browser.Version() < 7) {
		//alert('ie6');
	}
	if (Browser.Version() >= 7 && Browser.Version() < 8) {
		//alert('ie7');
	}
	if (Browser.Version() >= 8 && Browser.Version() < 9) {
		//alert('ie8');
	}
	
	if(1){	
//	if(Browser.Version() < 9){	
// alert(document.getElementById('productPhotos').style.display);
//	if(document.getElementById('productPhotos').style.display=='none' || Browser.Version() < 9){	
//alert(document.getElementById('productPhotos').style.display);
		//if (Browser.Version() >= 9){
			document.getElementById('productPhotos').style.display='none';
		//}
		//document.getElementById('photos').style.display='none';
		//alert('');
		//document.getElementById('productDescription').innerHTML = document.getElementById('productDescription').innerHTML.replace(/<div class="body">/g, mbinclude);
		document.getElementById('productDescription').innerHTML = mbinclude + document.getElementById('productDescription').innerHTML;
		document.getElementById('mbaltphotos').style.display='';
		document.getElementById('thephoto').src = mbimages[1];
		document.getElementById('mbthumb1').src = mbimages[0];
		//check the number of photos in the main section and only include the right number.
		if (mbimagecount > 2) {
			document.getElementById('mbthumb2').src = mbimages[2];
		}
		if (mbimagecount > 4) {
			document.getElementById('mbthumb3').src = mbimages[4];
		}
}

}
//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;

		//alert note for shipping delay message in shopping cart
		//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 Sept. 20.</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);
			}
		}
	}
}	

/* ]]> */

