/**

* Hide HTML elements

*

* @param string of elements

* @return Hide passed HTML elements

*/



var ajaxObjects = Array();



function fnHideShowObject(strHideElements, strShowElements)

{	

	

	if (strHideElements != "")

	{

		arrHideElements = strHideElements.split(' ');

		for (intI = 0; intI < arrHideElements.length; intI++)

		{

			if (document.getElementById(arrHideElements[intI]).style.display == "")

			{

				document.getElementById(arrHideElements[intI]).value = "";

				document.getElementById(arrHideElements[intI]).style.display = "none";

			}

			else

			{

				document.getElementById(arrHideElements[intI]).style.display = "";

			}

		}

	}

	

	if (strShowElements != "")

	{

		arrShowElements = strShowElements.split(' ');

		for (intI = 0; intI < arrShowElements.length; intI++)

		{

			if (document.getElementById(arrShowElements[intI]).style.display == "none")

			{

				document.getElementById(arrShowElements[intI]).style.display = "";

			}

			else

			{

				document.getElementById(arrShowElements[intI]).value = "";

				document.getElementById(arrShowElements[intI]).style.display = "none";

			}

		}

	}

}



function fnLoginPopup()

{

	strFormAction = sitename + "/login?goto=" + returnurl;

	strRegeAction = sitename + "/signup?goto=" + returnurl;

	

	if (Base64.decode(returnurl) != "action=home")

	{
		try{
		document.frmPopupLogin.action = strFormAction;

		document.getElementById("id_RegisterLink").href = strRegeAction;
		}catch (e)
		{}
	}

	

	Lightbox.showBoxByID('id_LoginBox',530,360);

}



/*function fnSetGotoLink(strhref)

{

	document.getElementById("id_LoginForm").action   = sitename+"/login?goto="+strhref;

	document.getElementById("id_RegisterLink").href  = sitename+"/signup?goto="+strhref;

	Lightbox.showBoxByID('id_LoginBox',530,360);

}*/



function fnClearText(objControl)

{

	strSearchValue = objControl.value;

	if (strSearchValue == "")

	{

		objControl.value = "Example: Who's the sexiest reality TV star?";

	}

	else

	{

		arrSearchValue = strSearchValue.split(":");

		if (arrSearchValue[0] == "Example")

			objControl.value = "";

	}

}



function fnCheckUncheckAll(theElement)

{

	var theForm = theElement.form, z = 0;



	for(z=0; z<theForm.length;z++)

	{

		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')

		{

		   theForm[z].checked = theElement.checked;

		}

	}

}



function fnSetCheckAll(theElement)

{

	if (fnCheckUncheck(theElement) == 1)

		document.getElementById("checkall").checked = true;

	else

		document.getElementById("checkall").checked = false;

}



function fnCheckUncheck(theElement)

{

	var theForm = theElement.form, z = 0, intElementCnt = 0, intCheckCnt = 0;



	for(z=0; z<theForm.length;z++)

	{

		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')

		{

			intElementCnt = intElementCnt + 1;

			if (theForm[z].checked == true)

				intCheckCnt = intCheckCnt + 1;

		}

	}

	

	if (intCheckCnt == intElementCnt)

		return 1;

	else

		return 0;

}



function fnRefershActivityBox()

{

	//intActivityPage++;

	/*document.getElementById("id_LastActivityContainer").innerHTML = "<img src='images/loading.gif' />";*/

	

	//CHECKES FOR PAGE COUNTER GREATER THAN DATABASE PAGE COUNTER

	//if(intActivityPage > intNoofpages)

		intActivityPage = 1;

	

	ajaxObjects[32] = new sack();

	ajaxObjects[32].requestFile = sitename+'/index.php?action=home&mode=ajax&ajax_action=refreshactivity&activitypage='+intActivityPage;

	//ajaxObjects[0].requestFile = sitename+'/index.php?action=home&mode=ajax&ajax_action=refreshactivity';

	ajaxObjects[32].onCompletion = function(){

												document.getElementById("id_LastActivityContainer").innerHTML = ajaxObjects[32].response;

											};

	ajaxObjects[32].runAJAX();

	

	setTimeout("fnRefershActivityBox()",30000);

}



function fnHideShowText(objTextBox, strText, strActiveClass, strInActiveClass)

