function readCookie(name)
{
  var cookieValue = "";
  var search_s = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search_s);
    if (offset != -1)
    { 
      offset += search_s.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
function writeCookie(name, value, hours)
{
  var expire = "";  
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire + ";domain=.ea3w.com;path=/; ";
}
function last_view(tp,pro_name,subcatid,subcatname){
	var cookie_name = 'visited_pro_cookie_1ast';
	var write_new 	= true;	
	var cookie_value=readCookie(cookie_name);
	//alert(cookie_value);
	var item_arr=cookie_value.split("###");
	
	if(item_arr){
		
		var i = item_arr.length;
		var j = 0;
		var t = 0;
		//alert(i);
		if(i>5){
			t = i-5;
		}else{
			t = 0;
		};
		//alert(i);
		var ids = '';
		var proid = '';
		var name = '';
		for(; t<item_arr.length; t++){
			//alert(item_arr[i]);
			tmp_info_arr=item_arr[i-1].split("|");
			proid  = tmp_info_arr[0];
			name = tmp_info_arr[1];
			if(proid && name){
				i--;
				document.write('<li><a href="http://price.ea3w.com/product.php?pro_id='+proid+'">'+name.substring(0,20)+'</a></li>');
				j=1;
			}
		}		
	}
	tmp_info_arr = item_arr[item_arr.length-1].split("|");
	proid  = tmp_info_arr[0];
	userid = tmp_info_arr[4];
	if(proid != tp && item_arr.length>2){
		ids = proid+','+tp+','+userid;
		document.write("<img border=0 width=0 height=0 src='http://pv.zol.com.cn/images/pvhit0002.gif?id="+ids+"'>");
	}
	if(write_new){
	var var_productname = pro_name;
		var_subcatid = subcatid;
		var_subcat_name = subcatname;
		var userid = readCookie("ea3w_cookies_userid");
		var newcook = '###' + tp + '|' + var_productname + '|' + var_subcatid+ '|' +var_subcat_name+'|'+userid;		
		//alert(newcook);
		while( cookie_value.indexOf(newcook)>=0 ){
			cookie_value = cookie_value.replace(newcook,"");
		}
		cookie_value = cookie_value + newcook;		
		writeCookie(cookie_name,cookie_value,24*7);
		//alert(cookie_value);
	}
}