var str1="Recent_Wiredigest";
var newid = new Array();
var newmargin = new Array();
var newname = new Array();
var newprice = new Array();
var newsaleprice = new Array();
var newimgpath = new Array();
var price = '';
var saleprice = '';
function createCookie(name,value,days)
{
	
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function GetCookie(name) 
{  
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function checkCookie(id, name, imgpath, margin)
{
	var i,count;

	
	totalcookie = GetCookie("Total_Wiredigest");

	if(totalcookie != null)
	{
		i = Number(totalcookie);
		count=0;
		for(j=1;j<=i;j++)
		{
			username = GetCookie(str1 + j + "_id");
			if(username == id)
			{
				count++;
			}
		}
		if(count == 0)
		{
			if(i == 4)
			{
				for(m=1;m<=4;m++)
				{
					username=GetCookie(str1 + m);
					newname[newname.length] = username;
					//del_cookie(str1 + m);
	
				/*	str=str1+m;
					str=str+"_price";
					username = GetCookie(str);
					newprice[newprice.length] = username;
					del_cookie(str);
					
					str=str1+m;
					str=str+"_saleprice";
					username = GetCookie(str); 
					newsaleprice[newsaleprice.length] = username;
					del_cookie(str);*/
				
					str=str1+m;
					str=str+"_id";
					username = GetCookie(str); 
					newid[newid.length] = username;
//					del_cookie(str);
					
					str=str1+m;
					str=str+"_imgpath";
					username = GetCookie(str); 
					newimgpath[newimgpath.length] = username;
	//				del_cookie(str);

					
					str=str1+m;
					str=str+"_margin";
					username = GetCookie(str); 
					newmargin[newmargin.length] = username;
		//			del_cookie(str);
				}
				
				for(m=1, n=1;m<4;m++, n++)
				{
					
					createCookie(str1+m, newname[n]); 
	
				/*	str=str1+m;
					str=str+"_price";
					createCookie(str,newprice[n]); 
					
					str=str1+m;
					str=str+"_saleprice";
					createCookie(str,newsaleprice[n]);
					*/
					str=str1+m;
					str=str+"_margin";
					createCookie(str,newmargin[n]); 
					

					str=str1+m;
					str=str+"_id";
					createCookie(str,newid[n]); 
					
					str=str1+m;
					str=str+"_imgpath";
					createCookie(str,newimgpath[n]); 
				}
				cookie_store(m, id, name, imgpath, margin);
			}
			else
			{
				i++;
				createCookie("Total_Wiredigest",i);
				cookie_store(i, id, name, imgpath, margin);
			}
		}
	}
	else
	{
			i=1;
			createCookie("Total_Wiredigest",i);
			cookie_store(i, id, name, imgpath, margin);
	}

}



function gc1()
{

	var i;
	var d = document;
	totalcookie = GetCookie("Total_Wiredigest");

	if(Number(totalcookie) > 1)
	{
		i = Number(totalcookie) - 1;
		count=1;
		maindiv = d.getElementById("recentdiv");
		var ihtml = "";
		for(j = i; j > 0; j--)
		{
			id = GetCookie(str1 + j + "_id");
			name = GetCookie(str1 + j);
			imgpath = GetCookie(str1 + j + "_imgpath");
			margin = GetCookie(str1 + j + "_margin");
			//price = GetCookie(str1 + j + "_price");


			if(count ==3)
			{
				ihtml += "<div class='recentlyviewed_items_box' style='background: none;'>";
			}
			else
			{
				ihtml += "<div class='recentlyviewed_items_box'>";
			}
			count++;
			
		
			ihtml += "<div class='recentlyviewed_items_img'>";
			ihtml += "<a href='" + id + ".html'><img src='" + imgpath + "' border='0' alt='" + name + "' title='" + name + "' style='margin-top: 7px;'></a>";
			ihtml += "</div>";
			ihtml += "<h2>" + "<a href='" + id + "'>" + name + "</a></h2>";
			ihtml += "<h3 style='text-align:left; width:150px;'>Sale Price : <span class='our_price'>$";

			var floatprice = new Number(margin);
    		ihtml += floatprice.toFixed(2);			
		/*if(price > 0 && saleprice > 0)
			{
				ihtml += "<p>Regular Price : <span class='regular_price'>$" + price + "</span><br>Our Price : <span class='our_price'>$" + saleprice + "</span></p>";
			}
			else
			{
				ihtml += "<p>Our Price : <span class='our_price'>$";
				if(price > 0)
				{
				 	ihtml += saleprice;
				}
				else
				{
					ihtml += price;
				}
				ihtml += "</span></p>";
			}
			*/
            ihtml +=  "</h3><p style='text-align:center;'><a href='" + id + ".html' style='color: #cc0000; font-weight:bold; text-decoration: underline; font-size: 11px; font-size:12px;'>view more</a></p>";			
			ihtml += "</div>";
			
		}
		document.getElementById("recentdiv").innerHTML = ihtml;
	}
}


function cookie_store(val, id, name, imgpath, margin)
{
	createCookie(str1+val,name);
	
	/*	str=str1+val;
	str=str+"_price";
	createCookie(str,price);
	
	str=str1+val;
	str=str+"_saleprice";
	createCookie(str,saleprice);
	*/	
	str=str1+val;
	str=str+"_margin";
	createCookie(str,margin);

	
	str=str1+val;
	str=str+"_id";
	createCookie(str,id);
	
	str=str1+val;
	str=str+"_imgpath";
	createCookie(str,imgpath);
	

	
	

}

function del_cookie(name) {
document.cookie = name +
'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}