{

	if (objTextBox.value == "")

	{

		objTextBox.value = strText;

		objTextBox.className = strActiveClass;

	}

	else if (objTextBox.value == strText)

	{
		objTextBox.value = "";
		objTextBox.className = strInActiveClass;
	}

}

function fnHideShowTextEditPro(objTextBox, strText, strActiveClass, strInActiveClass)
{
	if (objTextBox.value == "")
	{
		objTextBox.value = strText;
		objTextBox.className = strActiveClass;
	}
	else if (objTextBox.value == strText)
	{
		objTextBox.value = "";
		objTextBox.className = strInActiveClass;
	}
	/*else if(objTextBox.value !="Example: www.frankrank.com")
	{
		objTextBox.value = document.getElementById("id_txtHomePage").value;
		objTextBox.className = strInActiveClass;
	}*/
}



strOtherFunction = "";



function fnAjaxPagination(strContentId, intLimit, intPage, strFuseName)

{ 
	if (strContentId != "" && parseInt(intLimit) > 0 && parseInt(intPage) > 0)
	{
		fnAjaxPaginationLoader(strContentId);
		ajaxObjects[33] = new sack();
		ajaxObjects[33].requestFile = sitename+"/index.php?action="+strFuseName+"&mode=ajax&ajax_action=ajaxpagination&limit="+intLimit+"&page="+intPage;
		ajaxObjects[33].onCompletion = function(){ 
													document.getElementById(strContentId).innerHTML = ajaxObjects[33].response;
												 }
		ajaxObjects[33].runAJAX();
	}
}



function fnAjaxPaginationLoader(strContentId)

{
	strHtml = "";
	strHtml = strHtml + "<div style='text-align:center; padding: 40px 0  40px 0;'>";
	strHtml = strHtml + "<span style='font-size: 14px; font-weight: bold; color: #AAAAAA;'>Loading...</span><br /><br />";
	strHtml = strHtml + "<img src='images/big_slide_loader.gif' align='absmiddle'>";
	strHtml = strHtml + "</div>";
	document.getElementById(strContentId).innerHTML = strHtml;
}



function fnUserFriendsUrl(sorttype)

{

	document.getElementById("id_userfriends").value = sorttype;

	document.frmUserFriends.submit();

	return false;

}





/* Function to set the URL and its Param */

function fnSetUrl(strSortType,strValue,strUrl)

{
	/*document.getElementById("id_LastActivityContainer").innerHTML = "<img src='images/loading.gif' />";*/
	ajaxObjects[1] = new sack();
	ajaxObjects[1].requestFile = sitename+'/index.php?action=user&mode=ajax&ajax_action=seturl&sorttype='+strSortType+'&strvalue='+strValue;
	ajaxObjects[1].onCompletion = function(){
												window.location.href = strUrl;
												//document.getElementById("id_LastActivityContainer").innerHTML = ajaxObjects[0].response;
											};
	ajaxObjects[1].runAJAX();
	//setTimeout("fnRefershActivityBox()",30000);
}



function fnSetPopVoteUrl(strUserId,strUrl)

{

	ajaxObjects[0] = new sack();

	ajaxObjects[0].requestFile = sitename+'/index.php?action=home&mode=ajax&ajax_action=setpopvoteurl&userid=' + strUserId;

	ajaxObjects[0].onCompletion = function () {

													window.location = strUrl;

													//alert(ajaxObjects[0].response);

											  };

	ajaxObjects[0].runAJAX();

	return false;

}



function fnGetAjaxPagination(strContentId, intLimit, intPage, strFuseName)

{

	if (strContentId != "" && parseInt(intLimit) > 0 && parseInt(intPage) > 0)

	{

		ajaxObjects[0] = new sack();

		ajaxObjects[0].requestFile = sitename+"/index.php?action="+strFuseName+"&mode=ajax&ajax_action=ajaxpagination&limit="+intLimit+"&page="+intPage;

		ajaxObjects[0].onCompletion = function(){

													document.getElementById(strContentId).innerHTML = ajaxObjects[0].response;

													document.getElementById(strContentId).style.display = "";

												}

		ajaxObjects[0].runAJAX();

	}

}



