var childHandle;
var dateHandle;
var timeHandle;
var textHandle;

function paivitapuu(str){
	if (parent.Group){
		if(str)
			parent.Group.location = str;
		else
			parent.Group.location=parent.Group.location;
	}
}

function paivitapuu_fast(e){
	if(!e) e = false;
	if (parent.Group){
		var o = parent.Group.document.getElementById("deeptree");
		o.SyncExpandLast(e);
		o.SyncContentXML();
	}
}

function openWindow(url, nimi, width, height) {
    var handle = window.open(url, nimi, "width="+width+",height="+height+",resizable=no,toolbar=no,status=no,location=no,titlebar=no,scrollbars=no");
    if (!handle.opener) handle.opener = self;
    childHandle = handle;
    return handle;
}

function openWindow2(url, nimi, width, height) {
    var handle = window.open(url, nimi, "width="+width+",height="+height+",resizable=no,toolbar=no,status=no,location=no,titlebar=no,scrollbars=yes");
    if (!handle.opener) handle.opener = self;
    childHandle = handle;
    return handle;
}

function openWindow3(url, nimi, width, height) {
    var handle = window.open(url, nimi, "width="+width+",height="+height+",resizable=yes,toolbar=no,status=yes,location=no,titlebar=no,scrollbars=yes");
	handle.focus();
	childHandle = handle;
	return false;
}
function openWindow4(url, nimi, width, height) {
    var handle = window.open(url, nimi, "width="+width+",height="+height+",resizable=yes,toolbar=no,status=no,location=no,titlebar=no,scrollbars=yes");
	handle.focus();
	childHandle = handle;
	return false;
}

function openWindow5(url, nimi, width, height) {
    var handle = window.open(url, nimi, "width="+width+",height="+height+",resizable=no,toolbar=no,status=no,location=no,titlebar=no,scrollbars=no");
	handle.focus();
	childHandle = handle;
	return false;
}


function openForm(url, nimi) {
	var handle = openWindow(url, nimi, 750, 450);
	handle.focus();
	childHandle = handle;
	return false;
}

function openLargeForm(url, nimi) {
	var handle = openWindow(url, nimi, 750, 600);
	handle.focus();
	childHandle = handle;
	return false;
}

function openWideForm2 (url, nimi) {
	var handle = window.showModalDialog (url,window,"dialogWidth:840px;dialogHeight:450px;scroll:0;help:0;status:0;");
	return false;
}

function openTextEditor(id) {
	var handle = openWindow("texteditor_frameset.html", "texteditor", 750, 450);
	handle.focus();
	textHandle = id;
	return false;
}

function openSmallForm(url, nimi) {
	var handle = openWindow(url, nimi, 400, 300);
	handle.focus();
	childHandle = handle;
	return false;
}

function openSmallForm2(url, nimi) {
	var handle = openWindow2(url, nimi, 400, 300);
	handle.focus();
	childHandle = handle;
	return false;
}

function openAverigeForm(url, nimi) {
	var handle = openWindow(url, nimi, 500, 375);
	handle.focus();
	childHandle = handle;
	return false;
}

function openNarrowForm(url, nimi) {
	var handle = openWindow(url, nimi, 300, 450);
	handle.focus();
	childHandle = handle;
	return false;
}

function openDatePicker(pvmFieldId, timeFieldId, d, disbefday, disaftday) {
	dateHandle = pvmFieldId;
	timeHandle = timeFieldId;
	var handle = openWindow("paivavalikko.aspx?paiva=" + d + "&amp;disbefday=" + disbefday + "&amp;disaftday=" + disaftday, "paivavalikko", 230, 220);
	handle.focus();
	childHandle = handle;
	return false;
}

function setDateField(newValue) {
	var dateForm = document.getElementById(dateHandle);
	var timeForm = document.getElementById(timeHandle);
	if (!dateForm) return;
	dateForm.value = newValue;
	if (!timeForm) return;
	timeForm.value = "";
}

function openHelp(url) {
    var handle = window.open(url, "popup", "width=500,height=450,resizable=yes,toolbar=no,scrollbars=yes,status=no,location=no,titlebar=no");
    if (!handle.opener) handle.opener = self;
    handle.focus();
	return false;
}

function closeChildWindows() {
	if (childHandle != null) childHandle.close();
}

function reloadParentAndClose(){
	var o = opener;
	try {
		opener.location.href = opener.location.href;
	}
	catch (ex) {}
	self.close();
}

// Animated screens
function setUp(id) {
	var obj = document.getElementById(id);
	obj.style.width = obj.getAttribute("minwidth");
	obj.style.height = obj.getAttribute("minheight");
	animateOpen(id);
}

function animateOpen(id) {
	var obj = document.getElementById(id);
	if (obj.getAttribute("cancel") == "1") return;
	var currentWidth = parseInt(obj.style.width);
	var currentHeight = parseInt(obj.style.height);
	var maxWidth = parseInt(obj.getAttribute("maxwidth"));
	var maxHeight = parseInt(obj.getAttribute("maxheight"));
	if (currentWidth < maxWidth || currentHeight < maxHeight) {
		var widthDiff = (maxWidth-currentWidth)/6;
		var heightDiff = (maxHeight-currentHeight)/6;
		if (widthDiff > 1 || heightDiff > 1) {
			if (widthDiff > 1) obj.style.width = currentWidth + widthDiff;
			if (heightDiff > 1) obj.style.height = currentHeight + heightDiff;
			setTimeout("animateOpen('" + id + "')", 20);}
		else {
			obj.style.width = maxWidth;
			obj.style.height = maxHeight;
			setTimeout("quickClose('" + id + "')", 5000);}
	}
	else {
		setTimeout("quickClose('" + id + "')", 5000);
	}
}

function quickClose(id) {
	var obj = document.getElementById(id); // Viitataan boxiin
	if (obj.getAttribute("cancel") == "1") return;
	obj.style.width = obj.getAttribute("minwidth");
	obj.style.height = obj.getAttribute("minheight");
}

function quickOpen(id) {
	var obj = document.getElementById(id); // Viitataan boxiin
	obj.style.width = obj.getAttribute("maxwidth");
	obj.style.height = obj.getAttribute("maxheight");
	obj.cancel = "1";
}

function quickToggle(id) {
	var obj = document.getElementById(id); // Viitataan boxiin
	if (parseInt(obj.style.width) == parseInt(obj.getAttribute("maxwidth")) && parseInt(obj.style.height) == parseInt(obj.getAttribute("maxheight"))) {
		obj.style.width = obj.getAttribute("minwidth");
		obj.style.height = obj.getAttribute("minheight");
	}
	else {
		obj.style.width = obj.getAttribute("maxwidth");
		obj.style.height = obj.getAttribute("maxheight");
	}
	obj.cancel = "1";
}