  // this function is need to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   
  
  

 function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    
    var oddColor = arguments[1] ? arguments[1] : "#fff";
    var evenColor = arguments[2] ? arguments[2] : "#DBE7F0" ; /*"#B7DFFF";  "#edf3fe";*/
    
   // var oddColor = arguments[2] ? arguments[2] : "#eee";
    
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

	    // avoid rows that have a class attribute
        // or backgroundColor style
	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 
         // get all the cells in this row...
          //var tds = trs[i].getElementsByTagName("td");
          
          trs[i].style.backgroundColor = even ? evenColor : oddColor;
        
          // and iterate through them...
          /*for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
	        if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
        
		      mytd.style.backgroundColor = even ? evenColor : oddColor;
              
            }
          }*/
          
        }
        
       /*trs[i].onmouseover = function(e) {  
       		//var targ = getEventSource(e);
       		event.target.className="hovered";
       	};
		trs[i].onmouseout = function(e) {
       		event.target.className="";
		};*/
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
    
  }

  
function confirm_redirect(msg, url)
{
	if (confirm(msg))
	{	
		location.href=url;
	}
}

function AddEventHandler(target, name, func, phase) {
        if (target.attachEvent) {
            target.attachEvent("on"+name, func);
        }
        else {
            target.addEventListener(name, func, phase);
        }      
 }

function checkBoxToggle(ctrlbox_id, chk_prefix)
{
	ctrlbox = document.getElementById(ctrlbox_id); 

	var newVal=false;
	if (ctrlbox.checked)
		newVal = true;

	var j = 1;
	while (1) {
		box = document.getElementById(chk_prefix+j); 
		if (box)
		{
			box.checked = newVal;
			j++;
		}else{
			break;
		}
	}
}

function expandTextArea(areaid, nrows)
{
	var obj=document.getElementById(areaid);
	obj.rows=nrows;
}

function toggleDisplay(obj_id)
{
	var  obj= document.getElementById(obj_id);
	obj.style.visibility = (obj.style.visibility == "visible") ? "hidden" : "visible";
}



function stopEnter(e) {
	if (e && e.preventDefault){
	
		if (e.keyCode==13)
		    e.preventDefault(); // DOM style
	}
	else
	{
		if (event.keyCode==13)
			event.returnValue=false;
		return false; // IE style
	}
}

function numvalidator(field) {
     var value = field.value;          // get input value
// Change the backgroundColor of the input field based on whether or not
// the value of the input field is a number.
     if(isNaN(value)) {
          field.style.backgroundColor = 'red';
     } else {
          field.style.backgroundColor = 'white';
     }
}

function overlay()
{
	overlay(null, 0, 0);
}

function overlay(onTopDiv, w, h)
 {
	el = document.getElementById("overlay");
	theDiv = document.getElementById(onTopDiv);
	
	if (el.style.visibility == "visible")
	{
		el.style.width = '0px' ;
		el.style.height = '0px' ;
		el.style.visibility = "hidden";
	}else
	{
		el.style.visibility = "visible";
		el.style.width = '100%' ;
		el.style.height = '100%' ;
	}
	//el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
	
	
	var x,y; 
	if (self.innerHeight) // all except Explorer 
		{ x = self.innerWidth; y = self.innerHeight; } 
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode 
		{ x = document.documentElement.clientWidth; y = document.documentElement.clientHeight; } 
	else if (document.body) // other Explorers 
		{ x = document.body.clientWidth; y = document.body.clientHeight; }

	if (theDiv){
		theDiv.style.height=h+'px';
		theDiv.style.left = (x- w )/2 + 'px'; // viewport minus width, divide by 2 
		theDiv.style.top = ((y- h )/2 + f_scrollTop()) + 'px'; // viewport minus height, divide by 2
		
		theDiv.style.visibility = (theDiv.style.visibility == "visible") ? "hidden" : "visible";
	}
}

/*
function overlay(onTopDiv, w, h)
 {
	el = document.getElementById("overlay");
	theDiv = document.getElementById(onTopDiv);
	
	if (el.style.visibility == "visible")
	{
		el.style.width = '0px' ;
		el.style.height = '0px' ;
		el.style.visibility = "hidden";
	}else
	{
		el.style.visibility = "visible";
		el.style.width = '100%' ;
		el.style.height = '100%' ;
	}
	//el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
	
	
	var x,y; if (self.innerHeight) // all except Explorer 
	{ x = self.innerWidth; y = self.innerHeight; } 
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode 
	{ x = document.documentElement.clientWidth; y = document.documentElement.clientHeight; } 
	else if (document.body) // other Explorers 
	{ x = document.body.clientWidth; y = document.body.clientHeight; }
	
	theDiv.style.height = h;
	theDiv.style.left = (x- w )/2 + 'px'; // viewport minus width, divide by 2 
	theDiv.style.top = ((y- h )/2 + f_scrollTop()) + 'px'; // viewport minus height, divide by 2
	
	theDiv.style.visibility = (theDiv.style.visibility == "visible") ? "hidden" : "visible";
}*/

function f_scrollLeft() {
        return f_filterResults (
                window.pageXOffset ? window.pageXOffset : 0,
                document.documentElement ? document.documentElement.scrollLeft : 0,
                document.body ? document.body.scrollLeft : 0
        );
}
function f_scrollTop() {
        return f_filterResults (
                window.pageYOffset ? window.pageYOffset : 0,
                document.documentElement ? document.documentElement.scrollTop : 0,
                document.body ? document.body.scrollTop : 0
        );
}
function f_filterResults(n_win, n_docel, n_body) {
        var n_result = n_win ? n_win : 0;
        if (n_docel && (!n_result || (n_result > n_docel)))
                n_result = n_docel;
        return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}