//- DOM related functions
//-
function cmasGetElementPtr( elementID ) 
 {
 if (document.getElementById) return(document.getElementById(elementID));
	if (document.all) return(document.all[elementID]);
	if ((navigator.appName.indexOf('Netscape') != -1) 
	 && (parseInt(naviator.appVersion) == 4))
	 {
		return(document.layers[elementID]);
		}
	return(null);
	}

function cmasGetElementStylePtr( elementID ) 
 {
 if (document.getElementById) return(document.getElementById(elementID).style);
	if (document.all) return(document.all[elementID].style);
	if ((navigator.appName.indexOf('Netscape') != -1) 
	 && (parseInt(naviator.appVersion) == 4))
	 {
		return(document.layers[elementID]);
		}
	return(null);
	}
	
function cmasGetClickedElementForEvent( eventPtr )
 {
	if (!eventPtr) var eventPtr = window.event;
	if (eventPtr.target) return(eventPtr.target.id);
	if (eventPtr.srcElement) 
	 {
		return(eventPtr.srcElement.id);
		}
	return(null);
	}

function cmasGetClickedElement( )
 {
 return(	cmasGetClickedElementForEvent( event ) );
	}
	
function cmasTestClick()
 {
	var elementID = cmasGetClickedElement();
	if (elementID==null) alert('cmas: Could not locate element !');
	else alert('Event on ' + elementID);
	}

function cmasTestClickEvent(event)
 {
	var elementID = cmasGetClickedElementForEvent(event);
	if (elementID==null) alert('cmas: Could not locate element !');
	else alert('Event on ' + elementID);
	}

function cmasTestClickItem( elementPtr )
 {
	if (elementPtr==null) alert('cmas: Could not locate element !');
	else alert('Event on ' + elementPtr.name);
	}

//- Called as:-
//- onClick=cmasMenuCLick(this,event)
//- this: does not seem to get set by Mozilla
//- event: does not work well in Safari (Geko ?)
//- auto: 0 = contract ( make invisible )
//-       1 = expand ( make visible )
//-      -1 = auto(flip)
function cmasMenuClick(elementPtr,eventPtr,action)
	{
	//- NOT Konqueror ( if does not seem to refresh the menu size )...
 if ( navigator.vendor == 'KDE' ) return;
	//- NOT Opera...
	if (navigator.appName.indexOf('Opera') != -1) return;
	//-
	if (eventPtr == null) 
	 {
		var elementID = elementPtr.name;
		//- Use ID if no name property ( Firebird / Mozilla )...
		if (!elementID) var elementID = elementPtr.id;
		} else {
	 var elementID = cmasGetClickedElementForEvent(eventPtr);
	 }
	//- For Safari (Geko)...
//x alert('Element(a)=' + elementID);
	if (!elementID)	var elementID = elementPtr.name;
	if (!elementID) var elementID = elementPtr.id;
	//- Get pointers to all elements associated with this menu heading...
//x alert('Element(b)=' + elementID);
	var menuMainItemPtr = cmasGetElementPtr( elementID );
//x alert('mainElementPtr=' + menuMainItemPtr);
	var menuArrowPtr = cmasGetElementPtr( elementID + 'arrow');
	var menuDetailPtr = cmasGetElementPtr( elementID  + 'detail');
//x alert('menuDetailPtr=' + menuDetailPtr);
//x alert('Class(old)=' + menuDetailPtr.className);
	//-

	if (action == -1)
	 {
		if (menuDetailPtr.className == 'visibleon') 
		 {
			action = 0; //- contract
			} else {
			action = 1; //- expand
			}
  }
	//-	
	if (action == 1) 
	 {
		//- Cope with default(left margin column) and db (database) styles...
		if (menuMainItemPtr.className.substring(0,3) == 'db-')
		 {
		 menuMainItemPtr.className = 'db-menuselected';
			} else {
		 menuMainItemPtr.className = 'menuselected';
		 }
		menuDetailPtr.className = 'visibleon';
		menuArrowPtr.src = 'img/downarrow.gif';
		} else {
		//- Cope with default(left margin column) and db (database) styles...
		if (menuMainItemPtr.className.substring(0,3) == 'db-')
		 {
 		menuMainItemPtr.className = 'db-menunormal';
			} else {
 		menuMainItemPtr.className = 'menunormal';
		 }
		menuDetailPtr.className = 'visibleoff';
		menuArrowPtr.src = 'img/rightarrow.gif';
		}
//x alert('Class(new)=' + menuDetailPtr.className);
	}

