/**
 * Social Media Tool Module JS Files
 * @author Praxis Solutions India
 * @link http://www.praxissolutions.biz
 * @version 1.0
 * @package justmeans
 * @subpackage Social Media Tool
 */
 
/*----------------------------- COMMON FUNCTIONS ----------------------------------*/
var strLoadingHtml = "<div style='text-align:center; padding: 40px;'><span style='font-size: 20px; font-weight: bold; color: #AAAAAA;'>Loading...</span><br /><br /><img src='images/big_slide_loader.gif' align='absmiddle'></div>";
var strSmallLoadingHtml = "<div style='text-align:center; padding: 22px;'><span style='font-size: 15px; font-weight: bold; color: #AAAAAA;'>Loading...</span>&nbsp;<img src='images/ajax-loader-small-bar.gif' align='absmiddle'></div>";
var ajaxObjects = new Array();
var ajaxObjects = new Array();
var arrSubtabOnclick = new Array();
var strFacebookAccountOption = "";
Lightbox.enmStopResetSession = 0;


var strOperation = "";
var strOperationTest = "";
var boolLogginUserId = 0;

var arrMediaAccounts = new Array();
arrMediaAccounts[0] = new Array();
arrMediaAccounts[0]['type'] = "tw";
arrMediaAccounts[0]['display'] = "none";
arrMediaAccounts[1] = new Array();
arrMediaAccounts[1]['type'] = "fb";
arrMediaAccounts[1]['display'] = "none";
arrMediaAccounts[2] = new Array();
arrMediaAccounts[2]['type'] = "ln";
arrMediaAccounts[2]['display'] = "none";

function fnBuildMediaArray(strMediaAccounts) {
	var arrTempArray = new Array();
	if(strMediaAccounts != "") {
		arrTempArray  = strMediaAccounts.split(",");
	}
	for(var i=0 ; i< arrMediaAccounts.length; i++) {
		var strTabs = arrMediaAccounts[i]["type"];
		for(var j=0; j<arrTempArray.length; j++) {
			var strSelectedTab = arrTempArray[j];
			if(strTabs == strSelectedTab) {
				arrMediaAccounts[i]["display"] = "";
			}
		}	
	}
}

function fnResetMediaArray(strSelectedTabName) {
	var intParentTabCount = arrParentTabs.length;
	for(var i=0; i<intParentTabCount; i++) {
		strTabType = arrParentTabs[i]['type'];
		if(strTabType == strSelectedTabName) {
			switch(strOperation) {
				case "view":
				case "add":
					arrParentTabs[i]["display"] = "";
				break;
				case "remove":
					arrParentTabs[i]["display"] = "none";
					strSelectedTabName = "list";
				break;
				default:
					strSelectedTabName = "list";
				break;
			}
			break;
		}
	}
	strOperation = "";
	return strSelectedTabName;
}

function fnSetParentTabs(strSelectedTabName) {
	strSelectedTabName = fnResetMediaArray(strSelectedTabName);
	var intParentTabCount = arrParentTabs.length;
	for(var i=0; i<intParentTabCount; i++) {
		strTabType = arrParentTabs[i]['type'];
		if(strSelectedTabName != "") {
			if(strSelectedTabName == strTabType) {
				if(strTabType == "stat" || strTabType == "rss") arrParentTabs[i]["class"] = "lightBlueButton lightBlueButtonActive";	
				else arrParentTabs[i]["class"]= "active";	
			} else {
				if(strTabType == "stat" || strTabType == "rss") arrParentTabs[i]["class"] = "lightBlueButton";	
				else arrParentTabs[i]["class"] = "";
			}
		}	
	}
	 
	for(var i=0; i<intParentTabCount; i++) {
		var strTabType = arrParentTabs[i]['type'];
		var strTabId = arrParentTabs[i]['id'];
		var strTabDispalay =  arrParentTabs[i]['display'];
		var strTabClassName = arrParentTabs[i]['class'];
		document.getElementById(strTabId).style.display = strTabDispalay;
		document.getElementById(strTabId).className = strTabClassName;
	}
}


function fnShowTabAccount(strAccountType, objTab, boolLogin) {
	if(!boolLogin) { 
		fnNewRegisterLogin(0,0);
		return false;
	}
	if(strAccountType == null) return false;
	if(objTab == null) return false;
	strOperation = 'view'; 
	fnSetParentTabs(strAccountType);
	switch(strAccountType){
		case "all":
			fnShowAllAccounts();
		break;
		case "jm":
			 fnShowJustmeansAccount(objTab);
		break;
		case "tw":
			fnShowTwitterAccounts(objTab);
		break;
		case "fb":
			fnShowFacebookAccount(objTab);
		break;
		case "ln":
			fnShowLinkedinAccount(objTab);
		break;
		case "list":
			fnShowAddAccount(objTab);
		break;
		case "stat":
			fnShowUrlStatDetails();
		break;
		case "rss":
			fnShowRssDetails();
		break;
		default:
			return false;
		break;
	}
}
var arrAccounts = new Array( "justmeans", "fb", "tw", "ln", "network");


function fnInitMediaAccount()
{
	arrMenuTabs = document.getElementById("id_Account_Tab").getElementsByTagName("LI");
	fnShowJustmeansAccount(arrMenuTabs[0], "", "");
}

function fnViewMainNavigationTabs(strTabType)
{
	ajaxObjects[3] = new sack();
	ajaxObjects[3].PostParam = "&tabtype="+strTabType;
	ajaxObjects[3].requestFile = sitename+"/managesocialmedianetwork&mode=ajax&ajax_action=viewallaccounttabs";
	ajaxObjects[3].onCompletion = function(){
												strResponse = ajaxObjects[3].response;
												document.getElementById("id_SocialMediaSite_Tab").innerHTML = strResponse;
												var objTwitterTab = null;
												arrAccountTabs = document.getElementById("id_Account_Tab").getElementsByTagName("LI");
												
												for (intI = 0; intI < arrAccountTabs.length; intI++)
												{
													if (arrAccountTabs[intI].getAttribute("tabname") == "tw" && strTabType == "tw")
													{
														objTwitterTab = arrAccountTabs[intI];
														fnShowTwitterAccount(objTwitterTab);
														break;
													}
													if (arrAccountTabs[intI].getAttribute("tabname") == "fb" && strTabType == "fb")
													{
														objTwitterTab = arrAccountTabs[intI];
														fnShowFacebookAccount(objTwitterTab);
														break;
													}
													if (arrAccountTabs[intI].getAttribute("tabname") == "ln" && strTabType == "ln")
													{
														objTwitterTab = arrAccountTabs[intI];
														fnShowLinkedinAccount(objTwitterTab);
														break;
													}
												}
											};
	ajaxObjects[3].runAJAX();
}

function fnProcessManageAccounts()
{
	ajaxObjects[3] = new sack();
	ajaxObjects[3].requestFile = sitename+"/addsocialnetwork&mode=ajax&ajax_action=viewmanageaccount";
	ajaxObjects[3].onCompletion = function(){
												strResponse = ajaxObjects[3].response;
												document.getElementById("id_ManageAccountForm").innerHTML = strResponse;
											};
	ajaxObjects[3].runAJAX();
}

function fnEditAccount(strAccoutId,strAccountType)
{
	document.getElementById("id_Edit_"+strAccoutId).style.display = "none";
	document.getElementById("id_Edit_Loading_"+strAccoutId).style.display = "";
	
	ajaxObjects[5] = new sack();
	ajaxObjects[5].PostParam = "&account="+strAccoutId+"&type="+strAccountType;
	ajaxObjects[5].requestFile = sitename+"/addsocialnetwork&mode=ajax&ajax_action=editaccount";
	ajaxObjects[5].onCompletion = function(){
												document.getElementById("id_Edit_"+strAccoutId).style.display = "";
												document.getElementById("id_Edit_Loading_"+strAccoutId).style.display = "none";
												strResponse = ajaxObjects[5].response;
												arrResponse = strResponse.split("|");
												
												if (arrResponse[0] == "error")
												{
													//document.getElementById("id_ErrorMessage").style.display = "";
													document.getElementById("id_ErrorMessage").innerHTML = arrResponse[1];
													if (document.getElementById("id_ErrorMessage").style.display == "none")
														$("#id_ErrorMessage").slideToggle();
												}
												else
												{
													document.getElementById("id_ErrorMessage").style.display = "none";
													document.getElementById("id_ErrorMessage").innerHTML = "";
													
													document.getElementById("id_EditAccount").innerHTML = arrResponse[1];
													Lightbox.enmStopResetSession = 0;
													Lightbox.showBoxByID("id_EditAccount");
												}
											};
	ajaxObjects[5].runAJAX();
}

