function test()
{

}

function ExpandDetailOfSelectedItemInGrid(grid, detail, selectedIndex)
{
	if (selectedIndex > -1){
		if (document.getElementById(grid) != null && document.getElementById(detail) != null) {
			objGrid = document.getElementById(grid);		
			var row = objGrid.insertRow(selectedIndex+2);
			row.className="InsertedRow";
			var cell = row.insertCell(0);
			cell.style.backgroundColor = bgColor;
			cell.className="InsertedCell";			
			cell.colSpan=objGrid.rows.item(0).cells.length;			
			cell.innerHTML= document.getElementById(detail).innerHTML;			
			document.getElementById(detail).innerHTML = "";			
		}
	}
}


function ExpandDetailOfSelectedItemInGrid(grid, detail, selectedIndex, bgColor)
{
	if (selectedIndex > -1){
		if (document.getElementById(grid) != null && document.getElementById(detail) != null) {
			objGrid = document.getElementById(grid);		
			var row = objGrid.insertRow(selectedIndex+2);
			row.className="InsertedRow";
			var cell = row.insertCell(0);
			cell.style.backgroundColor = bgColor;
			cell.className="InsertedCell";			
			cell.colSpan=objGrid.rows.item(0).cells.length;			
			cell.innerHTML= document.getElementById(detail).innerHTML;			
			document.getElementById(detail).innerHTML = "";			
		}
	}
}

function ExpandDetailOfSelectedItemInPagedGrid(grid, detail, selectedIndex, bgColor)
{
	if (selectedIndex > -1){
		if (document.getElementById(grid) != null && document.getElementById(detail) != null) {
			objGrid = document.getElementById(grid);		
			var row = objGrid.insertRow(selectedIndex+3);
			row.className="InsertedRow";
			var cell = row.insertCell(0);
			cell.style.backgroundColor = bgColor;
			cell.className="InsertedCell";			
			cell.colSpan=objGrid.rows.item(1).cells.length;			
			cell.innerHTML= document.getElementById(detail).innerHTML;			
			document.getElementById(detail).innerHTML = "";			
		}
	}
}


function Search() 
{
	var strValue = null;
	var tmpValue = null;
	var checkString = null;
	var strFound;

	if(Form1.findthis.value!=null && Form1.findthis.value!='')
       str = Form1.findthis.value;       
	else return;  

   if (strValue!=null) 
   {
		checkString=document.body.createTextRange();
 
		if (tmpValue.inRange(checkString)) 
		{
			strValue.collapse(false);
			strFound=strValue.findText(str);
			if (strFound) 
			{
				document.body.scrollTop = document.body.scrollTop + strValue.offsetTop;
				strValue.select();
			}

		}
   		else 
   		{
			strValue=document.body.createTextRange();
			strValue.collapse(false);
			strFound=strValue.findText(str);
			if (strFound) 
			{
				document.body.scrollTop = strValue.offsetTop;
				strValue.select();
			}
		}	
	}
  
   if (strValue==null || strFound==0) 
   {
		strValue=document.body.createTextRange();
		tmpValue = strValue.duplicate();
		strFound=strValue.findText(str);
		if (strFound) 
		{
            document.body.scrollTop = strValue.offsetTop;
			strValue.select();
        }
   }

  if (!strFound) 
	alert ("'"+str+"' was not found!") 
}


function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function moveTableHeaders(grid, contentLayer, followingRows)
{    
    var htmlString = "<table ";    
    for (var i = 0; i< grid.attributes.length; i++)
    {
        var attribute = grid.attributes[i];
        if (attribute.specified) 
        {
            if (attribute.nodeName == 'id')
                htmlString+= attribute.nodeName + '=' + attribute.nodeValue + "_HEADER ";
            else
                htmlString+= attribute.nodeName + '=' + attribute.nodeValue + " ";                
        }
    }
    
    htmlString += ">" + grid.rows[0].outerHTML + followingRows + "</table>";   
    grid.deleteRow(grid.rows[0]);    
    contentLayer.innerHTML = htmlString;
}

function adjustGridWidth(gridContainer)
{	
	if (gridContainer != null)
	{
	    gridContainer.insertAdjacentHTML("beforeBegin", '<div id=__DIVTOGETSCROLLWIDTH__ style="width:100%;height:100%"></div>');
	    scrollWidthDiv = document.getElementById('__DIVTOGETSCROLLWIDTH__');
	    var scrollBarWidth = scrollWidthDiv.clientWidth - gridContainer.clientWidth;
	    scrollWidthDiv.parentElement.removeChild(scrollWidthDiv);
	    adjustGridWidthOffset(gridContainer, scrollBarWidth);
	}
}

