// an array of cache tokens
var _cacheTokens = null;

function SetCacheTokens(cacheTokensArr)
{
	if(_cacheTokens == null)
	{
		_cacheTokens = cacheTokensArr;
	}
}


function ResolveIframeSource()
{
	//alert(_cacheTokens);

	// find cache operator
	var operator = GetCacheOperator();
	if(operator != "")
	{
		// cache operation required
		operator += '=true';
		
		// get a collection of all IFRAMEs on screen
		var ifrCol = document.getElementsByTagName("iframe");
				
		for (i=0; i<ifrCol.length; i++)
		{
			var ifrSrc = ifrCol[i].src;
			//alert(ifrSrc);
			
			// then we check if this our own app IFRAME
			if (ifrSrc.indexOf("aspx") > 0)
			{
				// replace the src for the IFRAME
				if (ifrSrc.indexOf("?") > 0)
				{
					// append to query params
					ifrCol[i].src = ifrSrc + "&" + operator;
				}
				else
				{
					// create new query param
					ifrCol[i].src = ifrCol[i].src + "?" + operator;
				}
				//alert(ifrCol[i].src);
			}
		}
	}
}


function GetCacheOperator()
{
	var url = document.location.href.toLowerCase();
	//alert(url);
	
	// find cache operator
	var operator = "";

	for(i=0; i < _cacheTokens.length; i++)
	{
		var cacheToken = _cacheTokens[i].toLowerCase();
		//alert(cacheToken);


		// try to find within query string
		if(url.indexOf(cacheToken + "=true") != -1)
		{
			operator = cacheToken;
			break;
		}
	
		// try to find within cookies
		/*
		var cookieVal = readCookie(cacheToken).toString().toLowerCase();
		//alert(cookieVal);
		
		if(cookieVal == "true")
		{
			operator = cacheToken;
			break;
		}
		*/
	}

	//alert(operator);
	return operator;
}





