/* Global Variables Decleration Start*/
var __doc__;
var __frm__;
var gblArrStoryId=new Array();
var intCount=0;
var strCartMode='';
var strCartContent=false;
var strDivPageErrorId='';//Error Div Id.
var strDivPageErrorLabelId='';//Label within the Div,on which the error message has to be displayed.
var strControlId='';//Control on which the errorDiv exists.
var strErrorFlag='';//'S' for Story,'A' for Asset.
var blnIsViewContents=0;
var blnIsAddToCart=0;
var arrAssetCount=new Array();
var intCtr=0;
var intTimeOutId;
var intTimeOutBars;
var blnCartErrorMsg = false;
var blnDownloadErrorMsg = false;
var flgIsCartClosed=true;
var intNoOfItems;
var divScrollFlag='';
var flgNoAction=false;
var strOmnitureSearchTrail = '';
var strOmnitureBrowseProcess = '';
var strOmnitureGUID ='';
var strOmnitureSiteSection = '';
var strOmnitureSuggestion='';
var blnOmnitureAdd2Cart = true;
var blnCartLayerCallBackError = false;
/* Global Variables Decleration End*/

//SR9.10
function isNonLoggedInDownloadProcess()
{	
	try
	{
		var strUserLoginType=$(returnControlId('MastHeadHome_ascx') + '_' + 'hdAddToCartFlag').value;		
		if (strDownloadIsNonLoggedInData != '0' && strUserLoginType=='0')
		{
			var strTemp= strDownloadIsNonLoggedInData;
			var arrTemp=strTemp.split('~');
			//alert(arrTemp[0]);
			if (arrTemp[0] != '0' && arrTemp[0] != '')
			{
				AssetdownloadLayer_GetAssetValue(arrTemp[0]);
				AssetDownloadLayer_expandAssetDownload();
			}
		}
	}
	catch(ex)
	{
	}
}
//SR9.10

function isNonLoggedInCartProcess()
{	
	try
	{
		var strUserLoginType=$(returnControlId('MastHeadHome_ascx') + '_' + 'hdAddToCartFlag').value;		
		if (strCartIsNonLoggedInData != '0' && strUserLoginType=='0')
		{
			var strTemp= strCartIsNonLoggedInData;
			var arrTemp=strTemp.split('~');
			cartLayerCallback(arrTemp[0],arrTemp[1],0,'');
		}
	}
	catch(ex)
	{
	}
}

/********************************************************************************************
   Description: 1)Function used to generate the HTML for the Assets which has been just added.
   
   Parameters:  1)strCartData  : String containing data for generating HTML.
				
*********************************************************************************************/
function cart_GenerateCartData(strCartData)
{		
	try
	{
		var arrTemp = strCartData.split('*');
		var arrTempTwo=new Array(arrTemp.length);
		var strHTMLOutput='';
		for(i=0;i<arrTemp.length-1;i++)
		{
			var arrTempOne = arrTemp[i].split('~');
			var assetTypeImage=arrTempOne[0];//Spacer.
			var thumbnail=arrTempOne[1];//Thumbnail.
			var titleLink=arrTempOne[2];//Asset Title Link.
			var title=arrTempOne[3];//Asset Title.
			var source=arrTempOne[4];//Source Title.
			var strSourceFullTitle=arrTempOne[5];//Source Full Title.
			var intSourceId=arrTempOne[6];//Source Id.
			var intAssetTypeId=arrTempOne[7];//Asset TypeId.
			var str='<table cellpadding="0" cellspacing="0" width="100%" border="0">' +
						'<tr>' +
							'<td><img src="' + strjsImagePath + 's.gif" height="13"></td>' +
						'</tr>' +
						'<tr>' +
							'<td align="left">' +
								'<table cellpadding="0" cellspacing="0" width="100%" border="0">' + 
									'<tr>' +
										'<td><img src="' + strjsImagePath + 's.gif" width="5"></td>' +
										'<td valign="top" align="left"><img align="top" src="' + assetTypeImage + '" border="0"></td>' +
										'<td><img src="' + strjsImagePath + 's.gif" width="7"></td>' +
										'<td valign="top" align="left"><a href="Javascript:TitleRedirect(' + titleLink + ')">' + '<img src="' + thumbnail + '" style="height:39; width:53;" border="0"></a></td>' +
										'<td><img src="' + strjsImagePath + 's.gif" width="8"></td>' +
										'<td align="left" style="width:100%"><a class="cartLayerAssetTitleLink" onClick="Javascript:setTimeout(\'' + 'closeCartExtensionLines();' + '\',600);cart_collapse();" href="Javascript:TitleRedirect(' + titleLink + ')">' + title + '</a><br>' +
										'<font class="assetSourceColor">[ Source:</font><a class="cartLayerSourceTitle" onClick="Javascript:setTimeout(\'' + 'closeCartExtensionLines();' + '\',600);cart_collapse();return changePageForSource(\'' + strSourceFullTitle + '\',' + intSourceId + ',' + intAssetTypeId + ');" ' +
										'href="#">' + source + '</a><font  class="assetSourceColor">]</font></td>' +
										'<td><img src="' + strjsImagePath + 's.gif" width="1"></td>' +
									'</tr>' +
								'</table>' + 
							'</td>' +
						'</tr>' +
					'</table>';
			//Store the HTML created for each and every asset into an Temp array.	
			arrTempTwo[i]=str;
		}
		
		//Process the Temp Array and Generate the HTML string.
		strHTMLOutput='<table cellpadding="0" cellspacing="0" height="40" border="0"><tr><td align="left">';
		for(j=0;j<arrTempTwo.length-1;j++)
		{
			strHTMLOutput+=arrTempTwo[j];
			strCartContent=true;
		}
		strHTMLOutput+='</td></tr></table>';
		
		//Assign the Generated HTML to the CartLayer Div.
		$('divCartContents').innerHTML=strHTMLOutput;
		
		//Assign Just added asset count to a string var and then assign to the label for display.
		var strCartCount=$(returnControlId('CartLayer_ascx') + '_hdCartAssetsCount').value;
		$(returnControlId('CartLayer_ascx') + '_snpCartLayer_lblAssetsCount').innerHTML=strCartCount;
		
		intNoOfItems=arrTempTwo.length;
		
		//Fixing the size of the div,at runtime depending on the no. of assets added.
		if(arrTempTwo.length=='2')
		{
			$('divCartContents').style.height="70px";
		}
		else if(arrTempTwo.length=='3')
		{
			$('divCartContents').style.height="140px";
		}
		else
		{
			$('divCartContents').style.height="172px";
		}
		
		if (strHTMLOutput!='' && strCartContent==true)
		{
			$('cartCallbackLoading').style.display="none";
			$('cartTitlesBorder').style.display='block';
			blnIsAddToCart=1;
			$('cartCallbackLoading').style.display="none";
			cart_expand();
			cart_AutoCloseCartLayer('ADD');
		}
		else
		{
			strHTMLOutput='';
		}
	}
	catch(ex)
	{
	}
}

