//sripts for opening pop-up windows.

function PopUpCenter(sUrl,sName,sFeatures)
{
	//		this function provides the functionality
	//		of centering a pop-up window in the
	// 		current browser window.
	//	
	//		it takes three arguments, sUrl, sName, sFeatures
	//		these work exactly the same as the arguments
	// 		of the standard javascript function window.open.
	//
	//		this function's only advantage over 
	//		the window.open function is the centering part.
	//		to center the pop-up window, it needs to know the width
	//		and the height of the pop-up.
	//
	//		also, in the sFeatures argument the arguments
	// 		screenX,screenY,left and top cannot be specified,
	//		since they position the window absolute.
	//
	//		so the correct way of calling this function is
	//		PopUpCenter('http://www.myurl.com','sMyWindowName','width=500,height=400')
	// 		in addition to the width and the height attribute, also one or more
	//		of the following attributes can be specified:
	//		http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm#1202731
	//		for example
	//		PopUpCenter('http://www.myurl.com','sMyWindowName','width=500,height=400,scrollbars=yes')
	//
	//		if the function is called without one of the three arguments, or without
	//		the width and the height, or with screenX,screenY,left or top, than
	//		it alerts.
	//		if you just want to open a window, not center it, use window.open
	//
	//		Like window.open, PopUpCenter returns the window object of the pop-up window.
	//		Use the following syntax to focus the window after opening a page in it:
	//
	//		**********************************************************************************************
	//		COPY AND PASTE THIS LINE OF CODE. USE DIFFERENT VARIABLES FOR DIFFERENT WINDOWS!!
	//		OTHERWISE YOU OPEN THE SAME WINDOW INSTEAD OF ANOTHER, AND YOU CANNOT RESIZE IT IF WANTED!
	//		onClick="oMyPopup=PopUpCenter('myPage.html','myPage','width=500,height=296');oMyPopup.focus()"
	//		**********************************************************************************************
	//		IF YOU ONLY WANT TO DISPLAY AN IMAGE INSIDE THE NEW WINDOW, USE THIS BODY TAG IN THE HTML PAGE YOU OPEN:
	//		<body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="0" marginheight="0" marginwidth="0">
	//		**********************************************************************************************
	//
	//		To begin with: a browser check. This check will be replaced with the new check
	//		when it will be used in the new Corporate Schil, 2002
	//		if the current browser is Netscape nor Internet Explorer, this function returns
	//		true and quits.
	var ns4 = (document.layers)? true:false
	var ie4 = (document.all)? true:false
	if (!ns4 && !ie4) return true
	
	var iBrowserWidth					//	integer indicating width of clientArea
	var iBrowserHeight					//	integer indicating height of clientArea
	var iLeftCurrentWindow				//	integer indicating the horizontal position of current window
	var iTopCurrentWindow				//	integer indicating the vertical position of current window
	var sWidth							//	string containing specified width in sFeatures argument
	var sHeight							//	string containing specified height in sFeatures argument
	var iPositionWidth					//	position 'width' substring in string sFeatures
	var iPositionNextCommaAfterWidth	//	position ',' substring after width in string sFeatures
	var iPositionHeight					//	position 'height' substring in string sFeatures
	var iPositionNextCommaAfterHeight	//	position ',' substring after height in string sFeatures
	var iLeftPosition					//	integer containing wanted horizontal position
	var iTopPosition					//	integer containing wanted vertical position
	var sFeaturesAdjusted				//	string containing comma separated list of Windowfeatures, 
										//	with the calculated position added to it
	
	//		checks on specified arguments
	if (sUrl == "" || sName == "" || sFeatures == "") 
	{
		alert('PopUpCenter misses one or more arguments!')
		return true
	}
	if (sFeatures.search('width') == -1 || sFeatures.search('height') == -1)
	{
		alert('PopUpCenter needs a width and a height specified in the sFeatures argument!')
		return true
	}
	if (sFeatures.search('screenX') != -1 || sFeatures.search('screenY') != -1 || sFeatures.search('left') != -1 || sFeatures.search('top') != -1)
	{
		alert('PopUpCenter doesn\'t take screenX, screenY, left or top in its sFeatures argument!')
		return true
	}
	
	//		get proportions display area of current browser-window
	if (ns4)
	{
		iBrowserWidth = window.innerWidth
		iBrowserHeight = window.innerHeight
		iLeftCurrentWindow = window.screenX
		iTopCurrentWindow = window.screenY
	}
	if (ie4)
	{
		iBrowserWidth = window.document.body.clientWidth
		iBrowserHeight = window.document.body.clientHeight
		iLeftCurrentWindow = window.screenLeft
		iTopCurrentWindow = window.screenTop
	}
	
	//		get specified width
	iPositionWidth = sFeatures.indexOf('width')
	iPositionNextCommaAfterWidth = sFeatures.indexOf(',',iPositionNextCommaAfterWidth)
	if (iPositionNextCommaAfterWidth == -1)
	{
		iPositionNextCommaAfterWidth = sFeatures.length
	}
	//		+6, because we want to skip the characters 'width='
	sWidth = sFeatures.substring(iPositionWidth+6,iPositionNextCommaAfterWidth)
	
	//		get specified height
	iPositionHeight = sFeatures.indexOf('height')
	iPositionNextCommaAfterHeight = sFeatures.indexOf(',',iPositionHeight)
	if (iPositionNextCommaAfterHeight == -1)
	{
		iPositionNextCommaAfterHeight = sFeatures.length
	}
	//		+7, because we want to skip the characters 'height='
	sHeight = sFeatures.substring(iPositionHeight+7,iPositionNextCommaAfterHeight)
	
	//		calculate position
	iLeftPosition = iLeftCurrentWindow + ((iBrowserWidth/2) - (sWidth/2))
	iTopPosition = iTopCurrentWindow + ((iBrowserHeight/2) - (sHeight/2))
	
	//		adjust sFeatures string
	sFeaturesAdjusted = sFeatures + ',screenX='+iLeftPosition+',screenY='+iTopPosition+',left='+iLeftPosition+',top='+iTopPosition+''
	
	//		call window.open method
	return window.open(sUrl,sName,sFeaturesAdjusted)
}


