var __doc__;
var __frm__;
var IsFromSearch;

function AJAX_MethodForBrowseAll()
{
	hideErrPageDiv();
	eval(returnControlId('BrowseAll_ascx') + '_' + 'BrowseAllCallback').Callback($().hidSelectedBeatId.value);
}

function BrowseAllCallBackEnd()
{
	CloseAssetLayer();
	IsFromSearch=false;
	CallbackForChannelContent();
	HideErrorMessageDiv();

}

function OnLoadEventChannelGateway()
{
	//onLoadRecentSearches(); Ani
	if(IsRequiredBrowseAll == 'TRUE' || IsRequireWhenBrowseAllBackTo != '1')
	{
		IsFromSearch=false;
		CallbackForChannelContent();
		HideErrorMessageDiv();
	}
}

function setFocus(linkid) 
{
	var focusIt = $(linkid);
	focusIt.focus();
}
function BrowseByLoad()
{
	
	if(CurrentPageName == "SEARCHRESULT")
	{
		
		var strImgId = "imgShowBeatSource";
		$(strImgId).src = strjsImagePath + "img_plus.gif";
		$("divShowBeatSource").style.display = "none";
		
		if($().hidDyndiv.value != "")
		{
			if($($().hidDyndiv.value)!=null)
			{
				$($().hidDyndiv.value).className="";
			}
		}
	
	}
}
function CollapseBeatsOrSource(imgObj, strAssetType,strHasSubBeatOrSubSource,clickEvent,Url,strBeatSourceName)
{
	
	var strImgId;
	if(clickEvent == "image")
	{
		strImgId = imgObj.id;
	} 
	else
	{
		strImgId = 'imgBrowseBy_' + imgObj;
	}
	var strDivSubBeatId = strImgId.replace( "img", "divSubBeat");
	var strDivBeatId = strImgId.replace( "img", "divBeat");
	var strLink = strImgId.replace( "img", "AnchorBeat");
	var arrIDs = strImgId.split("_");
	strBeatOrSourceID = arrIDs[1];
	//if MINUS is clicked
	
	if($(strDivSubBeatId).style.display == "block")
	{
		$(strDivSubBeatId).style.display = "none";
		$(strDivBeatId).className = "whiteColor";
			if(strHasSubBeatOrSubSource == 'Yes')
		{
			$(strImgId).src = strjsImagePath + "img_plus.gif";
			$(strLink).focus();
		}
		//sstchur_SmartScroller_Scroll();
	}
	else
	{
		//if PLUS is clicked
		if($().hidDynSubdiv.value != "")
		{
		
			if(($($().hidDynSubdiv.value) == '[object]') || ($($().hidDynSubdiv.value) == '[object HTMLDivElement]'))
			{
			
				if($($().hidDynSubdiv.value).style.display == "block")
				{
					if($().hidDyndiv.value!= "")
					{
						$($().hidDyndiv.value).className = "whiteColor";
						if(($($().hidDynimg.value) == '[object]') || ($($().hidDynimg.value) == '[object HTMLImageElement]'))
						{
							$($().hidDynimg.value).src = strjsImagePath + "img_plus.gif"
						}
					}
				}
				$($().hidDynSubdiv.value).style.display="none"
			}
			
			//sstchur_SmartScroller_Scroll();
			if(clickEvent == "image")
			{
				$(strLink).focus();
			}
		}
		
		if(strDivBeatId != "")
		{
			$(strDivBeatId).className = "browseAllBeatOrSourceGreyLineDashed";
			if($().hidDyndiv.value!="")
			{
				if($($().hidDyndiv.value)!=null)
				{
					if($().hidDyndiv.value!= strDivBeatId)
				    {
					 $($().hidDyndiv.value).className="";
					}
				}
			}
		}
		
		if(strHasSubBeatOrSubSource == 'Yes')
		{
			$(strDivSubBeatId).style.display = "block";
			$(strImgId).src = strjsImagePath + "img_minus.gif";
		}
		
		
		if(clickEvent == "image")
		{
			$(strLink).focus();
		}
		//}
		if(clickEvent == "image")
		{
			$(strLink).focus();
		}
		$().hidDynSubdiv.value = strDivSubBeatId;
		$().hidDyndiv.value = strDivBeatId;
		$().hidDynimg.value = strImgId;
		if(clickEvent == "image")
		{
			$().hidDynLink.value = "No";
		}
		else
		{
			$().hidDynLink.value = "Yes";
		}
				
		//SubmitForBeatsOrSources(strBeatOrSourceID, strAssetType,Url,strBeatSourceName);
	}
	
}

