function test()
{
    alert();
}

//use this method to restrict the max length of multi-line textboxes
//i.e. onkeydown="RestrictTextBoxLength(this, 1000)"
function RestrictTextBoxLength(object, maxLength)
{
    if (object.value.length < maxLength)
    {
        return true;
    }
    else 
    {
        //only allow following keys: delete, backspace, left and right arrows
        if ((event.keyCode>=37 && event.keyCode<=40) || (event.keyCode==8) || (event.keyCode==46)) 
        {
            event.returnValue = true;
        }
        else
        {
            event.returnValue = false;
        }
    }
}

//use this method to restrict the max length of multi-line textboxes
//i.e. onkeydown="RestrictTextBoxLength(this, 1000)"
function RestrictTextBoxLength(object, maxLength)
{
    if (object.value.length < maxLength)
    {
        return true;
    }
    else 
    {
        //only allow following keys: delete, backspace, left and right arrows
        if ((event.keyCode>=37 && event.keyCode<=40) || (event.keyCode==8) || (event.keyCode==46)) 
        {
            event.returnValue = true;
        }
        else
        {
            event.returnValue = false;
        }
    }
}

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!='')
//    if(document.forms[0].findthis.value!=null && document.forms[0].findthis.value!='')
//    {
//	   //str = Form1.findthis.value;       
//	   str = document.forms[0].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;
	    if (checkVal) 
    	    grid.rows[i].className = "SelectedItemStyle";
    	else if (i%2==1)
    	    grid.rows[i].className = "ItemStyle";
    	else
    	    grid.rows[i].className = "AlternatingItemStyle";
	}
}
function SetClass(cb)
{
    if (cb.checked)
        cb.parentNode.parentNode.parentNode.className = "SelectedItemStyle";
    else
        cb.parentNode.parentNode.parentNode.className = "ItemStyle";
}

// More Actions Drop Down control implementation
// /////////////////////////////////////////////
var MoreActions_timeout         = 500;
var MoreActions_closetimer		= 0;
var MoreActions_ddmenuitem      = 0;

// open hidden layer
function mopen(id)
{	
    // cancel close timer
    mcancelclosetime();

    // close old layer
    if(MoreActions_ddmenuitem)
    {
        MoreActions_ddmenuitem.style.visibility = 'hidden';
    }
    
    // get new layer and show it
    MoreActions_ddmenuitem = document.getElementById(id);
    MoreActions_ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
    if(MoreActions_ddmenuitem)
    {
        MoreActions_ddmenuitem.style.visibility = 'hidden';
    }
}

// go close timer
function mclosetime()
{
    MoreActions_closetimer = window.setTimeout(mclose, MoreActions_timeout);
}

// cancel close timer
function mcancelclosetime()
{
    if(MoreActions_closetimer)
    {
        window.clearTimeout(MoreActions_closetimer);
        MoreActions_closetimer = null;
    }
}

//mechanism to properly enable/disable links
var linkButtonClickFunctions = new ActiveXObject("Scripting.Dictionary");
function EnableLink(button)
{
    if (linkButtonClickFunctions.Exists(button.id))
    {
        button.onclick = linkButtonClickFunctions.Item(button.id);
        linkButtonClickFunctions.Remove(button.id);
        
        button.disabled = false;
    }
}
function DisableLink(button)
{
    if (button.onclick != ReturnFalse)
    {
        if (linkButtonClickFunctions.Exists(button.id))
            linkButtonClickFunctions.Remove(button.id);
        
        linkButtonClickFunctions.Add(button.id, button.onclick);
        button.onclick = ReturnFalse;
        
        button.disabled = true;
    }
}
function ReturnFalse()
{
    return false;
}