function adjustGridWidth2(gridContainer, tdScrollPadding)
{
    gridContainer.insertAdjacentHTML("beforeBegin", '<div id=__DIVTOGETSCROLLWIDTH__ style="width:100%;height:100%"></div>');
    scrollWidthDiv = document.getElementById('__DIVTOGETSCROLLWIDTH__');
    var scrollBarWidth = scrollWidthDiv.clientWidth - gridContainer.clientWidth;
    scrollWidthDiv.parentElement.removeChild(scrollWidthDiv);
    tdScrollPadding.style.paddingRight = scrollBarWidth;
}

function adjustGridWidthOffset(gridContainer, scrollBarWidth)
{	
	if (gridContainer != null)
	{	    
		if (gridContainer.scrollHeight <= gridContainer.clientHeight)
			gridContainer.style.marginRight = "17px";
		else
			gridContainer.style.marginRight = (17 - scrollBarWidth) + "px";
	}
}

function adjustGridWidthOffset(gridContainer)
{	
	if (gridContainer != null)
	{
	    var scrollBarWidth = gridContainer.parentElement.clientWidth - gridContainer.clientWidth;
		if (gridContainer.scrollHeight <= gridContainer.clientHeight)
			gridContainer.style.marginRight = "17px";
		else
			gridContainer.style.marginRight = (17 - scrollBarWidth) + "px";
	}
}

function GetDialogFeatures(dialogWidth, dialogHeight, resizable, scrollable)
{
    return "dialogWidth: " + dialogWidth + "px;dialogHeight: " + dialogHeight + "px;status: no;unadorned: yes;help: no; " + (resizable ? "resizable: yes;" : "") + (scrollable ? "scroll: yes;" : "scroll: no;");
}

function AddLoadEvent(func) 
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } 
  else 
  {
    window.onload = function() {oldonload();func();}
  }
}

function AddEvent(func, eventPointer)
{
  var oldonload = eventPointer;
  if (typeof eventPointer != 'function') 
  {
        eventPointer = func;
  } 
  else 
  {
    eventPointer = function() {oldonload();func();}
  }
    
}

function AppendEvent(func, currentFunction)
{
      var oldonload = currentFunction;
      if (typeof currentFunction != 'function') 
      {
            currentFunction = func;
      } 
      else 
      {
            currentFunction = function() {oldonload();func();}
      }
      return currentFunction;
}

function AddOnClickEvent(object, func)
{
  var oldonclick = object.onclick;
  if (typeof object.onclick != 'function') 
  {
    object.onclick = func;
  } 
  else 
  {
    object.onclick = function() {oldonclick();func();}
  }
}

function AddOnClickEventToBeginning(object, func)
{
  var oldonclick = object.onclick;
  if (typeof object.onclick != 'function') 
  {
    object.onclick = func;
  } 
  else 
  {
    object.onclick = function() {func();oldonclick();}
  }
}

function AddConditionalOnClickEventToBeginning(object, func)
{
  var oldonclick = object.onclick;
  if (typeof object.onclick != 'function') 
  {
    object.onclick = func;
  } 
  else 
  {
    object.onclick = function() {if (func()) oldonclick();}
  }
}

function AddConditionalOnClickEvent(object, func)
{
  var oldonclick = object.onclick;
  
  if (typeof object.onclick != 'function') 
  {
    object.onclick = func;
  } 
  else 
  {
    object.onclick = function() {if (oldonclick()) func();}
  }
}

function AddDebouncer(onclickObject)
{
    onclickObject.onclick = AppendEvent(Debounce, onclickObject.onclick);
}

function Debounce()
{    
    if (event.returnValue == false)
    {
        
    }
    else
    {
        event.srcElement.onclick = SuppressClick;
    }
}

function SuppressClick()
{
    event.returnValue = false;
}

function ShowModalessDialogue(path, name, height, width)
{
    var top = (screen.height - height) / 2 + "px";
    var left = (screen.width - width) / 2 + "px";
    var properties = 'dialogHeight:' + height + 'px;dialogWidth:' + width + 'px;dialogTop:' + top + ';dialogLeft:' + left + ';resizable:0; scrollbars:1';
    var popup = window.showModelessDialog(path,name,properties);
    popup.focus();
}

function ShowModalDialogue(path, name, height, width)
{
    var top = (screen.height - height) / 2 + "px";
    var left = (screen.width - width) / 2 + "px";
    var properties = 'dialogHeight:' + height + 'px;dialogWidth:' + width + 'px;dialogTop:' + top + ';dialogLeft:' + left + ';resizable:0; scrollbars:1';
    alert('');
    return window.showModalDialog(path,name,properties);
}

function checkAllBoxesInGrid(checkVal, grid) 
{   
    for (var i = 1; i < grid.rows.length; i++)
	{ 
	    grid.rows[i].cells[0].getElementsByTagName("input")[0].checked = checkVal;		    
	}
}