/********************************************************************************************
   Description: 1)Function used to collapse the Cart Layer.
*********************************************************************************************/
function cart_collapse()
{
	draw();
	setTimeout('showselectboxes();',600);
	
	
}
/********************************************************************************************
   Description: 1)Function used to expand the Cart Layer.
*********************************************************************************************/
function cart_expand()
{
	try
	{
		pull();
		setTimeout('showselectboxes();',600);
	}
	catch(ex)
	{
	}
}
/********************************************************************************************
   Description: 1)Function used to auto close the layer,depending the given time stamp.
*********************************************************************************************/
function cart_AutoCloseCartLayer(flg)
{	
	try
	{
		var obj=eval(returnControlId('CartLayer_ascx') + '_hdToggleTime');
		var intTime=obj.value;
		if (flg.toUpperCase()=='ADD')
			intTimeOutId=window.setTimeout("cart_collapse();",intTime);
		intTime=parseInt(intTime)+600;
	}
	catch(ex)
	{
	}
}
/********************************************************************************************
   Description: 1)Function to Process Just Added Assets.
   
   Parameters:  1)intItemId  :Asset(s)/Story(s) id's.
				2)strItemType:'S'-For Story.
							  'A'-For Asset.
   
   Flags     :
				1)strUserLoginType=0: Make a Database entry for the selected cart items,
									  as the user is logged in.(LoggedIn Mode)
				2)strUserLoginType=1: Make a Cookies entry for the selected cart items(NonloggedIn Mode).
				3)strUserLoginType=2: Add to Cart Not allowed(Restrictions flag ON).
				4)strUserLoginType=3: Make a Database entry for the selected cart items in 
									  temp table,as the user is not logged in and UserId 
									  Exists in cookies.(SoftLoggedIn Mode)	
*********************************************************************************************/
function processCart(intItemId,strItemType)
{
	try
	{
		
		$('divPassRemCont').style.display="none";
		blinkErrorImage();
		var strUserLoginType;
		var strAssetsInCookie='';
		var strTotalAssets='';
		
		//Flag which is used for toggling the images.	
		strCartMode='ADD';
		
		showDiv('DivCartLayerTitles');
		
		//The value is retrieved from the hidden field,which is set in the Mast Head.
		strUserLoginType=$(returnControlId('MastHeadHome_ascx') + '_' + 'hdAddToCartFlag').value;		
		if ((strUserLoginType=='0' || strUserLoginType=='3'))
		{
			showDiv('cartCallbackLoading');
			//CallBack for saving the Just added assets to DB and to get the just added asset details for display.
			cartLayerCallback(intItemId,strItemType,strUserLoginType,'');
		}
			
		if (strUserLoginType=='1')
		{
			showDiv('cartCallbackLoading');
			strAssetsInCookie=getCookie('TNM_ADDTOCART_ASSETS');
			if (strAssetsInCookie==null)
				strAssetsInCookie='';
			strTotalAssets = strAssetsInCookie + '*' + intItemId;
			//CallBack to get the details of Just added assets which resides in the cookies.
			cartLayerCallback(strTotalAssets,strItemType,strUserLoginType,'');
		}
		//Add to Cart Not allowed.
		if (strUserLoginType=='2')
		{
			var strDataForAddToCart=$(returnControlId('MastHeadHome_ascx') + '_' + 'hdATCartNloggedInData');
			if (strDataForAddToCart.value != '0')
			{
				strDataForAddToCart.value = intItemId + '~' + strItemType + '~' + 0;
				
				if (document.body.scrollTop == 0)
				{
					var strHidValue=$(returnControlId('MastHeadHome_ascx') + '_' + 'hdErrmsgNonLoginAddToCart').value;
					expandPassRemWithCustomMessage(strHidValue,'N');
				}
				else
				{
					blnCartErrorMsg = true;
					Expand_FloatingLayer();
				}
				blinkErrorImage();
				$('cartCallbackLoading').style.display='none';
				$(returnControlId('MastHeadHome_ascx') + '_' + 'hdACNonlogedVdationFlags').value=strDivPageErrorId + '~' + strDivPageErrorLabelId + '~' + strControlId + '~' + strErrorFlag;
				if ($(returnControlId('MastHeadHome_ascx') + '_' + 'hdCustomLinkFlag').value == "CL")
					$(returnControlId('MastHeadHome_ascx') + '_' + 'hdRegistrationFlag').value="CCART";
				return ;
			}
		}
	}
	catch(ex)
	{
	}
}

/********************************************************************************************
   Description: 1)Duplicate AssetIds will be removed in the Codebehind 
				  and the remaining Asset Ids(Just Added Assets) will be saved to cookies.
   
   Parameters:  1)strItemsToCookies:Just Added AssetId's.
*********************************************************************************************/
function saveAssetIdsToCookies(strItemsToCookies)
{
	try
	{
		setCookie('TNM_ADDTOCART_ASSETS',strItemsToCookies , 365,'/');
	}
	catch(ex)
	{
	}
}

