<!--// Leave this comment line! --><%
/******************************************************************************
 ***  Copyright© 2002 Challenger International Ltd. All rights reserved.    ***
 ******************************************************************************
 *
 * Script functions to open new browser windows.
 *
 * _openWindow(url,title) simple fixed-size popup based on screen size.
 * _openProportionalWindow(url,title,[disableList],[referenceScreenSize]) 
 *      Flexible popup based on current window size or optionally screen size.
 * _openWin(url) deprecated!
 * _openSizedPlainWindow(url, title, height, width) simple centred sized popup
 *
 *
 * $Author: cmadden $
 * $Date: 2002/11/30 00:38:59 $
 * 
 * $Log: openWindow.js,v $
 * Revision 1.2  2002/11/30 00:38:59  cmadden
 * Added _openProportionalWindow()  to open a centered window slightly smaller than the parent window.
 *
 * Updates:
 *  02-01-2003 CM. modified _openSizedPlainWindow() to accept optional param of list of 
 *                 window features to turn on.
 *  29-12-2003 CM. modified _openProportionalWindow() to accept additional optional 
 *                 parameters to hide window features and base window size on screen
 *                 rather than calling window size.
 *	20-10-2003 CM. modified _openSizedPlainWindow() to centre window and hide scroll bars.
 * 
 ******************************************************************************/

function _openWindow(url,title){
//
// Open a centered window 80% of screen width 70% of height.
// If a window name is supplied as "title", it is used as the
// window handle and the same window is "shared" by all calls
// from the same link.  If a "title" is NOT supplied,a unique
// one is generated resulting in a new window opening for each 
// call.
//
var strTitle = new String(title);
var undefined;


	if(title==undefined){
		// If no title supplied, generate a unique one..
		title = (new Date()).getSeconds().toString();
	}

	var options = "HEIGHT="+(screen.availHeight*0.7)+", width="+(screen.availWidth*0.8);
	options +=",top="+((screen.availHeight*0.48)-((screen.availHeight*0.79)/2));
	options +=",left="+((screen.availWidth/2)-((screen.availWidth*0.8)/2));
	options += ",scrollbars=1,location=0,directories=0,status=1,menubar=0,toolbar=1,resizable=1";
	
	win=open(url, title, options);
	
}

