//alert("cd_query.js");
var passValue = "";
var passValue1 = "";
var isSavePending = false;
var currentField = null;
var addRowCnt=0;
var numbers = /^[0-9.]+$/; 


function resizeVideoPage(){
    var width = 1000;
   var height = 700;
   window.resizeTo(width, height);
   window.moveTo(((screen.width - width) / 2), ((screen.height - height) / 2));      
   }


function upperCase(fieldId)
{

   var fieldValue = document.getElementById(fieldId).value; 
   document.getElementById(fieldId).value = fieldValue.toUpperCase();

}

function windowOnLoad() // Perform the operation when window transaction page
				// load
{
	resizeVideoPage();
	document.getElementById("tranDiv").style.opacity = "1";
	document.getElementById("tranDiv").style.disabled = "false";
	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
													// unselect
	addAndRemoveDetail("detailTable", "X", document.getElementById(""));
	addAndRemoveDetail("detail3Table", "X", document.getElementById(""));
	
}

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



function onKeyDownFun(field, e) // Key events for input on fields
{
       // alert("onKeyDownFun");
	isSavePending = false;
	var tableName = "";
	if (field.name.indexOf("Detail3") != -1)
	{
		tableName = "detail3Table";
	} else
	{
		tableName = "detailTable";

	}

	table = document.getElementById(tableName);
		
	var tableLength = table.rows.length;
	/*addRowCnt=tableLength+1;
	alert("tableLength :"+addRowCnt);*/
    var KeyID = (window.event) ? event.keyCode : e.keyCode;	
	
	
	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)
		{
			alert("error  from case 38 :"+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)
		{
			alert("error  from case 40 :"+err);
		}
		return false;
		break;
		
	// F9 key event code 120 //Enter key event code 13
	case 13:// case 120:
		onBlurFunction(field);
		popupHelp(field.name, KeyID);
		return false;
		break;
		
	// F2 key event code 113
	case 113:
		onBlurFunction(field);
		popupHelp(field.name, KeyID);
		
		return false;
		break;
		
	// F6 key event code 117
	case 117:
		addRowCnt=tableLength-1;
		addAndRemoveDetail("detailTable", "R", field);
		return false;
		break;
	// F4 key event code 115
	case 115:
		addRowCnt=tableLength+1;
		//alert("tableLength :"+addRowCnt);
		if(document.getElementById("OBJ_NAME").value != "grnentry_cd")
	    {
			//alert("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 13:// 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 == "receipt_gen_wiz" && fieldName == "cust_code")
			{
				keystring = document.getElementById("Detail1.1.cust_code").value;
				document.getElementById("fieldSuggFrame").src = "../jsp/receiptPopUp.jsp?FIELDNAME="
						+ field.name
						+ "&OBJ_NAME="
						+ objName
						+ "&KEYSTRING=:SITE_CODE:CUST_CODE=" + keystring+"&fieldName=cust_code";
				
				//alert(document.getElementById("fieldSuggFrame").src);
			
				
			}
			else if(document.getElementById("OBJ_NAME").value == "receipt_gen_wiz" && fieldName == "site_code")
			{
				
				document.getElementById("fieldSuggFrame").src = "../jsp/receiptPopUp.jsp?FIELDNAME="
						+ field.name
						+ "&OBJ_NAME="
						+ objName+"&fieldName=site_code";
						//+ "&KEYSTRING=:SITE_CODE&fieldName=bank_code";
				
				//alert(document.getElementById("fieldSuggFrame").src);
			
				
			}
			else if(document.getElementById("OBJ_NAME").value == "receipt_gen_wiz" && fieldName == "bank_code")
			{
				
				//keystring = document.getElementById("Detail1.1.bank_code").value;
				
				document.getElementById("fieldSuggFrame").src = "../jsp/receiptPopUp.jsp?FIELDNAME="
						+ field.name
						+ "&OBJ_NAME="
						+ objName
						+ "&KEYSTRING=:SITE_CODE&fieldName=bank_code";
			
				
			}
			/*else if(document.getElementById("OBJ_NAME").value == "receipt_gen_wiz" && fieldName == "ref_ser")
			{
				//alert("ref_ser!!!!");
				//keystring = document.getElementById("Detail1.1.bank_code").value;
				document.getElementById("fieldSuggFrame").src = "../jsp/receiptPopUp.jsp?FIELDNAME="
						+ field.name
						+ "&OBJ_NAME="
						+ objName+"&fieldName=ref_ser";
						//+ "&KEYSTRING=:SITE_CODE";
			
				
			}*/
			else if(document.getElementById("OBJ_NAME").value == "receipt_gen_wiz" && fieldName == "ref_ser")
			{
				
				var custCode1 = document.getElementById("Detail1.1.cust_code").value;
				//alert("custCode1 :"+custCode1);
				var siteCode1 = document.getElementById("Detail1.1.site_code").value;
			 // alert("siteCode1 :"+siteCode1);
				//alert("ref_ser!!!!");
				//keystring = document.getElementById("Detail1.1.bank_code").value;
				document.getElementById("fieldSuggFrame").src = "../jsp/receiptPopUp.jsp?FIELDNAME="
						+ field.name
						+ "&OBJ_NAME="
						+ objName
				+ "&KEYSTRING=:SITE_CODE:CUST_CODE&cust_code="+custCode1+"&site_code="+siteCode1+"&fieldName=ref_ser";
						//+ "&KEYSTRING=:SITE_CODE";
			
				
			}
			else if(document.getElementById("OBJ_NAME").value == "receipt_gen_wiz" && fieldName == "ref_no")
			{
			
				var custCode = document.getElementById("Detail1.1.cust_code").value;
				var siteCode = document.getElementById("Detail1.1.site_code").value;
				var index = fieldID.charAt(8);
				var refSer = document.getElementById("Detail2."+index+".ref_ser").value;
				//alert("custCode :"+custCode);
				//alert("siteCode :"+siteCode);
				//alert("refSer :"+refSer);
				
				
				document.getElementById("fieldSuggFrame").src = "../jsp/receiptPopUp.jsp?FIELDNAME="
						+ field.name
						+ "&OBJ_NAME="
						+ objName
						//+ "&KEYSTRING=:SITE_CODE:CUST_CODE&cust_code="+custCode+"&fieldName=ref_no";
						+ "&KEYSTRING=:SITE_CODE:CUST_CODE:REF_SER&site_code="+siteCode+"&cust_code="+custCode+"&ref_ser="+refSer+"&fieldName=ref_no";
				
			}
			
		}
		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
{
	//alert("savedata!zzzz!!");
	//alert("addRowCnt :"+addRowCnt);
	//alert("field :"+field);
   /*  alert("savedata!!!");
     if()
    {
    	 
    }*/
	//document.getElementById("loading").style.visibility = "visible";
	createActionEventElement(field);
	
	if (document.getElementById("ACTION") != null)
	{
		//alert("IF 01");
		document.getElementById("ACTION").value = "";
	}
	if (document.getElementById("FOCUSED_COL") != null)
	{
		//alert("IF 02");
		document.getElementById("FOCUSED_COL").value = "";
	}
	if (document.getElementById("forcedSave") != null)
	{
		//alert("IF 03");
		document.getElementById("forcedSave").value = "false";
	}
	
	
	if(!(document.getElementById("Detail1.1.chq_amt").value.match(numbers)))
	{
		  alert("Please enter valid cheque amount");
		  return false;
	}
	/*var k = 0;
			alert("addRowCnt :"+addRowCnt);
	if(addRowCnt == 0)
	{
		if(!(document.getElementById("Detail2.1.rcp_amt").value.match(numbers)))
		{
			  alert("Please enter valid receipt amount");
			  return false;
		}
		
	}
	else
	{
		k=addRowCnt;
		//alert("addRowCnt :"+addRowCnt);
		alert("outside K"+k);
		for(var p = 0 ; p< addRowCnt; p++)
		{
			alert("inside K"+k);
		    alert(document.getElementById("Detail2."+k+".rcp_amt").value);
			//if(document.getElementById("Detail2."+k+".ref_ser").value == "")
			if(!(document.getElementById("Detail2."+k+".rcp_amt").value.match(numbers)))
			{
				alert("Please enter valid receipt amount");
				return false;
			}
			
		    k--;
		}
		
	}*/
	
	/*if(document.getElementById("Detail1.1.remarks").value == "")
	{
		alert("Remarks Should not be blank");
	}*/
	//alert(document.getElementById("Detail2.1.rcp_amt").value);
	
/*	var j = 0;
	
	if(addRowCnt == 0)
	{
		if(document.getElementById("Detail2.1.ref_ser").value == "")
		{
			alert("Refernce series should not be blank.");
			return false;
		}
		if(document.getElementById("Detail2.1.ref_no").value == "")
		{
			alert("Refernce no should not be blank.");
			return false;
		}
		if(document.getElementById("Detail2.1.rcp_amt").value == "" || document.getElementById("Detail2.1.rcp_amt").value == 0)
		{
			   alert("Receipt amount should not be blank.");
			   return false;
		}
	}
	else
	{
		j=addRowCnt;
		for(var i = 0 ; i< addRowCnt; i++)
		{
			
		   // alert(document.getElementById("Detail2."+j+".rcp_amt").value);
			if(document.getElementById("Detail2."+j+".ref_ser").value == "")
			{
				alert("Refernce series should not be blank.");
				return false;
			}
			if(document.getElementById("Detail2."+j+".ref_no").value == "")
			{
				alert("Refernce no should not be blank.");
				return false;
			}
		    if(document.getElementById("Detail2."+j+".rcp_amt").value == "" || document.getElementById("Detail2."+j+".rcp_amt").value == 0)
		    {
		        alert("Receipt amount should not be blank.");	
		        return false;
		    }
		    j--;
		}
	}	
	*/
	
	passValue = getPassValue("detailTable");
	passValue1 = getPassValue("detail3Table");
	xmlhttpPost("/ibase/E12SingleTranEditorServlet", "form1",
			"<img src=\"../images/loading.gif\">");
	
	isSavePending = false;
	//document.getElementById("loading").style.visibility = "hidden";
	return false;
}

function focusSaveButton(field)
{
    if(! isSavePending)
    {
      return false;
    } 
    else
    {
	isSavePending = false;
	return saveData(field);
    }
}

function xmlhttpPost(strURL, formname, responsemsg)
{
	var xmlHttpReq = false;
	var self = this;
	
	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, false);
	self.xmlHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	
	self.xmlHttpReq.send(getquerystring(formname));
     showMessage(self.xmlHttpReq.responseText);
     
// if(currentField !=null)
    try
    {
    	
    	 // **Added new code by sachin on 22/05/14 * in onblur function
		if (document.getElementById("OBJ_NAME").value == "physicalstock_cd") 
		{
			this.chkValidBarCodFrPhyStk(self.xmlHttpReq.responseText);
			setTimeout(function() { document.getElementById("Detail1.1.bar_code").focus(); }, 1);
		}
		// ** End Added new code by sachin on 11/05/14

	/*	if (document.getElementById("OBJ_NAME").value == "poschg" && currentField.name.indexOf("bar_code") != -1)
		{
			checkBarCodeScan(currentField);
			getTotalAdjAmt();
			
		}*/
/*	if (document.getElementById("OBJ_NAME").value == "poschg" && (currentField.name.indexOf("credit_note_no") != -1 || currentField.name.indexOf("gift_voucher_no") != -1)) 
		{
			getTotalAdjAmt();
		}
*/	if (document.getElementById("OBJ_NAME").value == "denomination" && (currentField.name.indexOf("pos_id") != -1))
		{
			setPayTypeFrDenomination();
		}
	
/*	if (document.getElementById("OBJ_NAME").value == "poschg" && (currentField.name.indexOf("cust_name") != -1))
	{
		getTotalAmtFrCust();
	}
*/   
    }
    catch(error)
    {
    	
    }
	currentField = null;
}
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)

