// Example:
// alert( readCookie("myCookie") );
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    var offset = document.cookie.indexOf(search);
    if(offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire + "; path=/";
}

function addValue( newvalue ){
	curvalues = readCookie("props");
	valuearray = new Array();
	old = false;
	
	if( curvalues.indexOf(',') != -1 )
		valuearray = curvalues.split(',');
	else
		if( curvalues != "")
			valuearray[0] = curvalues ;
		
	for( i=0; i<valuearray.length; i++)
	{
		if( valuearray[i] == newvalue )
		{
			alert( "This property is already in your favorites.");
			old = true;
			break;
		}
	}
	
	if( !old )
	{
		curvalues = "";
		
		for( i=0; i<valuearray.length; i++)
			curvalues += valuearray[i]+",";
		curvalues += newvalue;
		//alert( curvalues );
	}
	//alert(newvalue );
	writeCookie("props",curvalues,8000);
}
function removeValues(){

	var values = new Array();
	var x=0;
	for( i=0; i<document.forms[0].elements.length; i++){
		if(document.forms[0].elements[i].type == "checkbox" && document.forms[0].elements[i].checked ){
			//alert(i+" "+document.forms[0].elements[i].value);
			values[x] = document.forms[0].elements[i].value;
			x++;
		}
	}
	//alert( values.length+" "+values);

	removeValues2( values );
}
function removeValue( value ){
	//alert(value);

	curvalues = readCookie("props");
	valuearray = new Array();
	if( curvalues.indexOf(',') != -1 )
		valuearray = curvalues.split(',');
	else
		if( curvalues != "")
			valuearray[0] = curvalues ;
			
	curvalues = "";
	
	for( i=0; i<valuearray.length; i++)
	{
		if( valuearray[i] != value )
		{
			curvalues += valuearray[i];
			if( i < valuearray.length-2 )
				curvalues +=',';
		}
	}
	//alert( curvalues);
	writeCookie("props",curvalues,8000);
}

function removeValues2( values ){
	//alert(values);
	curvalues = readCookie("props");
	valuearray = new Array();
	if( curvalues.indexOf(',') != -1 )
		valuearray = curvalues.split(',');
	else
		if( curvalues != "")
			valuearray[0] = curvalues ;
			
	curvalues = "";
	
	for( i=0; i<valuearray.length; i++)
	{
		for(j=0; j< values.length ; j++){
			if( valuearray[i] == values[j] )
			{
				delete valuearray[i];
			}
		}
		if( valuearray[i]  != null){
			curvalues += valuearray[i];
			if( i < valuearray.length-2 )
				curvalues +=',';
		} 
	}
	//alert( curvalues);
	writeCookie("props",curvalues,8000);
}