function fnRemoveAccount(strAccoutId, strAccountType, verified)
{
	if(verified) {
		var isAccountExists = 0;
		try { ajax_hideTooltip(); } catch(e) { }
		var strDecodedAccountType = Base64.decode(strAccountType);
		switch(strDecodedAccountType) {
			case "fb":
			case "fbp":
				try { 
					fnUnsetFacebookAccount(strAccoutId, strAccountType)
				} catch(e) { }
			break;
			default:
				ajax_hideTooltip();	
				ajaxObjects[7] = new sack();
				ajaxObjects[7].PostParam = "&account="+strAccoutId;
				ajaxObjects[7].requestFile = sitename+"/addsocialnetwork&mode=ajax&ajax_action=removeaccount";
				ajaxObjects[7].onCompletion = function(){
															var strResponse = ajaxObjects[7].response;
															arrResponse = strResponse.split("|");
															if(arrResponse[0] == "success") {
																isAccountExists = parseInt(arrResponse[2], 10);
																if(!isAccountExists) strOperation = "remove";
																else strOperation = "";
																fnSetParentTabs(Base64.decode(strAccountType));
																fnSetSocialNetworkAccounts(1);
																fnShowAddAccount(document.getElementById('id_list'));
															} else {
																ajax_showTooltip('id_remove_error',document.getElementById('id_Remove_'+strAccoutId),220,55);
															}
														};
				ajaxObjects[7].runAJAX();			
			break;
		}
		return true;
	} else {
		document.getElementById('id_remove_confirm').setAttribute('onClick', "fnRemoveAccount('" + strAccoutId + "' , '" + strAccountType + "', 1); void(0);" );
		ajax_showTooltip('id_remove_account',document.getElementById('id_Remove_'+strAccoutId),220,60);
		return false;
	}
}

function fnToggleAccountMenu(intTabId)
{
	var arrAccountTabs=null;
	try{
		if(document.getElementById("id_AccountTabContainer"))
		arrAccountTabs = document.getElementById("id_AccountTabContainer").getElementsByTagName("A");
		
		for (intI = 0; intI < arrAccountTabs.length; intI++)
		{
			if (intTabId == arrAccountTabs[intI].getAttribute("value"))
				//arrAccountTabs[intI].parentNode.className = "active";
				AddClassName(arrAccountTabs[intI].parentNode,"active");
			else
				//arrAccountTabs[intI].parentNode.className = "";
				RemoveClassName(arrAccountTabs[intI].parentNode,"active");
		}
	}
	catch(e)
	{
		
	}

	document.getElementById("id_JustmeansForm").style.display = "none";
	document.getElementById("id_JustmeansForm").innerHTML = "";
	
	document.getElementById("id_TwitterForm").style.display = "none";
	document.getElementById("id_TwitterForm").innerHTML = "";
	
	document.getElementById("id_FacebookForm").style.display = "none";
	document.getElementById("id_FacebookForm").innerHTML = "";
	
	document.getElementById("id_FacebookPagesForm").style.display = "none";
	document.getElementById("id_FacebookPagesForm").innerHTML = "";
	
	document.getElementById("id_LinkedinForm").style.display = "none";
	document.getElementById("id_LinkedinForm").innerHTML = "";
	
	document.getElementById("id_DeliciousForm").style.display = "none";
	document.getElementById("id_DeliciousForm").innerHTML = "";
	
	document.getElementById("id_TumblerForm").style.display = "none";
	document.getElementById("id_TumblerForm").innerHTML = "";
	
	document.getElementById("id_ManageAccountForm").style.display = "none";
	document.getElementById("id_ManageAccountForm").innerHTML = "";
	
	strFacebookAccountOption = "";
	
	switch (intTabId)
	{
		case 1:
		
			document.getElementById("id_TwitterForm").style.display = "";
			document.getElementById("id_TwitterForm").innerHTML = strLoadingHtml;
			fnProcessToggleMenu("id_TwitterForm","tw");
		break;
		case 2:
			document.getElementById("id_FacebookForm").style.display = "";
			document.getElementById("id_FacebookForm").innerHTML = strLoadingHtml;
			strFacebookAccountOption = "account";
			fnConnectToFacebook("id_FacebookForm","fb")
			//fnProcessToggleMenu("id_FacebookForm","fb");
		break;
		case 3:
			document.getElementById("id_LinkedinForm").style.display = "";
			document.getElementById("id_LinkedinForm").innerHTML = strLoadingHtml;
			fnProcessToggleMenu("id_LinkedinForm","ln");
		break;
		case 4:
			document.getElementById("id_ManageAccountForm").style.display = "";
			document.getElementById("id_ManageAccountForm").innerHTML = strLoadingHtml;
			fnProcessManageAccounts();
		break;
		case 5:
			document.getElementById("id_DeliciousForm").style.display = "";
			document.getElementById("id_DeliciousForm").innerHTML = strLoadingHtml;
			fnProcessToggleMenu("id_DeliciousForm","del");
		break;
		
		case 6:
			document.getElementById("id_TumblerForm").style.display = "";
			document.getElementById("id_TumblerForm").innerHTML = strLoadingHtml;
			fnProcessToggleMenu("id_TumblerForm","tumb");
		break;
		
		case 7:
			document.getElementById("id_FacebookPagesForm").style.display = "";
			document.getElementById("id_FacebookPagesForm").innerHTML = strLoadingHtml;
			strFacebookAccountOption = "page";
			fnProcessToggleMenu("id_FacebookPagesForm","fbp");
		break;
		case 8:
			document.getElementById("id_JustmeansForm").style.display = "";
			document.getElementById("id_JustmeansForm").innerHTML = strLoadingHtml;
			fnProcessToggleMenu("id_JustmeansForm","jm");
		break;
	}
}

function fnProcessToggleMenu(strContainer,strAccountType)
{
	ajaxObjects[6] = new sack();
	ajaxObjects[6].PostParam = "&type="+Base64.encode(strAccountType);
	ajaxObjects[6].requestFile = sitename+"/managesocialmedianetwork&mode=ajax&ajax_action=togglemenu";
	ajaxObjects[6].onCompletion = function(){
													document.getElementById(strContainer).innerHTML = ajaxObjects[6].response;
											};
	ajaxObjects[6].runAJAX();
}

function fnShowAddAccount(objAccountTab)
{
	fnSetParentTabs("list");
	document.getElementById("id_SocialMediaSite_Container").innerHTML = strLoadingHtml;
	
	ajaxObjects[12] = new sack();
	ajaxObjects[12].requestFile = sitename+"/managesocialmedianetwork&mode=ajax&ajax_action=viewaddaccount";
	ajaxObjects[12].onCompletion = function(){
												document.getElementById("id_SocialMediaSite_Container").innerHTML = ajaxObjects[12].response;
											};
	ajaxObjects[12].runAJAX();
}

function fnDisableSubAccountTabs()
{
	arrMenuTabs = document.getElementById("id_Sub_Account_Tab").getElementsByTagName("LI");
	intLastItem = (arrMenuTabs.length - 1);
	for (intTab = 0; intTab < arrMenuTabs.length; intTab++)
	{
		arrSubtabOnclick[intTab] = arrMenuTabs[intTab].onclick;
		arrMenuTabs[intTab].onclick = "";
	}
}

function fnEnableSubAccountTabs()
{
	arrMenuTabs = document.getElementById("id_Sub_Account_Tab").getElementsByTagName("LI");
	intLastItem = (arrMenuTabs.length - 1);
	for (intTab = 0; intTab < arrMenuTabs.length; intTab++)
	{
		arrMenuTabs[intTab].onclick = arrSubtabOnclick[intTab];
	}
}

function fnGetContainerDiv(strParentDivId, strChildDivId)
{
	objParentDiv = document.getElementById(strParentDivId);
	arrChildDiv = objParentDiv.getElementsByTagName("DIV");
	
	for (intI = 0; intI < arrChildDiv.length; intI++)
	{
		if (arrChildDiv[intI].id == strChildDivId)
			return arrChildDiv[intI];
	}
}