{
    // alert("message :"+messageStr);
	try
	{
	  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);
	  }
	}
	catch(parseError)
	{
	  alert("Error " + parseError + ":[" + messageStr + "]");
	  return false;
	}
	if (document.getElementById("ACTION").value != ""
			&& document.getElementById("FOCUSED_COL").value != "" && xmlDoc != null && xmlDoc.getElementsByTagName("Root")[0] != null)
	{
		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 (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)
									{
									}
								}
							}
						}
						for (cnt = 2; (cnt <= detailLength && detailLength > actualDetailLength); cnt++)
						{
							addAndRemoveDetail("detailTable", "A", document
									.getElementById(detailElement.nodeName
											+ "." + domID + ".line_no"));

							actualDetailLength = document
									.getElementById("detailTable").rows.length;
						}
					} 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("000000000");
		//added by mahendra date 18-feb-2015,start
		/*var j = 0;
		if(document.getElementById("Detail1.1.remarks").value == "")
		{
			alert("Remarks should not be blank.");
			return false;
		}
	
		
	
		
		if(addRowCnt == 0)
		{
			if(document.getElementById("Detail2.1.ref_ser").value == "")
			{
				alert("Refernce series should not be blank.");
				return false;
			}
			if(document.getElementById("Detail2.1.ref_no").value == "")
			{
				alert("Refernce no should not be blank.");
				return false;
			}
			if(document.getElementById("Detail2.1.rcp_amt").value == "" || document.getElementById("Detail2.1.rcp_amt").value == 0 || document.getElementById("Detail2.1.rcp_amt").value < 0)
			{
				   alert("Receipt amount should not be blank.");
				   return false;
			}
			
		}
		else
		{
			j=addRowCnt;
			for(var i = 0 ; i< addRowCnt; i++)
			{
				//alert("ref ser :"+document.getElementById("Detail2."+j+".ref_ser").value);
			   // alert(document.getElementById("Detail2."+j+".rcp_amt").value);
				if(document.getElementById("Detail2."+j+".ref_ser").value == "")
				{
					alert("Refernce series should not be blank.");
					return false;
				}
				if(document.getElementById("Detail2."+j+".ref_no").value == "")
				{
					alert("Refernce no should not be blank.");
					return false;
				}
			    if(document.getElementById("Detail2."+j+".rcp_amt").value == "" || document.getElementById("Detail2."+j+".rcp_amt").value == 0)
			    {
			        alert("Receipt amount should not be blank.");	
			        return false;
			    }
			    j--;
			}
		}*/
		
		//added by mahendra date 18-feb-2015,end
	
	  if(document.getElementById("OBJ_NAME").value=="poschg")
	  {
	    var d       = new Date();
	    var year    =d.getFullYear();	      
	    var ordDate =document.getElementById("Detail1.1.tran_date").value;
	    var temp    = ordDate.split("/");	   
	    ordDate     =temp[0]+"-"+temp[1]+"-"+year;	    
	    var siteCode =document.getElementById("Detail1.1.site_code").value;
	    var objectName=document.getElementById("OBJ_NAME").value;
	    var x;
	    var tranID=xmlDoc.getElementsByTagName("TranID")[0].firstChild.nodeValue;
	    var r=confirm("Data Saved Successfully. \nTransaction ID : [ "+ xmlDoc.getElementsByTagName("TranID")[0].firstChild.nodeValue+ " ].\n\nTo View Report Press OK.");
	    if (r==true)
	    {
	      //window.open("/ibase/webitm/jasprerportria/CustomReportJasp.jsp?as_site_code="+siteCode+"&cash_memo_fr="+tranID+"&cash_memo_to="+tranID+"&OBJ_NAME=poschg");
	    	window.open("/ibase/webitm/jasprerportria/CustomReportJasp.jsp?as_site_from="+siteCode+"&as_site_to="+siteCode+"&as_fr_date="+ordDate+"&as_to_date="+ordDate+"&pos_id_fr="+tranID+"&pos_id_to="+tranID+"&OBJ_NAME=poschg"); 

	           
	    }
	    else
	    {
	      x="You pressed Cancel!";
	    }	
	    window.close();
	  }
		
	  
	  

	  else if(document.getElementById("OBJ_NAME").value=="founditem_cd")
	  {
		
		  this.clearFoundItemAllFld();
	  }
	  
	  
	  else 
	  {	 
		  
		//  alert("ref ser1 :"+document.getElementById("Detail2.1.ref_ser").value);
		//  alert("ref ser2 :"+document.getElementById("Detail2.2.ref_ser").value);
	    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 // field value in the // main window field
{
	
	//alert("tableRowField:"+tableRowField);
	//alert("domName:"+domName);
	//alert("fieldId:"+fieldId);
	var var1 = tableRowField.getElementsByTagName("input");
	//alert("var1 :"+var1);
	if (var1 == null)
	{
		closePopWindow(fieldId,true);
	} else
	{
		//alert("var1.length :"+var1.length);
		for (i = 0; i < var1.length; i++)
		{
			//alert(i);
			var2 = tableRowField.getElementsByTagName("input")[i].name;
			//alert("var2@@"+var2);
			if(var2.match("Reference_No"))
			{
				//alert("IFFFFF");
				var2="ref_no";
			}
			if(var2.match("Tran_Ser"))
			{
				var2="ref_ser";
			}
			//alert("^^^^^ "+document.getElementById(var2));
			if (var2.indexOf(".") == -1 && var2.indexOf("Detail") == -1)
			{
				//alert("domName :"+domName);
				//alert("var2.toLowerCase() "+var2.toLowerCase());
				var2 = domName + "." + var2.toLowerCase()
				//var2 = fieldId;
				//alert("var2 ###!!!!"+var2);
			}
			if (document.getElementById(var2) != null)
			{
				//alert("@@@^^^^^^^^^^^@@@@@");
				document.getElementById(var2).value = tableRowField.getElementsByTagName("input")[i].value;
				//alert("result :"+document.getElementById(var2).value);
			}
		}
	}
}

function closePopWindow(str,flag) // 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)
	{
	    var field = document.getElementById(str);
	    if(field != null)
	    {
	      field.focus();
	      var isServerCallField = document.getElementById(str).getAttribute("isservercallonchange");
	      if(isServerCallField != null && isServerCallField == "true" && flag == true)
	      {
		  getNextFocusField("form1",field)
	      }
	    }
	}
}
function onBlurFunction(field)
{
	 
      //alert("field :"+field);       
	
	//document.getElementById(field).value = fieldValue.toUpperCase();
	
	if (field != null && ((field.getAttribute("isservercallonchange") != null && field.getAttribute("isservercallonchange") == "true") || field.name .indexOf("itm_default") != -1)) // CHECK FIELD IS SET FOR
	// ITEM CHANGE OR NOT
	{
		//alert("IF!!!!!!!");
		isSavePending = true;		
		createActionEventElement(field);		
		if (document.getElementById("ACTION") != null)
		{
			document.getElementById("ACTION").value = "post_item_change";
		}
		if (document.getElementById("FOCUSED_COL") != null)
		{
			document.getElementById("FOCUSED_COL").value = field.name;
			currentField = field;
		}
		
		if (document.getElementById("forcedSave") != null)
		{
			document.getElementById("forcedSave").value = "false";
		}
// window.setTimeout("xmlhttpPost('/ibase/E12SingleTranEditorServlet', 'form1', 'loading')",3000);
                
	xmlhttpPost("/ibase/E12SingleTranEditorServlet", "form1", "<img src=\"../images/loading.gif\">");
	//**Added new code by sachin on 11/04/14 *  in onblur function\\\
				if(document.getElementById("OBJ_NAME").value=="founditem_cd")
				  {
					this.chkValidFoundData();
					setTimeout(function(){document.getElementById("Detail1.1.barcode").focus();}, 1);

				}
				//** End Added new code by sachin on 11/04/14*\\\

	}

}
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)
{
	//alert("=====addAndRemoveDetail===");
	//alert("=====addAndRemoveDetail===tableName:"+tableName);
//	alert("=====addAndRemoveDetail===field:"+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);
			// Delete row logic
			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;
			// for drop-down select box deletion
			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]);
			}

			// end
			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")
	{
		/* Added  New Code by Sachin on 11/2/14 for Cash Memo  check tableLength is 12*/
		
		if(tableLength<12)
		{
		var maxLineNo = 1;
		var domID = 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));
		//	document.getElementById(formId + "." + domID + ".line_no__ref").value = 2;
			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";
			currentField = null;
			eval(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;
				
				
				// newly added if conditions
				
				var objName = document.getElementById("OBJ_NAME").value;
				
				if(objName == "porder_cd")
				{
					
					var pordType = document.getElementById("Detail1.1.pord_type").value;
				   // for trading only first coulmn should be cloned
										
				  // for Jobwork no rows should be cloned
					if(pordType.trim() == "J")
					{
						
						if (fieldName != "tran_id" && isPrimaryKey != "true")
						{
							rowFields[count].value = "";
						}
					}
				}
				
				else  if(objName != "porder_cd")
				{
					if (fieldName != "tran_id" && isPrimaryKey != "true")
						{
							rowFields[count].value = "";
						}
				}
				// end of newly added if conditions
				
			}
			
			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);
                //alert("tempLine_no  :"+tempLine_no);
				document.getElementById(formId + "." + domID + ".line_no").value = tempLine_no;
				document.getElementById(formId + "." + domID + ".line_no__ref").value = 1;
				document.getElementById(formId + "." + domID + ".rcp_amt").value = 0.00;
				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";
				    
				}
				else if (objName == "porder_cd")
				{
					var pordType = document.getElementById("Detail1.1.pord_type").value;
					   if(pordType.trim() == "J" || pordType.trim() == "T")
					   {
						document.getElementById(formId + "." + domID + ".FS").value = "FS";					
						document.getElementById(formId + "." + domID + ".HS").value = "HS";
					   }
				}
				
				else if(objName != "poschg")
				{
				 document.getElementById(formId + "." + domID + ".site_code").value=document.getElementById(formId + ".1.site_code").value
				 document.getElementById(formId + "." + domID + ".loc_code").value=document.getElementById(formId + ".1.loc_code").value
				}
			
			// Add new code on dated 18/01/2014 by sachin
				 // alert("In aadd remove");
			
			
			  else	 if(objName="poschg")
				
			     {
				  	/* Code Add By Dhanendra for Set Focus on barcode textbox 17Dec2014*/
			  		 document.getElementById(formId + "." + domID + ".bar_code").focus();
			  		/* End Code By Dhanendra for Set Focus on barcode textbox 17Dec2014*/
			  		 document.getElementById(formId + "." + domID + ".curr_code").value="INR";
			     }

						
			
			// End new code on dated 18/01/2014 by sachin
			
			
			       
			} catch (err)
			{
			}
			
			// Add new code on dated 18/01/2014 by sachin
		 if (objName == "denomination")
		     {
			  
			document .getElementById(formId + "." + domID + ".curr_code").value = document .getElementById(formId + ".1.curr_code").value;
			document.getElementById(formId + "." + domID + ".std_exrt").value = document .getElementById(formId + ".1.std_exrt").value;
		     }
			
			// Add new code on dated 18/01/2014 by sachin
			
			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);
		 }
	
		}else
		{
		 alert("You can add only 12 bar code in cash memo");	
		}
		
		/* End Added  New Code by Sachin on 11/2/14 for Cash Memo  check tableLength is 12*/
	
	}
	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";
		}
	}
}

