/**
*	
*	kiennd
*	getCookie - get cookie for fix error IE6 using yahoo.util.getCookie.
*/

function getCookieIE6(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
/**
*	
*	kiennd
*	checkIe6 - check browser agent. if IE6 return true.
*/
function checkIE6() {
	if(navigator.userAgent.search(/MSIE 6/)!=-1) {
		return true;
	}
	return false;
}
function setRecentview(type,div,id,tbpath,path)
{
	if (type=="product"||type=="buyinglead"||type=="sellinglead")
	{
		var productid = YAHOO.util.Cookie.get("productid");
		//alert(str);
		/**/
		if(checkIE6()==true) {
			var productid = getCookieIE6("productid");
		}
		
					
		var result=-1;
	    if (productid)result = productid.indexOf(id);  	
	
		
		if (result>-1)
		{
	      //already:      
	    }

	    else
		{		        
			if (tbpath=='')tbpath="/images/no_product.png";
			else
				tbpath="/"+tbpath;
			var link="";
			if(type=="product")
			{
				//link="?action=detail&task=viewproduct&proid="+id;
				link="./PR"+id+"/";
			}
			else if(type=="buyinglead")
			{
				//link="?action=detail&task=viewbuylead&buyid="+id;
				link="./BU"+id+"/";
			}
			else if(type=="sellinglead")
			{
				//link="?action=detail&task=viewselllead&sellid="+id;
				link="./SE"+id+"/";
			}
			var img = '<div class="imgborder2"><a href="'+link+'" class="title2" target="_blank" ><img src="'+tbpath+'" style="border:1px solid #ccc;" width="65" height="65"></a></div>';
			//<a href="?action=detail&task=viewproduct&proid={id}" class="title2" target="_blank" ></a>
			var d = document.getElementById(div);		
			productid += ','+id;
			YAHOO.util.Cookie.set("productid", productid);  
			if(d)
			{
				d.innerHTML +=  img;        
				YAHOO.util.Cookie.set("recentproducts", d.innerHTML);		    
			}
			else
			{		
				  
				var value = YAHOO.util.Cookie.get("recentproducts");
				if(checkIE6()==true){
					var value = getCookieIE6("recentproducts");
				}
				if(value==null)
				{
					YAHOO.util.Cookie.set("recentproducts", img);
				}
				else
				{
					value +=  img;
					YAHOO.util.Cookie.set("recentproducts", value);
				} 
			}
			YAHOO.util.Cookie.set("recentproducts_plh", div);
			var btn = document.getElementById("btnClearRecent");
			if (btn) btn.style.display = 'block';
		}							
	}
}
function LoadRecentView()
{
  var div =  YAHOO.util.Cookie.get("recentproducts_plh"); 
  var value = YAHOO.util.Cookie.get("recentproducts"); 
  if(checkIE6()==true){
  	var div =  getCookieIE6("recentproducts_plh"); 
  	var value = getCookieIE6("recentproducts"); 
  }
	var d = document.getElementById(div)
	var btn = document.getElementById("btnClearRecent");
  if (d && value!=null)
  {
    d.innerHTML = value;
    
    if (btn) btn.style.display = 'block';
  }
  else
  {
    if (btn) btn.style.display = 'none';
  }
}
function ClearRecentView()
{
  YAHOO.util.Cookie.remove("recentproducts");
  YAHOO.util.Cookie.remove("productid");
  var div =  YAHOO.util.Cookie.get("recentproducts_plh");
  if(checkIE6()==true){
  	var div =  getCookieIE6("recentproducts_plh");
  }
	var d = document.getElementById(div)
  if (d)d.innerHTML = '';
  var btn = document.getElementById("btnClearRecent");
  if (btn) btn.style.display = 'none';
}