// JavaScript Document
var strTextBoxDefaultValue;
var strShrinkDefalult;
var objTextBox;
var objCharCount;
var intCharCount;
var strStatusMessage;
var objSendButton;
var objLoadingButton;
var isBoxDisplay = true;
var isUploadMediaBoxDisplay = false;
var intProcessCount = 0;
var intCompletedProcessCount = 0;
var strProcessErrorMessage="";
var objCheckProcess;

/******************************************************/
/*     TOGGER SEND UPDATE BOX 						*/
/******************************************************/
function fnToggleSendMessageBox() {
	$("#id_SendMessageBox").slideToggle();
	if (!isBoxDisplay)
	{
		document.getElementById("id_BoxButton").innerHTML = "Open Update Box";
		document.getElementById("id_img_update_box").src = "images/mdc/ico_expand_sml.gif";
		isBoxDisplay = true;
		document.getElementById("uploadLnk").style.display = "none";
		document.getElementById("id_sch_box").style.display = "none";
		if(document.getElementById('uploadLayer'))
			document.getElementById('uploadLayer').style.display = "none";
		document.getElementById('id_img_upload_media_box').src = "images/mdc/ico_expand_sml.gif";
	}
	else
	{
		document.getElementById("id_BoxButton").innerHTML = "Close Update Box";
		document.getElementById("id_img_update_box").src = "images/mdc/ico_collapse_sml.gif";
		isBoxDisplay = false;
		document.getElementById("uploadLnk").style.display = "";
		document.getElementById("id_sch_box").style.display = "";
	}
}

function fnSelectAccount(intAccountId,intselectedacval,isjmac)
{
	var arrInputType1 = null;
	var arrInputType2 = null;
	var isalreadyselected;
	var isseemorealreadyselected;
	
	if(document.getElementById("id_AccountContainer_"+intAccountId))
	{
		arrInputType1 = document.getElementById("id_AccountContainer_" + intAccountId).getElementsByTagName("INPUT");
	}
	
	if(document.getElementById("id_SeeMoreAccountContainer_"+intAccountId)) {
		arrInputType2 = document.getElementById("id_SeeMoreAccountContainer_" + intAccountId).getElementsByTagName("INPUT");
	}
	
	if(arrInputType1) 
	{
		if(arrInputType1[0].checked) 
		{
			if(isjmac==1)
			{
				document.getElementById('id_isjmac').value="";
			}
		
			document.getElementById("id_AccountBtn_"+intAccountId).className = "";
			arrInputType1[0].checked = false;
		} 
		else 
		{
			if(isjmac==1)
			{
				if(document.getElementById('id_isjmac').value!="")
				{
					isalreadyselected=document.getElementById('id_isjmac').value;
					document.getElementById("id_AccountBtn_"+isalreadyselected).className = "";
					document.getElementById("id_AccountContainer_"+isalreadyselected).getElementsByTagName("INPUT")[0].checked = false;
					document.getElementById('id_isjmac').value=intAccountId;
		
				}	
				else
				{
					document.getElementById('id_isjmac').value=intAccountId;
				}
			}
			
			document.getElementById("id_AccountBtn_"+intAccountId).className = "selected";
			arrInputType1[0].checked = true;
		}
	}
	
	if(arrInputType2) 
	{
		if(arrInputType2[0].checked) 
		{
			if(isjmac==1)
			{
				document.getElementById('id_isjmmoreac').value="";
			}
		
		
			document.getElementById("id_SeeMoreAccountBtn_" + intAccountId).className = "";
			arrInputType2[0].checked = false;
		} 
		else 
		{
			if(isjmac==1)
			{
				if(document.getElementById('id_isjmmoreac').value!="")
				{
					isseemorealreadyselected=document.getElementById('id_isjmmoreac').value;
					document.getElementById("id_SeeMoreAccountBtn_"+isseemorealreadyselected).className = "";
					document.getElementById("id_SeeMoreAccountContainer_"+isseemorealreadyselected).getElementsByTagName("INPUT")[0].checked = false;
					document.getElementById('id_isjmmoreac').value=intAccountId;
		
				}	
				else
				{
					document.getElementById('id_isjmmoreac').value=intAccountId;
				}
			}
			
			document.getElementById("id_SeeMoreAccountBtn_"+intAccountId).className = "selected";
			arrInputType2[0].checked = true;
		}
	}
	
	var intSelectAll = true;
	var intI = 0;
	for (intI = 1; intI < document.getElementById("id_hdnTotalAccounts").value; intI++)
	{
		arrInputType1 = null;
		arrInputType2 = null;
		
		if(document.getElementById("id_AccountContainer_"+intI)) {
			arrInputType1 = document.getElementById("id_AccountContainer_"+intI).getElementsByTagName("INPUT");
		}
		
		if(document.getElementById("id_SeeMoreAccountContainer_"+intI)) {
			arrInputType2 = document.getElementById("id_SeeMoreAccountContainer_"+intI).getElementsByTagName("INPUT");
		}
		
		if(arrInputType1 && arrInputType1[0].checked == false) {
			intSelectAll = false;
			break;
		} 
		if(arrInputType2 && arrInputType2[0].checked == false) {
			intSelectAll = false;
			break;
		} 
	}
	
	if (intSelectAll == true) {
		if(document.getElementById("id_CheckAll") && document.getElementById("id_CheckNone"))  {
			document.getElementById("id_CheckAll").className = "selected";
			document.getElementById("id_CheckNone").className = "";
		}
		
		if(document.getElementById("id_SeeMoreCheckAll") && document.getElementById("id_SeeMoreCheckNone")) {
			document.getElementById("id_SeeMoreCheckAll").className = "selected";
			document.getElementById("id_SeeMoreCheckNone").className = "";
		}
	}
	else {
		if(document.getElementById("id_CheckAll") && document.getElementById("id_CheckNone"))  {
			document.getElementById("id_CheckAll").className = "";
			document.getElementById("id_CheckNone").className = "selected";
		}
		
		if(document.getElementById("id_SeeMoreCheckAll") && document.getElementById("id_SeeMoreCheckNone")) {
			document.getElementById("id_SeeMoreCheckAll").className = "";
			document.getElementById("id_SeeMoreCheckNone").className = "selected";
		}
	}
	
}