function getNextFocusField(formname,currentField)
{
  var form = document.forms[formname];
  var currentIndex = parseInt(currentField.getAttribute("tabIndex"))+1;
  var closestIndex = 1;
  var nextField = currentField;
  var elemArray = form.elements;
  for ( var i = 0; i < elemArray.length; i++)
  {
	  var element = elemArray[i];
	  targetIndex = parseInt(element.getAttribute("tabIndex"));
	  if(targetIndex >= currentIndex && (closestIndex > targetIndex || closestIndex == 1))
	  {
	    nextField = element;
	    closestIndex = targetIndex;
	  }
  }
  nextField.focus();
}


// Add New function by sachine on dated 18/01/2013


/*function getTotalAdjAmt() {
  
	  try {
		var crNoteAmt = document.getElementById("Detail1.1.credit_note_amount").value;
		var giftVoucherAmt = document .getElementById("Detail1.1.gift_voucher_amount").value;
		

		var totalAdjAmt = document.getElementById("Detail1.1.adj_amt");
		var crNote = parseFloat(crNoteAmt.substr(1));
		var giftVoucher = parseFloat(giftVoucherAmt.substr(1));
                var crNoteFloat = isNaN(crNote) ? parseFloat(0.0) : crNote;
		var giftVoucherFloat = isNaN(giftVoucher) ? parseFloat(0.0) : giftVoucher;

		var totalAmount = parseFloat(crNoteFloat) + parseFloat(giftVoucherFloat);

		if(totalAmount>0)
			{
			totalAdjAmt.value = parseFloat(totalAmount).toFixed(2);
			}
		else
		{
			totalAdjAmt.value = parseFloat(totalAmount).toFixed(1);
		}		
		
		crNoteAmt = "";
		giftVoucherAmt = "";

		var invoiceAmt = parseFloat(document .getElementById("Detail1.1.inv_amt").value);
		var discountAmt = parseFloat(document .getElementById("Detail1.1.disc_amt").value);
		var adjustmentAmt = parseFloat(document .getElementById("Detail1.1.adj_amt").value);
		var specialDiscountAmt = parseFloat(document .getElementById("Detail1.1.spdisc_amt").value);
		var deliveryChrg=parseFloat(document.getElementById("Detail1.1.delivery_chrg").value);
		var adjNowAmt=parseFloat(document.getElementById("Detail1.1.adjust_now").value);	
		var netAmountAftCal = parseFloat(invoiceAmt) - parseFloat(adjustmentAmt)- parseFloat(specialDiscountAmt)-parseFloat(adjNowAmt)+parseFloat(deliveryChrg)-parseFloat(discountAmt); 
																																									
		if (!isNaN(netAmountAftCal)) 
		{
			if(netAmountAftCal>0)
				{
				document.getElementById("Detail1.1.net_amt").value = parseFloat(netAmountAftCal).toFixed(2);
				}else
				{
					document.getElementById("Detail1.1.net_amt").value = parseFloat(netAmountAftCal).toFixed(1);	
				}
			this.setCashAmt();
		}
	} catch (error) {
	}

}
*/
// End New function by sachin on dated 18/2014


