function onClickCriteria(ctrlName, ctrlSource)
{
	var ctrl = document.getElementById(ctrlName);
	if(ctrl.className == 'hidden')
	{
		ctrl.className = 'show';
	}
	else
	{
		ctrl.className = 'hidden';
	}
}

function wButtonOn(ctrl)
{
	if(ctrl.className == 'wcontrol_wbutton')
	{
		ctrl.className = 'wcontrol_wbutton_hover';
	}
}
function wButtonOut(ctrl)
{
	if(ctrl.className == 'wcontrol_wbutton_hover')
	{
		ctrl.className = 'wcontrol_wbutton';
	}
}

function wGridSendAjax(gridid, cmd, param1, param2, pageEvent)
{
    document.getElementById(gridid + '_cmd').value = cmd;
    document.getElementById(gridid + '_param1').value = param1;
    document.getElementById(gridid + '_param2').value = param2;
	var pageAjax = new dibPageAjax();
	pageAjax.addById(gridid + '_cmd');
	pageAjax.addById(gridid + '_param1');
	pageAjax.addById(gridid + '_param2');
	pageAjax.sendRequest(pageEvent, null);
}

function wGridPagesPagesSize(gridid, pageEvent)
{
	var pageSize = document.getElementById(gridid + "_pagesize").value;
	wGridSendAjax(gridid, 'pagessize', pageSize, '', pageEvent);
}

function wGridPagesDirect(gridid, page, pageEvent)
{
	wGridSendAjax(gridid, 'pagesmove', 'direct', page, pageEvent);
}
function wGridFirstPage(gridid, pageEvent)
{
	wGridSendAjax(gridid, 'pagesmove', 'first', '', pageEvent);
}
function wGridPreviousPage(gridid, pageEvent)
{
	wGridSendAjax(gridid, 'pagesmove', 'previous', '', pageEvent);
}
function wGridNextPage(gridid, pageEvent)
{
	wGridSendAjax(gridid, 'pagesmove', 'next', '', pageEvent);
}
function wGridLastPage(gridid, pageEvent)
{
	wGridSendAjax(gridid, 'pagesmove', 'last', '', pageEvent);
}
function wGridHeadOver(head)
{
    head.className = 'wgrid_headOn';
}
function wGridHeadOut(head)
{
    head.className = 'wgrid_head';
}
function wGridItemOver(item)
{
    if(item.className == 'wgrid_item_row1')
    {
        item.className = 'wgrid_item_row1On';
    }
    else
    {
        item.className='wgrid_item_row2On';
    }
}
function wGridItemOut(item)
{
    if(item.className == 'wgrid_item_row1On')
    {
        item.className='wgrid_item_row1';
    }
    else
    {
        item.className='wgrid_item_row2';
    }
}
function wGridHeadClick(gridid, pageEvent, datafield)
{
    var div = document.getElementById(gridid + '_' + datafield);
    var orderby;
    if(div.className == 'wgrid_head_order_neutral')
    {
    	div.className = 'wgrid_head_order_up';
        orderby = 'ASC';
    }
    else
    if(div.className == 'wgrid_head_order_up')
    {
    	div.className = 'wgrid_head_order_down';
        orderby = 'DESC';
    }
    else
    {
    	div.className = 'wgrid_head_order_neutral';
        orderby = '';
    }
    wGridSendAjax(gridid, 'headorder', datafield, orderby, pageEvent);
}
function wGridItemClick(gridid, primarykey, pageEvent, commandName)
{
	if(commandName != "null")
	{
		if(commandName == "")
		{
			commandName = 'itemclick';
		}
		wGridSendAjax(gridid, commandName, primarykey, '', pageEvent);
	}
}
function wGridExportExcel(gridid, pageEvent)
{
	wGridSendAjax(gridid, 'export', 'excel', '', pageEvent);
}

function wListItemOn(itemName)
{
    document.getElementById(itemName).className = 'wlist_itemOn'
}
function wListItemOut(itemName)
{
    document.getElementById(itemName).className = 'wlist_item'
}

