﻿// JScript File
function CaptureEvents(obj)
{
    tbody = obj.getElementsByTagName('tbody')[0];
    if(tbody.isAssigned != true)
    for (i = 0; i < tbody.getElementsByTagName('tr').length; i++)
	{
	    tbody.isAssigned = true;
	    node = tbody.getElementsByTagName('tr')[i];
	    if (node.className != 'tablesmall')
	        continue;
		
		if (node.nodeName == "TR")
		{
			node.onmouseover=CaptureMouseOver;
			
			node.onclick=CaptureClick;
			
			node.ondblclick=CaptureDbClick;
				
			node.onmouseout=CaptureMouseOut;
			
			node.cells[0].onclick = function()
			{
			    window.globalTDCheckboxClicked = true;
			}
			
		}
	}
}

function CaptureClick(obj)
{
    if (this.cells[0].childNodes[0].type == 'checkbox' && window.globalTDCheckboxClicked != true)
    {
        this.cells[0].childNodes[0].checked = !this.cells[0].childNodes[0].checked;
    }
    else window.globalTDCheckboxClicked = false; 
}

function CaptureDbClick(obj)
{
    var btnImg = this.cells[this.cells.length-1].getElementsByTagName('input')[0];
    if(btnImg.type == 'image' && btnImg.name.indexOf('btnEdit') > 0)
        __doPostBack(btnImg.name, '');
}

function CaptureMouseOut(obj)
{
    this.className = this.className.replace(" trOver", "");
}

function CaptureMouseOver(obj)
{
    this.className += " trOver";
}

//transfer items between listboxes
function Transfer( sourceID, destinationID, hidden, isAdd, delim){
	var sourceList = document.getElementById(sourceID);
	var destinationList = document.getElementById(destinationID);
	var hiddenField = document.getElementById(hidden);

	var itemsForTransfer = new Array();

	var i;
	for(i = 0; i < sourceList.options.length; i++){
		var option = sourceList.options[i];
		if(option.selected){
			itemsForTransfer[itemsForTransfer.length] = new Option(option.text, option.value);
		}
	}
	for(i = 0; i < sourceList.options.length; i++){
		var option = sourceList.options[i];
		if(option.selected){
			sourceList.options[i] = null;
			i--;
		}
	}

	for(i = 0; i < itemsForTransfer.length; i++){
		var option = itemsForTransfer[i];
		destinationList.options[destinationList.options.length] = option;
	}
	
	hiddenField.value = '';
	if (isAdd > 0) {
	    for (i = 0; i < destinationList.options.length; i++) {
	        var option = destinationList.options[i];
	        if (i > 0)
	            hiddenField.value = hiddenField.value + delim;
	        hiddenField.value = hiddenField.value + option.value;
	    }
	}
	else {
	    for (i = 0; i < sourceList.options.length; i++) {
	        var option = sourceList.options[i];
	        if (i > 0)
	            hiddenField.value = hiddenField.value + delim;
	        hiddenField.value = hiddenField.value + option.value;
	    }
	}
}


function selectTab(sender){
    var tabsElement = $('Tabs');
    var childElement;
    
    //clear styles for exisiting tabs
    for (var i = 0; i < tabsElement.childNodes.length; i++){
        childElement = tabsElement.childNodes[i];
        if (childElement.id) {childElement.className = "";}
    }
    sender.className = "selected";
}

// When enter is pressed, check if the component should have an event fired (images, buttons and links). All other events
// are not handled because they make the page refresh into the English version.        
function checkClicked(clickedId)
{
    var links = document.getElementsByTagName('a');
    var buttons = document.getElementsByTagName('input');
  
    if(clickedId != '')
    {
        for(var j = 0; j < buttons.length; j++)
        {
            if(buttons[j].id == clickedId && (buttons[j].type == 'image' || buttons[j].type == 'button' || buttons[j].type == 'submit'))
            {
                return true;
            }
        }          
      
        for(var j = 0; j < links.length; j++)
        {
            if(links[j].id == clickedId)
            {
              return true;
            }
        }
    }
  
    return false;
}