/*function setCashAmt() {
	var ddChqAmt = document.getElementById("Detail1.1.dd_chq_amt").value;
	var ccAmt = document.getElementById("Detail1.1.cc_amt").value;

	var netAmt = document.getElementById("Detail1.1.net_amt").value;
	
	var otherAmt = 0.0;

	if (parseFloat(ddChqAmt) > 0) 
	{
		otherAmt = parseFloat(ddChqAmt);
	}
	if (parseFloat(ccAmt) > 0) 
	{
		otherAmt = otherAmt + parseFloat(ccAmt);
	}
	document.getElementById("Detail1.1.cash_amt").value = (parseFloat(netAmt) - parseFloat(otherAmt)).toFixed(2);


}*/


/*function genCreditNote() {
	var netAmt = document.getElementById("Detail1.1.net_amt").value;
	var amount = parseInt(netAmt);

	var creditntBtn = document.getElementById("gen_credit_note");
	if (amount < 0) {
		creditntBtn.style.visibility = 'visible';
	} else {

		creditntBtn.style.visibility = 'hidden';
	}
}*/

/*function setPayTypeFrDenomination() {

	var paymentType = document.getElementById("Detail1.1.pay_type").value;
	var denomPayType = document.getElementById("Detail2.1.type");
	var denomination = document.getElementById("Detail2.1.denomination");

	if (paymentType == "E" || paymentType == "Q" || paymentType == "D") {
		denomPayType.value = "D";
		denomPayType.disabled = true;
	} else if (paymentType == "C") {
		denomPayType.value = "C";
	}

}*/