function fnRefreshDebate(isRefresh)
{
	ajaxObjects[100] = new sack();
	ajaxObjects[100].requestFile = sitename+'/index.php?action=home&mode=ajax&ajax_action=refreshdebate&question='+intQuestionId+'&commentcount='+intCommentCnt;
	
	ajaxObjects[100].onCompletion = function () {
													if (isRefresh)
													{
														document.getElementById("id_txtQuickUpdate").value = "";
														document.getElementById("id_viewdebate").style.display = "";
													}
													document.getElementById("id_viewdebate").innerHTML = ajaxObjects[100].response;
											  };
	ajaxObjects[100].runAJAX();


	if (!isRefresh)
		setTimeout("fnRefreshDebate(0)",15000);
	
	return false; 
}

var intNextItemCommentCnt = 0;
function fnQuickDebate(intQueId,intSessionUserId)
{
	var strTxtQuickUpdate = document.getElementById("id_txtQuickUpdate");
	
	if(strTxtQuickUpdate.value != "")
	{
		strQuickUpdateText    = document.getElementById("id_txtQuickUpdate").value;
		
		var browser=navigator.appName;
		
		var myarry = new Array();
		pattern = /(\w+)\s+(\w+)/;
		
		if(browser == "Microsoft Internet Explorer")
			myarry = strQuickUpdateText.split(" ");
		else
			myarry = strQuickUpdateText.split(pattern);
		
		for (i=0;i<myarry.length;i++)
		{
			if((myarry[i].length) >= 20)
			{	
				if((!myarry[i].match("http://")) && (!myarry[i].match("www")) && (!myarry[i].match("http://www")) && (!myarry[i].match("https://")))
				{
					alert("Single word limit exceeded. Please make sure that a single word is not more than 20 characters.");
					return false;
				}		
			}
		}

		var strDivStyle = document.getElementById("id_Debate_AddComment");
		strDivStyle.style.display = "";
		var txtQuickUpdate = document.getElementById("id_txtQuickUpdate").value;
		txtQuickUpdate = Base64.encode(txtQuickUpdate);
		
		intNextItemCommentCnt =  1 + intNextItemCommentCnt;
		
		ajaxObjects[2000] = new sack();
		ajaxObjects[2000].requestFile = sitename+'/index.php?action=viewproduct&mode=ajax&ajax_action=addcomentupdate&usrid=' + intSessionUserId + '&question=' + intQueId+ '&commentn=' + txtQuickUpdate+'&commentcount='+intNextItemCommentCnt;
			
			ajaxObjects[2000].onCompletion = function(){ 
														strDivStyle.style.display = "none";		
														document.getElementById("id_postcmt_cnclcmy").style.display = "";	
														document.getElementById("id_quickcmt_viewcmy").style.display = "";
														document.getElementById("id_Commentcount").innerHTML = "("+intNextItemCommentCnt+")";
														document.getElementById("id_RightCommentcount").innerHTML = intNextItemCommentCnt;
														fnRefreshDebate(1);	
														//return false;
													};
			ajaxObjects[2000].runAJAX();
	}
	else
	{
			var errormsg = "Please enter comment";
			//alert("Please enter comment");
			fnLightBoxError(errormsg, 0);
			strTxtQuickUpdate.focus;
			return;
	}
	
}

function fnQuickDebateCancel(strHideShow)
{
	if(strHideShow == 1)
	{
		
		try
		{
			document.getElementById("id_viewdebate").style.display = "none";
			document.getElementById("id_Debate_AddComment").style.display = "";		
			document.getElementById("id_quickcmt_viewcmy").style.display = "none";
			document.getElementById("id_postcmt_cnclcmy").style.display = "none";	
		}
		catch(e)
		{
			alert(e);
		}
		
	}
	else
	{
		document.getElementById("id_viewdebate").style.display = "";
		document.getElementById("id_Debate_AddComment").style.display = "none";	
		document.getElementById("id_quickcmt_viewcmy").style.display = "";	
		document.getElementById("id_postcmt_cnclcmy").style.display = "";
		
	}
}

/*function test()
{
	document.getElementById("boxContents").style.margin = "0";
	document.getElementById("boxContents").style.padding = "0";
	
	document.getElementById("id_FbAuthenticate").innerHTML = document.getElementById("id_Temp").innerHTML;
	
	//removeElement = document.getElementById("close");
	//removeElement.parentNode.removeChild(removeElement);
	Lightbox.showBoxByID("id_FbAuthenticate",650,238);
}*/

