// an external roots array
var _extRoots = null;

function SetExternalRoots(extRootsArr)
{
	if(_extRoots == null)
	{
		_extRoots = extRootsArr;
	}
}


function ResolveHrefs(originalRoot)
{
	//alert(_extRoots);

	// find external root, if appears within the url
	var extRoot = GetExternalRoot();
	if(extRoot != "")
	{
		// get a collection of all HtmlAnchors on screen
		var aCol = document.getElementsByTagName("a");
				
		for (i=0; i<aCol.length; i++)
		{
			var aHref = aCol[i].href.toLowerCase();
			//alert(aHref);
			
			// then we check if this our own app href
			var index = aHref.indexOf(originalRoot.toLowerCase());
			if (index >= 0)
			{
				// ignore VOD links
				// comment out to ignore links to homepage
				if(aHref.indexOf('/vod') > 0 /* || aHref.indexOf('/index.aspx') > 0 || aHref.indexOf('/cm.index,') > 0 */)
				{
					continue;
				}
				
				var pathFromRoot = aCol[i].href.substring(index+originalRoot.length);
				aCol[i].href = extRoot + pathFromRoot;
				//alert(aCol[i].href);
			}
		}
	}
}


function GetExternalRoot()
{
	var url = document.location.href.toLowerCase();
	//alert(url);
	
	// find external root if any
	var foundRoot = "";

	for(i=0; i < _extRoots.length; i++)
	{
		var extRoot = _extRoots[i].toLowerCase();
		//alert(extRoot);


		// try to find within url
		if(url.indexOf(extRoot) != -1)
		{
			foundRoot = extRoot;
			break;
		}
	}

	//alert(foundRoot);
	return foundRoot;
}





