/// <summary>
/// Main JavaScript
/// </summary>
/// <remarks>
/// <para>version: 1.00.0000</para>
/// <para>filename: MainScript.js</para>
/// <para>created: 2006/02/28</para>
/// <para>last revision: 2006/02/28</para>
/// <para>revision history:</para>
/// <para>- 2006/02/28 - EH - file created</para>
/// <para>- 2006/02/28 - EH - Added BookmarkPage function</para>
/// </remarks>



var popupUnternehmensgruppe = "";
var linkNestleUnternehmensgruppe = "http://www.nestle.de/corporate//Templates/Pages/unternehmensgruppe.html";
var linkNestleUnternehmensgruppeAT = "http://www.nestle.at/Marken/default.htm";



function openPopupUnternehmensgruppe()
{
	popupUnternehmensgruppe = window.open(linkNestleUnternehmensgruppe,"unternehmensgruppePopup","width=355,height=370,resizable=no,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no");
	popupUnternehmensgruppe.focus();
}

function openPopupUnternehmensgruppeAT()
{
	popupUnternehmensgruppe = window.open(linkNestleUnternehmensgruppeAT,"unternehmensgruppePopup","width=1024,height=768,resizable=yes,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no");
	popupUnternehmensgruppe.focus();
}


function BookmarkPage(url,title)
{

	//var urlPrefix = "http://localhost";
	//var urlPrefix = "http://integration.nutrition.dev.isc4u.de";
	//var urlPrefix = "http://authoring.babyservice.de"; 
	//var urlPrefix = "http://www.babyservice.de"; 
	//urlPrefix is now added in MainUserControl to each page
  
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) 
	{
		window.external.AddFavorite(urlPrefix + url,title);
	} 
	else if (navigator.appName == "Netscape") 
	{
		window.sidebar.addPanel(title, urlPrefix + url,'');
		//alert("Drücken Sie Strg-D (Netscape und Firefox) um die Seite zu bookmarken");
	} 
	else 
	{
		alert("Drücken Sie Strg-T (Opera) um die Seite zu bookmarken");
	}

}

//var strSiteRootPath = "http://localhost/babyservice";
//var strSiteRootPath = "http://www.babyservice.de";
//strSiteRootPath is added in MainUserControl to each page
function MediaPopup(fileName, width, height)
{
	if(fileName != "" && width != "" && height != "")
	{
		var sOption='toolbar=no,location=no,directories=no,menubar=no,';
		sOption+='scrollbars=no,width=' + width + ',height=' + height + ',left=200,top=225';
		var winprint = window.open(strSiteRootPath + "/components/pages/MediaPopup.aspx?fileName=" + escape(fileName) + "&width=" + width +"&height=" + height ,'',sOption);
		//winprint.document.close();
		winprint.focus();
	}
	else
	{
		var sOption='toolbar=no,location=no,directories=no,menubar=no,';
		var winprint = window.open('','Fehler in den Angaben',sOption);
		winprint.document.open();
		winprint.document.write("Fehlende Angaben");
		//winprint.document.close();
		winprint.focus();
	}
}

function HerbstSpecialPopup(width, height)
{
	if(width != "" && height != "")
	{
		var LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
		var sOption='toolbar=no,location=no,directories=no,menubar=no,';
		sOption+='scrollbars=no,width=' + width + ',height=' + height + ',left=' + LeftPosition + ',top=0';
		var winprint = window.open(strSiteRootPath +  "/herbstspecial/default.html?width=" + width +"&height=" + height ,'',sOption);
		//winprint.document.close();
		winprint.focus();
	}
	else
	{
		var sOption='toolbar=no,location=no,directories=no,menubar=no,';
		var winprint = window.open('','Fehler in den Angaben',sOption);
		winprint.document.open();
		winprint.document.write("Fehlende Angaben");
		//winprint.document.close();
		winprint.focus();
	}
}