function fnLoadAddUpdateBacisSetting()
{
	strTextBoxDefaultValue = "Enter your  text message here";
	objTextBox = document.getElementById("id_txtWhatAreUWorking");
	objCharCount = document.getElementById("id_CharCount");
	objSendButton = document.getElementById("btnSent");
	objLoadingButton = document.getElementById("btnLoad");
	intCharCount = 140;
	
	objTextBox.value = strTextBoxDefaultValue;
	objTextBox.style.color='#999999'; 
	//objTextBox.className = "bigTextArea txtGray";
	objTextBox.onfocus = fnSetDefaultValue;
	objTextBox.onblur = fnSetDefaultValue;
	objTextBox.onkeyup = fnSetCharacterCount;
	document.getElementById("id_hdnReplyToId").value = 0;
	
	objCharCount.innerHTML = intCharCount;
	
	objSendButton.onclick = fnSendStatusUpdate;
	
	/*FOR SHRINK URL BUTTON*/
	strShrinkDefalult = "URL too long? Insert here to shrink it.";
	//document.getElementById("txtShrinkUrl").style.color='#999999 !important';
	document.getElementById("txtShrinkUrl").className = "txtDisable";
	document.getElementById("txtShrinkUrl").onfocus = fnSetDefaultShrinkValue;
	document.getElementById("txtShrinkUrl").onblur = fnSetDefaultShrinkValue;	
	document.getElementById("txtShrinkUrl").value = strShrinkDefalult;
	document.getElementById("btnShrinkUrl").onclick = fnAddShrinkUrl;
}

function fnSetDefaultValue()
{
	
	if (objTextBox.value == strTextBoxDefaultValue)
	{
		objTextBox.value = "";
		objTextBox.style.color='#000000';
		objTextBox.style.height = '54px';
		
	}
	else if (objTextBox.value == "")
	{
		objTextBox.value = strTextBoxDefaultValue;
		objTextBox.style.color='#999999'; 
		objTextBox.style.height = '24px';
	}
}

function fnSetDefaultShrinkValue()
{
	if (document.getElementById("txtShrinkUrl").value == strShrinkDefalult)
	{
		document.getElementById("txtShrinkUrl").value = "";
		//document.getElementById("txtShrinkUrl").style.color='#000000 !important';
		document.getElementById("txtShrinkUrl").className = "txtEnable";
	}
	else if (document.getElementById("txtShrinkUrl").value == "")
	{
		document.getElementById("txtShrinkUrl").value = strShrinkDefalult;
		//document.getElementById("txtShrinkUrl").style.color='#999999 !important'; 
		document.getElementById("txtShrinkUrl").className = "txtDisable";
	}
}

function fnSetCharacterCount()
{
	if (objTextBox.value == strTextBoxDefaultValue)
	{
		objCharCount.innerHTML = intCharCount;
		objCharCount.className = "charcount";
	}
	else
	{
		objCharCount.innerHTML = (intCharCount - objTextBox.value.length);
		
		if((intCharCount - objTextBox.value.length) >= 20)
			objCharCount.className = "charcount";
		else if(((intCharCount - objTextBox.value.length) < 20) &&  ((intCharCount - objTextBox.value.length) > 10) )
			objCharCount.className = "charcount20";
		else
			objCharCount.className = "charcountnegative";
			
	}
}

function fnSendStatusUpdate()
{
	if(!intIsLobin) {
		fnNewRegisterLogin(0,0);
		return false;
	}
	arrAllowAccounts = new Array();
	strAllowAccounts = "";
	
	intReplyToAccount  = document.getElementById("id_hdnReplyToId").value;
	
	fnValidateScheduleDate();
	//alert(intScheduleDate);
}

function fnValidateStatusMessage()
{
	strStatusMessage = trim(objTextBox.value);
	if (strStatusMessage == "" || strStatusMessage == strTextBoxDefaultValue)
	{
		ajax_showTooltip("id_BlankMsgError",objSendButton,200,20);
		return false;
	}
	if (!fnCheckWordLengthExeed(strStatusMessage, 50))
	{
		ajax_showTooltip("id_WordLengthExceed",objSendButton,250,50);
		return false;
	}
	if (strStatusMessage.length > intCharCount)
	{
		ajax_showTooltip("id_MsgLengthExceed",objSendButton,250,50);
		return false;
	}
	return true;
}


