/*****************************************************************************
*
*	on load page stuff
*
******************************************************************************/

function initNewsExplorerPage()
{
	initLangSelection();
	setTimelineImg();
	correctPNG();
	SWFworkarround();
}

/*****************************************************************************
*
*	correctly handle PNG transparency in Win IE 5.5 & 6. 
*   http://homepage.ntlworld.com/bobosola/index.htm
*
******************************************************************************/

function correctPNG() 
{
	if (navigator.appVersion.indexOf("MSIE") != -1)
	{
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])
		if ((version >= 5.5) && (version < 7.0)  &&(document.body.filters)) 
		{
			for(var i=0; i<document.images.length; i++)
			{
				var img = document.images[i]
				var imgName = img.src.toUpperCase()
				if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
				{
					var imgID = (img.id) ? "id='" + img.id + "' " : ""
					var imgClass = (img.className) ? "class='" + img.className + "' " : ""
					var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
					var imgStyle = "display:inline-block;" + img.style.cssText 
					
					if (img.align == "left") imgStyle = "float:left;" + imgStyle
					if (img.align == "right") imgStyle = "float:right;" + imgStyle
					if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
					
					var strNewHTML = "<span " + imgID + imgClass + imgTitle
						+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
						+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
						+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
					img.outerHTML = strNewHTML
					i = i-1
				}
			}
		}
	}  
}     
/*****************************************************************************
*
*	Set timeline image
*
******************************************************************************/
function setTimelineImg()
{
	var img = document.getElementById("timeline_img");
	if (img!=null)
	{
		var form =document.forms['formPage'];
		var page = form.elements["page"];
		
		img.src = HM_PL_ImageDir + 'png-cache/timeline/' +HM_PL_Language+'/' + page.value.substr(0, 6) +'.png';
	}
}

/*****************************************************************************
*
*	Navigation
*
******************************************************************************/

function gotopage(nPage)
{
	var form =document.forms['formPage'];
	form.page.value=nPage;
	form.submit();
}

function gotolanguage(language)
{
	var form =document.forms['formPage'];
	var edition=form.elements["edition"].value;
	var page = form.elements["page"].value;
	var option = form.elements["option"].value;

	if (edition == 'clusteredition' || edition == 'storyedition' || edition == 'search' || edition=='storyindex')
	{
		edition='home';
		page='latest';
	}
	
	if (edition == 'dayedition')
	{
		if(option == 'latest')
			edition = 'home';
	}

	if (edition == 'timelineedition' || edition == 'entities' || edition == 'search' || edition == 'liveindex' || edition == 'liveedition')
	{
		page = option;
	}

	if (edition == 'home')
	{
		page = 'latest';
	}
	
	//if (window.location.pathname.indexOf('/latest.') != -1) page = 'latest';
			
	window.location.href=HM_PL_ImageDir + edition + '/'+language+'/' + page + '.html';
	
}

/*****************************************************************************
*
*	Language logic
*
******************************************************************************/

function initLangSelection()
{
	var obj = document.forms['langSelect']['select_lang'];
	obj.selectedIndex = -1;
	for (var i=0; i<obj.options.length; i++) {
		if (obj.options[i].value == HM_PL_EMMLocale) {
			obj.options[i].selected = true;
		}
	}
}

/*****************************************************************************
*
*	Display some additinal (hidden) tips
*
******************************************************************************/

function OnShowMore(me)
{
	var el=me.parentNode.nextSibling;
	
	if (el.nodeName!='DIV') el=el.nextSibling; // Netscape likes to see a text node here...
	if (el.style.display=='none')
	{
			el.style.display='inline';
	}
		else
	{
			el.style.display='none';
	}
}

function OnShowMuchMore()
{
	var items=document.getElementsByName("alert_more");
	var value='inline';
	
	if (items.length>0 && items[0].style.display=='inline') value='none';
	
	for (var i=0; i<items.length;i++)
	{
		items[i].style.display=value;
	}
}

/*****************************************************************************
*
*	Search
*
******************************************************************************/

function dosearch()
{
	var form =document.forms['formSearch'];
	var items=document.getElementsByName("search");
	form.elements["query"].value = items[0].value;
	form.submit();
}

/*****************************************************************************
*
*	Show help
*
******************************************************************************/
var oldHelpWindow = null

function OnShowHelp(page)
{
		var helpWindow = window.open(HM_PL_ImageDir+page,"NewsExplorerHelp","");
		if (oldHelpWindow == helpWindow)
			helpWindow.markHelp();
		oldHelpWindow = helpWindow
}

var oldHelpID = null

function markHelp()
{
	if(this.oldHelpID != null && this.oldHelpID != "")
	{
		var el=this.document.getElementById(this.oldHelpID);
		if (el!=null)
		{
			el.className="";
		}
		this.oldHelpID = null;
	}

	var helpid=this.window.location.hash
	if(helpid != null && helpid != "")
	{
		helpid = helpid.substring(1);
		var el=this.document.getElementById(helpid);
		if (el!=null)
		{
			el.className="seleced_help";
			this.oldHelpID = helpid;
		}
	}
}

