/* vanquish a cookie
  
@name = name of cookie to slay
*/
function killCookie(name){    
   document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT; "; //kill the cookie
}

/* resurrect a cookie

@name = name of cookie to summon
@value = value of cookie being conjured
*/
function setCookie(name, value){
	killCookie(name);
	var path = '/';
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 1000*60*60*24*30); // expires in a month
	document.cookie = name + "=" + value + "; expires=" + expires.toGMTString() + "; path="+path+";"; //set it anew
	return true;
}

/* access a cookies' value

@n = name of cookie being accessed
*/
function readCookie(n) {
var cookiecontent = new String();
if(document.cookie.length > 0) {
	var cookiename = n+ '=';
	var cookiebegin = document.cookie.indexOf(cookiename);
	var cookieend = 0;
	if(cookiebegin > -1) {
		cookiebegin += cookiename.length;
		cookieend = document.cookie.indexOf(";",cookiebegin);
		if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
		cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		}
	}
return cookiecontent;
} // function ReadCookie()

function setRecentlyViewed(productno){
		var recentlyViewedArray = readCookie('psrcv').split(':::');
		var newCookieValue = new Array();
                var startIndex = 1;
		newCookieValue[0] = productno;

		for(var i=0;i<recentlyViewedArray.length;i++){
			if(recentlyViewedArray[i]!=productno && recentlyViewedArray[i]){
				newCookieValue[startIndex] = recentlyViewedArray[i];startIndex++;
			}
		}
		setCookie('psrcv',newCookieValue.join(':::'));
}