function PrintThisPage()
{ 
	var sOption='toolbar=no,location=no,directories=no,menubar=no,';
	sOption+='scrollbars=yes,width=800,height=700,left=100,top=25';
	//var strMainHeader = "Druckvorschau";
	
	
	var strContent = "";
	
	
	// registration sites have a different control container than other sites. This block checks if they exist or not
	//normal content
	try
	{
		strContent = document.getElementById('mainUserControl__ctl1_contentControlContainer').innerHTML;	
	}
	catch(err)
	{
		
	}
	// registration
	try
	{
		strContent = document.getElementById('_ctl0_dynamicContentContainer').innerHTML;		
	}
	catch(err)
	{
		
	}
	
	//
/* Remove in body script to circumvent document.write overwriting content in firefox */
	var sTmpContent		= "";
	var scanComplete	= false;
	var i = 0, j = 0;

	while(!(scanComplete))
	{
		scanComplete = true;

		i = strContent.toLowerCase().indexOf("<script");
		j = strContent.toLowerCase().indexOf("</script>");
		if((-1 != i)&&(-1 != j))
		{
			sTmpContent =  strContent.substring(0, i - 1);
			sTmpContent += strContent.substring(j + 9, strContent.length);
			strContent   = sTmpContent;
			
			scanComplete = false;
		}
	}


/* Replace Links (href) */
	var replacehref=/ href=/gi;
	strContent = strContent.replace(replacehref," dontprinthref=");

/* Replace alt  */
	var replacehref=/ alt=/gi;
	strContent = strContent.replace(replacehref," dontprintalt=");

/* Replace title  */
	var replacehref=/ title=/gi;
	strContent = strContent.replace(replacehref," dontprinttitle=");
	
/* Replace Size of div layers to print properly in IE6 THIS IS A TEMPORARY QUICK FIX, THIS NEEDS TO BE REDONE   */
	if (navigator.userAgent.indexOf("MSIE 6.") != "-1") {
		var re = /654px/gi;
		var re2 = /MARGIN-LEFT: 15px/gi
		var re3 = /<TABLE border=0>/gi
		/*var re4 = /MARGIN-TOP: 0px/gi */
		var re4 = / WIDTH: 674px/gi
		var re5 = /<TABLE cellSpacing=0 cellPadding=0 border=0>/gi
		var re6 = /PADDING-RIGHT: 15px/gi
		var re7 = /PADDING-RIGHT: 20px/gi
		var re8 = /PADDING-LEFT: 10px/gi
		var re9 = /WIDTH: 390px/gi
		var re10 = /WIDTH: 350px/gi
		var re11 = /PADDING-LEFT: 27px/gi
		var re12 = /WIDTH: 312px/gi
		strContent = strContent.replace(re,"625px");
		strContent = strContent.replace(re2,"MARGIN-LEFT: 5px");
		strContent = strContent.replace(re3,"<TABLE border=0 width='580'>");
		/*strContent = strContent.replace(re4,"MARGIN-TOP: 0px; width:315px");*/
		strContent = strContent.replace(re4,"width:315px");
		strContent = strContent.replace(re5,"<TABLE cellSpacing=0 cellPadding=0 border=0 width='580'>");
		strContent = strContent.replace(re6,"PADDING-RIGHT: 0px");
		strContent = strContent.replace(re7,"PADDING-RIGHT: 5px");// diesen ändern für produkt
		strContent = strContent.replace(re8,"PADDING-LEFT: 0px");
		strContent = strContent.replace(re9,"WIDTH: 300px");
		strContent = strContent.replace(re10,"WIDTH: 300px");
		strContent = strContent.replace(re11,"PADDING-LEFT: 5px");
		strContent = strContent.replace(re12,"WIDTH: 300px");
		
	}

	var winprint = window.open('','',sOption);
	winprint.document.open();
	
	winprint.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>");
	winprint.document.write("<html>");
	winprint.document.write("<head>");
	
	var styles,i;
	styles = document.getElementsByTagName('Link');
	for(i in styles)
	{
	  winprint.document.write("<LINK href='" + document.getElementsByTagName('Link')[i].href + "' type='text/css' rel='stylesheet'>");
	}
 
	styles = document.getElementsByTagName('Style');
	for(i in styles)
	{
		winprint.document.write("<style type='text/css'>" + document.getElementsByTagName('Style')[i].innerHTML + "</style>");
	}
	

	winprint.document.write("<title>");
	winprint.document.write("Nestle");
	winprint.document.write("</title>");
	winprint.document.write("</head>");
	winprint.document.write("<body>");
	winprint.document.write("<table cellpadding=0 cellspacing=5 width=625px style='border-top-width: 0px; border-left-width: 0px; float: none; border-bottom-width: 0px; width: 625px; border-right-width: 0px'>");
	winprint.document.write("<tr>");
	winprint.document.write("<td colspan=3 class=print_header>");
	//winprint.document.write(strMainHeader);
	winprint.document.write("</td>");
	winprint.document.write("</tr>");
	winprint.document.write("<tr>");
	winprint.document.write("<td><img src=/Globals/images/blank.gif width=400 height=26></td>");
	winprint.document.write("<td><img src=\"/Globals/images/print_icon.gif\" width=26 height=26 style=\"cursor:hand;\" alt=\"Seite drucken\" title=\"Seite drucken\" onclick=window.print();></td>");
	winprint.document.write("<td><img src=\"/Globals/images/close_icon.gif\" width=26 height=26 style=\"cursor:hand;\" alt=\"Fenster schließen\" title=\"Fenster schließen\" onclick=javascript:window.close();></td>");
	winprint.document.write("</tr>");
	winprint.document.write("<tr>");
	winprint.document.write("<td colspan=3 class=print_content>");
	winprint.document.write(strContent);
	winprint.document.write("</td>");
	winprint.document.write("</tr>");
	winprint.document.write("</table>");
	winprint.document.write("</body>");
	winprint.document.write("</html>");
	winprint.document.close();
	winprint.focus();
}


