
/*----------------------------------------------------------------------------
GENERAL.JS

Copyright by
plenum stoll & fischbach Communication GmbH,
Herrenberg, Germany

general.js 			contains functions for general purposes
----------------------------------------------------------------------------*/


//	openWindow()
//
//	Arguments:
//	- uri (required):			uri to be opened
//	- windowName (optional):	name of browser window
//	- windowStyle (optional):	style of browser window (as string)
//
//	what:	opens a new browser window
//	note:	this function provides same functionality as target="_blank"
//			as long as windowStyle is empty: ''

/*
function openWindow(uri,windowName,windowStyle)
{
	if (windowName == '') windowName = 'newWindow';
	if (typeof(thisWindow) != ('undefined')) thisWindow.close();
	thisWindow = window.open(uri,windowName,windowStyle);
	setTimeout('thisWindow.focus()',100);
}
*/

var nw;

window.onunload = function() {
	if(nw && !nw.closed) {
		nw.close();
	}
}

function openWindow(uri,windowName,windowStyle)
{
	if (windowName == '') windowName = 'newWindow';
	if(nw && !nw.closed){
		nw.close();
	}
	nw=window.open(uri,windowName,windowStyle);
	if(nw){
		nw.focus();
	}
}

//	openWindowImg()
//
//	Arguments:
//	- uri (required):			uri to be opened
//	- windowName (optional):	name of browser window
//	- windowStyle (optional):	style of browser window (as string)
//
//	what:	opens a new browser window for images
function openWindowImg(uri,windowName,windowStyle)
{
	windowName = windowName.replace(/ /,"");
	if (windowName == '') windowName = 'newWindow';
	if (typeof(thisWindow) != ('undefined')) thisWindow.close();

	var doctype = buildHtmlDoctype4Img(uri,windowName);

	thisWindow = window.open('',windowName,windowStyle);
	var winWidth = parseInt(extractString(windowStyle,'width=',','));
	var winHeight = parseInt(extractString(windowStyle,'height=',','));
	thisWindow.resizeTo(winWidth,winHeight);
	thisWindow.innerWidth = winWidth;
	thisWindow.innerHeight = winHeight;
	thisWindow.document.write(doctype);
	setTimeout('thisWindow.focus()',100);
}

//	openWindowFullScreen()
//
//	Arguments:
//	- uri (required):			uri to be opened
//
//	what:	opens a new browser window in full screen size and
//			with original user browser properties
//	note:	works not when uri links to another domain
function openWindowFullScreen(uri)
{
	thisWindow = window.open(location.protocol + '//'+location.hostname,'newWindow');
	thisWindow.resizeTo(screen.availWidth,screen.availHeight);
	thisWindow.location.href = uri;
	thisWindow.moveTo(0,0);
	setTimeout('thisWindow.focus()',100);
}


//	openWindowInherit()
//
//	Arguments:
//	- uri (required):				uri to be opened
//	- windowName (required):		window name
//	- left (required):				window left
//	- top (required):				window top
//	- width (required):				window width
//	- height (required):			window height
//
//	what:	opens a new browser window with possibility to set size and
//			with original user browser properties
//	note:	works not when uri links to another domain
var thisWindowInherit;
function openWindowInherit(uri,windowName)
{
	if (typeof(thisWindowInherit) != ('undefined')) thisWindowInherit.close();

	var windowWidth;
	var windowHeight;

	var UserAgent = navigator.userAgent.toLowerCase();

	if (UserAgent.indexOf('msie') != -1)
	{
		windowWidth = parseInt(document.body.offsetWidth) + 25; // ungefähre Werte, es wird body abgefragt, Fenstergröße kann nicht abgefragt werden
		windowHeight = parseInt(document.body.offsetHeight) + 210; // ungefähre Werte, es wird body abgefragt, Fenstergröße kann nicht abgefragt werden
	}
	else
	{
		windowWidth = window.outerWidth;
		windowHeight = window.outerHeight;
	}

	thisWindowInherit = window.open('http://'+location.hostname,windowName);
	thisWindowInherit.resizeTo(windowWidth,windowHeight);
	thisWindowInherit.moveTo(0,0);
	thisWindowInherit.location.href = uri;
	setTimeout('thisWindowInherit.focus()',100);
}


