

	//-----------------------------------------------------------------------------------------------------------------------------
	//-- Bespoke Ajax Functions for App, needs Ajax.js
	//-----------------------------------------------------------------------------------------------------------------------------
	
	var strCookieName = "VictoryBannerCookie";
	var arGUIDStore = new Array ();	
	var strSiteRoot = "";
	var bTrace = false;
	
	//-----------------------------------------------------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------------------------------------------------	
		
	function JS_Custom_CookieToSession ( strSiteRootParam )
	{
		if ( bTrace ) alert ( "JS_Custom_CookieToSession" );
		
		strSiteRoot = strSiteRootParam;
		var strCookieValue = JS_Custom_ReadCookie();
		if ( strCookieValue ) JS_Ajax_SendQuery ( "convert cookie to session", JS_Custom_AjaxComplete, strCookieValue, strSiteRoot ); // use ajax to put cookies into session
	}
	
	function JS_Custom_AjaxComplete ( strResponse )
	{
		if ( bTrace ) alert ( "JS_Custom_AjaxComplete" );
		
		arBadGUIDS = strResponse.split(",");
		if ( arBadGUIDS.length > 0 )
		{
			for ( var n=0; n<arBadGUIDS.length; n++ )
			{
				JS_Custom_TrimCookie ( arBadGUIDS[n] );  // delete bad cookies
			}
		}
		
		JS_Custom_UpdateBasketCount(); // good cookies are now in session, update basket count
	}

	function JS_Custom_UpdateBasketCount ()
	{	
		if ( bTrace ) alert ( "JS_Custom_UpdateBasketCount" );
		
		if ( JS_Custom_IsLoggedIn() )
		{
			JS_Ajax_SendQuery ( "count banners for user", "spanBasketCount", "", strSiteRoot ); // update basket count
		}
		else
		{
			JS_Ajax_SendQuery ( "count banners in session", "spanBasketCount", "", strSiteRoot ); // update basket count
		}
	}	
	
	//-----------------------------------------------------------------------------------------------------------------------------
	//-- 
	//-----------------------------------------------------------------------------------------------------------------------------	
	
	function JS_Custom_CookieToArray ()
	{
		var strCookieValue = JS_Custom_ReadCookie();
		if ( strCookieValue ) arGUIDStore = strCookieValue.split(",");	
	}
	
	function JS_Custom_AppendCookie ( strNewItem )
	{		
		if ( JS_Utils_InArray ( strNewItem, arGUIDStore ) == -1 ) arGUIDStore.push ( strNewItem );
	}
	
	function JS_Custom_CreateCookie ( strGUID )
	{
		if ( bTrace ) alert ( "JS_Custom_CreateCookie = " + strGUID );
		
		if ( JS_Custom_IsLoggedIn() )
		{
			// dont create a cookie
		}
		else
		{
			if ( strGUID.length > 10 )
			{
				JS_Custom_CookieToArray();
				JS_Custom_AppendCookie(strGUID);
				JS_Cookie_Create ( strCookieName, arGUIDStore, 30 );
			}
		}
	}
	
	function JS_Custom_ReadCookie ()
	{
		return JS_Cookie_Read ( strCookieName );
	}
	
	function JS_Custom_TrimCookie ( strGUID )
	{
		JS_Custom_CookieToArray();
		
		var nIndex = JS_Utils_InArray ( strGUID, arGUIDStore ); // get index of item to delete
		if ( nIndex > -1 )
		{
			arGUIDStore.splice(nIndex,1); // slice item
			JS_Cookie_Create ( strCookieName, arGUIDStore, 30 );
		}
	}
	
	function JS_Custom_EraseCookie ()
	{
		JS_Cookie_Erase ( strCookieName );
		//alert ( "Erased" );
	}
	
	function JS_Custom_IsLoggedIn ()
	{
		if ( typeof ( window[ 'bLoggedIn' ] ) != "undefined" )
		{
			if ( bLoggedIn )
			{
				return true;
			}
			else
			{
				return false;
			}			
		}
		else
		{
			return false;
		}
	}
	
	//-----------------------------------------------------------------------------------------------------------------------------
	//-- Banner Select
	//-----------------------------------------------------------------------------------------------------------------------------		
	
	var objPrev;
	
	function JS_Custom_BringToFront ( objElement )
	{
		if ( objPrev ) objPrev.style.zIndex = 1;	
		objElement.style.zIndex = 2;
		objPrev = objElement;
	}
	
	function JS_Custom_HideAllOptions ( )
	{
		var arUL = document.getElementsByTagName("ul");
		for ( var n=0; n<arUL.length; n++ )
		{
			if ( arUL[n].className == "Options" ) arUL[n].style.display = "none";
		}
	}		
	
	function JS_Custom_ShowOptions ( objElement )
	{
		JS_Custom_HideAllOptions (); // hide any visible options lists
		JS_Custom_BringToFront ( JS_Utils_GetParent(objElement) ); // bring current row to front
		
		// show current item list
		var arUL = objElement.getElementsByTagName("ul");
		arUL[0].style.display = "block";
	}	
	
	function JS_Custom_HideOptions ( objElement )
	{
		JS_Custom_HideAllOptions (); // hide any visible options lists
	}
	
	//-----------------------------------------------------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------------------------------------------------

