//----------------------------------------------------------------------------
function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';				 
  } else {
     dark.style.display='none';
  }
}

//----------------------------------------------------------------------------
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

//------------------------------------------------------------------------------
function setImageMaxSize(imageElement, width, height) {
	if(window.attachEvent) {
		var newImg = new Image();
		newImg.src = imageElement.src;
		var h = newImg.height;
		var w = newImg.width;
		if (w > width || h > height) {
			if (w > h) {
				imageElement.width = width;
			}
			else {
				imageElement.height = height;
			}
		}
	}
}	

//------------------------------------------------------------------------------
function highlight() {
	if(!document.attachEvent) {return;}
	
	var tables=document.getElementsByTagName("table");
	var _className=" highlight"
	for(var t=0;t<tables.length;t++)
	{
		if((tables[t].className.indexOf("Grid")>-1 && tables[t].className.indexOf("highlight")>-1) || tables[t].className=="lm_tables highlight" || (tables[t].className.indexOf("highlight")>-1 && tables[t].parentElement.tagName == "DIV" && tables[t].parentElement.className == "rounded_table"))
		{
			var tbods=tables[t].getElementsByTagName("tbody");
			for(var b=0;b<tbods.length;b++)
			{
				var rows=tbods[b].getElementsByTagName("tr");
				for(var i=0;i<rows.length;i++)
				{
					if(rows[i].className.indexOf("nohighlight")<0)
					{
						rows[i].onmouseover=function(){this.className=this.className+_className;};
						rows[i].onmouseout=function(){this.className=this.className.replace(_className,"");};
					}
				}
			}
		}
	}
}
//------------------------------------------------------------------------------
function changeCheckboxStateByName(name, image){
    var checkbox = document.getElementsByName(name);
    checkbox[0].click();
    var checked = "";
    if (checkbox[0].checked == true)
	checked = "checked";
    else
	checked = "unchecked";
    image.src = "images/checkbox_"+checked+".png";
}
//------------------------------------------------------------------------------
function changeCheckboxStateById(id, image){
    var checkbox = document.getElementById(id);
    checkbox.click();
    var checked = "";
    if (checkbox.checked == true)
	checked = "checked";
    else
	checked = "unchecked";
    image.src = "images/checkbox_"+checked+".png";
}
//------------------------------------------------------------------------------
function header_highlight() {
	if(!document.attachEvent) return;
	var tables=document.getElementsByTagName("table");
	var _className=" highlight_hover"
	for(var t=0;t<tables.length;t++)
	{
		if(tables[t].className.indexOf("Grid")>-1)
		{
			var tbods=tables[t].getElementsByTagName("tbody");
			for(var b=0;b<tbods.length;b++)
			{
				var rows=tbods[b].getElementsByTagName("tr");
				for(var i=0;i<rows.length;i++)
				{
					
					var heads=rows[i].getElementsByTagName("th");
					for(var h=0;h<heads.length;h++)
					{
						if(heads[h].className=="highlight")
						{	
							heads[h].onmouseover=function(){this.className=this.className+_className;};
							heads[h].onmouseout=function(){this.className=this.className.replace(_className,"");};
						}
					}
				}
			}
		}
	}
}
//------------------------------------------------------------------------------
function Button0_SetTitle(id,title) {
	id = id+"_title";
	var elem = document.getElementById(id);
	elem.innerHTML=title;
}
//------------------------------------------------------------------------------
function Button0_Enable(id,enabled) {
	var id_a = id+"_a";
	var id_table = id+"_table";
	var a = document.getElementById(id_a);
	var t = document.getElementById(id_table);
	var cName
	if ('\v'=='v')
	{cName = 'className';}
	else
	{cName = 'class';}
	if(enabled)
	{
		var href = a.getAttribute('_backup');
		if(href=='' || href==null) {return;}
		a.removeAttribute('_backup');
		a.setAttribute('href',href);
		
		var clas = a.getAttribute(cName);
		a.removeAttribute(cName);
		a.setAttribute(cName,clas.replace('_disabled',''));
		
		var oncl = t.getAttribute('_backup');
		t.removeAttribute('_backup');
		t.setAttribute('onclick',oncl);
		t.style.cssText = 'CURSOR: hand';
		
		var heads = t.getElementsByTagName('th');
		for(var h=0;h<heads.length;h++)
		{
			heads[h].setAttribute(cName,heads[h].getAttribute(cName).replace('_disabled',''));	
		}
	}
	else
	{
		var href = a.getAttribute('href');
		if(href=='' || href==null) {return;}
		a.removeAttribute('href');
		a.setAttribute('_backup',href);
		
		var clas = a.getAttribute(cName);
		a.removeAttribute(cName);
		a.setAttribute(cName,clas+'_disabled');
		
		var oncl = t.getAttribute('onclick');
		//t.removeAttribute('onclick');
		t.onclick = function() {};
		t.setAttribute('_backup',oncl);
		t.style.cssText = '';
		
		var heads = t.getElementsByTagName('th');
		for(var h=0;h<heads.length;h++)
		{
			heads[h].setAttribute(cName,heads[h].getAttribute(cName)+'_disabled');	
		}
	}
}

//------------------------------------------------------------------------------

function catchLoginEnter(evt, formId)
{
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    var user_login = (document.getElementById('user_login').value != '');
    var user_password = (document.getElementById('user_password').value != '');
    if (charCode == 13) {	
		if (!user_login || !user_password) {
			return false;
		} else {
		    document.forms[formId].submit(); 
		    return true;
		}
    } else {
        return true;
    }
}

//------------------------------------------------------------------------------
	
function checkbox_setChecked(id, checked) 
{
	document.getElementById(id).checked = checked;
	if (checked) 
		document.getElementById(id + '_icon').src="images/checkbox_checked.png";
	else {
		document.getElementById(id + '_icon').src="images/checkbox_unchecked.png";
	}
}

//------------------------------------------------------------------------------

function IsNumeric(expression) {
	var nums = "0123456789";
	if (expression.length == 0)
		return(false);
	for (var n=0; n < expression.length; n++) {
		if(nums.indexOf(expression.charAt(n)) == -1)
			return(false);
	}
	return(true);
}