function linkValidate(loggedin) {
	var output;
	document.getElementById("loader").style.display= '';
	if(loggedin)
		output = true;
	else {
		document.getElementById("loader").style.display= 'none';
		output = false;
		document.getElementById("login-message-pos").style.display = '';
		document.getElementById("login-message-pos").style.left    = findPosX(document.getElementById("add_links"))-140+"px";
		document.getElementById("login-message-pos").style.top     = findPosY(document.getElementById("add_links"))+25+"px";
	}
	return output;
}

function showDeleteIcon(link_id,link_map_id){
	if(document.getElementById('doActionVote'+link_id).value == "delete") {
		if(document.getElementById(link_map_id+"_deleteicon"))
			document.getElementById(link_map_id+"_deleteicon").style.display = '';
		if(document.getElementById(link_id+"_editicon"))
			document.getElementById(link_id+"_editicon").style.display = '';
	}
}

function hideDeleteIcon(link_id,link_map_id) {
	if(document.getElementById(link_map_id+"_deleteicon"))
		document.getElementById(link_map_id+"_deleteicon").style.display = 'none';
	if(document.getElementById(link_id+"_editicon"))
		document.getElementById(link_id+"_editicon").style.display = 'none';
}

function showReplyBox(link_id,strconcat) {
	document.getElementById(link_id+strconcat).style.display     = '';	
}

function hideReplyBox(link_id,strconcat) {
	document.getElementById(link_id+strconcat).style.display     = 'none';
}

function showCommentBox(link_id) {
	document.getElementById(link_id+"_edit").style.display     = '';
	if(document.getElementById(link_id+"_comment_link_bottom"))
		document.getElementById(link_id+"_comment_link_bottom").style.display = 'none';
	if(document.getElementById("link_comment_"+link_id))
		document.getElementById("link_comment_"+link_id).focus();
}

function hideCommentBox(link_id) {
	document.getElementById(link_id+"_edit").style.display     = 'none';	
	
	if(document.getElementById(link_id+"_comment_link_bottom")) 
	document.getElementById(link_id+"_comment_link_bottom").style.display = '';
}


function commentForLink(link_id,val,link_page,name,page_key,href) {
	var success = function(t) {commentForLinkSuccess(t,link_id);}
	var failure = function(t) {fnLoginbk(t);}
	var url     = "/link_comment_ajax.php";
	pars    = "link_id="+link_id+"&val="+val+"&link_page="+link_page+"&name="+name+"&page_key="+page_key+"&href="+href;
	var myAjax  = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});
}

function commentForLinkSuccess(t,link_id) {
	document.getElementById("link_comment_"+link_id).value="";
	if(document.getElementById(link_id+"_edit")) 
		document.getElementById(link_id+"_edit").style.display  = 'none';
	if(document.getElementById(link_id+"_comment_link_bottom")) 
		document.getElementById(link_id+"_comment_link_bottom").style.display = '';
	if(t.responseText)
		document.getElementById(link_id+"_reply_bar").innerHTML     = t.responseText;
}

function AddToFavourites(id,link_member_map_id,doActionFavorite,page_key) {
	var success = function(t) {AddToFavouritesSuccess(t,id,page_key);}
	var failure = function(t) {fnLoginbk(t);}
	var url     = "/favourites_ajax.php";
	var pars    = "id="+id+"&link_member_map_id="+link_member_map_id+"&doActionFavorite="+doActionFavorite;
	var myAjax  = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure}); 
}

function AddToFavouritesSuccess(t,id,page_key) {
	if(t.responseText=='') {
		var str    = document.getElementById("favorite"+id).src;
		var strAry = str.split("/");
		if(strAry[strAry.length-1] == 'bookmarkIt.png') {
			document.getElementById("favorite"+id).src = '/images/bookmark.png';
			document.getElementById("favorite"+id).title = 'remove from my bookmarks';
			document.getElementById('doActionFavorite'+id).value = 'delete';
		} if(strAry[strAry.length-1] == 'bookmark.png') {
			document.getElementById("favorite"+id).src = '/images/bookmarkIt.png';
			document.getElementById("favorite"+id).title = 'add to my bookmarks';
			document.getElementById('doActionFavorite'+id).value = 'add';
			if(page_key == "bookmarks") {
				document.getElementById("comments_hr_bar"+id).innerHTML = "";
			}
		}
	} else {
		document.getElementById("login-message-pos").style.display = '';
		document.getElementById("login-message-pos").style.left    = findPosX(document.getElementById("favoritetext"+id))+10+"px";
		document.getElementById("login-message-pos").style.top     = findPosY(document.getElementById("favoritetext"+id))+10+"px";
	}
}

