<!--//
if (document.layers) { // Netscape
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
		document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
		document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
	try {
		if (document.layers) {
				xMousePos = e.pageX;
				yMousePos = e.pageY;
				xMousePosMax = window.innerWidth+window.pageXOffset;
				yMousePosMax = window.innerHeight+window.pageYOffset;

		} else if (document.all) {
				xMousePos = window.event.x+document.body.scrollLeft;
				yMousePos = window.event.y+document.body.scrollTop;
				xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
				yMousePosMax = document.body.clientHeight+document.body.scrollTop;
		} else if (document.getElementById) {
				// Netscape 6 behaves the same as Netscape 4 in this regard
				xMousePos = e.pageX;
				yMousePos = e.pageY;
				xMousePosMax = window.innerWidth+window.pageXOffset;
				yMousePosMax = window.innerHeight+window.pageYOffset;
		}
	} catch (error) {

	}
}

// hide the glossary div
function hideGlossary() {
    var obj;
	if ((obj = findObj("glossaryLayer")) != null) {
			// now that the div has been moved into position show it.
			obj.style.visibility = "hidden";
			obj.style.display = "none";
			obj.innerHTML = '';
	}
}

// show the div
function showTitle(title) {
    var obj;

	if ((obj = findObj("glossaryLayer")) != null) {

			newHTML = '<table id="glossaryTable" cellpadding="3" cellspacing="0" border="0" style="border:1px solid black;">';
			newHTML += "   <tr>";
			newHTML += '        <th>' + title + '</th>';
			newHTML += '	</tr>';
			newHTML += '</table>';
	
			obj.innerHTML = newHTML;
			obj.style.visibility = "visible";
			obj.style.display = "";

			xpos = xMousePos + 'px';
			ypos = yMousePos + 'px';

			obj.style.left = xpos;
			obj.style.top = ypos;
	}
}

function setRowClass(src, style) {
	src.className = style;
}

function setClassById(id, style) {
	var obj;

	if ((obj = findObj(id)) != null) {
		setClass(obj, style);
	}
}


/* search the dom for the object */
function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) {
    x=d.all[n];
  }
  for (i=0;!x&&i<d.forms.length;i++) {
    x=d.forms[i][n];
  }
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) {
    x=findObj(n,d.layers[i].document);
  }
  if(!x && d.getElementById) {
    x=d.getElementById(n);
  }
  // alert('object ' + n + ' is ' + x);
  return x;
}


/* find then set a layers visibility */
function showHideLayers() { //v6.0
  var i,p,v,obj,args=showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) {

        if ((obj=findObj(args[i]))!=null) {
            v=args[i+2];
            if (obj.style) {
                obj=obj.style;
                v=(v=='show')? 'visible' : (v=='hide')? 'hidden':v;
            }
            obj.visibility=v;
    }
  }
}

/* takes the highlighting of a field */
function blurField(field) {
	try {
		var classes = field.className.split(" fieldOn");
		if (classes.length > 0) {
			field.className = classes[0];
		}
	} catch (error) {

	}
}

/* puts highlighting focus on a field */
function focusField(field) {
	
	try {
	  field.className = field.className + ' fieldOn';
	  field.focus();
	} catch (error) {

	}
}

/* sets the background colour of a field */
function setColour(src, colour) {
  src.style.backgroundColor=colour;
}

/**
 * Set the css class of an object
 */
function setClass(src, name) {
  src.className = name;
}

/* selects an array element */
function selectRadio(groupName, newval) {
   var buttonGroup;

   // get the button group element from its name
   eval("buttonGroup = " + groupName);

   for (var i=0; i<buttonGroup.length; i++) {

         if (buttonGroup[i].value == newval) {
            buttonGroup[i].checked = true;
         }
      }
   }

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

/**
 *
 */
function displayLayer(name, value) {

	element = findObj(name);

	if (element != null) {

		//
		if (value == 'none') {
			element.style.display = 'none';
		} else {
			element.style.display = '';
		}
	}
}

/**
 * Check if the value of a field is i digit
 */
function isDigit(textfield) {

	var numeric = /^[0-9]+$/.test(textfield.value);
	if (!numeric) {
		alert('Please enter a numeric value');
		return false;
	}
	return true;

}

/**
 * Sets the inner html for a label
 */
function setLabel(lbl, value) {
	var obj;
	if ((obj = findObj(lbl)) != null) {
		obj.innerHTML = value;
	}
}

/**
 * The general page submissiong script, calls the validation
 * which can in turn show any errors
 */
function submitForm() {

	if (validateForm()) {
		document.form.submit();
		return true; // never gets to here
	}

	return false;
}

/**
 * Sets the selected option on a select
 */
function selectOption(field, value) {
	options = field.options;

	for(i=0;i<options.length;i++) {

		if (options[i].value == value) {
			field.options.selectedIndex = i;
		}
	}
}

function confirmDelete(item) {
  	return confirm('Are you sure you want to delete this ' + item + '?\n\tTo continue click \'OK\'\n');
}

function openPopup(height, width) {
	var left = 0;
	var top = 0;

	try {
	    left = (screen.width) ? (screen.width-width)/2 : 0;
    	top  = (screen.height) ? (screen.height-height)/2 : 0;
	} catch (error) {
		// 
	}

	window.open("","x",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',resizable=1');
}

function showGlossary(title, definition, e) {
    var obj;

	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.PageX;
		posy = e.PageY;
	} else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
	
	if ((obj = findObj("glossaryLayer")) != null) {

			newHTML = '<table id="glossaryTable" cellpadding="3" cellspacing="0" border="0" style="border:1px solid black;">';
			newHTML += "   <tr>";
			newHTML += '        <th>' + title + '</th>';
			newHTML += '	</tr>';
			newHTML += '	<tr>';
			newHTML += '		<td>' + definition + '</td>';
			newHTML += '    </tr>';
			newHTML += '</table>';

			obj.innerHTML = newHTML;
			obj.style.visibility = "visible";
			obj.style.display = "";

			xpos = xMousePos + 'px';
			ypos = yMousePos + 'px';

			obj.style.left = xpos;
			obj.style.top = ypos;
	}
}
//-->