/********************************************************************************************
   Description: 1)Function CartLayer Callback.
   
   Parameters:  1)intItemId		   :StoryId/AssetId.
				2)strItemType      :'S' for Story/'A' for Asset.
			    3)strUserLoginType :0/1/2/3 as specified above. 
*********************************************************************************************/
function cartLayerCallback(intItemId,strItemType,strUserLoginType,strViewContentsFlag)
{
	//Clear the contents of the cart.
	$('divCartContents').innerHTML='';
	$(returnControlId('CartLayer_ascx') + '_snpCartLayer_lblAssetsCount').innerHTML='';
	$(returnControlId('CartLayer_ascx') + '_snpCartLayer_lblStoryTitle').innerHTML='';
	if(strUserLoginType=='0' || strUserLoginType=='3')
	{
		if(getCookie('TNMUserId')==null)
		{
			_LogoRedirectToHome();
		}
	}
	if(!(intItemId=='') ||(strViewContentsFlag.toUpperCase()=='VIEWCONTENTS' && intItemId==''))
		//CallBack to the CodeBehind function.	
		eval(returnControlId('CartLayer_ascx') + '_CartLayerCallback').Callback(intItemId,strItemType.toUpperCase(),strUserLoginType,strViewContentsFlag);
}
/* Function to Post Omniture Data on Successfull completion of Add2Cart Event */
function postOmnitureAdd2CartData()
{
		/* Omniture Phase 4 implementation Starts */
		omnitureFlag=true;
		var strTitle=' ';
		/* eVar9 is used to track Page name */
		s.eVar9= returnOmnPropValue(OmnitureBasePageId,'eVar9');
		/* eVar1 will be posted only for Search results page */
		if (strOmnitureSearchTrail != '')
		{
			s.eVar1 = strOmnitureSearchTrail;
		}
		if(blnOmnitureAdd2Cart == true)
		{
			getQueryVariable();	/* Setting of Query String Variables */
		}
		/* eVar4 and eVar5 to Track Site Sections */
		if (strOmnitureSiteSection.toUpperCase() =='IN') /* 'IN' denotes 'inTheNews' section */
		{
			strTitle=stripChars(document.title.substring(16,document.title.length+1));
			if(strTitle.length > 100)
				strTitle=strTitle.substring(0,100);
			s.eVar4=strTitle;
			/* eVar7 to track Custom Link pages */
			s.eVar7 = strOmnitureGUID;
		}
		else if (strOmnitureSiteSection.toUpperCase() =='SP') /* 'SP' denotes 'specials' section */
		{
			strTitle=stripChars(document.title.substring(16,document.title.length+1));
			if(strTitle.length > 100)
				strTitle=strTitle.substring(0,100);
			s.eVar5=strTitle;
			/* eVar7 to track Custom Link pages */
			s.eVar7=strOmnitureGUID;
		}
		else if (strOmnitureSiteSection.toUpperCase() =='BN') /*  'BN' denotes 'BANNER/Image' section */
		{
			/* eVar7 to track Custom Link pages */
			s.eVar7='banner:'+ strOmnitureGUID;
		}
		/* eVar6 to track Browse Process */		
		if(strOmnitureBrowseProcess != '')
		{
			s.eVar6 = strOmnitureBrowseProcess;
		}
		else
		{	
			if (strOmnitureSuggestion.toUpperCase() == 'SU')
			{
				s.eVar6 = returnOmnPropValue(OmnitureBasePageId,'p3')+ ':' + 'Suggestions-User Profile';
			}
			else if(strOmnitureSuggestion.toUpperCase() == 'SC')
			{
				s.eVar6 = returnOmnPropValue(OmnitureBasePageId,'p3')+ ':' + 'Suggestions-Community';
			}
			else if(strOmnitureSuggestion.toUpperCase() == 'LS')
			{
				s.eVar6 = 'LatestRelease';
			}
		}
		omnitureJsCode('A2C');
		s.pageName="The NewsMarket : Add To Cart";		
		OmnitureControlCallBackStart();
		/* Omniture ends */
}

function getQueryVariable()
{  
	var query = window.location.search.substring(1); 
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) 
	{
	   var pair = vars[i].split("=");
	   if (pair[0] == 'GUID')
	   {
			strOmnitureGUID = pair[1];
	   }
	   if (pair[0] == 'sug')
	   {
			strOmnitureSuggestion = pair[1];
	   }
	   if (pair[0] == 'ss')
	   {
			strOmnitureSiteSection = pair[1];
	   }
	   if (pair[0] == 'lr')
	   {
			strOmnitureSuggestion = pair[1];
	   }
	}
	blnOmnitureAdd2Cart = false;
	
}

