// browser detection
var ffox = navigator.userAgent.indexOf("Firefox") != -1
var ie4 = navigator.userAgent.indexOf("MSIE") != -1
var ns6 = navigator.userAgent.indexOf("Netscape") != -1
var saf = navigator.userAgent.indexOf("Safari") != -1
var opra = navigator.userAgent.indexOf("Opera") != -1

// open a popup centered in user's screen
function popCenter(page, name, w, h, scroll) {
	 var winl = (screen.width - w) / 2;
	 var wint = (screen.height - h) / 2;
	 winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',';
	 win = window.open(page, name, winprops);
	 win.focus();
}

// open a popup fullscreen
function popFull(page, name) {
	window.open(page, name, 'fullscreen=yes, scrollbars=no');
}

// rollover for .gif images (3 states: of, on, in)
function changeGifImage(which) { 
	myImgSrc = document.getElementById(which);
	buttonStatus = myImgSrc.src.substring(myImgSrc.src.length -6, myImgSrc.src.length -4);
	if (buttonStatus == 'of') myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'on.gif';
	else if (buttonStatus == 'in') myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'in.gif';
	else myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'of.gif';
}

// rollover for .jpg images (3 states: of, on, in)
function changeJpgImage(which) { 
	myImgSrc = document.getElementById(which);
	buttonStatus = myImgSrc.src.substring(myImgSrc.src.length -6, myImgSrc.src.length -4);
	if (buttonStatus == 'of') myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'on.jpg';
	else if (buttonStatus == 'in') myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'in.jpg';
	else myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'of.jpg';
}

// show & hide a layer
function layerVisibility(layerId) {
	if (ffox || ie4 || opra) {
		if (document.all[layerId].style.display == "none") {
			document.all[layerId].style.display = "block";
		}
		else {
			document.all[layerId].style.display = "none";
		}
	}
	if (ns6 || saf) {
		if (document.getElementById([layerId]).style.display == "none") {
			document.getElementById([layerId]).style.display = "block";
		}
		else {
			document.getElementById([layerId]).style.display = "none";
		}
	}
}

// limit the number of caracters inside a textarea
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}