// cookie functions
var cookieItems = new Array();
var seperator = '&';
var savedImage = '';
function initSaveRadioBox()
{
	var cookieValue=readCookie("saveList");
	if(cookieValue && cookieValue != "empty"){
      cookieItems = cookieValue.split(seperator);
   }  
}

initSaveRadioBox();

function addSaveRadioBoxItem(elem) {
	if(elem.className=='safeRadioBoxOff') {
		if(cookieItems.length<20) {
		cookieItems[cookieItems.length] = elem.id;
		elem.className='safeRadioBoxOn';
		elem.src = 'img/layout_products/icons/remove_saved_list' + savedImage + '.png';
		}
		else {
			alert('No more than 20 items!')
		}
	}
	else {
		for(i in cookieItems) {
			if(cookieItems[i]==elem.id) {
				cookieItems.splice(i, 1)
				break;
			}
		}
		elem.className='safeRadioBoxOff';
		elem.src = 'img/layout_products/icons/add_saved_list' + savedImage + '.png';
	}
	
	var string = '';
	if(cookieItems.length>0) {
		for(i in cookieItems) {
			string += cookieItems[i];
			if(i<cookieItems.length-1)
				string += seperator;	
		}
	
	}
	createCookie("saveList",string,30);
}

function sendFrmListCmp(sessionId,pid)
{
	
	var productList = '';
	var countItems = 0;
	for (var i = 0; i < document.forms[1].listCmp.length; ++i) {
		if(document.forms[1].listCmp[i].checked == true) {
			productList += document.forms[1].listCmp[i].value + '-';
			countItems++;
		}
	}
	
	if(productList=='' || countItems<2)
		alert('You must choose at least two Items!')
	else
		location.href = "procProductList,productComparisonList," + sessionId + "," + pid + "," + productList + ".html";
}

var countListCmp = 0;
function initCheckListCmp() {
	if(document.forms[1].listCmp != undefined) {
		for (var i = 0; i < document.forms[1].listCmp.length; ++i) {
			if(document.forms[1].listCmp[i].checked == true) {
				countListCmp++;
			}
		}
	}
}


function checkListCmp(elem) {
	if(elem.checked==true) {
		if(countListCmp==3)
		{
			alert("Please select only three Items!")
			return false;
		}
		else
			countListCmp++;
	}
	else {
		countListCmp--;
	}
	

}

function saveItem(productId,picture) {
	if(picture=='bg')
		savedImage = "_" + picture;
		
	var cssClass = 'safeRadioBoxOff';
	for(i in cookieItems)
	{
		if(cookieItems[i]==productId) {
			cssClass = 'safeRadioBoxOn';
			break;
		}	
	}
	
	if(cssClass == 'safeRadioBoxOn')
		document.write('<img style="cursor: pointer" src="img/layout_products/icons/remove_saved_list' + savedImage + '.png" id="' + productId + '" onclick="addSaveRadioBoxItem(this)" class="' + cssClass +'">');
	else
		document.write('<img style="cursor: pointer" src="img/layout_products/icons/add_saved_list' + savedImage + '.png" id="' + productId + '" onclick="addSaveRadioBoxItem(this)" class="' + cssClass +'">');
}