// <summary>
// Some common javascripts (only client side)
// </summary>
// <remarks>
// <para>version: 1.0.0.0</para>
// <para>Filename: Common.js</para>
// <para>created: 2008/04/17</para>
// <para>last revision: 2008/04/17</para>
// <para>revision history:</para>
// <para>- 2008/04/17 - AK - class created.</para>
// </remarks>

function popWindow (url,name,params) {
//fuer Fenster die auf onlick in einem a href aufgehen
    pwin=window.open(url, name, params);
    pwin.focus();
    return false;
}

function closeWindow() {
    if ((typeof newWin == 'object') && (! (newWin.closed))) newWin.close();
}

function openSelectboxLink(object)
{
	var objectValue = object[object.selectedIndex].value.replace("/Channels","");
	if (objectValue == "") return;
	self.location.href = objectValue;
}

function openCompanySelect()
{
	var selectBox = document.getElementById("selectboxCompanySelect");
	var linkUrl = selectBox[selectBox.selectedIndex].value;
	closeWindow();
	newWin=window.open(linkUrl,"","");
	try{
		newWin.focus();
	}catch(e){
	}
}

function openMaggiRecipe(id){
	recipeUrl='http://www.maggi.de/RecipeOnline?s=0&action=print&partner=_Nestle&id='+id
	openWindow(recipeUrl,'MAGGIREZEPT','top=50,left=50,width=610,height=580,scrollbars=yes,menubar=yes,resizable=no');
}

function openNestleRecipe(id){
	recipeUrl=appPath+'/RezepteUndKochtipps/Rezepte/PopRezept.aspx?contentKey='+id+'&sid='+sid;
	openWindow(recipeUrl,'NestleRezept','top=50,left=50,width=608,height=630,scrollbars=yes,menubar=yes,resizable=no');
}
// add article to leavelet
function getSiteArea()
{
	if(document.getElementById('siteArea')!=null) siteAreaText=document.getElementById('siteArea').innerHTML.replace('&gt;&nbsp;','');
	else siteAreaText=getSiteTitle();
	return UrlEncodieren(siteAreaText);
}

function getPageTitle()
{
	var pageHeadlineMain = document.getElementById("HeadlineMain");
	var pageHeadline = document.getElementById("HeadlineAndContent").getElementsByTagName("h1")[0];
	
	var pageHeadlineMainText = "";
	var pageHeadlineText = "";
	
	for (var i=0; i<pageHeadlineMain.childNodes.length; i++)
		if (pageHeadlineMain.childNodes[i].nodeValue != null) pageHeadlineMainText += String(pageHeadlineMain.childNodes[i].nodeValue) + " ";
	
	for (var i=0; i<pageHeadline.childNodes.length; i++)
		if (pageHeadline.childNodes[i].nodeValue != null) pageHeadlineText += String(pageHeadline.childNodes[i].nodeValue) + " ";
	
	var pageTitle = pageHeadlineMainText;
	if (pageHeadlineText != "") pageTitle += " - " + pageHeadlineText;
	
	return UrlEncodieren(pageTitle);
}

function AddToLeaflet(){
	var siteAreaText = escape(getSiteArea());
	var siteTitleText = escape(getSiteTitle());
	if(siteTitleText==siteAreaText){
		siteTitleText=UrlEncodieren("Übersicht");
	}
	siteUrlText=encodeURIComponent(window.location+"");
	openWindow(appPath+'/MeinNestle/Merkzettel/articlePopup.aspx?sid='+sid+'&topic='+siteAreaText+'&name='+siteTitleText+'&url='+siteUrlText,'leaflet','width=496,height=145,resizable=yes,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,left=20,top=40');
}

function UrlEncodieren(headline) {
	return headline.replace(/ä/g, "%E4").replace(/ö/g, "%F6").replace(/ü/g, "%FC").replace(/ß/g, "%DF").replace(/&/g, "%26").replace(//g,"-").replace(//g,"%22").replace(//g,"%22");
}

function scrollBottom()
{
	window.scrollTo(0,5000);
}

var popupUnternehmensgruppe = "";

function openPopupUnternehmensgruppe()
{
	popupUnternehmensgruppe = window.open(appPath + "/Templates/Pages/unternehmensgruppe.html","unternehmensgruppePopup","width=355,height=380,resizable=no,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no");
	popupUnternehmensgruppe.focus();
}

function showLayer(index)
{
	var scrollPosition, visibleHeight;
	if (document.all)
	{
		scrollPosition = document.documentElement.scrollTop;
		visibleHeight = document.documentElement.clientHeight;
	}
	else
	{
		scrollPosition = window.pageYOffset;
		visibleHeight = window.innerHeight;
	}

	var targetContainer = document.getElementById("ContentLayer");
	if (targetContainer == null) return;
	var targetLayerArray = targetContainer.getElementsByTagName("div");
	
	for (var i=0; i<targetLayerArray.length; i++)
		targetLayerArray[i].style.display = "none";
	
	if (index > 0 && index <= targetLayerArray.length)
	{
		targetContainer.style.top = (scrollPosition + (visibleHeight/2-100)) + "px";
		targetLayerArray[index-1].style.display = "block";
	}
}

var popupImageUrl, popupText, fotospecialPopup;
function openFotospecialPopup(LinkObject)
{
	if (LinkObject.parentNode.getElementsByTagName("td")[1].childNodes.length == 0) return;
	
	var index = 1;
	if (LinkObject.nextSibling.nodeName == "#comment") index = 2;
	
	var popupContentCells = LinkObject.parentNode.parentNode.getElementsByTagName("tr")[index].getElementsByTagName("td");
	popupImageUrl = popupContentCells[0].firstChild.getAttribute("src");
	popupText = popupContentCells[1].firstChild.data;
		
	fotospecialPopup = window.open(appPath + "/Templates/Pages/fotospecialpopup.html","fotospecialdetail","height=400,width=590,left=100,top=100,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
	setTimeout(setFotospecialPopupContent,1000);
	fotospecialPopup.focus();
}

function setFotospecialPopupContent()
{
	fotospecialPopup.document.body.style.backgroundImage = "url(" + popupImageUrl + ")";
	fotospecialPopup.document.getElementsByTagName("p")[0].appendChild(fotospecialPopup.document.createTextNode(popupText));
}

var setCellHeightAllowed = true;
function setCellHeight()
{
	if (!setCellHeightAllowed) return;
	var visibleHeight;
	if (document.all) visibleHeight = document.documentElement.clientHeight;
	else visibleHeight = window.innerHeight;
	
	document.getElementById("basisSpalteMitte").style.height = (visibleHeight - 17) + "px";
}