function showEditBox(link_id) {
	document.getElementById("description_bar_"+link_id).style.display    = 'none';
	document.getElementById("edit_description_bar_"+link_id).style.display     = '';
	document.getElementById("title_bar_"+link_id).style.display    = 'none';
	document.getElementById("edit_title_bar_"+link_id).style.display     = '';
	document.getElementById("foot_tags_"+link_id).style.display    = 'none';
	document.getElementById("edit_tags_bar_"+link_id).style.display     = '';
}

function changeLink(link_id,link_map_id,title,desc,tags,fnaction) {
	var tagslimit;
	tagslimit = checkTagsLimit(tags,5,'ajax_tags_validation'+link_id);
	if(tagslimit) {
		var success = function(t) {changeLinkSuccess(t,link_id);}
		var failure = function(t) {fnLoginbk(t);}
		var url     = "/link_ajax.php";
		var pars    = "link_id="+link_id+"&link_map_id="+link_map_id+"&title="+title+"&desc="+desc+"&tags="+tags+"&fnaction="+fnaction;
		var myAjax  = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});
	}
}

function changeLinkSuccess(t,link_id) {
	var strAry;
	var str = t.responseText;
	strAry = str.split("$$"); 
	document.getElementById("edit_description_bar_"+link_id).style.display = 'none';
	document.getElementById("description_bar_"+link_id).style.display    = '';
	document.getElementById("description_bar_"+link_id).innerHTML     = strAry[2];
	
	document.getElementById("edit_title_bar_"+link_id).style.display = 'none';
	document.getElementById("title_bar_"+link_id).style.display    = '';
	document.getElementById("title_bar_"+link_id).innerHTML     = strAry[0];
	
	document.getElementById("edit_tags_bar_"+link_id).style.display = 'none';
	document.getElementById("foot_tags_"+link_id).style.display     = '';
	document.getElementById("foot_tags_"+link_id).innerHTML     = strAry[1];
}

function cancelLinkEdit(link_id) {
	document.getElementById("description_bar_"+link_id).style.display = '';
	document.getElementById("edit_description_bar_"+link_id).style.display = 'none';
	
	document.getElementById("title_bar_"+link_id).style.display    = '';
	document.getElementById("edit_title_bar_"+link_id).style.display = 'none';

	document.getElementById("foot_tags_"+link_id).style.display    = '';
	document.getElementById("edit_tags_bar_"+link_id).style.display = 'none';
}

function fnReadLink(id,doActionVote,link_map_id,member_id) {
	var proceed = true;
	if(doActionVote == "delete") {
		 proceed = false;
		if(confirm("Are you sure wanna remove from your reading list?"))
			 proceed = true;
	}
	
	if(proceed) {
		var success = function(t) {fnReadLinksuccess(t,id);}
		var failure = function(t) {fnLoginbk(t);}
		var url     = "/read_link_ajax.php";
		var pars    = "id="+id+"&doActionVote="+doActionVote+"&link_map_id="+link_map_id+"&member_id="+member_id;
		var myAjax  = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});
	}
}

function fnReadLinksuccess(t,id) {
	if(t.responseText=='') {
		if(document.getElementById("voteStatus"+id).value == '0') { 
			document.getElementById("populateVote"+id).innerHTML = parseInt(document.getElementById("populateVote"+id).innerHTML)+1;
			document.getElementById("voteStatus"+id).value = '1';
			document.getElementById("btnVote"+id).className = 'readImgTxt';
			document.getElementById('doActionVote'+id).value = 'delete';
		}
		else if(document.getElementById("voteStatus"+id).value == '1') { 
				document.getElementById("comments_hr_bar"+id).innerHTML = "";
				document.getElementById("voteStatus"+id).value = '0'
				//document.getElementById("btnVote"+id).className = 'likeitImgTxt';
				document.getElementById('doActionVote'+id).value = 'add';
				if(document.getElementById(link_map_id+"_deleteicon"))
					document.getElementById(link_map_id+"_deleteicon").style.display = 'none';
		}
	} else {
		document.getElementById("login-message-pos").style.display = '';
		document.getElementById("login-message-pos").style.left    = findPosX(document.getElementById(id))+10+"px";
		document.getElementById("login-message-pos").style.top     = findPosY(document.getElementById(id))+10+"px";
	}
}

function deleteComments(comment_id) {
	if(confirm("Are you sure wanna delete this comment?")) {
		var success = function(t) {deleteCommentssuccess(t,comment_id);}
		var failure = function(t) {fnLoginbk(t);}
		var url     = "/delete_comments.php";
		var pars    = "comment_id="+comment_id;
		var myAjax  = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});
	}
}

function deleteCommentssuccess(t,comment_id) {
	document.getElementById("comments_bar_"+comment_id).innerHTML="";
}
