var str1="Recent_Netaya";
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, linkpage, imgpath, price)
{
	var i,count;
	
	totalcookie = GetCookie("Total_Netaya");
	
	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 == 5)
			{
				for(m=1;m<=5;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<5;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, price);
			}
			else
			{
				i++;
				createCookie("Total_Netaya",i);
				cookie_store(i, id, name, imgpath, price);
			}
		}
	}
	else
	{
			i=1;
			createCookie("Total_Netaya",i);
			cookie_store(i, id, name, imgpath, price);
	}

}



function gc1()
{

	var i;
	var d = document;
	totalcookie = GetCookie("Total_Netaya");
		
	if(Number(totalcookie) > 1)
	{
		i = Number(totalcookie) - 1;
		
		count=1;
		maindiv = d.getElementById("recentdiv");
		var ihtml = "<div class='recently_title'>Recently Viewed Items</div>";
		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");

			str=str1;
			str=str+j;
			str=str+'_id';
			lp =GetCookie(str);
			
			ihtml += "<div class=recently_box>";			
			ihtml += "<div class='img_center'>";
			ihtml += "<span></span><a href='" + lp + ".html'><img src='" + imgpath + "' alt='" + name + "' border=0 align='center'></a></div>";
			ihtml +="<h2 class=name><a href='" + lp + ".html'> " + name + "</a></h2>";
			
			str=str1;
			str=str+j;
			str=str+'_price';
			username=GetCookie(str); 
			var sp= parseFloat(username);
							
			ihtml += "<p class=price>Price: <span>$" + sp.toFixed(2) + "</span></p>";
						
			str=str1;
			str=str+j;
			str=str+'_id';
			username=GetCookie(str); 
			
			ihtml += "</div>";	
			
		}
		document.getElementById("recentdiv").innerHTML = ihtml;
	}
	else
	{
		document.getElementById("recentdiv").style.display = 'none';
	}
}


function cookie_store(val, id, name, imgpath, price)
{
	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;';
}