function viewSelectedItems() {
	var elementValue = null;
	var productIds = (getCookie('productIds')==null) ? '' : getCookie('productIds');
	var styleIds = (getCookie('styleIds')==null) ? '' : getCookie('styleIds');
	var numSelected = 0;
	var numItems = '<fmt:message key="constant.numOfViewSelectedItemsLimit" bundle="${UItext}"/>';			
	if (isNaN(numItems)) {
		numItems = 20;
	}
	var numSelected=(productIds.split("|").length)-1;
	if(productIds=='' ){ //This will check if cookies are disabled, so that functionality still works
		for (var i=0;i<document.viewSelectedItems.elements.length;i++){
			var e=document.viewSelectedItems.elements[i];
			if (e.type=='checkbox' && e.checked){
				numSelected += 1;
				elementValue = e.value;
				productIds = productIds + elementValue.substring(0,elementValue.indexOf('|'))+ '|';
				styleIds = styleIds + elementValue.substring(elementValue.indexOf('|') + 1, elementValue.length) + '|';	
			}
		}
	}
	if (numSelected == 0) {
		alert('Please check an item checkbox or click on individual item image or name to view item details.');
	} else if (numSelected > numItems) {
		alert('You can select upto 20 products. Please un-select some products to select new ones.');
	} else {
		document.viewSelectedItems.productIds.value = productIds.substring(0, productIds.length - 1);
		document.viewSelectedItems.styleIds.value = styleIds.substring(0, styleIds.length - 1);
		document.viewSelectedItems.submit();
	}
}
function setValuesToCookie(productId,styleId,elem){
	var productIds = (getCookie('productIds')==null) ? '' : getCookie('productIds');
	var styleIds = (getCookie('styleIds')==null) ? '' : getCookie('styleIds');
	// check if number of selected items exceeds 20, then dont allow selection
	if(elem.checked && exceedsMax(productIds)){
	elem.checked=false;
	alert('You already selected 20 products. Please un-select some products to select new ones.');
	return;
	}
	if(elem.checked && productIds.indexOf(productId)==-1 ){
		productIds=productIds+productId+'|';
		styleIds=styleIds+styleId+'|';
	}else{
		productIds=removeStr(productIds,productId);
		styleIds=removeStr(styleIds,styleId);
	}
	setCookie('styleIds',styleIds,null);
	setCookie('productIds',productIds,null);	
}
function removeStr(parentStr,childStr){
    childStr+='';
	var idx=parentStr.indexOf(childStr);
	if(idx!=-1){
	var parentStr=parentStr.substring(0,idx)+parentStr.substring(idx+childStr.length+1);
     }
	return parentStr;
	}	
function setCookie(name, value, days){
	if (days!=null){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie (name){
	var dc = document.cookie;
    var cname = name + "=";
    if (dc.length > 0){
    	begin = dc.indexOf(cname);
        if (begin != -1){
        	begin += cname.length;
	        end = dc.indexOf(';', begin);
    		if (end == -1) end = dc.length;
        	return unescape(dc.substring(begin, end));
		}
	}
    return null;
}
function exceedsMax(products){
var prod = products.split("|");
if(prod.length > 20)return true;
else return false;
}