c = new Cookie();
function Cookie()
{

	//Public properties
	this.isSet = (document.cookie.toString().length != 0);
	this.isEnabled = navigator.cookieEnabled;

	//Private properties
	this.expires = new Date();
	this.path = '';
	this.domain = '';
	this.isSecure = false;

	//Public methods
	this.getIsSet = function() { return (document.cookie != ""); }
	this.setExpires = function(date) { this.expires = date; }
	this.setPath = function(path) { this.path = path; }
	this.setDomain = function(domain) { this.domain = domain; }
	this.setSecure = function(secure) { this.isSecure = secure; }

	this.erase = function()
	{
		this.setExpires(new Date(new Date().getTime() - 1000000));
		var cArr = this.getCookieAsArray();
		for(var i in cArr) this.setValue(i, '');

		document.cookie = '';
	}

	this.parse = function()
	{
		var cValues = this.getCookieAsArray();
		for(var i in cValues) eval(i + ' = unescape("' + cValues[i] + '");');
	}

	this.getValue = function(name)
	{
		var cValues = this.getCookieAsArray();
		return cValues[name];
	}

	this.setValue = function(name, value) { document.cookie = name + '=' + escape(value) + '; ' + this.getCookieSettings(); }

	this.getCookieAsArray = function()
	{
		if(!document.cookie.toString().length) return new Array();

		cArr = document.cookie.toString().split('; ');
		var cookieArray = new Array();
		for(var x=0; x<cArr.length; x++)
		{
			if(!cArr[x].length) continue;
			cArr[x] = cArr[x].split("=");
			cookieArray[cArr[x][0].toString()] = unescape(cArr[x][1]);
		}

		return cookieArray;
	}

	//Private methods
	this.getCookieSettings = function()
	{
		var str = 'expires=' + this.expires.toGMTString() + '; ';
		if(this.domain.length) str += 'path=' + this.path + '; ';
		if(this.domain.length) str += 'domain=' + this.domain + '; ';
		if(this.isSecure) str += 'secure; ';
		return str;
	}
}

c.setExpires(new Date(new Date().getTime() + (60 * 60 * 48 * 1000)));
function updatecookie(ucnid,value,cookiename)
{
	var matchfound = false;
	var ucndata = c.getValue(cookiename);
  if (ucndata)// && ucndata != undefined)
  {
  	if(ucndata.length > 0)
  	{
  		ucndata = ucndata.split(",");
  		for(var x=0;x<ucndata.length; x++)
  		{
  			if (ucndata[x] == '' || ucndata[x] == 'undefined')
  			{
  				ucndata.splice(x,1);
  			}
  			if (ucnid == ucndata[x])
  			{
  				if (value == true)
  				{
  					ucndata[x] = ucnid;
  				}
  				else
  				{
  					ucndata.splice(x,1);
  				}
  			}
  		}
  	}
  	else
  	{
  		ucndata = Array();
  		if (value == true)
  		{
  			ucndata[0] = ucnid;
  			matchfound = true;
  		} 
  	}
  }
	else
	{
		ucndata = Array();
		if (value == true)
		{
			ucndata[0] = ucnid;
			matchfound = true;
		} 
	}
	if (matchfound == false)
	{
		if (value == true)
		{
			ucndata[ucndata.length] = ucnid;
		}
	}
	if(ucndata.length > 0 && ucndata.join(",") != 'undefined')
	{
		//alert(ucndata);
		c.setValue(pagecookiename,ucndata.join(","));
		if(document.getElementById('view_garage_link')){document.getElementById('view_garage_link').style.display='block';}
		if(document.getElementById('view_garage_blank')){document.getElementById('view_garage_blank').style.display='none';}
		if(document.getElementById('clear_garage_link')){document.getElementById('clear_garage_link').style.display='block';}
		if(document.getElementById('clear_garage_blank')){document.getElementById('clear_garage_blank').style.display='none';}
	}
	else
	{
		c.setValue(pagecookiename,ucndata.join(","));
		if(document.getElementById('view_garage_link')){document.getElementById('view_garage_link').style.display='none';}
		if(document.getElementById('view_garage_blank')){document.getElementById('view_garage_blank').style.display='block';}
		if(document.getElementById('clear_garage_link')){document.getElementById('clear_garage_link').style.display='none';}
		if(document.getElementById('clear_garage_blank')){document.getElementById('clear_garage_blank').style.display='block';}
	}
}

function loadcookie(cookiename)
{
	var ucndata = c.getValue(cookiename);
  if(ucndata && ucndata != 'undefined')
  {
		if(document.getElementById('return_to_results_link')){document.getElementById('return_to_results_link').style.display='none';}
		if(document.getElementById('view_garage_link')){document.getElementById('view_garage_link').style.display='block';}
		if(document.getElementById('view_garage_blank')){document.getElementById('view_garage_blank').style.display='none';}
		if(document.getElementById('clear_garage_link')){document.getElementById('clear_garage_link').style.display='block';}
		if(document.getElementById('clear_garage_blank')){document.getElementById('clear_garage_blank').style.display='none';}
		ucndata = ucndata.split(",");
		for(var x=0;x<ucndata.length; x++)
		{
			if (target = document.getElementById('ucnid_'+ucndata[x]+'_target'))
			{
				target.checked = true;
			}
		}
	}
}