/********************************************************************************************
   Description: 1)Function CartLayer callback complete.
   
   Parameters:  1)strCartData      :String used to generate HTML,which has been formed in the 
									codebehind.
				2)strStoryTitle    :If single story added to cart,Story title is displayed.
			    3)strItemsToCookies:Asset Ids which are to be added to cookies.
*********************************************************************************************/
function cartLayerDataForDisplay()
{
	try
	{
		/* Omniture function call */
		postOmnitureAdd2CartData();
		
		var strCartData=$(returnControlId('CartLayer_ascx') + '_hdCartData').value;
		var strStoryTitle=$(returnControlId('CartLayer_ascx') + '_hdStoryTitle').value;
		var strItemsToCookies=$(returnControlId('CartLayer_ascx') + '_hdAssetsIdsToCookies').value;
		var blnStatusFlag=$(returnControlId('CartLayer_ascx') + '_hdViewContentsFlag').value;
		var strIsNonLiveAsset=$(returnControlId('CartLayer_ascx') + '_hdIsNonLiveAsset').value;
		var strUserIncartLimit=$(returnControlId('CartLayer_ascx') + '_hdUserIncartLimit').value;
		
		//Update Your cart as the data is retrieved in from the hidden field,which is set in the codebehind file.
		var temp=$(returnControlId('CartLayer_ascx') + '_hdShoppingCartAssetsCount').value;
		if (temp =='-1')
		{
				document.getElementById('cartCallbackLoading').style.display='none';
				document.getElementById('divCartContents').style.height="80px";
				document.getElementById('divCartContents').innerHTML='<table cellspacing="0" cllpadding="0" border="0">' + 
																	 '<tr><td><img src="' + strjsImagePath + 's.gif" height="10px"></td></tr>' +
																	 '<tr><td class="cartAssetCountFontColor">&nbsp;&nbsp;Please note that some of the assets &nbsp;&nbsp;you added are not ready for delivery &nbsp;&nbsp;today and were not added.</td></tr>' + 
																	 '</table>';
				cart_expand();
				document.getElementById('cartTitlesBorder').style.display='none';
				blnIsAddToCart=1;
				clearTimeout(intTimeOutId);
				cart_AutoCloseCartLayer('ADD');
				return;
		}
		if (temp.toUpperCase()!='NOTHING')
		{
			var arrTemp=temp.split('~');
			$(returnControlId('YourCart_ascx') + '_lblYourCartCount').innerHTML=arrTemp[3];
		}
		
		//Function call for generating HTML for the Assets Just Added.	
		if (strCartData.toUpperCase()!="NOTHING")
		{
			cart_GenerateCartData(strCartData);	
		}
		else 
		{
			
			$('cartCallbackLoading').style.display='none';
			$('DivCartLayerTitles').style.display='none';
							
			if(strIsNonLiveAsset == "1" && blnStatusFlag==0)
			{
				$('divCartContents').style.height="80px";
				$('divCartContents').innerHTML='<table cellspacing="0" cllpadding="0" border="0">' + 
																	 '<tr><td><img src="' + strjsImagePath + 's.gif" height="10px"></td></tr>' +
																	 '<tr><td class="cartAssetCountFontColor">&nbsp;&nbsp;Please note that some of the assets &nbsp;&nbsp;you added are not ready for delivery &nbsp;&nbsp;today and were not added.</td></tr>' + 
																	 '</table>';
				cart_expand();
				$('cartTitlesBorder').style.display='none';
				blnIsAddToCart=1;
			}
			else if(strUserIncartLimit > 0)
			{
				$('divCartContents').style.height="100px";
				$('divCartContents').innerHTML='<table cellspacing="0" cllpadding="0" border="0">' + 
																	 '<tr><td><img src="' + strjsImagePath + 's.gif" height="10px"></td></tr>' +
																	 '<tr><td class="cartAssetCountFontColor">&nbsp;You have reached your cart limit of &nbsp;' + intUserCartMaxCount + ', you can only add a further <<' + strUserIncartLimit + '>> &nbsp;items to your cart. Alternatively, you &nbsp;may also proceed to checkout to &nbsp;remove items from your cart.</td></tr>' + 
																	 '</table>';
				blnIsAddToCart=1;
				$('cartTitlesBorder').style.display='none';
				cart_expand();
			}	
			else if(strUserIncartLimit <= 0)
			{
				$('divCartContents').style.height="90px";
				$('divCartContents').innerHTML='<table cellspacing="0" cllpadding="0" border="0">' + 
																	 '<tr><td><img src="' + strjsImagePath + 's.gif" height="12px"></td></tr>' +
																	 '<tr><td class="cartAssetCountFontColor">&nbsp;You have reached your cart limit of &nbsp;' + intUserCartMaxCount + '. Alternatively, you may also &nbsp;proceed to checkout to remove &nbsp;items from your cart.</td></tr>' + 
																	 '</table>';
				blnIsAddToCart=1;
				$('cartTitlesBorder').style.display='none';
				if(blnCartLayerCallBackError == true)
				{
					document.forms[0].submit();
						
				}
				else
				{
					cart_expand();
				}
			}
			clearTimeout(intTimeOutId);
			cart_AutoCloseCartLayer('ADD');
		}
		
		//Update cookies as the duplicate AssetId's has been removed in the codebehind.
		if (strItemsToCookies.toUpperCase()!='NOTHING')
			saveAssetIdsToCookies(strItemsToCookies);
		
		//Update the Story title,if only single story is added to cart.
		if(strStoryTitle!='')
		{
			showDiv('divStoryTitle');
			$(returnControlId('CartLayer_ascx') + '_snpCartLayer_lblStoryTitle').innerHTML='from: ' + strStoryTitle;
		}
		else
		{
			$('divStoryTitle').style.display="none";
			$('divStoryTitle').style.visible="hidden";
		}
		
	}
	catch(ex)
	{
	}
}

/********************************************************************************************
   Description: 1)Function for maintaining the Asset/Story id which has been selected.
            	2)As the Asset/Story is checked,the corresponding AssetId/StoryId
				  will be stored in the array "gblArrStoryId".
				3)As the Asset/Story is unchecked,the corresponding AssetId/StoryId will be 
				  removed from array "gblArrStoryId".
   
   Parameters:  1)intStoryId: StoryId/AssetId.
*********************************************************************************************/
function addSelectedToCartList(intStoryId)
{   
	try
	{
		if($('chk_'+intStoryId).checked == true)
		{
			gblArrStoryId[intCount]=intStoryId;
			intCount = intCount + 1;
		}
		if($('chk_'+intStoryId).checked == false)
		{
			for(var i=0; i <= gblArrStoryId.length; i++)
			{
				if(gblArrStoryId[i] == intStoryId)
				{
					gblArrStoryId.splice(i,1);
					intCount = intCount - 1;
				}
			}
		}
	}
	catch(ex)
	{
	}
}

