/* ig/20040831 - Javascript to handle pop-up user survey... */

// standard event handlers...
window.onunload = showSurvey;
document.onmousedown = internal;

// this flag indicates that we're following an internal link, so we shouldn't show the survey
var isinternal = false;
// this flag is for forcing the survey to be hidden (which means that this script can be used 
// by the survey itself, without getting ourselves into a perpetual loop)
var nosurvey = false;

// usual ting, innit...
function openURLInNewWindow(title,name,url,width, height, additionalParams) {
	params = '';
	
	if (width > 0) {
		if (width < screen.width) {
			// if we're specifying the width and height, then centre it on the screen
			dialogLeft = (screen.width / 2) - (width / 2);
		} else {
			dialogLeft = 0;
			width = screen.width;
		}
	} else {
		// if no width and height are specified, then fill the screen
		dialogLeft = 0;
		width = screen.width;
	}
	
	if (height > 0) {
		if (height < screen.height) {
			// if we're specifying the width and height, then centre it on the screen
			dialogTop = (screen.height / 2) - (height / 2);
		} else {
			dialogTop = 0;
			height = screen.height - 100;
		}
	} else {
		// if no width and height are specified, then fill the screen (allowing space for taskbar)
		dialogTop = 0;
		height = screen.height - 100;
	}

	//if ((additionalParams.indexOf('menubar') != -1) && (is.ie4up)) {
		// ie mucks up the height if we include a menu bar, so do some adjustment
		//params = 'width=' + (width - 5) + ',height=' + (height - 23) + ',dependent,left=' + dialogLeft + ',top=' + dialogTop;
	//} else {
		params = 'width=' + width + ',height=' + height + ',dependent,left=' + dialogLeft + ',top=' + dialogTop;
	//}	

	if (additionalParams != '') {
		params = params + ',' + additionalParams
	}
	
	newWindow = window.open (url, '', params);
	newWindow.document.close();
	newWindow.focus();
}

// if we're following an internal site link, set the flag
function internal() {
	isinternal = true;
}

// if we're not following an internal site link, unset the flag
function notinternal() {
	isinternal = false;
}

// show the survey...
function showSurvey() {
	// also check cookie here, to see if they've done or refused to do the survey before
	if ((! isinternal) && (! nosurvey) && (checkSurvey()==null)) {
		// survey currently disabled, to avoid annoying everyone
		//openURLInNewWindow("Survey", "survey", "survey/survey1.html", 500, 400, "scrollbars=yes");
	}
}

// when the survey's been done, or refused, set a cookie to stop it from being shown again
function doneSurvey() {
	createCookie('watfordmuseum-survey', "done", 365);
}

// checks to see whether the survey's been done already
function checkSurvey() {
	return cookie = readCookie('watfordmuseum-survey');
}