// End new function

//Added new fucntion by sachin 6/03/13 

/*function getTotalAmtFrCust() 
{
	var amt = 0.0; var price; var priceInFloat = 0.0; var count = 0; var priceCount = 0;
	var bcShirt = 0; var flotAmt = parseFloat(amt).toFixed(2);
	var priceArr = new Array();
	tableLength = document.getElementById("detailTable").rows.length;
	for (i = 0; i < tableLength; i++) 
	{
		price = document.getElementById("detailTable").rows[i].cells[8] .getElementsByTagName("input")[0];
		priceInFloat = (parseFloat(price.value)).toFixed(2);
		if (!isNaN(priceInFloat)) 
		{
			priceCount++;
			priceArr.push(priceInFloat);
			flotAmt = parseFloat(flotAmt) + parseFloat(priceInFloat);
		}
		var lineNo = document.getElementById("detailTable").rows[i].cells[0] .getElementsByTagName("input")[0];
		if (lineNo.value == "") 
		{
			document.getElementById("Detail2.1.line_no").value = 1;
		}
		count++;
	}
	
	
	document.getElementById("totalQuantity").value = count;
	document.getElementById("Detail1.1.inv_amt").value = (parseFloat(flotAmt)).toFixed(2);
	bcShirt = document.getElementById("Detail1.1.bc_shirts").value;
	bcShirt = (parseInt(bcShirt) + parseInt(priceCount));
	
	if (isNaN(bcShirt) || bcShirt == "") 
	{
		bcShirt = 0;
	}
	priceArr.sort();
	priceArr.reverse();
	
	getTotlShritNAmt(priceCount);
	bcShirt=document.getElementById("totalShirt").value;
	
	if (bcShirt > 8)
	{
		var amt = 0; var finalDiscount = 0;
		var bcAmt = document.getElementById("Detail1.1.bc_amt").value;
		var invAmt = document.getElementById("Detail1.1.inv_amt").value;
		var totalAmt = parseFloat(bcAmt) + parseFloat(invAmt);
		var discount = Math.round((totalAmt /16).toFixed(2));
		for ( var i = 0; i < priceArr.length; i++)
		{
			amt = priceArr[i];
			if (amt > discount) 
			{
				finalDiscount = amt;
				break;
			}
		}
		if (finalDiscount <= 0) 
		{
			amt = 0;
			for ( var i = priceArr.length - 1; i >= 0; i--) 
			{
				amt = amt + parseFloat(priceArr[i]);
				finalDiscount = amt;
				if (amt > discount) 
				{
					finalDiscount = amt;
					break;
				}
			}
		}
		finalDiscount = Math.round((totalAmt-finalDiscount)/15);
			if(finalDiscount >0)
				{
				alert('Congratulations ,you have purchase 15-shirts so your discount amt ==' + Math.round(finalDiscount).toFixed(2));
				document.getElementById("Detail1.1.bc_disc_descr").value = finalDiscount.toFixed(2);
				}else
				{
					document.getElementById("Detail1.1.bc_disc_descr").value = 0.0;	
				}
	}
	else
	{
		if (!isNaN(document.getElementById("Detail1.1.bc_shirts").value)) 
		{
			if (document.getElementById("Detail1.1.bc_shirts").value != "") 
			{
				document.getElementById("Detail1.1.bc_disc_descr").value = "0.0";
			}
		}
	}
	//getTotlShritNAmt(priceCount);
	bcShirt = 0;
	priceCount = 0;
}*/