function wMenu_Browser() {
	  var ua, s, i;
	  this.isIE    = false;  
	  this.isNS    = false;  
	  this.version = null;

	  ua = navigator.userAgent;

	  s = "MSIE";
	  if ((i = ua.indexOf(s)) >= 0) {
	    this.isIE = true;
	    this.version = parseFloat(ua.substr(i + s.length));
	    return;
	  }

	  s = "Netscape6/";
	  if ((i = ua.indexOf(s)) >= 0) {
	    this.isNS = true;
	    this.version = parseFloat(ua.substr(i + s.length));
	    return;
	  }

	  // Treat any other "Gecko" browser as NS 6.1.

	  s = "Gecko";
	  if ((i = ua.indexOf(s)) >= 0) {
	    this.isNS = true;
	    this.version = 6.1;
	    return;
	  }
	}

	var wMenu_browser = new wMenu_Browser();

	//----------------------------------------------------------------------------
	// Code for handling the menu bar and active button.
	//----------------------------------------------------------------------------

	var wMenu_activeButton = null;

	// Capture mouse clicks on the page so any active button can be
	// deactivated.

	if (wMenu_browser.isIE)
	  document.onmousedown = wMenu_pageMousedown;
	else
	  document.addEventListener("mousedown", wMenu_pageMousedown, true);

	function wMenu_pageMousedown(event) {
	  var el;
	  if (wMenu_activeButton == null)
	    return;

	  if (wMenu_browser.isIE)
	    el = window.event.srcElement;
	  else
	    el = (event.target.tagName ? event.target : event.target.parentNode);

	  if (el == wMenu_activeButton)
	    return;

	  if (wMenu_getContainerWith(el, "DIV", "wMenu_menu") == null) {
	    wMenu_resetButton(wMenu_activeButton);
	    wMenu_activeButton = null;
	  }
	}

	function wMenu_buttonClick(event, menuId) {
	  var button;

	  if (wMenu_browser.isIE)
	    button = window.event.srcElement;
	  else
	    button = event.currentTarget;

	  button.blur();

	  if (button.menu == null) {
	    button.menu = document.getElementById(menuId);
	    wMenu_menuInit(button.menu);
	  }

	  if (wMenu_activeButton != null)
	    wMenu_resetButton(wMenu_activeButton);

	  if (button != wMenu_activeButton) {
	    wMenu_depressButton(button);
	    wMenu_activeButton = button;
	  }
	  else
	    wMenu_activeButton = null;

	  return false;
	}

	function wMenu_buttonMouseover(event, menuId) {
	  var button;

	  if (wMenu_browser.isIE)
	    button = window.event.srcElement;
	  else
	    button = event.currentTarget;

	  if (wMenu_activeButton != null && wMenu_activeButton != button)
	    wMenu_buttonClick(event, menuId);
	}

	function wMenu_depressButton(button) {
	  var x, y;

	  button.className += " wMenu_menuButtonActive";

	  x = wMenu_getPageOffsetLeft(button);
	  y = wMenu_getPageOffsetTop(button) + button.offsetHeight;

	  if (wMenu_browser.isIE) {
	    x += button.offsetParent.clientLeft;
	    y += button.offsetParent.clientTop;
	  }

	  button.menu.style.left = x + "px";
	  button.menu.style.top  = y + "px";
	  button.menu.style.visibility = "visible";
	}

	function wMenu_resetButton(button) {
	  wMenu_removeClassName(button, "wMenu_menuButtonActive");

	  if (button.menu != null) {
	    wMenu_closeSubMenu(button.menu);
	    button.menu.style.visibility = "hidden";
	  }
	}


	function wMenu_menuMouseover(event) {
	  var menu;
	  if (wMenu_browser.isIE)
	    menu = wMenu_getContainerWith(window.event.srcElement, "DIV", "wMenu_menu");
	  else
	    menu = event.currentTarget;

	  if (menu.activeItem != null)
	    wMenu_closeSubMenu(menu);
	}

	function wMenu_menuItemMouseover(event, menuId) {
	  var item, menu, x, y;
	  if (wMenu_browser.isIE)
	    item = wMenu_getContainerWith(window.event.srcElement, "A", "wMenu_menuItem");
	  else
	    item = event.currentTarget;
	  menu = wMenu_getContainerWith(item, "DIV", "wMenu_menu");

	  if (menu.activeItem != null)
	    wMenu_closeSubMenu(menu);
	  menu.activeItem = item;

	  item.className += " wMenu_menuItemHighlight";

	  if (item.subMenu == null) {
	    item.subMenu = document.getElementById(menuId);
	    wMenu_menuInit(item.subMenu);
	  }

	  x = wMenu_getPageOffsetLeft(item) + item.offsetWidth;
	  y = wMenu_getPageOffsetTop(item);

	  var maxX, maxY;

	  if (wMenu_browser.isNS) {
	    maxX = window.scrollX + window.innerWidth;
	    maxY = window.scrollY + window.innerHeight;
	  }
	  if (wMenu_browser.isIE && wMenu_browser.version < 6) {
	    maxX = document.body.scrollLeft + document.body.clientWidth;
	    maxY = document.body.scrollTop  + document.body.clientHeight;
	  }
	  if (wMenu_browser.isIE && wMenu_browser.version >= 6) {
	    maxX = document.documentElement.scrollLeft + document.documentElement.clientWidth;
	    maxY = document.documentElement.scrollTop  + document.documentElement.clientHeight;
	  }
	  maxX -= item.subMenu.offsetWidth;
	  maxY -= item.subMenu.offsetHeight;

	  if (x > maxX)
	    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
	      + (menu.offsetWidth - item.offsetWidth));
	  y = Math.max(0, Math.min(y, maxY));

	  item.subMenu.style.left = x + "px";
	  item.subMenu.style.top  = y + "px";
	  item.subMenu.style.visibility = "visible";

	  if (wMenu_browser.isIE)
	    window.event.cancelBubble = true;
	  else
	    event.stopPropagation();
	}

	function wMenu_closeSubMenu(menu) {
	  if (menu == null || menu.activeItem == null)
	    return;

	  if (menu.activeItem.subMenu != null) {
	    wMenu_closeSubMenu(menu.activeItem.subMenu);
	    menu.activeItem.subMenu.style.visibility = "hidden";
	    menu.activeItem.subMenu = null;
	  }
	  wMenu_removeClassName(menu.activeItem, "wMenu_menuItemHighlight");
	  menu.activeItem = null;
	}

	function wMenu_menuInit(menu) {
	  var itemList, spanList
	  var textEl, arrowEl;
	  var itemWidth;
	  var w, dw;
	  var i, j;

	  if (wMenu_browser.isIE) {
	    menu.style.lineHeight = "2.5ex";
	    spanList = menu.getElementsByTagName("SPAN");
	    for (i = 0; i < spanList.length; i++)
	      if (wMenu_hasClassName(spanList[i], "wMenu_menuItemArrow")) {
	        spanList[i].style.fontFamily = "Webdings";
	        spanList[i].firstChild.nodeValue = "4";
	      }
	  }

	  itemList = menu.getElementsByTagName("A");
	  if (itemList.length > 0)
	    itemWidth = itemList[0].offsetWidth;
	  else
	    return;

	  for (i = 0; i < itemList.length; i++) {
	    spanList = itemList[i].getElementsByTagName("SPAN")
	    textEl  = null
	    arrowEl = null;
	    for (j = 0; j < spanList.length; j++) {
	      if (wMenu_hasClassName(spanList[j], "wMenu_menuItemText"))
	        textEl = spanList[j];
	      if (wMenu_hasClassName(spanList[j], "wMenu_menuItemArrow"))
	        arrowEl = spanList[j];
	    }
	    if (textEl != null && arrowEl != null)
	      textEl.style.paddingRight = (itemWidth 
	        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
	  }

	  if (wMenu_browser.isIE) {
	    w = itemList[0].offsetWidth;
	    itemList[0].style.width = w + "px";
	    dw = itemList[0].offsetWidth - w;
	    w -= dw;
	    itemList[0].style.width = w + "px";
	  }
	}

	function wMenu_getContainerWith(node, tagName, className) {
	  while (node != null) {
	    if (node.tagName != null && node.tagName == tagName &&
	        wMenu_hasClassName(node, className))
	      return node;
	    node = node.parentNode;
	  }

	  return node;
	}

	function wMenu_hasClassName(el, name) {
	  var i, list;
	  list = el.className.split(" ");
	  for (i = 0; i < list.length; i++)
	    if (list[i] == name)
	      return true;

	  return false;
	}

	function wMenu_removeClassName(el, name) {
	  var i, curList, newList;
	  if (el.className == null)
	    return;
	  newList = new Array();
	  curList = el.className.split(" ");
	  for (i = 0; i < curList.length; i++)
	    if (curList[i] != name)
	      newList.push(curList[i]);
	  el.className = newList.join(" ");
	}

	function wMenu_getPageOffsetLeft(el) {
	  var x;
	  x = el.offsetLeft;
	  if (el.offsetParent != null)
	    x += wMenu_getPageOffsetLeft(el.offsetParent);

	  return x;
	}

	function wMenu_getPageOffsetTop(el) {
	  var y;
	  y = el.offsetTop;
	  if (el.offsetParent != null)
	    y += wMenu_getPageOffsetTop(el.offsetParent);

	  return y;
	}

	function wPanelOnOut(wPanelName)
	{
	    var arrow = document.getElementById(wPanelName + "_arrow")
	    var title = document.getElementById(wPanelName + "_title")
	    title.className = 'wpanel_title';
	    if(arrow.className == 'wpanel_03_openOn')
	    {
	        arrow.className = 'wpanel_03_open';
	    }
	    else
	    if(arrow.className == 'wpanel_03_closeOn')
	    {
	        arrow.className = 'wpanel_03_close';
	    }
	}
	function wPanelOnOver(wPanelName)
	{
	    var arrow = document.getElementById(wPanelName + "_arrow")
	    var title = document.getElementById(wPanelName + "_title")
	    title.className = 'wpanel_titleOn';
	    if(arrow.className == 'wpanel_03_open')
	    {
	        arrow.className = 'wpanel_03_openOn';
	    }
	    else
	    if(arrow.className == 'wpanel_03_close')
	    {
	        arrow.className = 'wpanel_03_closeOn';
	    }
	}
	function wPanelOpenClose(wPanelName)
	{
	    var arrow = document.getElementById(wPanelName + "_arrow")
	    var content = document.getElementById(wPanelName + "_content")
	    var title = document.getElementById(wPanelName + "_title")
	    if(arrow.className == 'wpanel_03_open' || arrow.className == 'wpanel_03_openOn')
	    {
	        arrow.className = 'wpanel_03_close';
	        content.style.display = 'none';
	    }
	    else
	    {
	        arrow.className = 'wpanel_03_open';
	        content.style.display = '';
	    }
	    wPanelOnOver(wPanelName);
	}

	function wTreeMergeVisible(idParent, idCnt)
	{
	    var cnt = document.getElementById(idCnt);
	    var parentCtrl = document.getElementById(idParent);
	    if(parentCtrl.className != 'wtree_parent_open')
	    {
	        parentCtrl.className = 'wtree_parent_open';
	        cnt.style.display = '';
	    }
	    else
	    {
	        parentCtrl.className = 'wtree_parent_close';
	        cnt.style.display = 'none';
	    }
	}
	function wTreeOnClickItem(id, idItem, canChange, onlyOneSelected)
	{
	    if(canChange == 1)
	    {
	        var item = document.getElementById(idItem);
	        var idCtrl = document.getElementById(id);
	        if(onlyOneSelected == 0)
	        {
	            idCtrl.value = idCtrl.value.replace("[" + idItem + "]", "");
	        }
	        else
	        {
	            ids = idCtrl.value.split("]");
	            var index;
	            for(index = 0; index < ids.length; index++)
	            {
	                var idUn = ids[index].substring(1, ids[index].length);
	                if(idUn != '')
	                {
	                    var idUnCtrl = document.getElementById(idUn);
	                    idUnCtrl.className = 'wtree_item';
	                }
	            }
	            idCtrl.value = '';
	        }
	        if(item.className == 'wtree_item')
	        {
	            item.className = 'wtree_item_selected';
	            idCtrl.value += '[' + idItem + ']';
	        }
	        else
	        {
	            item.className = 'wtree_item';
	        }
	    }
	}
	
	function wTwoListMoveItem(listID, itemID)
	{
		var select1ctrl = document.getElementById(listID + "_1");
		var select2ctrl = document.getElementById(listID);
		var index;
		for(index = 0; index < select1ctrl.length; index++)
		{
			if(select1ctrl.options[index].value == itemID)
			{
				var newitem = document.createElement('option');
				newitem.text = select1ctrl.options[index].text;
				newitem.value = select1ctrl.options[index].value;
				select1ctrl.remove(index);
				select2ctrl.options.add( newitem, 0 );
				break;
			}
		}
	}
	function wTwoListChgItem(sourceID, destinationID)
	{
		var select1ctrl = document.getElementById(sourceID);
		var select2ctrl = document.getElementById(destinationID);
		
		var index;
		for( index = select1ctrl.length -1; index >= 0; index-- )
		{
			if( select1ctrl.options[index].selected )
			{
				var newitem = document.createElement('option');
				newitem.text = select1ctrl.options[index].text;
				newitem.value = select1ctrl.options[index].value;
				select1ctrl.remove( index );
				select2ctrl.options.add( newitem, 0 );
			}
		}
	}
	function wTwoListSubmit(listID)
	{
		var selectctrl = document.getElementById(listID);
		var index;
		for( index = 0; index < selectctrl.length; index ++ )
		{
			selectctrl.options[index].selected = true;
		}
	}


function lightBoxShow(width, height, src, scrolling)
{
	document.body.style.position = "relative";
	
	if(src != null && src != "" && width > 0 && height > 0)
	{
		if(scrolling == null || scrolling == "")
		{
			scrolling = "yes";
		}
		
		var newCreatedFade = false;
		var lightboxFade = document.getElementById("lightbox_fade");
		if(lightboxFade == null)
		{
			newCreatedFade = true;
			lightboxFade = document.createElement("div");
			lightboxFade.id = lightboxFade.className = "lightbox_fade";
			lightboxFade.onclick = lightBoxHide;
		}
		lightboxFade.style.display = "block";
		if(document.all)
		{
			lightboxFade.style.position = "absolute";
		}
		if(newCreatedFade)
		{
			document.body.appendChild(lightboxFade);
		}

		var newCreatedBox = false;
		var lightbox = document.getElementById("lightbox");
		if(lightbox == null)
		{
			newCreatedBox = true;
			lightbox = document.createElement("div");
			lightbox.id = lightbox.className = "lightbox";
		}		
		lightbox.style.left = parseInt((document.body.clientWidth / 2) - (width / 2)) + "px";
		lightbox.style.top = (window.pageYOffset ? (window.pageYOffset + 100) : (window.document.documentElement.scrollTop + 100)) + "px";
		lightbox.style.width = parseInt(width) + "px";
		lightbox.style.height = parseInt(height) + "px";
		lightbox.style.display = "block";
		
		var lightbox_content = document.getElementById("lightbox_iframe");
		if(lightbox_content != null)
		{
			lightbox_content.src = src;
		}
		else
		{
			lightbox_content = document.createElement("iframe");
			lightbox_content.id = lightbox_content.name = "lightbox_iframe";
			lightbox_content.width = lightbox_content.height = "100%";
			lightbox_content.frameBorder = "0";
			lightbox_content.src = src;
			lightbox_content.scrolling = scrolling;
			lightbox.appendChild(lightbox_content);
		}
		if(newCreatedBox)
		{
			document.body.appendChild(lightbox);
		}
	}
}
function lightBoxHide()
{
	var lightboxFade = document.getElementById("lightbox_fade");
	if(lightboxFade != null)
	{
		lightboxFade.style.display = "none";
	}
	
	var lightbox = document.getElementById("lightbox");
	if(lightbox != null)
	{
		lightbox.style.display = "none";
	}
	
	var lightbox_content = document.getElementById("lightbox_iframe");
	if(lightbox_content != null)
	{
		lightbox_content.src = "";
	}
}