function ToggleBeatsAndSource(imgObj)
{
	var strImgId = imgObj.id;
	var strDivBeatsAndSourceId = strImgId.replace( "img", "div");

	//if MINUS is clicked
	if($(strDivBeatsAndSourceId).style.display =="block")
	{
		$(strDivBeatsAndSourceId).style.display = "none";
		imgObj.src = strjsImagePath + "img_plus.gif";
	}
	else
	{
		//if PLUS is clicked
		$(strDivBeatsAndSourceId).style.display = "block";
		imgObj.src = strjsImagePath + "img_minus.gif";
	}
}

function SubmitForBeatsOrSources(strBeatOrSourceID, strAssetType,Url,strBeatSourceName)
{

	var strId;
	if (strAssetType.toUpperCase() == "BEATS")
	{
		strId = "+AND+EQUAL{" + strBeatOrSourceID + "}:BeatID";
		$().hidChannelGatewayTrail.value = strBeatSourceName + '~Beat~' + strBeatOrSourceID;
		$().hidCGSearchTrail.value = $().hidChannelGatewayTrail.value;
	}
	else
	{
		strId = "+AND+EQUAL{" + strBeatOrSourceID + "}:SourceID";
		$().hidChannelGatewayTrail.value = strBeatSourceName + '~Source~' + strBeatOrSourceID;
		$().hidCGSearchTrail.value = $().hidChannelGatewayTrail.value;
	}
	$().hidChannelGatewayTrailClicked.value = "0";
	$().hidChannelGatewayTrailRequired.value = "1";
    $().hidGatewayParentName.value = strBeatSourceName;
	$().hidGatewayRefineResultId.value =  strId;
	$().hidGatewayParentId.value = strBeatOrSourceID;
	$().hidGatewayResType.value = strBeatOrSourceID;
	$().hidSelectedBeatId.value = strBeatOrSourceID;
	
	if((IsBrowseAllPageSubmitRequire == 'TRUE') || ($().hidBrowseAllSubmitRequired.value == 'TRUE'))
	{
		var path = Url;
		$().hidBrowseAllSubmitRequired.value = "1";
		document.forms[0].action = path;
		document.forms[0].method  = "post";
		document.forms[0].submit();
	}
	else
	{
		AJAX_MethodForBrowseAll();
	}
	
	return false;
}
	