function fnCheckAccounts(strType)
{
	var objSelectAll1 = null;
	var objSelectNone1 = null;
	var objSelectAll2 = null;
	var objSelectNone2 = null;
	var isJmChk;
	
	try {
		objSelectAll2 = document.getElementById("id_SeeMoreCheckAll");
		objSelectNone2 = document.getElementById("id_SeeMoreCheckNone");
		objSelectAll2.className = "";
		objSelectNone2.className = "";

	} catch(e) {
		objSelectAll2 = null;
		objSelectNone2 = null;
	}

	try 
	{
		objSelectAll1 = document.getElementById("id_CheckAll");
		objSelectNone1 = document.getElementById("id_CheckNone");
		objSelectAll1.className = "";
		objSelectNone1.className = "";
	} 
	catch(e)
	{
		objSelectAll1 = null;
		objSelectNone1 = null;
	}
	
	if (strType == "all") 
	{
		if(objSelectAll2) objSelectAll2.className = "selected";
		if(objSelectAll1) objSelectAll1.className = "selected";
	} 
	else
	{
		if(objSelectNone1) objSelectNone1.className = "selected";
		if(objSelectNone2) objSelectNone2.className = "selected";
	}

	
	
	var intTotalSelectedAccount = document.getElementById("id_hdnTotalAccounts").value;
	for (intI = 1; intI < intTotalSelectedAccount; intI++)
	{
		
			
		var arrInputType1 = null;
		var objAccountButtonType1 = null;
		
		var arrInputType2 = null;
		var objAccountButtonType2 = null;		
		
		try {
			arrInputType1 = document.getElementById("id_AccountContainer_"+intI).getElementsByTagName("INPUT");
			objAccountButtonType1 = document.getElementById("id_AccountBtn_"+intI);
			
		} catch(e) { 
			arrInputType1 = null;
			objAccountButtonType1 = null;
		}
		
		try {
			arrInputType2 = document.getElementById("id_SeeMoreAccountContainer_"+intI).getElementsByTagName("INPUT");
			objAccountButtonType2 = document.getElementById("id_SeeMoreAccountBtn_"+intI);
			
		} catch(e) { 
			arrInputType2 = null;
			objAccountButtonType2 = null;
		}
		
		//code by chaitanya to select only JM AC
		var iscontinue=0;
		if (strType == "all")
		{
			try
			{
				if(arrInputType1[1].getAttribute('jmac')==1)
				{
					if(arrInputType1[1].value!="jm")
					{
						objAccountButtonType1.className = "";
						arrInputType1[0].checked = false;
						iscontinue=1; 
					}
					else
					{
						document.getElementById('id_isjmac').value=1;
					}
				}
			}
			catch(e) 
			{ 
				arrInputType1 = null;
				objAccountButtonType1 = null;
			}
			
			try
			{
				if(arrInputType2[1].getAttribute('jmmoreac')==1)
				{	
					if(arrInputType2[1].value!="jm")
					{	
						objAccountButtonType2.className = "";
						arrInputType2[0].checked = false;
						iscontinue=1;
					}
					else
					{
						document.getElementById('id_isjmmoreac').value=1;
					}
				}
			}
			catch(e) 
			{ 
				arrInputType2 = null;
				objAccountButtonType2 = null;
			}
		}
		if(iscontinue==1)
		continue;
		//code by chaitanya to select only JM AC
		
		if (strType == "all")
		{
			if(objAccountButtonType1 && arrInputType1) 
			{
				objAccountButtonType1.className = "selected";
				arrInputType1[0].checked = true;
			}
			if(objAccountButtonType2 && arrInputType2)
			{
				objAccountButtonType2.className = "selected";
				arrInputType2[0].checked = true;
			}
		}
		else if (strType == "none")
		{
			if(objAccountButtonType1 && arrInputType1) {
				objAccountButtonType1.className = "";
				arrInputType1[0].checked = false;
			}
			if(objAccountButtonType2 && arrInputType2) {
				objAccountButtonType2.className = "";
				arrInputType2[0].checked = false;
			}
		}
	}
}

function fnSeeMoreCheckAccountsSubmit()
{
	Lightbox.hideBox();
}

function fnUpdateSendMessageBox(strMessageText, strAccountId)
{
	fnLoadAddUpdateBacisSetting();
	objTextBox.value = strMessageText;
	objTextBox.style.color='#000000';
	objTextBox.style.height = '54px';
	intAccountId = Base64.decode(strAccountId);
	for (intI = 1; intI < document.getElementById("id_hdnTotalAccounts").value; intI++)
	{
		arrInputType = document.getElementById("id_AccountContainer_"+intI).getElementsByTagName("INPUT");
		try{
			arrSeeMoreInputType = document.getElementById("id_SeeMoreAccountContainer_"+intI).getElementsByTagName("INPUT");
		}
		catch (e)
		{ }

		if (arrInputType[1].value == intAccountId)
		{
			arrInputType[0].checked = false;
			document.getElementById("id_AccountBtn_"+intI).className = "";
			try{
				arrSeeMoreInputType[0].checked = false;
				document.getElementById("id_SeeMoreAccountBtn_"+intI).className = "";
			}
			catch (e)
			{ }
		}
		else
		{
			arrInputType[0].checked = true;
			document.getElementById("id_AccountBtn_"+intI).className = "selected";
			try{
				arrSeeMoreInputType[0].checked = true;
				document.getElementById("id_SeeMoreAccountBtn_"+intI).className = "selected";
			}
			catch (e)
			{ }
		}
	}
}

