

function setButton(award_id){
	var cookie=$.cookie("cart");
	var ex=new RegExp(/\|/);
	if(ex.test(cookie)){
		var tmp=cookie.split("|");
		if(tmp.in_array(award_id)){
			disableB()
		}else{
			enableB();
		}
	}else{
		var tmp=parseInt(cookie);
		if(tmp){
			if(tmp==award_id){
				disableB();
			}else{
				enableB();
			}
		}else{
			enableB();
		}
	}
}

function disableB(){
	$("#addC").css("display","none");
	$("#delC").css("display","inline");
}
function enableB(){
	$("#addC").css("display","inline");
	$("#delC").css("display","none");
}

function addCart(id){

	disableB();
	var flag=null;
	var cookie=$.cookie("cart");
	if($.cookie("student")){
		addToShortlist(id);
	}else{
		if (cookie){
			var tmp=cookie.split('|');
			if(!tmp.in_array(id)){
				cookie=cookie+"|"+id;
				$.cookie("cart", cookie,{/*domain: location.host,*/path:'/' });
			}
		}else{
			$.cookie("cart", id,{/*domain: location.host,*/ path:'/' });
		}
	}

	$("#shortmenu > li ").each(function(){
		var id=getId(this.firstChild.getAttribute("href"));
		if(id==award_id){
			this.style.display="block";
			flag=1;
		}
	});

	if(!flag){
		$("<li><a href='/donor/"+award_id+"'>"+sholarship+"</a></li>").appendTo("#shortmenu");
	}






}

function delCart(id){
	enableB();
$("#shortmenu > li ").each(function(){
	var id=getId(this.firstChild.getAttribute("href"));
	if(id==parseInt(award_id)){
		this.style.display="none";
		//this.setAttribute("style","display:none");
	}
});
	var cookie=$.cookie("cart");
	var ex=new RegExp(/\|/);
	if($.cookie("student")){
		delFromShortlist(id);
	}else{
		if(ex.test(cookie)){ //
			var tmp=cookie.split("|");
			tmp.remove(id);
			tmp=tmp.join("|");
		}else{
			var tmp=cookie;
			$.cookie('cart',null,{/*domain: location.host,*/ path:'/' });
			tmp=null;
		}
		if(tmp){
			$.cookie("cart", tmp,{/*domain: location.host,*/ path:'/' });
		}
	}
}

function getId(string){
	string=string.replace(location.host,"");
	string=string.replace(/\/donor\/(.*?)\//,"");
	string=string.replace(/\//ig,"");
	string=string.replace(/[^0-9]+/ig,"");
	return parseInt(string);

}
function showAll(){
	$("#allsch").html('<a href="javascript:hideAll();"><i>Collapse items...</i></a>');
	$("#shortmenu > li ").each(function(){
		var id=getId(this.firstChild.getAttribute("href"));
		if(id!=parseInt(award_id)){
			this.setAttribute("style","display:block");
		}
	});
	$.cookie("itemlist", "expand",{domain: location.host, path:'/' });

}
function hideAll(){
	$("#allsch").html('<a href="javascript:showAll();"><i>View all shortlist items...</i></a>');
	$("#shortmenu > li:gt(5) ").each(function(){
		var id=getId(this.firstChild.getAttribute("href"));
		if(id!=parseInt(award_id)){
			this.setAttribute("style","display:none");
		}
	});
	$.cookie("itemlist", "collapse",{domain: location.host, path:'/' });
}



function addToShortlist(id){
	$.get("cartgrid.php",{action:"addToShortlist",id:id});
}
function delFromShortlist(id){
	$.get("cartgrid.php",{action:"delFromShortlist",id:id});
}
