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>";

function fnToggleSubPage(strSubPageId,strPageConentId)
{
	fnShowSelectedSubPage(strSubPageId);
	document.getElementById("id_SubPageInfo").innerHTML = strLoadingHtml;

	ajaxObjects[0] = new sack();
	ajaxObjects[0].PostParam = "&subpage="+strSubPageId+"&pagecontent="+strPageConentId;
	ajaxObjects[0].requestFile = sitename+"/viewcompanyprofile?mode=ajax&ajax_action=viewsubpage&id="+intCompanyId;
	ajaxObjects[0].onCompletion = function(){
													document.getElementById("id_SubPageInfo").innerHTML = ajaxObjects[0].response;
											 };
	ajaxObjects[0].runAJAX();
}

function fnShowSelectedSubPage(strSubPageId)
{
	arrSubPages = document.getElementById("id_SubPageList").getElementsByTagName("LI");
	
	for (intI = 0; intI < arrSubPages.length; intI++)
	{
		if (arrSubPages[intI].id == strSubPageId)
			arrSubPages[intI].className = "active";
		else
			arrSubPages[intI].className = "";
	}
}

function fnViewMediaVideo(intVideoId)
{
	Lightbox.showBoxByID("id_Video_Popup_"+intVideoId, 455,450);
}

function fnPlayVideo(strMediaId)
{
	document.getElementById("id_VideoImage_"+strMediaId).innerHTML = document.getElementById("id_VideoPlayer_"+strMediaId).innerHTML;
	document.getElementById("id_VideoPlayer_"+strMediaId).style.display = "none";
}

var intGlobalContentId;
var strGlobalListType;
function fnShowCompanyContactList(intCompanyId,strListType,intContentId)
{
	intGlobalContentId = intContentId;
	strGlobalListType = strListType;

	document.getElementById("id_CompanyContact_"+intContentId).innerHTML = strLoadingHtml;
	Lightbox.hideCloseButton = 1;
	Lightbox.enmStopResetSession = 0;
	Lightbox.showBoxByID("id_CompanyContact_"+intContentId, 400, 260);

	ajaxObjects[1] = new sack();
	ajaxObjects[1].PostParam = "&listtype="+strListType;
	ajaxObjects[1].requestFile = sitename+"/viewcompanyprofile?mode=ajax&ajax_action=viewcompanycontactlist&id="+intCompanyId+"&content="+intContentId;
	ajaxObjects[1].onCompletion = function(){
													document.getElementById("id_CompanyContact_"+intContentId).innerHTML = ajaxObjects[1].response;
											};
	ajaxObjects[1].runAJAX();
}

function fnAddRemoveContactGroup(strContentId)
{
	  
	strCompanyId = Base64.encode(document.getElementById("id_Company_Id").value);
	intContactUser = Number(document.getElementById("id_Contact_User").value);
	intGroupChecked = Number(document.getElementById("id_Group_Checked").value);
	
	arrGroupContainer = document.getElementById("id_ContactGroups").getElementsByTagName("input");
	arrGroups = new Array();
	intCount = 0;
	for (intI = 0; intI < arrGroupContainer.length; intI++)
	{
		objCheckBox = arrGroupContainer[intI];
		if (objCheckBox.checked)
		{
			arrGroups[intCount] = Number(objCheckBox.value);
			intCount++;
			
		}
	}
	strGroups = arrGroups.join();
	
	if (strGroups == "" && intGroupChecked == 0)
	{
		$("#optContactGroupErr").slideToggle();
		return false;
	}
	
	document.getElementById("id_ContactSubmit").style.display = "none";
	document.getElementById("id_ContactLoading").style.display = "";
	
	ajaxObjects[2] = new sack();
	ajaxObjects[2].PostParam = "&companyid="+strCompanyId+"&groups="+strGroups+"&contactbox="+strContentId;
	ajaxObjects[2].requestFile = sitename+"/setunsetsessionvars?mode=ajax&ajax_action=setsessionparams&settoparams=addcompanycontactgroup";
	ajaxObjects[2].onCompletion = function(){
												if (intContactUser == 0)
												{
													Lightbox.hideBox();
													Lightbox.refreshAfterClose=1;
													fnChangeLoginBoxHeader("Login to join the company network");
													fnNewRegisterLogin(0,0);
												}
												else
												{
													fnAddContactGroup();
												}
											};
	ajaxObjects[2].runAJAX();
	
	return false;
}