function fnUpdateReplyMessageBox(strMessageText, strAccountId)
{
	fnScrollWindow("id_CharCount");
	objTextBox.value = strMessageText;
	objTextBox.focus();
	//objTextBox.className = "bigTextArea";
	objTextBox.style.height = '54px';
	intAccountId = Base64.decode(strAccountId);
	for (intI = 1; intI < document.getElementById("id_hdnTotalAccounts").value; intI++)
	{
		arrInputType = document.getElementById("id_AccountContainer_"+intI).getElementsByTagName("INPUT");
		try{
			arrSeeMoreInputType = document.getElementById("id_SeeMoreAccountContainer_"+intI).getElementsByTagName("INPUT");
		}
		catch (e)
		{ }

		if (arrInputType[1].value == intAccountId)
		{
			document.getElementById("id_AccountBtn_"+intI).className = "selected";
			arrInputType[0].checked = true;
			try{
				document.getElementById("id_SeeMoreAccountBtn_"+intI).className = "selected";
				arrSeeMoreInputType[0].checked = true;
			}
			catch (e)
			{ }
		}
		else
		{
			document.getElementById("id_AccountBtn_"+intI).className = "";
			arrInputType[0].checked = false;
			try{
				document.getElementById("id_SeeMoreAccountBtn_"+intI).className = "";
				arrSeeMoreInputType[0].checked = false;
			}
			catch (e)
			{ }
		}
	}
}

function fnAddShrinkUrl()
{
	if(!intIsLobin) {
		fnNewRegisterLogin(0,0);
		return false;
	}

	strShrinkValue = document.getElementById("txtShrinkUrl").value;

	if (strShrinkValue == strShrinkDefalult)
	{
		document.getElementById("id_ShrinkError").innerHTML = "Please enter URL to shrink.";
		ajax_showTooltip("id_ShrinkError",document.getElementById("btnShrinkUrl"),150,20);
		return false;
	}
	
	document.getElementById("btnShrinkUrl").style.display = "none";
	document.getElementById("btnShrinkLoad").style.display = "";
	
	ajaxObjects[201] = new sack();
	ajaxObjects[201].PostParam = "&shrinkurl="+Base64.encode(strShrinkValue);
	ajaxObjects[201].requestFile = sitename+"/managesocialmedianetwork&mode=ajax&ajax_action=shrinkurl";
	ajaxObjects[201].onCompletion = function(){
													document.getElementById("btnShrinkUrl").style.display = "";
													document.getElementById("btnShrinkLoad").style.display = "none";
													strResponse = ajaxObjects[201].response;
													arrResponse = strResponse.split(" | ");
													if (arrResponse[0] == "error")
													{
														document.getElementById("id_ShrinkError").innerHTML = arrResponse[1];
														ajax_showTooltip("id_ShrinkError",document.getElementById("btnShrinkUrl"),150,20);
														return false;
													}
													else
													{
														document.getElementById("txtShrinkUrl").value = strShrinkDefalult;
														//document.getElementById("txtShrinkUrl").style.color='#999999  !important'; 
														document.getElementById("txtShrinkUrl").className = "txtDisable";
														if (strTextBoxDefaultValue == objTextBox.value) {
															objTextBox.value = arrResponse[1];
															fnSetCharacterCount();
															objTextBox.style.color='#000000  !important';															
														}
														else {
															objTextBox.value = objTextBox.value + " " + arrResponse[1];
															fnSetCharacterCount();
															objTextBox.style.color='#000000  !important';															
														}
													}
								 			  };
	ajaxObjects[201].runAJAX();
}


function fnToggleUploadMediaBox()
{
	if(!intIsLobin) {
		fnNewRegisterLogin(0,0);
		return void(0);
	}
	
	var iframeEl = document.getElementById('upload_target');
	if ( iframeEl.contentDocument ) { // DOM
		objFormId = iframeEl.contentDocument.getElementById('file_upload_form');
	} else if ( iframeEl.contentWindow ) { // IE win
		objFormId = iframeEl.contentWindow.document.getElementById('file_upload_form');
	}
	
	objFormId.elements['image_upload'].value = "";
	objFormId.elements['document_upload'].value = "";
	
	if(isUploadMediaBoxDisplay == false) {
		isUploadMediaBoxDisplay = true;
		document.getElementById("id_img_upload_media_box").src = "images/mdc/ico_collapse_sml.gif";
	} else {
		isUploadMediaBoxDisplay = false;
		document.getElementById("id_img_upload_media_box").src = "images/mdc/ico_expand_sml.gif";
	}
	$("#uploadLayer").slideToggle();
}