/********************************************************************************************
   Description: 1)Function for adding single Item to Cart(Asset/Story).
   
   Parameters:  1)intStoryId : StoryId/AssetId.
			    2)strFlag    : 'S' for Story/'A' for Asset.
*********************************************************************************************/
function addStoryIdToCart(intStoryId,strFlag)
{	
	try
	{
		if(blnIsAddToCart)//If the cart layer is open and the user tries to add the assets/stories to cart.
		{
			clearTimeout(intTimeOutId);
			//flgNoAction=true;
		}
		hideErrPageDiv();
		$('spnLoadingData').innerHTML=returnMessage(15000);
		if (strUserStatus == 'True')
		{
			window.scrollTo(0,0);
		}
		$('spnLoadingData').innerHTML=returnMessage(15000);
		//Function call for firing the callback ,depending on the userlogin type.
		processCart(intStoryId,strFlag);
	}
	catch(ex)
	{
	}
	
}
/********************************************************************************************
   Description: 1)Function for adding Selected Item to Cart(Assets/Stories).
   
   Parameters:  1)strFlag    : 'S' for Story/'A' for Asset.
*********************************************************************************************/
function addSelectedToCart(strFlag)
{
	try
	{
		if(blnIsAddToCart)
		{
			clearTimeout(intTimeOutId);
			//flgNoAction=true;
		}
		// For Closing the Preview Layer, if open
		CloseAssetLayer();	
		hideErrPageDiv();	
		$('spnLoadingData').innerHTML=returnMessage(15000);
		var strList='';
		var arrStoryIds = document.getElementsByTagName("input");
		for (var i=0; i<arrStoryIds.length; i++)
		{
			if (arrStoryIds[i].id.substring(0,4)=='chk_')
			{
				if($(arrStoryIds[i].id).checked == true)
				{
					strList+=document.getElementsByTagName("input").item(i).value + ',';
				}
			}
		}
		if (strUserStatus == 'True')
		{
			window.scrollTo(0,0);
		}
		//Function call for firing the callback ,depending on the userlogin type.
		processCart(strList,strFlag);
	}
	catch(ex)
	{
	}
}

/********************************************************************************************
   Description: 1)Function for adding All Items to Cart(Assets/Stories).
   
   Parameters:  1)strFlag   : 'S' for Story/'A' for Asset.
*********************************************************************************************/
function addAllToCartList(strFlag)
{
	try
	{
		if(blnIsAddToCart)
		{
			clearTimeout(intTimeOutId);
			//flgNoAction=true;
		}
		
		// For Closing the Preview Layer, if open
		CloseAssetLayer();		
		hideErrPageDiv();
		$('spnLoadingData').innerHTML=returnMessage(15000);
		
		var arrStoryIds = document.getElementsByTagName("input");
		var strStoryIds='';
		for (var i=0; i<arrStoryIds.length; i++)
		{
			if (arrStoryIds[i].id.substring(0,4)=='chk_')
			{
				strStoryIds+=document.getElementsByTagName("input").item(i).value + ',';
			}
		}
		if (strUserStatus == 'True')
		{
			window.scrollTo(0,0);
		}
		//Function call for firing the callback ,depending on the userlogin type.
		processCart(strStoryIds,strFlag);
	}
	catch(ex)
	{
	}
}
/********************************************************************************************
   Description: 1)Function for closing the cart layer and re-setting the flags to the 
				  default values.
*********************************************************************************************/

function cart_CloseLayer()
{
	try
	{
		cart_collapse();
		blnIsViewContents=0;
		blnIsAddToCart=0;
	}
	catch(ex)
	{
		
	}
}
/********************************************************************************************
   Description: 1)Function used to set the default values for the Page Error Message which 
				  has to be shown in case of error..
*********************************************************************************************/
function AssetControl_ascx_addToCart()
{
	try
	{
		
		if($("divNoStoryDocs")=='[object]')
			hideDiv('divNoStoryDocs');
		$('DivPageErrorMessageAssetContainer').style.display="none";
		strDivPageErrorId = 'DivPageErrorMessageAssetContainer';
		strDivPageErrorLabelId = 'lblErrorAssetContainer';
		strErrorFlag='A';
		strControlId = 'AssetContainer_ascx';
	}
	catch(ex)
	{
	}	
}

