var str1="Recent_Beverly";
var newid = new Array();
var newname = new Array();
var newprice = new Array();
var newsaleprice = new Array();
var newimgpath = new Array();
var price = '';
var newbrand = new Array();
var newbrandlink = new Array();
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, saleprice)
{
	var i,count;
	totalcookie = GetCookie("Total_Beverly");

	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)
			{
				var m=1;
				var n=m+1;
				
				for(m=1;m<5;m++)
				{
					n=m+1;
					
					username=GetCookie(str1 + n);
					createCookie(str1 + m, username, 0);
					
		
					str=str1+n;
					str=str + "_saleprice";
					username=GetCookie(str);
					str=str1 + m;
					str=str + "_saleprice";
					createCookie(str,username,0);
					
					str=str1+n;
					str=str+"_imgpath";
					username=GetCookie(str);
					str=str1+m;
					str=str+"_imgpath";
					createCookie(str,username,0);
				
				}
				createCookie(str1 + m, name + "+" + id);
				
				str=str1+m;
				str=str+"_saleprice";
				createCookie(str,saleprice,0);
				
				str=str1+m;
				str=str+"_imgpath";
				createCookie(str, imgpath,0);
				
			}
			else
			{
				i++;

				createCookie("Total_Beverly",i);
				cookie_store(i, id, name, imgpath, saleprice);
			}
		}
	}
	else
	{
			i=1;
			createCookie("Total_Beverly",i,0);
			cookie_store(i, id, name, imgpath, saleprice);
	}

}




function gc1()
{

	var i;
	//var d = document;
	totalcookie = GetCookie("Total_Beverly");


	if(Number(totalcookie) > 1)
	{
		i = Number(totalcookie) - 1;

		count=1;
		maindiv = document.getElementById("recentdiv");
		var ihtml = "";
		
		for(j = i; j > 0; j--)
		{
//			id = GetCookie(str1 + j + "_id");
			name = GetCookie(str1 + j);
			cname = name.split("+");
			idprint = cname[0];
			nameprint = cname[1];
			imgpath = GetCookie(str1 + j + "_imgpath");
		//	margin = GetCookie(str1 + j + "_margin");
			saleprice = GetCookie(str1 + j + "_saleprice");


			ihtml += "<div class='recently_box'>";
				
		
			ihtml += "<div class='recently_img'>";
		//	ihtml += "<a href='" + id + ".html'><img src='" + imgpath + "' border='0' alt='" + name + "' style='margin-top:" + margin + "px; margin-bottom: " + margin + "px;' title='" + name + "'></a>";
			ihtml += "<a href='" + cname[1] + ".html'><img src='" + imgpath + "' border='0' alt='" + cname[0] + "' title='" + cname[0] + "'></a>";
			ihtml += "</div>";
			ihtml += "<h3>" + "<a href='" + cname[1] + ".html'>" + cname[0] + "</a></h3>";
			ihtml += "$<span>";
		 	ihtml += saleprice;
			ihtml += "</span>";

			ihtml += "</div>";
			
		}
		document.getElementById("recentdiv").innerHTML = ihtml;
	}

}

function cookie_store(val, id, name, imgpath, saleprice)
{
	createCookie(str1+val,name + "+" + id);
	
	str=str1+val;
	str=str+"_saleprice";
	createCookie(str,saleprice);
		
	
/*	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;';
}