function fnCallAfterLogin()
{
	Lightbox.refreshAfterClose = 0;
	Lightbox.hideBox();
	document.getElementById("boxContents").style.margin = "0";
	document.getElementById("boxContents").style.padding = "0";
	removeElement = document.getElementById("close");
	removeElement.parentNode.removeChild(removeElement);
	strRedirectUrl = sitename+"/index.php?action=home&mode=ajax&ajax_action=fbauthenticate&straction="+straction+"&goto="+gotourl;
	ajaxObjects[24] = new sack();
	ajaxObjects[24].requestFile = strRedirectUrl;
	ajaxObjects[24].onCompletion = function(){
												strResponse = ajaxObjects[24].response;
												if(strResponse != "")
												{
													document.getElementById("id_FbAuthenticate").innerHTML = strResponse;
													Lightbox.showBoxByID("id_FbAuthenticate",650,235);
												}
												else
												{
													window.location=sitename+"/index.php?action=fbauthentication&goto="+gotourl;
												}
											};
	ajaxObjects[24].runAJAX();
	return false;
}

function fnCallAfterLoginFBPub()
{
	var ajaxObjects = Array();
	document.getElementById("boxContents").style.margin = "0";
	//document.getElementById("boxContents").style.padding = "0";
	removeElement = document.getElementById("close");
	removeElement.parentNode.removeChild(removeElement);
	strRedirectUrl = sitename+"/home&mode=ajax&ajax_action=fbauthenticatepub&goto="+gotourl;
	ajaxObjects[24] = new sack();
	ajaxObjects[24].requestFile = strRedirectUrl;
	ajaxObjects[24].onCompletion = function(){
												strResponse = ajaxObjects[24].response;
												if(strResponse != "")
												{
													document.getElementById("id_FbAuthenticatePublish").innerHTML = strResponse;
													Lightbox.showBoxByID("id_FbAuthenticatePublish");
												}
												else
												{
													fnPublishDataOnFacebook();
												}
											};
	ajaxObjects[24].runAJAX();
	return false;
}

function fnCallAfterLoginFBPubItem()
{
	var ajaxObjects = Array();
	document.getElementById("boxContents").style.margin = "0";
	//document.getElementById("boxContents").style.padding = "0";
	removeElement = document.getElementById("close");
	removeElement.parentNode.removeChild(removeElement);
	strRedirectUrl = sitename+"/home&mode=ajax&ajax_action=fbauthenticatepubitem&goto="+gotourl;
	ajaxObjects[24] = new sack();
	ajaxObjects[24].requestFile = strRedirectUrl;
	ajaxObjects[24].onCompletion = function(){
												strResponse = ajaxObjects[24].response;
												if(strResponse != "")
												{
													document.getElementById("id_FbAuthenticatePublishItem").innerHTML = strResponse;
													Lightbox.showBoxByID("id_FbAuthenticatePublishItem");
												}
												else
												{
													window.location=itemprofileurl;
												}
											};
	ajaxObjects[24].runAJAX();
	return false;
}

function fnCallAfterLoginContinue()
{
	window.location=itemprofileurl;
}

function fnCheckEmailPermission()
{
	if(document.getElementById("AuthenticatechkAgree").checked == false)
	{
		alert("Select I Agree to Terms and Conditions.");
		return false;
	}
	else
	{
		 Lightbox.hideBox("id_FbAuthenticate",650,235);
		 fnEmailPermission(); 
	}
}
function fnEmailPermission()
{
	Lightbox.hideBox("id_FbAuthenticate",650,235);
	FB.Connect.showPermissionDialog("email",function(strReturn){ if (strReturn == "") fnEmailPermission(); else window.location=sitename+"/index.php?action=fbauthentication&goto="+gotourl; });
}

var strMessage      = "";
var strAttachment   = "";
var strActionLinks  = "";

function fnPublishDataOnFacebook()
{
	Lightbox.hideBox();
	ajaxObjects[46] = new sack();
	ajaxObjects[46].requestFile = sitename+'/index.php?action=viewproduct&ajax_action=getfacebookinfo&mode=ajax&question='+intQuestionId;
	ajaxObjects[46].onCompletion = function(){ 
												strAttachment = eval('('+ajaxObjects[46].response+')');
												strMessage = "";
												FB.Connect.streamPublish(strMessage, strAttachment, strActionLinks, '', '', function() {  window.location.reload(); });
											 };
	ajaxObjects[46].runAJAX();
}