function fnRequestContactGroup()
{    
    var strGroups =""; 
	var strErrorMessage ='';
	var ReqContactGroups = '';
	var ReqContactGroups1 = '';
	strCompanyId = document.getElementById("company_id").value;
	arrGroupContainer = document.getElementById("contactgroupdtls_div").getElementsByTagName("input");
	document.getElementById('id_ReqContactSubmit').style.display ='none';
	document.getElementById('id_ReqContactLoading').style.display ='';
	
    arrGroups = new Array();
	intCount = 0;
	for (intI = 0; intI < arrGroupContainer.length; intI++)
	{  
		objCheckBox = arrGroupContainer[intI];
		if (objCheckBox.checked)
		{ var deptId = objCheckBox.value;
		  
			if(document.getElementById("id_checkboxGroup_"+deptId).style.display=='' && document.getElementById("id_checkboxGroup_"+deptId).checked == true)
			{
				arrGroups[intCount] = Number(objCheckBox.value);
				
				
				strGroups ="";
				strGroups = document.getElementById('id_dept_'+deptId).innerHTML;
				document.getElementById('id_checkboxGroup_'+deptId).style.display='none';
				document.getElementById('id_ImgcheckboxGroup_'+deptId).style.display='';
				if(intCount>1 )
				{
					sepetator = ', ';
				}
				else
				{
					sepetator = '';
				}
					
				ReqContactGroups = ReqContactGroups+" "+sepetator+""+strGroups;
				ReqContactGroups1 = strGroups+"-"+ReqContactGroups1;
				intCount++; 
			}
		}
	}
	
	
	 
	  /*  alert(ReqContactGroups1);
	 return false; */
	if(arrGroupContainer.length > 1)
	{
		var prural= 's';
	}
	else
	{
		var prural= "";
	}
	 
	
  
	if(intCount < 1)
	{
		document.getElementById("id_error_msg").innerHTML = "Please select appropriate contact group.";
		document.getElementById('id_ReqContactSubmit').style.display ='';
		document.getElementById('id_ReqContactLoading').style.display ='none';
		ajax_showTooltip("id_error_msg", document.getElementById('id_ReqContactSubmit'),190,40);
		return false;
		//strMsg='Select appropriate contact group.';		
		//fnShowMsgDiv(strMsg);
		
		return false;
	}
	
	strGroups = arrGroups.join(); 
	/* alert(strGroups);
	 document.getElementById('id_ReqContactSubmit').style.display ='';
	 return false; */
	ajaxObjects[2] = new sack();
	ajaxObjects[2].PostParam = "&strGroups="+strGroups+"&comapnyID="+strCompanyId;
	ajaxObjects[2].requestFile = sitename+"/viewcompanyprofile&mode=ajax&ajax_action=reqContactGroupcomanyprofile";
	ajaxObjects[2].onCompletion = function(){
												strResponse = ajaxObjects[2].response;
												arrResponse = strResponse.split("|");
												fnShowMsgDiv(arrResponse[1]);
												if (arrResponse[0] == "1")
												{
													setTimeout("location.reload(true)",4000) ;
												}
												else
												{
													document.getElementById('id_ReqContactSubmit').style.display ='';
													document.getElementById('id_ReqContactLoading').style.display ='none';
												}
											};
	ajaxObjects[2].runAJAX();
	return false;
	
}

 

function fnAddContactGroup()
{
	ajaxObjects[3] = new sack();
	ajaxObjects[3].requestFile = sitename+"/addcompanycontactgroup?ajax=1";
	ajaxObjects[3].onCompletion = function(){
												document.getElementById("id_ContactSubmit").style.display = "";
												document.getElementById("id_ContactLoading").style.display = "none";
												
												strResponse = ajaxObjects[3].response;
												arrResponse = strResponse.split("|");
												enmJoinButton = parseInt(arrResponse[0]);
												
												window.scroll(0,0);
												fnShowMsgDiv(arrResponse[1]);
												Lightbox.hideBox();
												
												objContactInfo = document.getElementById("id_Contact_Text_"+intGlobalContentId);
												objContactButton = document.getElementById("id_Contact_Button_"+intGlobalContentId);
												if (enmJoinButton)
												{
													objContactButton.innerHTML = Base64.decode(objContactInfo.getAttribute("jointext"));
													objContactButton.parentNode.setAttribute("onclick",Base64.decode(objContactInfo.getAttribute("joinfunction")));
												}
												else
												{
													objContactButton.innerHTML = Base64.decode(objContactInfo.getAttribute("leavetext"));
													objContactButton.parentNode.setAttribute("onclick",Base64.decode(objContactInfo.getAttribute("leavefunction")));
												}
											};
	ajaxObjects[3].runAJAX();
}

function fnShowMsgDiv(strMessage)
{ 
   document.getElementById("spam").className = "spamsuccessmessage";
   document.getElementById("spam").innerHTML = "<img src='images/ico_delete.gif' class='floatRt' alt='close' title='close' onclick='javascript:fnHideMsgDiv();' />" + strMessage;
   $("#spam").slideToggle();
   setTimeout("fnHideMsgDiv();",5000);
}
 
