// disable back button
//history.forward();

// fix a big in flash player 9
function nullFlashLoopFunction() { 
	__flash_savedUnloadHandler = null; 
}
window.onbeforeunload = nullFlashLoopFunction;

// browser detection
var firefox = navigator.userAgent.indexOf("Firefox") != -1
var explorer = navigator.userAgent.indexOf("MSIE") != -1
var explorer7 = navigator.userAgent.indexOf("MSIE 7.0") != -1
var netscape = navigator.userAgent.indexOf("Netscape") != -1
var safari = navigator.userAgent.indexOf("Safari") != -1
var opera = navigator.userAgent.indexOf("Opera") != -1
var camino = navigator.userAgent.indexOf("Camino") != -1
var macintosh = navigator.platform.indexOf("Mac") != -1

// return browser's is
function whoAreYou() {
	if (firefox) { alert('firefox'); }
	if (explorer && !explorer7) { alert('explorer6'); }
	if (explorer7) { alert('explorer7'); }
	if (opera) { alert('opera'); }
	if (netscape) { alert('netscape'); }
	if (safari) { alert('safari'); }
	if (camino) { alert('camino'); }
	/*
		if (macintosh) { alert('macintosh'); }
		else { alert('pc'); }
	*/
}

// open a popup centered in user's screen
function popCenter(page, name, width, height, scroll) {
	 var winLeft = (screen.width - width) / 2;
	 var winTop = (screen.height - height) / 2;
	 winprops = 'width=' + width + ',height=' + height + ',left=' + winLeft + ',top=' + winTop + ',scrollbars=' + scroll + ',';
	 win = window.open(page, name, winprops);
	 win.focus();
}

// rollover for .gif images (3 states: of, on, in)
function changeGifImage(which) { 
	try {
		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';
	}
	catch(err){}
}

// rollover for .jpg images (3 states: of, on, in)
function changeJpgImage(which) { 
	try {
		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';
	}
	catch(err){}
}

// show & hide a layer
function layerVisibility(layerId) {
	if (document.getElementById([layerId]).style.display == "none") {
		document.getElementById([layerId]).style.display = "block";
	}
	else { document.getElementById([layerId]).style.display = "none"; }
}

// show a layer
function showLayer(layerId) {
	document.getElementById([layerId]).style.display = "block";
}

// hide a layer
function hideLayer(layerId) {
	document.getElementById([layerId]).style.display = "none";
}

// change an iframe's src
function changeFrame(frameId, url) {
	var oIframe = document.getElementById([frameId]);
	oIframe.src = url;
}

// load empty.aspx in a specific frame
function emptyFrame(frameId) {
	var oIframe = document.getElementById([frameId]);
	oIframe.src = "/empty.aspx";
}

// embed a flash file
function insertFlash(name, width, height, flashvars) {
	document.write('<object width="' + width + '" height="' + height + '" id="' + name + '" align="top" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="/resources/flash/' + name + '.swf" />\n');
	document.write('<param name="menu" value="false" />\n');
	document.write('<param name="flashvars" value="' + flashvars + '">\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="scale" value="noscale" />\n');
	document.write('<param name="align" value="t" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<param name="bgcolor" value="#FFFFFF" />\n');
	document.write('<embed width="' + width + '" height="' + height + '" name="' + name + '" src="/resources/flash/' + name + '.swf" flashvars="' + flashvars + '" menu="false" align="top" quality="high" scale="noscale" salign="t" wmode="transparent" bgcolor="#FFFFFF" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>\n');
}

// print the page
function printMe() { window.print(); }

// go to position (x,y) inside the page
function goTo(x, y) { self.scrollTo(x, y) }

// set max character on 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; }
}