function fnChangeSendUpdateBtn()
{
	strSelectedDate = document.getElementById('schedule_date').value;
	var currentTime = new Date();
	var curr_hour = currentTime.getHours();
	var month = currentTime.getMonth()+1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	arrResponse = strSelectedDate.split("/");
	var intyear = parseInt(arrResponse[2],10);
	var intmonth = parseInt(arrResponse[0],10);
	var intday = parseInt(arrResponse[1],10);
	strScheduleTime = document.getElementById('select_time').value;
	hr=0;
	if(strScheduleTime != "now") {
		var strSplitScheduleTime = strScheduleTime.split(':');
		hr = parseInt(strSplitScheduleTime[0],10);
	}
	
	if(strSelectedDate == "Today" || strSelectedDate == "")  
	{
		var today = new Date();
		strScheduleDate = (parseInt(today.getMonth(), 10)+1)+"/"+today.getDate()+"/"+today.getFullYear();
		var strSplitScheduleDate = strScheduleDate.split('/');
		intmonth = parseInt(strSplitScheduleDate[0],10);
		intday = parseInt(strSplitScheduleDate[1],10);
		intyear = parseInt(strSplitScheduleDate[2],10);
	}
	
	
	curr_hour = parseInt(curr_hour,10);
	if((year!= intyear || month!= intmonth || day!= intday) && strSelectedDate!='')
	{
		document.getElementById("btnSent").src = "images/scheduleBtn.gif";
	}
	else
	{
		if(year== intyear && month== intmonth && day== intday && hr > curr_hour){
			document.getElementById("btnSent").src = "images/scheduleBtn.gif";
		}
		else{
			document.getElementById("btnSent").src = "images/send_btn_new.gif";
		}
	}
}

function fnValidateScheduleDate() {
	var intScheduleDate='';
	document.getElementById("schedule_date_error").innerHTML = "";
	var strScheduleDate = "";
	var strScheduleTime = "";
	var myScheduleDate = "";
	var year = "";
	var month = "";
	var day = "";
	var hr = "";
	var mm = "";
	var sec = "";
	var strReturn='';
	
	strScheduleDate = document.getElementById('schedule_date').value;
	strScheduleTime = document.getElementById('select_time').value;
	if(strScheduleDate == "Today" || strScheduleDate == "")  {
		var today = new Date();
		strScheduleDate = (parseInt(today.getMonth(), 10)+1)+"/"+today.getDate()+"/"+today.getFullYear();
		strTodayParameter = "&today=1";
		if(strScheduleTime == "now" || strScheduleTime == "") {
			strScheduleDate = "";
		}
	}
	
	if(strScheduleDate != "") {
		var strSplitScheduleDate = strScheduleDate.split('/');
		month = parseInt(strSplitScheduleDate[0],10);
		day = parseInt(strSplitScheduleDate[1],10);
		year = parseInt(strSplitScheduleDate[2],10);
	}
	
	if(strScheduleTime == "now") {
		strScheduleTime = "";
		hr = "";
		mm = "";
		sec = "";
	} else {
		var strSplitScheduleTime = strScheduleTime.split(':');
		hr = strSplitScheduleTime[0];
		mm = strSplitScheduleTime[1];
		sec = strSplitScheduleTime[2];
	}
	
	var intyear = parseInt(year,10);
	var intmonth = parseInt(month,10);
	var intday = parseInt(day,10);
	
	var inthr = "";
	if(hr != "") inthr = parseInt(hr,10);
	var intmm = "";
	if(mm != "") intmm = parseInt(mm,10);
	var intsec = "";
	if(sec != "") intsec = parseInt(sec,10);
	
	if(year != "" && month != "" && day != "") {
		ajaxObjects[109] = new sack();				 
		ajaxObjects[109].PostParam = "&year="+year+"&month="+month+"&day="+day+"&hr="+inthr+"&mm="+intmm+"&sec="+intsec;
		ajaxObjects[109].requestFile = sitename+"/distributemedia&mode=ajax&ajax_action=gettimezonetime";
		ajaxObjects[109].onCompletion = function(){
												try  
												{
													strResponse = ajaxObjects[109].response;
													if(strResponse=="error"){
														document.getElementById("schedule_date_error").innerHTML = "Select correct schedule date or time";
													    fnScrollWindow("main");
													    ajax_showTooltip('schedule_date_error',document.getElementById('schedule_date'),160,40);
														strReturn="error";
														return false;
													}
													else
													{
														var strCDate = strResponse.split('|');
														var strGetMessage = strCDate[1];
														
														if(strGetMessage == "schedule"){
															if(hr == "") hr = "00";
															if(mm == "") mm = "00";
															if(sec == "") sec = "00";
															intScheduleDate= year+"-"+month+"-"+day+" "+hr+":"+mm+":"+sec;
														} else {
															intScheduleDate="";
														}
														
															var intTotalAccountSelected = document.getElementById("id_hdnTotalAccounts").value;
															enmIsReply = false;
															if (!fnValidateStatusMessage())
																return false;
															var objAccountContainerInput = null;
															for (intI = 1; intI < intTotalAccountSelected; intI++)
															{
																if(document.getElementById("id_SeeMoreAccountContainer_"+intI))
																{
																	objAccountContainerInput = document.getElementById("id_SeeMoreAccountContainer_"+intI).getElementsByTagName("INPUT");
																}
																else if(document.getElementById("id_AccountContainer_"+intI))
																{
																	objAccountContainerInput = document.getElementById("id_AccountContainer_"+intI).getElementsByTagName("INPUT");
																}
																
																if (objAccountContainerInput[0].checked)
																{
																	arrAllowAccounts[(intI - 1)] = objAccountContainerInput[1].value;
																	if (objAccountContainerInput[1].value == intReplyToAccount)
																		enmIsReply = true;
																}
															}
														
															if (arrAllowAccounts.length == 0) {
																document.getElementById('id_message_lable').innerHTML = "Please select at least one social network to post from";
																ajax_showTooltip('id_error_message_span',objSendButton,220,40);
																return false;
															}
															var strExtraParam = "";
															if (enmIsReply)
																strExtraParam = "&ajax_action=reply&updateid="+intReplyToAccount;
															if(intScheduleDate!='')
																strExtraParam = strExtraParam+"&scheduledate="+intScheduleDate;
															objSendButton.style.display = "none";
															objLoadingButton.style.display = "";
															
															if (arrAllowAccounts.length > 0)
																strAllowAccounts = arrAllowAccounts.join(",");
															ajaxObjects[4] = new sack();
															ajaxObjects[4].PostParam = "&message="+Base64.encode(strStatusMessage)+"&accounts="+Base64.encode(strAllowAccounts)+strExtraParam;
															ajaxObjects[4].requestFile = sitename+"/sendstatusmessage";
															ajaxObjects[4].onCompletion = function(){
																										objSendButton.style.display = "";
																										objSendButton.src = "images/send_btn_new.gif";
																										document.getElementById('schedule_date').value='Today';
																										document.getElementById('select_time').value='now';
																										objLoadingButton.style.display = "none";
																										strResponse = ajaxObjects[4].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 {
																											if (arrResponse[0] == "success_sch") 
																												fnShowMsgDiv(arrResponse[1], "");
																											else
																												fnShowMsgDiv("Message sent", "");
																											fnLoadAddUpdateBacisSetting();
																											fnCheckAccounts("none");
																										}
																									};
															ajaxObjects[4].runAJAX();
													}
												} catch(e) {}
										};
		ajaxObjects[109].runAJAX();	
		return strReturn;
	} else {
		fnCallStatusUpdate(strScheduleDate);
	}
}

