// JScript File
function WinOpen(url, name, height, width) {
	var options = 'status=yes,resizable=yes,toolbar=no,location=no,menubar=no,scrollbars=yes' 
	    + ',top=' + Math.floor((screen.height - height) / 2)
	    + ',left=' + Math.floor((screen.width - width) / 2) 
	    + ',height=' + height
	    + ',width=' + width;
	var newwindow = window.open(url, name, options);
	if(window.focus) 
	    newwindow.focus();
	return newwindow;
}

function maximize() {
    window.resizeTo(screen.availWidth, screen.availHeight);
    window.moveTo(0, 0);
}

var sideBySideWindow = null;

function openWindowSideBySide(url, name, widthPercent, toRight) {
    var screenWidth = screen.availWidth;
    var newWindowWidth = parseInt('' + (screenWidth * widthPercent / 100));
    var newWindowHeight = screen.availHeight;
    var callingWindowWidth = screenWidth - newWindowWidth;
    
    // resize and reposition calling window
    window.resizeTo(callingWindowWidth, newWindowHeight);
    if(toRight)
        window.moveTo(0, 0);
    else
        window.moveTo(newWindowWidth, 0);
    window.focus();
    
    // open new window 
    sideBySideWindow = window.open(url, name, 'resizable=yes,scrollbars=yes,menubar=no,toolbar=no,location=no,status=yes');
    sideBySideWindow.resizeTo(newWindowWidth, newWindowHeight);
	if(toRight)
	    sideBySideWindow.moveTo(callingWindowWidth, 0);
	else
	    sideBySideWindow.moveTo(0, 0);
	sideBySideWindow.focus();
	
	return false;
}

function dockWindowSideBySide(widthPercent, toRight) {
    var screenWidth = screen.availWidth;
    var newWindowWidth = parseInt('' + (screenWidth * widthPercent / 100));
    var newWindowHeight = screen.availHeight;
    var openerWindowWidth = screenWidth - newWindowWidth;
    
    // resize and reposition opener window
    opener.resizeTo(openerWindowWidth, newWindowHeight);
    if(toRight)
        opener.moveTo(0, 0);
    else
        opener.moveTo(newWindowWidth, 0);
    opener.focus();
    
    // dock
    window.resizeTo(newWindowWidth, newWindowHeight);
	if(toRight)
	    window.moveTo(openerWindowWidth, 0);
	else
	    window.moveTo(0, 0);
	window.focus();
	
	return false;
}

function Toggle(img, cellId) {
    var ctrlGroup = document.getElementById(cellId);
    if(ctrlGroup.style.display == "none") {
		ctrlGroup.style.display = "block";
		img.src = "../images/arrow_up.gif";
	}
	else {
		ctrlGroup.style.display = "none";
		img.src = "../images/arrow_down.gif";
	}
    return false;
}

function GetSelectedIds(rootId) {
	var selected = '';
	var root = $(rootId);
	if(root != null) {
		var inputs = root.getElementsByTagName('input');
		for(var i = 0; i < inputs.length; i++)
			if(inputs[i].type == 'checkbox')
				if(inputs[i].checked)
					selected = selected.concat(inputs[i].name);
	}
	return selected;
}

function SelectRow(root) {
	if(root == null) return;
	var _class = (root.checked ? 'sel' : '');
	var _parent = root.parentNode;
	while(_parent != null) {
		if(_parent.nodeName == 'TR') {
			_parent.className = _class;
			break;
		}
		_parent = _parent.parentNode;
	}
}


//Allow only delete, and tab keys go through.
function Suppress(control) {
        	
	        if (event.keyCode != 9 && event.keyCode != 46) 
		        event.returnValue = false;
        	
	        if (event.keyCode == 46)
		        control.value = "";
        	
	        //window.status = event.keyCode;
}

function CollapsiblePanel(id, targetDivId, targetImgId, maxHeight, expandedImage, collapsedImage)
{
		this.id = id;
		this.targetDivId = targetDivId;
		this.targetImgId = targetImgId;
		this.togglePanel = TogglePanel;
		this.expandedImage = expandedImage;
		this.collapsedImage = collapsedImage;
		this.height = parseInt(document.getElementById(this.targetDivId).style.height);
		this.maxHeight = maxHeight;
		this.expanded = (this.height >= this.maxHeight);
}

var velocityX = 0;
var velocityY = 15;
var cycles = 5; //in milliseconds

function TogglePanel()
{
	if (this.expanded == false)
	{
		document.getElementById(this.targetImgId).src = this.expandedImage;
		document.getElementById(this.targetDivId).style.display = "block"
		
		if (this.height < this.maxHeight){
			this.height += velocityY; 
			window.setTimeout(this.id + ".togglePanel()", cycles);
		}
		else if (this.height >= this.maxHeight) 
				this.expanded = true; 
	}
	else 
	{
		document.getElementById(this.targetImgId).src = this.collapsedImage;
		
		if (this.height > 5) {
			this.height -= velocityY;
			window.setTimeout(this.id + ".togglePanel()", cycles);
		}
		else if (this.height <= 5) {
			this.expanded = false;
			document.getElementById(this.targetDivId).style.display = "none";
		}
		
	}
	
	document.getElementById(this.targetDivId).style.height = this.height + "px";
}