/******************************** ALL TABS FUNCTION *****************************************/
function fnGetMoreTwits(intPageid,intMax_id,strSearchq)
{
	document.getElementById("id_twitmoreupdates_"+intPageid).innerHTML  ="<div style='text-align:center; padding: 40px;'><span style='font-size: 20px; font-weight: bold; color: #AAAAAA;'>Loading...</span><br /><br /><img src='images/big_slide_loader.gif' align='absmiddle'></div>";	
	ajaxObjects[110] = new sack();
	ajaxObjects[110].requestFile = sitename+"/allaccountstab?mode=ajax&ajax_action=getmoretwitupdate&pageid="+intPageid+"&maxid="+intMax_id+"&search='"+strSearchq+"'";
	//alert(ajaxObjects[110].requestFile);
	ajaxObjects[110].onCompletion = function(){ 
					// SET RESPONSE AS INNER HTML
					if(ajaxObjects[110].response != "Bad Request" || ajaxObjects[110].response !='INVALID REQUEST!')
					{
						document.getElementById('id_twitmoreupdates_'+intPageid).innerHTML = ajaxObjects[110].response;
					}
					else
					{
						return false;
					}
			};
	ajaxObjects[110].runAJAX();	
}

function fnHideShowRetweet(intFlag,intId)
{
	if(intFlag)
	{
		document.getElementById('id_retweet_'+intId).style.display="";
	}
	else
	{
		document.getElementById('id_retweet_'+intId).style.display="none";
	}	
}

function FnGetlatest()
{
	var ajaxIndex = ajaxObjects.length;	
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].requestFile = sitename+"/allaccountstab?mode=ajax&ajax_action=latesttweet";
	//alert(ajaxObjects[ajaxIndex].requestFile);
	ajaxObjects[ajaxIndex].onCompletion = function(){ 
					// SET RESPONSE AS INNER HTML
					//alert(ajaxObjects[ajaxIndex].response);
					if(ajaxObjects[ajaxIndex].response != "Bad Request" || ajaxObjects[ajaxIndex].response !='INVALID REQUEST!')
					{
						$("div#twitupdates").prepend(ajaxObjects[ajaxIndex].response);
						$("#twitupdate").slideDown("40");
					}
					else
					{
						return false;
					}
			};
	ajaxObjects[ajaxIndex].runAJAX();	
	setTimeout("FnGetlatest();", 20000);
}

function fnGetUpdateList_jm(strLoad_jm,distid,intjmuserid,strtwoption)
{
	var updatename=strLoad_jm.split("_");
	var strUpdateName = updatename[0];
	
	var ajaxIndex = ajaxObjects.length;	
	ajaxObjects[ajaxIndex] = new sack();
	if(strUpdateName=="jm")
	{
		ajaxObjects[ajaxIndex].requestFile = sitename+"/allaccountstab&mode=ajax&ajax_action=jm_getupdates&jmuserid="+intjmuserid+"&distid="+distid;
	}
	else
	{
		var sendUpdateName = strUpdateName+"_getupdates";
		ajaxObjects[ajaxIndex].requestFile = sitename+"/allaccountstab&mode=ajax&ajax_action="+sendUpdateName+"&distid="+distid+"&tweetopt="+strtwoption;
	}
	ajaxObjects[ajaxIndex].onCompletion = function(){
						document.getElementById(strLoad_jm).innerHTML = ajaxObjects[ajaxIndex].response;
					};
	ajaxObjects[ajaxIndex].runAJAX();
}

function fnSeArrayUpdates()
{
	var allC = document.getElementById('id_SocialMediaSite_Container').getElementsByTagName('input');
    for(var i=0;i<allC.length;i++)
	{
        if(allC[i].type=='hidden')
		{
			var rowid= allC[i].id;
			var my_array=rowid.split("_");
			var strUpdate = my_array[1];
			var distid = my_array[2];
			var intjmuserid = my_array[3];
			var strtwoption = my_array[4];
			switch(strUpdate)
			{
				case "tw":
					var strUpdatesdiv = "tw_"+distid+"_"+intjmuserid+"_"+strtwoption;
					document.getElementById(strUpdatesdiv).innerHTML = strLoadingHtml;
					fnGetUpdateList_jm(strUpdatesdiv,distid,intjmuserid,strtwoption);
				break;
				case "ln":
					var strUpdatesdiv = "ln_"+distid+"_"+intjmuserid;
					document.getElementById(strUpdatesdiv).innerHTML = strLoadingHtml;
					fnGetUpdateList_jm(strUpdatesdiv,distid,intjmuserid,'');
				break;
				case "fb":
					var strUpdatesdiv = "fb_"+distid+"_"+intjmuserid;
					document.getElementById(strUpdatesdiv).innerHTML = strLoadingHtml;
					fnGetUpdateList_jm(strUpdatesdiv,distid,intjmuserid,'');
				break;
				case "fbp":
					var strUpdatesdiv = "fbp_"+distid+"_"+intjmuserid;
					document.getElementById(strUpdatesdiv).innerHTML = strLoadingHtml;
					fnGetUpdateList_jm(strUpdatesdiv,distid,intjmuserid,'');
				break;
				case "jm":
					var strUpdatesdiv = "jm_"+distid+"_"+intjmuserid;
					document.getElementById(strUpdatesdiv).innerHTML = strLoadingHtml;
					fnGetUpdateList_jm(strUpdatesdiv,distid,intjmuserid,'');
				break;
			}
        }
    }
}

/******************************** ALL TABS FUNCTION *****************************************/
function fnShowAllAccounts() 
{
	fnSetParentTabs("all");
	document.getElementById("id_SocialMediaSite_Container").innerHTML = strLoadingHtml;
	var newTabFlag = "";
	var strSetResponse;
	ajaxObjects[9] = new sack();
	ajaxObjects[9].requestFile = sitename+"/allaccountstab";
	ajaxObjects[9].onCompletion = function(){
													strResponse = ajaxObjects[9].response;
													document.getElementById("id_SocialMediaSite_Container").innerHTML = strResponse;
													fnSeArrayUpdates();
											};
	ajaxObjects[9].runAJAX();
}
/********************************************************************************************/


/*----------------------------- FUNCTIONS FOR JUSTMEANS TAB ----------------------------------*/
var intJustmeansUpdatePage;
var strJustmeansUpdateDiv;
//var strJustMeansNewTab = "id_Justmeans_Tab_3";
var strJustMeansNewTab = "";
 
function fnShowJustmeansAccount(objJusmeansTab, newaddedflag, newaccount) {
	document.getElementById("id_SocialMediaSite_Container").innerHTML = strLoadingHtml;
	var newTabFlag = "";
	if(newaddedflag) newTabFlag = "&stab=1";
	ajaxObjects[9] = new sack();
	ajaxObjects[9].requestFile = sitename+"/listjustmeansupdates&mode=ajax&ajax_action=viewjustmeansallaccounts" + newTabFlag;
	ajaxObjects[9].onCompletion = function(){
													//alert(Base64.decode(ajaxObjects[9].response));
													strResponse = ajaxObjects[9].response;
													arrResponse = strResponse.split(" | ");
													document.getElementById("id_SocialMediaSite_Container").innerHTML = Base64.decode(arrResponse[0]);
													
													try
													{
														jQuery('#id_Sub_Account_Tab').jcarousel();
													}
													catch(e)
													{
														
													}
													fnDisableSubAccountTabs();
													intJustmeansUpdatePage = 1;
													strJustmeansUpdateDiv = "id_Justmeans_Container";
													objFirstTab = document.getElementById("id_Justmeans_Tab_1");
													if(newaddedflag) {
														arrMenuTabs = document.getElementById("id_Sub_Account_Tab").getElementsByTagName("LI");
														var newTab = "";
														for(var i = 0; i<arrMenuTabs.length;i++) {
															if(arrMenuTabs[i].getAttribute('tabid') == Base64.encode(newaddedflag)) { 
																objFirstTab = arrMenuTabs[i];
																//arrMenuTabs[i].className = "active"; 
																AddClassName(arrMenuTabs[i],"active");
																break;
															} else {
																 //arrMenuTabs[i].className = "";
																 RemoveClassName(arrMenuTabs[i],"active");
															}
														}
													} else if(newaccount) {
														
														arrMenuTabs = document.getElementById("id_Sub_Account_Tab").getElementsByTagName("LI");
														var newTab = "";
														for(var i = 0; i<arrMenuTabs.length;i++) {
															if(arrMenuTabs[i].getAttribute('jmid') == Base64.decode(newaccount)) { 
																objFirstTab = arrMenuTabs[i];
																//arrMenuTabs[i].className = "active"; 
																AddClassName(arrMenuTabs[i],"active");
																break;
															} else {
																 //arrMenuTabs[i].className = "";
																 RemoveClassName(arrMenuTabs[i],"active");
															}
														}
													}
													
													
													fnViewJustmeansUpdates(arrResponse[1],objFirstTab);
											};
	ajaxObjects[9].runAJAX();
}