function fnCallStatusUpdate(strScheduleDate)
{
	var intTotalAccountSelected = document.getElementById("id_hdnTotalAccounts").value;
	enmIsReply = false;

	if (!fnValidateStatusMessage())
		return false;
	
	var objAccountContainerInput = null;

	var arrTwitterAccounts = new Array();
	var arrFacebookAccounts = new Array();
	var arrJustmeansAccounts = new Array();
	var arrLinkedinAccounts = new Array();
	var arrTumblrAccounts = new Array();
	var arrDeliciousAccounts = new Array();

	var intTwitterAccounts = 0;
	var intFacebookAccounts = 0;
	var intJustmeansAccounts = 0;
	var intLinkedinAccounts = 0;
	var intTumblrAccounts = 0;
	var intDeliciousAccounts = 0;
	
	for (intI = 1; intI < intTotalAccountSelected; intI++)
	{
		if(document.getElementById("id_SeeMoreAccountContainer_"+intI))
		{
			objAccountContainerInput = document.getElementById("id_SeeMoreAccountContainer_"+intI).getElementsByTagName("INPUT");
		}
		else if(document.getElementById("id_AccountContainer_"+intI))
		{
			objAccountContainerInput = document.getElementById("id_AccountContainer_"+intI).getElementsByTagName("INPUT");
		}
		
		if (objAccountContainerInput[0].checked)
		{
			if (objAccountContainerInput[1].value == intReplyToAccount)
				enmIsReply = true;
				
			if (objAccountContainerInput[1].getAttribute("accounttype") == "tw")
			{
				arrTwitterAccounts[intTwitterAccounts] = objAccountContainerInput[1].value;
				intTwitterAccounts++;
			}
			else if (objAccountContainerInput[1].getAttribute("accounttype") == "fb" || objAccountContainerInput[1].getAttribute("accounttype") == "fbp")
			{
				arrFacebookAccounts[intFacebookAccounts] = objAccountContainerInput[1].value;
				intFacebookAccounts++;
			}
			else if (objAccountContainerInput[1].getAttribute("accounttype") == "ln")
			{
				arrLinkedinAccounts[intLinkedinAccounts] = objAccountContainerInput[1].value;
				intLinkedinAccounts++;
			}
			else if (objAccountContainerInput[1].getAttribute("accounttype") == "del")
			{
				arrDeliciousAccounts[intDeliciousAccounts] = objAccountContainerInput[1].value;
				intDeliciousAccounts++;
			}
			else if (objAccountContainerInput[1].getAttribute("accounttype") == "tumb")
			{
				arrTumblrAccounts[intTumblrAccounts] = objAccountContainerInput[1].value;
				intTumblrAccounts++;
			}
			else
			{
				arrJustmeansAccounts[intJustmeansAccounts] = objAccountContainerInput[1].value;
				intJustmeansAccounts++;
			}
			
			arrAllowAccounts[(intI - 1)] = objAccountContainerInput[1].value;
		}
	}

	if (arrAllowAccounts.length == 0)
	{
		document.getElementById('id_message_lable').innerHTML = "Please select at least one social network to post from";
		ajax_showTooltip('id_error_message_span',objSendButton,220,40);
		return false;
	}
	
	var strExtraParam = "";
	
	if (enmIsReply)
		strExtraParam = "&ajax_action=reply&updateid="+intReplyToAccount;
	if(strScheduleDate!='')
		strExtraParam = strExtraParam+"&scheduledate="+strScheduleDate;
		
	var strTwitterAccounts = "";
	var strFacebookAccounts = "";
	var strJustmeansAccounts = "";
	var strLinkedinAccounts = "";
	var strTumblrAccounts = "";
	var strDeliciousAccounts = "";
	
	if (arrTwitterAccounts.length > 0)
		strTwitterAccounts = arrTwitterAccounts.join(",");
	
	if (arrFacebookAccounts.length > 0)
		strFacebookAccounts = arrFacebookAccounts.join(",");
	
	if (arrTumblrAccounts.length > 0)
		strTumblrAccounts = arrTumblrAccounts.join(",");
	
	if (arrDeliciousAccounts.length > 0)
		strDeliciousAccounts = arrDeliciousAccounts.join(",");

	if (arrJustmeansAccounts.length > 0)
		strJustmeansAccounts = arrJustmeansAccounts.join(",");
		
	if (arrLinkedinAccounts.length > 0)
		strLinkedinAccounts = arrLinkedinAccounts.join(",");
	
	objSendButton.style.display = "none";
	objLoadingButton.style.display = "";
	
	if (strTwitterAccounts != "")
	{
		fnSendUpdateToTwitter(strTwitterAccounts, strStatusMessage, strExtraParam);
		intProcessCount++;
	}
	
	if (strFacebookAccounts != "")
	{
		fnSendUpdateToFacebook(strFacebookAccounts, strStatusMessage, strExtraParam);
		intProcessCount++;
	}
	
	if (strTumblrAccounts != "")
	{
		fnSendUpdateToTumblr(strTumblrAccounts, strStatusMessage, strExtraParam);
		intProcessCount++;
	}
	
	if (strDeliciousAccounts != "")
	{
		fnSendUpdateToDelicious(strDeliciousAccounts, strStatusMessage, strExtraParam);
		intProcessCount++;
	}
	
	if (strJustmeansAccounts != "")
	{
		fnSendUpdateToJustmeans(strJustmeansAccounts, strStatusMessage, strExtraParam);
		intProcessCount++;
	}
	
	if (strLinkedinAccounts != "")
	{
		fnSendUpdateToLinkedin(strLinkedinAccounts, strStatusMessage, strExtraParam);
		intProcessCount++;
	}
	
	objCheckProcess = setTimeout("fnCheckForCompleteProcess()",5);
	
	/*if (arrAllowAccounts.length > 0)
		strAllowAccounts = arrAllowAccounts.join(",");
	
	ajaxObjects[4] = new sack();
	ajaxObjects[4].PostParam = "&message="+Base64.encode(strStatusMessage)+"&accounts="+Base64.encode(strAllowAccounts)+strExtraParam;
	ajaxObjects[4].requestFile = sitename+"/sendstatusmessage";
	ajaxObjects[4].onCompletion = function(){
												objSendButton.style.display = "";
												objSendButton.src = "images/send_btn_new.gif";
												document.getElementById('schedule_date').value='Today';
												document.getElementById('select_time').value='now';
												objLoadingButton.style.display = "none";
												strResponse = ajaxObjects[4].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 {
													if (arrResponse[0] == "success_sch") 
														fnShowMsgDiv(arrResponse[1], "");
													else
														fnShowMsgDiv("Message sent", "");
													fnLoadAddUpdateBacisSetting();
													objTextBox.value = "";
													fnSetDefaultValue();
													fnCheckAccounts("none");
												}
											};
	ajaxObjects[4].runAJAX();*/
}

