//for testing cache
/*function moveToPrivacyPolicy()
{
		//sLink = 'Mrbase/br/Help/TermsAndConditionsPage.aspx?type=5&FromRegistration=1';
		sLink = '../br/Help/TermsAndConditionsPage.aspx?type=5&FromRegistration=1';
		submitPageFE(sLink)
		return true;
}*/

var intCount=0;
var gblArrStoryId=new Array();
var gblArrStoryCount=new Array();
function addSelectedToCart()
{
var strList='';
var AssetCount;
	try
	{
		for(i=0;i<gblArrStoryId.length;i++)
		{
			if(strList!='')
			{
			strList = strList + ','+ gblArrStoryId[i];
			AssetCount=AssetCount + gblArrStoryCount[i];
			}
			else
			{
				strList=gblArrStoryId[i];
				AssetCount=gblArrStoryCount[i];
			}
		}
		
		if(AssetCount==0)
		{
			alert("There are no media assets associated with this story.");		       
			return false;
		}
		else
		{
			if(strList=='')
			{
				alert("To add Media Assets to the Cart, please check at least one Media Asset.");		       
				return false;
				
			}
			else
			{	
				var obj=document.getElementById("hidAddSelectedAssetIDs");
				obj.value = strList;
				
			}
		}
	}
	catch(ex)
	{
	
	}
}
function addSelectedAssetsToCart()
{
var strList='';
var AssetCount;
	try
	{
		for(i=0;i<gblArrStoryId.length;i++)
		{
			if(strList!='')
			{
			strList = strList + ','+ gblArrStoryId[i];
			AssetCount=AssetCount+gblArrStoryCount[i];
			}
			else
			{
				strList=gblArrStoryId[i];
				AssetCount=gblArrStoryCount[i];
			}
		}
		if(strList=='')
		{
			alert("To add Media Assets to the Cart, please check at least one Media Asset.");		       
			return false;
			
		}
		else
		{	
			var obj=document.getElementById("hidAddSelectedAssetIDs");
			obj.value = strList;
			
		}
		
	}
	catch(ex)
	{
	
	}
}
function addSelectedToCartList(intStoryId,intAssetCount)
{  
	
	try
	{
		if(document.getElementById('chk_'+intStoryId).checked == true)
		{
			gblArrStoryId[intCount]=intStoryId;
			gblArrStoryCount[intCount]=intAssetCount
			intCount = intCount + 1;
		}
		if(document.getElementById('chk_'+intStoryId).checked == false)
		{
			for(var i=0; i <= gblArrStoryId.length; i++)
			{
				if(gblArrStoryId[i] == intStoryId)
				{
					gblArrStoryId.splice(i,1);
					gblArrStoryCount.splice(i,1);
					intCount = intCount - 1;
				}
			}
		}
	}
	catch(ex)
	{
	}
	
}

function addAllToCartList()
{  
	try
	{
		var arrStoryIds = document.getElementsByTagName("input");
		var strStoryIds='';
		/*fix for issue 10127 starts*/
		var strAssetCount=new Array();		
		var strIndex;
		var endIndex;
		var storySelectedCount=0;
		var totalAssetCount=0;
		/*fix for issue 10127 ends*/
		
		for (var i=0; i<arrStoryIds.length; i++)
		{
			if (arrStoryIds[i].id.substring(0,4)=='chk_')
			{
				if(strStoryIds!='')
				{
					strStoryIds = strStoryIds + ','+ document.getElementsByTagName("input").item(i).value;
				}
				else
				{
					strStoryIds=document.getElementsByTagName("input").item(i).value;
				}
				
				/*fix for issue 10127 starts*/									
				strIndex=arrStoryIds[i].offsetParent.innerHTML.indexOf(",");
				endIndex= arrStoryIds[i].offsetParent.innerHTML.indexOf(")");					
				
				strAssetCount[storySelectedCount]=arrStoryIds[i].offsetParent.innerHTML.substring(parseFloat(strIndex)+1,parseFloat(endIndex))				
				storySelectedCount++;
				/*fix for issue 10127 ends*/
			}
		}
				
		if(strStoryIds=='')
		{
		    alert("To add Media Assets to the Cart, please check at least one Media Asset.");		       
			return false;
			
		}
		else
		{				
			/*fix for issue 10127 starts*/	
			if(window.location.pathname.search("VideoLibrary.aspx") >0 || window.location.pathname.search("AudioLibrary.aspx") >0 || window.location.pathname.search("DocumentLibrary.aspx") > 0 || window.location.pathname.search("StillLibrary.aspx") > 0)
			{				
				var obj=document.getElementById("hidAddSelectedAssetIDs");
				obj.value = strStoryIds;
			}
			else
			{

				for (var j=0; j<strAssetCount.length; j++)
				{
					totalAssetCount=parseFloat(totalAssetCount) + parseFloat(strAssetCount[j]);				
				}			
				if(totalAssetCount==0 && parseFloat(storySelectedCount)>1)
				{
					alert("There are no media assets associated with these stories.");		       
					return false;
				}
				else if(totalAssetCount==0)
				{
					alert("There are no media assets associated with this story.");		       
					return false;
				}
				else
				{
					var obj=document.getElementById("hidAddSelectedAssetIDs");
					obj.value = strStoryIds;
				}				
			}
			/*fix for issue 10127 ends*/
		}
		
	}
	catch(ex)
	{
	}
	
}
//End Amit
function goPage(strMRserverPath)
{
	window.document.forms[0].action= strMRserverPath + "/br/Login/landing.aspx";
	window.document.forms[0].submit();
}
//cookie functions
function getCookie(NameOfCookie){	
    if (document.cookie.length > 0) {              
    begin = document.cookie.indexOf(NameOfCookie+"=");       
    if (begin != -1) {           
      begin += NameOfCookie.length+1;       
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;      
        return document.cookie.substring(begin, end);
    } 
  }
  return null;
}