//	openWindowInheritWithinFrame()
//
//	Arguments:
//	- uri (required):				uri to be opened
//	- windowName (required):		window name
//	- left (required):				window left
//	- top (required):				window top
//	- width (required):				window width
//	- height (required):			window height
//
//	what:	opens a new browser window with possibility to set size and
//			with original user browser properties
//	note:	works not when uri links to another domain
var thisWindowInheritWithinFrame;
function openWindowInheritWithinFrame(uri,windowName)
{
	if (typeof(thisWindowInheritWithinFrame) != ('undefined')) thisWindowInheritWithinFrame.close();

	var windowWidth;
	var windowHeight;

	var UserAgent = navigator.userAgent.toLowerCase();

	if (UserAgent.indexOf('msie') != -1)
	{
		windowWidth = parseInt(parent.document.body.offsetWidth) + 5; // ungefähre Werte, es wird body abgefragt, Fenstergröße kann nicht abgefragt werden
		windowHeight = parseInt(parent.document.body.offsetHeight) + 130; // ungefähre Werte, es wird body abgefragt, Fenstergröße kann nicht abgefragt werden
	}
	else
	{
		windowWidth = window.outerWidth;
		windowHeight = window.outerHeight;
	}

	thisWindowInheritWithinFrame = window.open('http://'+location.hostname,windowName);
	thisWindowInheritWithinFrame.resizeTo(windowWidth,windowHeight);
	thisWindowInheritWithinFrame.moveTo(0,0);
	thisWindowInheritWithinFrame.location.href = uri;
	setTimeout('thisWindowInheritWithinFrame.focus()',100);
}


//	openWindowInheritWithSize()
//
//	Arguments:
//	- uri (required):				uri to be opened
//	- windowName (required):		window name
//	- left (required):				window left
//	- top (required):				window top
//	- width (required):				window width
//	- height (required):			window height
//
//	what:	opens a new browser window with possibility to set size and
//			with original user browser properties
//	note:	works not when uri links to another domain
// Edit: SEG 13.02.07 uri abfrage eingebaut
function openWindowInheritWithSize(uri,windowName,left,top,width,height)
{
	if (uri.substr(0, 7) == "http://")
		thisWindow = window.open(uri, 'newWindow');
	else
		thisWindow = window.open('http://'+location.hostName+'/'+uri, 'newWindow');

	thisWindow.resizeTo(width,height);
	thisWindow.moveTo(left,top);

	setTimeout('thisWindow.focus()',100);
}


//	buildHtmlDoctype4Img()
//
//	Arguments:
//	- uri (required):		uri to be opened
//	- docTitle (required):	title for browser window
//
//	what:	writes complete html document for images
function buildHtmlDoctype4Img(uri,docTitle)
{
	var doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
	doctype += '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">';
	doctype += '<head>';
	doctype += '<title>STIHL - ' + docTitle + '</title>';
	doctype += '<style>body {margin:0;padding:0;}</style>';
	doctype += '</head>';
	doctype += '<body>';
	doctype += '<div><img src="' + uri + '" alt="' + docTitle + '" /></div>';
	doctype += '</body>';
	doctype += '</html>';
	return doctype;
}


//	extractString()
//
//	Arguments:
//	- fullString (required):	string to be extracted
//	- startString (required):	start string identifier
//	- endString (required):		end string identifier, reading begins from startString position
//
//	what:	extracts string out of another string by start and end identifiers
function extractString(fullString,startString,endString)
{
	var stringPosStart = fullString.indexOf(startString) + startString.length;
	var stringPosEnd = fullString.indexOf(endString,stringPosStart);
	var extract = fullString.substring(stringPosStart,stringPosEnd);
	return extract;
}



//	openLinkInOpener()
//
//	Arguments:
//	- uri (required):			uri to be opened
//	- closeWindow (optional):	close window, where the link has been clicked (true | false)
//
//	what:	opens a link in the opener browser window
function openLinkInOpenerWindow(uri,closeWindow)
{
	if (window.opener)
	{
		if (window.opener.top)
		{
			window.opener.top.location.href = uri;
		}
		else
		{
			window.opener.location.href = uri;
		}
		if (closeWindow == true)
		{
			window.self.close();
		}
		setTimeout('window.opener.focus();',100);
	}
	else
	{
		window.location.href = uri;
	}
}