function SubmitChild(strBeatOrSourceID, strSubBeatOrSubSourceID, strAssetType,SubBeatTitle,Url,strBeatSourceName)
{

	var AssetType = $("hidmediaType").value;
	var strId;
	var strBeatSourceId;
	$().hidGatewayParentName.value = strBeatSourceName;
	if (strAssetType.toUpperCase() == "BEATS")
	{
		//if(isChannelGateway == 'true')
		strBeatSourceId = "+AND+EQUAL{" + strBeatOrSourceID + "}:BeatID";
		strId = '+AND+EQUAL{'+strSubBeatOrSubSourceID+'}:SubBeatID';
	    
		ShowHideControls();
	}
	else
	{
	$().hidChannelGatewayTrail.value = SubBeatTitle + '~SubSource~' + strSubBeatOrSubSourceID;
	strBeatSourceId = "+AND+EQUAL{" + $().hidGatewayParentId.value + "}:SourceID";
	strId = '+AND+EQUAL{'+strSubBeatOrSubSourceID+'}:SubSourceID';
	$().hidCGSearchTrail.value = $().hidChannelGatewayTrail.value;
	}	
	$().hidChannelGatewayTrailClicked.value = "0";
	$().hidChannelGatewayTrailRequired.value = "1";
	$().hidGatewayRefineResultId.value = strBeatSourceId + strId;
	/*if(isChannelGateway == 'true')
	{
		$().hidGatewayRefineResultId.value = strBeatSourceId + strId;
	}
	else
	{
		$().hidGatewayRefineResultId.value = strId;
	}*/
	var hidcntrl = returnControlId('BrowseAll_ascx') + '_' + 'hidGatewayTrail';
	hidcntrl = $(hidcntrl);
	if(CurrentPageName == "SEARCHRESULT")
	{
	 $().hidGatewayParentId.value=0;
	}	
	if($().hidGatewayParentId.value == strBeatOrSourceID)
	{
	$().hidChannelGatewayTrail.value = SubBeatTitle + '~SubBeat~' + strSubBeatOrSubSourceID;
	$().hidCGSearchTrail.value = $().hidChannelGatewayTrail.value;
	 hidcntrl.value = $().hidChannelGatewayTrail.value;
	$().hidGatewayParentId.value = strBeatOrSourceID;
	$().hidGatewayChildId.value = strSubBeatOrSubSourceID;
	AJAX_MethodForBrowseAll();
	}
	else
	{
	    $().hidChannelGatewayTrail.value = strBeatSourceName + '~Beat~' + strBeatOrSourceID + ',' + SubBeatTitle + '~SubBeat~' + strSubBeatOrSubSourceID;
	    $().hidGatewayParentId.value = strBeatOrSourceID;
		$().hidGatewayChildId.value = strSubBeatOrSubSourceID;
		hidcntrl.value = $().hidChannelGatewayTrail.value;
		$().hidCGSearchTrail.value = $().hidChannelGatewayTrail.value;
	    var path = Url;
		$().hidBrowseAllSubmitRequired.value = "1";
		document.forms[0].action = path;
		document.forms[0].method  = "post";
		document.forms[0].submit();
	}
	window.scrollTo(0, 200);
	
	return false; 
	
}


function TabBrowseClick(mode)
	{
	
		var bIsSourceTabClickable = true;
		try
		{
			var mediaType = mode.split("_");
			if(bIsUserLoggedIn == 'False')
			{	
				if(mediaType[1] == 'Sources')
				{
					bIsSourceTabClickable = false;
				}
			}
			if(bIsSourceTabClickable != false)
			{
				$().hidBrowsemediaType.value = mediaType[1];
				
				CallBrowseBy();
			}
			return false; 
		}
		
		catch(ex)
		{
		
		}
	}
	function CallBrowseBy()
	{
	   var objBrowseBy = returnControlId('BrowseAll_ascx') + '_' + 'Browse_ByCallback';	
	   var strCurrentURL;
	   var strCurrentURLInUpperCase;
		strCurrentURL = document.location.href;
		//alert(strCurrentURL);
		strCurrentURLInUpperCase = strCurrentURL.toUpperCase();
				
		if(strCurrentURLInUpperCase.indexOf("CHANNEL_GATEWAY") > 0 )
		{
			if($().hidBrowsemediaType.value != "Beats")
			{
			
				if(strCurrentURLInUpperCase.indexOf("CHANNEL_GATEWAY.ASPX") > 0 )
				{ 
				            
				$().hidBrowseAllSubmitRequired.value = "FALSE";
				}
				else
				{
				$().hidBrowseAllSubmitRequired.value = "TRUE";
				}
			} 
			else
			{
			
			$().hidBrowseAllSubmitRequired.value = "TRUE";
			}
		}	
		else
		{
		$().hidBrowseAllSubmitRequired.value = "TRUE";
		}
				
		eval(objBrowseBy).Callback($().hidBrowsemediaType.value,$().hidBrowseAllSubmitRequired.value);	
	}
	function CallBrowseTab()
	{
	 		
		var objTab = returnControlId('Tab_BrowseAll_ascx');
		
		if($().hidBrowsemediaType.value == 'Sources')
		{
			$(objTab + "_img_Beats").src = strjsImagePath + 'tab_beats_off.gif';
			if(($(objTab + "_img_Sources") == '[object]') || ($(objTab + "_img_Sources") == '[object HTMLInputElement]'))
			{
			$(objTab + "_img_Sources").src = strjsImagePath + 'tab_sources_on.gif';
			}		
			
		}
		if($().hidBrowsemediaType.value == 'Beats')
		{
			$(objTab + "_img_Beats").src = strjsImagePath + 'tab_beats_on.gif';
			if(($(objTab + "_img_Sources") == '[object]') || ($(objTab + "_img_Sources") == '[object HTMLInputElement]'))
			{
			$(objTab + "_img_Sources").src = strjsImagePath + 'tab_sources_off.gif';
			}
		}
	}
	
