/**
 * Home Module JS Files
 * @author Pathfinder Solutions India
 * @link http://www.pathfindersolutions.biz
 * @version 1.0
 * @package justmeans
 * @subpackage home
 */
 	var ajaxObjects = new Array();
	var BckEndCommentAction = "shweta";
	function fnCheckCharCnt()
	{
		var strText;
		var intFlag =0;
		strText = document.getElementById('id_txtEventWhatAreUWorking').value;
		if(intFlag==0)
			elementid.style.height = elementid.scrollHeight + 'px';
		// \s Matches any white-space character.
		// \s is equivalent to [ \f\n\r\t\v].
		// removes white spaces \n etc
		/*if(140 - strText.length > 0)
		{
			document.getElementById('id_chartextcnt').innerHTML = 140 - strText.length;
		}
		else
		{*/
			
			if(140 - strText.length > 0)
			{
				document.getElementById('id_chartextcnt').innerHTML = 140 - strText.length;
			}
			else
			{
				document.getElementById('id_chartextcnt').innerHTML = 0;
			}	
			document.getElementById('id_txtWhatAreUWorking').value = strText.substring(0, 140);
		/*}*/
		
	}
	
	function fnCheckCommentCharCnt()
	{ 
		var strText;
		var strTextLen;		
		//document.getElementById("id_txtWhatAreUWorking").style.class = "inputfont";
		strText = document.getElementById("id_txtWhatAreUWorking").value;
		
		// \s Matches any white-space character.
		// \s is equivalent to [ \f\n\r\t\v].
		// removes white spaces \n etc
		/*if(140 - strText.length > 0)
		{
			document.getElementById('id_chartextcnt').innerHTML = 140 - strText.length;
		}
		else
		{*/	 
			if(1000 - strText.length >= 20)
			{
				if(siteid!='sg')
				{
					document.getElementById("id_chartextcnt").className = "charcount";
				}
				else
				{
					document.getElementById("id_chartextcnt").className = "counter floatRt";
				}
			}
			else if((1000 - strText.length < 20) &&  (1000 - strText.length > 10) )
			{
				if(siteid!='sg')
				{
					document.getElementById("id_chartextcnt").className = "charcount20";
				}
				else
				{
					document.getElementById("id_chartextcnt").className = "sgcharcount20";
				}
				
			}
			else
			{
				if(siteid!='sg')
				{
					document.getElementById("id_chartextcnt").className = "charcountnegative";
				}
				else
				{
					document.getElementById("id_chartextcnt").className = "sgcharcountnegative";
				}
				
			}
			
			if(1000 - strText.length  < 0)
			{
				if(siteid!='sg')
				{
					document.getElementById("btnaddcomment").src = "images/btn_enterdisable.gif";
				}
				else
				{
					document.getElementById("btnaddcomment").src = "images/btn_enter.gif";
				}
				
			}
			else
			{
				document.getElementById("btnaddcomment").src = "images/btn_enter.gif";
			}
			if((1000 - strText.length <= 999) && (1000 - strText.length > -1)){ 
				try{
			  		ajax_hideTooltip();
				}
				catch(e){}
			}
			if(strText != "Write a Comment..."  &&  strText != "Share your comments here...")
			{					
				document.getElementById('id_chartextcnt').innerHTML = 1000 - strText.length;
			}
	}
	
	// Function For  Char Count Reply Comment and respond to  replies 
	
	function fnCheckReplyCommentCharCnt(parentid)
	{ 
	
		var strText;
		var strTextLen;		
		
			strText = document.getElementById("id_txtWhatAreUWorking_"+parentid).value;			
			if(parentid)
			{
				strCountDivId = "id_chartextcnt_"+parentid;
				
			}
			if(1000 - strText.length >= 20)
			{
				if(siteid!='sg')
				{
					document.getElementById(strCountDivId).className = "charcount";
				}
				else
				{
					document.getElementById(strCountDivId).className = "counter floatRt";
				}
				
			}
			else if((1000 - strText.length < 20) &&  (1000 - strText.length > 10) )
			{	
				if(siteid!='sg')
				{
					document.getElementById(strCountDivId).className = "charcount20";
				}
				else
				{
					document.getElementById(strCountDivId).className = "sgcharcount20";
				}

			}
			else
			{
				if(siteid!='sg')
				{
					document.getElementById(strCountDivId).className = "charcountnegative";
				}
				else
				{
					document.getElementById(strCountDivId).className = "sgcharcountnegative";
				}
				
			}
			
			if(1000 - strText.length  < 0)
			{
				if(siteid!='sg')
				{
					document.getElementById("btnaddcomment_"+parentid).src = "images/btn_enterdisable.gif";
				}
				else
				{
					document.getElementById("btnaddcomment_"+parentid).src = "images/btn_enterdisable.gif";
				}
				
			}
			else
			{
				document.getElementById("btnaddcomment_"+parentid).src = "images/btn_enter.gif";
			}
			if((1000 - strText.length <= 999) && (1000 - strText.length > -1)){ 
				try{
					
			  		ajax_hideTooltip();
				}
				catch(e){}
			} 
			if(strText != "Write a Comment..."  &&  strText != "Share your comments here..." && strText != "Respond to this conversation..." && strText != "Comment Back...")
			{				
				document.getElementById(strCountDivId).innerHTML = 1000 - strText.length;
			}
	}
	
	
	function fnValidateInputForComment(loginuserid,type,typeid,parentid,companypageid,approveflag,BckEndCommentAction)
	{
		
		var strErrorMessage = "";
		var strCommentText = "";
	
		var intCompetitionCategory = "";		
		
		var extparam;
		if(parentid != 0)
		{			
			extparam = "_"+parentid;
		}
		else
		{
			extparam = "";
		}		
		
	
		strCommentText = document.getElementById('id_txtWhatAreUWorking'+extparam).value;		
		
		if(type == "competitionidea")
		{				
			intCompetitionCategory = document.getElementById('hid_categoryid').value;			
			if(intCompetitionCategory == "")
			{
				strErrorMessage = "Select Category from List.\n";				
			}
			
			if(strCommentText != "" && strCommentText != "Share your ideas here...")
			{				
				Lightbox.refreshAfterClose = 1;
				document.getElementById('id_select2').style.display = 'none';
			}
		}
		
		if(type == "competitionideacomment")
		{
			type = "competitionidea";
		}	
		
		if(strCommentText == "" || strCommentText == "Write a Comment..." || strCommentText == "Share your ideas here..." || strCommentText == "Share your comments here..." || strCommentText == "Respond to this conversation..." || strCommentText == "Comment Back...")
		{
			ajax_showTooltip('id_ErrorMessageDiv'+extparam,document.getElementById("btnaddcomment"+extparam),250,50);
			//alert("Enter Text For 'What good work are you doing right now?' ");
			return false;
		}
		
		
		else if(1000 - strCommentText.length  < 0)
		{ 
			
			ajax_showTooltip('id_ErrorMessageExceedDiv'+extparam,document.getElementById("btnaddcomment"+extparam),280,60);
			return false;
		}		
		
		
		
		/*if(strCommentText == "" || strCommentText == "Write a Comment..." || strCommentText == "Share your ideas here..." || strCommentText == "Share your comments here...")
		{
			strErrorMessage = strErrorMessage + "Write a Comment";
		}*/
		
		/*if(strErrorMessage != "")
		{
			alert(strErrorMessage);
			document.getElementById('id_select2').style.display = '';
			document.getElementById('id_txtWhatAreUWorking'+extparam).focus();
			return false;
		}*/
		else
		{
			
			var myarry = new Array();
			
			var tab= RegExp( "\\n", "g" )
			strText = strCommentText.replace(tab, " ")
			//myarry = strCommentText.split(' ');  
			myarry = strText.split(' ');  
			for (i=0;i<myarry.length;i++)
			{	
				if((myarry[i].length) >= 25)
				{	
					if((!myarry[i].match("http://")) && (!myarry[i].match("www")) && (!myarry[i].match("http://www")) && (!myarry[i].match("https://")))
					/*if(!myarry[i].match("http://"))*/
					{
						if (parseInt(parentid) > 0)
						ajax_showTooltip('id_CommentExceedWord',document.getElementById("id_CommentEnter_"+parentid),200,50);
						else
						ajax_showTooltip('id_CommentExceedWord',document.getElementById('btnaddcomment'),200,50);
						return false;
					}		
				}
			}
			
			//FOR LOADER IMAGE
			if (parseInt(parentid) > 0)
				fnShowDefauleLoaderImage("id_CommentEnter_"+parentid,"id_CommentLoader_"+parentid);
			else
				fnShowDefauleLoaderImage("id_CommentEnter","id_CommentLoader");

			// ajax call to set variables
			strCommentText = Base64.encode(strCommentText);
			var ajaxIndex = ajaxObjects.length;	
			ajaxObjects[0] = new sack();
			var strNewParentId = 0;
			
			
			
			if(siteid!='sg')
			{
				ajaxObjects[0].requestFile = sitename+"/index.php?action=setunsetsessionvars&mode=ajax&ajax_action=setsessionparams&settoparams=forcomments&type="+type+"&typeid="+typeid+"&parentid="+strNewParentId+"&companypageid="+companypageid+"&commenttext="+strCommentText+"&compcat="+intCompetitionCategory+"&strBckEndCommentAction="+BckEndCommentAction+"&approveflag="+approveflag;
			}
			else
			{
				ajaxObjects[0].requestFile = justsitename+"/index.php?action=setunsetsessionvars&mode=ajax&ajax_action=setsessionparams&settoparams=forcomments&type="+type+"&typeid="+typeid+"&parentid="+strNewParentId+"&companypageid="+companypageid+"&commenttext="+strCommentText+"&compcat="+intCompetitionCategory;				
			}
			
				
			ajaxObjects[0].onCompletion = function(){ 				
															if(loginuserid == 0 || loginuserid == "")
															{
																if (parseInt(parentid) > 0)
																	fnHideDefauleLoaderImage("id_CommentEnter_"+parentid,"id_CommentLoader_"+parentid);
																else
																	fnHideDefauleLoaderImage("id_CommentEnter","id_CommentLoader");
																if(siteid=='sg')
																{
																	Lightbox.showBoxByID("divRegisterLogin", intLoginPopupWidth, intLoginPopupHeight);
																}
																else
																{
																	Lightbox.showBoxByID("divRegisterLogin", intLoginPopupWidth, intLoginPopupHeight);
																}
																return false;
															}
															else
															{
																ajaxObjects[1] = new sack();
																if(siteid!='sg')
																{
																	ajaxObjects[1].requestFile = sitename+"/index.php?action=checkuseractype";
																	
																}
																else
																{
																	ajaxObjects[1].requestFile = justsitename+"/index.php?action=checkuseractype";
																}
																
																ajaxObjects[1].onCompletion = function(){ 
																											if (ajaxObjects[1].response == 1)
																											{ 
																												fnProcessAjaxCode(8);
																											}
																											else if (ajaxObjects[1].response == 2)
																											{
																												/*if (parseInt(parentid) > 0)
																			fnHideDefauleLoaderImage("id_CommentEnter_"+parentid,"id_CommentLoader_"+parentid);
																											else
																			fnHideDefauleLoaderImage("id_CommentEnter","id_CommentLoader");*///commented by chaitanya
																													
																												document.getElementById('divRegisterLogin').innerHTML = "";
																												if(siteid=='sg')
																												{
																													//Lightbox.showBoxByID("divRegisterLogin", 670, 400);
																												}
																												else
																												{
																													Lightbox.showBoxByID("divRegisterLogin", intLoginPopupWidth, intLoginPopupHeight);
																												}
																												fnProcessAjaxCode(8);	
																												
																											}
																											else
																											{
																												//alert("You do not have permission to add Comment.");
																												return false;
																											}
																										}
																ajaxObjects[1].runAJAX();
															}
														};	// Specify function that will be executed after file has been found
			ajaxObjects[0].runAJAX();
			
			
		}
	}
	
	function fnSendConnectRequest(loginuserid,recieverid,recid)
	{
		
		if(recieverid != "" || recieverid != 0)
		{
			//fnAjaxCaller("", "setunsetsessionvars", "setsessionparams", "&settoparams=forconnectuser&connectrecieverid="+recieverid,"","");
			//setTimeout("",1000);
			var ajaxIndex = ajaxObjects.length;	
			ajaxObjects[ajaxIndex] = new sack();
			ajaxObjects[ajaxIndex].requestFile = sitename+"/index.php?action=setunsetsessionvars&mode=ajax&ajax_action=setsessionparams&settoparams=forconnectuser&connectrecieverid="+recieverid;
			ajaxObjects[ajaxIndex].onCompletion = function(){
																if(loginuserid == 0 || loginuserid == "")
																{
																	Lightbox.showBoxByID("divRegisterLogin", intLoginPopupWidth, intLoginPopupHeight);
																}
																else
																{
																	if(loginuserid == recieverid)
																	{
																		document.getElementById("relationsipdiv_" + recid).style.display="";
																		document.getElementById("relationsipdiv_" + recid).innerHTML="<br /><b><font color='#FF0000'>Sorry, you can not connect with yourself</font></b>"; 
																	}
																	else
																	{
																		fnAjaxCaller("relationsipdiv_" + recid,"sendconnecttouser","","&isbyajax=1","","");
																		document.getElementById("relationsipdiv_" + recid).style.display="none";
																	}
																}
															};	// Specify function that will be executed after file has been found
			ajaxObjects[ajaxIndex].runAJAX();
			
		}
		
	}
	
	
	function fnToggleImageForReplyConnect(intRec,suserid,loginuserid)
	{
		
			/*var strFileSource = document.getElementById('imageid_' + intRec).src; 
			var temp = strFileSource.split('/');*/
			
			/*if(temp[temp.length - 1] == "arrowside.gif")*/
			if(document.getElementById("relationsipdiv_" + intRec).style.display=="none")
			{
				/*document.getElementById('imageid_'+intRec).src= "images/arrowdown.gif"; */
				if(suserid == loginuserid)
				{
					document.getElementById("relationsipdiv_" + intRec).style.display="";
					document.getElementById("relationsipdiv_" + intRec).innerHTML="<br /><b><font color='#FF0000'>Sorry, you can not send a private message to yourself.</font></b>"; 
				}
				else
				{
					//issetfocus
					document.getElementById('issetfocus').value = "msg_"+intRec;
					fnAjaxCaller("relationsipdiv_" + intRec,"showallcomment","showreplytoconnect","&recid="+intRec+"&suserid=" + suserid,"","");
				}
			}
			else
			{
				/*document.getElementById('imageid_' + intRec).src= "images/arrowside.gif"; */
				document.getElementById("relationsipdiv_" + intRec).innerHTML=""; 
				document.getElementById("relationsipdiv_" + intRec).style.display="none";
			}		
	}
	
	function fnProcessReplyToConnect(loginuserid,recid,uid)
	{
			strSubject = document.getElementById('sub_'+recid).value;
			strMessage = document.getElementById('msg_'+recid).value;
			
			strMessage = escape(strMessage);
			strMessage = strMessage.replace(/\r?\n/g,'<br/>');
			
			strSubject = escape(strSubject);
			
			if(strSubject == "" || strMessage == "")
			{
				alert("Please Enter Subject and Message to send");
			}
			else
			{
				//fnAjaxCaller("", "setunsetsessionvars", "setsessionparams", "&settoparams=forreplytoconnect&suserid="+uid+"&replyconnectsubject="+strSubject+"&replyconnectmessage="+strMessage,"","");
				//setTimeout("",1000);
				var ajaxIndex = ajaxObjects.length;	
				ajaxObjects[ajaxIndex] = new sack();
				ajaxObjects[ajaxIndex].requestFile = sitename+"/index.php?action=setunsetsessionvars&mode=ajax&ajax_action=setsessionparams&settoparams=forreplytoconnect&suserid="+uid+"&replyconnectsubject="+strSubject+"&replyconnectmessage="+strMessage;
				ajaxObjects[ajaxIndex].onCompletion = function(){
																	if(loginuserid == 0 || loginuserid == "")
																	{
																		Lightbox.showBoxByID("divRegisterLogin", intLoginPopupWidth, intLoginPopupHeight);
																	}
																	else
																	{
																		fnAjaxCaller("relationsipdiv_" + recid,"addreplytoconnect","","&recid=" + recid + "&isbyajax=1","","");
																		document.getElementById("relationsipdiv_" + recid).style.display="none";
																	}
																};	// Specify function that will be executed after file has been found
				ajaxObjects[ajaxIndex].runAJAX();
				
			}
	}

	function fnSetReplyUserName(strUserName)
	{
		if(strUserName != "")
		{
			
			document.getElementById('id_txtWhatAreUWorking').value = "@"+strUserName+ " " ;
			var strText = document.getElementById('id_txtWhatAreUWorking').value;
			document.getElementById('id_chartextcnt').innerHTML = 140 - (strText.length);
		}
		
		document.getElementById('id_txtWhatAreUWorking').focus();
	}
	
	function fnReplyToComment(intRec,suserid,loginuserid,statusid,straction,strcommenttype)
	{
		
			/*var strFileSource = document.getElementById('imageid_' + intRec).src; 
			var temp = strFileSource.split('/');*/
			/*if(temp[temp.length - 1] == "arrowside.gif")*/
			if(loginuserid == 0 || loginuserid == "")
			{
				Lightbox.showBoxByID("divRegisterLogin", intLoginPopupWidth, intLoginPopupHeight);
			}
			else
			{
			
				if(document.getElementById("relationsipdiv_" + intRec).style.display=="none")
				{
					/*document.getElementById('imageid_'+intRec).src= "images/arrowdown.gif"; */
					if(suserid == loginuserid)
					{
						document.getElementById("relationsipdiv_" + intRec).style.display="";
						document.getElementById("relationsipdiv_" + intRec).innerHTML="<br /><b><font color='#FF0000'>Sorry, you can not comment to yourself.</font></b>"; 
					}
					else
					{
						document.getElementById('issetfocus').value = "id_txtWhatAreUWorking_"+statusid;
						fnAjaxCaller("relationsipdiv_" + intRec,"showallcomment","showreplytocomment","&recid=" + intRec + "&suserid=" + suserid + "&statusid=" + statusid + "&strredirectaxn=" + straction + "&commenttype= " + strcommenttype,"","");
					}
				}
				else
				{
					/*document.getElementById('imageid_' + intRec).src= "images/arrowside.gif"; */
					document.getElementById("relationsipdiv_" + intRec).innerHTML=""; 
					document.getElementById("relationsipdiv_" + intRec).style.display="none";
				}	
				
			}
	}
	
	function fnHideShowCommentBox(loginuserid,statusid)
	{
		isLoad = false;
		/*if(loginuserid == 0 || loginuserid == "")
		{
			Lightbox.showBoxByID("divRegisterLogin", 650, 420);
		}
		else
		{*/
			//alert("Open Box");
			//id_CommentBoxTd
			document.getElementById("id_CommentBoxTd_"+statusid).innerHTML=""; 
			document.getElementById('issetfocus').value = "id_txtWhatAreUWorking_"+statusid;
			fnAjaxCaller("id_CommentBoxTd_" + statusid,"showallcomment","showreplytocomment","&suserid=" + loginuserid + "&statusid=" + statusid + "&strredirectaxn=showallwruwo","","");
		/*}*/
	}
	
	function fnShowCommentBoxer(statusid)
	{
		
		var extparam;
		if(statusid)
		{
			extparam = "_"+statusid;
		}
		else
		{
			extparam = "";
		}
		
		if(document.getElementById("id_txtWhatAreUWorking"+extparam).value == "" || document.getElementById("id_txtWhatAreUWorking"+extparam).value == "Write a Comment..." || document.getElementById("id_txtWhatAreUWorking"+extparam).value == "Share your ideas here..." || document.getElementById("id_txtWhatAreUWorking"+extparam).value == "Share your comments here..." || document.getElementById("id_txtWhatAreUWorking"+extparam).value == "Respond to this conversation..." || document.getElementById("id_txtWhatAreUWorking"+extparam).value == "Comment Back...")
		{
			document.getElementById("id_txtWhatAreUWorking"+extparam).style.height = "85px";
			document.getElementById("id_txtWhatAreUWorking"+extparam).value = "";
			document.getElementById("btnaddcomment"+extparam).style.display = "";
			document.getElementById("id_txtWhatAreUWorking"+extparam).className = "inputblack";
			document.getElementById("id_txtWhatAreUWorking"+extparam).focus();
		}
	}
	
	function fnViewAllComment(commentcnt,statusid)
	{
		for(i=1;i<=commentcnt;i++)
		{
			document.getElementById("id_tr_" + i + "_" + statusid).style.display="";			
		}		
		
		
		/*for(i=1;i<=commentcnt;i++)
		{			
			document.getElementById("id_dottedH_" + i + "_" + statusid).style.display="";
		}*/
		if(document.getElementById("id_before_" + statusid).style.display=="")
		{ 
			document.getElementById("id_before_" + statusid).style.display="none";
			document.getElementById("id_after_" + statusid).style.display="";
		}
		else
		{
			document.getElementById("id_before_" + statusid).style.display="";
			document.getElementById("id_after_" + statusid).style.display="none";
			for(i=1;i<=commentcnt;i++)
			{
			document.getElementById("id_tr_" + i + "_" + statusid).style.display="none";			
			}
		}
		
	}
	
	function fnIncreaseHieghtofTA(elementid)
	{
		elementid.style.height = elementid.scrollHeight + 'px';
	}
	
	function fnDeleteCommentByAjax(intCommentId,intMainCommentId,trtempcnt,commentcnt)
	{
		ajax_hideTooltip();	
		fnAjaxCaller("","deletecomment","","&commentid=" + intCommentId,"","");
		if(intMainCommentId == 0)
		{			
			document.getElementById("id_tr_" + intCommentId).style.display="none";
			document.getElementById("id_separator_" + intCommentId).style.display="none";
			document.getElementById("id_CommentBoxTd_" + intCommentId).style.display="none";
		}
		else
		{		
			if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
			{ //test for MSIE x.x;
			 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
			 if (ieversion==6)
			  this.location.reload();			
			}	 
			 
			/*if(commentcnt > 2)
			{				
				for(i=2;i<=commentcnt;i++)
				{
					document.getElementById("id_tr_" + i + "_" + intMainCommentId).style.display="";
				}			
				//document.getElementById("id_maintr_" + intMainCommentId).style.display="none";				
			}*/			
			
			//alert("here");
			//this.location.reload();
			document.getElementById("id_tr_"+trtempcnt+"_" +intMainCommentId).style.display="none";			
		}
	}
	
	function fnDisplayReplyCommentBox(intStatusId)
	{		
		document.getElementById("id_CommentBoxTd_"+ intStatusId).style.display="";
		document.getElementById("id_txtWhatAreUWorking_"+ intStatusId).focus();
	}
	
	function fnCheckCharCntForIdea()
	{
		 
		var strText;
		strText = document.getElementById('id_txtWhatAreUWorking').value;
		// \s Matches any white-space character.
		// \s is equivalent to [ \f\n\r\t\v].
		// removes white spaces \n etc
		/*if(140 - strText.length > 0)
		{
			document.getElementById('id_chartextcnt').innerHTML = 140 - strText.length;
		}
		else
		{*/
			
			if(1000 - strText.length > 0)
			{
				if(strText != "Share your ideas here...")
					document.getElementById('id_ideacharcnt').innerHTML = 1000 - strText.length;
			}
			else
			{
				document.getElementById('id_ideacharcnt').innerHTML = 0;
			}	
			document.getElementById('id_txtWhatAreUWorking').value = strText.substring(0, 1000);
		/*}*/
		
	}
	
	function fnSetCatgHidValue()
	{
		var catgid = "";
		catgid = document.getElementById('id_select2').value;		
		document.getElementById('hid_categoryid').value = catgid;
	}
	
	/*function fnAjaxPaginationLoader(strContentId)
	{
		document.getElementById(strContentId).innerHTML = "<div style='padding-top: 140px; text-align: center;'><span style='font-size: 20px; font-weight: bold; color: rgb(170, 170, 170);'>Loading...</span><br/><br/><img align='absmiddle' src='images/big_slide_loader.gif'/></div>";	
	}*/
	
	function fnShowTollTipForDeleteCommentByAjax(strElementId)
	{
		isCloseBtnEnable = false;
		ajax_showTooltip('id_divDeleteCommentByAjax_'+strElementId,document.getElementById('id_imgDeleteCommentByAjax_'+strElementId),290,55);
	}