/***********************************************************************
 * (C) SCC Informationssysteme GmbH 2000 - 2004                        *
 ***********************************************************************/

var ie     = Browser.isIE();
var ns     = Browser.isNS();
var opera  = Browser.isOpera();
var safari = Browser.isSafari();

/*
+ ---------------------------------------------------------------------------------+
| Purpose....: Initialize the eventhandlers needed by the common controls framework
|
| Date        Author            Notice
| ----------  ----------------  ----------------------------------------------------
| 23.12.2002  G.Schulz (SCC)    Erstversion
|
+ ---------------------------------------------------------------------------------+
*/
function init() {
	// initialize Eventhandlers for MouseOver, MouseOut-Events
	setupEventHandler();
}


/*
+ ---------------------------------------------------------------------------------+
| Purpose....: Captures the events needed by the common controls framework and
|              registers the Eventhandlers
|
| Date        Author            Notice
| ----------  ----------------  ----------------------------------------------------
| 23.12.2002  G.Schulz (SCC)    Erstversion
| 31.03.2004  G.Schulz (SCC)    Safari support added
+ ---------------------------------------------------------------------------------+
*/
function setupEventHandler() {

	if (ie || opera) {
		// register Mouse-Handler in IE
		document.onmouseover = HandleMouseover;
		document.onmouseout  = HandleMouseout;
	} else if (ns || safari) {
		// Event-Capturing in NS
		window.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		window.onmouseover = HandleMouseover;
		window.onmouseout  = HandleMouseout;
	}
}


/*
+ ---------------------------------------------------------------------------------+
| Purpose..:  Eventhandler for HandleMouseover
|             Changes the image for a button/menuitem, if the user moves the coursor
|             over the button/menuitem (element).
|             For this buttons must of type 'img' or 'input' and the id must start with "btn".
|             - the image (gif) with the ending 1.gif stands for an active element
|             - the image (gif) with the ending 3.gif stands for an active element hover
|             - the image (gif) with the ending 5.gif stands for a selected element
|             - the image (gif) with the ending 6.gif stands for a selected element (hover)
|
| Datum       Author            Bemerkung
| ----------  ----------------  ----------------------------------------------------
| 23.12.2002  G.Schulz (SCC)    Erstversion
| 16.01.2004  G.Schulz (SCC)    Suppports now all type of images, not only gif's
| 31.03.2004  G.Schulz (SCC)    Safari support added
+ ---------------------------------------------------------------------------------+
*/
function HandleMouseover(event) {
	var eSrc = null;
	if (ie) {
		eSrc = window.event.srcElement;
	}
	else if(ns || safari) {
		eSrc = event.target;
	}

	if (null == eSrc || null == eSrc.tagName ) return;

	if (("IMG" == eSrc.tagName.toUpperCase() || "INPUT" == eSrc.tagName.toUpperCase()) && eSrc.id.indexOf('btn') != -1) {

		var tokens = eSrc.src.split('.');					// example btnLogin.gif or http://www.domain.com/.../btnLogin.gif
		var imgtype = tokens[tokens.length - 1];			// should return: gif, jpg, etc...

		if (null != imgtype) {

			if (eSrc.src.lastIndexOf('1.' + imgtype) != -1) {
				eSrc.src = eSrc.src.substr(0, eSrc.src.indexOf('.' + imgtype)-1) + '3.' + imgtype;
			}

			if (eSrc.src.lastIndexOf('5.' + imgtype) != -1) {
				eSrc.src = eSrc.src.substr(0, eSrc.src.indexOf('.' + imgtype)-1) + '6.' + imgtype;
			}
		}
	}
}

/*
+ ---------------------------------------------------------------------------------+
| Purpose..:  Eventhandler for HandleMouseout
|             Changes the image for a button/menuitem, if the user moves the coursor
|             away from the button/menuitem (element).
|             For this buttons must of type 'img' or 'input' and the id must start with "btn".
|             - the image (gif) with the ending 1.gif stands for an active element
|             - the image (gif) with the ending 3.gif stands for an active element hover
|             - the image (gif) with the ending 5.gif stands for a selected element
|             - the image (gif) with the ending 6.gif stands for a selected element (hover)
|
| Date        Author            Notice
| ----------  ----------------  ----------------------------------------------------
| 23.12.2002  G.Schulz (SCC)    Erstversion
| 16.01.2004  G.Schulz (SCC)    Suppports now all type of images, not only gif's
| 31.03.2004  G.Schulz (SCC)    Safari support added
+ ---------------------------------------------------------------------------------+
*/
function HandleMouseout(event) {
	var eSrc = null;
	if (ie) {
		eSrc = window.event.srcElement;
	}
	else if(ns || safari) {
		eSrc = event.target;
	}

	if (null == eSrc || null == eSrc.tagName ) return;

	if (("IMG" == eSrc.tagName.toUpperCase() || "INPUT" == eSrc.tagName.toUpperCase()) && eSrc.id.indexOf('btn') != -1) {

		var tokens = eSrc.src.split('.');					// example btnLogin.gif or http://www.domain.com/.../btnLogin.gif
		var imgtype = tokens[tokens.length - 1];			// should return: gif, jpg, etc...

		if (null != imgtype) {
			if (eSrc.src.lastIndexOf('3.' + imgtype) != -1) {
				eSrc.src = eSrc.src.substr(0, eSrc.src.indexOf('.' + imgtype)-1) + '1.' + imgtype;
			}
			if (eSrc.src.lastIndexOf('6.' + imgtype) != -1) {
				eSrc.src = eSrc.src.substr(0, eSrc.src.indexOf('.' + imgtype)-1) + '5.' + imgtype;
			}
		}
	}
}

/*
+ ---------------------------------------------------------------------------------+
| Purpose..:  Sets the color in a row of the Listcontrol if the cursors is moved
|             over the row.
|
| Date        Author            Notice
| ----------  ----------------  ----------------------------------------------------
| 23.12.2002  G.Schulz (SCC)    Erstversion
|
+ ---------------------------------------------------------------------------------+
*/
function high(obj) {
   if (obj.className == 'odd')
      obj.className = 'odds';
   else if (obj.className == 'even')
      obj.className = 'evens';
	//obj.style.background = 'rgb(220,232,236)';
}

function low(obj, isEvenLine) {
   if (obj.className == 'odds')
      obj.className = 'odd';
   else if (obj.className == 'evens')
      obj.className = 'even';
	//if (obj.className == 'odd') {
	//	obj.style.background='white';
	//}
	//else if (obj.className == 'even') {
	//	obj.style.background='rgb(237,239,240)';
	//} else if (obj.className == 'odds' || obj.className == 'evens') {
	//	obj.style.background='##FFCC99';
	//}
}

function submitControlForm(element,control,action,actionPath,param)
{
   var form = element;

   while (form != null && form.tagName != "FORM" && form.tagName != "form")
      form = form.parentNode;

   if (form != null)
   {
      if (actionPath == null)
         actionPath = form.action;

      form.action = actionPath + "?ctrl=" + control + "&action=" + action + "&param=" + param;
      form.submit();
   }
}