/*function setCookie(NameOfCookie, value, expiredays,path) {
	var ExpireDate = new Date ();	
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + value + 
    ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) +
    ((path) ? "; path=" + path : "" );
    
}*/

/*function delCookie (NameOfCookie,path) {	
  if (getCookie(NameOfCookie)) {	
	var Days=3*24*60*60*1000;
	var expDate=new Date()
	expDate.setTime(expDate.getTime()-Days);
    document.cookie = NameOfCookie + "=" +
    ((path) ? "; path=" + path : "" ) +
    "; expires=" + expDate.toUTCString;
  }  
}*/

/*function DoCookieStuff(cookiename,maxSearchValue)
{
	if(maxSearchValue<0)
	{
		return 0;
	}
	else
	{
		if(cookie_check()==1)
		{
			times_visited=eval(getCookie(cookiename))+1;	
			if (times_visited >maxSearchValue) 
			{	
				if(times_visited-maxSearchValue==1)
				{					
					//setCookie(cookiename,times_visited,365,"/");  
				}	
 				return 1;
			}
			else
			{	
				//setCookie(cookiename,times_visited,null,"/");  
				//setCookie(cookiename,times_visited,365,"/");  
				return 0;
			}
		}
		else
		{
			return 1;
		}	
	}
}*/

/*function cookie_check()
{
	document.cookie = "tnmcookie=set"
	if (document.cookie.indexOf("tnmcookie=set")!=-1)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}*/

