var ProgressBarImages = "<img src=\""+SiteGlobalPath+"images/blue_login.gif\" border=\"0\" align=\"absmiddle\">";
var Values = "";
function doThumb(tdId,linkId,profileId,Status,fileName){
	if(document.getElementById(tdId))
		document.getElementById(tdId).innerHTML = "<font color='#FF0000'>Saving...</font>";
	Values = tdId;
	var success = function(t){loadThumb(t, Values);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName; 
    var pars = 'linkId='+linkId+'&Status='+Status+'&profileId='+profileId; 
    var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadThumb(t, Values){
	var strContent = '';
	strContent = t.responseText;
	document.getElementById(Values).innerHTML = strContent;
}

function doComments(tdId,linkId,profileId,fileName){
	var strValue;
	strValue = document.getElementById('txtSubject').value;
	strValue += "||"+document.getElementById('txtComments').value;
	Values = tdId;
	if(document.getElementById("ProgressId"))
		document.getElementById("ProgressId").innerHTML = ProgressBarImages;
	var success = function(t){loadComments(t, Values);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName;
    var pars = 'ifCond=Comments&linkId='+linkId+'&strContent='+strValue+'&profileId='+profileId;
    var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function sendEmail(fileName){
	if(document.getElementById('txtToEmail').value==""){
		alert("Email should not be empty");
		document.getElementById('txtToEmail').focus();
		return false;
	}

	if(document.getElementById('txtSubject').value==""){
		alert("Subject should not be empty");
		document.getElementById('txtSubject').focus();
		return false;
	}
	
	if(document.getElementById('txtComments').value==""){
		alert("Comments should not be empty");
		document.getElementById('txtComments').focus();
		return false;
	}
	
	if(document.getElementById("ProgressId"))
		document.getElementById("ProgressId").innerHTML = ProgressBarImages;

	var strValue;
	strValue = document.getElementById('txtSubject').value;
	strValue += "||"+document.getElementById('txtComments').value;
	strValue += "||"+document.getElementById('txtToEmail').value;
	var success = function(t){loadEmailComments(t, Values);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName;
    var pars = 'ifCond=SendEmail&strContent='+strValue;
    var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadEmailComments(t, Values){
	document.getElementById("strMsg").innerHTML = t.responseText
}

function loadComments(t, Values){
	setTimeout("Userdetailsshowout()",1500);
	document.getElementById("strMsg").innerHTML = '<table border="0" cellpadding="10" cellspacing="0" width="100%"><tr><td><span class="LabelText"><b>Add a Comment</b></span></td><td align="right" valign="top" style="padding-right:10px;"></td></tr><tr><td colspan="2"><hr style="border:1px solid #000000" /></td></tr><tr><td colspan="2" nowrap colspan="2" width="100%" class="GreenText" style="padding-top:15px;padding-right:30px;"><b>Your Comment added Succesfully!</b></td></tr>';
}

function getBookmarkLabels(tdId,fileName){
	Values = tdId;
	var success = function(t){loadBookmarkLabels(t, Values);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName;
    var pars = 'ifCond=getLabels';
    var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadBookmarkLabels(t, Values){
	if(document.getElementById(Values))
		document.getElementById(Values).innerHTML = t.responseText;
}

function doBookmars(tdId,linkId,profileId,fileName){
	var strSelValue;
	var strTxtValue;
	strSelValue = document.getElementById('selProfileLabel').value;
	strTxtValue = document.getElementById('txtLabel').value;
	Values = tdId;
	var success = function(t){loadBookmarks(t, Values);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName;
    var pars = 'ifCond=Bookmarks&linkId='+linkId+'&strSelValue='+strSelValue+'&strTxtValue='+strTxtValue+'&profileId='+profileId;
    var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadBookmarks(t, Values){
	setTimeout("Userdetailsshowout()",1500);
	document.getElementById("strMsg").innerHTML = '<table border="0" cellpadding="10" cellspacing="0" width="100%"><tr><td><span class="LabelText"><b>Add a Bookmark</b></span></td><td align="right" valign="top" style="padding-right:10px;"></td></tr><tr><td colspan="2"><hr style="border:1px solid #000000" /></td></tr><tr><td colspan="2" class="GreenText" style="padding-top:15px;"><b>You have successfully bookmarked the profile in your Saved items.!</b></td></tr>';
}

function CloseAddTagLayer(Layer)	{
	document.getElementById(Layer).innerHTML ="";
}

function doAddTag(tdId,fileName,profileId,linkId,MainTag,Display,Total,TagCount,TagCountId,AllTags){
	//	alert(tdId+" - "+fileName+" - "+profileId+" - "+linkId+" - "+MainTag+" - "+Display+" - "+Total+" - "+TagCount+" - "+TagCountId+" - "+AllTags)
	if(document.getElementById('txtTag').value=="")	{
		alert("Tag shouldnot be empty.");
		document.getElementById('txtTag').focus();
		return false;
	}
	/*if(document.getElementById('HdRelatedTagArray').value!=""){
	strTagId = document.getElementById('HdRelatedTagArray').value;
	myString = strTagId.split("_");
	}*/
	TaglayerValue = Display.substring(8,Display.length)
	TotalTagLayer = "HdTotalCount"+TaglayerValue;
	/*if(document.getElementById('HdRelatedFontSize').value!=""){
	strTagFont = document.getElementById('HdRelatedFontSize').value;
	}*/
	if(document.getElementById(TotalTagLayer)){
	if(document.getElementById(TotalTagLayer).value!=""){
	TagCount = document.getElementById(TotalTagLayer).value;
	}
	}
	var strValue;
	strValue = document.getElementById('txtTag').value;
	Values = tdId;
	var success = function(t){loadAddTagComplete(t,Values,profileId,linkId,fileName,MainTag,Display,Total,TagCount,TagCountId,AllTags,strValue);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName;
	var pars = 'ifCond=AddingNewTag&strContent='+strValue+'&ProfileId='+profileId+'&Total='+Total+'&linkId='+linkId+'&TagCount='+TagCount+'&TagCountId='+TagCountId+'&AllTags='+AllTags+'&Values='+Values+'&MainTag='+MainTag+'&Display='+Display;
    var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadAddTagComplete(t,Values,profileId,linkId,fileName,MainTag,Display,Total,TagCount,TagCountId,AllTags,strTagName){
	var strValue = t.responseText; 
	var strDisplay = strValue.split("|");
	if(strDisplay[1]=="LoginLayer")	{
		var DisplayTag =  "AddTag"+profileId;
	showLogin("showLogin",DisplayTag,linkId,profileId,"AddNewTagLayer","","",Total,Values,MainTag,TagCount,TagCountId,"","","","","","",AllTags,strTagName);
	
	} else {
		var strCount = TagCount;
		var TotalCount = parseInt(strCount)+1;
		TaglayerValue = Display.substring(8,Display.length)
		TotalTagLayer = "HdTotalCount"+TaglayerValue;
		document.getElementById(TotalTagLayer).value = TotalCount;
		TagsDetails(profileId,linkId,fileName,Values,MainTag,Display,Total,TagCountId,AllTags)
		if(strDisplay[0]!="")
		{ 
			RelatedTags(document.getElementById('HdRelatedTagArray').value,fileName)
		}  
		document.getElementById(Display).innerHTML = strDisplay[0];
	}
}
function WhoAllVoted(profileId,linkId,fileName){
	var success = function(t){loadWhoAllVotedComplete(t);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName;
	var pars = 'ifCond=WhoAllVoted&ProfileId='+profileId+'&MemberId='+linkId;
    var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}
function loadWhoAllVotedComplete(t) {
	if(document.getElementById('Whoallvoted'))
	document.getElementById('Whoallvoted').innerHTML = t.responseText;
}


function  RelatedTags(strTagValues,fileName)
{
	var success = function(t){loadRelatedTagsDetailsComplete(t);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName;
    var pars = 'ifCond=DisplayRelatedTags&strTagValue='+strTagValues;
    var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
	
}
function loadRelatedTagsDetailsComplete(t) {
	document.getElementById('HdRelatedTag').innerHTML = t.responseText
}

function TagsDetails(profileId,linkId,fileName,Values,MainTag,Display,Total,TagCountId,AllTags)
{
	if(document.getElementById('HdDisplayCount')) {
	TagDisplayCount = document.getElementById('HdDisplayCount').value
	}
	else {
	TagDisplayCount = "";
	}
	if(document.getElementById('EndValue'))
	 var EndValue =document.getElementById('EndValue').value
	else
	
	 EndValue= "";
	var success = function(t){loadTagsDetailsComplete(t,Values,MainTag,Display,TagCountId,profileId,linkId,fileName);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName;
    var pars = 'ifCond=DisplayTag&ProfileId='+profileId+'&Total='+Total+'&Display='+Display+'&AllTags='+AllTags+'&LinkId='+linkId+'&MainTag='+MainTag+'&TagCountId='+TagCountId+'&TagDisplayCount='+TagDisplayCount+'&EndValue='+EndValue;
  	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadTagsDetailsComplete(t,Values,MainTag,Display,TagCountId,profileId,linkId,fileName)  {
	var strDisplay = t.responseText.split('||');
	var strTagLink = strDisplay[1];
	Mystring = strDisplay[0].split('<a onclick')
	TotalCount = Mystring.length-1;
	TotalCountId(profileId,linkId,fileName,TagCountId,strTagLink)
/*	if(document.getElementById(TagCountId)){
	  document.getElementById(TagCountId).innerHTML =' <a href='+strTagLink+' class="Blueicon" style="cursor:pointer">Tags('+TotalCount+')</a>';
	}*/
	   var strContent = strDisplay[0]
		document.getElementById(MainTag).innerHTML = strDisplay[0];
		WhoAllVoted(profileId,linkId,fileName)

		if(strContent!="")
		{
			window.setTimeout("Closedetailsshowout('"+Display+"');",1000);
		}
}
function TotalCountId(profileId,linkId,fileName,TagCountId,strTagLink) {
	var success = function(t){loadTotalCountIdDetailsComplete(t,TagCountId,strTagLink);}
	var failure = function(t){editFailed(t);}
	var url = fileName;
    var pars = 'ifCond=TotalCount&ProfileId='+profileId+'&LinkId='+linkId;
  	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadTotalCountIdDetailsComplete(t,TagCountId,strTagLink)
{
	  document.getElementById(TagCountId).innerHTML =' <a href='+strTagLink+' class="Blueicon" style="cursor:pointer">Tags('+t.responseText+')</a>';
}

function ShowVoteDetails(linkId,profileId,fileName,TagId,Vote,Display,MainTag,Total,AllTags,TagCountId)
{
	AllTags = AllTags.replace(/ /g,"_");
//	alert(linkId+" - "+profileId+" - "+fileName+" - "+TagId+" - "+Vote+" - "+Display+" - "+MainTag+" - "+Total+" - "+AllTags+" - "+TagCountId)
	document.getElementById('ChangeVote').innerHTML  = "<img src='"+SiteGlobalPath+"images/no.gif' alt='' onclick=AddAnVote('"+linkId+"','"+profileId+"','"+fileName+"','"+TagId+"','"+Vote+"','"+Display+"','"+MainTag+"','"+Total+"','"+TagCountId+"','"+AllTags+"'); onkeypress=AddAnVote('"+linkId+"','"+profileId+"','"+fileName+"','"+TagId+"','"+Vote+"','"+Display+"','"+MainTag+"','"+Total+"','"+TagCountId+"','"+AllTags+"'); style='cursor:pointer'  align='absmiddle' tabindex='300'> &nbsp;&nbsp; ";//<a href='#'  class='url' >Remove Tag</a>
}

function AddAnVote(linkId,profileId,fileName,TagId,Vote,Display,MainTag,Total,TagCountId,AllTags) {
	//alert(linkId+" - "+profileId+" - "+fileName+" - "+TagId+" - "+Vote+" - "+Display+" - "+MainTag+" - "+Total+" - "+TagCountId+" - "+AllTags)
	var success = function(t){loadAddAnVoteComplete(t,linkId,profileId,fileName,TagId,Vote,Display,MainTag,Total,AllTags,TagCountId);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName;
    var pars = 'ifCond=AddingVote&ProfileId='+profileId+'&linkId='+linkId+'&TagId='+TagId+'&Vote='+Vote;
    var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadAddAnVoteComplete(t,linkId,profileId,fileName,TagId,Vote,Display,MainTag,Total,AllTags,TagCountId)  {
 	TagsDetails(profileId,linkId,fileName,Values,MainTag,Display,Total,TagCountId,AllTags)
	//document.getElementById(TagCountId).innerHTML =' <a href='+MyTagUrl+' class="Blueicon" style="cursor:pointer">Tags('+TotalCount+')</a>';
	//alert(t.responseText)
	if(t.responseText=="Insert") {
    DisplayMessage = "Vote has been added successfully"; 
	} else if(t.responseText=="Update") {
	DisplayMessage = "Your vote has been changed"; 
	} else if(t.responseText=="Delete") {
	 DisplayMessage = "The Tag that have added is removed";
	 RelatedTags(document.getElementById('HdRelatedTagArray').value,fileName)
	}
	strContent = "<table border='0' cellpadding='0' cellspacing='0'><tr><td>";
	strContent = strContent+"<img src='"+SiteGlobalPath+"images/greenleft.gif' alt=''></td><td background='"+SiteGlobalPath+"images/greentopbg.gif'>";
	strContent = strContent+"</td><td><img src='"+SiteGlobalPath+"images/greenright.gif' alt=''></td></tr><tr><td background='"+SiteGlobalPath+"images/greenleftbg.gif' ></td>";
	strContent = strContent+"<td bgcolor='#FFFFFF' class='content'> "+DisplayMessage+ "</td><td background='"+SiteGlobalPath+"images/greenrightbg.gif'></td></tr>";
	strContent = strContent+"<tr><td><img src='"+SiteGlobalPath+"images/greenbtmleft.gif'alt=''></td><td background='"+SiteGlobalPath+"images/greenbtmbg.gif'></td>";
	strContent = strContent+"<td><img src='"+SiteGlobalPath+"images/greenbtmright.gif'  alt=''></td></tr></table>";
	document.getElementById(Display).innerHTML = strContent;
	if(strContent!="")
	{
		window.setTimeout("Closedetailsshowout('"+Display+"');",1000);
	}
}

function WhoVoted(TagId,fileName,Display) {
	var success = function(t){loadWhoVotedComplete(t,Display);}
	var failure = function(t){editFailed(t, Values);}
	var url = fileName;
    var pars = 'ifCond=WhoVoted&TagId='+TagId;
    var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadWhoVotedComplete(t,Display)  {
	document.getElementById('WhoVotedDisplay').style.visibility = "visible";
	document.getElementById('WhoVotedDisplay').style.position   = "relative";
			objXML 					= t.responseXML;
			
			var objElements 		= objXML.getElementsByTagName("WhoVote");
			var strContent  = ""
			if(objElements.length!="") {
				for (var iNode=0;iNode<objElements.length;iNode++)
				{
					thisNode 		 = objElements.item(iNode);
					var InterestList = thisNode.getAttribute("UserName").toString();
					strContent 	 = strContent+"<a href="+thisNode.getAttribute("Member_Url").toString()+">"+InterestList+"</a><Br>";
				} 
			}
			strContent = strContent+"";
		document.getElementById('VoterDetailsDisplay').innerHTML = strContent;
}

function AddToMyInterest(InterestId,spanid,strCategoryCode,PosImg,CatgoryTitle) {
				CatgoryTitle=CatgoryTitle.replace(/ /g,"_");
				CatgoryTitle=CatgoryTitle.replace(/&/g,"AMP");
				
				var success = function(t){loadAddToMyInterestComplete(t,spanid,InterestId,strCategoryCode,CatgoryTitle,PosImg);}
				var failure = function(t){loadFailed(t);}
				var url 	= SiteGlobalPath+"ajax/peopleresults.php";
				var pars 	= "ifCond=DirectoryInterest&InterestId="+InterestId+'&strCategoryCode='+strCategoryCode+'&Display='+spanid+'&PosImg='+PosImg+'&CatgoryTitle='+CatgoryTitle;
				var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadAddToMyInterestComplete(t,spanid,InterestId,strCategoryCode,CatgoryTitle,PosImg)
{
	var strValue = t.responseText; 
	var strDisplay = strValue.split("|");
	if(strDisplay[1]=="LoginLayer")	{
	var DisplayTag =  "AddInterestImg";
	showLogin("showLogin",PosImg,"","",DisplayTag,"","","",spanid,"","","","","",InterestId,strCategoryCode,CatgoryTitle);
	} else {
		strcontent = "<Table width='40%' border='0' cellpadding='2' cellspacing='2' class='TableBorder' bgcolor='#FFFFFF'>";
		strcontent = strcontent+"<tr><td align='right' style='padding-bottom:10px'><img src='"+SiteGlobalPath+"images/icon_red_close_over.gif' border='0'  align='right' onClick=Closedetailsshowout('"+spanid+"') title='Close'></td></tr>";
		strcontent = strcontent+"<Tr><td  class='InterestTextSmall' align='center'  style='padding-bottom:10px;padding-right:4px;padding-left:4px;' nowrap>"+strValue+"</td></tr>";
		strcontent = strcontent+"<Tr><td  class='LeftPanelLinks'  align='center'>";
		strcontent = strcontent+"<a onclick=Closedetailsshowout('"+spanid+"');><u>Close</u></a> </td></tr></table>";
		document.getElementById(spanid).innerHTML=strcontent; 
		if(trim(strValue) =="Member interest already exist" || trim(strValue) =="Member interest added successfully" || trim(strValue) =="You already have 10 interest added to your interest list" )
		 {
			 PeopleListing(strCategoryCode,spanid,InterestId,CatgoryTitle,PosImg);
		  }
	}
}

function PeopleListing(strCategoryCode,spanid,InterestId,CatgoryTitle,PosImg) {
				var success = function(t){loadPeopleListingComplete(t,spanid);}
				var failure = function(t){loadFailed(t);}
				var url 	= SiteGlobalPath+"ajax/peopleresults.php";
				var pars 	= "op=PeopleList&c="+strCategoryCode+"&InterestId="+InterestId+'&CatgoryTitle='+CatgoryTitle+'&PosImg='+PosImg;
				var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}

function loadPeopleListingComplete(t,spanid) {
		document.getElementById('PeopleList').innerHTML = t.responseText;
		window.setTimeout("Closedetailsshowout('"+spanid+"');",2000);
}