function _openProportionalWindow(url,title){
//
// Open a centered window slightly smaller than either the 
// parent window or screen size. Tidy way to ensure new windows 
// are not obscured, yet are still new popup windows.
//
//
// Parameters:
//               url (string): resource to load in new window.
//             title (string): name for window to refer to in script (not displayed)
//                             If a window name is supplied as "title", it is used 
//                             as the window handle and the same window is "shared" 
//                             by all calls from the same link.  If a "title" is NOT 
//                             supplied,a unique one is generated resulting in a new 
//                             window opening for each call.
//       disableList (string): comma-separated list of window features to turn off. 
//                             By default, all window features are on. Choose from 
//                             this list of options: "scrollbars,location,directories,
//                             status,menubar,toolbar,resizable"
// referenceScreenSize (bool): if true, base new window on overall screen dimensions 
//                             rather than current window size. Useful if current 
//                             window is very small and we desire a larger one for 
//                             new content.
//
var strTitle = new String(title);
var undefined;
var iWidth, iHeight, wWidth, wHeight;

//
// Optional parameter enables various window features to 
// be disabled.  Pass a comma separated list of feature names.
// By default all features are on.
//
var disableList = ""; 
	if(arguments.length > 2)
		disableList = getString(arguments[2]);
//
// Optional parameter determines is new window size is to be 
// based on the total screen size rather than the calling 
// document window.
//
var referenceScreenSize = false;
	if(arguments.length > 3)
		if(typeof(arguments[3])=="boolean")
			referenceScreenSize = arguments[3];

	if(referenceScreenSize){
		// Base new window propotions on overall screen dimensions..
		iWidth = (screen.width) ? screen.width : document.body.offsetWidth;
		iHeight = (screen.height) ? screen.height : document.body.offsetHeight;
		wWidth = iWidth*0.9;
		wHeight = iHeight*0.8;
	}else{
		// Base new window propotions on current window dimensions..
		iWidth = (window.innerWidth) ? window.innerWidth : document.body.offsetWidth;
		iHeight = (window.innerHeight) ? window.innerHeight : document.body.offsetHeight;
		wWidth = iWidth*0.9;
		wHeight = iHeight*0.99;
	}

	if(title==undefined){
		// If no title supplied, generate a unique one..
		title = (new Date()).getSeconds().toString();
	}
	var options = "HEIGHT="+wHeight+", width="+wWidth;
	options +=",top="+ Math.floor( (screen.height - wHeight) / 2); // Centre the new window!
	options +=",left="+ Math.floor( (screen.width - wWidth) / 2);
	
	var optionList = {"scrollbars":"1","location":"1","directories":"1","status":"1","menubar":"1","toolbar":"1","resizable":"1"};
	if(disableList!=""){
		var arr = disableList.split(",");
		for(var i=0;i<arr.length;i++){
			//alert("arr["+i+"]:"+arr[i]);
			switch(arr[i].toLowerCase()){
			case "scrollbars":{optionList["scrollbars"]="0";break;}
			case "location":{optionList["location"]="0";break;}
			case "directories":{optionList["directories"]="0";break;}
			case "status":{optionList["status"]="0";break;}
			case "menubar":{optionList["menubar"]="0";break;}
			case "toolbar":{optionList["toolbar"]="0";break;}
			case "resizable":{optionList["resizable"]="0";break;}
			}
		}
	}
	for(var j in optionList){
		options += ","+j+"="+optionList[j];
		//alert("optionList["+j+"]"+optionList[j]);
	}
	win=open(url, title, options);
}

function _openWin(url){
  win=open(url, "displayWindow",
    "width=500,HEIGHT=350,resizable=yes,status=no,toolbar=yes,menubar=yes scrollbars=yes");
}

function _openSizedPlainWindow(url, title, height, width) {
// Opens a (centered) plain browser window with specified height 
// and width with all window features turned off by defeult except 
// scrollbars if required.
//
// An optional string parameter enables various window features to 
// be enabled.  Pass a comma separated list of feature names.
// By default all features are off.
//
var enableList = ""; 
	if(arguments.length > 4)
		enableList = getString(arguments[4]);
		
	var options = "HEIGHT="+height+", width="+width;
	options +=",top="+ Math.floor( (screen.height - height) / 2);
	options +=",left="+ Math.floor( (screen.width - width) / 2);
	//options += ",resizable=yes,status=no,toolbar=no,menubar=no,scrollbars=no";
	
	var optionList = {"scrollbars":"0","location":"0","directories":"0","status":"0","menubar":"0","toolbar":"0","resizable":"1"};
	if(enableList!=""){
		var arr = enableList.split(",");
		for(var i=0;i<arr.length;i++){
			//alert("arr["+i+"]:"+arr[i]);
			switch(arr[i].toLowerCase()){
			case "scrollbars":{optionList["scrollbars"]="1";break;}
			case "location":{optionList["location"]="1";break;}
			case "directories":{optionList["directories"]="1";break;}
			case "status":{optionList["status"]="1";break;}
			case "menubar":{optionList["menubar"]="1";break;}
			case "toolbar":{optionList["toolbar"]="1";break;}
			case "resizable":{optionList["resizable"]="1";break;}
			}
		}
	}
	for(var j in optionList){
		options += ","+j+"="+optionList[j];
		//alert("optionList["+j+"]"+optionList[j]);
	}
		
	win=open(url, title, options);
}

