/* must include lightwindow.js before including this one */

// show the browse window
function lw_browse(url, title, w, h) {
	if (typeof(myLightWindow) == "undefined") {
		myLightWindow = new lightwindow();
	}
	
	myLightWindow.activateWindow({
		href: url, 
		title: title,
		type: 'external',
		width: w,
		height: h
	});
}

// close the browse window
function lw_deactivate_browse() {
	myLightWindow.deactivate();
}

// select
// arguments[4] = extra function specified in parent to be run.
//				it accepts string argument
function lw_select(parentFormName, showTextID, showText, parameters) {
	// set the form hidden values
	if (parentFormName != "") {
		var parent_obj = eval("parent.document." + parentFormName);
		
		if ((parent_obj != null) && (parameters != null)) {
			for (var param_prop in parameters) {
				try {
					eval("parent_obj." + param_prop + ".value = parameters." + param_prop);
				} catch (err) {
				}
			}
		}
	}
	
	// set the text
	var show_text_obj = parent.document.getElementById(showTextID);
	
	if (show_text_obj != null) {
		//alert("show_text_obj type: " + show_text_obj.type + "\ntypeof show_text_obj: " + typeof show_text_obj)
		if (show_text_obj.type == "text") {
			show_text_obj.value = showText;
		} else {
			show_text_obj.innerHTML = showText;
		}
	}

	// run callback function
	if (arguments[4]) {
		var eval_str = "";
		
		try {
			// make the text js safe string
			showText = showText.replace(/(\'|\"|\\)/ig,"\\$1");
			
			//eval("parent." + arguments[4] + "('" + showText + "')");
			eval_str = "parent." + arguments[4] + "('" + showText + "')";
			eval(eval_str);
		} catch (err) {
			alert("error:" +
						"\nmessage: " + err.message +
						"\narguments[4]: " + arguments[4] +
						"\neval: eval(\"" + eval_str + "\")");
		}
		/*
		var action_div = parent.document.getElementById("divAction");
		if (action_div) {
			action_div.style.display = "inline";
		}
		*/
	}

	// close the browse window
	parent.lw_deactivate_browse()
}
