var functionPending = "";
var passValue = "";
var passValue1 = "";
currentField = null;
function windowOnLoad() 
{
	document.getElementById("loading").style.visibility = "hidden";
	document.getElementById("tranDiv").style.opacity = "1";
	document.getElementById("tranDiv").style.disabled = "false";
	document.getElementById("otherHelpDiv").style.visibility = "hidden";
	document.getElementById("fieldSuggestionDiv").innerHTML = "<iframe src=\"\" class=\"fieldSuggFrame\" id=\"fieldSuggFrame\" name=\"fieldSuggFrame\" ></iframe>";
	var element1 = document.createElement("input");
	element1.type = "hidden";
	element1.name = "EVENT_CODE";
	element1.setAttribute("id", "KEY_EVENT_CODE");
	element1.value = "";
	document.getElementById("tranDiv").appendChild(element1);
	onBlurFunction(document.getElementById("")); // add detail are set
	addAndRemoveDetail("detailTable", "X", document.getElementById(""));
	addAndRemoveDetail("detail3Table", "X", document.getElementById(""));

}
function windowOnClick(str) // Close the popup when click on other location in
{
	closePopWindow(str)
}

document.onkeydown = keyCheck; // key event when any key pressed
function keyCheck(e) // check key when any key pressed on window page
{
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	switch (KeyID)
	{
	case 121:
		saveData(document.getElementById(""));
		return false;
		break;

	}
	return true;
}
function onKeyDownFun(field, e) // Key events for input on fields
{

	var tableName = "";
	if (field.name.indexOf("Detail3") != -1)
	{
		tableName = "detail3Table";
	} else
	{
		tableName = "detailTable";

	}
	table = document.getElementById(tableName);
	var tableLength = table.rows.length;

	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	document.getElementById("KEY_EVENT_CODE").value = "" + KeyID;
	switch (KeyID)
	{
	// UP Arrow Key event code 38
	case 38:
		var minRowId = table.rows[0].cells[0].children[0].id;
		pos1 = minRowId.indexOf(".");
		pos = minRowId.lastIndexOf(".");
		var minRowId = parseInt(minRowId.substring(pos1 + 1, pos));
		fieldId = field.id;
		RowIndexVal = parseInt(field.parentNode.parentNode.rowIndex) - 1;
		colIndexVal = parseInt(field.parentNode.cellIndex);
		try
		{
			table.rows[RowIndexVal].cells[colIndexVal]
					.getElementsByTagName("input")[0].focus();
		} catch (err)
		{
		}
		return false;
		break;
	// DOWN Arrow Key event code 40
	case 40:
		var maxRowId = table.rows[tableLength - 1].cells[0].children[0].id;
		pos1 = maxRowId.indexOf(".");
		pos = maxRowId.lastIndexOf(".");
		var maxRowId = parseInt(maxRowId.substring(pos1 + 1, pos));
		fieldId = field.id;
		RowIndexVal = parseInt(field.parentNode.parentNode.rowIndex) + 1;
		colIndexVal = parseInt(field.parentNode.cellIndex);
		try
		{
			table.rows[RowIndexVal].cells[colIndexVal]
					.getElementsByTagName("input")[0].focus();
		} catch (err)
		{
		}
		return false;
		break;
	// F9 key event code 120
	case 120:
		onBlurFunction(field);

		functionPending = "popupHelp(\"" + field.name + "\"," + KeyID + ")";
		return false;
		break;
	// F2 key event code 113
	case 113:
		onBlurFunction(field);

		functionPending = "popupHelp(\"" + field.name + "\"," + KeyID + ")";
		return false;
		break;
	// F6 key event code 117
	case 117:

		addAndRemoveDetail("detailTable", "R", field);

		return false;
		break;
	// F4 key event code 115
	case 115:

		addAndRemoveDetail("detailTable", "A", field);

		return false;
		// F12 key event code 123
	case 123:
		addAndRemoveDetail("detail3Table", "R", field);
		return false;
		break;
	// F8 Key event code 119
	case 119:
		addAndRemoveDetail("detail3Table", "A", field);
		return false;
		break;
	}
	return true;
}
function popupHelp(fieldID, KeyID) // Open Popup Logic for the event and field
{
	field = document.getElementById(fieldID);

	switch (KeyID)
	{
	// F9 Key for other calculation
	case 120:
		var url = field.getAttribute("calpageurl");
		if (url != null && url.length > 0)
		{
			document.getElementById("tranDiv").style.opacity = "0.5";
			document.getElementById("tranDiv").style.disabled = "true";
			document.getElementById("fieldSuggestionDiv").style.visibility = "visible";
			document.getElementById("fieldSuggFrame").focus();
			var pos = getAbsolutePosition(field);
			var fieldName = field.name;
			var pos = fieldName.lastIndexOf(".");
			fieldName = fieldName.substring(pos + 1, fieldName.length);
			var objName = document.getElementById("OBJ_NAME").value;
			keystring = document.getElementById(field.id).value;
			keystring = getquerystring("form1");
			document.form1.method = "post";
			document.form1.action = "../jsp/" + url + "?FIELDNAME="
					+ field.name + "&OBJ_NAME=" + objName;
			document.form1.target = 'fieldSuggFrame';
			document.form1.submit();
		}
		return false;

		break;
	// F2 key for field suggestion popup
	case 113:
		var ispopup = field.getAttribute("ispopup");
		if (ispopup != null && ispopup == "true")
		{
			document.getElementById("tranDiv").style.opacity = "0.5";
			document.getElementById("tranDiv").style.disabled = "true";
			document.getElementById("fieldSuggestionDiv").style.visibility = "visible";
			document.getElementById("fieldSuggFrame").focus();
			var pos = getAbsolutePosition(field);
			var objName = document.getElementById("OBJ_NAME").value;
			var fieldName = field.name;
			var pos = fieldName.lastIndexOf(".");
			fieldName = fieldName.substring(pos + 1, fieldName.length);
			keystring = document.getElementById(field.id).value;

			/*call when bon card no pop up shows  */
			if (document.getElementById("OBJ_NAME").value == "poschg"
					&& fieldName == "bon_card_no")
			{
				keystring = document.getElementById("Detail1.1.cust_code").value;
			}

			document.getElementById("fieldSuggFrame").src = "../jsp/CDPopUp.jsp?FIELDNAME="
					+ field.name
					+ "&OBJ_NAME="
					+ objName
					+ "&KEYSTRING=:ITEM_CODE&ITEM_CODE=" + keystring;
		}
		return false;
		break;
	}
	return true;
}
function getAbsolutePosition(element) // get the absolute position of current
// element or field
{
	var r = {
		x : element.offsetLeft,
		y : element.offsetTop
	};
	if (element.offsetParent)
	{
		var tmp = getAbsolutePosition(element.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

function saveData(field) // save data logic
{

	createActionEventElement(field);
	if (document.getElementById("ACTION") != null)
	{
		document.getElementById("ACTION").value = "";
	}
	if (document.getElementById("FOCUSED_COL") != null)
	{
		document.getElementById("FOCUSED_COL").value = "";
	}
	if (document.getElementById("forcedSave") != null)
	{
		document.getElementById("forcedSave").value = "false";
	}
	passValue = getPassValue("detailTable");
	passValue1 = getPassValue("detail3Table");
	xmlhttpPost("/ibase/E12SingleTranEditorServlet", "form1",
			"<img src=\"../images/loading.gif\">");
	return false;
}

function xmlhttpPost(strURL, formname, responsemsg)
{

	var xmlHttpReq = false;
	var self = this;
	// Xhr per Mozilla/Safari/Ie7
	if (window.XMLHttpRequest)
	{
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// per tutte le altre versioni di IE
	else if (window.ActiveXObject)
	{
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open("POST", strURL, true);
	self.xmlHttpReq.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4)
		{
			document.getElementById("loading").style.visibility = "hidden";

			showMessage(self.xmlHttpReq.responseText);
			if (functionPending != "")
				;
			{
				eval(functionPending);
			}
			functionPending = "";
			if(document.getElementById("OBJ_NAME").value == "poschg" && currentField.name.indexOf("bar_code") != -1 )
			{
				checkBarCodeScan(currentField);
			}
			currentField = null;
		} else if (responsemsg != "")
		{
			document.getElementById("loading").style.visibility = "visible";
			document.getElementById("loading").innerHTML = "<img id=\"loading-image\" src=\"../images/loading.gif\" alt=\"Loading...\"/>";
		}
	}
	self.xmlHttpReq.send(getquerystring(formname));
}
function getquerystring(formname)
{
	var form = document.forms[formname];
	var qstr = "";
	function GetElemValue(name, value)
	{
		if (passValue == "" && passValue1 == "")
		{

			qstr += (qstr.length > 0 ? "&" : "")
					+ escape(name).replace(/\+/g, "%2B") + "="
					+ escape(value ? value : "").replace(/\+/g, "%2B");
		} else
		{
			if (passValue == "" && passValue1 != "")
			{
				if (name.indexOf(passValue) == -1)
				{
					qstr += (qstr.length > 0 ? "&" : "")
							+ escape(name).replace(/\+/g, "%2B") + "="
							+ escape(value ? value : "").replace(/\+/g, "%2B");
				}
			} else if (passValue != "" && passValue1 == "")
			{
				if (name.indexOf(passValue1) == -1)
				{
					qstr += (qstr.length > 0 ? "&" : "")
							+ escape(name).replace(/\+/g, "%2B") + "="
							+ escape(value ? value : "").replace(/\+/g, "%2B");
				}
			} else
			{
				if (name.indexOf(passValue) == -1
						&& name.indexOf(passValue1) == -1)
				{
					qstr += (qstr.length > 0 ? "&" : "")
							+ escape(name).replace(/\+/g, "%2B") + "="
							+ escape(value ? value : "").replace(/\+/g, "%2B");
				}
			}
		}
	}
	var elemArray = form.elements;
	for ( var i = 0; i < elemArray.length; i++)
	{
		var element = elemArray[i];
		var elemType = element.type.toUpperCase();
		var elemName = element.name;
		if (elemName)
		{
			if (elemType == "TEXT" || elemType == "TEXTAREA"
					|| elemType == "PASSWORD" || elemType == "BUTTON"
					|| elemType == "RESET" || elemType == "SUBMIT"
					|| elemType == "FILE" || elemType == "IMAGE"
					|| elemType == "HIDDEN")
				GetElemValue(elemName, element.value);
			else if (elemType == "CHECKBOX" && element.checked)
				GetElemValue(elemName, element.value ? element.value : "On");
			else if (elemType == "RADIO" && element.checked)
				GetElemValue(elemName, element.value);
			else if (elemType.indexOf("SELECT") != -1)
				for ( var j = 0; j < element.options.length; j++)
				{
					var option = element.options[j];
					if (option.selected)
						GetElemValue(elemName, option.value ? option.value
								: option.text);
				}
		}
	}
	return qstr;
}

// Data save messages handling
function showMessage(messageStr)
{
	if (window.DOMParser)
	{
		parser = new DOMParser();
		xmlDoc = parser.parseFromString(messageStr, "text/xml");
	} else
	// Internet Explorer
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = false;
		xmlDoc.loadXML(messageStr);
	}
	if (document.getElementById("ACTION").value != ""
			&& document.getElementById("FOCUSED_COL").value != "")
	{
		var x = xmlDoc.getElementsByTagName("Root")[0].childNodes;
		if (x != null)
		{
			for (i = 1; i < x.length; i++)
			{

				detailElement = x[i];
				if (detailElement.nodeName.indexOf("Detail") != -1)
				{
					domID = detailElement.getAttribute("domID");
					if (domID != null)
					{
						detailChild = detailElement.childNodes;
						detailLength = xmlDoc.getElementsByTagName("Detail2").length;
						actualDetailLength = document
								.getElementById("detailTable").rows.length;
						for (cnt = 2; (cnt <= detailLength && detailLength > actualDetailLength); cnt++)
						{
							addAndRemoveDetail("detailTable", "A", document
									.getElementById(detailElement.nodeName
											+ "." + domID + ".line_no"));

							actualDetailLength = document
									.getElementById("detailTable").rows.length;
						}
						for (j = 1; j < detailChild.length; j++)
						{
							if (detailChild[j] != null)
							{
								fieldName = detailChild[j].nodeName;
								if (document
										.getElementById(detailElement.nodeName
												+ "." + domID + "." + fieldName) != null)
								{
									try
									{
										document
												.getElementById(detailElement.nodeName
														+ "."
														+ domID
														+ "."
														+ fieldName).value = detailChild[j].childNodes[0].nodeValue;
										if (detailChild[j]
												.getAttribute("protect") == "1"
												|| detailChild[j]
														.getAttribute("PROTECT") == "1")
										{
											document.getElementById(
													detailElement.nodeName
															+ "." + domID + "."
															+ fieldName)
													.setAttribute("readonly",
															"true");
											document.getElementById(
													detailElement.nodeName
															+ "." + domID + "."
															+ fieldName)
													.setAttribute("tabIndex",
															"-1");
										}
									} catch (err)
									{
									}
								}
							}
						}
					} else
					{
						detailChild = detailElement.childNodes;
						for (j = 0; j < detailChild.length; j++)
						{
							if (detailChild[j] != null)
							{
								fieldName = detailChild[j].nodeName;
								columnNameInHtml = document
										.getElementById("FOCUSED_COL").value;
								pos = columnNameInHtml.indexOf(".");
								pos1 = columnNameInHtml.lastIndexOf(".");
								domID = columnNameInHtml.substring(pos + 1,
										pos1);
								
								if (detailElement.nodeName == "Detail1")
								{
									domID = "1";
								}
								if (document
										.getElementById(detailElement.nodeName
												+ "." + domID + "." + fieldName) != null)
								{
									try
									{
										nodeForSet = detailChild[j].childNodes[0];
										nodeValueForSet = "";
										if(nodeForSet != null && nodeForSet != undefined)
										{
											nodeValueForSet = nodeForSet.nodeValue;
										}
										document
												.getElementById(detailElement.nodeName
														+ "."
														+ domID
														+ "."
														+ fieldName).value = nodeValueForSet;
										if (detailChild[j]
												.getAttribute("protect") == "1"
												|| detailChild[j]
														.getAttribute("PROTECT") == "1")
										{
											document.getElementById(
													detailElement.nodeName
															+ "." + domID + "."
															+ fieldName)
													.setAttribute("readonly",
															"true");
											document.getElementById(
													detailElement.nodeName
															+ "." + domID + "."
															+ fieldName)
													.setAttribute("tabIndex",
															"-1");
										}
									} catch (err)
									{
									}
								}
							}
						}
					}
				}
			}
		}
	} else
	{
		var x = xmlDoc.getElementsByTagName("error");
		showMessage.isOk = false;
		if (x != null)
		{
			for (i = 0; i < x.length; i++)
			{
				errorType = "";
				errorStr = "";
				errorType1 = x[i].getElementsByTagName("type")[0];
				if (errorType1 == null)
				{
					errorType = x[i].getAttribute("type");
				} else
				{
					errorType = errorType1.childNodes[0].nodeValue;
					errorStr = " Error ID : " + x[i].getAttribute("id");
				}
				if (errorType == "E")
				{
					showMessage.isOk = false;
					errorStr = errorStr
							+ "\n"
							+ x[i].getElementsByTagName("message")[0].childNodes[0].nodeValue;
					errorStr = errorStr
							+ "\n Description : "
							+ x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue;
					alert(errorStr);
					break;
				} else if (errorType == "W")
				{
					errorStr = errorStr
							+ "\n"
							+ x[i].getElementsByTagName("message")[0].childNodes[0].nodeValue;
					errorStr = errorStr
							+ "\n Description : "
							+ x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue;
					showMessage.isOk = confirm(errorStr);
					if (!showMessage.isOk)
					{
						break;
					}
				}
			}
		}
	}
	if (showMessage.isOk && x != null && x.length != 0)
	{
		document.getElementById("forcedSave").value = "true";
		xmlhttpPost("/ibase/E12SingleTranEditorServlet", "form1",
				"<img src=\"../images/loading.gif\">");
	}
	if (x != null && x.length == 0 && messageStr.indexOf("Success") != -1)
	{
		alert("Data Saved Successfully. \nTransaction ID : ["
				+ xmlDoc.getElementsByTagName("TranID")[0].firstChild.nodeValue
				+ "]");
		window.close();
	} else if (messageStr.indexOf("Exception") != -1)
	{
		alert("Error:[" + messageStr + "]");
	}
}

function setPopValue(tableRowField, domName, fieldId) // set the popup focused
{
	var var1 = tableRowField.getElementsByTagName("input");
	if (var1 == null)
	{
		closePopWindow(fieldId);
	} else
	{
		for (i = 0; i < var1.length; i++)
		{
			var2 = tableRowField.getElementsByTagName("input")[i].name;
			if (var2.indexOf(".") == -1 && var2.indexOf("Detail") == -1)
			{
				var2 = domName + "." + var2.toLowerCase()
			}
			if (document.getElementById(var2) != null)
			{
				document.getElementById(var2).value = tableRowField
						.getElementsByTagName("input")[i].value;
			}
		}
	}
}

function closePopWindow(str) // logic for close the popup
{
	document.getElementById("tranDiv").style.opacity = "1";
	document.getElementById("tranDiv").style.disabled = "false";
	document.getElementById("fieldSuggestionDiv").style.visibility = "hidden";
	document.getElementById("fieldSuggFrame").src = "";
	if (str != null)
	{
		document.getElementById(str).focus();
	}
}
function onBlurFunction(field)
{
	if (field != null
			&& functionPending == ""
			&& ((field.getAttribute("isservercallonchange") != null && field
					.getAttribute("isservercallonchange") == "true") || field.name
					.indexOf("itm_default") != -1)) // CHECK FIELD IS SET FOR
	// ITEM CHANGE OR NOT
	{

		createActionEventElement(field);
		if (document.getElementById("ACTION") != null)
		{
			document.getElementById("ACTION").value = "post_item_change";
		}
		if (document.getElementById("FOCUSED_COL") != null && currentField == null)
		{
			document.getElementById("FOCUSED_COL").value = field.name;
			currentField = field;
		}
		else if(document.getElementById("FOCUSED_COL") != null)
		{
			document.getElementById("FOCUSED_COL").value = currentField.name;
		}
		if (document.getElementById("forcedSave") != null)
		{
			document.getElementById("forcedSave").value = "false";
		}
		xmlhttpPost("/ibase/E12SingleTranEditorServlet", "form1", "");
	}

}
function onBlurForDetail(field, tableName) // for unselect the detail rows
{
	if (field != null && field.parentNode.className == "detailFieldCol")
	{
		var table = document.getElementById(tableName);
		var curRowId = field.parentNode.parentNode.rowIndex;
		var tableLength = table.rows.length;
		for (i = 0; i < tableLength; i++)
		{
			table.rows[i].className = "deSelectedRow";
			colLength = table.rows[i].cells.length;
			for (count = 0; count < colLength; count++)
			{
				if (table.rows[i].cells[count].firstChild.className
						.indexOf("Disable") == -1)
				{
					table.rows[i].cells[count].firstChild.className = "detailField";
				} else
				{
					table.rows[i].cells[count].firstChild.className = "detailFieldDisable";
				}
			}
		}
	}
	return false;
}
function createActionEventElement(field)
{

	if (document.getElementById("ACTION") == null)
	{
		var element = document.createElement("input");

		element.type = "hidden";
		element.name = "ACTION";
		element.value = "post_item_change";
		element.setAttribute("id", "ACTION");
		element.setAttribute("readonly", "readonly");
		document.form1.appendChild(element);
	}
	if (document.getElementById("FOCUSED_COL") == null)
	{
		var element = document.createElement("input");
		element.type = "hidden";
		element.name = "FOCUSED_COL";
		if (field != null)
		{
			element.value = field.name;
		} else
		{
			element.value = "";
		}
		element.setAttribute("id", "FOCUSED_COL");
		element.setAttribute("readonly", "readonly");
		document.form1.appendChild(element);
	}
	if (document.getElementById("forcedSave") == null)
	{
		var element = document.createElement("input");
		element.type = "hidden";
		element.name = "forcedSave";
		element.value = "false"
		element.setAttribute("id", "forcedSave");
		element.setAttribute("readonly", "readonly");
		document.form1.appendChild(element);
	}
}
function focusRow(field) // for select the focus field detail row
{

	var tableName = "";
	if (field.name.indexOf("Detail2") != -1)
	{
		tableName = "detailTable";
	} else if (field.name.indexOf("Detail3") != -1)
	{
		tableName = "detail3Table";
	}
	onBlurForDetail(field, tableName);
	field.select();
	field.parentNode.parentNode.className = "selectRow";
	colLength = field.parentNode.parentNode.cells.length;
	for (count = 0; count < colLength; count++)
	{
		if (field.parentNode.parentNode.cells[count].firstChild.className
				.indexOf("Disable") == -1)
		{
			field.parentNode.parentNode.cells[count].firstChild.className = "selectedDetailRow";
		} else
		{
			field.parentNode.parentNode.cells[count].firstChild.className = "selectDetailFieldDisable";
		}
	}
	return false;
}
function setCalPopUpValue(domNameParent, domIdParent, parentFieldName,
		fieldvalue)
{
	if (document.getElementById(domNameParent + "." + domIdParent + "."
			+ parentFieldName) != null)
	{
		document.getElementById(domNameParent + "." + domIdParent + "."
				+ parentFieldName).value = fieldvalue;
	}
}
function addAndRemoveDetail(tableName, flag, field)
{

	var table = document.getElementById(tableName);

	var tableDelete = document.getElementById(tableName + "Delete")

	tableLength = table.rows.length;
	if (flag == "R")
	{
		if (tableLength > 1)
		{
			var maxRowId = table.rows[tableLength - 1].cells[0].children[0].id;
			pos1 = maxRowId.indexOf(".");
			pos = maxRowId.lastIndexOf(".");
			var maxRowId = parseInt(maxRowId.substring(pos1 + 1, pos));
			var curRowId = field.parentNode.parentNode.rowIndex;
			fieldId = field.id;
			pos1 = fieldId.indexOf(".");
			pos = fieldId.lastIndexOf(".");
			var domId = parseInt(fieldId.substring(pos1 + 1, pos));
			formId = fieldId.substring(0, pos1);
			fieldName = fieldId.substring(pos + 1, field.id.length);
			isAdded = false;
			if (document.getElementById(formId + "." + (domId) + ".status").value == "N"
					&& document.getElementById(formId + "." + (domId)
							+ ".updateFlag").value == "A")
			{
				isAdded = true;
			}
			document.getElementById(formId + "." + (domId) + ".status").value = "O";
			document.getElementById(formId + "." + (domId) + ".updateFlag").value = "D";
			var fieldLength = table.rows[curRowId]
					.getElementsByTagName("input").length;
			var selectFieldLength = table.rows[curRowId]
					.getElementsByTagName("select").length;
			for (cnt = 0; cnt < selectFieldLength; cnt++)
			{
				table.rows[curRowId].getElementsByTagName("select")[cnt].style.visibility = "hidden";
			}
			for (cnt = 0; cnt < fieldLength; cnt++)
			{
				table.rows[curRowId].getElementsByTagName("input")[cnt].style.visibility = "hidden";

			}
			if (isAdded)
			{
				table.deleteRow(curRowId);
			} else
			{
				tableDelete.appendChild(table.rows[curRowId]);
			}
			domId = domId - 1;
			while ((document.getElementById(formId + "." + (domId) + "."
					+ fieldName) == null || document.getElementById(formId
					+ "." + (domId) + "." + fieldName).style.visibility == "hidden")
					&& domId > 1)
			{
				domId--;
			}
			if (document.getElementById(formId + "." + domId + "." + fieldName) == null)
			{
				table.rows[0].cells[0].children[0].focus();
			} else
			{
				document.getElementById(formId + "." + domId + "." + fieldName)
						.focus();
			}
		}
	}
	if (flag == "A")
	{
		var maxLineNo = 1;
		for (cnt = 0; cnt < tableLength; cnt++)
		{
			inputField = table.rows[cnt].cells[0].getElementsByTagName("input")[0];
			inputFieldID = inputField.id;
			pos1 = inputFieldID.indexOf(".");
			formId = inputFieldID.substring(0, pos1);
			pos = inputFieldID.lastIndexOf(".");
			domID = parseInt(inputFieldID.substring(pos1 + 1, pos));
			currLineNo = parseInt(document.getElementById(formId + "." + domID
					+ ".line_no").value.trim());
			if (currLineNo > maxLineNo)
			{
				maxLineNo = currLineNo;
			}
		}
		for (cnt = 0; cnt < tableDelete.length; cnt++)
		{
			inputField = table.rows[cnt].cells[0].getElementsByTagName("input")[0];
			inputFieldID = inputField.id;
			pos1 = inputFieldID.indexOf(".");
			formId = inputFieldID.substring(0, pos1);
			pos = inputFieldID.lastIndexOf(".");
			domID = parseInt(inputFieldID.substring(pos1 + 1, pos));
			currLineNo = parseInt(document.getElementById(formId + "." + domID
					+ ".line_no").value.trim());
			if (currLineNo > maxLineNo)
			{
				maxLineNo = currLineNo;
			}
		}
		if (tableLength == 1
				&& table.rows[0].cells[0].getElementsByTagName("input")[0].disabled == true)
		{

			cells = table.rows[0].cells;
			for (cnt = 0; cnt < cells.length; cnt++)
			{
				var rowFields = cells[cnt].getElementsByTagName("input");
				for (count = 0; count < rowFields.length; count++)
				{
					rowFields[count].disabled = false;
					fieldName = rowFields[count].id;
					pos1 = fieldName.indexOf(".");
					formId = fieldName.substring(0, pos1);
					pos = fieldName.lastIndexOf(".");
					domID = parseInt(fieldName.substring(pos1 + 1, pos));
				}
			}
			inputElement = table.rows[0].cells[0].getElementsByTagName("input")[0];
			inputElement.focus();
			var element1 = document.createElement("input");
			element1.type = "hidden";
			element1.name = formId + "." + domID + ".itm_default";
			onBlurFunction(element1);
			document.getElementById(formId + "." + domID + ".line_no").value = "  1";
		} else
		{

			var appendRow1 = table.rows[tableLength - 1].cloneNode(true);
			var table1 = table.rows[0].parentNode;
			table1.appendChild(appendRow1);
			var rowFields = table.rows[tableLength]
					.getElementsByTagName("input");
			for (count = 0; count < rowFields.length; count++)
			{
				var fieldName = rowFields[count].id;
				var isPrimaryKey = document.getElementById(fieldName)
						.getAttribute("isPrimaryKey");
				var pos1 = fieldName.indexOf(".");
				formId = fieldName.substring(0, pos1);
				pos = fieldName.lastIndexOf(".");
				domID = maxLineNo + 1;

				fieldName = fieldName.substring(pos + 1, fieldName.length);
				rowFields[count].id = formId + "." + domID + "." + fieldName;
				;
				rowFields[count].name = formId + "." + domID + "." + fieldName;

				rowFields[count].disabled = false;
				if (fieldName != "tran_id" && isPrimaryKey != "true")
				{
					rowFields[count].value = "";
				}
			}

			document.getElementById(formId + "." + domID + ".status").value = "N";
			document.getElementById(formId + "." + domID + ".updateFlag").value = "A";
			try
			{
				var tempLine_no = "   " + domID;
				tempLine_no = tempLine_no.substring(tempLine_no.length - 3,
						tempLine_no.length);

				document.getElementById(formId + "." + domID + ".line_no").value = tempLine_no;
				var objName = document.getElementById("OBJ_NAME").value;
				if (objName == "grnentry_cd")
				{

					document.getElementById(formId + "." + domID
							+ ".line_no__ord").value = tempLine_no;
					document.getElementById(formId + "." + domID + ".FS").value = "FS";
					document.getElementById(formId + "." + domID + ".HS").value = "HS";
				}
				if (objName == "porder_cd")
				{
					document.getElementById(formId + "." + domID + ".FS").value = "FS";
					document.getElementById(formId + "." + domID + ".HS").value = "HS";
				}
			} catch (err)
			{
			}
			document.getElementById(formId + "." + domID + ".dbID").value = document
					.getElementById("pkValues").value
					+ ":" + domID + ":";


			inputElement = table.rows[tableLength].cells[0]
					.getElementsByTagName("input")[0];
			inputElement.focus();
			var element1 = document.createElement("input");
			element1.type = "hidden";
			element1.name = formId + "." + domID + ".itm_default";
			onBlurFunction(element1);
		}
	}
	if (flag == "X")
	{
		domID = "";
		if (tableName == "detailTable")
		{
			domID = "Detail2.1"
		} else if (tableName == "detail3Table")
		{
			domID = "Detail3.1"
		}
		if (document.getElementById(domID + ".updateFlag") != null
				&& document.getElementById(domID + ".updateFlag") != undefined
				&& document.getElementById(domID + ".updateFlag").value != "A")
		{
			var rowFields = table.getElementsByTagName("input");
			for (count = 0; count < rowFields.length; count++)
			{
				rowFields[count].disabled = false;
			}
		}
	}
}
function getPassValue(tableName)
{

	var table1 = document.getElementById(tableName);
	var tableLength1 = table1.rows.length;
	if (tableLength1 == 1
			&& table1.rows[0].cells[0].getElementsByTagName("input")[0] != null
			&& table1.rows[0].cells[0].getElementsByTagName("input")[0].disabled == true)
	{
		if (tableName == "detailTable")
		{
			passValue = "Detail2.1";
		} else if (tableName == "detail3Table")
		{
			passValue = "Detail3.1";

		}
	}
}