/*Start -- Added to fix Issue 9432 */
function Paging_PrevNext(iFlag)
	{
	if (typeof(document.getElementById('Search_Values_Name')) == 'object')
				{
					if (document.getElementById('Search_Values_Name') != null)
					document.getElementById('hidDyComps_Selected_Values_Name').value = document.getElementById('Search_Values_Name').value;
				}
				if (typeof(document.getElementById('Search_Values_Id')) == 'object')
				{
					if (document.getElementById('Search_Values_Id') != null)
					document.getElementById('hidDyComps_Selected_Values_Id').value = document.getElementById('Search_Values_Id').value;
				}
				if (typeof(document.getElementById('hidFilterRifineID')) == 'object')
				{
					if (document.getElementById('hidFilterRifineID') != null)
					document.getElementById('hidFilterMainAttributeID').value=document.getElementById('hidFilterRifineID').value;
				}
				if (typeof(document.getElementById('hidYearRifineID')) == 'object')
				{
					if (document.getElementById('hidYearRifineID') != null)
					document.getElementById('hidYearMainAttributeID').value=document.getElementById('hidYearRifineID').value;
				}	
	    var objFrm = window.document.forms[0];//eval('document.'+strForm)
	   	if(iFlag == 0)
		{
			objFrm.hidPageNum.value= parseInt(objFrm.hidPageNum.value,10) -1
		}
		else
		{
			objFrm.hidPageNum.value= parseInt(objFrm.hidPageNum.value,10) + 1
		}
	}	
	/*End -- Added to fix Issue 9432 */
	
	/*Start -- Commented to fix Issue 9432*/
	/*function Paging_SelectedIndexChanged(obj)
	{
	    var objFrm = window.document.forms[0];
	   	//alert(obj[obj.selectedIndex].value)
		objFrm.hidRecordsPerPage.value = obj[obj.selectedIndex].value
//		objFrm.hidSelectedIndexChanged.value='1'
		objFrm.hidPageNum.value = '1'
		document.getElementById('hidFilterMainAttributeID').value=document.getElementById('hidFilterRifineID').value;
		document.getElementById('hidYearMainAttributeID').value=document.getElementById('hidYearRifineID').value;
		document.getElementById('hidBeatsId').value=GetBeatsID()
		document.getElementById('hidSourceId').value=GetSourceID()
		var objTopPage = getObj("objTopPagingControl_cboRecordsPerPage",2)
		var objBottomPage = getObj("objBottomPagingControl_cboRecordsPerPage",2)
		if(typeof(objTopPage) =='object'){
			for(var i=0; i<objTopPage.length;i++){
				if(objTopPage.options[i].value == obj[obj.selectedIndex].value){
					objTopPage.selectedIndex = i;
				}
			}
		}
		if(typeof(objBottomPage) == 'object'){
			for(var i=0; i<objBottomPage.length;i++){
				if(objBottomPage.options[i].value == obj[obj.selectedIndex].value){
					objBottomPage.selectedIndex = i;
				}
			}
		}
		if (typeof objFrm.hidPagesizeChanged == 'object')
		{
			objFrm.hidPagesizeChanged.value = "TRUE";
		}
		objFrm.submit()
	}*/
	/*End -- Commented to fix Issue 9432*/
	
	/*Start -- Added to fix Issue 9432 */
	function Paging_SelectedIndexChanged(obj)
	{
				if (typeof(document.getElementById('Search_Values_Name')) == 'object')
				{
					if (document.getElementById('Search_Values_Name') != null)
					document.getElementById('hidDyComps_Selected_Values_Name').value = document.getElementById('Search_Values_Name').value;
				}
				if (typeof(document.getElementById('Search_Values_Id')) == 'object')
				{
					if (document.getElementById('Search_Values_Id') != null)
					document.getElementById('hidDyComps_Selected_Values_Id').value = document.getElementById('Search_Values_Id').value;
				}
				if (typeof(document.getElementById('hidFilterRifineID')) == 'object')
				{
					if (document.getElementById('hidFilterRifineID') != null)
					document.getElementById('hidFilterMainAttributeID').value=document.getElementById('hidFilterRifineID').value;
				}
				if (typeof(document.getElementById('hidYearRifineID')) == 'object')
				{
					if (document.getElementById('hidYearRifineID') != null)
					document.getElementById('hidYearMainAttributeID').value=document.getElementById('hidYearRifineID').value;
				}	
	    var objFrm = window.document.forms[0];
	   	//alert(obj[obj.selectedIndex].value)
		objFrm.hidRecordsPerPage.value = obj[obj.selectedIndex].value
//		objFrm.hidSelectedIndexChanged.value='1'
		objFrm.hidPageNum.value = '1'
		
		var objTopPage = getObj("objTopPagingControl_cboRecordsPerPage",2)
		var objBottomPage = getObj("objBottomPagingControl_cboRecordsPerPage",2)
		if(typeof(objTopPage) =='object'){
			for(var i=0; i<objTopPage.length;i++){
				if(objTopPage.options[i].value == obj[obj.selectedIndex].value){
					objTopPage.selectedIndex = i;
				}
			}
		}
		if(typeof(objBottomPage) == 'object'){
			for(var i=0; i<objBottomPage.length;i++){
				if(objBottomPage.options[i].value == obj[obj.selectedIndex].value){
					objBottomPage.selectedIndex = i;
				}
			}
		}
		if (typeof objFrm.hidPagesizeChanged == 'object')
		{
			objFrm.hidPagesizeChanged.value = "TRUE";
		}
		objFrm.submit()
	}
	/*End -- Added to fix Issue 9432 */
	
	function setPagingComboValue(strValue)
		{
		var objTopPage = getObj("objTopPagingControl_cboRecordsPerPage",2)
		var objBottomPage = getObj("objBottomPagingControl_cboRecordsPerPage",2)
		if(typeof(objTopPage) =='object')
		{
			for(var i=0; i<objTopPage.length;i++)
				{
					if(objTopPage.options[i].value == strValue)
					{
						objTopPage.selectedIndex = i;
					}
				}
		}
		if(typeof(objBottomPage) == 'object')
		{
			for(var i=0; i<objBottomPage.length;i++)
			{
				if(objBottomPage.options[i].value == strValue)
				{
					objBottomPage.selectedIndex = i;
				}
			}
		}
	}

