// JS document

function setupMulitpleLikes(){
	$('.likeLink').live("click",function() {
	
		var likeDocName = $(this).attr("id");
		//remove click event
		$(this).parent().html("<span class='like'>Like this</span>");
	  
		$.get("?IdcService=KEW_LIKE_SUBMIT",{ 	
				"likeDocName": likeDocName,
				"ts"		: new Date().getTime()
			},function(data) { 
					handleLikeResponse(likeDocName);				
				}
		);
		return false;
	});
	
	$('.closeLink').live("click",function() {
		$(this).parent().css("display","none");
	});
}

function handleLikeResponse(likeDocName){
	// increment the like counter
	incrementLikeCount(likeDocName);
	
	//Show the relevant like thank you box
	showThankYouBox(likeDocName);
	
}

function incrementLikeCount(likeDocName){
	 var currentNumLikes = parseInt($(".numLikesDisp_"+likeDocName).html());
	 $(".numLikesDisp_"+likeDocName).html(currentNumLikes+1);
}

function showThankYouBox(likeDocName){
	$(".thanksBox_"+likeDocName).show();
}




function setupLikes2()
{ 
	if(document.getElementById("utility-like2")) {
		var likesBoxHolderObj2 = document.getElementById("utility-like-holder2");
		var anchorObj2 = document.getElementById("utility-like2");
		var likesBoxObj2 = document.getElementById("add-like2");
		var likesTextObj2 = document.getElementById("likes-text2");
		
		anchorObj2.onclick = function()
		{
			if(likesBoxObj2.style.display == "block")
				likesBoxObj2.style.display = "none";
			else
				likesBoxObj2.style.display = "block";
			return false;
		};
		var closeObj2 = document.getElementById("close-likes2");
		closeObj2.onclick = function() {
			likesBoxObj2.style.display = "none";
			return false;
		};
		var yesObj2 = document.getElementById("likes-yes2");
		yesObj2.onclick = function() {
			likesTextObj2.innerHTML = "Thanks for letting us know.";
			likesBoxHolderObj2.innerHTML = "<span class='like'>Like this</span>";
			//Do ajax call to update the db and increment the "likes" number by one.
			return false;
		};
		/* GP:MB:29-07-update */
		/*
		var noObj2 = document.getElementById("likes-no2");
		noObj2.onclick = function() {
			likesBoxObj2.style.display = "none";
			return false;
		};
		*/
	}
	setupLikesCust();
}
function setupLikes()
{ 
	if(document.getElementById("utility-like")) {
		var likesBoxHolderObj = document.getElementById("utility-like-holder");
		var anchorObj = document.getElementById("utility-like");
		var likesBoxObj = document.getElementById("add-like");
		var likesTextObj = document.getElementById("likes-text");
		
		/*GM update 17/06/2010: commented this code to fix issue on RSS/two-col links on blog pages
		/*anchorObj.onclick = function()
		{
			if(likesBoxObj.style.display == "block")
				likesBoxObj.style.display = "none";
			else
				likesBoxObj.style.display = "block";
			return false;
		};*/
		var closeObj = document.getElementById("close-likes");
		closeObj.onclick = function() {
			likesBoxObj.style.display = "none";
			return false;
		};
		var yesObj = document.getElementById("likes-yes");
		yesObj.onclick = function() {
			likesTextObj.innerHTML = "Thanks for letting us know.";
			likesBoxHolderObj.innerHTML = "<span class='like'>Like this</span>";
			//Do ajax call to update the db and increment the "likes" number by one.
			return false;
		};
		/* GP:MB:29-07-update */
		/*
		var noObj = document.getElementById("likes-no");
		noObj.onclick = function() {
			likesBoxObj.style.display = "none";
			return false;
		};
		*/
	}
}