function fnToggleJustmeansAccount(objJustmeansTab)
{
	try{
		document.getElementById('id_subtab_operation').style.display="none";
	}
	catch(e)
	{
		
	}
	
	fnToggleSubAccountTabs(objJustmeansTab.id);
	intJustmeansUpdatePage = 1;
	strJustmeansUpdateDiv = "id_Justmeans_Container";	
	//document.getElementById(strJustmeansUpdateDiv).className = "scrollCont";
	//document.getElementById(strJustmeansUpdateDiv).style.height = "300px";
	fnViewJustmeansUpdates(objJustmeansTab.getAttribute("account"), objJustmeansTab);
	
}

function fnViewJustmeansAccountFeed(strAccountId, strDivId, intPage, intRequest)
{
	if (intPage == 1) document.getElementById(strDivId).innerHTML = strLoadingHtml;
	ajaxObjects[intRequest] = new sack();
	ajaxObjects[intRequest].PostParam = "&account="+strAccountId+"&page="+intPage;
	ajaxObjects[intRequest].requestFile = sitename+"/listjustmeansupdates&mode=ajax&ajax_action=getjustmeansinnerhtml";
	ajaxObjects[intRequest].onCompletion = function(){
														if (intPage == 1) {
															document.getElementById(strDivId).innerHTML = ajaxObjects[intRequest].response;
														} else	{
															document.getElementById(strDivId).removeChild(document.getElementById(strDivId).lastChild);
															document.getElementById(strDivId).innerHTML = document.getElementById(strDivId).innerHTML + ajaxObjects[intRequest].response;
														}
													};
	ajaxObjects[intRequest].runAJAX();
}


function fnViewAllJustmeansAccount(strJustmeansId, objJustmeansTab) {
	strTabType  = objJustmeansTab.getAttribute("tabtype");
	strTabValue = objJustmeansTab.getAttribute("tabvalue");
	document.getElementById(strJustmeansUpdateDiv).innerHTML = strLoadingHtml;
	ajaxObjects[32] = new sack();
	ajaxObjects[32].PostParam = "&account="+strJustmeansId+"&action="+strTabType+"&actionvalue="+strTabValue+"&page="+intJustmeansUpdatePage;
	ajaxObjects[32].requestFile = sitename+"/listjustmeansupdates&mode=ajax&ajax_action=viewallaccounts";
	ajaxObjects[32].onCompletion = function(){
												strResponse = ajaxObjects[32].response;
												arrResponse = strResponse.split(" | ");
												document.getElementById(strJustmeansUpdateDiv).innerHTML = Base64.decode(arrResponse[0]);
												strAccountIds = Base64.decode(arrResponse[1]);
												arrAccountIds = strAccountIds.split(",");
												for (intI = 0; intI < arrAccountIds.length; intI++) {
													strAccountId = arrAccountIds[intI].toString();
													strDivId = "id_JustmeansHome_"+(intI + 1);
													intRequest = 10000 + intI;
													fnViewJustmeansAccountFeed(Base64.encode(strAccountId),strDivId,1,intRequest);
												}
											};
	ajaxObjects[32].runAJAX();
}




/*
	VIEW ALL JUSTMEANS ACCOUNT IN ALL TAB [TAB ALL] [JUSTMEANS]
*/
function fnViewAllJustmeansAc(objJustmeansTab) {
	document.getElementById('id_subtab_operation').style.display="none";
	fnToggleSubAccountTabs(objJustmeansTab.id);
	intJustmeansUpdatePage = 1;
	strJustmeansUpdateDiv = "id_Justmeans_Container";	
	//document.getElementById(strJustmeansUpdateDiv).className = "";
	//document.getElementById(strJustmeansUpdateDiv).style.height = "";
	fnViewAllJustmeansAccount(objJustmeansTab.getAttribute("account"), objJustmeansTab);
	fnEnableSubAccountTabs();
}



function fnViewJustmeansUpdates(strJustmeansId,objJustmeansTab)
{
	strTabType  = objJustmeansTab.getAttribute("tabtype");
	strTabValue = objJustmeansTab.getAttribute("tabvalue");
	intJMUserId = objJustmeansTab.getAttribute("jmid");
	
	document.getElementById(strJustmeansUpdateDiv).innerHTML = strLoadingHtml;
	ajaxObjects[16] = new sack();
	ajaxObjects[16].PostParam = "&account="+strJustmeansId+"&action="+strTabType+"&actionvalue="+strTabValue+"&page="+intJustmeansUpdatePage+"&jmac=" + intJMUserId;
	ajaxObjects[16].requestFile = sitename+"/listjustmeansupdates&mode=ajax&ajax_action=getjustmeansupdates";
	ajaxObjects[16].onCompletion = function(){
													document.getElementById(strJustmeansUpdateDiv).innerHTML = ajaxObjects[16].response;
													if(strTabValue != "") document.getElementById('id_subtab_operation').style.display="";
													//id_subtab_operation
													fnEnableSubAccountTabs();
											 };
	ajaxObjects[16].runAJAX();
}

function fnListJustmeansUpdates(strAccountId)
{
	intJustmeansFeedPage = 1;
	intJustmeansDirectMessagePage = 1;
	intJustmeansMentionsPage = 1;

	strJustmeansFeedDiv = "id_JustmeansHome";
	strJustmeansDirectMessageDiv = "id_JustmeansMessages";
	strJustmeansMentionsDiv = "id_JustmeansMentions";
	
	document.getElementById(strJustmeansFeedDiv).innerHTML = strLoadingHtml;
	document.getElementById(strJustmeansDirectMessageDiv).innerHTML = strLoadingHtml;
	document.getElementById(strJustmeansMentionsDiv).innerHTML = strLoadingHtml;

	fnListJustmeansFeedMessages(strAccountId);
	//fnListTwitterMentionMessages(strAccountId);
	//fnListTwitterDirectMessages(strAccountId);
	//intTwitterResponse = 2;
}

function fnListJustmeansFeedMessages(strAccountId)
{
	objFeedContainer = fnGetContainerDiv(document.getElementById(strJustmeansFeedDiv).parentNode.id, strJustmeansFeedDiv);
	if (intJustmeansFeedPage == 1)
		objFeedContainer.innerHTML = strLoadingHtml;
	ajaxObjects[13] = new sack();
	ajaxObjects[13].PostParam = "&account="+strAccountId+"&type=feed&page="+intJustmeansFeedPage+"&all="+0;
	ajaxObjects[13].requestFile = sitename+"/listjustmeansupdates&mode=ajax&ajax_action=getjustmeansupdates";
	ajaxObjects[13].onCompletion = function(){
													if (intTwitterFeedPage == 1)
													{
														objFeedContainer.innerHTML = ajaxObjects[13].response;
														fnListTwitterMentionMessages(strAccountId)
													}
													else
													{
														arrChildElement = objFeedContainer.getElementsByTagName("DIV");
														intLastElementIndex = (arrChildElement.length - 1);
														objLastChild = arrChildElement[intLastElementIndex];
														objFeedContainer.removeChild(objLastChild.parentNode);
														objFeedContainer.innerHTML = objFeedContainer.innerHTML + ajaxObjects[13].response;
													}
													intTwitterResponse = intTwitterResponse + 1;
													fnAfterTwitterResponse();
													return true;
											};
	ajaxObjects[13].runAJAX();
}


