var loadingImg = '<img src="'+SiteGlobalPath+'images/blue_login.gif" border="0" align="absmiddle">';
var CommentMsg = '<table border="0" width="100%" cellspacing="0" cellpadding="0" style="padding-left:5px; border:1px solid #999999;" bgcolor="#FFFFCC"><tr><td align="center" height="30" class="RedLinkText">Comment Should not be empty.</td></tr></table>';
var SuccessMsg = '<table border="0" width="100%" cellspacing="0" cellpadding="0" style="padding-left:5px; border:1px solid #999999;" bgcolor="#FFFFCC"><tr><td align="center" height="30" class="RedLinkText">Your Comment Posted Successfully .</td></tr></table>';
function CommentPreview(spanid,PreviewId) {
	var strComment = document.getElementById("frmComment").value;
	document.getElementById(spanid).innerHTML =loadingImg;
	
	var success = function(t){CommentPreviewComplete(t,spanid,PreviewId);}
	var failure = function(t){editFailed(t);}
	var url = SiteAjaxFolder+"comment.php";
	var pars = 'action=Preview&Comments='+strComment;
	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function CommentPreviewComplete(t,spanid,PreviewId)	{
	var strValue = t.responseText;
	if(strValue=="ChkComment")	{
		document.getElementById(spanid).innerHTML = "";
		document.getElementById(PreviewId).innerHTML= CommentMsg;
	} else {
		document.getElementById(PreviewId).innerHTML= "";
		document.getElementById(spanid).innerHTML =strValue;
	}
}

function CheckLoggedUser(spanid,ProfileId) {
	var success = function(t){CheckLoggedUserComplete(t,spanid,ProfileId);}
	var failure = function(t){editFailed(t);}
	var url = SiteAjaxFolder+"comment.php";
	var pars = 'action=chkUser&ProfileId='+ProfileId;
	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function CheckLoggedUserComplete(t,spanid,ProfileId)	{
	var strValue = t.responseText;
	if(strValue==ProfileId)
		document.getElementById("PostaComment").innerHTML= "";
}

function PostComment(spanid,PosImg,LoginId,ProfileId,PreviewId) {
	var strComment = document.getElementById("frmComment").value;
/*	if(LoginId=="" || LoginId==0)	{
		showLogin("showLogin",PosImg,'','','PostComment');
		return false;
	}
	if(trim(strComment)=="")	{
		alert("Comment should not be empty.");
		return false;
	}*/
//	document.getElementById(spanid).innerHTML =loadingImg;
	var success = function(t){PostCommentComplete(t,spanid,PosImg,PreviewId,ProfileId);}
	var failure = function(t){editFailed(t);}
	var url = SiteAjaxFolder+"comment.php";
	var pars = 'action=Insert&Comments='+strComment+'&ProfileId='+ProfileId;
	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}	

function PostCommentComplete(t,spanid,PosImg,PreviewId,ProfileId)	{
	var strValue = t.responseText;
	var strDisplay = strValue.split("|");

	if(strDisplay[0]=="LoginLayer")	{
		document.getElementById("CommentPreview").innerHTML= "";
		showLogin("showLogin",PosImg,'',ProfileId,'PostComment');
	} else if(strDisplay[0]=="ChkComment")	{
		document.getElementById("CommentPreview").innerHTML= "";
		document.getElementById(PreviewId).innerHTML= CommentMsg;
	} else {
		if(strDisplay[1]!="")	{
		//	document.getElementById("PostaComment").innerHTML= "";
			document.getElementById(PreviewId).innerHTML= strDisplay[1];
		} else if(strDisplay[2]!="")	{
			//document.getElementById("PostaComment").innerHTML= "";
			document.getElementById(PreviewId).innerHTML= strDisplay[1];
		} else {
			
			document.getElementById(spanid).innerHTML =strDisplay[0];
			if(strDisplay[1]=="" && strDisplay[2]=="")	{
				document.getElementById(PreviewId).innerHTML= SuccessMsg;
				document.getElementById("frmComment").value = "";
				window.setTimeout("HideSuccessMsg('"+PreviewId+"');",2000);
				Show_Pagination('','0','',ProfileId,'');
			}
		}
	}
}

function HideSuccessMsg(PreviewId)	{
	document.getElementById(PreviewId).innerHTML= "";
}

/*function Show_Pagination(Page,StartLimit,EndLimit,ProfileId)	{
	document.getElementById("CommentList").innerHTML = loadingImg;
	var success = function(t){Show_PaginationComplete(t,Page,StartLimit,EndLimit,ProfileId);}
	var failure = function(t){editFailed(t);}
	var url = SiteAjaxFolder+"comment.php";
	var pars = 'action=Display&p='+Page+'&ProfileId='+ProfileId;
	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});	
}

function Show_PaginationComplete(t,Page,StartLimit,EndLimit,ProfileId)	{
	var strValue = t.responseText;
	var strDisplay = strValue.split("||");
	document.getElementById("CommentList").innerHTML = strDisplay[0];
	document.getElementById("CommentPagination").innerHTML = strDisplay[1];
}*/

function Show_Pagination(Page,StartLimit,EndLimit,ProfileId,CommentsPerPage)	{
	if(CommentsPerPage)
		var strCommentsPerPage = '&strCommentsPerPage='+CommentsPerPage;
	else
		var strCommentsPerPage = '&strCommentsPerPage=';
	document.getElementById("CommentList").innerHTML = loadingImg;
	var success = function(t){Show_PaginationComplete(t,Page,StartLimit,EndLimit,ProfileId);}
	var failure = function(t){editFailed(t);}
	var url = SiteAjaxFolder+"comment.php";
	var pars = 'action=Display&Page='+Page+'&StartLimit='+StartLimit+'&EndLimit='+EndLimit+'&ProfileId='+ProfileId+strCommentsPerPage;
	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});	
}

function Show_PaginationComplete(t,Page,StartLimit,EndLimit,ProfileId)	{
	var strValue = t.responseText;
	var strDisplay = strValue.split("||");
	if(document.getElementById("ProfilePage"))	{
		if(document.getElementById("CommentPagination"))
			document.getElementById("CommentPagination").innerHTML = "";
		if(document.getElementById("ViewAllComments"))	{
			if(trim(strDisplay[3])!="")
				document.getElementById("ViewAllComments").innerHTML = "<a href=\""+strDisplay[3]+"\" title=\"View All Comments\"><span class=\"bluetext\">View All Comments</span></a>";	
		}
	} else {
		if(document.getElementById("CommentPagination"))
			document.getElementById("CommentPagination").innerHTML = strDisplay[1];
		if(document.getElementById("ViewAllComments"))
			document.getElementById("ViewAllComments").innerHTML = "";
	}
	if(document.getElementById("CommentList"))
		document.getElementById("CommentList").innerHTML = strDisplay[0];
	
	//else
	//document.getElementById("ViewAllComments").innerHTML = "<a href=\"{$objCustomUrls->getPageUrl('ViewAllComments',$ProfileId)}\" title=\"View All Comments\"><span class=\"bluetext\">View All Comments</span></a>";
	if(document.getElementById("CommentsResult"))
		document.getElementById("CommentsResult").innerHTML = strDisplay[2];
}