function fnHideMsgDiv()
{  
	if (document.getElementById("spam").style.display != 'none')
		$("#spam").slideToggle();
}

function fnConnectWaitingMessage(intCompanyGroup)
{
	/*ajax_showTooltip("id_ConnectMessage_"+intCompanyGroup,document.getElementById("id_DisContact_"+intCompanyGroup),300,45);
	setTimeout("ajax_hideTooltip();",5000);*/
	
	//document.getElementById("id_ConnectMessage_"+intCompanyGroup).style.display = "";
	
	strMessage = "<img src='images/ico_delete.gif' class='floatRt' onclick='javascript:fnCloseMsgBox();' />";
	strMessage = strMessage + document.getElementById("id_ConnectMessage_"+intCompanyGroup).innerHTML;
	document.getElementById("optContactGroupMsg").innerHTML = strMessage;
	
	//document.getElementById("optContactGroupMsg").style.display = "";
	$("#optContactGroupMsg").slideToggle();
	setTimeout("fnCloseMsgBox();",5000);
}

function fnCloseMsgBox()
{
	if (document.getElementById("optContactGroupMsg").style.display != "none")
		$("#optContactGroupMsg").slideToggle();
		
	document.getElementById("optContactGroupMsg").innerHTML = "";
}

function fnShowCompanyCommentBox(strAddCommentDiv, strAddCommentBox, isSetFocus)
{
	try{
			document.getElementById(strAddCommentDiv).style.display = "";
			fnCompanyOpenInternalCommentBox(strAddCommentBox, isSetFocus);
			strCommentContainerId = "id_"+strAddCommentBox+"_CommentContainer";
			document.getElementById(strCommentContainerId).style.display = "";
		//$("#"+strCommentContainerId).slideToggle();
	}
	catch(e)
	{
	}
}

function fnCompanyOpenInternalCommentBox(strElementId, isSetFocus)
{
	try{
			document.getElementById("id_AddComment_"+strElementId).style.display = "";
			document.getElementById("id_txtNewsFeedDiv_"+strElementId).style.display = "none";
			document.getElementById("id_txtNewsFeedTbl_"+strElementId).style.display = "";
	
			if (isSetFocus == 1)
				document.getElementById("id_txtNewsFeedComment_"+strElementId).focus();
	}
	catch(e)
	{
		//alert(e.message);
	}
}

function fnShowCompanySimilarTextUpdates(strSimilarPostParam,intUpdateId)
{
	if (strSimilarPostParam == "")
		return;
	
	document.getElementById("id_Separator_"+intUpdateId).style.display = "none";
	document.getElementById("id_Similar_Post_"+intUpdateId).style.display = "none";

	ajaxObjects[47] = new sack();
	ajaxObjects[47].requestFile = sitename+"/?mode=ajax&ajax_action=similartextupdate&similarupdateparam="+strSimilarPostParam;
	ajaxObjects[47].onCompletion = function(){
													objResponse = ajaxObjects[47].response;
													document.getElementById("id_SimilarPostContainer").innerHTML = objResponse;
													arrSimilarPosts = document.getElementById("id_SimilarPostContainer").getElementsByTagName("LI");
													arrSimilarObjects = new Array();
													intObjectCount = 0;
													for (intI = 0; intI < arrSimilarPosts.length; intI++)
													{
														objCurrentObject = arrSimilarPosts[intI];
														if (objCurrentObject.className == "updateListItem")
														{
															arrSimilarObjects[intObjectCount] = objCurrentObject;
															intObjectCount++;
														}
													}

													objRecentAddedObject = document.getElementById("id_update_"+intUpdateId);
													for (intI = 0; intI < arrSimilarObjects.length; intI++)
													{
														objCurrentObject = arrSimilarObjects[intI];
														if (objRecentAddedObject.nextSibling)
															objRecentAddedObject.parentNode.insertBefore(objCurrentObject,objRecentAddedObject.nextSibling);
														else
															objRecentAddedObject.parentNode.appendChild(objCurrentObject);

														fnSetFadeEffects(objCurrentObject.id);
														
														objRecentAddedObject = objCurrentObject;
													}
													fnComapnyRenderFacebookShare("id_NewsFeedTab", objFacebookButton);
													document.getElementById("id_SimilarPostContainer").innerHTML = "";
											 };
	ajaxObjects[47].runAJAX();
}

function fnComapnyRenderFacebookShare(strDivId, objFacebookObject)
{
	arrFacebookObjects = document.getElementById(strDivId).getElementsByTagName('a');
	for (intI = 0; intI < arrFacebookObjects.length; intI++)
	{
		if (arrFacebookObjects[intI].name == "fb_share")
		{
			if (arrFacebookObjects[intI].innerHTML == "Share")
				objFacebookObject.Share.renderButton(arrFacebookObjects[intI]);
		}
	}
}