var suppliedContentWin;
function _openSuppliedContentPopup(targetObjectId, eventObj) { // [CSS path]
/*
 *	Displays text in a simple popUp window at the location a click event occurred.
 *	To use, place your content inside a hidden container object eg. DIV, SPAN, etc. 
 *	and attach this function as the onClick event handler another object such as a 
 *	button or link.  If the event is passed as NULL, then the popup will be centered
 *	on the screen.
 *	
 *	If your content DIV has width and height style properties, they will be used 
 *	for the popup window dimensions. If your DIV has a name attribute it will be 
 *	used as the popup window title with any underscore chars converted to spaces.
 *	
 *	If .popUp and .popUpSource CSS attributes are available, they will be used.
 *	A URL path to CSS file will be accepted as an optional 3rd string argument.
 *	
 *	Your .popUp and .popUpSource attributes might be similar to this:
 *	.popUp {padding:10;}
 *	.popUpSource {position:absolute; visibility:hidden; overflow:hidden;}
 *	
 *	Example Usage:
 *	<div  style='width:500;height:290;' id='helpText'  name='Confirmation_Gateway_Use' 
 *		class=popUpSource>
 *		<p>Use the drop down boxes on the Confirmation Gateway form to set up how your 
 *		letters will be presented to you when you enter this page. You can choose to
 *		show them &#34;All&#34; or reduce the amount in the list.</p>
 *	</div>
 *	...
 *	[<a href="#" onClick="return !_openSuppliedContentPopup('helpText', event,
 *			'<%=ResolveUrl("~/SynergyStyle.css")%>');" class=popupLink>More...</a>]
 *	
 */
	//Check if there is already a popup window open and close it if there is..
	if(suppliedContentWin){
		suppliedContentWin.close();
	}
	var styleSheet = "";
	if(arguments.length > 2)
		styleSheet = getString(arguments[2]);
	var x,y;	
	var xOffset = 30;
	var yOffset = -5;
	var popupWidth = 500;
	var popupHeight = 200;
	var popUpContent = "";
	var sourceText = "";
	var titleText = "";
	var div = window.document.getElementById(targetObjectId);
	if(div){
		sourceText = div.innerHTML;
		popupWidth = parseInt(div.style.width);
		popupHeight = parseInt(div.style.height);
		if(div.name){
			titleText = div.name;
			titleText = titleText.replace(/_/g," ");
		}
	}
	if(eventObj){
		x = (eventObj.screenX)?eventObj.screenX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
		y = (eventObj.screenY)?eventObj.screenY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
	}else{
		// An even was not supplied, so use screen centre instead..
		x = Math.floor( (screen.width - popupWidth) / 2);	
		y = Math.floor( (screen.height - popupHeight) / 2);
	}
	suppliedContentWin=open("", "popUpWindow",
		"width="+popupWidth+",height="+popupHeight+",top="+y+",left="+x+",resizable=yes,status=no,toolbar=no,menubar=no scrollbars=yes");
	// Add some style and a window close button..
	popUpContent = "<html><title>"+titleText+"</title>";
	if(styleSheet!="")
		popUpContent += "<link href='"+styleSheet+"' rel='stylesheet' type='text/css' media='all'>";
	popUpContent += "<body class=popUp>";
	popUpContent += sourceText;
	popUpContent += "<center><form><input type=button value='Close' onClick='window.close();'></form></center></body></html>";
	suppliedContentWin.document.write(popUpContent);
	suppliedContentWin.document.title.text="";
}

function getString(strData){
/*
* Strips out any illegal characters found in the supplied String.
* If the string happens to be "undefined" or "null", however, it fails to 
* accept this as there is no way to check if the supplied value 
* is a defined string before converting it to a String.
*/
	var str = new String(strData);
	if(str=="undefined"||str=="null"){
		str="";
	}
	
	if(str.indexOf(String.fromCharCode(0)) > 0){ // str contains a null character?
		str = str.substr(0,str.indexOf(String.fromCharCode(0)))
	}
	// Trim whitespace from start and end of string..
	str =  str.replace(/^\s*(\S+)\s*%/ig,"$1");
	return str;
}
//%>