function winUp(url, w, h) {
    var name = 'IMG';
    var top  = Math.ceil((screen.height-h)/2);
    var left = Math.ceil((screen.width-w)/2);
    var features = "width="+w+",height="+h+",top="+top+",left="+left+",location=no,status=no,resizable=no,toolbar=no,menubar=no,scrollbars=yes";
    window.open(url, name, features);
}

function eskeip(str) {
    var res = escape(str);
    res = res.replace('+', '%2B');
    res = res.replace('/', '%2F');
    return res;
}

function showhide(did) {
    if (!document.getElementById(did)) return;
    if (document.getElementById(did).style.display == 'none') {
        document.getElementById(did).style.display = '';
    } else {
        document.getElementById(did).style.display = 'none';
    }
}

function getposOffset(element, type) {
    var totaloffset = type == "left" ? element.offsetLeft : element.offsetTop;
    var parent = element.offsetParent;
    while (parent != null) {
        totaloffset = type == "left" ? totaloffset + parent.offsetLeft : totaloffset + parent.offsetTop;
        parent = parent.offsetParent;
    }
    return totaloffset;
}
/*
appstat
0 = now shown
1 = appearing
2 = shown
3 = disappearing
*/

var menuOpened = 0;

function preshowelement(id, e) {
	if (!menuOpened) {
		return;
	} else {
		return showelement(id);
	}
	if (!e)
		relTarg = window.event.fromElement;
	else
		relTarg = e.relatedTarget;
	//if (relTarg.parentNode.className != 'cats-catnames')
	//	return;
		//alert('Show: '+relTarg.parentNode.className);
	//return setTimeout("preshowelement2('"+id+"');", 100);
	//return;
}

function prehideelement(id, e) {
	if (!e)
		relTarg = window.event.toElement;
	else
		relTarg = e.relatedTarget;
		//alert('Hide: '+relTarg.parentNode.className);
	//if (relTarg.parentNode.className == 'submenu')
	//	return;
	return hideelement(id);
}

function showelement(id) {
	menuOpened = 1;
	if (document.getElementById("submenu" + id).appstat == 1)
		return;
	// menu
    document.getElementById("menu" + id).className = "menu-selected";
    // submenu - positioning
    document.getElementById("submenu" + id).style.left = getposOffset(document.getElementById("menu" + id), "left") + "px";
    document.getElementById("submenu" + id).style.top = getposOffset(document.getElementById("menu" + id), "top") + 24 + "px";
    // display
    document.getElementById("submenu" + id).style.display = "block";
    if (document.getElementById("submenu" + id).offsetHeight > 307) {
    	document.getElementById("submenu" + id).style.height = '300px';
    	document.getElementById("submenu" + id).style.maxHeight = '300px';
    }
    // increase opacity
    document.getElementById("submenu" + id).appstat = 1;
    showElTime(id);
    //alert(parseInt(document.getElementById("submenu" + id).style.filter));
}

function hideelement(id) {
	if (document.getElementById("submenu" + id).appstat == 3)
		return;
	// menu
    document.getElementById("menu" + id).className = "menu";
    // decrease opacity
    document.getElementById("submenu" + id).appstat = 3;
    hideElTime(id);
}

function showElTime(id) {
    transp = parseFloat(document.getElementById("submenu" + id).style.opacity) * 10;
    if (document.getElementById("submenu" + id).appstat == 1 && transp < 10) {
    	transp++;
    	document.getElementById("submenu" + id).style.opacity = transp / 10;
    	document.getElementById("submenu" + id).style.filter = 'alpha(opacity=' + transp*10 + ')';
		// increase opacity, end
		if (transp == 10) {
			document.getElementById("submenu" + id).appstat = 2;
    		menuOpened = 1;
		} else setTimeout("showElTime('"+id+"')", 10);
    }
}

function hideElTime(id) {
    transp = parseFloat(document.getElementById("submenu" + id).style.opacity) * 10;
    if (document.getElementById("submenu" + id).appstat == 3 && transp > 0) {
    	transp--;
    	document.getElementById("submenu" + id).style.opacity = transp / 10;
    	document.getElementById("submenu" + id).style.filter = 'alpha(opacity=' + transp*10 + ')';
		// decrease opacity, end
		if (transp == 0) {
			document.getElementById("submenu" + id).style.display = "";
			document.getElementById("submenu" + id).appstat = 0;
			menuOpened = 0;
		}
		else setTimeout("hideElTime('"+id+"')", 10);
    }
}

function processForm() {
	if (typeof el_show == 'undefined' || !document.getElementById('subheading')) {
		return
	}
	formelements = document.getElementById('slud-form').elements;
	podr = document.getElementById('subheading');
	subheading = podr.options[podr.selectedIndex].value;
	for (a = 0; a < formelements.length; a++) {
		// show/hide
		el = formelements[a];
		if (typeof el_show[el.id] != 'undefined') {
			el.parentNode.style.display = 'none';
			for (var i in el_show[el.id]) {
				if (el_show[el.id][i] == subheading) {
					el.parentNode.style.display = 'block';
					break;
				}
			}
		}
		// highlight
		if (typeof el_mand[el.id] != 'undefined') {
			el.parentNode.firstChild.firstChild.className = 'non-mandatory';
			for (var i in el_mand[el.id]) {
				if (el_mand[el.id][i] == subheading) {
					el.parentNode.firstChild.firstChild.className = 'mandatory';
					break;
				}
			}
		}
	}
}