function fnAddJustmeansTab(objJustmeansTab)
{
	document.getElementById('id_subtab_operation').style.display="none";
	fnToggleSubAccountTabs(objJustmeansTab.id);
	document.getElementById("id_Justmeans_Container").innerHTML = strLoadingHtml;
	
	ajaxObjects[21] = new sack();
	ajaxObjects[21].requestFile = sitename+"/listjustmeansupdates&mode=ajax&ajax_action=addjustmeanstab";
	ajaxObjects[21].onCompletion = function(){
													document.getElementById("id_Justmeans_Container").innerHTML = ajaxObjects[21].response;
													fnEnableSubAccountTabs();
											 };
	ajaxObjects[21].runAJAX();
}

function fnEditJustmeansTab()
{
	var intTabId = 0;
	var objJustmeansTab = "";
	var boolObjFound = false;
	do{
		try {
			objJustmeansTab = document.getElementById("id_Justmeans_Tab_" + intTabId);
			//if(objJustmeansTab.className == "active") boolObjFound = true;
			if(HasClassName(objJustmeansTab,"active")) boolObjFound = true;
		} catch(e) { }
		intTabId++;
	} while(boolObjFound == false)
	objJustmeansTab.className = "";
	var strTabId = objJustmeansTab.getAttribute("tabid");
	
	fnToggleSubAccountTabs(objJustmeansTab.id);
	document.getElementById("id_Justmeans_Container").innerHTML = strLoadingHtml;
	ajaxObjects[21] = new sack();
	ajaxObjects[21].requestFile = sitename+"/listjustmeansupdates&mode=ajax&ajax_action=editjustmeanstab&tabvalue=" + strTabId;
	ajaxObjects[21].onCompletion = function(){
													document.getElementById("id_Justmeans_Container").innerHTML = ajaxObjects[21].response;
													fnEnableSubAccountTabs();
											 };
	ajaxObjects[21].runAJAX();
}

function fnRemoveJustmeansTab(removetab)
{
	
	var intTabId = 0;
	var objJustmeansTab = "";
	var boolObjFound = false;
	do{
		try {
			objJustmeansTab = document.getElementById("id_Justmeans_Tab_" + intTabId);
			//if(objJustmeansTab.className == "active") boolObjFound = true;
			if(HasClassName(objJustmeansTab,"active")) boolObjFound = true;
		} catch(e) { }
		intTabId++;
	} while(boolObjFound == false)
	
	
	
	if(removetab) {
		ajax_hideTooltip();
		objJustmeansTab.className = "";
		var strTabId = objJustmeansTab.getAttribute("tabid");
		fnToggleSubAccountTabs(objJustmeansTab.id);
		ajaxObjects[21] = new sack();
		ajaxObjects[21].requestFile = sitename+"/listjustmeansupdates&mode=ajax&ajax_action=removejustmeanstab&tabid=" + strTabId;
		ajaxObjects[21].onCompletion = function(){
													arrMenuTabs = document.getElementById("id_Account_Tab").getElementsByTagName("LI");
													fnShowJustmeansAccount(arrMenuTabs[0], "", "");													
												 };
		ajaxObjects[21].runAJAX();
	} else {
		ajax_showTooltip('id_remove_sub_tab',objJustmeansTab,220,40);
		return false;
	}
}


function fnAddJustmeansNewTabData(intAccountId, intSubTabId)
{
	lightbox = 0;
	errordiv = "";
	showerrorinlable = 1;
	
	if (fnValidateForm(document.getElementById("id_frmAddJustmeansTab")) == false)
		return false;
		
	document.getElementById("id_EnterButton").style.display = "none";
	document.getElementById("id_LoadingButton").style.display = "";

	strTabName = Base64.encode(document.getElementById("id_TabName").value);
	strTabKeyword = Base64.encode(document.getElementById("id_TabKeyword").value);
	strTabIdParam = "";
	var intTabId = 0;
	var strActionName = "addjustmeanstabdata";
	if(document.getElementById('id_edit_justmeans_tab').value != "") { 
		intTabId = document.getElementById('id_edit_justmeans_tab').value;
		strActionName = "editjustmeanstabdata";
	}

	ajaxObjects[22] = new sack();
	ajaxObjects[22].PostParam = "&tabname="+strTabName+"&tabvalue="+strTabKeyword+"&tabid="+intTabId;
	ajaxObjects[22].requestFile = sitename+"/listjustmeansupdates&mode=ajax&ajax_action="+strActionName;
	ajaxObjects[22].onCompletion = function(){
													strResponse = ajaxObjects[22].response;
													arrResponse = strResponse.split("|");
													
													if(arrResponse[0] == "error") {
														document.getElementById("id_ErrorMessage").style.display = "";
														document.getElementById("id_ErrorMessage").innerHTML = arrResponse[1];
														
													} else {
														
														document.getElementById("id_ErrorMessage").style.display = "none";
														
														
														if(strActionName == "editjustmeanstabdata") {
															var arrSubMenuTabs = document.getElementById("id_Sub_Account_Tab").getElementsByTagName("LI");
															var objTab = "";
															for(var i=0; i<arrMenuTabs.length; i++) {
																objTab = arrMenuTabs[i];
																//var intSelected = document.getElementById('selected_parent_account').value;
																if(objTab.getAttribute("tabid") == intTabId) {
																	objTab.setAttribute("tabvalue", strTabKeyword);
																	break;
																}
															}
															fnToggleJustmeansAccount(objTab);
														} else {
															arrMenuTabs = document.getElementById("id_Account_Tab").getElementsByTagName("LI");
															fnShowJustmeansAccount(arrMenuTabs[0], arrResponse[1], "");														
														}
													}
											 };
	ajaxObjects[22].runAJAX();
	
	return false;
}

function fnViewMoreJustmeansUpdates(objViewMoreDiv)
{
	strJustmeansUpdateDiv = "id_ViewMore_"+intJustmeansUpdatePage;
	intJustmeansUpdatePage = intJustmeansUpdatePage + 1;
	objViewMoreDiv.style.display = "none";
	fnViewJustmeansUpdates(objViewMoreDiv.getAttribute("account"),objViewMoreDiv);
}

function fnSendUpdateToOtherNetwork(intUpdate) {
	var optiondiv = document.getElementById('id_update_option_' + intUpdate);
	var strUpdate = document.getElementById('id_update_content_' + intUpdate).innerHTML;
	var plainText = strUpdate.replace(/<\/?[^>]+(>|$)/g, ""); 
	document.getElementById('id_txtWhatAreUWorking').value = plainText;
	document.getElementById('id_txtWhatAreUWorking').style.color = "#000000";
	optiondiv.style.display = "none";
	fnScrollWindow('bblTabsBlue');
}


function fnGetTop(inputObj)
 {  
   var returnValue = inputObj.offsetTop;
   while((inputObj = inputObj.offsetParent) != null){
    if(inputObj.tagName!='HTML'){
     returnValue += inputObj.offsetTop;
     if(document.all)returnValue+=inputObj.clientTop;
    }
   } 
   return returnValue;
 }
 
function fnGetLeft(inputObj)
 {   
   var returnValue = inputObj.offsetLeft;
   while((inputObj = inputObj.offsetParent) != null){
    if(inputObj.tagName!='HTML'){
     returnValue += inputObj.offsetLeft;
     if(document.all)returnValue+=inputObj.clientLeft;
    }
   }
   return returnValue;
 }
 

function fnShowOperationDiv(intUpdate, obj, intExtraLeft, intExtraTop) {
	var optiondiv = document.getElementById('id_update_option_' + intUpdate);
	if(optiondiv.style.display == "none") {
		optiondiv.style.display = "";
		
		if(intExtraLeft) intExtraLeft = parseInt(intExtraLeft, 10); else intExtraLeft = 0;
		if(intExtraTop) intExtraTop = parseInt(intExtraTop, 10); else intExtraTop = 0;	
		
		optiondiv.style.left = (parseInt(fnGetLeft(obj),10) + intExtraLeft) + "px";
		optiondiv.style.top =  (parseInt(fnGetTop(obj),10) + intExtraTop) + "px";		
	} else {
		optiondiv.style.display = "none";
	}
}