function popupWin(url, parWidth, parHeight, ch, showStatus, popName,toreSize)
{

	showStatus = (arguments.length==4) ? 'yes' : showStatus;
	popName = (arguments.length==5) ? 'Popup' : popName;
	//toreSize = (arguments.length==6) ? 'no' : toreSize;
	
	if(arguments.length==7)
		toreSize = 'yes'
	else
		toreSize = 'no'
	popName = 'Popup';
		
	pWidth = (parWidth.toUpperCase()=='FULL') ? screen.availWidth : parWidth;
	pHeight = (parHeight.toUpperCase()=='FULL') ? screen.availHeight : parHeight;
	
	var topCal = ((screen.height  - pHeight)/2);
	var leftCal = ((screen.width - pWidth)/2);

	winArgs = 'resizable='+toreSize+',toolbar=0, location=0, directories=0, status=' + showStatus + ', scrollbars=' + ch + ', width=' + pWidth + ', height=' + pHeight + ', left=' + leftCal + ', top=' + topCal;
	//winArgs = 'dialogWidth:'+pWidth+'px;dialogHeight:'+pHeight+'px;dialogTop:'+topCal+'px;dialogLeft:'+leftCal+'px;scroll:'+ch+';status:'+showStatus;
	popWin = window.open("", popName, winArgs);
	//popWin = window.showModalDialog(url,'xxx',winArgs);
	//if(popWin=='true'){
	//	window.location.reload(true);
	//}
	var isQuestPresent = url.indexOf("?");
	var firstPartUrl ='';
	var middlePartUrl = '';
	if(isQuestPresent!=-1)
	{
	
		firstPartUrl = url.substring(0,isQuestPresent);
		if (url.indexOf("objBackTo") != -1)
		{
			middlePartUrl = firstPartUrl+"?objBackTo:hidFromModule=FRONTEND&"
			url = middlePartUrl+url.substring(isQuestPresent+1);
		}
	}
	else
	{
		url = url + "?objBackTo:hidFromModule=FRONTEND"
	}
	
	//Added for handling Unhandled Exceptions through web.config Redirection
	url = url + "&UExisPopup=1"
	
	popWin.location.href=url;

	if (parWidth.toUpperCase()=='FULL' && parHeight.toUpperCase()=='FULL')
		popWin.window.moveTo(0,0);
	
	/*Start -- Added to fix issue NewsM00001107*/
	if(navigator.userAgent.toLowerCase().indexOf('chrome') <= -1)	
		popWin.window.resizeTo(pWidth,pHeight);
	/*End -- Added to fix issue NewsM00001107*/
}
function submitPageFE(strQueryString)
{
	if (typeof document.forms[0].hidPageNum == 'object') 
		{
			document.forms[0].hidPageNum.value = '1';
		}
	if ( typeof window.document.forms[0] == 'object')
	{
		window.document.forms[0].action = strQueryString;
		window.document.forms[0].submit();
	}
}

// Function by raju to enter key
NS4 = (document.layers) ? true : false;

function checkEnter(event,obj,validateFunName)
{ 	
	var code = 0;
	var objbtnlogin
	var bSubmitToValidate
	
	if (NS4)
		code = event.which;
	else
		code = event.keyCode;
		
	if (code==13)
	{
		if (typeof obj == 'object')
		{
			bSubmitToValidate = eval(validateFunName)
			
			if (bSubmitToValidate)
			{
				return true;
			}else
			{
				return false; 
			}
		}
	}
}

// addby raju
// This function called on on load of the body.
/*function onBodyLoad()
{
	objhidEnterClick = document.getElementById(objMastHeadName + '_hidEnterClick')			
		
	if (objhidEnterClick != null)
	{
		if (typeof objhidEnterClick == 'object')
			objhidEnterClick.value = 0;
	}
	
}*/

// added by raju, 
function winReload()
{
	// This code avoids the pop up of the Retry cancel Box and
	// resets the Listing page to the first Page
	window.document.forms[0].submit();
	return true;
		
}