/*function getTotlShritNAmt(priceCount)
{
	var bcShirt = document.getElementById("Detail1.1.bc_shirts").value;
	var bcAmt = document.getElementById("Detail1.1.bc_amt").value;

	if (isNaN(bcShirt) || bcShirt == "") 
	{
		bcShirt = 0;
	}
	if (isNaN(bcAmt) || bcAmt == "") 
	{
		bcAmt = 0;
	}
	if(invoiceAmount>0)
	{
		document.getElementById("totalShirt").value = parseFloat(priceCount) + parseFloat(bcShirt)-totalNoOfShirt;
	} else
	{
		document.getElementById("totalShirt").value = parseFloat(priceCount) + parseFloat(bcShirt);
	}	
	document.getElementById("totalAmt").value = (parseFloat(bcAmt) + parseFloat(document .getElementById("Detail1.1.inv_amt").value)).toFixed(2)-parseFloat(invoiceAmount);
}*/


//**Added new code by sachin on 11/04/14 *\\\
/*function clearFoundItemAllFld()
{
	document.getElementById("Detail1.1.barcode").value="";
	document.getElementById("Detail1.1.item_code").value="";
	document.getElementById("Detail1.1.item_descr").value="";
	document.getElementById("Detail1.1.shirt_type").value="";
	document.getElementById("Detail1.1.size_width").value="";
	document.getElementById("Detail1.1.shade").value="";
	var count=document.getElementById("Detail1.1.counter").value;
	
	if(count==undefined)
    {
		count=0;
	}
	count=parseInt(count)+1;
	document.getElementById("Detail1.1.counter").value=count;
}*/


