


var MSIE = (navigator.userAgent.toLowerCase().search(/msie/) != -1);


function centeredPopupCoords(xsize, ysize) {
	var positY = (screen.availHeight / 2) - (ysize / 2);
	var positX = (screen.availWidth / 2) - (xsize / 2); 
	var position;
	if (window.MSIE) position = "left=" + positX + ",top=" + positY + ",";
	else position = "screenX=" + positX + ",screenY=" + positY + ",";
	return position;
}


function emllnk (ct) {
	var alphabet = " !\"#$%'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~&";
	document.write('<a href="mailto:');
	for (i = 0; i < String(ct).length; i += 2) {
		k = String(ct).substring(i, i+2);
		document.write(String(alphabet).substring(k, parseInt(k)+1));
	}
	document.write('">');
}


function setStatus(text) {
	text = text.replace(/\'/g, "\\'");
	var statusSet = 'window.status=\''+text+'\'';
	setTimeout(statusSet,1);
	return true;
}


function standBy(message) {
	window.loading = true;
	var standByURL = "/Blink/StandBy/1,2498,,00.html?msg="+escape(message);
	var xsize = 200;
	var ysize = 100;
	var standByOptions = centeredPopupCoords(xsize, ysize);
	standByOptions += "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+xsize+",height="+ysize;
	window.open(standByURL,'standByWin',standByOptions);
}


setTimeout('setCursor();',100);

function setCursor(cType) {
	if (typeof(cType) == 'undefined' || cType == '') cType = 'default';
	if (document.body) {
		if (document.body.style) {
			if (document.body.style.cursor) document.body.style.cursor = cType;
		} else {
			if (document.body.cursor) document.body.cursor = cType;
		}
	}
}


function openGallery(picField) {
	window.open("/Blink/Internal/Gallery/Chooser/1,1165,,00.html?formName=contentForm&picField="+picField, "chooser", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=400");
	return false;
}


function sidebarGallery(pthField, destForm) {
	window.open("/Blink/Internal/Gallery/Chooser/1,1165,,00.html?formName="+destForm+"&pthField="+pthField, "sb_chooser", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=400");
	return false;
}


function openTopicChooser(titleField, urlField, destForm) {
	window.open("/Blink/External/Topics/Chooser/1,1176,,FF.html?formName="+destForm+"&topicTitle="+titleField+"&topicURL="+urlField, "topicChooser", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=700,height=300");
	return false;
}


function liveArticleChooser(titleField, urlField, destForm, siteField) {
	window.open("/Blink/External/Topics/Chooser/1,1176,,FF.html?topicSite="+siteField+"&formName="+destForm+"&topicTitle="+titleField+"&topicURL="+urlField,"topicChooser","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=700,height=300");
	return false;
}


function openHelpWindow(urlField) {
	window.open(urlField,"helpWindow","width=370,height=150,scrollbars=yes");
	return false;
}


function centerPopup(url, xDim, yDim, winAttributes) {
	var position = centeredPopupCoords(xDim, yDim);
    var windowName = window.open(url,'newWin',winAttributes+position+',height='+yDim+',width='+xDim);
    return(windowName);
}


var changed = false;
function promptUser() {
	return (!changed)||(confirm('Is it OK to abandon your changes?'));
}


function no_local_cache(old_url) {
	var new_url = old_url
	var re0 = /\/0,/;
	var re1 = /\/1,/;
	if (old_url.match(re0) == null) {
		new_url = old_url.replace(re1, "/0,");
	} else {
		new_url = old_url.replace(re0, "/1,");
	}
	return new_url;
}


function updateParentWindow() {
	if (typeof(opener) != 'undefined') {
		var idx = opener.location.toString().indexOf("#");
		if (idx != -1) var parent_address = opener.location.toString().substring(0, idx);
		else var parent_address = opener.location.toString();
		opener.location = no_local_cache(parent_address);
	}
}


function getMenuItem(lyrItem) {
    return getLayerItem(lyrItem);
}


function getLayerItem(lyrItem) {
    if (document.getElementById) {
	    return document.getElementById(lyrItem)
    } else if (document.layers) {
		// ns 4.x
	    return document.layers[lyrItem]
    } else if (document.all) {
	    return eval('document.all.' + lyrItem)
    }
}


function getObject(id) {
	var handle;
	if (document.getElementById) {
		handle = document.getElementById(id);
		handle = handle.style;
	} else if (document.all){
		handle = eval('document.all.' + id);
		handle = handle.style;
	} else if (document.images){
		handle = document.images[id];
	}
	return handle;
}


function getValue(name) {
	var params = (new String(window.location)).split('?')[1];
	if (params) {
		params = params.split('&');
		var identifier;
		for (p in params) {
			identifier = params[p].split('=')[0];
			if (identifier == name) return params[p].split('=')[1];
		}
	}
	return "";
}


function noEmptySearch(formName) {
	var form = eval('document.'+formName);
	if (form && form.google_query && form.google_query.value == '') return false;
	else return true;
}




function logoutOver(src) {
	if (typeof(window.jlink_active) != 'undefined' && window.jlink_active) {
		src.style.cursor = 'pointer';
		setStatus('Logout off Single Sign-on and Content Manager');
	}
}

function logoutOut(src) {
	if (typeof(window.jlink_active) != 'undefined' && window.jlink_active) src.style.cursor = 'default';
}

function jlinkLogout() {
	if (typeof(window.JLOUT) != 'undefined') JLOUT();
}