/* Paging Start */
function  PageNavigationBrowseAllCallBackEnd(param)
{		
	//call the method to populate story control
	CallbackForStoryAssetListing();
}
/* Paging End */



function CallbackForChannelContent()
{
	
	var objChannelContent = returnControlId('ChannelContents_ascx');
	if(objChannelContent != null)
	eval(returnControlId('ChannelContents_ascx') + '_' + 'ChannelContentCallback').Callback();
}

function NarrowResults(AssetType)
{	
	var objcontrolid = returnControlId('StandardSearch_ascx');
	var Search;
	Search = $(objcontrolid + '_txtKeywords').value;
	if($().hidmediaType.value != AssetType)
	{
		$().hidNewTabClick.value = true;
	} 
		
	var hidcntrl = returnControlId('BrowseAll_ascx') + '_' + 'hidGatewayTrail';
		hidcntrl = $(hidcntrl);
		
	if($().hidChannelGatewayTrail.value == "")
	$().hidChannelGatewayTrail.value = hidcntrl.value;
	$().hidCGSearchTrail.value = $().hidChannelGatewayTrail.value;
	$("hidmediaType").value = AssetType;
	AJAX_MethodForBrowseAll();
	CallHeaderTab();
	return false; 
}

function ShowHideControls()
{
	// to hide the MPP
	if(($("ctrMostPopularPlayer") == '[object]') || ($("ctrMostPopularPlayer") == '[object HTMLDivElement]') || ($("ctrMostPopularPlayer") == '[object DIV]'))
	{
		$("ctrMostPopularPlayer").style.visibility = "hidden"; 
		$("ctrMostPopularPlayer").style.display = "none";	
	}
	
	if(($("DIV_" + MPP_PlaceholderId) == '[object]') || ($("DIV_" + MPP_PlaceholderId) == '[object HTMLDivElement]') || ($("DIV_" + MPP_PlaceholderId) == '[object DIV]'))
	{
		$("DIV_" + MPP_PlaceholderId).style.visibility = "hidden";
		$("DIV_" + MPP_PlaceholderId).style.display = "none";
	}
	/*
	if(($("customImage") == '[object]') || ($("customImage") == '[object HTMLDivElement]'))
	{
		$("customImage").style.visibility = "hidden";
		$("customImage").style.display = "none";	
	}
	*/
}
function $(__strId__)
	{
		__doc__ = (typeof __doc__ == "object") ? __doc__ : document;
		__frm__ = (typeof __frm__ == "object") ? __frm__ : (typeof __doc__.forms[0] == "undefined") ? __frm__ : __doc__.forms[0].elements;

		if (arguments.length < 1)
			return __frm__;
		else
			return __doc__.getElementById(__strId__);
	}