function swapImgRestore(ctrlname,imgname) { 				
	//var e=window.document.getElementById(ctrlname) ;
	ctrlname.src=imgname;				
}

function swapImage(ctrlname,imgname) {
	//var e=window.document.getElementById(ctrlname);					
	ctrlname.src=imgname;	
}

 function setTabSelected(iSelectedIndex){
	var objForm=eval(document.forms[0]); 
	objForm.hidWhichTabSelected.value = iSelectedIndex;
	if (typeof document.forms[0].hidPageNum == 'object') 
	{
		objForm.hidPageNum.value = '1'; // Page Number
	}
	if (typeof document.forms[0].hidDyComps_Selected_Values == 'object') 
	{
		objForm.hidDyComps_Selected_Values.value = ''; // Page Number
	}
	if (typeof document.forms[0].hidYearAttributeID == 'object') 
	{
		objForm.hidYearAttributeID.value = ''; // Page Number
	}
	if (typeof document.forms[0].hidSearchText_Values == 'object') 
	{
		objForm.hidSearchText_Values.value = ''; // Page Number
	}
	objForm.submit();
}

/*function moveToPrivacyPolicy(){
		sLink = '/HelpCenter/HelpCenter.aspx?type=5&FromRegistration=1';
		submitPageFE(sLink)
		return false;
	}*/
		
	function AssetSelectedIndexChanged(obj)
	{	
		var objFrm = window.document.forms[0];
		objFrm.hidAssetTypeChanged.value = "true";	
		objFrm.hidAssetTypeSelected.value = obj[obj.selectedIndex].value
		document.getElementById('hidYearMainAttributeID').value=document.getElementById('hidYearRifineID').value;
		document.getElementById('hidBeatsId').value=GetBeatsID()
		document.getElementById('hidSourceId').value=GetSourceID()
		var AssetType
		if (obj[obj.selectedIndex].value=="1")
		{
			AssetType ="Video"
		}
		else if (obj[obj.selectedIndex].value=="2")
		{
			AssetType = "Audio"
		}
		else if (obj[obj.selectedIndex].value=="3")
		{
			AssetType = "Stills"
		}
		else if (obj[obj.selectedIndex].value=="4")
		{
			AssetType = "Document"
		}else
		{
			AssetType = "Video"
		}	
		
		if (AssetType==document.getElementById('hidFirstRifineAsset').value)
		{
			document.getElementById('hidFilterMainAttributeID').value=document.getElementById('hidFirstFilterRifineID').value
		}
		else
		{
			if(AssetType == "Video")
			{
				document.getElementById('hidFilterMainAttributeID').value=document.getElementById('hidVideoAttributeId').value
			}
			else if(AssetType == "Audio")
			{
				document.getElementById('hidFilterMainAttributeID').value=document.getElementById('hidAudioAttributeId').value
			}
			else if(AssetType == "Stills")
			{
				document.getElementById('hidFilterMainAttributeID').value=document.getElementById('hidStillAttributeID').value
			}
			else if(AssetType == "Document")
			{
				document.getElementById('hidFilterMainAttributeID').value=document.getElementById('hidDocumentAttributeId').value
			}
			
		}
		if(typeof document.forms[0].hidWhichTabSelected == 'object')
			{
				strURL="../CommonPages/StoriesAssetsListing.aspx"
			}
			else
			{
				strURL="../Asset/AssetListing.aspx"
			}
		
		if (strURL !='')
			{
				document.forms[0].action=strURL;
				document.forms[0].submit();
			}
			else
			{
				objFrm.submit();
			}
		//objFrm.submit();
	}

	function setTab(iSelectedIndex,iTabIndex)
	{
		var objForm=eval(document.forms[0]); 
		objForm.hidSelectedAssetTab.value = iSelectedIndex; //Actuall Tab Selected
		objForm.hidTabIndex.value = iTabIndex; //TAb Position.
		objForm.hidPageNum.value = '1'; // Page Number
		objForm.hidAssetTypeChanged.value = "true"; //For Asset Control	
		objForm.hidAssetTypeSelected.value = iSelectedIndex;
		objForm.submit();
	}

	function setOrderHistoryTab(iSelectedIndex){
	var objForm=eval(document.forms[0]); 
	objForm.hidTabSelected.value = iSelectedIndex;
	objForm.hidPageNum.value = '1'; // Page Number
	objForm.submit();
	}