
// 点击商品分类链接到商品列表页
$(function() {

			$(".myItemType").click(function() {

				var myParentId = $(this).siblings(".itemTypePid").html();
				var myParentContent = $("#parentItemType" + myParentId).html();
				var myId = $(this).next(".itemTypeId").html();
				var myContent = $(this).html();
				myContent = myContent.replace(/&amp;/ig,"&");
				myParentContent = myParentContent.replace(/&amp;/ig,"&");
				if(myParentContent.indexOf("<img") >-1 || myParentContent.indexOf("<IMG") >-1 )
				{
					myParentContent=$(myParentContent).attr("alt");
				}
				
				
				if(myContent.indexOf("<img") >-1 || myContent.indexOf("<IMG") >-1)
				{
					myContent=$(this).attr("title");
					
				}

				
				//alert("myContent="+myContent);
				var content = myParentId + ":" + encodeURIComponent(myParentContent,"utf-8") + ";" + myId
						+ ":" + encodeURIComponent(myContent,"utf-8");
				var href = $(this).attr("href");
				
				
				$(this).attr("href", href + "&itypeNames=" + content);

			});

			$(".myItemTypeParent").click(function() {

						var myId = $(this).siblings(".itemTypeId").html();
						var myContent = $(this).html();
						//alert("before myItemTypeParent content="+myContent.replace(/&amp;/ig,"%26"));
						myContent = myContent.replace(/&amp;/ig,"&");
						if(myContent.indexOf("<img") >-1 || myContent.indexOf("<IMG") >-1)
						{
							myContent=$(this).attr("title");
							
						}
						
						var content = myId + ":" + encodeURIComponent(myContent,"utf-8");
						var href = $(this).attr("href");
						//alert("myItemTypeParent content="+content);
						$(this).attr("href", href + "&itypeNames=" + content);
						
					});
});

			// 加入到cookie
//			$(".itemPhoto").click(function() {
//				var itemId = $(this).children(".item_id").html();
//				var url = $(this).children("img").attr("src");
//				url = url.replace("100x100", "45x45");
//				var sellingPrice = $(this).children(".item_price").html();
//				var item = itemId + "-www.ctoshop.com-" + url
//						+ "-www.ctoshop.com-" + sellingPrice
//						+ "@www.ctoshop.com@"
//
//				if (!isExist(itemId, item)) {
//					var before = $.cookie("item");
//					if (null != before) {
//						item = before + item;
//					}
//					$.cookie("item", item, {
//								expires : 7
//							});
//				}
//
//			});
//
//		});
//
//		function isExist(id, item) {
//			if (item != null) {
//				if (item.indexOf(id + "-www.ctoshop.com-") > 0) {
//					return true;
//				} else {
//					return false;
//				}
//			}
//		}


//cookie相关函数
		var myHostName=location.hostname.replace(/\./g,"_");

		function getCookieVal (offset) 
		{ 
			var endstr = document.cookie.indexOf (";", offset); 
			if (endstr == -1) endstr = document.cookie.length; 
			return unescape(document.cookie.substring(offset, endstr)); 
		} 
								 
		 function getCookie (name) 
		 {
				 var arg = name + "="; 
				 var alen = arg.length; 
				 var clen = document.cookie.length; 
				 var i = 0; 
				 while (i < clen) 
				 { 
					 var j = i + alen; 
					 if (document.cookie.substring(i, j) == arg) return getCookieVal (j); 
					 i = document.cookie.indexOf(" ", i) + 1; 
					 if (i == 0) break; 
				 } 
				 return null; 
		 } 

		function setCookie (name, value) 
		{ 
			   var exp = new Date(); 
			   exp.setTime (exp.getTime()+1 * (30 * 1000)); //+1 day
			   document.cookie = name + "=" + value + "; expires=" + exp.toGMTString(); 
		}

		function glog(evt)
		{
			//alert("location.hostname myHostName="+myHostName);	
			evt=evt?evt:window.event;
			var srcElem=(evt.target)?evt.target:evt.srcElement;
			try
			{
				while(srcElem.parentNode&&srcElem!=srcElem.parentNode)
				{

					
								
					if(srcElem.tagName&&srcElem.tagName.toUpperCase()=="A")
					{
						//linkname=encodeURIComponent(srcElem.innerHTML,"utf-8");
						//linkname=encodeURIComponent(linkname,"utf-8");
						
						linkname=$(srcElem.innerHTML).attr("src");//srcElem.innerHTML;
						//alert("linkname="+$(srcElem.innerHTML).attr("src"));
						linkname=linkname.replace("220x220","45x45");
						myHref=srcElem.href.substring(srcElem.href.lastIndexOf("?")+1);
						//alert("srcElem.href="+srcElem.href+"\n"+myHref);
						address=myHref+"_www.ctoshop.cn_";
						wlink=linkname+"+"+address;	
						myAddr =wlink;
						old_info=getCookie(myHostName);//history_info
						var insert=true;
						if(old_info==null)     //判断cookie是否为空
						{
							insert=true;
						}
						else
						{	
							var old_link=old_info.split("_www.ctoshop.cn_");
							for(var j=0;j<=5;j++)
							{
								if(old_link[j].indexOf(linkname)!=-1)
									insert=false;
								if(old_link[j]=="null")
									break;
							}
						}
					/////////////////////////////
						if(insert)  
						{
							wlink+=getCookie(myHostName);
							setCookie(myHostName,wlink);
							history_show().reload();
							break;
						}
					}

					srcElem = srcElem.parentNode;
				}
			}
			catch(e){}

			return true;
		}

		document.onclick=glog;

		function history_show()
		{			
			var history_info=getCookie(myHostName);
			var content="";	
			if(history_info!=null)
			{
				history_arg=history_info.split("_www.ctoshop.cn_");
				var i;
				for(i=0;i<=5;i++)
				{
					if(history_arg[i]!="null" && history_arg[i] != undefined)
					{
						var wlink=history_arg[i].split("+");
						//alert("history_show="+i+""+wlink);
						//content+=("<font color='#ff000'>↑</font>"+"<a href='"+decodeURI(decodeURI(wlink[1],"utf-8"),"utf-8")+"' target='_blank'>"+decodeURI(decodeURI(wlink[0],"utf-8"),"utf-8")+"</a><br>");
						content+=("<li>"+"<a href='http://"+location.hostname+"/template/detail/displaydetail.html?"+wlink[1]+"'><img src='"+wlink[0]+"' /></a></li>");


					}
					document.getElementById("history").innerHTML=content;
				}
			}
			else
			{
				document.getElementById("history").innerHTML="对不起，您没有任何浏览纪录";
			}
		}

		function cleanCookie (name, value)  
		 {  
			 var argv = cleanCookie.arguments;  
			 var argc = cleanCookie.arguments.length;  
			 var expires = (argc > 2) ? argv[2] : null;  
			 var path = (argc > 3) ? argv[3] : null;  
			 var domain = (argc > 4) ? argv[4] : null;  
			 var secure = (argc > 5) ? argv[5] : false;  
			 document.cookie = name + "=" + escape (value) +  
			 ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +  
			 ((path == null) ? "" : ("; path=" + path)) +  
			 ((domain == null) ? "" : ("; domain=" + domain)) +  
			 ((secure == true) ? "; secure" : "");  
			 
		 }  

		 function ResetCookie()  
		 {  
			//alert("myAddr="+myAddr);
			cleanCookie(myHostName, 0, null, "/");   
		 }
		// JavaScript Document