//	linkInTopFrame()
//
//	Arguments:
//	- uri (required):			uri to be opened in top frame
//
//	what:	opens a link in top frame
function linkInTopFrame(uri)
{
	top.location.href = uri;
}

function linkInParentFrame(uri)
{
	parent.location.href = uri;
}

function closeWindow()
{
	self.close();
}

//  formsuche()
//
//  Pulldownmenü zur Seitenanwahl

function formsuche()
{
	var list = document.forms['auswahl'].liste;
	var opt = list.options[list.selectedIndex];

	if (opt.value && opt.value != opt.text)
	{
		parent.content.window.location.href = opt.value;
	}

	return false;
}

/* md */

var popWinGrillen;
function popWinGrillen(url, width, height) {
	if (popWinGrillen && !popWinGrillen.closed && popWinGrillen.close)
	{
		popWinGrillen.close();
	}

	popWinGrillen = window.open(url, 'popWinGrillen', 'top=100, left=400, menubar=0, location=0, toolbar=0, scrollbars=0, status=0, resizable=0, width=' + width + ', height=' + height);
	popWinGrillen.focus();
}


/* Öffnet Fenster nur für Bild ohne Toolsbar/Statusbar etc.*/
function openImgWin(url, width, height)
{
	if (typeof imgWin != 'undefined' && !imgWin.closed && imgWin.close)
	{
		imgWin.close();
	}

	var html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
			+ '\n<html xmlns="http://www.w3.org/1999/xhtml">'
			+ '\n<head><title>STIHL</title><style type="text/css">* { margin: 0; padding: 0; } img { display: block; } </style></head>'
			+ '\n<body><div><img src="' + url + '" width="' + width + '" height="' + height + '" alt="" title="" /></div></body>'
			+ '\n</html>';

	imgWin = window.open('', 'imgWin', 'top=40, left=40, toolbar=no, scrollbars=no, menubar=no, location=no, resizable=yes, status=yes, width=' + width + ', height=' + height);

	imgWin.document.open();
	imgWin.document.write(html);
	imgWin.document.close();

	imgWin.focus();
}

/* Öffnet Fenster nur für Flash ohne Toolsbar/Statusbar etc.*/
function openFlashWin(url, width, height)
{
	if (typeof imgWin != 'undefined' && !imgWin.closed && imgWin.close)
	{
		imgWin.close();
	}

	var html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
			+ '\n<html xmlns="http://www.w3.org/1999/xhtml">'
			+ '\n<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />'
			+ '\n<head><title>STIHL</title><style type="text/css">* { margin: 0; padding: 0; } img { display: block; } </style></head>'
			+ '\n<body><div><object type="application/x-shockwave-flash" data="' + url + '" width="' + width + '" height="' + height + '" /><param name="movie" value="' + url + '" /></object></div></body>'
			+ '\n</html>';

	imgWin = window.open('', 'imgWin', 'top=40, left=40, toolbar=no, scrollbars=no, menubar=no, location=no, resizable=yes, status=yes, width=' + width + ', height=' + height);

	imgWin.document.open();
	imgWin.document.write(html);
	imgWin.document.close();

	imgWin.focus();
}


function openPopWin(url, width, height, scrollbars)
{
//md discussion+++
if (typeof scrollbars == "undefined") {
	scrollbars="no";
	if(width > 600){
		scrollbars="yes";
	}
}
//md++++++++++++++
	if (typeof popWin != 'undefined' && !popWin.closed && popWin.close)
	{
		popWin.close();
	}

	popWin = window.open(url, 'popWin', 'top=40, left=40, toolbar=no, scrollbars='+scrollbars+', menubar=no, location=no, resizable=yes, status=yes, width=' + width + ', height=' + height);
	popWin.focus();
}

/* VIKING Microsite Rasenpflege & M-Tronic */
/********************************/
var newWin;
function newWindow(url,breite,hoehe){
	if(newWin && !newWin.closed) newWin.close();

	var posX = screen.width;
	var posY = screen.height;

	posX = (posX-breite)/2;
	posY = (posY-hoehe)/2;

	newWin = window.open(url,'popup','toolbar=no,location=no,directories=no,menubar=no,status=no,scrollbars=yes,resizable=no,left=' + posX + ',top=' + posY + ',width=' + breite + ',height=' + hoehe + '');
}