/*function chkValidFoundData()
{
	var itemCode=document.getElementById("Detail1.1.item_code").value;
	var shirtType=document.getElementById("Detail1.1.shirt_type").value;
	var sizeWidth=document.getElementById("Detail1.1.size_width").value;
	var shade=document.getElementById("Detail1.1.shade").value;
	var barCode=document.getElementById("Detail1.1.barcode").value;
	
	if(barCode.length>0)
	  {
		if(itemCode.length>0 && shirtType.length>0 && sizeWidth.length>0  && shade.length>0)
		{
		 document.getElementById("saveBtn").click();
		}else
		{
		 alert("Please enter valid bar code");	
		}
	  }	
}*/

//**Added new code by sachin on 21/05/14 
/*function chkValidBarCodFrPhyStk(message) 
{
	if (message.length > 0) 
	{
		var barCode=document.getElementById("Detail1.1.bar_code").value;
		var count = document.getElementById("Detail1.1.counter").value;
		if (count == undefined)
		{
			count = 0;
		}
		count = parseInt(count) + 1;
		document.getElementById("Detail1.1.counter").value = count;
		document.getElementById("Detail1.1.lst_scan_barcode").value=barCode;
		document.getElementById("Detail1.1.bar_code").value="";
		document.getElementById("Detail1.1.bar_code").focus();
		document.getElementById("Detail1.1.bar_code").select();
	}
	else 
	{
		alert("Please enter valid bar code");
	}
}*/

// **Added new code by sachin on 21/05/14 



//**Added new code by sachin on 11/04/14 *\\\

function isNumberKey(e)
{		
	var unicode = e.charCode ? e.charCode : e.keyCode;
	if ((unicode == 8) || (unicode == 9) || (unicode > 47 && unicode < 58)
		|| (unicode == 37) || (unicode == 46) || (unicode == 39)
		|| (unicode == 115) || (unicode == 121) || (unicode == 117)|| (unicode > 95 && unicode < 106)) {
	return true;
	} 
	else 
	{
		window.alert("This field accepts only Numbers");
		return false;
	}
}