function cmasMenu(id,action)
 {
	//z if (action == 1)	cmasMenuCollapse();
	cmasMenuClick(cmasGetElementPtr(id),null,action);
	}
	
//- Init global variable...
cmasActiveMenu='';
//- Used in this function ( may get set durng menu construction )
function cmasCollapseIfNotActive(id)
 {
 if (cmasActiveMenu == id) return;
	cmasMenuClick(cmasGetElementPtr(id),null,0);
	}
function cmasMenuCollapse()
 {
 cmasCollapseIfNotActive('mWWD');
 cmasCollapseIfNotActive('mCL');
// cmasCollapseIfNotActive('mCC');
 cmasCollapseIfNotActive('mNP');
 cmasCollapseIfNotActive('mTR');
	return(true);
	}
//- - - 
function cmasChangeClass(elementPtr, classname)
 {
	elementPtr.className = classname;
 }
	
function cmasOverLink(id)
 {
	cmasChangeClass(cmasGetElementPtr(id),'menuhover');
	}

function cmasOutLink(id)
 {
	cmasChangeClass(cmasGetElementPtr(id),'menulink');
	}
	
	//- Window size related...
var gcmasWidth = 0;
var gcmasHeight = 0;
function cmasGetWindowSize() 
 {
 if( typeof( window.innerWidth ) == 'number' ) 
	 {
  //- Non-IE...
  gcmasWidth = window.innerWidth;
  gcmasHeight = window.innerHeight;
  } else if ( document.documentElement && 
		 ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		{
  //- IE 6+ in 'standards compliant mode'...
  gcmasWidth = document.documentElement.clientWidth;
  gcmasHeight = document.documentElement.clientHeight;
  } else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
		{
  //- IE 4 compatible...
  gcmasWidth = document.body.clientWidth;
  gcmasHeight = document.body.clientHeight;
 }
//x alert( 'Width = ' + gcmasWidth );
//x alert( 'Height = ' + gcmasHeight );
}

function cmasSetMainAreaSize()
 {
	//- Fetch current window height...
	cmasGetWindowSize();
// alert( 'Height = ' + gcmasHeight );
	if (gcmasHeight <=0 ) return;
	//- NOT Konqueror...
	if (navigator.appName == 'Konqueror') return;
	//- Subtract height of Birchcroft logo images + 1 little extra...
	var iHeight = gcmasHeight - 300;
	var mainareaPtr = cmasGetElementPtr("mainarea");
	mainareaPtr.style.height = iHeight + "px";
	}
//-	
//- Form data functions...
var gbIsDirty;
//-
function cmasSetDirty()
 {
	gbIsDirty = true;
	}
	//-
function cmasSetNotDirty()
 {
	gbIsDirty = false;
	}
//-
function cmasCheckDirty()
 {
	if (gbIsDirty)
	 {
		return(confirm('Form data has changed : Please confirm you wish to loose the changes'));
		}
	}
//-	
//-
//- Other functions...
//- Code for this is (modified) from:- http://lab.amanwithapencil.com/tool_tips/		
function cmasTooltipFixIE() 
 { 
	if (document.images && navigator.user_agent.indexOf('MSIE') != -1) 
	 { 
		var iLoop;
		var docImgs = document.images; 
		if (docImgs.length > 0 && docImgs[0].getAttribute) 
		 { 
			for (iLoop = 0; iLoop < docImgs.length; iLoop++) 
			 { 
				if (docImgs[iLoop].getAttribute('alt') != '' && docImgs[iLoop].getAttribute('title') == '') 
				 {
					docImgs[iLoop].setAttribute('title',''); 
					if (docImgs[iLoop].parentNode.getAttribute('title') != '') 
					 {
						docImgs[iLoop].setAttribute('title',docImgs[iLoop].parentNode.getAttribute('title'));
						}
					}
			 } 
			}
		}
 }