function ChangePage(intPageID) {
  document.frmMain.elements['inpPageID'].value = intPageID;
  document.frmMain.elements['inpAction'].value = 'CHANGEPAGE';
  SubmitPage();
}
function ChangePreviousPage() {
  document.frmMain.elements['inpAction'].value = 'CHANGEPAGEPREVIOUS';
  SubmitPage();
}
function PrintPage() {
  document.frmMain.elements['inpAction'].value = 'PRINTPAGE';
  SubmitPage();
}
function SaveOnlyPage() {
  document.frmMain.elements['inpAction'].value = 'SAVEONLY';
  SubmitPage();
}
function SubmitPage() {
  if(typeof AdjustResponse != 'undefined') AdjustResponse();
  document.frmMain.submit();
}

/* ******************************** */

function isJSON(strText) 
{
    var str = strText.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
    return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
}

function doAction(strAction)
{
	document.frmMain.elements['inpAction'].value = strAction;
	document.frmMain.submit();
}

function LoginSubmit() 
{
	document.frmLogin.submit();
}

function ForgotPassword() 
{
	document.frmLogin.inpAction.value = 'FORGOTTENPASSWORD';
	document.frmLogin.submit();
}

function CancelReset() 
{
	document.frmMain.inpAction.value = 'CANCELRESET';
	document.frmMain.submit();
}

function eventRemoveBubbling(e)
{
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

// toggle or assign display property to specific element
function toggleLayer( whichLayer, state)
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	
	if (state != 'none' && state != 'block')
		vis.display = (vis.display==''||vis.display=='block')?'none':'block';
	else
		vis.display = state;
}

// check display property of specific element
function checkLayerDisplay( whichLayer )
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	
	return (vis.display==''||vis.display=='block')?'block':'none';
}

// toggle or assign disabled property to specific element
function toggleDisabledLayer( whichLayer, state)
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];

	if (state != 'disabled' && state != 'enabled')
		elem.disabled = !(elem.disabled);
	else if (state == 'enabled')
		elem.disabled = false;
	else 
		elem.disabled = true;
}

// return disabled status of element id
function checkDisabledLayer( whichLayer)
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];

	return elem.disabled;
}

// clear value of provided text field
function clearValue(whichLayer)
{
	var elem;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];

	elem.value = '';   	
}

// get reference to object of provided field
function getObject(whichLayer)
{
	var elem;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];

	return elem;
}

// get value of provided text field
function getValue(whichLayer)
{
	var elem;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];

	return elem.value;
}

// set value of provided text field
function setValue(whichLayer, newvalue)
{
	var elem;

	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];

	elem.value = newvalue;
}

// focus on specified object
function focusOn(whichLayer)
{
	var elem;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];

	elem.focus();
}

// return disabled status of element id
function isDefined( whichLayer)
{
	var elem;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	
	return (elem != null);
}


// update html contents of specified span tag
function updateSpan(whichLayer, content)
{
	var elem;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];

	elem.innerHTML = content;   	
}

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};


// dump contents of variable
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}
