﻿function TBL_OnButtonClick(oButton, sOnValueSelectScript,sOnClientBeforeClick, iPopupHeight, iPopupWidth) {
	var oTR = null;
	var oTextBox = null;
	var vRetVal = "";
	var oTagTextBox = null;
	var sValue = "";
	var sURLToOpen = "";

	// do somthing before click
	if (sOnClientBeforeClick.length != 0){
		if (!eval(sOnClientBeforeClick))
			return false;
	}	
	
	// set url location
	oTR = oButton.parentElement.parentElement
	oTextBox = oTR.cells[0].children[0]
	
	sURLToOpen = oTextBox.URLToOpen;

	oTagTextBox = TBL_GetHiddenTextBox(oTextBox)
	if (oTagTextBox)
		sValue = oTagTextBox.value
	
	if ((!sURLToOpen) || (sURLToOpen.length == 0))
		return false
		
	if (sURLToOpen.indexOf("?") == -1)
		sURLToOpen = sURLToOpen + "?"
	else
		sURLToOpen = sURLToOpen + "&"

	sURLToOpen = sURLToOpen + "Value=" + sValue + 
					"&Description=" + oTextBox.value;
	//-------------------------------------
	
	vRetVal = JG_OpenModalWindow(sURLToOpen, iPopupHeight, iPopupWidth)
	if (vRetVal) {
		if (vRetVal[0]) {
			if (vRetVal[1] || vRetVal[1] == 0) 
				oTextBox.value = vRetVal[1];
				if (oTagTextBox)
					oTagTextBox.value = vRetVal[0];
			else 
			{
				oTextBox.value = vRetVal[0];
			}
		}
		else 
		{
			oTextBox.value = vRetVal;
		}

		if (sOnValueSelectScript.length > 0) {
			eval(sOnValueSelectScript);
		}
		return true;
	}
	return false;
}

function TBL_GetHiddenTextBox(oLookupTextBox) {
	return document.all["__" + oLookupTextBox.name + "_TXT_LOOKUP_FIELD"];
}

function TBL_SetDisabled(oLookupTextBox, bDisabled) {
	oLookupTextBox.parentElement.parentElement.cells[1].children.item(0).disabled = bDisabled;
}