var m_szDefaultWinHnd = "babyservice";
var m_oPopUpWnd		   = null;	  
function open_pop_up(nHeight, nWidth, bCentered, szURL, bHasScrollBars, szWinName)
	{
	var n_w = 0, n_h = 0; 
	var n_x = 0, n_y = 0;
	var szResizable = null, szScrollBars  = null;

	szResizable = szScrollBars = "no";
	n_w = (nWidth < window.screen.availWidth) ? nWidth : window.screen.availWidth;
	n_h = (nHeight < window.screen.availHeight) ? nHeight : window.screen.availHeight;
	if((nWidth >= window.screen.availWidth)||(nHeight >= window.screen.availHeight))
		szResizable = "yes";		
	n_x = ((window.screen.availWidth) - n_w) / 2; 
	n_y = ((window.screen.availHeight) - n_h) / 2;
	
	if(m_oPopUpWnd)
		if(!(m_oPopUpWnd.closed))
			m_oPopUpWnd.close();
	m_oPopUpWnd = null;		
	
	if(bHasScrollBars)
		szScrollBars = "yes";
	
	if((!(szWinName))||(!(szWinName.length)))
		szWinName = m_szDefaultWinHnd;
		
	if(bCentered)
		m_oPopUpWnd = window.open(szURL, szWinName, "left=" + n_x + ",top=" + n_y + ",resizable=" + szResizable + ",scrollbars=" + szScrollBars + ",menubar=no,location=no,toolbar=no,status=no,width=" + n_w + ",height=" + n_h);
	else
		m_oPopUpWnd = window.open(szURL, szWinName, "resizable=" + szResizable + ",scrollbars=" + szScrollBars + ",menubar=no,location=no,toolbar=no,status=no,width=" + n_w + ",height=" + n_h);
	m_oPopUpWnd.focus();			
	}			
	
function open_product_popup(szURL)
	{
	open_pop_up(400, 600, true, szURL, true);
	}
	
function open_ecoupon_popup(szURL)
	{
	open_pop_up(600, 700, true, szURL, true);
	}