/*----------------------------- FUNCTIONS FOR TWITTER TAB ----------------------------------*/
var intTwitterFeedPage;
var strTwitterFeedParentDiv;
var intTwitterDirectMessagePage;
var intTwitterMentionsPage;
var strTwitterFeedDiv;
var strTwitterDirectMessageDiv;
var strTwitterMentionsDiv;
var strTwitterTabDiv;
var intTwitterTabPage;
var intTwitterResponse = 0;


function fnSetSocialNetworkAccounts(networklist) {
	if(document.getElementById("id_ManageAccountForm") && networklist) {
		document.getElementById("id_ManageAccountForm").innerHTML = strLoadingHtml;
	}
	document.getElementById('id_social_sites_account_block').innerHTML = strSmallLoadingHtml;
	ajaxObjects[32] = new sack();
	ajaxObjects[32].requestFile = sitename+"/addsocialnetwork&mode=ajax&ajax_action=getsocialnetworkaccounts";
	ajaxObjects[32].onCompletion = function(){
												strResponse = ajaxObjects[32].response;
												try {
													document.body.removeChild(document.getElementById('id_SeeMore'));
												} catch(e) { }
												//document.getElementById('id_social_sites_account_block').innerHTML = strResponse;
												document.getElementById('id_all_account_list').innerHTML = strResponse;
												if(networklist) fnToggleAccountMenu(4);
										    };
	ajaxObjects[32].runAJAX();	
}

function fnValidateAddJustmeans()
{
	// VALIDE FORM INPUTS
	lightbox = 0;
	errordiv = "";
	showerrorinlable = 1;
	
	if (fnValidateForm(document.getElementById("id_fnJustmeansAction")) == false)
		return false;
		
	document.getElementById("id_EnterButton").style.display = "none";
	document.getElementById("id_LoadingButton").style.display = "";
	
	strJustmeansAccountName = Base64.encode(document.getElementById("id_txtJustmeansAcName").value);
	strJustmeansLogin 		= Base64.encode(document.getElementById("id_txtJustmeansLogin").value);
	strJustmeansPassword 	= Base64.encode(document.getElementById("id_txtJustmeansPassword").value);
	
	ajaxObjects[0] = new sack();
	ajaxObjects[0].PostParam = "&login="+strJustmeansLogin+"&password="+strJustmeansPassword+"&accountname="+strJustmeansAccountName;
	ajaxObjects[0].requestFile = sitename+"/addsocialnetwork&mode=ajax&ajax_action=addjustmeansaccount";
	ajaxObjects[0].onCompletion = function(){
												try { Lightbox.hideBox(); } catch(e) { }	
												strResponse = ajaxObjects[0].response;
												arrResponse = strResponse.split("|");
												
												document.getElementById("id_EnterButton").style.display = "";
												document.getElementById("id_LoadingButton").style.display = "none";
												
												if (arrResponse[0] == "success")
												{
													strOperation = "add";
													fnSetParentTabs("jm");
													fnSetSocialNetworkAccounts(1);
													document.getElementById("id_JustmeansErrorMessage").innerHTML = "";
													document.getElementById("id_JustmeansErrorMessage").style.display = "none";
													try{ Lightbox.hideBox(); } catch(e) { } 
													if(arrResponse[2]) {
														
														arrMenuTabs = document.getElementById("id_Account_Tab").getElementsByTagName("LI");
														
														fnShowJustmeansAccount(arrMenuTabs[0], "", arrResponse[2]);	
													}
												}
												else
												{
													document.getElementById("id_JustmeansErrorMessage").innerHTML = arrResponse[1];
													document.getElementById("id_JustmeansErrorMessage").style.display = "";
												}
										    };
	ajaxObjects[0].runAJAX();
}

function fnGetMainAccountId(mainaccounttype) {
	var arrMenuTabs = document.getElementById("id_Account_Tab").getElementsByTagName("LI");
	for(var i=0; i<arrMenuTabs.length; i++) {
		if(arrMenuTabs[i].getAttribute("tabname") == mainaccounttype) {
			return  arrMenuTabs[i];
		}
	}
	return arrMenuTabs[0];
}


function fnValidateDelicious()
{
	// VALIDE FORM INPUTS
	lightbox = 0;
	errordiv = "";
	showerrorinlable = 1;
	
	if (fnValidateForm(document.getElementById("id_fnDeliciousAction")) == false)
		return false;
		
	document.getElementById("id_EnterButton").style.display = "none";
	document.getElementById("id_LoadingButton").style.display = "";
		
	strDeliciousLogin 		= Base64.encode(document.getElementById("id_txtDeliciousLogin").value);
	strDeliciousPassword 	= Base64.encode(document.getElementById("id_txtDeliciousPassword").value);
	strDeliciousAccountName = Base64.encode(document.getElementById("id_txtDeliciousAcName").value);
		
	ajaxObjects[0] = new sack();
	ajaxObjects[0].PostParam = "&login="+strDeliciousLogin+"&password="+strDeliciousPassword+"&accountname="+strDeliciousAccountName;
	ajaxObjects[0].requestFile = sitename+"/addsocialnetwork&mode=ajax&ajax_action=adddeliciousaccount";
	ajaxObjects[0].onCompletion = function(){
												try { Lightbox.hideBox(); } catch(e) {}	
												strResponse = ajaxObjects[0].response;
												arrResponse = strResponse.split("|");
												
												document.getElementById("id_EnterButton").style.display = "";
												document.getElementById("id_LoadingButton").style.display = "none";
												
												if (arrResponse[0] == "success")
												{
													document.getElementById("id_DeliciousErrorMessage").innerHTML = "";
													document.getElementById("id_DeliciousErrorMessage").style.display = "none";
													try{ Lightbox.hideBox(); } catch(e) { } 
													strOperation = "Add";
													fnSetParentTabs("list");
													fnSetSocialNetworkAccounts(1);
												}
												else
												{
													document.getElementById("id_DeliciousErrorMessage").innerHTML = arrResponse[1];
													document.getElementById("id_DeliciousErrorMessage").style.display = "";
												}
										    };
	ajaxObjects[0].runAJAX();
}

function fnValidateTumbler()
{
	// VALIDE FORM INPUTS
	lightbox = 0;
	errordiv = "";
	showerrorinlable = 1;
	
	if (fnValidateForm(document.getElementById("id_fnTumblerAction")) == false)
		return false;
		
	document.getElementById("id_EnterButton").style.display = "none";
	document.getElementById("id_LoadingButton").style.display = "";
		
	strTumblerLogin 	  = Base64.encode(document.getElementById("id_txtTumblerLogin").value);
	strTumblerPassword 	  = Base64.encode(document.getElementById("id_txtTumblerPassword").value);
	strTumblerAccountName = Base64.encode(document.getElementById("id_txtTumblerAcName").value);
		
	ajaxObjects[0] = new sack();
	ajaxObjects[0].PostParam = "&login="+strTumblerLogin+"&password="+strTumblerPassword+"&accountname="+strTumblerAccountName;
	ajaxObjects[0].requestFile = sitename+"/addsocialnetwork&mode=ajax&ajax_action=addtumbleraccount";
	ajaxObjects[0].onCompletion = function(){
												try { Lightbox.hideBox(); } catch(e) { }		
												strResponse = ajaxObjects[0].response;
												arrResponse = strResponse.split("|");
												
												document.getElementById("id_EnterButton").style.display = "";
												document.getElementById("id_LoadingButton").style.display = "none";
												
												if (arrResponse[0] == "success")
												{
													
													document.getElementById("id_TumblerErrorMessage").innerHTML = "";
													document.getElementById("id_TumblerErrorMessage").style.display = "none";
													try{ Lightbox.hideBox(); } catch(e) { } 
													fnSetSocialNetworkAccounts(1);
													
												}
												else
												{
													document.getElementById("id_TumblerErrorMessage").innerHTML = arrResponse[1];
													document.getElementById("id_TumblerErrorMessage").style.display = "";
												}
										    };
	ajaxObjects[0].runAJAX();
}

function fnShowSelectedTwitterAccount()
{
	var objTwitterTab = null;
	arrAccountTabs = document.getElementById("id_Account_Tab").getElementsByTagName("LI");
	
	for (intI = 0; intI < arrAccountTabs.length; intI++)
	{
		if (arrAccountTabs[intI].getAttribute("tabname") == "tw")
		{
			objTwitterTab = arrAccountTabs[intI];
			objTwitterTab.style.display = "";
			break;
		}
	}
	
	if (objTwitterTab == null)
	{
		fnViewMainNavigationTabs("tw");
	}
	else
	{
		fnShowTwitterAccount(objTwitterTab);
	}
}
 
