function customise() {
	document.location.href='DesktopServlet?action=edit&provider=rheCustomisePortal';
}

function closeWindow() {
	window.close()
}
function printWindow() {
	window.print()
}
function focusWindow() {
	window.focus()
}


/**/
function launchWithRewriteToolbars(URL, width, height, windowName) {
	launchNoRewriteToolbars(URL, width, height, windowName)
}

function launchNoRewriteToolbars(URL, width, height, windowName) {
	var addFeatures = 'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizeable=1';
	new popupWindow(windowName, width, height, addFeatures).launch(URL);
}
/**/
function launchWithRewrite(URL, width, height, windowName, addFeatures) {
	launchNoRewrite(URL, width, height, windowName, addFeatures);
}

function launchNoRewrite(URL, width, height, windowName, addFeatures) {
	new popupWindow(windowName, width, height, addFeatures).launch(URL);
}
/**/
function launchRemote(URL, width, height, windowName, addFeatures) {
	if(URL.indexOf('portalgw.zurich.com.au/adviserassist') > -1) URL='https://www.zurich.com.au/AdviserAssist/login.do';
	if(URL.indexOf('/zportal/cs/')==0) URL='http://www.zurich.com.au'+URL;
	launchRemoteNoRewrite(URL, width, height, windowName, addFeatures)
}

function launchRemoteNoRewrite(URL, width, height, windowName, addFeatures) {
	new popupWindow(windowName, width, height, addFeatures).launch(URL);
}
/**/
function launch(URL,windowName,addFeatures) {
	return launchPopup(URL,windowName,addFeatures)
}

function launchPopup(URL,windowName,addFeatures) {
	return new popupWindow(windowName, null, null, addFeatures).launch(URL);
}
/**/
function setPopupDefaults(windowName, width, height) {
	this.windowName = windowName;
	this.width = width;
	this.height = height;
}
popupDefaults = new setPopupDefaults("_blank", 780, 550)
/**/
function popupWindow(windowName, width, height, addFeatures) {
	this.setWindowName = function (windowName) {if (windowName) {this.windowName = windowName;}}
	this.setWidth = function (width) {
		if (width) {
			if (width>screen.availWidth) width = screen.availWidth;
			this.features.width = width;
			this.setDftLeft()
		}
	}
	this.setHeight = function (height) {
		if (height) {
			if (height>screen.availHeight - 28) height = screen.availHeight - 28;
			this.features.height = height;
			this.setDftTop()
		}
	}
	this.setFeatures = function (addFeatures) {if (addFeatures) {this.addFeatures = addFeatures;}}
	this.setLeft = function(left) {this.features.left = left;this.features.screenX = left}
	this.setTop = function(top) {this.features.top = top;this.features.screenY = top}	

	this.windowName = (windowName)?windowName:popupDefaults.windowName;
	this.features = new Array();
	this.features.width = (width)?width:popupDefaults.width;
	this.features.height = (height)?height:popupDefaults.height;
	this.features.scrollbars = 1;
	this.features.resizable = 1;
	this.features.channelmode=0;
	this.features.dependent=0;
	this.features.directories=0;
	this.features.fullscreen=0;
	this.features["location"]=0;
	this.features.menubar=0;
	this.features.status=1;
	this.features.toolbar=0;
			
//- SetWindow to be Centred
	this.setDftLeft = function () {
		var dftLeft = (screen.availWidth - this.features.width) / 2;
		if (dftLeft<0) dftLeft=0;
		this.setLeft(dftLeft);
	}
	this.setDftLeft();
	
	this.setDftTop = function () {
		var dftTop  = (screen.availHeight - this.features.height - 28) / 2;
		if (dftTop<0) {dftTop=0;}
		this.setTop(dftTop);
	}
	this.setDftTop();
	this.addFeatures = addFeatures

	this.launch = function (URL) {
		this.URL = (URL)?URL:"";
		var features = "";
		for (feature in this.features) {features += feature + "=" + this.features[feature] + ",";}
		if (this.addFeatures) features += this.addFeatures;
		var remote = open(this.URL, this.windowName, features);
		remote.focus()
		if (remote.opener == null)remote.opener = window;
		this.remote=remote;
		return remote;
	}
}

//**************************
function Set_Cookie( name, value, expires, path, domain, secure ) {
		 // set time, it's in milliseconds
		 var today = new Date();
		 today.setTime( today.getTime() );

		 /*
				if the expires variable is set, make the correct
				expires time, the current script below will set
				it for x number of days, to make it for hours,
				delete * 24, for minutes, delete * 60 * 24
			*/
			if (expires) {
					expires = expires * 1000 * 60 * 60 * 24;
			}
			var expires_date = new Date(today.getTime() + (expires));
			document.cookie = name + "=" +escape( value ) +
						(( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
						(( path ) ? ";path=" + path : "" ) +
						(( domain ) ? ";domain=" + domain : "" ) +
						(( secure ) ? ";secure" : "" );
	}


//**************************
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
		// first we'll split this cookie up into name/value pairs
		// note: document.cookie only returns name=value, not the other components
		var a_all_cookies = document.cookie.split( ';' );
		var a_temp_cookie = '', cookie_name = '', cookie_value = '';
		var b_cookie_found = false; // set boolean t/f default f

		for (i=0; i < a_all_cookies.length; i++)
		{
			// now we'll split apart each name=value pair
			a_temp_cookie = a_all_cookies[i].split( '=' );


			// and trim left/right whitespace while we're at it
			cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

			// if the extracted name matches passed check_name
			if ( cookie_name == check_name ) {
				b_cookie_found = true;
				// we need to handle case where cookie has no value but exists (no = sign, that is):
				if ( a_temp_cookie.length > 1 ) {
					cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				}
				// note that in cases where cookie is initialized but no value, null is returned
				return cookie_value;
				break;
			}
			a_temp_cookie = null;
			cookie_name = '';
		}
		if ( !b_cookie_found ) {
			return null;
		}
}


//**************************
function getCheckedValue(radioObj) {
		if(!radioObj) {
			return "";
		}
		var radioLength = radioObj.length;
		if(radioLength == undefined) {
			return (radioObj.checked ? radioObj.value : "");
		}
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				return radioObj[i].value;
			}
		}
		return "";
}


//**************************
function setCheckedValue(radioObj, newValue) {
		if(!radioObj) {
			return;
		}
		var radioLength = radioObj.length;
		if(radioLength == undefined) {
			radioObj.checked = (radioObj.value == newValue.toString());
			return;
		}
		for(var i = 0; i < radioLength; i++) {
			radioObj[i].checked = ((radioObj[i].value == newValue.toString()) ? true : false);
		}
}
