//
// Core JavaScript include file - this should be included on the front end and backend.
//

debugEnabled = false;

if(debugEnabled) {
	document.write ('<div id="jsdebug" style="width:100%;position:absolute;visibility:hidden;left:0px;top:0px;height:0px;">');
	document.write ('<div id="debugtext" style="border-bottom:1px solid #000000;padding:10px;line-height:140%;"><strong>JavaScript debug...</strong><br /><br /></div>');
	document.write ('<div id="debugtoggle" style="border-bottom:1px solid #000000;padding:4px;text-align:right;background-color:#FFFFFF;">[ <a href="javascript:toggleDiv(\'debugtext\');">toggle debug</a> ]</div>');
	document.write ('</div>');
}


// Used to add a line to debug window...
function debug(debugString) {
	if(debugEnabled) {
		if(document.getElementById('jsdebug')) {
			
			// Have we displayed the JavaScript debug window yet?
			if(document.getElementById('jsdebug').style.visibility == 'hidden') {
				document.getElementById('jsdebug').style.visibility = 'visible';
				document.getElementById('jsdebug').style.opacity = '.95';
				document.getElementById('jsdebug').height = '170px';
				document.getElementById('debugtext').style.height = '140px';
				document.getElementById('debugtext').style.backgroundColor = '#FFFFCC';
				document.getElementById('debugtext').style.overflow = 'auto';
			}
			
			document.getElementById('debugtext').innerHTML += '> '+debugString+'<br />';
			document.getElementById('debugtext').scrollTop = document.getElementById('debugtext').scrollHeight;
		}
		else alert(debugString);
	}
}


// Used to obtain the screen size...
function getScreenSize() {

	var coords=new Object();
	coords.x = screen.width;
	coords.y = screen.height;

	return (coords);
}

// Used to display popup windows...
function popup(u,n,w,h,s) {
    var l = (screen.width)  ? (screen.width  - w)/2 : 0;
    var t = (screen.height) ? (screen.height - h)/2 : 0;
    var p = window.open(u, n, 'width='+w+',height='+h+',scrollbars='+s+',left='+l+',top='+t+',resizable');
	p.opener = self;
	p.focus();
}

function updateImageAltStatus() {
	if(document.getElementById('imagealt').style.display == "block") { document.getElementById('showimgalt').value = 'on'; }
	else { document.getElementById('showimgalt').value = 'off'; }
}


// Used to set the source image for the specified element...
function setSourceImage(element, source) { if(document.getElementById(element)) document.getElementById(element).src = source; }

// Used to set the source innerHTML for the specified element...
function setSourceData(element, data) { if(document.getElementById(element)) document.getElementById(element).innerHTML = data; }

// Used to set the source value for the specified element...
function setSourceValue(element, data) { if(document.getElementById(element)) document.getElementById(element).value = data; }


// Used to output a confirmation dialog...
function showConfirm(text, destination) {
	var returnState = confirm(text);
	if (returnState) document.location=destination;
}


// Used to toggle the visibility of a div...
function toggleDiv(divname) {
    if (document.getElementById(divname).style.display == "none") showDiv(divname);
    else hideDiv(divname);
}


// Used to show a div...
function showDiv(divname) { document.getElementById(divname).style.display="block"; }

// Used to hide a div...
function hideDiv(divname) { document.getElementById(divname).style.display="none"; }

// Used to enable a div...
function enableElement(id) { document.getElementById(id).disabled=false; }

// Used to disable a div...
function disableElement(id) { document.getElementById(id).disabled=true; }