function fnShowSelectedLinkedInAccount()
{
	var objLinkedInTab = null;
	/*arrAccountTabs = document.getElementById("id_Account_Tab").getElementsByTagName("LI");
	
	for (intI = 0; intI < arrAccountTabs.length; intI++)
	{
		if (arrAccountTabs[intI].getAttribute("tabname") == "ln")
		{
			objLinkedInTab = arrAccountTabs[intI];
			objTwitterTab.style.display = "";
			break;
		}
	}
	if (objLinkedInTab == null)
	{*/
		//fnViewMainNavigationTabs("ln");
	/*}
	else
	{*/
		fnShowLinkedinAccount(document.getElementById('id_ln'));
	//}
}

/*twitter changed by sagar*/


/***************************************************************/
/* ADD NEW TWITTER SUB TAB */
/***************************************************************/

/***********************************************/
/* INITIAT OBJECTS */
/***********************************************/

var objTwitterSubTabContainer = "";
var objTwitterHtmlContainer = "";
var objSocialMediaListContainer= "";

function fnInitObject() {
	if(!objSocialMediaListContainer) {
		try {
			objSocialMediaListContainer = document.getElementById("id_SocialMediaSite_Container");
		} catch(e) { }
	}
	if(!objTwitterSubTabContainer) {
		try {
			objTwitterSubTabContainer = document.getElementById('id_Sub_Account_Tab');
		} catch(e) { }
	}
	if(!objTwitterHtmlContainer) {
		try {
			objTwitterHtmlContainer = document.getElementById("id_Twitter_Tab_Container");
		} catch(e) { }
	}
}


/***********************************************/
/* SET TWITTER ACCOUNT SUB TABS */
/***********************************************/
function fnHideOptionDiv(strUpdateId) {
	var optiondiv = document.getElementById('id_update_option_' + strUpdateId);
	optiondiv.style.display = "none";
	fnScrollWindow('bblTabsBlue');
}


function fnRetweetOtherNetwork(strUpdateDivId, strTweetId, strAccountId) {
	if(!strUpdateDivId || !strTweetId || !strAccountId) return false;
	objUpdateInfo = document.getElementById("id_Update_Info_" + strUpdateDivId);
	strUpdateText = objUpdateInfo.getAttribute("text");
	strAccountId  = objUpdateInfo.getAttribute("account");
	fnConfirmRetweetRequest(strUpdateDivId, strTweetId, strAccountId, 0);
}

function fnConfirmRetweetRequest(strUpdateDivId, strTweetId, strAccountId, verified) {
	if(!strUpdateDivId || !strTweetId || !strAccountId) return false;
	if(parseInt(verified, 10)) {
		fnHideOptionDiv(strUpdateDivId);
		try { ajax_hideTooltip(); } catch(e) { }
		ajaxObjects[25] = new sack();
		ajaxObjects[25].PostParam = "&account="+strAccountId+"&tweet=" + strTweetId;
		ajaxObjects[25].requestFile = sitename+"/listtwitterupdates&mode=ajax&ajax_action=retweetupdate";
		ajaxObjects[25].onCompletion = function(){
													
													strResponse = ajaxObjects[25].response;
													arrResponse = strResponse.split("|");
													fnCheckAccounts("none");
													if (arrResponse[0] == "error") {
														var strErrorMessage = "Error while sending update";
														if(arrResponse[1]) strErrorMessage = arrResponse[1];
														fnShowMsgDiv(strErrorMessage, "");
													} else {
														fnShowMsgDiv("Message sent", "");
														fnLoadAddUpdateBacisSetting();
														fnCheckAccounts("none");
													}
										};
		ajaxObjects[25].runAJAX();
	} else {
		verified = 1;
		document.getElementById('id_retweet_confirm_ok').setAttribute('onClick', "fnConfirmRetweetRequest('" + strUpdateDivId + "', '" + strTweetId + "', '" + strAccountId + "', '" + verified + "');" );
		ajax_showTooltip("id_confirm_retweet", document.getElementById('id_re_tweet_' + strUpdateDivId), 200, 38);
	}
}

function fnPublishToOtherNetwork(strUpdateDivId)
{
	fnHideOptionDiv(strUpdateDivId);
	objUpdateInfo = document.getElementById("id_Update_Info_"+strUpdateDivId);
	strUpdateText = objUpdateInfo.getAttribute("text");
	strAccountId  = objUpdateInfo.getAttribute("account");
	fnUpdateSendMessageBox(Base64.decode(strUpdateText), strAccountId);
}

function fnReplyTweet(strUpdateDivId)
{
	fnHideOptionDiv(strUpdateDivId);
	objUpdateInfo = document.getElementById("id_Update_Info_"+strUpdateDivId);
	
	strUpdateText = "@"+Base64.decode(objUpdateInfo.getAttribute("username"))+" ";
	strAccountId  = objUpdateInfo.getAttribute("account");
	strReplyMsgId = objUpdateInfo.getAttribute("update");

	document.getElementById("id_hdnReplyToId").value = Base64.decode(strReplyMsgId);
	
	var objTextBox = document.getElementById("id_txtWhatAreUWorking");
	objTextBox.style.color='#000000';

	fnUpdateReplyMessageBox(strUpdateText, strAccountId);
}

function fnViewAddUserToList(strUpdateDivId)
{
	fnHideOptionDiv(strUpdateDivId);
	objUpdateInfo = document.getElementById("id_Update_Info_"+strUpdateDivId);
	
	strAccountId  = objUpdateInfo.getAttribute("account");
	strUpdateUser = objUpdateInfo.getAttribute("userid");
	
	Lightbox.enmStopResetSession = 0;
	Lightbox.showBoxByID('id_Twitter_LightBox',400,200);
	document.getElementById("id_Twitter_LightBox").innerHTML = strLoadingHtml;
	
	ajaxObjects[25] = new sack();
	ajaxObjects[25].PostParam = "&account="+strAccountId+"&user="+strUpdateUser;
	ajaxObjects[25].requestFile = sitename+"/listtwitterupdates&mode=ajax&ajax_action=viewtwitterlistbox";
	ajaxObjects[25].onCompletion = function(){
													document.getElementById("id_Twitter_LightBox").innerHTML = ajaxObjects[25].response;
										    };
	ajaxObjects[25].runAJAX();
}

function fnAddUserToList(strUpdateDivId)
{
	try{ fnHideOptionDiv(strUpdateDivId); } catch(e) { }
	document.getElementById("id_Loading_Button").style.display = "";
	document.getElementById("id_Submit_Button").style.display = "none";
	
	strListName 	= document.getElementById("id_optTwitterList").value;
	strUserId 		= document.getElementById("id_hdnUserId").value;
	strAccountId 	= document.getElementById("id_hdnAccountId").value;
	
	ajaxObjects[26] = new sack();
	ajaxObjects[26].PostParam = "&account="+strAccountId+"&user="+strUserId+"&list="+Base64.encode(strListName);
	ajaxObjects[26].requestFile = sitename+"/listtwitterupdates&mode=ajax&ajax_action=addtwitterusertolist";
	ajaxObjects[26].onCompletion = function(){
													Lightbox.hideBox()
													strResponse = ajaxObjects[26].response;
													arrResponse = strResponse.split("|");
													document.getElementById("id_TwitterSuccess").style.display = "";
													document.getElementById("id_TwitterSuccess").innerHTML = arrResponse[1];
													if (arrResponse[0] == "error")
													{
														document.getElementById("id_TwitterSuccess").className = "errormessage";
														
														document.getElementById("id_Loading_Button").style.display = "none";
														document.getElementById("id_Submit_Button").style.display = "";
													}
													else
													{
														document.getElementById("id_TwitterSuccess").className = "success";
													}
													
													setTimeout("fnHideTwitterSuccess();", 1000);
										    };
	ajaxObjects[26].runAJAX();
}

function fnHideTwitterSuccess() {
	document.getElementById('id_TwitterSuccess').innerHTML='';
}

