// JavaScript Document

function fnCheckSearchCategoryText(objFrm)
{
	strErrorMessage = "";
	var objElement = "";	
	
	objElement = document.getElementById("id_searchcategorytext");
	strErrorMessage = fnGetErrorMessage(objElement, strErrorMessage);

	if(strErrorMessage != "")
	{
		alert(strErrorMessage);
		return false;
	}
	return true;
}


function fnCheckAddNewCategory(objFrm)
{
	var objElement = "";	
	strErrorMessage = "";
	
	objElement = document.getElementById("id_txtsgCategoryTitle");
	strErrorMessage = fnGetErrorMessage(objElement, strErrorMessage);

	if(strErrorMessage != "")
	{
		alert(strErrorMessage);
		return false;
	}
	return true;
}

function fnCheckEditCategory(objFrm)
{
	var objElement = "";	
	strErrorMessage = "";
	
	objElement = document.getElementById("id_txtsgCategoryTitle");
	strErrorMessage = fnGetErrorMessage(objElement, strErrorMessage);

	if(strErrorMessage != "")
	{
		alert(strErrorMessage);
		return false;
	}
	return true;
}




	function fnShowLinks(categoryid)
	{
		document.getElementById('id_operationdiv_'+categoryid).style.display='block';
	}
	
	
	function fnHideLinks(categoryid)
	{
		document.getElementById('id_operationdiv_'+categoryid).style.display='none';
	}
	
	function fnDeleteCategory(categoryid, intInUserFlag)
	{
		intInUserFlag = parseInt(intInUserFlag, 10);
		if(intInUserFlag)
		{
			alert("Best Practice belongs to this category, you can not delete.");
			return false;
		}
		else
		{
			var isconfirm;
			isconfirm=fnValidateConfirmation('delete this category');
			if(isconfirm)
			{
				return true;
				//location.href=sitename+"/sgadmindeletecategory?categoryid="+categoryid;	
			}
			else
			{
				return isconfirm;
			}
		}
	}

	function fnDeleteCategoryByCheck(intInUserFlag)
	{
		intInUserFlag = parseInt(intInUserFlag, 10);
		if(intInUserFlag)
		{
			alert("Practice belongs to this category, you can not delete.");
			return false;
		}
		else
		{
			return true;
		}
	}







	var img = new Image();
	img.src = "images/loading.gif";
	var categoryid;
	var contenttype;
	var isactive;
	
	
	
	function fnHideStatus(response)
	{
		document.getElementById('id_Successdiv_'+response).style.display = "none";	
	}
	
	function fnProcessAjaxResponse(response)
	{
		document.getElementById('id_loadingdiv_'+ response).style.display = "none";
		document.getElementById('id_Successdiv_'+ response).style.display = "";
		setTimeout('fnHideStatus("' + response + '")', 1000);
	}
	
	
	function fnAjaxRequestInProgress(categoryid,contenttype)
	{
		document.getElementById('id_loadingdiv_'+contenttype+categoryid).style.display = "";	
	}
	
	function fnAjaxRequestError(categoryid,contenttype)
	{
		document.getElementById('id_updateerror_'+contenttype+categoryid).style.display = "";
	}
	
	
	
	function fnSetCategoryIsActive(contenttype,categoryid,isactive)
	{	
		
		if(isactive=='y')
		{
			document.getElementById('id_rdbIsyShowCategory_'+categoryid).checked=true;
		}
		else
		{
			document.getElementById('id_rdbIsnShowCategory_'+categoryid).checked=true;
		}
		
		ajaxObjects[0] = new sack();
		ajaxObjects[0].requestFile = sitename+"/"+'index.php?action=ajaxmanagesgcategory&content_action='+contenttype+'&mode=ajax'+'&categoryid='+categoryid+'&isactive='+isactive;
		ajaxObjects[0].onLoading = function(){
													fnAjaxRequestInProgress(categoryid,contenttype);
											 };
		ajaxObjects[0].onFail = function(){
													fnAjaxRequestError(categoryid,contenttype);
										  };
		ajaxObjects[0].onCompletion = function(){
													fnProcessAjaxResponse(ajaxObjects[0].response);
												};
		ajaxObjects[0].runAJAX();
	}
	
	
	function fnSetCategoryType(contenttype,categoryid,categorytype)
	{	
	
		if(categorytype=='c')
		{
			document.getElementById('id_rdbCategoryTypec_'+categoryid).checked=true;
		}
		else
		{
			document.getElementById('id_rdbCategoryTypep_'+categoryid).checked=true;
		}
	
		ajaxObjects[0] = new sack();
		ajaxObjects[0].requestFile = sitename+"/"+'index.php?action=ajaxmanagesgcategory&content_action='+contenttype+'&mode=ajax'+'&categoryid='+categoryid+'&categorytype='+categorytype;
		ajaxObjects[0].onLoading = function(){
													fnAjaxRequestInProgress(categoryid,contenttype);
											 };
		ajaxObjects[0].onFail = function(){
													fnAjaxRequestError(categoryid,contenttype);
										  };
		ajaxObjects[0].onCompletion = function(){
													fnProcessAjaxResponse(ajaxObjects[0].response);
												};
		ajaxObjects[0].runAJAX();
	}
	
	
	
	
	function fnChangeCategory()
	{
		var categoryid;
		categoryid=document.getElementById("id_categoryId").value;
		location.href=sitename + "/sgcategorydetails?cid="+categoryid;	
	}