function fnSetUpdateUrl(strUpdateUrl) {
	//document.getElementById('id_upload_media_url').value = strUpdateUrl;
	fnToggleUploadMediaBox();
	var arrUrls = new Array();
	arrUrls = Base64.decode(strUpdateUrl).split('|');
	var strUpdate = document.getElementById('id_txtWhatAreUWorking').value;
	if(strUpdate == "Enter your  text message here") strUpdate = "";
	for(var i=0; i<arrUrls.length; i++) {
		strUpdate += " " + arrUrls[i];
	}
	document.getElementById('id_txtWhatAreUWorking').value = strUpdate;
	fnSetCharacterCount();
	document.getElementById('id_txtWhatAreUWorking').style.color = "#000000";
	
}

function fnSendUpdateToTwitter(strTwitterAccounts, strStatusMessage, strExtraParam)
{
	ajaxObjects[200] = new sack();
	ajaxObjects[200].PostParam = "&message="+Base64.encode(strStatusMessage)+"&accounts="+Base64.encode(strTwitterAccounts)+strExtraParam;
	ajaxObjects[200].requestFile = sitename+"/sendstatusmessage";
	ajaxObjects[200].onCompletion = function(){
													strResponse = ajaxObjects[200].response;
													arrResponse = strResponse.split("|");
													intCompletedProcessCount++;
													if (arrResponse[0] == "error")
														strProcessErrorMessage = strProcessErrorMessage + arrResponse[1] + "<br />";
											  };
	ajaxObjects[200].runAJAX();
}
	