/********************************************************************************************
   Description: 1)Function used to validate the selection of the assets and make a callback 
				  to add the selected assets..
*********************************************************************************************/
function checkForAddSelectedAssets()
{
	try
	{
		// For Closing the Preview Layer, if open
		CloseAssetLayer();
		hideErrPageDiv();
		if($("divNoStoryDocs")=='[object]')
			hideDiv('divNoStoryDocs');
		/*
			Object type across browser
				in IE		--	[object]
				in FireFox	--	[object HTMLInputElement]	:: for HTMLInput Element
								[object HTMLImageElement]	:: for HTMLImage Element
								[object HTMLDivElement]		:: for HTMLDiv Element
				in Netscape	--	same as FireFox
		*/
		
		if ($("hidChkcontrol")== '[object]' || $("hidChkcontrol")== '[object HTMLInputElement]' || $("hidChkcontrol")== '[object INPUT]')
		{
			var strPageName=$("hidChkcontrol").value;
		}
				
		$('DivPageErrorMessageAssetContainer').style.display="none";
		var arrStoryIds = document.getElementsByTagName("input");
		var intCntr=0;
		for (var i=0; i<arrStoryIds.length; i++)
		{
			if (arrStoryIds[i].checked)
			{
				intCntr+=1;
			}
		}
		if(intCntr==0)
		{
			if(strPageName=='SEARCH')
			{	
				
				showDiv('DivPageErrorMessageAssetContainer');
				var strClientId=$(returnControlId('Search_ascx') + '_hidAssetListingClientId').value;
				$(strClientId + '_lblErrorAssetContainer').innerHTML=returnMessage('40014');
				$(strClientId + '_lblPageErrorMessageThree').innerHTML=returnMessage('40035')+": ";
				
				window.scrollTo($("DivPageErrorMessageAssetContainer").offsetTop,$("DivPageErrorMessageAssetContainer").offsetTop);
			}
			else
			{
				
				showDiv('DivPageErrorMessageAssetContainer');
				$(returnControlId('AssetContainer_ascx') + '_' + 'lblErrorAssetContainer').innerHTML=returnMessage('40014');
				$(returnControlId('AssetContainer_ascx') + '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('40035')+": ";
				window.scrollTo($("DivPageErrorMessageAssetContainer").offsetTop,$("DivPageErrorMessageAssetContainer").offsetTop);
			}
		}
		else
		{
			addSelectedToCart('A'); 
		}
		blinkErrorImage();
	}
	catch(ex)
	{
		
	}
}
function hideErrPageDiv()
{
	contractPassRem();
	var aLyrs = document.getElementsByTagName("DIV")
	if ((typeof aLyrs == 'object') || (aLyrs == '[object NodeList]'))
	{
		for (var i=0; i<aLyrs.length; i++)
		{
			if (aLyrs[i].id.substring(0,10)== 'DivPageErr')
			{
				document.getElementsByTagName("DIV").item(i).style.display ='none';
				document.getElementsByTagName("DIV").item(i).style.visibility ='hidden';
			} 
		}
	}
}

/********************************************************************************************
   Description: 1)Function used to validate the selection of the story and make a callback 
				  to add the selected assets.
*********************************************************************************************/	
function checkForAddSelectedStory()
{
	// Close the Preview Layer, if Open
	CloseAssetLayer();
	hideErrPageDiv();
	var arrStoryIds = document.getElementsByTagName("input");
	var intCntr=0;
	
	for (var i=0; i<arrStoryIds.length; i++)
	{
		if (arrStoryIds[i].checked)
		{
			intCntr++;
		}
	}
	strPageName=$("hidChkcontrol").value;
	if(intCntr==0)
	{
		showDiv('DivPageErrorMessage');
		
		var strPageName;
		if(strPageName=='Releases')
		{
			$(returnControlId('MoreReleases_ascx') +  '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80001');
			$(returnControlId('MoreReleases_ascx') +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
			
			blinkErrorImage();
		}
		else if(strPageName=='SEARCH')
		{
			if(strBrowser=="IE")
			{
				$(returnControlId('Search_ascx') + '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80001');
				$(returnControlId('Search_ascx') +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
				blinkErrorImage();
			}
			else
			{
				var strClientId=$(returnControlId('Search_ascx') + '_hidAssetListingClientId').value;
				$(strClientId +  '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80001');
				$(returnControlId('Search_ascx') +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
				$(returnControlId('Search_ascx') + '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80001');
				blinkErrorImage();
			}
		}
		else if(strPageName=='STORYASSETEX')
		{	
			$(returnControlId('StoryAssetListingEx_ascx') +  '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80001');
			$(returnControlId('StoryAssetListingEx_ascx') +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
			blinkErrorImage();
		}
		else
		{
			$(returnControlId('StoryList_ascx') + '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80001');
			$(returnControlId('StoryList_ascx') +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
			blinkErrorImage();
		}
		window.scrollTo($("DivPageErrorMessage").offsetTop,$("DivPageErrorMessage").offsetTop);
	}
	else if(intCntr>=1)
	{
		var blnFlag=false;
		for(j=0; j<= arrAssetCount.length-1; j++)
		{
			var temp=arrAssetCount[j].split(',');
			if(temp[1]>=1)
			{
				blnFlag=true;
				break;
			}
		}
		strPageName=$("hidChkcontrol").value;
		if(!blnFlag)
		{
			showDiv('DivPageErrorMessage');
			
			if(strPageName=='Releases')
			{
				$(returnControlId('MoreReleases_ascx') +  '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80000');
				$(returnControlId('MoreReleases_ascx') +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
				blinkErrorImage();
			}
			else if(strPageName=='SEARCH')
			{
				var strClientId=$(returnControlId('Search_ascx') + '_hidAssetListingClientId').value;
				$(strClientId +  '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80000');
				$(strClientId +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
				blinkErrorImage();
			}
			else if(strPageName=='STORYASSETEX')
			{	
				$(returnControlId('StoryAssetListingEx_ascx') +  '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80000');
				$(returnControlId('StoryAssetListingEx_ascx') +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
				blinkErrorImage();
			}
			else
			{
				$(returnControlId('StoryList_ascx') + '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80000');
				$(returnControlId('StoryList_ascx') +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
				blinkErrorImage();
			}
			window.scrollTo($("DivPageErrorMessage").offsetTop,$("DivPageErrorMessage").offsetTop);
		}
		else
		{
			hideDiv('DivPageErrorMessage');
			strDivPageErrorId = 'DivPageErrorMessage';
			strDivPageErrorLabelId = 'lblPageErrorMessage';
			strErrorFlag='S';
			if(strPageName=='Releases')
			{
				strControlId = 'MoreReleases_ascx';
			}
			else if(strPageName=='SEARCH')
			{
				strControlId=$(returnControlId('Search_ascx') + '_hidAssetListingClientId').value;
			}
			else if(strPageName=='STORYASSETEX')
			{	
				strControlId = 'StoryAssetListingEx_ascx';
			}
			else
			{
				strControlId = 'StoryList_ascx';
			}
			addSelectedToCart('S');
		}
	}
	else
	{
		hideDiv('DivPageErrorMessage');
		hideDiv('DivPageErrorMessage');
		strDivPageErrorId = 'DivPageErrorMessage';
		strDivPageErrorLabelId = 'lblPageErrorMessage';
		strErrorFlag='S';
		if(strPageName=='Releases')
		{
			strControlId = 'MoreReleases_ascx';
		}
		else if(strPageName=='SEARCH')
		{
			strControlId=$(returnControlId('Search_ascx') + '_hidAssetListingClientId').value;
		}
		else if(strPageName=='STORYASSETEX')
		{	
			strControlId = 'StoryAssetListingEx_ascx';
		}
		else
		{
			strControlId = 'StoryList_ascx';
		}
		addSelectedToCart('S');
	}
	blinkErrorImage();
}


/********************************************************************************************
   Description: 1)Function used to validate the selection of the story for assets and make a 
				  callback to add the selected assets.
*********************************************************************************************/		
function checkForNullAssetInStory(chk_Assets,strStoryId,strStoryStatus)
{ 
	var strPageName;
	hideErrPageDiv();
	strPageName=$("hidChkcontrol").value;
	// Close the Asset Preview layer, if Open
	CloseAssetLayer();
	if(chk_Assets==0)
	{
		showDiv('DivPageErrorMessage');
		
		if(strPageName=='Releases')
		{
			$(returnControlId('MoreReleases_ascx') +  '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80000');
			$(returnControlId('MoreReleases_ascx') +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
			blinkErrorImage();
		}
		else if(strPageName=='SEARCH')
		{	
			if(strBrowser=="IE")
			{
				$(returnControlId('Search_ascx') + '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80000');
				$(returnControlId('Search_ascx') + '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
				blinkErrorImage();
			}
			else
			{
				var strClientId=$(returnControlId('Search_ascx') + '_hidAssetListingClientId').value;
				$(strClientId +  '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80000');
				$(returnControlId('Search_ascx') + '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80000');
				$(returnControlId('Search_ascx') + '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
				blinkErrorImage();
			}
		}
		else if(strPageName=='STORYASSETEX')
		{	
			$(returnControlId('StoryAssetListingEx_ascx') +  '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80000');
			$(returnControlId('StoryAssetListingEx_ascx') +  '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
			blinkErrorImage();
		}
		else
		{
			$(returnControlId('StoryList_ascx') + '_' + 'lblPageErrorMessage').innerHTML=returnMessage('80000');
			$(returnControlId('StoryList_ascx') + '_' + 'lblPageErrorMessageThree').innerHTML=returnMessage('80039')+": ";
			blinkErrorImage();
		}
		window.scrollTo($("DivPageErrorMessage").offsetTop,$("DivPageErrorMessage").offsetTop);
	}
	else
	{
		hideDiv('DivPageErrorMessage');
		strDivPageErrorId = 'DivPageErrorMessage';
		strDivPageErrorLabelId = 'lblPageErrorMessage';
		strErrorFlag='S';
		if(strPageName=='Releases')
		{
			strControlId = 'MoreReleases_ascx';
		}
		else if(strPageName=='SEARCH')
		{
			strControlId=$(returnControlId('Search_ascx') + '_hidAssetListingClientId').value;
		}
		else if(strPageName=='STORYASSETEX')
		{
			strControlId = 'StoryAssetListingEx_ascx';
			if(strStoryStatus == '0')
			{
				showDiv('DivPageErrorMessage');
				$(returnControlId('StoryAssetListingEx_ascx') +  '_' + 'lblPageErrorMessage').innerHTML='Sorry! The asset/s for this story you\'ve selected cannot be added to your cart because it is &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currently' + 
																										   ' in a special preview mode and is not available for delivery. Please contact &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;media@thenewsmarket.com if' +
																										   ' you would like to get notified when delivery is enabled.'; 
				blinkErrorImage();
				return false;
			}
		}
		else
		{
			strControlId = 'StoryList_ascx';
		}
		
		
		addStoryIdToCart(strStoryId,'S');
	}
	blinkErrorImage();
}

/********************************************************************************************
   Description: 1)Function used to validate the story for assets and make a callback 
				  to add the selected assets.
*********************************************************************************************/			
function addStoryAssetCountToList(intStoryId,intAssetCount)
{
	// Close the preview layer, if open
	CloseAssetLayer();
	hideErrPageDiv();
	if($('chk_'+intStoryId).checked == true)
	{
		arrAssetCount[intCount]=intStoryId + ',' + intAssetCount;
		intCtr = intCtr + 1;
	}
	if($('chk_'+intStoryId).checked == false)
	{
		for(var i=0; i <= arrAssetCount.length-1; i++)
		{
			var tmp=arrAssetCount[i].split(',');
			if(tmp[0] == intStoryId)
			{
				arrAssetCount.splice(i,1);
				intCtr--;
			}
		}
	}
}

var cartOnclickFlag=false;
var cartMouseOverFlag='';
var cartOnScrollFlag;

function setBodyOnclick()
{
	if(flgNoAction==true)
	{
		flgNoAction=false;
		return false;
	}
	if(cartOnclickFlag==false && flgIsCartClosed==false)
	{
		clearTimeout(intTimeOutId);
		cart_CloseLayer();
		cartOnclickFlag=false;
	}
	else
		cartOnclickFlag=false;
}
function setBodyOnScroll()
{
	if(divScrollFlag!='INNER')
	{
		if(cartOnScrollFlag==0)
		{
			clearTimeout(intTimeOutId);
			cart_CloseLayer();
		}
		cartOnScrollFlag=parseInt(cartOnScrollFlag)+1;
	}
	divScrollFlag='';
		
}
function divScroll()
{
	divScrollFlag='INNER';
}

function setCartOnclick()
{
	cartOnclickFlag=true;
}
if( document.captureEvents && Event.MOUSEMOVE ) {
  //remove this part if you do not need Netscape 4 to work
  document.captureEvents( Event.MOUSEMOVE );
}
document.onmousemove = alertCoord;
var statusFlag='Out';
function alertCoord(e) {
  if( !e ) {
    if( window.event ) {
      //Internet Explorer
      e = window.event;
    } else {
      //total failure, we have no way of referencing the event
      return;
    }
  }
  if( typeof( e.pageX ) == 'number' ) {
    //most browsers
    var xcoord = e.pageX;
    var ycoord = e.pageY;
  } else if( typeof( e.clientX ) == 'number' ) {
    //Internet Explorer and older browsers
    //other browsers provide this, but follow the pageX/Y branch
    var xcoord = e.clientX;
    var ycoord = e.clientY;
    var badOldBrowser = ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
     ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ||
     ( navigator.vendor == 'KDE' )
    if( !badOldBrowser ) {
      if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //IE 4, 5 & 6 (in non-standards compliant mode)
        xcoord += document.body.scrollLeft;
        ycoord += document.body.scrollTop;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE 6 (in standards compliant mode)
        xcoord += document.documentElement.scrollLeft;
        ycoord += document.documentElement.scrollTop;
      }
    }
  } else {
    //total failure, we have no way of obtaining the mouse coordinates
    return;
  }
  
   
 
  if(cartOnScrollFlag=='0' && intNoOfItems=='2') 
  {
	if(!((xcoord>=755 && ycoord>=118) && (xcoord<=990 && ycoord<=347)))
	{
		if(statusFlag=='')
		{
			clearTimeout(intTimeOutId);
			cart_AutoCloseCartLayer('ADD');
			statusFlag='Out';
			return;
		}
	}
	if((xcoord>=755 && ycoord>=118) && (xcoord<=990 && ycoord<=347))
	{
		clearTimeout(intTimeOutId);
		statusFlag='';
		return;
	}
  }
  else if(cartOnScrollFlag=='0' && intNoOfItems=='3') 
  {
	if(!((xcoord>=755 && ycoord>=118) && (xcoord<=990 && ycoord<=417)))
	{
		if(statusFlag=='')
		{
			clearTimeout(intTimeOutId);
			cart_AutoCloseCartLayer('ADD');
			statusFlag='Out';
			return;
		}
	}
	if((xcoord>=755 && ycoord>=118) && (xcoord<=990 && ycoord<=417))
	{
		clearTimeout(intTimeOutId);
		statusFlag='';
		return;
	}
  }
  else if(cartOnScrollFlag=='0' && intNoOfItems>'3')
  {
	if(!((xcoord>=755 && ycoord>=118) && (xcoord<=990 && ycoord<=451)))
	{
		if(statusFlag=='')
		{
			clearTimeout(intTimeOutId);
			cart_AutoCloseCartLayer('ADD');
			statusFlag='Out';
			return;
		}
	}
	if((xcoord>=755 && ycoord>=118) && (xcoord<=990 && ycoord<=451))
	{
		clearTimeout(intTimeOutId);
		statusFlag='';
		return;
	}
  }
}
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__);
	}

//SR9.10 Starts
/********************************************************************************************
   Description: 1)Function for adding single Item to Cart(Asset/Story).
   
   Parameters:  1)intStoryId : StoryId/AssetId.
			    2)strFlag    : 'S' for Story/'A' for Asset.
*********************************************************************************************/
function addStoryIdToDownload(intStoryId,strFlag)
{	
	try
	{
		processDownloadLayer(intStoryId,strFlag);
	}
	catch(ex)
	{
	}
	
}
/********************************************************************************************
   Description: 1)Function to Process Just Added Assets.
   
   Parameters:  1)intItemId  :Asset(s)/Story(s) id's.
				2)strItemType:'S'-For Story.
							  'A'-For Asset.
   
   Flags     :
				1)strUserLoginType=0: Make a Database entry for the selected cart items,
									  as the user is logged in.(LoggedIn Mode)
				2)strUserLoginType=1: Make a Cookies entry for the selected cart items(NonloggedIn Mode).
				3)strUserLoginType=2: Add to Cart Not allowed(Restrictions flag ON).
				4)strUserLoginType=3: Make a Database entry for the selected cart items in 
									  temp table,as the user is not logged in and UserId 
									  Exists in cookies.(SoftLoggedIn Mode)	
*********************************************************************************************/
function processDownloadLayer(intItemId,strItemType)
{
	try
	{
		
		$('divPassRemCont').style.display="none";
		blinkErrorImage();
		var strUserLoginType;
		var strAssetsInCookie='';
		var strTotalAssets='';
		
		//The value is retrieved from the hidden field,which is set in the Mast Head.
		strUserLoginType=$(returnControlId('MastHeadHome_ascx') + '_' + 'hdAddToCartFlag').value;		
				
		if ((strUserLoginType=='0'))
		{	
			AssetdownloadLayer_GetAssetValue(intItemId);
			AssetDownloadLayer_expandAssetDownload();
		}
			
		if ((strUserLoginType=='3'))
		{
			blnDownloadErrorMsg = true;
			Expand_FloatingLayer();	
			blinkErrorImage();
			var strDataForDownload=$(returnControlId('MastHeadHome_ascx') + '_' + 'hdDownloadNloggedInData');
			if (strDataForDownload.value != '0')
			{
				strDataForDownload.value = intItemId + '~' + strItemType + '~' + 0;				
				return ;
			}					
		}
					
		if (strUserLoginType=='1')
		{			
			AssetdownloadLayer_GetAssetValue(intItemId);
			AssetDownloadLayer_expandAssetDownload();
		}		
		
		//Add to Cart Not allowed.
		if (strUserLoginType=='2')
		{	
			if (document.body.scrollTop == 0)
			{
				var strHidValue=$(returnControlId('MastHeadHome_ascx') + '_' + 'hdErrmsgNonLoginDownload').value;
				expandPassRemWithCustomMessage(strHidValue,'N');			
			}
			else
			{
				blnDownloadErrorMsg = true;
				Expand_FloatingLayer();
			}
				
			blinkErrorImage();
						
			var strDataForDownload=$(returnControlId('MastHeadHome_ascx') + '_' + 'hdDownloadNloggedInData');
			if (strDataForDownload.value != '0')
			{
				strDataForDownload.value = intItemId + '~' + strItemType + '~' + 0;
				return ;
			}
			
		}		
	}
	catch(ex)
	{
	}
}
//SR9.10 Ends