function fnSendTwitterMessage(strUpdateDivId)
{
	fnHideOptionDiv(strUpdateDivId);
	objUpdateInfo = document.getElementById("id_Update_Info_"+strUpdateDivId);
	
	strUpdateText = "d "+Base64.decode(objUpdateInfo.getAttribute("username"));
	strAccountId  = objUpdateInfo.getAttribute("account");
	strTwitterUserId = objUpdateInfo.getAttribute("userid");

	fnUpdateReplyMessageBox(strUpdateText, strAccountId);
}


	function fnScrollWindow(strObjectId, intPosition)
	{	
		arrDivPosition = fnFindPos(document.getElementById(strObjectId));
		if(intPosition)
		{
			window.scroll(0, ( intPosition + arrDivPosition[1] ) );
		}
		else
		{
			window.scroll(0, arrDivPosition[1]);
		}
		//parent.window.scroll(0,900);
	}
	
	function fnFindPos(obj)
	{	
		var curleft = curtop = 0;  
		if (obj.offsetParent)
		{  
			curleft = obj.offsetLeft  
			curtop = obj.offsetTop  
			while (obj = obj.offsetParent)
			{  
				curleft += obj.offsetLeft  
				curtop += obj.offsetTop  
			}  
		}  
		return Array(curleft, curtop);
	}
	
	
	function fnViewProfile(intUserId, intUpdate) {
		ajaxObjects[11] = new sack();
		ajaxObjects[11].PostParam = "&user="+intUserId;
		ajaxObjects[11].requestFile = sitename+"/listjustmeansupdates&mode=ajax&ajax_action=getuserprofile";
		ajaxObjects[11].onCompletion = function(){
													try {
														document.getElementById("id_update_option_" + intUpdate).style.display = "none";
													} catch(e) {
													}
													document.getElementById('id_profile_html_div').innerHTML = "";
													document.getElementById('id_profile_html_div').innerHTML = Base64.decode(ajaxObjects[11].response);
													Lightbox.enmStopResetSession = 0;
													Lightbox.showBoxByID('id_profile_html_div',400,300);
												};
		ajaxObjects[11].runAJAX();
	}

function fnSendJustmeansMessage(intUpdate, strsendmessagetext)
{
	try {
		document.getElementById("id_update_option_" + intUpdate).style.display = "none";
	} catch(e) {}
			
	strUpdateText = "d "+ strsendmessagetext;
	strAccountId  = 0;
	fnUpdateReplyMessageBox(strUpdateText, strAccountId);
}

function fnValidateRss()
{
	lightbox = 0;
	errordiv = "";
	showerrorinlable = 1;
	document.getElementById('id_txt_feedUrlErr').innerHTML = "";
	//alert(document.getElementById('id_includetxt').checked);return false;
	/*if(document.getElementById('id_includetxt').checked==false && document.getElementById('id_includetxt').value=="")
		document.getElementById('id_includetxt').alt="M-";*/
	
	if(fnValidateForm(document.getElementById('id_frm_addBlog')) == false)
			return false;
	
		
	 document.getElementById('id_frm_addBlog').submit();
}

function fnSetDistributedValue(accno,accval)
{
	if(document.getElementById('id_distribution_'+accno).value)	
		document.getElementById('id_distribution_'+accno).value='';
	else
		document.getElementById('id_distribution_'+accno).value=accval;
	
}

function fnSelectAllccounts(strType,distvalue)
{
	document.getElementById("id_CheckAll").className = "";
	document.getElementById("id_CheckNone").className = "";
	if (strType == "all")
		{
			document.getElementById("id_CheckAll").className = "selected";
			document.getElementById("id_alldistribution").value =distvalue;
		}
	else
		{
			document.getElementById("id_CheckNone").className = "selected";
			document.getElementById("id_alldistribution").value ='';
		}

	for (intI = 1; intI < document.getElementById("id_hdnTotalAccounts").value; intI++)
	{
		if (strType == "all")
		{
			document.getElementById("id_AccountBtn_"+intI).className = "selected";
		}
		else if (strType == "none")
		{
			document.getElementById("id_AccountBtn_"+intI).className = "";
		}
	}
}

function fnShowMsgDiv(strMessage,strDivClass) { 
	if(strDivClass == "") strDivClass = "spamsuccessmessage";
	if(strMessage != "") {   
	   try {
			document.getElementById("searchoptions").style.display='none';   
	   } catch(e) {} 
	   
	   document.getElementById("spam").innerHTML = "<img src='images/ico_delete.gif' align='right' style='vertical-align:top;cursor:pointer;margin-left=900px;' alt='close' title='close' onclick='javascript:fnCloseMsgDiv();' /><br>" + strMessage;
	   document.getElementById("spam").className = strDivClass; //spamerrormessage , spamsuccessmessage
	   $("#spam").slideToggle();
	   setTimeout("fnHideMsgDiv();",5000);    
	}  
 }
 
var intFlag = 0;
 
function fnHideMsgDiv() {  
	if(intFlag == 0) {  
		$("#spam").slideToggle();
		try {
			document.getElementById("searchoptions").style.display="block";
		} catch(e){} 
		document.getElementById("spam").style.display='none';
	}
}
 
function fnCloseMsgDiv() {   
	$("#spam").slideToggle();
	try {
		document.getElementById("searchoptions").style.display="block";
	} catch(e) {} 
	document.getElementById("spam").style.display='none';
	intFlag = 1;    
}




function fnToggleSubAccountTabs(intAccountId)
{
	fnDisableSubAccountTabs();
	arrMenuTabs = document.getElementById("id_Sub_Account_Tab").getElementsByTagName("LI");
	intLastItem = (arrMenuTabs.length - 1);
	for (intTab = 0; intTab < arrMenuTabs.length; intTab++)
	{
		if (intTab == intLastItem)
		{
			
			RemoveClassName(arrMenuTabs[intTab],"active");
			//alert("tab="+intTab+"class="+arrMenuTabs[intTab].className);
			//arrMenuTabs[intTab].className = "";
		}
		else
		{
			RemoveClassName(arrMenuTabs[intTab],"active");
			//alert("tab="+intTab+"class="+arrMenuTabs[intTab].className);
			//arrMenuTabs[intTab].className = "";			
		}
			
			
			
		if (arrMenuTabs[intTab].id.replace(/[^0-9]/g,'') == intAccountId.replace(/[^0-9]/g,''))
		{
			if (arrMenuTabs[intTab].className == "")
			{
				//arrMenuTabs[intTab].className = "active";
				AddClassName(arrMenuTabs[intTab],"active");
			}			
			else
			{
				//arrMenuTabs[intTab].className = arrMenuTabs[intTab].className + " active";
				AddClassName(arrMenuTabs[intTab],"active");
			}
		}
	}
}



// ----------------------------------------------------------------------------
// RemoveClassName
//
// Description : removes a class from the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to remove
//
function RemoveClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // remove array item
            arrList.splice(i, 1);

            // decrement loop counter as we have adjusted the array's contents
            i--;

            }

         }

      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   // there is nothing to remove

   }
// 
// RemoveClassName
//


// AddClassName
//
// Description : adds a class to the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function AddClassName(objElement, strClass, blnMayAlreadyExist)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // if the new class name may already exist in list
      if ( blnMayAlreadyExist )
         {

         // get uppercase class for comparison purposes
         var strClassUpper = strClass.toUpperCase();

         // find all instances and remove them
         for ( var i = 0; i < arrList.length; i++ )
            {

            // if class found
            if ( arrList[i].toUpperCase() == strClassUpper )
               {

               // remove array item
               arrList.splice(i, 1);

               // decrement loop counter as we have adjusted the array's contents
               i--;

               }

            }

         }

      // add the new class to end of list
      arrList[arrList.length] = strClass;

      // add the new class to beginning of list
      //arrList.splice(0, 0, strClass);
      
      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   else
      {

      // assign modified class name attribute      
      objElement.className = strClass;
   
      }

   }
// 
// AddClassName
//


// ----------------------------------------------------------------------------
// HasClassName
//
// Description : returns boolean indicating whether the object has the class name
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function HasClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // we found it
            return true;

            }

         }

      }

   // if we got here then the class name is not there
   return false;

   }
// 
// HasClassName
//

	function fnShowRegistrationLoginForm()
	{
		if(document.getElementById("divRegisterLogin").style.display == "none")
		{
			fnNewRegisterLogin(0,0);
		}
		return false;
	}
