var count=0;
function CC_Add(carID,prefix)
{
	if(CC_Count() < 3)
	{	
		
		if(!CC_Exists(carID,prefix))
		{
			var value = CC_GetValue(CC_cookieName);
			
			if(value=="")
				value = prefix+"."+carID;
			else
				value += ","+prefix+"."+carID;
			
			document.cookie= CC_cookieName + "=" + value;							
			return 1;
			
		}				
		else
		//alert("This item has already been added for comparison");	
			ShowErrMsg("1");
		return 0;
	}
	
	else
	{
	//alert("You can not select more than three cars for comparison");
	ShowErrMsg("2")//alert(GetMsgg("2"));
	return 0;	
	}
	
	
}
function CC_Count()
{
	var value=CC_GetValue(CC_cookieName);
	if(value!=null)
	{
		if(value.length>0)
		{
			var value_array=new Array();	
			value_array=value.split(",");
			return value_array.length;		
		}	
	}
	return 0;
}

function CC_Exists(carID,prefix)
{
	var value=CC_GetValue(CC_cookieName);	
	if(value!=null)
	{
		if(value.length>0)
		{
			var value_array=new Array();	
			value_array=value.split(",");
			for(i=0;i<value_array.length;i++)
			{
				if(prefix+"."+carID == value_array[i])				
				return true;				
			}			
		}	
	}
	return false;
}

function CC_Remove(carID,prefix)
{	
	if(CC_Exists(carID,prefix))
	{
		
		var value=CC_GetValue(CC_cookieName);
		var itemIndex = -1;
		var value_array=new Array();	
		value_array=value.split(",");
		for(i=0;i<value_array.length;i++)
		{
			if(prefix+"."+carID == value_array[i])		
			itemIndex = i;				
		}		
		value_array.splice(itemIndex,1);
		document.cookie= CC_cookieName + "=" + value_array.join();		
	}	
}
function CC_GetValue()
{	
	if (document.cookie.length>0)
	{
	c_start=document.cookie.indexOf(CC_cookieName + "=");
	if (c_start!=-1)
		{ 
		c_start=c_start + CC_cookieName.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function ShowErrMsg(MsgID)
{
	var retString="";
		
		if(MsgID=="1")
			{				
				if(document.getElementById("CarCompMsg1")!=null)
				{
					
					retString=document.getElementById("CarCompMsg1").value;
					alert(retString);
				//return retString;
				}
			else
				alert("This item has already been added for comparison.");	
			}
			
		else if(MsgID=="2")
			{
				
			if(document.getElementById("CarCompMsg2")!=null)
				{					
					retString=document.getElementById("CarCompMsg2").value;
					alert(retString);
					//return retString;
				}
			else
				alert("You can not select more than three cars for comparison.");
			}
}
