/***************************** domFunctions.js ***************************** 

Author: Paul Kerrison
Creation Date: 01/08/07
Description: Common DOM javascript functions - used to get references to DOM objects, manipulate them etc 
Dependencies: generalFunctions.js

********************************************************************************/


/*********************************** CONTENTS ***********************************

		1.  htmlObject(name) - Used to create a javascript HTML object
		2.  getElmt(elmtId) - Used to gain raw access to a HTML element (if possible create an object using htmlObject above)
		3.  switchVis(elmtId) - Pass in an element's id - if it is hidden, it'll be made visible and vice versa
		4.  switchColor(elmtId, colour1, colour2) - pass in an elemnt's id and two colours - the elements background colour will switch between the two
		5.  switchClass(elmtId, class1, class2) - pass in an element's id and two css classes - the elements css class will switch between the two
		6.  switchElmtClass(elmtId, class1, class2) - pass in an element and two css classes - the elements css class will switch between the two (where possible use switchClass above)
		7.  showTableRow(rowId, hiddenInputField, formId) - pass in an elemnt's id a hidden field that you want the row's id to go in and the containing form - the function will populate the hidden field and then submit the form
		8.  cancelPropagation(e, elmt) - Use to cancel propogation of an event further up the DOM tree (ie click on a table cell but stop it activating the click on the row)
		9.  
		10. 
		11. 
		12. 
		13. 
		14. 
		15. 

*********************************** END CONTENTS ***********************************/

//Uncomment the following line to check the file is being loaded
//alert("Loaded Javascript file: Generic functions");


//Simple test to ensure the browser supports dhtml operations
var DHTML = (document.getElementById || document.all || document.layers);

//1. Used to create a javascript HTML object
function htmlObject(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

//2. Used to gain raw access to a HTMl element (if possible create an object using htmlObject above)
function getElmt(elmtId){
	var elmt;
	if (document.all){
		elmt = document.all[elmtId];
	}else{
		elmt = document.getElementById(elmtId);
	}
	return elmt;
}

//3. Pass in an element's id - if it is hidden, it'll be made visible and vice versa
function switchVis(elmtId){
	//alert(elmtId);
	if (!DHTML) return;
	var elmt = new htmlObject(elmtId);
	elmt.style.visibility = (elmt.style.visibility=='visible') ? 'hidden' : 'visible';
}

//4. pass in an elemnt's id and two colours - the elements background colour will switch between the two
function switchColor(elmtId, colour1, colour2){
	//alert(elmtId);
	if (!DHTML) return;
	var  elmt = new htmlObject(elmtId);
	elmt.style.backgroundColor = (elmt.style.backgroundColor==colour1) ? colour2 : colour1;
}

//5. pass in an elemnt's id and two css classes - the elements css class will switch between the two
function switchClass(elmtId, class1, class2){
	//alert(elmtId);
	if (!DHTML) return;
	var  elmt = new htmlObject(elmtId);
	elmt.obj.className = (elmt.obj.className==class1) ? class2 : class1;
}

//6. pass in an elemnt and two css classes - the elements css class will switch between the two (if possible use swicthClass above)
function switchElmtClass(elmt, class1, class2){
	if (!DHTML) return;
	elmt.className = (elmt.className==class1) ? class2 : class1;
}

//7. pass in an elemnt's id a hidden field that you want the row's id to go in and the containing form - the function will populate the hidden field and then submit the form
function showTableRow(rowId, hiddenInputField, formId){
	//alert("XXXX rowId: " + rowId + "\nhiddenInputField: " + hiddenInputFieldId + "\nformId: " + formId);
	if (!DHTML) return;
	var  elmt = new htmlObject(hiddenInputField); //hidden input field used to contain row id
	elmt.obj.value = rowId;
	var form = new htmlObject(formId); // form containing hidden field
	form.obj.submit();
}

//8. Use to cancel propogation of an event further up the DOM tree (ie click on a table cell but stop it activating the click on the row)
function cancelPropagation(e, elmt){
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}
 


