
function wnd_open(url, width, height, properties) {
	var dialogWin = new Object();
	var attr = '' + properties;
	dialogWin.width = width;
    dialogWin.height = height;
    dialogWin.name = "";
    // generate name from url
    for(j=0; j<url.length; j++)
		if(url.charAt(j) > 'A' && url.charAt(j) < 'z')
			dialogWin.name = dialogWin.name + url.charAt(j);
	


    // Assemble window attributes and try to center the dialog.
    // The best we can do is center in screen.
	dialogWin.left = (screen.width - dialogWin.width) / 2;
	dialogWin.top = (screen.height - dialogWin.height) / 2;
	attr = "left=" + dialogWin.left + ",top=" + dialogWin.top + ",width=" + dialogWin.width + ",height=" + dialogWin.height;
    attr = attr + ", menubar=no, resizable=yes, status=yes, scrollbars=yes";

    //if(navigator.appCodeName.equals("Mozilla"))
	//    attr = attr + ", alwaysRaised=yes, dependent=yes";
   
	newWindow = window.open(url, dialogWin.name, attr);
	newWindow.opener = self;
	newWindow.focus();
	return newWindow;
}

function wnd_openIfBrowse(url, width, height, properties) {
	// get select component
	var cmt = "component=";
	var compStart = url.indexOf(cmt) + cmt.length;
	var compEnd = url.indexOf("&", compStart);
	if(compEnd == -1) compEnd = url.length;
	var component = url.substring(compStart, compEnd);
	
	// if selected is "(broswe" open window and set select to first
	if(eval(component + ".options[" + component + ".selectedIndex].value") == "(browse)") {
		wnd_open(url, width, height, properties);
		eval(component + ".selectedIndex = 0");
	}
	
}


//// Select Component Functions //////////////////

function deleteAllOptions(component) {
	component = "document." + component;
	for (j=eval(component + ".length") - 1; j>=0; j--) {
    		eval(component + ".options[0] = null");
    }
}

function addOption(component, label, id) {
	component = "document." + component;
	eval(component + ".options[" + component + ".length] = new Option('" + label + "', '" + id + "')");
}

function setSelectValue(component, value) {
	component = "document." + component;
	for (i=0; i<eval(component + ".length"); i++) {
		if (eval(component + ".options[i].value") == value) 
			eval(component + ".selectedIndex = " + i);
		
	}
}


function setSelectText(component, text) {
	component = "document." + component;
	for (i=0; i<eval(component + ".length"); i++) {
		if (eval(component + ".options[i].text") == text) 
			eval(component + ".selectedIndex = " + i);
		
	}
	
}
function setSelectText(component, text) {
	setSelectText(component, text);
}

function setSelectSimple(component, label, value) {
	deleteAllOptions(component);
	addOption(component, "None", "0");
	addOption(component, label, value);
	addOption(component, "[browse]", "(browse)");
	setSelectValue(component, value);

	
}

function getSelectValue(component) {
	component = "document." + component;
	return eval(component + ".options[" + component + ".selectedIndex].value");
}

function setInputValue(component, value) {
	component = "document." + component;
	return eval(component + ".value = '" + value + "'");
	
}




///
/// With curr
///


function wnd_openCurr(currElement, url, width, height, properties) 
{
	//alert(currElement.innerHTML);
	var prevElem = currElement.previousSibling.previousSibling;
	
	
	//alert(prevElem.name);
	if(prevElem == null) {
		alert("No previos element");
		return;
	}
	
	// hide old __current
	component = document.getElementById("__current");
	if(component != null)
		component.id = "__oldcurrent";
	
	prevElem.id = "__current";
	
	return wnd_open(url, width, height, properties);
}

function setSelectValueCurr(value) {
	component = document.getElementById("__current");
		
	for (i=0; i<component.length; i++) {
		if (component.options[i].value == value) 
			component.selectedIndex  = i;
		
	}
}

function getSelectValueCurr() {
	component = document.getElementById("__current");
	return component.options[component.selectedIndex].value
}

function deleteAllOptionsCurr() {
	component = document.getElementById("__current");
	for (j=component.length - 1; j>=0; j--) 
    		component.options[0] = null;
}

function addOptionCurr(label, id) {
	component = document.getElementById("__current");
	component.options[component.length] = new Option(label, id);
}


