// common DoITPoMS Javascript 

// Default values for window features
var vlocation = 'no';
var vmenubar = 'no';
var vresizable = 'yes';
var vstatus = 'no';
var vscrollbars = 'yes';
var vtoolbar = 'no';
var vwidth = 500;
var vheight = 400;
var vleft = 0;
var vtop = 0;
//==========================================================================
// encodeSpaceChars replaces all space chars by '+' chars for use in a URL. The following would be more efficient but
// depends on Javascript 1.2.
// var encoded = string.replace(/\s/g, "+");
function encodeSpaceChars(string) {
	var encoded = '';
	var i = 0;
	var j = string.indexOf(' ');
	while (j != -1) {
		encoded = encoded + string.substring(i, j) + '+';
		i = j + 1;
		j = string.indexOf(' ', i);
	}
	encoded = encoded + string.substring(i, string.length);
	return encoded;
}
//==========================================================================
// makeFeaturesStr assembles and returns a features string
function makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop) {
	return 'location=' + vlocation + ',menubar=' + vmenubar + ',resizable=' + vresizable + ',status=' + vstatus + ',scrollbars=' + vscrollbars + ',toolbar=' + vtoolbar + ',width=' + vwidth + ',height=' + vheight;
}
//==========================================================================
// openGlossWin opens a new window displaying a MATTER or DoITPoMS Glossary entry
function openGlossWin(term) {
	var vwidth = 700;
	var vheight = 500;
	if (arguments.length > 1) {
		vwidth = arguments[1];
		vheight = arguments[2];
	}
// Following line requires JavaScript 1.2, so replaced by call to function which does same job. DH 21/11/02.
//	var encodedTerm = term.replace(/\s/g, "+");
	var encodedTerm = escape(term);
	var features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
	var win = window.open('http://www.doitpoms.ac.uk/glossary/entry.php?term=' + encodedTerm, '', features);
}
//==========================================================================
// openPopUpWin opens a new window displaying the URL specified in it
function openPopUpWin(url) {
	var vwidth = 700;
	var vheight = 500;
	if (arguments.length > 1) {
		vwidth = arguments[1];
		vheight = arguments[2];
	}
	var features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
	var win = window.open(url, '', features);
}
//==========================================================================
// openImgWin opens a new window displaying the image specified by the URL in it
function openImgWin(image, w, h) {
	var vwidth = w + 40;
	var vheight = h + 40;
	var vmenubar = 'yes';
	var features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
	var win = window.open('images/' + image, '', features);
}
//==========================================================================
// openMediaWin opens a new window displaying media
function openMediaWin(type, file, caption, w, h) {
	var vwidth = w + 150;
	var vheight = h + 180;
	if (type == 'vr') {
		vheight += 40;
	}
// Following line requires JavaScript 1.2, so replaced by call to function which does same job. DH 21/11/02.
//	var encodedCaption = caption.replace(/\s/g, "+");
	var encodedCaption = escape(caption);
	var queryStr = 'type=' + type + '&file=' + file + '&caption=' + encodedCaption + '&width=' + w + '&height=' + h + '&popup=1';
	var features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
	var win = window.open('media.php?' + queryStr, '', features);
}
//==========================================================================
// openImageSeqWin opens a new window displaying imageseq.php, with the image and title passed as parameters to it
function openImageSeqWin(type, image, total, caption, w, h) {
	var vwidth = w + 200;
	var vheight = h + 190;
// Following line requires JavaScript 1.2, so replaced by call to function which does same job. DH 21/11/02.
//	var encodedCaption = caption.replace(/\s/g, "+");
	var encodedCaption = escape(caption);
	var queryStr = 'type=' + type + '&image=' + image + '&total=' + total + '&no=1&caption=' + encodedCaption;
	var features = makeFeaturesStr(vlocation, vmenubar, vresizable, vstatus, vscrollbars, vtoolbar, vwidth, vheight, vleft, vtop);
	var win = window.open('imageseq.php?' + queryStr, '', features);
}
//==========================================================================