function fnSendUpdateToFacebook(strFacebookAccounts, strStatusMessage, strExtraParam)
{
	ajaxObjects[201] = new sack();
	ajaxObjects[201].PostParam = "&message="+Base64.encode(strStatusMessage)+"&accounts="+Base64.encode(strFacebookAccounts)+strExtraParam;
	ajaxObjects[201].requestFile = sitename+"/sendstatusmessage";
	ajaxObjects[201].onCompletion = function(){
													strResponse = ajaxObjects[201].response;
													arrResponse = strResponse.split("|");
													intCompletedProcessCount++;
													if (arrResponse[0] == "error")
														strProcessErrorMessage = strProcessErrorMessage + arrResponse[1] + "<br />";
											  };
	ajaxObjects[201].runAJAX();
}

function fnSendUpdateToTumblr(strTumblrAccounts, strStatusMessage, strExtraParam)
{
	ajaxObjects[202] = new sack();
	ajaxObjects[202].PostParam = "&message="+Base64.encode(strStatusMessage)+"&accounts="+Base64.encode(strTumblrAccounts)+strExtraParam;
	ajaxObjects[202].requestFile = sitename+"/sendstatusmessage";
	ajaxObjects[202].onCompletion = function(){
													strResponse = ajaxObjects[202].response;
													arrResponse = strResponse.split("|");
													intCompletedProcessCount++;
													if (arrResponse[0] == "error")
														strProcessErrorMessage = strProcessErrorMessage + arrResponse[1] + "<br />";
											  };
	ajaxObjects[202].runAJAX();
}

function fnSendUpdateToDelicious(strDeliciousAccounts, strStatusMessage, strExtraParam)
{
	ajaxObjects[203] = new sack();
	ajaxObjects[203].PostParam = "&message="+Base64.encode(strStatusMessage)+"&accounts="+Base64.encode(strDeliciousAccounts)+strExtraParam;
	ajaxObjects[203].requestFile = sitename+"/sendstatusmessage";
	ajaxObjects[203].onCompletion = function(){
													strResponse = ajaxObjects[203].response;
													arrResponse = strResponse.split("|");
													intCompletedProcessCount++;
													if (arrResponse[0] == "error")
														strProcessErrorMessage = strProcessErrorMessage + arrResponse[1] + "<br />";
											  };
	ajaxObjects[203].runAJAX();
}

function fnSendUpdateToJustmeans(strJustmeansAccounts, strStatusMessage, strExtraParam)
{
	ajaxObjects[204] = new sack();
	ajaxObjects[204].PostParam = "&message="+Base64.encode(strStatusMessage)+"&accounts="+Base64.encode(strJustmeansAccounts)+strExtraParam;
	ajaxObjects[204].requestFile = sitename+"/sendstatusmessage";
	ajaxObjects[204].onCompletion = function(){
													strResponse = ajaxObjects[204].response;
													arrResponse = strResponse.split("|");
													intCompletedProcessCount++;
													if (arrResponse[0] == "error")
														strProcessErrorMessage = strProcessErrorMessage + arrResponse[1] + "<br />";
											  };
	ajaxObjects[204].runAJAX();
}

function fnSendUpdateToLinkedin(strLinkedinAccounts, strStatusMessage, strExtraParam)
{
	ajaxObjects[205] = new sack();
	ajaxObjects[205].PostParam = "&message="+Base64.encode(strStatusMessage)+"&accounts="+Base64.encode(strLinkedinAccounts)+strExtraParam;
	ajaxObjects[205].requestFile = sitename+"/sendstatusmessage";
	ajaxObjects[205].onCompletion = function(){
													strResponse = ajaxObjects[205].response;
													arrResponse = strResponse.split("|");
													intCompletedProcessCount++;
													if (arrResponse[0] == "error")
														strProcessErrorMessage = strProcessErrorMessage + arrResponse[1] + "<br />";
											  };
	ajaxObjects[205].runAJAX();
}

function fnCheckForCompleteProcess()
{
	clearTimeout(objCheckProcess);
	if (intProcessCount > 0)
	{
		if (intProcessCount == intCompletedProcessCount)
			fnAfterSentMessage();
		else
			objCheckProcess = setTimeout("fnCheckForCompleteProcess()",5);
	}
}

function fnAfterSentMessage()
{
	objSendButton.style.display = "";
	objSendButton.src = "images/send_btn_new.gif";
	objLoadingButton.style.display = "none";

	document.getElementById('schedule_date').value='Today';
	document.getElementById('select_time').value='now';

	if (strProcessErrorMessage != "")
	{
		fnShowMsgDiv("Error while sending update. We will send your message after 5 mins.", "");
	}
	else
	{
		fnShowMsgDiv("Message sent", "");
	}

	fnLoadAddUpdateBacisSetting();
	objTextBox.value = "";
	fnSetDefaultValue();
	fnCheckAccounts("none");

	intProcessCount = 0;
	intCompletedProcessCount = 0;
	strProcessErrorMessage = "";
}