function OpenWin(myURL) {
	var mypopupwin=window.open(myURL,'myPopup', "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=400,left=5,top=5,screenX=0");
	mypopupwin.focus();
}

function OpenWinTools(myURL) {
	window.open(myURL,'myPopup', "toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=400,left=5,top=5")
}

//script for opening a new window with attributes, see code for the attributes
//use the following code as link:
//<a href="#" name="openWin" onClick='openWindowVar("pagina.htm", "", "yes", "no", "no", "yes", "yes", "yes", "no", 200, 200, 10, 10, 10, 10)'>Linknaam</a>
function openWindowVar( url, titel, tb, loc, dire, stat, sb, res, hist, w, h, x, y, l, t  )
{
    var style     = "";

    style     = "toolbar="+tb;
    style    += ",location="+loc;
    style    += ",directories="+dire;
    style    += ",status="+stat;
    style    += ",scrollbars="+sb;
    style    += ",resizable="+res;
    style    += ",copyhistory="+hist;
    style    += ",width="+w + ",height="+h;
    style    += ",screenX="+x + ",screenY="+y;
    style    += ",left="+l + ",top="+t;
		
    var newWin     = window.open( url, titel, style );
    return newWin;
}

//sript for redirecting the user in the present window
function RedirectTo(myURL) {
	window.location.href = myURL;
}

function OpenWindow(theLocation,width,height) {
	var popupWindow, popupW, popupH, popupX, popupY
	var NN=(navigator.appName == "Netscape")?true:false
	var IE=(navigator.appName == "Microsoft Internet Explorer")?true:false
	var scrW=screen.availWidth
	var scrH=screen.availHeight
	var scrX=0
	var scrY=0
	if (isNaN(scrW))scrW=screen.width
	if (isNaN(scrH))scrH=screen.height
	if(NN){
		if (window.outerWidth<scrW)scrW=window.outerWidth;
		if (window.outerHeight<scrH)scrH=window.outerHeight
		scrX=window.screenX
		scrY=window.screenY
	}
	popupW=width;
	popupH=height;
	if(popupW<100)popupW=scrW
	if(popupH<100)popupH=scrH
	if(popupW<100)popupW=100
	if(popupH<100)popupH=100
	popupX=scrX+scrW-popupW;
	popupY=scrY+0;
	var extras='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,width=100,height=100';
	popupWindow = window.open(theLocation,'hgfhgfjh',extras);
	popupWindow.moveTo(0,0);
	if(NN){
		popupWindow.setResizable(true)
		popupWindow.outerWidth=popupW;
		popupWindow.outerHeight=popupH;
	}
	if(IE){
		popupWindow.resizeTo(popupW,popupH);
	}
	popupWindow.moveTo(popupX,popupY);
	popupWindow.focus()
}

function backtous() {   // function to open back to sni window

if (arguments.length > 0) {
var imgSrc = arguments[0]
}
else {
var imgSrc = 'images/backtous.gif'
}

//alert(imgSrc)
 	 			//winbacktous=window.open("http://194.178.157.30/sydneykladsites/siemens/Siemensnew/website/backtous.htm", "backtous", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width=220,height=115,left=5,top=5"); // open backtous window
//myURL = 'http://194.178.157.30/sydneykladsites/siemens/Siemensnew/website/backtous.htm?mySrc='+document.location.href+'&imgSrc='+imgSrc+'' //bij BPi
myURL = 'http://www.siemens.nl/backtous.htm?mySrc='+document.location.href+'&imgSrc='+imgSrc+'' //bij Siemens

winbacktous=window.open(myURL, "backtous", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width=220,height=115,left=5,top=5"); // open backtous window	 
}

function PopupSol(myURL) {
if (document.all) { 
	w = document.body.clientWidth; h = document.body.clientHeight; 
	var horizontaal = (w/2) - 370;
	var verticaal = (h/2) - 220;
}

if (document.layers) { 
	w = screen.width; h = screen.availHeight; 
	var horizontaal = (w/2) - 370;
	var verticaal = (h/2) - 220;
}
eval("var mypopupwindow=window.open('"+myURL+"','myPopup', 'toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=740,height=440,left="+horizontaal+",top="+verticaal+",screenX="+horizontaal+",screenY="+verticaal+"')");
mypopupwindow.focus()
//window.moveTo(w/2,h/2)
}


var win = null;
function NewWindow(mypage,myname,w,h,scroll) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}


