
/*----------------------------------------------------------------------------
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);
}

//	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('about:blank','newWindow')
	thisWindow.resizeTo(screen.availWidth,screen.availHeight)
	thisWindow.moveTo(0,0)
	thisWindow.location.href = uri
	setTimeout('thisWindow.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
function openWindowInheritWithSize(uri,windowName,left,top,width,height){
	thisWindow = window.open('about:blank','newWindow')
	thisWindow.resizeTo(width,height)
	thisWindow.moveTo(left,top)
	thisWindow.location.href = uri
	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)
	{
		window.opener.location.href = uri;
		if (closeWindow == true)
		{
			window.self.close();
		}
		setTimeout('window.opener.focus();',100);
	}
	else
	{
		window.location.href = uri;
	}
}

function openZoomWindow(uri,windowName)
{
	if (windowName == '') windowName = 'newWindow';
	if (typeof(thisWindow) != ('undefined')) thisWindow.close();
	thisWindow = window.open(uri,windowName);
	setTimeout('thisWindow.focus()',100);
}


//	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 closeWindow()
{
	self.close();
}
