function openWin(URL,name,args) {
	var win = window.open(URL,name,args);
	win.focus();
}

function checkZero(val)
{
	if(val<10){
		return "0" + val;
	}
	else{
		return "" + val;
	}
}


function hideErrorBox(){
//closes the Error/InfoBox 
errorBox = document.getElementById("InfoErrorBox");
errorBox.style.display="none";
}

function openWinEx(URL,ext,args) {
	var Now = new Date();
	var unique = "" + Now.getYear() + checkZero(Now.getMonth()+1) + checkZero(Now.getDate());
	unique = unique + checkZero(Now.getHours()) + checkZero(Now.getMinutes()) + checkZero(Now.getSeconds());
	openWin(URL + unique + ext, unique, args);
}

var firstCheckBox = null;
var part1 = '';
var part2 = '';

function SetCheckboxesRecursive(obj, state) {
	if (obj.nodeName == 'INPUT'
	 && obj.type == 'checkbox') {
		obj.checked = state;
	}
	if (obj.hasChildNodes()) {
		var childs = obj.childNodes;
		for (var i = 0; i < childs.length; i++) {
			SetCheckboxesRecursive(childs[i], state);
		}
	}
}

function SelectAllCheckBoxes(sender, parentNodeName) {
	if (sender.nodeName != 'INPUT'
	 && sender.type != 'checkbox') {
		return;
	}
	var state = sender.checked;
	var node = sender.parentNode;
	while (node.nodeName != parentNodeName) {
		node = node.parentNode;
	}
	SetCheckboxesRecursive(node, state);
	firstCheckBox = null;
}

function SetCheckBoxes(sender, partialName) {
	if (sender.nodeName != 'INPUT'
	 && sender.type != 'checkbox'
	 && sender.name.indexOf(partialName) > -1) {
		return;
	}
	if (firstCheckBox == null) {
		firstCheckBox = sender;
		return;
	}
	if (firstCheckBox == null
	 || firstCheckBox.checked != sender.checked) {
		return;
	}
	var state = sender.checked;
	part1 = 'a';
	part2 = 'b';
	var firstCounter = GetCounterFromName(firstCheckBox.id);
	var secondCounter = GetCounterFromName(sender.id);
	var from = 0;
	var to = 0;
	if (firstCounter < secondCounter) {
		from = firstCounter + 1;
		to = secondCounter;
	} else {
		from = secondCounter + 1;
		to = firstCounter;
	}
	for (i = from; i < to; i++) {
		var box = document.getElementById(part1 + i + part2);
		if (box.nodeName == 'INPUT'
		&& box.type == 'checkbox') {
			box.checked = state;
		}
	}
}

function GetCounterFromName(id, partialName) {
	var counter = -1;
	var pos1 = id.lastIndexOf('_ctl');
	if (pos1 == -1) {
		return counter;
	} else {
		pos1 += 4;
	}
	var pos2 = id.indexOf('_', pos1);
	if (pos2 == -1) {
		return counter;
	}
	var ctl = id.substring(pos1, pos2);
	part1 = id.substring(0, pos1);
	part2 = id.substring(pos2);
	return parseInt(ctl);
}


function SelectAllCheckboxesOld(partialName, sender) {
	var firstCheckBox = document.getElementById(firstCheckBoxName);
	var lastCheckBox = document.getElementById(lastCheckBoxName);
	if (!firstCheckBox && firstCheckBox.nodeName != 'INPUT' && firstCheckBox.type != 'checkbox') {
		return;
	}
	if (!lastCheckBox && lastCheckBox.nodeName != 'INPUT' && lastCheckBox.type != 'checkbox') {
		return;
	}
	if (firstCheckBox.checked == lastCheckBox.checked) {
		var state = firstCheckBox.checked;
		var inputs = document.getElementsByTagName('input');
		for	(var i = 0;	i	< inputs.length; i++) {
			if (inputs[i].getAttribute('type') == 'checkbox'
			&& inputs[i].name.indexOf(partialName) > -1) {
				inputs[i].checked = state;
			}
		}
	}
}

function PanelBarMouseHover(pObj) {
	if (pObj == null)
		return;
	pObj.style.cursor = "pointer";
	pObj.style.fontWeight = "bold";
}

function PanelBarMouseOut(pObj) {
	if (pObj == null)
		return;
	pObj.style.cursor = "default";
	pObj.style.fontWeight = "normal";
}

function PanelBarHeaderClick(pObj, pCtObj) {
	var pCt = document.getElementById(pCtObj);
	if (pCt == null)
		return;
	var status = pCt.style.display;
	var img = pObj.firstChild;
	if (status == '' || status == 'none') {
		status = 'block';
		if (img != null && img.nodeName == 'IMG') {
			img.src = "img/Collapse.gif";
		}
	} else {
		status = 'none';
		if (img != null && img.nodeName == 'IMG') {
			img.src = "img/Expand.gif";	
		}
	}
	pCt.style.display = status;
}

