Solved

Scope of Dictionary object across multiple servers, HTTP Header??? Please help me out. I am new to ASP.

Posted on 2004-04-23
1
625 Views
Last Modified: 2007-12-19
Hi, can anybody help me out..

To access multiple servers, session value has no scope. Hence, I am using dictionary object to store session values to maintain sessions.  But as the dictionary object loses scope on click of submit to the next page, how do i refer the dictionary object in subsequent pages ??  or how do I maintain session value stored in dictionary object across multiple servers??.  please give me solutions
 
===purchaseorder3.asp====

<!-- #include file="../include/validate.asp" -->
<!-- #include file="../include/lblObjecttag.inc" -->

<!-- #include file="../SessionManager.inc" -->

<%      
If UCase(Triamun_Session("Language")) = "E" Then%>
            <!-- #include file="../include/english/PurchaseOrder3_e.inc"-->
            <!-- #include file="../include/english/Qcd1_e.inc"-->
<%      ElseIf UCase(Triamun_Session("Language")) = "G" Then%>
            <!-- #include file="../include/german/PurchaseOrder3_g.inc"-->
            <!-- #include file="../include/german/Qcd1_g.inc"-->
<%      ElseIf UCase(Triamun_Session("Language")) = "F" Then%>
            <!-- #include file="../include/french/PurchaseOrder3_f.inc"-->
            <!-- #include file="../include/french/Qcd1_f.inc"-->            
<%      End If


'-----  block to avoid caching
Response.Buffer = true
Response.AddHeader"pragma","nocache"
Response.Expires=0
Response.Addheader"expires",now

                  
' Declaration of Variables to Hold the Screen Labels
Dim lblScreenTitle, lblPurchaseOrderNumber, lblSupplier, lblSupplierCode, lblStatus, lblOrderDate, lblOrderTime
Dim lblTransmissionTime, lblDeliveryDate, lblDeliveryTime, lblModeOfPO, lblPaymentTerm, lblTransmissionDate
Dim lblModeOfTransmission, lblTotalValue, lblSalesRep, lblRemark, lblTotalNumberOfLineItems, lblSrNo, lblSelect
Dim lblSelectTitle, lblItemType, lblItemDescription, lblStockQuantity, lblMinStockQuantity, lblMaxStockQuantity
Dim lblOpenOrderQuantity, lblOrderQuantity, lblBonus, lblTotal, lblRateInCHF, lblValueOfLine
Dim lblSpecialOfferIndicator, lblCustomerIndicator, lblControlled, lblControlledTitle, lblNonMovingItem
Dim lblNonMovingItemTitle, lblDelete, lblDeleteTitle, lblSelectAllForControlled, lblUnSelectAllForControlled
Dim lblCreatedBy, lblModifiedBy, lblOn, lblSearch, lblSearchPurchaseOrder, lblSearchSupplier, lblStockQuantityTT
Dim lblMinStockQuantityTT, lblMaxStockQuantityTT, lblOpenOrderQuantityTT, lblSpecialOfferIndicatorTT, lblItemTypeTT
Dim lblDeliverySlip, lblRef, lblGo
                  

' Declaration of Variables to Hold the Labels on Buttons, Warning Messages
Dim lblFetch, lblCreate, lblModify, lblAuthorise, lblAccept, lblTransmit, lblReset, lblChangeSupplier
Dim lblPrint, lblRePrint, lblClose, lblClear, lblShortClose, lblTransmissionLog, lblPartnerDefinedData
Dim lblStatistics, lblPurchaseOrders, lblPurchaseOrder, lblDuplicateItemsTitle, lblDuplicateItemsWarning
Dim lblAddToExistingLine, lblDeleteTheDuplicateLine, lblCancel


' Declaration of Variables to get Session Values
Dim varPartnerName, varUserName, sPARTNERID, sCON, sLANGID, errObject, errFileName, varPartnerType
Dim varDaysForNonMovingItem, ACTION, varFromScreen, varPONumber, varSalesOrderNo, varStatusOfPOBeforeUpdate
Dim varPOType, varPOAmount, varPrintFlag, varRecordCreationLabel
Dim varSupplierCode, varSupplierDescription, varPOTransmissionMode, varPODeliveryDate, varPODeliveryTime
Dim varPODate, varPOTime, varPOTransmissionTime


' CCH Help Variables
Dim CCHQueryForSupplier, varQCDForCCHSupplierStatus, varComboForCCHSupplierStatus
      
' Get Session Values
Set errObject                  = Application("ErrObject")
errFileName                        = Session("FEErrMsgFile")
sPARTNERID                        = Triamun_Session("nPartnerId")
varPartnerName                  = Triamun_Session("strPartnerName")
varUserName                        = Triamun_Session("strUserName")
sCON                              = Application("strODBC")
sLANGID                              = Triamun_Session("Language")
varDaysForNonMovingItem      = Session("PRT010")                        ' No of Days for an Item to become Non-Moving
varPartnerType                  = Trim(Triamun_Session("strPartnerType"))

If varDaysForNonMovingItem = "" Then varDaysForNonMovingItem = 0

' Declaration of Array variables for PO Detail
Dim arrMultiline

' Query String Values
ACTION                                    = Trim(Request.QueryString("mode"))
varPONumber                              = Trim(Request("txtPONumber"))
varFromScreen                        = Trim(Request("mFromScreen"))
varSalesOrderNo                        = Trim(Request("mSalesOrderNo"))
varStatusOfPOBeforeUpdate      = Trim(Request.QueryString("POStatus"))
      

' Set Default Values for Screen if they are empty
If varPOType       = ""                  Then varPOType        = "M"            End If
If varPOAmount       = ""                  Then varPOAmount  = "0.00"      End If
If varPrintFlag  = ""                  Then varPrintFlag = "N"            End If


' -------------------------------------------------------------------------------------------------------------------
' Creating the Query for CCH for Supplier and encoding it
' -------------------------------------------------------------------------------------------------------------------
CCHQueryForSupplier = "SELECT CVM.Customer_Vendor_Name AS 'CVM.Customer_Vendor_Name', "
CCHQueryForSupplier = CCHQueryForSupplier & " CVM.Customer_Vendor_Code AS 'CVM.Customer_Vendor_Code', "
CCHQueryForSupplier = CCHQueryForSupplier & " ISNULL(PA.Electronic_Flag, 'M') AS 'PA.Electronic_Flag', "
CCHQueryForSupplier = CCHQueryForSupplier & " CVM.Status AS 'CVM.Status' "
CCHQueryForSupplier = CCHQueryForSupplier & " FROM IIICustomer_Vendor_Master CVM (NOLOCK), "
CCHQueryForSupplier = CCHQueryForSupplier & " IIIPurchase_Agreements PA (NOLOCK)"
CCHQueryForSupplier = CCHQueryForSupplier & " WHERE CVM.Partner_Id *= PA.Partner_Id "
CCHQueryForSupplier = CCHQueryForSupplier & " AND CVM.Customer_Vendor_Type != 'C' "
CCHQueryForSupplier = CCHQueryForSupplier & " AND CVM.Customer_Vendor_Type != 'P' "
CCHQueryForSupplier = CCHQueryForSupplier & " AND CVM.Customer_Vendor_Code *= PA.Wholesaler_Code "
CCHQueryForSupplier = CCHQueryForSupplier & " AND CVM.Partner_Id = " & sPARTNERID
CCHQueryForSupplier = Server.URLEncode(CCHQueryForSupplier)
      
' Loop for populating the Supplier status in a QCD
For cntr = 0 to UBound(arrCustVendStatus, 1)
      varQCDForCCHSupplierStatus       = varQCDForCCHSupplierStatus & "~~" & arrCustVendStatus(cntr,0) & "~" & arrCustVendStatus(cntr,1)
      varComboForCCHSupplierStatus = varComboForCCHSupplierStatus & "~~" & arrCustVendStatus(cntr,1) & "~" & arrCustVendStatus(cntr,0)
Next

varQCDForCCHSupplierStatus       = Mid(varQCDForCCHSupplierStatus, 3, Len(varQCDForCCHSupplierStatus))
varComboForCCHSupplierStatus = Mid(varComboForCCHSupplierStatus, 3, Len(varComboForCCHSupplierStatus))
' -------------------------------------------------------------------------------------------------------------------

' For diplaying Record Created/Modified By ..
varRecordCreationLabel      = lblCreatedBy & " &lt" & "" & "&gt " & lblOn & " &lt" & "" & "&gt, " & lblModifiedBy & " &lt" & "" & "&gt " & lblOn & " &lt" &  "" & "&gt"
      

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'      Fetch the Description for the First Preferred Wholesaler defined if any in the System Parameter
'      and the Transmission Mode / Delivery Date & Time for the Wholesaler if any in Purchase Agreements
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If ACTION = "" Then      Call FetchPreferredWholesalerAndDeliveryTime()
      

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'      FUNCTION TO GET THE FIRST PREFERRED WHOLESALER AND DEFAULT THE ORDER DATE/TIME & DELIVERY DATE/TIME STARTS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function FetchPreferredWholesalerAndDeliveryTime()

      varSupplierCode = Trim(Session("PRT016"))
      
      If varSupplierCode <> "" Then
      
            Dim arrParamList
            Redim arrParamList(3,3)            

            ' Input Parameter Partner_Id
            arrParamList(0,0) = "@Partner_Id"
            arrParamList(0,1) = "ANY_COUNT"
            arrParamList(0,2) = "adParamInput"
            arrParamList(0,3) = sPARTNERID
            
            ' Input Parameter Customer Vendor Code            
            arrParamList(1,0) = "@Customer_Vendor_Code"
            arrParamList(1,1) = "ANY_NAME"
            arrParamList(1,2) = "adParamInput"
            arrParamList(1,3) = varSupplierCode
            
            ' Input Parameter Language            
            arrParamList(2,0) = "Lang"
            arrParamList(2,1) = "ANY_FLAG"
            arrParamList(2,2) = "adParamInput"
            arrParamList(2,3) = sLANGID

            Set objPURCHASEORDER            = Server.CreateObject("IIIGenericDataAccess.IIIFetchGeneric")
            Set rstPURCHASEORDERHEADER      = Server.CreateObject("ADODB.RecordSet")
            Set rstPURCHASEORDERHEADER      = objPURCHASEORDER.FetchGenericDataAccessUsingSP(sCON, _
                                                                  "IIIFetch_Wholesaler_And_Delivery_Time_For_PO", arrParamList, _
                                                                  nERRORNO, strERRORMESSAGE)
                              
            strERRORMESSAGE                        = ""
            
            If CInt(nERRORNO) > 0 Then
            
                  varSupplierDescription  = rstPURCHASEORDERHEADER.fields("Customer_Vendor_Name")
                  varPOTransmissionMode      = rstPURCHASEORDERHEADER.fields("PO_Transmission_Mode")
                  varPODeliveryDate            = rstPURCHASEORDERHEADER.fields("Delivery_Date")
                  varPODeliveryTime            = rstPURCHASEORDERHEADER.fields("Delivery_Time")
                  varPODate                        = rstPURCHASEORDERHEADER.fields("Current_Date")
                  varPOTime                        = rstPURCHASEORDERHEADER.fields("Current_Time")
                  varPOTransmissionTime      = varPOTime
                        
                  rstPURCHASEORDERHEADER.Close()
                  Set rstPURCHASEORDERHEADER = Nothing
            End if
                  
            Erase arrParamList
            Set objPURCHASEORDER = Nothing
      End If
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'      FUNCTION TO GET THE FIRST PREFERRED WHOLESALER AND DEFAULT THE ORDER DATE/TIME & DELIVERY DATE/TIME ENDS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''      


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' To Get the Language Code for CCH for BASLER TAXE Items
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetDEFAULTLANGUAGECODE(strLangId)

      SELECT CASE UCase(strLangId)
            CASE  "E" : LANGUAGECODE = "0"
            CASE  "G" : LANGUAGECODE = "1"
            CASE  "F" : LANGUAGECODE = "2"
            CASE  "F" : LANGUAGECODE = "3"
      END SELECT
      
      GetDEFAULTLANGUAGECODE = LANGUAGECODE
      
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'      FUNCTION TO GET THE QCD DESCRIPTION FOR THE QCD CODE AND THE QCD NAME PASSED STARTS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''      
Function GetQCDDESCRIPTIONFORCODE(strQCDNAME, strCODE)
      Dim cntr, arrTEMP
      arrTEMP = Eval(strQCDNAME)
      For cntr = 0 To UBound(arrTEMP, 1)
            If strCODE = arrTEMP(cntr, 0) Then
                  GetQCDDESCRIPTIONFORCODE = arrTEMP(cntr, 1)
                  Exit Function
            End If
      Next
      GetQCDDESCRIPTIONFORCODE = ""
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'      FUNCTION TO GET THE QCD DESCRIPTION FOR THE QCD CODE AND THE QCD NAME PASSED ENDS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''      
      
%>

<HTML>
<HEAD>

<!-- Include JS Files -->
<LINK HREF="../include/galmenu3.css" REL="StyleSheet" TYPE="Text/css">
<SCRIPT LANGUAGE="JavaScript" SRC="../INCLUDE/GALMENU.JS"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="../INCLUDE/COMMON.JS"></SCRIPT>
<!-- <SCRIPT LANGUAGE="JavaScript" SRC="../INCLUDE/DROPDOWN.JS"></SCRIPT> -->
<SCRIPT LANGUAGE="JavaScript" SRC="../INCLUDE/INTERFACES.JS"></SCRIPT>
<SCRIPT LANGUAGE="javascript" SRC="../INCLUDE/MULTILINEGRID.JS"></SCRIPT>

<STYLE type="text/css">
      #divPurchaseOrder
      {
            BEHAVIOR: url("../include/FPGRID.htc")
      }
</STYLE>

<!-- Client Side Script -->
<SCRIPT LANGUAGE="javascript">

      var cntOUTOFSALEITEM      = 0;                   //Counter for Out of sale Item ;      A Global variable set to check On_Authorise() method is called
      var objPODetailsXMLDOM      = null;
      var objPURCHASEORDER      = null;      
      var strACTION                  = "";
      var strPOModeArray            = ""
      var strItemHelpEnterRow      = 0
      
      // --------- Get all PO types in a string for later manupulation ---------/
      <% For nCtr=0 to Ubound(POMode)-1 %>
            strPOModeArray = strPOModeArray + "<%= POMode(nCtr,0) &"~~"& POMode(nCtr,1) &"~~~~"%>"      
      <% Next %>
      
      // --------------------- Display the screen Title -----------------------/
      window.parent.document.title = "Triamun " + "<%=lblScreenTitle%>" + " " + "<%=varPartnerName%>";
      <%if varFromScreen = "" then%>
            parent.frmMenu.writeit("<%=lblScreenTitle%>");
      <%end if%>
      
      
      /*************************************************************************************************************
            CODE FOR ITEM DROPDOWN STARTS
      **************************************************************************************************************/
      /*
      var List1                        = new Array()
      var List1_FixedLength      = 50
      var foc1 = 0
      var LocalFileFlag1            = true
      var LocalFileFlag2            = false
      var LocalFileName            = "c:\\iii\\" + "<%=sPARTNERID%>" + "\\" + "<%=sLANGID%>" + "_FUI.txt"
      var strItemHelpEnterRow      = 0


      /*************************************************************
            Function to know cursor current location for Dropdown
      **************************************************************/      
      /*function On_SetFocusValueForItemInMultiline(intRowNumber, chrItemOrPatient, fldItemDescription, fldListBox)
      {
            var strItemType = document.frmPurchaseOrder.cboItemType[intRowNumber].value
            
            if (strItemType == "I")
            {
                  DDQfoc(intRowNumber, chrItemOrPatient, fldItemDescription, fldListBox);
                  foc2 = intRowNumber;
                  return;
            }
      }*/
      
      /********************************************************************
            Function to fire when an Item is chosen from the Dropdown list
      *********************************************************************/      
      /*function On_SelectionOfAnItemInFUIDropDown(intIndexChosen)
      {
            docfrm = document.frmPurchaseOrder
            if(intIndexChosen == 1)
            {
                  if(!LocalFileFlag1)      return
                  
                  var fldListBox                  = docfrm.SearchList                        // Reference to the Listbox Object showing Dropdown
                  var fldItemDescription      = docfrm.mItemDescription[foc1] // Reference to the Object where dropdown is to be shown
            
                  if (fldListBox.value == "vv")
                  {
                        loadListOnEOL(fldItemDescription, fldListBox, intIndexChosen)
                        fldItemDescription.focus()
                        return
                  }
                  else if(fldListBox.value == "^^")
                  {
                        loadListOnBOL(fldItemDescription, fldListBox, intIndexChosen)
                        fldItemDescription.focus()
                        return
                  }
                  
                  fldItemDescription.value = fldListBox.options[fldListBox.selectedIndex].text

                  var strListValue             = fldListBox.options[fldListBox.selectedIndex].value
                  var arrDropDown                   = strListValue.split('~')
                                    
                  document.frmPurchaseOrder.mItemCode[foc1].value                  = arrDropDown[0]
                  
                  if ( document.frmPurchaseOrder.mItemCode[foc1].value != "")
                        GetItemDetailsOnHelpEnter("REGULARTABLE","document.frmPurchaseOrder","mItemDescription,mItemCode,mStockQuantity,mMinStockQuantity,mMaxStockQuantity,mOpenOrderQuantity","2,1,7,16,17,22",document.frmPurchaseOrder.mItemCode[foc1].value,foc1,"hidOnFetchItemDetails~onchange")
            
                  fldItemDescription.focus();
            }
      }*/

      /***************************************
            Loads the Local File on Body Load
      ****************************************/
      /*function On_LoadFUIFileOnBodyLoad()
      {
            DDFileload(LocalFileName, "document.frmPurchaseOrder.SearchList", 1)
      }*/
      
      /*************************************************************************************************************
            CODE FOR ITEM DROPDOWN ENDS
      **************************************************************************************************************/

      var strColumnPassed   = ""
      var strFocusIsOn        = ""
      var intPOStatus              = ""
      var strFromScreen        = "<%=varFromScreen%>"
      var langid                    = "<%=sLANGID%>"
      var intCurrentLine        = ""
      var winReport              = ""      
      
      /**********************************************************
            function to set the focus value to validate on submit
      ***********************************************************/
      function On_SetFocusValue(strValue, intRowNumber)
      {
            strFocusIsOn      = strValue
            intCurrentLine      = intRowNumber
      }
      
      /*****************************************
            Function to launch CCH For PO Number
      ******************************************/
      function HelpForPONumber()
      {
            var strFileName = "help.asp?HELP_ID=59&FilterValues=txtPONumber"
            launchhelp1(strFileName);
      }

      /*****************************************
            Function to launch CCH for Supplier
      ******************************************/
      function HelpForSupplier()
      {
            var strFileName = "help.asp?From=document.frmPurchaseOrder&fields=txtSupplierDescription,txtSupplierCode,cboModeOfTransmission&Query=<%=CCHQueryForSupplier%>&Filters=CVM.Customer_Vendor_Name,CVM.Customer_Vendor_Code,CVM.Status&FiltercolName=<%=lblSupplier%>,<%=lblSupplierCode%>,<%=lblStatus%>&Datatype=c,c,c,c&DisplayName=<%=lblSupplier%>,<%=lblSupplierCode%>,<%=lblModeOfTransmission%>,<%=lblStatus%>&Database=Partner&OrderByCols=CVM.Customer_Vendor_Name,CVM.Customer_Vendor_Code,CVM.Status&FilterLength=40,40,10&QCD=0,0,<%=varQCDForCCHTransmissionMode%>,<%=varQCDForCCHSupplierStatus%>&Combo=0,0,<%=varComboForCCHSupplierStatus%>&FilterValues=txtSupplierDescription&Title=<%=lblSearchSupplier%>"
            launchhelp1(strFileName);
      }

      /**************************************
            Funtion to launch different CCH
      ***************************************/
      function On_LaunchHelpLocal(strFileName, strWindowName)
      {
            var winHelp
            winHelp = window.open(strFileName, strWindowName, 'menubar=no,location=no,toolbar=no,resizable=yes,scrollbars=yes,top=80,left=0,width=1020,height=600')
            winHelp.focus()
      }      
      
      /***********************************
            Funtion to compare two dates
      ************************************/      
      function On_CompareTwoDateTimeFields(fldFromDate, fldToDate, fldFromTime, fldToTime, intValidationFlag)
      {
            var arrDate1 = (fldFromDate.value).toString().split(".")
            var arrDate2 = (fldToDate.value).toString().split(".")
            var arrTime1 = GetTimeValue(fldFromTime).toString().split(":")
            var arrTime2 = GetTimeValue(fldToTime).toString().split(":")
      
            var dtFirstDate  = new Date(arrDate1[2], arrDate1[1]-1, arrDate1[0], arrTime1[0], arrTime1[1])
            var dtSecondDate = new Date(arrDate2[2], arrDate2[1]-1, arrDate2[0], arrTime2[0], arrTime2[1])
            
            // Compare Date and Time
            if (dtFirstDate.getTime() > dtSecondDate.getTime()) return false
            else return true
      }      

      /***********************************************************      
         Function to provide Help on enter for Item Description
      ************************************************************/
      function On_HelpOnEnterForItems(intRowNumber, nItemDescColIndex, strItemType, strItemEANCode)
      {
      
            var strFieldsList            = ""
            var strItemHelpQuery      = ""
            var strLanguageCode            = ""
            strItemHelpEnterRow            = intRowNumber
      
            /** This is not to allow ' qoute in Help enter **/
            var strRegExp = /[']/ig;
            if (strRegExp.test(strItemEANCode))
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,305)%>", "<%=lblItemTypeTT%>")
                  objPURCHASEORDER.focus();
                  objPURCHASEORDER.SetActiveCell(nItemDescColIndex, intRowNumber)
                  return false;
            }
            
            if (strItemType == "I")
            {
                  //CR006 - 116 -- added by Sriram
                  var      strItemLaunchHelp = "";
                  var strFields = "";
                  var strFields_Help = "";

                  if (strItemEANCode.length <= 7) strItemEANCode = strItemEANCode.replace(/^0+/,"")

                  //Get the Column Index of required columns needs to be passed to the Item Search
                  strFields      += divPurchaseOrder.getColIndex("sprHIDDENITEMCODE").toString() + "," ;
                  strFields      += divPurchaseOrder.getColIndex("sprITEMDESCRIPTION").toString() + "," ;
                  strFields      += divPurchaseOrder.getColIndex("sprSTOCKQUANTITY").toString() + "," ;
                  strFields      += divPurchaseOrder.getColIndex("sprMINSTOCKQUANTITY").toString() + "," ;
                  strFields      += divPurchaseOrder.getColIndex("sprMAXSTOCKQUANTITY").toString() + "," ;
                  strFields      += divPurchaseOrder.getColIndex("sprOPENORDERQUANTITY").toString()

                  strFields_Help      += divPurchaseOrder.getColIndex("sprHIDDENITEMCODE").toString() + "," ;
                  strFields_Help      += divPurchaseOrder.getColIndex("sprITEMDESCRIPTION").toString() + ",,,,,,,,,," ;
                  strFields_Help      += divPurchaseOrder.getColIndex("sprSTOCKQUANTITY").toString() + ",,," ;
                  strFields_Help      += divPurchaseOrder.getColIndex("sprITEMTYPE").toString() + ",," ;
                  strFields_Help      += divPurchaseOrder.getColIndex("sprMINSTOCKQUANTITY").toString() + "," ;
                  strFields_Help      += divPurchaseOrder.getColIndex("sprMAXSTOCKQUANTITY").toString() + ",,,,,,," ;
                  strFields_Help      += divPurchaseOrder.getColIndex("sprOPENORDERQUANTITY").toString()

                  strItemLaunchHelp = "ITEMSEARCH.ASP?From=objPURCHASEORDER&StartText="+ intRowNumber +"&Fields="+ strFields_Help +"&ItemType=I"
                  
                  On_ChangeItemDescription(intRowNumber)
                  GetItemDetailsOnHelpEnter("GRID","objPURCHASEORDER",strFields,"1,2,7,16,17,22",strItemEANCode,intRowNumber,"hidOnFetchItemDetails~onchange","","","","","","",strItemLaunchHelp)
            }
            else
            {
                  // Get the language code for the logged in language
                  if(langid == 'E')
                        strLanguageCode = "0"
                  else if(langid == 'F')
                        strLanguageCode = "2"
                  else if(langid == 'G')
                        strLanguageCode = "1"
                  else if(langid == 'I')
                        strLanguageCode = "3"
                        
                  strFieldsList = "sprITEMDESCRIPTION,sprHIDDENITEMCODE,sprSTOCKQUANTITY,sprMINSTOCKQUANTITY,sprMAXSTOCKQUANTITY,sprOPENORDERQUANTITY,sprRATEINCHF"
                  
                  strItemHelpQuery += " SELECT Description, BaslerTaxeKey, 0, 0, 0, 0, DBO.IIIRoundPrice(0.00) "
                  strItemHelpQuery += " FROM IIIBasler_Taxe (NOLOCK) "
                  strItemHelpQuery += " WHERE BaslerTaxeKey = '" + strItemEANCode + "'"
                  strItemHelpQuery += " AND Language_Code = '" + strLanguageCode + "'"
                  
                  launchhelpEnter("HELPENTER.ASP?From=divPurchaseOrder&RowNo=" + intRowNumber + "&Grid=GRIDXML&fields=" + strFieldsList + "&Query=" + strItemHelpQuery + "&Database=Universal&QCD=0,0,0,0,0,0,0");
            }
            On_BlurCalculateTotals(intRowNumber)
      }
      

      /************************************************
            Function to provide CCH For Galdat Items/Chemicals
      *************************************************/      
      function HelpForItemOrChemical(intRowNumber)
      {
            var strFileName = ""
            var strFields      = ""
            var strItemType = divPurchaseOrder.getCellValue("sprITEMTYPE",intRowNumber);
            
            // If the Type selected is Item
            if (strItemType == "I")
            {
                  //Get the Column Index of required columns needs to be passed to the Item Search
                  strFields      += divPurchaseOrder.getColIndex("sprHIDDENITEMCODE").toString() + "," ;
                  strFields      += divPurchaseOrder.getColIndex("sprITEMDESCRIPTION").toString() + ",,,,,,,,,," ;
                  strFields      += divPurchaseOrder.getColIndex("sprSTOCKQUANTITY").toString() + ",,," ;
                  strFields      += divPurchaseOrder.getColIndex("sprITEMTYPE").toString() + ",," ;
                  strFields      += divPurchaseOrder.getColIndex("sprMINSTOCKQUANTITY").toString() + "," ;
                  strFields      += divPurchaseOrder.getColIndex("sprMAXSTOCKQUANTITY").toString() + ",,,,,,," ;
                  strFields      += divPurchaseOrder.getColIndex("sprOPENORDERQUANTITY").toString()
            
                  strFileName = "ITEMSEARCH.ASP?From=objPURCHASEORDER&StartText="+ intRowNumber +"&Fields="+ strFields +"&ItemType=I"
                  launchhelp1(strFileName);
            }
            else if (strItemType == "B")
            {
                  strFileName = "help.asp?HELP_ID=54&StartText=" + intRowNumber + "&FilterValues=sprITEMDESCRIPTION,sprHIDDENLANGUAGECODE,,sprHIDDENITEMCODE"
                  launchhelp1(strFileName);
            }
      }

      /**********************************************************************************************
            Function to fire on click of Clear Button - Goes to the BE and fetches default values
      ***********************************************************************************************/
      function On_Clear()
      {
            Allowupdate = true;
            strACTION = ""
            strFocusIsOn = "";
            On_CallXMLHTTPAfterValidations("FETCHDEFAULTVALUES");
      }
      

      /*********************************************************************
            Function to fire on click of Select/Unselect Controlled checkbox
      **********************************************************************/      
      function On_CheckUnCheckAllControlledCheckBoxes()
      {
            var intRowNo            = 0;
            var nRowLength            = 0;
            var rstPOMLDetails      = null;
            var objNodeList            = null;
            var blnControlled      = document.frmPurchaseOrder.chkSelectAllForControlled.checked
            
            // If the option is unchecked/checked just uncheck all the rows of controlled column
            var objPOGrid            = eval(divPurchaseOrder.getGridRef());
            var nColIndex            = divPurchaseOrder.getColIndex("sprCONTROLLED");
            Set_Value_For_Range(objPOGrid, 1, objPOGrid.MaxRows, nColIndex, "0")
            
            if(blnControlled == false)
            {
                  lblCheckUncheckControlled.innerHTML = "<%=lblSelectAllForControlled%>"
                  return false;
            }
            else
            {
                  lblCheckUncheckControlled.innerHTML = "<%=lblUnSelectAllForControlled%>"
            }
                  
            divPurchaseOrder.filters = "";
            divPurchaseOrder.filters = "@sprDELETE = '1' or @sprITEMDESCRIPTION = ''";
            
            var objPOMLDOM      = divPurchaseOrder.getXMLString();
            
            // Return if there is no rows..
            if ( objPOMLDOM == null ) return false;
            
            rstPOMLDetails      = objPOMLDOM.selectNodes("//row");
            nRowLength            = rstPOMLDetails.length
            
            if (nRowLength == 0) return false;
                  
            objNodeList = rstPOMLDetails.nextNode;
            while(objNodeList != null)
            {
                  // Get the row no from the XML node
                  intRowNo = objNodeList.getAttribute("ROWUID");
                  
                  //Check the controlled checkbox
                  divPurchaseOrder.setCellValue("sprCONTROLLED",intRowNo,"1")
                  objNodeList = rstPOMLDetails.nextNode;
            }
            
            objPOMLDOM      = null
            objNodeList      = null
            rstPOMLDetails      = null
      }


      /**************************************************
            Function to fire on click of Fetch button
      ***************************************************/      
      function On_Fetch()
      {
            if (document.frmPurchaseOrder.txtPONumber.value == "")
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,337)%>","<%=lblPurchaseOrderNumber%>")
                  document.frmPurchaseOrder.txtPONumber.focus();
                  return false
            }
            
            On_CallXMLHTTPAfterValidations("FETCH");
            strFocusIsOn = "";
            return false;
      }
      
      
      /************************************************************
            Function to call XML HTTP Submit based on the Mode
      *************************************************************/
      function On_CallXMLHTTPAfterValidations(strMODE)
      {
            
            //-------- From the required value as XMLDOMObject-----------------//
            var objXMLPOSTED      = StoreValuesAsXMLDOMObject(strMODE)
            var strRETURNRESULT = GetOutputXMLUSINGXMLHTTP("SERVER_PURCHASEORDER3.asp", "", objXMLPOSTED)
            
            //--------- Load the Result XML into an DOMObject -----------------//
            var objRESULTXML      = new ActiveXObject("Microsoft.XMLDOM");
            objRESULTXML.loadXML(strRETURNRESULT)
            
                        
            if (objRESULTXML.selectSingleNode("//ErrorNo").text > 0)
            {
                  // strAction/Mode is globally strored once if the screen throws success message
                  strACTION            = strMODE
                  divPurchaseOrder.ClearAll();
                  
                  //If the mode is delete and fetchdefault then only the header value is binded
                  if( (strMODE == 'DELETEPURCHASEORDER') || (strMODE == 'FETCHDEFAULTVALUES') )
                  {
                        objHdrXMLDom      = divPurchaseOrder.loadXMLStringHdr(objRESULTXML.selectSingleNode("//POHEADER/root").xml);
                        fnSetValuesOnSuccess('CLEAR', '')
                        SetDefaults('CLEAR');
                  }
                  else
                  {
                        objHdrXMLDom      = divPurchaseOrder.loadXMLStringHdr(objRESULTXML.selectSingleNode("//POHEADER/root").xml);
                        objMLXMLDom            = divPurchaseOrder.loadXMLString(objRESULTXML.selectSingleNode("//POMLDETAILS/root").xml);
                        fnSetValuesOnSuccess('SET', objHdrXMLDom);
                        SetDefaults('SET');
                        
                  }
                        
                  // Display the success error message
                  if( (objRESULTXML.selectSingleNode("//ErrorMessage").text != "") && (strMODE != 'FETCH') )
                        alert(objRESULTXML.selectSingleNode("//ErrorMessage").text.replace(/\\n/ig, "\n"))
            }
            else
            {
                  strACTION = ""
                  if(strMODE == 'FETCH')
                  {
                        divPurchaseOrder.ClearAll();
                        //document.frmPurchaseOrder.reset();
                        fnSetValuesOnSuccess('CLEAR', '');
                        SetDefaults('CLEAR');
                  }
                  
                  /** PO Containing PDI Item(s) cannot be authorised **/
                  if (objRESULTXML.selectSingleNode("//ErrorNo").text == -1)
                  {      
                        ItemDescriptionforPDI = GetItemDescriptionforPDI()
                        IIIalert("<%=errObject.getnthdescription(errFileName,1536)%>", ItemDescriptionforPDI)
                  }                                    
                  else
                  {
                        // Display the failed error message
                        alert(objRESULTXML.selectSingleNode("//ErrorMessage").text)
                  }
            }      
            
            objRESULTXML      = null;
            objXMLPOSTED      = null;
            objHdrXMLDom      = null;
            objMLXMLDom            = null;
            return false;
      }
      
      
      /***************************************************************
            Function to set default on success on success of any Action
      ***************************************************************/
      function fnSetValuesOnSuccess(strFlag, objHdrXMLDom)
      {
            var strCreatedOnDtls = ""
            if (objHdrXMLDom == null) return false;
            
            // Set defaults..
            if(strFlag == 'SET')
            {
                  var strCreatedBy      = objHdrXMLDom.selectSingleNode("//row").getAttribute("Created_By")
                  var strCreatedOn      = objHdrXMLDom.selectSingleNode("//row").getAttribute("Created_On")
                  var strModifiedBy      = objHdrXMLDom.selectSingleNode("//row").getAttribute("Modified_By")
                  var strModifiedOn      = objHdrXMLDom.selectSingleNode("//row").getAttribute("Modified_On")

                  strCreatedOnDtls            = "<%=lblCreatedBy%>" + " <" + strCreatedBy + "> " + "<%=lblOn%>" + " <" + strCreatedOn + ">, " + "<%=lblModifiedBy%>" + " <" + strModifiedBy + "> " + "<%=lblOn%>" + " <" + strModifiedOn + ">"
                  IDCreatedOn.innerText      = strCreatedOnDtls
            }
            else
            {
                  IDCreatedOn.innerHTML = "<%=varRecordCreationLabel%>"
            }
            
            //Clear the Selct all label and uncheck the combo..
            document.frmPurchaseOrder.chkSelectAllForControlled.checked = false;
            lblCheckUncheckControlled.innerHTML = "<%=lblSelectAllForControlled%>";
      }
      
      
      /*******************************************************************************************************************
            Function to store PO Header and detail values into a XMLDOM Object and the object is returned fro HTTP postings
      ********************************************************************************************************************/
      function StoreValuesAsXMLDOMObject(strMode)
      {
            var objDOMCLIENTSIDE      = new ActiveXObject("Microsoft.XMLDOM")
            var frmPurchaseOrder      = document.frmPurchaseOrder
            var strCSXML                  = ""
            var strHDRDetails            = ""
            var strMLDetails            = ""
            var objHeaderDOM            = null;
            var objPOMLDOM                  = null;
            
            
            //If the mode is just Fetch/Header Uypdate then only the required header info alone is passed to the server..
            if( (strMode == 'FETCH') || (strMode == 'TRANSMITPURCHASEORDERFETCH') || (strMode == 'TRANSMITPURCHASEORDERUPDATE') || (strMode == 'DELETEPURCHASEORDER') || (strMode == 'PRINTPURCHASEORDER') || (strMode == 'SHORTCLOSEPO') || (strMode == 'MODIFYTRANSMISSIONMODE') || (strMode == 'FETCHDEFAULTVALUES') )
            {
                  objHeaderDOM = divPurchaseOrder.getXMLStringHdr();
                  if (objHeaderDOM != null)
                        strHDRDetails = objHeaderDOM.xml;
            }
            else
            {
                  objHeaderDOM = divPurchaseOrder.getXMLStringHdr();
                  if (objHeaderDOM != null)
                        strHDRDetails = objHeaderDOM.xml;
                  
            
                  //--------- ML Detail is taken from the global object which is stored when Create/Modify action validation succeed
                  if (objPODetailsXMLDOM != null)      
                  {
                        strMLDetails = objPODetailsXMLDOM.xml
                  }
                  else
                  {      
                        objPOMLDOM            = divPurchaseOrder.getXMLString();
                        if (objPOMLDOM != null)      
                              strMLDetails = objPOMLDOM.xml
                  }
            }      
            
            
            //CLEAR THE OBJECT
            objPOMLDOM                  = null;
            objHeaderDOM            = null;
            objPODetailsXMLDOM      = null;
            
            
            /** Load the PO Header and PO MLData into the XMLDOM **/      
            strCSXML += "<XMLHTTPPurchaseOrder>"
            strCSXML += "<MODE>" + strMode + "</MODE>"
            strCSXML += "<NONMOVINGITEMLABEL>" + "<%=lblNonMovingItem%>" + "</NONMOVINGITEMLABEL>"
            strCSXML += "<DECIDERFLAG>" + strMode + "</DECIDERFLAG>"
            strCSXML += "<HEADERDETAILFETCHFLAG></HEADERDETAILFETCHFLAG>"
            strCSXML += "<POHEADER>" + strHDRDetails + "</POHEADER>"
            strCSXML += "<POMLDETAILS>" + strMLDetails + "</POMLDETAILS>"
            strCSXML += "<ErrorNo></ErrorNo>"
            strCSXML += "<ErrorMessage></ErrorMessage>"
            strCSXML += "</XMLHTTPPurchaseOrder>"
      
            objDOMCLIENTSIDE.loadXML(strCSXML);
            return objDOMCLIENTSIDE;
      }
      
      
      /******************************************************************************
            Function for validation of mandatory fields (Header Fields)
      *******************************************************************************/
      function On_ValidateMandatoryFields(strFieldName, strFieldLabel)
      {
            if (Trim(eval("document.frmPurchaseOrder." + strFieldName).value.toString()) == "")
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,335)%>", strFieldLabel)
                  eval("document.frmPurchaseOrder." + strFieldName).focus()
                  return false;
            }
            return true;
      }
      
      
      /******************************************************************************
            Function for validation of mandatory fields (PO ML Fields)
      *******************************************************************************/
      function On_ValidateMandatoryFieldsGrid(strColValue, strColName, nRow, strColLabel)
      {
            var nCol = ""
            
            if (strColValue == "")
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,335)%>", strColLabel)
                  nCol = divPurchaseOrder.getColIndex(strColName)
                  objPURCHASEORDER.focus();
                  objPURCHASEORDER.SetActiveCell(nCol, nRow)
                  return false;
            }
            return true;
      }
      
      
      /***************************************************
            Function for Validation for Valid Characters
      ****************************************************/      
      function On_ValidateCharSet(strControlName, strFieldLabel)
      {
            if (!isvalidCharSet(Trim(strControlName.value)))
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,305)%>", strFieldLabel)
                  strControlName.focus()
                  return false
            }
            return true
      }
      
      /**********************************************************************************
            Function to Validate That Number Fields should have greater than Zero Value
      ***********************************************************************************/      
      function On_ValidateNumberGreaterThanZero(strColValue, strColName, nRow, strColLabel)
      {
            var nCol = ""
            
            if (parseFloat(Trim(strColValue)) == "")
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,504)%>", strColLabel)
                  nCol = divPurchaseOrder.getColIndex(strColName)
                  objPURCHASEORDER.focus();
                  objPURCHASEORDER.SetActiveCell(nCol, nRow)
                  return false;
            }
            return true;
      }
      
      /*****************************************************************
            Function to show Modal Windows for Warnings to the User
      ******************************************************************/
      function On_ShowModalWindow(arrMsgs, arrBtns, height, width)
      {
            var arrLabels            = new Array(2);
            var strReturnValue      = ""
            
            arrLabels[0] = arrMsgs;
            arrLabels[1] = arrBtns;
            arrLabels[2] = "scrButton"      
            strReturnValue = window.showModalDialog("IIIMsgBox.asp", arrLabels, "center=yes;dialogWidth=" + width + ";dialogHeight=" + height + ";help:no;status:no")
            return strReturnValue;
      }      
      
      /************************************
            General Form Validation Routine
      *************************************/
      function Validate()
      {
            
            document.frmPurchaseOrder.mNoOfLinesManual.value      = 0
            document.frmPurchaseOrder.mNoOfLinesAutomatic.value = 0
            document.frmPurchaseOrder.mNoOfLinesCustomer.value      = 0

            /** Validating Charset **/
            if (!On_ValidateCharSet(document.frmPurchaseOrder.txtSupplierDescription, "<%=lblSupplier%>")) return false
            if (!On_ValidateCharSet(document.frmPurchaseOrder.txtSalesRep, "<%=lblSalesRep%>")) return false
            
            /** Validating Dates and Time Fields **/
            if (!validateDate(document.frmPurchaseOrder.txtOrderDate, "<%=lblOrderDate%>")) return false
            if (Trim(document.frmPurchaseOrder.txtTransmissionDate.value) != "") if (!validateDate(document.frmPurchaseOrder.txtTransmissionDate, "<%=lblTransmissionDate%>")) return false
            if (!validateDate(document.frmPurchaseOrder.txtDeliveryDate, "<%=lblDeliveryDate%>")) return false
            
            /** Validating Mandatory Fields **/
            if (!On_ValidateMandatoryFields('txtSupplierDescription', "<%=lblSupplier%>")) return false
            if (!On_ValidateMandatoryFields('txtOrderDate',"<%=lblOrderDate%>")) return false
            if (!On_ValidateMandatoryFields('txtDeliveryDate', "<%=lblDeliveryDate%>")) return false
            if (!On_ValidateMandatoryFields('cboModeOfTransmission', "<%=lblModeOfTransmission%>")) return false
            
            /** Validating that Order Date should not be a future Date **/
            var arrPODate            = (document.frmPurchaseOrder.txtOrderDate.value).toString().split(".")
            var arrPOTime            = GetTimeValue(document.frmPurchaseOrder.txtOrderTime).toString().split(":")
            var dtCurrentDate      = new Date()
            var dtPODateTime      = new Date(arrPODate[2], arrPODate[1]-1, arrPODate[0])                  
            
            if (dtPODateTime.getTime() > dtCurrentDate.getTime())
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,969)%>", "<%=lblOrderDate%>");
                  return false
            }
            
            /** Validating that Remarks should contain only a maximum of 500 chars **/
            if (parseFloat(Trim(document.frmPurchaseOrder.txtRemarks.value).length) > 500)
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,1124)%>".replace(/%/,"<%=lblRemark%>"), 500)
                  document.frmPurchaseOrder.txtRemarks.focus();
                  return false            
            }      
      
            /** Validation that Order Date is lesser than Transmission Date
                  and that Transmission Date is lesser than Delivery Date **/
            if (document.frmPurchaseOrder.txtTransmissionDate.value != "")      
            {
                  if (!On_CompareTwoDateTimeFields(document.frmPurchaseOrder.txtOrderDate, document.frmPurchaseOrder.txtTransmissionDate, document.frmPurchaseOrder.txtOrderTime, document.frmPurchaseOrder.txtTransmissionTime, 2))
                  {
                        alert("<%=errObject.getnthdescription(errFileName,575)%>")
                        return false
                  }
                  if (!On_CompareTwoDateTimeFields(document.frmPurchaseOrder.txtTransmissionDate, document.frmPurchaseOrder.txtDeliveryDate, document.frmPurchaseOrder.txtTransmissionTime, document.frmPurchaseOrder.txtDeliveryTime, 2))
                  {
                        alert("<%=errObject.getnthdescription(errFileName,577)%>")
                        return false
                  }
            }
            else
            {
                  if (!On_CompareTwoDateTimeFields(document.frmPurchaseOrder.txtOrderDate, document.frmPurchaseOrder.txtDeliveryDate, document.frmPurchaseOrder.txtOrderTime, document.frmPurchaseOrder.txtDeliveryTime, 2))
                  {
                        alert("<%=errObject.getnthdescription(errFileName,576)%>")
                        return false
                  }
            }

            // ----------------- Multiline Validation starts ------------------------------------------//
            
            /** To check that atleast one row exists in Multiline **/
            var intRowNo            = 0;
            var nRowLength            = 0;
            var rstPOMLDetails      = null;
            var objNodeList            = null;
            var objXMLDOC            = null;
            var strIemDesc, nLineDeleted, strPOCustomerDtls;

            divPurchaseOrder.filters = "";
            divPurchaseOrder.filters = "@sprITEMDESCRIPTION = '' or @sprDELETE = '1'";
            
            var objPOMLDOM      = divPurchaseOrder.getXMLString();
            
            // Return if there is no rows..
            if ( objPOMLDOM == null ) return false;
            
            rstPOMLDetails      = objPOMLDOM.selectNodes("//row");
            nRowLength            = rstPOMLDetails.length
            
            if (nRowLength == 0)
            {
                  alert("<%=errObject.getnthdescription(errFileName,320)%>");
                  return false;
            }
                  
            objNodeList = rstPOMLDetails.nextNode;
            
            var nOrderQuantity = "", nBonus = "", nRateInCHF = "", nCol = "", dblTotalPOValue = "0";
            var nLineTotal = "", strLineType = "", NoOfLinesManual = "0", NoOfLinesAutomatic = "0", NoOfLinesCustomer = "0";
            var nReturnedRow = "", nReturnedRow_Temp = "";
            var nItemDescColIndex = divPurchaseOrder.getColIndex("sprITEMDESCRIPTION")
            
            while(objNodeList != null)
            {
                  // Get all required values from the XML Node
                  intRowNo                  = objNodeList.getAttribute("ROWUID");
                  strIemDesc                  = Trim(objNodeList.getAttribute("sprITEMDESCRIPTION"));
                  nLineDeleted            = objNodeList.getAttribute("sprDELETE");
                  nOrderQuantity            = objNodeList.getAttribute("sprORDERQUANTITY");
                  nBonus                        = objNodeList.getAttribute("sprBONUS");
                  nRateInCHF                  = objNodeList.getAttribute("sprRATEINCHF");
                  nLineTotal                  = objNodeList.getAttribute("sprTOTALAMOUNT");
                  nReturnedRow            = 0
                  nReturnedRow_Temp      = intRowNo
                  
                  //Out of sale Item Check
                  if ((objNodeList.getAttribute('sprHIDDENITEMFLAG')== 'OUTOFSALEITEM'))      cntOUTOFSALEITEM++;
                  
                  // ------ To check that Duplicate Items should not exist in Purchase Order Multiline -----------
                  if ( (nLineDeleted != "1") && (strIemDesc != "") )
                  {
                  
                        //Check for the duplicate rows until the searchcol returns "-1"..
                        while(nReturnedRow != -1)
                        {
                              nReturnedRow = objPURCHASEORDER.SearchCol(nItemDescColIndex, nReturnedRow_Temp, objPURCHASEORDER.DataRowCnt, strIemDesc, 0)
                  
                              // Check if the duplicate row found is deleted or not, if yes return
                              if (nReturnedRow != -1)
                              {
                                    nLineDeleted_TEMP      = divPurchaseOrder.getCellValue("sprDELETE",nReturnedRow)
                                    nReturnedRow_Temp      = nReturnedRow
                              }
                                    
                              if (nReturnedRow != -1 && nLineDeleted_TEMP != '1')
                              {
                                    var arrMessages            = new Array()
                                    var arrButtons            = new Array()
                                    var arrReturnValue      = new Array()
                                    
                                    arrMessages[0]      = "Triamun " + "<%=lblDuplicateItemsTitle%>" + " " + "<%=UCase(varPartnerName)%>";
                                    arrMessages[1]      = "<%=lblDuplicateItemsWarning%>".replace(/%/,(intRowNo) + ", " + nReturnedRow)
                        
                                    arrButtons[0]      = "<%=lblAddToExistingLine%>"
                                    arrButtons[1]      = "<%=lblDeleteTheDuplicateLine%>"
                                    arrButtons[2]      = "<%=lblCancel%>"
                                    
                                    arrReturnValue      = On_ShowModalWindow(arrMessages, arrButtons, "130pt", "440pt");
                                          
                                    /** Add the New Line to Existing Line **/
                                    if (arrReturnValue[1] == 0)
                                    {
                                          /************************************************************************************
                                                Add the Order Quantity and Bonus in New Line to Existing Line Order Quantity
                                                and Bonus. Mark the New Line for Delete
                                          ************************************************************************************/
                                          var nQtyInEL      = divPurchaseOrder.getCellValue("sprORDERQUANTITY",intRowNo)==''?0:divPurchaseOrder.getCellValue("sprORDERQUANTITY",intRowNo)
                                          var nBonusInEL      = divPurchaseOrder.getCellValue("sprBONUS",intRowNo)==''?0:divPurchaseOrder.getCellValue("sprBONUS",intRowNo)
                                          var nQtyInNL      = divPurchaseOrder.getCellValue("sprORDERQUANTITY",nReturnedRow)==''?0:divPurchaseOrder.getCellValue("sprORDERQUANTITY",nReturnedRow)
                                          var nBonusInNL      = divPurchaseOrder.getCellValue("sprBONUS",nReturnedRow)==''?0:divPurchaseOrder.getCellValue("sprBONUS",nReturnedRow)
                                          
                                          divPurchaseOrder.setCellValue("sprORDERQUANTITY",intRowNo,parseFloat(nQtyInEL) + parseFloat(nQtyInNL))
                                          divPurchaseOrder.setCellValue("sprBONUS",intRowNo,parseFloat(nBonusInEL) + parseFloat(nBonusInNL))
                                          divPurchaseOrder.setCellValue("sprDELETE",nReturnedRow,"1")
                                          On_BlurCalculateTotals(intRowNo)
                                    }
                                    /** Remove the New Line **/
                                    else if (arrReturnValue[1] == 1)
                                    {
                                          divPurchaseOrder.setCellValue("sprDELETE",nReturnedRow,"1")
                                    }
                                    else if (arrReturnValue[1] == 2)
                                    {
                                          return false;
                                    }
                              }
                        }
                  }      
                  
                  
                  // --- Validate mandatory and proper values only if the item desc is not empty and line not marked as delete
                  if ( (nLineDeleted != "1") && (strIemDesc != "") )
                  {
                        /** Validation for Numeric Values **/
                        if (Trim(nOrderQuantity) != "" && IsQty(nOrderQuantity, "<%=lblOrderQuantity%>") == false) return false
                        if (Trim(nBonus) != "" && IsQty(nBonus, "<%=lblBonus%>") == false) return false
                        if (Trim(nRateInCHF) != "" && IsPrice(nRateInCHF, "<%=lblRateInCHF%>") == false) return false      
                        
                        
                        /** Validation for Mandatory Fields **/
                        if (!On_ValidateMandatoryFieldsGrid(nOrderQuantity, "sprORDERQUANTITY", intRowNo, "<%=lblOrderQuantity%>")) return false
                        if (!On_ValidateNumberGreaterThanZero(nOrderQuantity, "sprORDERQUANTITY", intRowNo, "<%=lblOrderQuantity%>")) return false
                        
                        
                        var dblOrderQuantity_Temp       = Trim(nOrderQuantity)==""?0:Trim(nOrderQuantity)
                        var dblBonus_Temp                  = Trim(nBonus)==""?0:Trim(nBonus)
                        var dblRateInCHF_Temp            = Trim(nRateInCHF)==""?0:Trim(nRateInCHF)
                        
                        // Calculating Line Level Totals
                        var dblTotal = RoundQty(parseFloat(dblOrderQuantity_Temp) + parseFloat(dblBonus_Temp))                              
                        // changed for TRIMAUNIII1.0S_015016
                        if (dblTotal.toString().length > "<%=MAXLENGTHFORQUANTITY%>")
                        {
                              alert("<%=errObject.getnthdescription(errFileName,1058)%>");
                              nCol = divPurchaseOrder.getColIndex("sprORDERQUANTITY")
                              divPurchaseOrder.setFocus(nCol, intRowNo)
                              return false;
                        }
                        
                        /** Setting Rate and Bonus Values to Zero if they are empty **/
                        if (Trim(nRateInCHF) == "")
                              divPurchaseOrder.setCellValue("sprRATEINCHF",intRowNo,dblRateInCHF_Temp)
                              
                        if (Trim(nBonus) == "")
                               divPurchaseOrder.setCellValue("sprBONUS",intRowNo,dblBonus_Temp)
                        
                        /** Calculate Line Totals and Grand Total **/
                        On_BlurCalculateTotals(intRowNo)
                  }
            
                  objNodeList = rstPOMLDetails.nextNode;
            }
            
            // --------- Store the Customer PO details alone into a seperate element to avoid special character ------- //
            objPOMLDOM            = null
            objNodeList            = null
            rstPOMLDetails      = null
            objXMLDOC            = new ActiveXObject("Microsoft.XMLDOM");
            
            // Get all the rows after filter from the ML
            divPurchaseOrder.filters = "";
            divPurchaseOrder.filters = "@sprITEMDESCRIPTION = ''";
            var objPOMLDOM      = divPurchaseOrder.getXMLString();
            
            rstPOMLDetails      = objPOMLDOM.selectNodes("//row");
            objNodeList = rstPOMLDetails.nextNode;
            
            while(objNodeList != null)
            {
                  nLineTotal                  = objNodeList.getAttribute("sprTOTALAMOUNT");
                  strLineType                  = objNodeList.getAttribute("sprHIDDENLINETYPE");
                  nLineDeleted            = objNodeList.getAttribute("sprDELETE");
                  strPOCustomerDtls      = objNodeList.getAttributeNode("sprHIDDENCUSTOMERREFERENCES");
                  
                  if(nLineDeleted != '1')
                  {
                        //Calculate the Total of All PO Lines
                        dblTotalPOValue = RoundAmt(parseFloat(dblTotalPOValue) + parseFloat(nLineTotal), "Y")
                  
                        /** Calculating No. of Rows per Line Type **/
                        if (strLineType.toUpperCase() == "M" || strLineType == "")
                              NoOfLinesManual =  parseFloat(NoOfLinesManual) + 1
                        else if (strLineType.toUpperCase() == "A")
                              NoOfLinesAutomatic =  parseFloat(NoOfLinesAutomatic) + 1
                        else if (strLineType.toUpperCase() == "C")
                              NoOfLinesCustomer =  parseFloat(NoOfLinesCustomer) + 1
                  }      
                  
                  
                  if ( strPOCustomerDtls.value != "" )
                  {
                        var newElement = objPOMLDOM.createElement("sprHIDDENCUSTOMERREFERENCES");
                        objXMLDOC.loadXML(unescape(strPOCustomerDtls.value));
                              
                        var ChildNode = objXMLDOC.selectSingleNode("root");
                        if (ChildNode != null)
                        {
                              objNodeList.appendChild(ChildNode);
                        }
                  }
                  
                  objNodeList.removeAttribute("sprHIDDENCUSTOMERREFERENCES");
                  objNodeList = rstPOMLDetails.nextNode;
            }
            
            //Total Value of PO and Total lines are calculated and Assigned..
            
            if (dblTotalPOValue.toString().length > 20)
            {
                  alert("<%=errObject.getnthdescription(errFileName,572)%>");
                  return false
            }
            
            document.frmPurchaseOrder.txtTotalValue.value            = Round(dblTotalPOValue,2)
            document.frmPurchaseOrder.mNoOfLinesManual.value      = NoOfLinesManual
            document.frmPurchaseOrder.mNoOfLinesAutomatic.value      = NoOfLinesAutomatic
            document.frmPurchaseOrder.mNoOfLinesCustomer.value      = NoOfLinesCustomer
            
            
            //assign the converted XML DOM object to a global object..
            objPODetailsXMLDOM      = objPOMLDOM
            objPOMLDOM                  = null
            objNodeList                  = null
            rstPOMLDetails            = null
            
            return true;
      }
      

      /***************************************************************************************************
            Function to calculate PO Total on Change of Lines (Like Delete/Undelete, clearing a Line etc)
      ****************************************************************************************************/
      function On_CalculateTotalValue(intRowNumber, strAddOrSubtractFlag)
      {
            On_BlurCalculateTotals(intRowNumber)
            
            var dblTotalPOValue        = document.frmPurchaseOrder.txtTotalValue.value
            var dblTotalLineValue = divPurchaseOrder.getCellValue("sprTOTALAMOUNT",intRowNumber)
            
            if (isNaN(dblTotalPOValue) || dblTotalPOValue == "")            dblTotalPOValue = 0
            if (isNaN(dblTotalLineValue) || dblTotalLineValue == "")      dblTotalLineValue = 0
            
            if (parseFloat(dblTotalPOValue) != 0)
            {
                  if (strAddOrSubtractFlag == "PLUS")                  dblTotalPOValue = parseFloat(dblTotalPOValue) + parseFloat(dblTotalLineValue)
                  else if (strAddOrSubtractFlag == "MINUS")      dblTotalPOValue = parseFloat(dblTotalPOValue) - parseFloat(dblTotalLineValue)
            }
            document.frmPurchaseOrder.txtTotalValue.value = RoundAmt(dblTotalPOValue, "Y")
      }
      
      /**************************************************
            Function to Calculate form totals on blur
      ***************************************************/      
      function On_BlurCalculateTotals(intRowNumber)
      {
            var dblTotalPOValue            = Trim(document.frmPurchaseOrder.txtTotalValue.value)
            var dblValueOfLine            = divPurchaseOrder.getCellValue("sprTOTALAMOUNT",intRowNumber)
            var dblOrderQuantity      = divPurchaseOrder.getCellValue("sprORDERQUANTITY",intRowNumber)
            var dblBonus                  = divPurchaseOrder.getCellValue("sprBONUS",intRowNumber)
            var dblRateInCHF            = divPurchaseOrder.getCellValue("sprRATEINCHF",intRowNumber)
            var strDelFlag                  = divPurchaseOrder.getCellValue("sprDELETE",intRowNumber)
            
            if (dblValueOfLine == "")      dblValueOfLine = 0
            if (dblTotalPOValue == "")      dblTotalPOValue = 0
            if (dblOrderQuantity == "")      dblOrderQuantity = 0
            if (dblBonus == "")                  dblBonus = 0
            if (dblRateInCHF == "")            dblRateInCHF = 0
            
            // If the line is not marked for deletion, then calculate the total..
            if (strDelFlag != "1")
            {
                  // Calculating Line Level Totals
                  var dblTotalQty = RoundQty(parseFloat(dblOrderQuantity) + parseFloat(dblBonus))
                  var dblTotalAmt      = RoundAmt(dblOrderQuantity * dblRateInCHF, "Y")
                  
                  // Setting the Line Totals in the appropriate columns
                  divPurchaseOrder.setCellValue("sprTOTALQTY",intRowNumber,dblTotalQty)
                  divPurchaseOrder.setCellValue("sprTOTALAMOUNT",intRowNumber, dblTotalAmt)
                  
                  dblTotalPOValue = RoundAmt(parseFloat(dblTotalPOValue) - parseFloat(dblValueOfLine) + parseFloat(dblTotalAmt), "Y")
                  
                  if (dblTotalPOValue.toString().length > 20)
                  {
                        alert("<%=errObject.getnthdescription(errFileName,572)%>");
                        divPurchaseOrder.setFocus("sprRATEINCHF",intRowNumber)
                        return false
                  }
                  document.frmPurchaseOrder.txtTotalValue.value = dblTotalPOValue
            }
      }

      /******************************************************************
            Function to clear fields when Supplier Description is changed
      *******************************************************************/      
      function On_ClearSupplierCode()
      {
            document.frmPurchaseOrder.txtSupplierCode.value = ""
      }
      
      /**************************************************************
            Function to clear fields when Item Description is changed
      ***************************************************************/
      function On_ChangeItemDescription(intRowNumber)
      {
            On_CalculateTotalValue(intRowNumber, "MINUS")

            //Clear all columns of that line..
            divPurchaseOrder.setCellValue("sprHIDDENITEMCODE",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprSTOCKQUANTITY",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprMINSTOCKQUANTITY",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprMAXSTOCKQUANTITY",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprOPENORDERQUANTITY",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprORDERQUANTITY",intRowNumber,"")
            
            divPurchaseOrder.setCellValue("sprBONUS",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprTOTALQTY",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprRATEINCHF",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprTOTALAMOUNT",intRowNumber,"")
            
            divPurchaseOrder.setCellValue("sprDELQTY",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprPENDQTY",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprNONMOVINGITEM",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprCONTROLLED",intRowNumber,"0")
            
            divPurchaseOrder.setCellValue("sprHIDDENCUSTOMERREFERENCES",intRowNumber,"")
            divPurchaseOrder.setCellValue("sprTOTALAMOUNT",intRowNumber,"")
            
            var nColIndex      = divPurchaseOrder.getColIndex("sprREFERENCE");
            Set_Button_Color(objPURCHASEORDER, intRowNumber, nColIndex, "NORMAL")
            
            var nItemDescColIndex = divPurchaseOrder.getColIndex("sprITEMDESCRIPTION")
            var nItemFlagColIndex = divPurchaseOrder.getColIndex("sprHIDDENITEMFLAG")
            ResetItemColour("GRID","objPURCHASEORDER",nItemDescColIndex,intRowNumber,nItemFlagColIndex)
      }      

      /**************************************************
            Function to fire on click of Create button
      ***************************************************/      
      function On_Create()
      {
            // If the focus is on PO Number and enter key is fired..
            if (strFocusIsOn ==      "txtPONumber")
            {
                  On_Fetch();
                  return false
            }
            else if (strFocusIsOn == "txtSupplierDescription")
            {
                  var strVendor      = document.frmPurchaseOrder.txtSupplierDescription.value
                  launchhelpEnter("HELPENTER.ASP?HELP_ID=107&ValuesForBESearch=" + strVendor + "&HelpScreenHelp_Id=186")
                  return false;
            }            
            else if (strFocusIsOn == "txtOrderDate")
            {
                  On_EnterKeyInOrderDate()
                  return false
            }
            
            if (!Validate()) return false

            if (Trim(document.frmPurchaseOrder.txtPONumber.value) != "")
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,306)%>","<%=lblPurchaseOrder%>")
                  document.frmPurchaseOrder.txtPONumber.focus()
                  return false
            }
            
            document.frmPurchaseOrder.cboModeOfTransmission.disabled = false
            On_CallXMLHTTPAfterValidations("INSERTPURCHASEORDER");
            return false;
      }
      
      /***********************************************************************
            To Default Delivery Date as per Time Rules defined for Wholesaler
      ************************************************************************/
      function On_EnterKeyInOrderDate()
      {
            if (!validateDate(document.frmPurchaseOrder.txtOrderDate, "<%=lblOrderDate%>")) return false
            
            if (Trim(document.frmPurchaseOrder.txtSupplierDescription.value) == "") return false
            if (Trim(document.frmPurchaseOrder.txtOrderDate.value) == "")                  return false

            var strSupplier                  = document.frmPurchaseOrder.txtSupplierDescription.value
            var strOrderDate            = document.frmPurchaseOrder.txtOrderDate.value
            var arrWeekDays                  = new Array("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT")
            var dtOrderDate                  = new Date(strOrderDate.substring(6,10), (parseFloat(strOrderDate.substring(3,5)) - 1) , strOrderDate.substring(0,2))
            var strOrderDay                  = arrWeekDays[dtOrderDate.getDay()]
            var strOrderTime            = GetTimeValue(document.frmPurchaseOrder.txtOrderTime)
            var intBitNoInString      = 0
            var strQuery                  = ""
            var strFieldsList            = "txtDeliveryDate,hidDeliveryTime"
            
            if (dtOrderDate.getDay() == "0")      intBitNoInString = 7
            else                                                intBitNoInString = dtOrderDate.getDay()
            
            strQuery += " SELECT CONVERT(NVARCHAR(10), DATEADD(DD, CONVERT(INT, SUBSTRING(Delivery_Day_String, " + intBitNoInString + ",1)),CONVERT(DATETIME,'" + strOrderDate + "',104)), 104) "
            strQuery += " ,Delivery_Time FROM        IIITime_Rules_Detail (NOLOCK) "
            strQuery += " WHERE       Partner_Id = '<%=sPARTNERID%>' "
            strQuery += " AND Vendor_Code = (SELECT TOP 1 Vendor_Code FROM IIICustomer_Vendor_Master (NOLOCK) WHERE Partner_Id = '<%=sPARTNERID%>' AND Customer_Vendor_Name ='" + document.frmPurchaseOrder.txtSupplierDescription.value + "')"
            strQuery += " AND Order_Option IN('" + strOrderDay + "','WD') "
            strQuery += " AND CONVERT(INT, SUBSTRING(Order_Day_String, " + intBitNoInString + ",1)) = '1' "
            strQuery += " AND CONVERT(DATETIME, Order_Time, 108) = "
            strQuery += " (      SELECT MIN(CONVERT(DATETIME, Order_Time, 108)) "
            strQuery += "        FROM IIITime_Rules_Detail TRD (NOLOCK) INNER JOIN IIICustomer_Vendor_Master CVM (NOLOCK) "
            strQuery += "        ON TRD.Partner_Id = CVM.Partner_id AND TRD.Vendor_Code = CVM.Customer_Vendor_Code AND CVM.Customer_Vendor_Name = '" + document.frmPurchaseOrder.txtSupplierDescription.value + "' "
            strQuery += "        AND CVM.Customer_Vendor_Type <> 'C' AND CONVERT(DATETIME, Order_Time, 108) >= CONVERT(DATETIME, '" + strOrderTime + "', 108))"
            
            launchhelpEnter("HelpEnter.asp?From=document.frmPurchaseOrder&fields=" + strFieldsList  + "&Query=" + strQuery + "&FieldAndEvent=hidDeliveryTime~onchange&Database=Partner&QCD=0,0");
      }

      /**************************************************
            Function to fire on click of Modify button
      ***************************************************/
      function On_Modify()
      {
            var strSUBMITMODE                        = ""
            var blnTRANSMISSIONMODEDISABLED = document.frmPurchaseOrder.cboModeOfTransmission.disabled
            var strTRANSMISSIONMODE                  = Trim(divPurchaseOrder.getCellValue("PO_Transmission_Mode"))
            intPOStatus                                    = Trim(divPurchaseOrder.getCellValue("PO_Status"))
            
            // Validate if PO Status is empty
            if (intPOStatus == "")
            {
                  alert("<%=errObject.getnthdescription(errFileName,639)%>")
                  return false
            }
            
            /** PO Number cannot be empty **/
            if (!On_ValidateMandatoryFields('txtPONumber', "<%=lblPurchaseOrderNumber%>")) return false

            /*******************************************************************************************************************
                  Allow Modification only
                  1.      If PO Status is OPEN
                  2.      If PO Status is AUTHORISED and Transmission Mode is Manual
                  3.      If PO Status is AUTHORISED and Transmission Mode is Manual
            ********************************************************************************************************************/
            //if (intPOStatus != "2" && !((intPOStatus == "3" || intPOStatus == "6") && blnTRANSMISSIONMODEDISABLED == false))
            //if (intPOStatus != "2" && !((intPOStatus == "3" || intPOStatus == "6") && strTRANSMISSIONMODE == "M"))
            if (intPOStatus != "2" && intPOStatus != "3" && intPOStatus != "6")
            {
                  alert("<%=errObject.getnthdescription(errFileName,1425)%>")
                  return false
            }
            
            
            if (intPOStatus != "2" && ((intPOStatus == "3" || intPOStatus == "6") && Allowupdate == false))
            {
                  alert("<%=errObject.getnthdescription(errFileName,1425)%>")
                  return false
            }
            else
            {
                  if (intPOStatus == "2")      strSUBMITMODE = "MODIFYPURCHASEORDER"
                  else                              strSUBMITMODE = "MODIFYTRANSMISSIONMODE"
                  
                  /** If PO is Authorised or Failed, allow Update of Transmission Mode only if it is MANUAL **/
                  if ( (intPOStatus == "3" || intPOStatus == "6") && strTRANSMISSIONMODE != "M" )
                  {
                        alert("<%=errObject.getnthdescription(errFileName,1475)%>");
                        return false
                  }
                  else /** Common Validation Procedure if PO Status is Open **/
                  {
                        if (!Validate()) return false
                  }
            }
            
            document.frmPurchaseOrder.cboModeOfTransmission.disabled = false
            On_CallXMLHTTPAfterValidations(strSUBMITMODE);
            return false;
      }
      

      /**************************************************
            Function to fire on click of Authorise button
      ***************************************************/
      function On_Authorise()
      {
            intPOStatus            = Trim(divPurchaseOrder.getCellValue("PO_Status"))
      
            // Validate if PO Status is empty
            if (intPOStatus == "")
            {
                  alert("<%=errObject.getnthdescription(errFileName,639)%>")
                  return false
            }      
            // Validate that only open purchase orders can be modified
            if (intPOStatus != "2")
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,309)%>", "<%=lblPurchaseOrders%>")
                  return false
            }

            /** PO Number cannot be empty **/
            if (!On_ValidateMandatoryFields('txtPONumber', "<%=lblPurchaseOrderNumber%>")) return false
                        
            // Global Variable for Out of sale item is set to to zero before validate method
            cntOUTOFSALEITEM      = 0;      
            
            // General Validation for full form controls
            if (!Validate()) return false
            
            // Out of Sale Item check
            if (cntOUTOFSALEITEM > 0 )
            {
                  if (!confirm("<%=errObject.getnthdescription(errFileName,1595)%>")) return false;
            }      
            
            document.frmPurchaseOrder.cboModeOfTransmission.disabled = false
            On_CallXMLHTTPAfterValidations("AUTHORISEPURCHASEORDER");
            return false;
      }
      
      /**************************************************
            Function to fire on click of transmit button
      ***************************************************/      
      function On_Transmit()
      {
            intPOStatus                        = Trim(divPurchaseOrder.getCellValue("PO_Status"))
            var PONumber                  = Trim(divPurchaseOrder.getCellValue("PO_Number"))
            var PDIExists                  = Trim(divPurchaseOrder.getCellValue("PDI_EXISTS"))
            var strTRANSMISSIONMODE      = Trim(divPurchaseOrder.getCellValue("PO_Transmission_Mode"))
            
            // Validate if PO Status is empty
            if (intPOStatus == "")
            {
                  alert("<%=errObject.getnthdescription(errFileName,639)%>")
                  return false
            }      
            // Validate that only authorised purchase orders can be transmitted
            if (intPOStatus != "3" && intPOStatus != "6")
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,573)%>", "<%=lblPurchaseOrders%>")
                  return false
            }
            
            /** PO Number cannot be empty **/
            if (!On_ValidateMandatoryFields('txtPONumber', "<%=lblPurchaseOrderNumber%>")) return false
            
            
            // Only PO's where transmission mode is Automatic can be Transmitted. Else it should be printed
            if (strTRANSMISSIONMODE != "A")
            {
                  alert("<%=errObject.getnthdescription(errFileName,874)%>")
                  return false
            }      
      
            
            //Begin : Interface 002:PO Transmission - Venki
            if(! validateforV50("<%=Session("ClientParams")%>"))
            {
                  return false
            }
            //End : Interface 002:PO Transmission - Venki
            
            /** PO Containing PDI Item cannot be transmitted **/
            if (PDIExists == 1)
            {      
                  ItemDescriptionforPDI = GetItemDescriptionforPDI()
                  //IIIalert("<%=errObject.getnthdescription(errFileName,1508)%>", PONumber)
                  IIIalert("<%=errObject.getnthdescription(errFileName,1508)%>", ItemDescriptionforPDI)
                  return false            
            }
            
            document.frmPurchaseOrder.cboModeOfTransmission.disabled = false
            On_CallXMLHTTPAfterValidations("TRANSMITPURCHASEORDERFETCH");
            return false;
      }      
      
      function GetItemDescriptionforPDI()
      {
            var LineItemDesc = ""
            var LineItemCode = ""
            var AllItemDesc = '\n' + '\n' + "<%=lblLineNo&"  "&lblItemDescription%>" + '\n' + "------  -----------------"
            
            divPurchaseOrder.filters = "";
            divPurchaseOrder.filters = "@sprITEMDESCRIPTION = '' or @sprDELETE = '1'";
            
            var objPOMLDOM      = divPurchaseOrder.getXMLString();
            
            // Return if there is no rows..
            if ( objPOMLDOM == null ) return false;
            
            rstPOMLDetails      = objPOMLDOM.selectNodes("//row");
            nRowLength            = rstPOMLDetails.length
            
            if (nRowLength == 0) return false;
                  
            objNodeList = rstPOMLDetails.nextNode;
            while(objNodeList != null)
            {
                  // Get the Item Code from the XML node
                  intRowNo            = objNodeList.getAttribute("ROWUID");
                  LineItemDesc      = objNodeList.getAttribute("sprITEMDESCRIPTION");
                  LineItemCode      = objNodeList.getAttribute("sprHIDDENITEMCODE");
                  
                  if (LineItemCode.substring(0, 3).toUpperCase() == "PDI")
                  {
                        AllItemDesc = AllItemDesc +'\n'+ (intRowNo) +"           "+ LineItemDesc
                  }
                  
                  objNodeList = rstPOMLDetails.nextNode;
            }
            
            objPOMLDOM      = null
            objNodeList      = null
            rstPOMLDetails      = null
            
            AllItemDesc = AllItemDesc + '\n' + '\n'
            return AllItemDesc
      }
      
      
      
      /***********************************************
            Function to fire on click of print button
      ************************************************/      
      function On_Print()
      {
            intPOStatus                        = Trim(divPurchaseOrder.getCellValue("PO_Status"))
            var strTRANSMISSIONMODE      = Trim(divPurchaseOrder.getCellValue("PO_Transmission_Mode"))
            var strPrintFlag            = Trim(divPurchaseOrder.getCellValue("Print_Flag"))
            
            // Validate if PO Status is empty
            if (intPOStatus == "")
            {
                  alert("<%=errObject.getnthdescription(errFileName,639)%>")
                  return false
            }

            // Validate that only authorised purchase orders can be printed
            if (intPOStatus == "2")
            {
                  alert("<%=errObject.getnthdescription(errFileName,1416)%>")
                  return false
            }
            
            /** PO Number cannot be empty **/
            if (!On_ValidateMandatoryFields('txtPONumber', "<%=lblPurchaseOrderNumber%>")) return false            

            /** Purchase Order is already Printed **/
            if (strTRANSMISSIONMODE == "M")
            {
                  if (Trim(strPrintFlag) != "Y")
                  {
                        document.frmPurchaseOrder.cboModeOfTransmission.disabled = false
                        On_CallXMLHTTPAfterValidations("PRINTPURCHASEORDER");
                        return false;
                  }
                  else
                  {
                        On_PrintReports()
                        return false
                  }
            }
            else
            {
                  On_PrintReports()
                  return false
            }
      }
      
      /************************************************
            Function to fire on click of Delete button
      *************************************************/      
      function On_Delete()
      {
            intPOStatus            = Trim(divPurchaseOrder.getCellValue("PO_Status"))
            
            // Validate if PO Status is empty
            if (intPOStatus == "")
            {
                  alert("<%=errObject.getnthdescription(errFileName,639)%>")
                  return false
            }
            if ( intPOStatus != "1" && intPOStatus != "2" )
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,310)%>", "<%=lblPurchaseOrders%>")
                  return false
            }
            
            /** PO Number cannot be empty **/
            if (!On_ValidateMandatoryFields('txtPONumber', "<%=lblPurchaseOrderNumber%>")) return false            
            
            /** Delete confirmation **/
            var msg = "<%=errObject.getnthdescription(errFileName,265)%>"
            if ( !window.confirm(msg) )      return;
            
            
            document.frmPurchaseOrder.cboModeOfTransmission.disabled = false
            On_CallXMLHTTPAfterValidations("DELETEPURCHASEORDER");
            return false;
      }
      

      /*****************************************************
            Function to fire on click of Short Close button
      ******************************************************/            
      function On_ShortClose()
      {
            intPOStatus      = Trim(divPurchaseOrder.getCellValue("PO_Status"))
      
            // Validate if PO Status is empty
            if (intPOStatus == "")
            {
                  alert("<%=errObject.getnthdescription(errFileName,639)%>")
                  return false
            }
            else if (intPOStatus == "2")
            {
                  alert("<%=errObject.getnthdescription(errFileName,1050)%>")
                  return false
            }
            else if (intPOStatus == "10")
            {
                  alert("<%=errObject.getnthdescription(errFileName,1051)%>")
                  return false
            }
            
            /** PO Number cannot be empty **/
            if (!On_ValidateMandatoryFields('txtPONumber', "<%=lblPurchaseOrderNumber%>")) return false            
            
            document.frmPurchaseOrder.cboModeOfTransmission.disabled = false
            On_CallXMLHTTPAfterValidations("SHORTCLOSEPO");
            return false;
      }


      /********************************************************
            Function to fire on click of Change Supplier Button
      *********************************************************/      
      function On_ChangeSupplier()
      {
            intPOStatus      = Trim(divPurchaseOrder.getCellValue("PO_Status"))
            
            if ( "<%=GetAccessPermission("ORDEROVERVIEWITEM3","FETCH")%>"  == "DISABLED" )
            {
                  IIIalert("<%=ErrObject.getnthDescription(ErrFileName,469)%>"," - <%=lblChangeSupplier%>")
                  return false;
            }
            
            // Validate if PO Status is empty
            if (intPOStatus == "")
            {
                  alert("<%=errObject.getnthdescription(errFileName,639)%>")
                  return false
            }
            // PO Number should be entered in order to navigate to Change Supplier Screen
            if (!On_ValidateMandatoryFields('txtPONumber', "<%=lblPurchaseOrderNumber%>")) return false

            // Validate that only for open PO's supplier can be changed
            if (intPOStatus != "2")
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,307)%>", "<%=lblPurchaseOrders%>")
                  return false
            }
            var strFileName = "OrderOverviewItem3.asp?From=PURCHASEORDER3&mode=FETCH&Order1=Vendor_Description&Order2=PO_Item_Description&Order3=PO_Number&PONUMBER=" + document.frmPurchaseOrder.txtPONumber.value
            On_LaunchHelpLocal(strFileName, "ORDEROVERVIEWITEM3")
      }
      
      /*****************************************************
            Function to fire on click of Item Price Button
      ******************************************************/      
      function On_ItemPrice()
      {
            if ( "<%=GetAccessPermission("ItemPrice","FETCH")%>"  == "DISABLED" )
            {
                  IIIalert("<%=ErrObject.getnthDescription(ErrFileName,469)%>"," - <%=lblItemPrice%>")
                  return false;
            }
                  
            // Set the defaults value
            var rowNode                                    = null
            var strItemCode                              = ""
            var intRowsInMultiline                  = ""
            var strItemCode                              = ""
            var strItemType                              = ""
            var blnAtleastOneRowIsChecked      = false
            var blnChemicalsChecked                  = false

      
            // Filter selected items having non empty item desc and Item type as item
            divPurchaseOrder.filters = "";
            divPurchaseOrder.filters = "@sprSEL != '1' or @sprITEMTYPE = '' or @sprITEMDESCRIPTION = ''";
            var objPOMLDetails = divPurchaseOrder.getXMLString();
            
            
            // If the ML object returns null then make the row as zero
            if ( objPOMLDetails == null )
                  intRowsInMultiline      = 0
            else
            {
                  var objMLRows = objPOMLDetails.selectNodes("//row");
                  intRowsInMultiline      = objMLRows.length
            }
            
            
            // Loop through the ML and get check for the proper value before calling statistics
            rowNode = objMLRows.nextNode;
            while(rowNode != null)
            {
                  strItemCode      = rowNode.getAttribute("sprHIDDENITEMCODE");
                  strItemType      = rowNode.getAttribute("sprITEMTYPE");
                  intRowCount      = rowNode.getAttribute("ROWUID");
                  
                  if(strItemType == "I")
                  {
                        blnAtleastOneRowIsChecked = true
                        blnChemicalsChecked              = false
                  
                        if (strItemCode == "")
                        {
                              IIIalert("<%=errObject.getnthdescription(errFileName,1057)%>", intRowCount);
                              //The Item in line number % does not have a matching Item Code. Please enter a valid Item or choose from the Help available (91057)
                              return false;
                        }
                        else //Launch the statistics screen
                        {
                              var strFileName = "ITEMPRICE.ASP?SCREENLAUNCH=yes&FROM=PURCHASEORDER3&ACTION=fetch&FIRST=N&WHOLENAMECODE3="+"<%=Trim(Session("PRT018"))%>"+"&TXTPHARMACODE="+strItemCode
                              On_LaunchHelpLocal(strFileName, "ITEMPRICE")
                              break;
                        }
                  }
                  else if (strItemType == "B")
                  {
                        blnAtleastOneRowIsChecked      = true
                        blnChemicalsChecked                  = true
                  }      
                  
                  rowNode = objMLRows.nextNode;
            }
            
      
            /** Select Atleast One Row to launch Item Statistics **/
            if (!blnAtleastOneRowIsChecked)
            {
                  alert("<%=errObject.getnthdescription(errFileName,63)%>")
                  return false
            }
            /** Chemicals cannot be used for launching Item Statistics Screen **/
            if (blnChemicalsChecked)
            {
                  alert("<%=errObject.getnthdescription(errFileName,1285)%>")
                  return false
            }
      }
      
      /**************************************************************
            Function to fire on click of Partner Defined Data Button
      ***************************************************************/
      function On_PartnerDefinedData()
      {
            if ( "<%=GetAccessPermission("PARTNERDEFINEDDATA3","FETCH")%>"  == "DISABLED" )
            {
                  IIIalert("<%=ErrObject.getnthDescription(ErrFileName,469)%>"," - <%=lblPartnerDefinedData%>")
                  return false;
            }
                  
            // Set the defaults value
            var rowNode                                    = null
            var strItemCode                              = ""
            var intRowsInMultiline                  = ""
            var strItemCode                              = ""
            var strItemType                              = ""
            var blnAtleastOneRowIsChecked      = false
            var blnChemicalsChecked                  = false

      
            // Filter selected items having non empty item desc and Item type as item
            divPurchaseOrder.filters = "";
            divPurchaseOrder.filters = "@sprSEL != '1' or @sprITEMTYPE = '' or @sprITEMDESCRIPTION = ''";
            var objPOMLDetails = divPurchaseOrder.getXMLString();
            
            
            // If the ML object returns null then make the row as zero
            if ( objPOMLDetails == null )
                  intRowsInMultiline      = 0
            else
            {
                  var objMLRows = objPOMLDetails.selectNodes("//row");
                  intRowsInMultiline      = objMLRows.length
            }
            
            
            // Loop through the ML and get check for the proper value before calling statistics
            rowNode = objMLRows.nextNode;
            while(rowNode != null)
            {
                  strItemCode      = rowNode.getAttribute("sprHIDDENITEMCODE");
                  strItemType      = rowNode.getAttribute("sprITEMTYPE");
                  intRowCount      = rowNode.getAttribute("ROWUID");
                  
                  if(strItemType == "I")
                  {
                        blnAtleastOneRowIsChecked = true
                        blnChemicalsChecked              = false
                  
                        if (strItemCode == "")
                        {
                              IIIalert("<%=errObject.getnthdescription(errFileName,1057)%>", intRowCount);
                              //The Item in line number % does not have a matching Item Code. Please enter a valid Item or choose from the Help available (91057)
                              return false;
                        }
                        else //Launch the statistics screen
                        {
                              var strFileName = "PartnerDefinedData3.ASP?FROM=PURCHASEORDER&MODE=fetch&PHARMACODE=" + strItemCode
                              On_LaunchHelpLocal(strFileName, "PARTNERDEFINEDDATA3")
                              break;
                        }
                  }
                  else if (strItemType == "B")
                  {
                        blnAtleastOneRowIsChecked      = true
                        blnChemicalsChecked                  = true
                  }      
                  
                  rowNode = objMLRows.nextNode;
            }
            
      
            /** Select Atleast One Row to launch Item Statistics **/
            if (!blnAtleastOneRowIsChecked)
            {
                  alert("<%=errObject.getnthdescription(errFileName,63)%>")
                  return false
            }
            /** Chemicals cannot be used for launching Item Statistics Screen **/
            if (blnChemicalsChecked)
            {
                  alert("<%=errObject.getnthdescription(errFileName,1285)%>")
                  return false
            }
      }
      
      /**********************************************************
            Function to fire on click of Transmission Log Button
      ***********************************************************/      
      function On_TransmissionLog()
      {
            intPOStatus            = Trim(divPurchaseOrder.getCellValue("PO_Status"))
            
            if ( "<%=GetAccessPermission("TRANSMISSIONLOG3","FETCH")%>"  == "DISABLED" )
            {
                  IIIalert("<%=ErrObject.getnthDescription(ErrFileName,469)%>"," - <%=lblTransmissionLog%>")
                  return false;
            }
            
            /** Validate if PO Status is empty **/
            if (intPOStatus == "")
            {
                  alert("<%=errObject.getnthdescription(errFileName,639)%>")
                  document.frmPurchaseOrder.txtPONumber.focus();
                  return false
            }
            
            /** PO Number should be entered in order to navigate to Transmission Log Screen **/
            if (!On_ValidateMandatoryFields('txtPONumber', "<%=lblPurchaseOrderNumber%>")) return false
            
            /** Validate that only for Automatic Transmitted PO's Transmission Log can be launched **/
            if (intPOStatus != "4")
            {
                  alert("<%=errObject.getnthdescription(errFileName,1254)%>")
                  return false
            }
            
            var strPONumber      = document.frmPurchaseOrder.txtPONumber.value      
            var strFileName = "TRANSMISSIONLOG3.ASP?FROMSCREEN=PURCHASEORDER&txtPONumber=" + strPONumber + "&mode=FETCH"
            On_LaunchHelpLocal(strFileName, "TRANSMISSIONLOG3")
      }
      
      /**********************************************************
            Function to fire on click of Item Statistics Button
      ***********************************************************/      
      function On_ItemStatistics()
      {
            if ( "<%=GetAccessPermission("DETAILOVERVIEW","FETCH")%>"  == "DISABLED" )
            {
                  IIIalert("<%=ErrObject.getnthDescription(ErrFileName,469)%>"," - <%=lblStatistics%>")
                  return false;
            }

            // Set the defaults value
            var rowNode                                    = null
            var strItemCode                              = ""
            var intRowsInMultiline                  = ""
            var strItemCode                              = ""
            var strItemType                              = ""
            var blnAtleastOneRowIsChecked      = false
            var blnChemicalsChecked                  = false

      
            // Filter selected items having non empty item desc and Item type as item
            divPurchaseOrder.filters = "";
            divPurchaseOrder.filters = "@sprSEL != '1' or @sprITEMTYPE = '' or @sprITEMDESCRIPTION = ''";
            var objPOMLDetails = divPurchaseOrder.getXMLString();
            
            
            // If the ML object returns null then make the row as zero
            if ( objPOMLDetails == null )
                  intRowsInMultiline      = 0
            else
            {
                  var objMLRows = objPOMLDetails.selectNodes("//row");
                  intRowsInMultiline      = objMLRows.length
            }
            
            
            // Loop through the ML and get check for the proper value before calling statistics
            rowNode = objMLRows.nextNode;
            while(rowNode != null)
            {
                  strItemCode      = rowNode.getAttribute("sprHIDDENITEMCODE");
                  strItemType      = rowNode.getAttribute("sprITEMTYPE");
                  intRowCount      = rowNode.getAttribute("ROWUID");
                  
                  if(strItemType == "I")
                  {
                        blnAtleastOneRowIsChecked = true
                        blnChemicalsChecked              = false
                  
                        if (strItemCode == "")
                        {
                              IIIalert("<%=errObject.getnthdescription(errFileName,1057)%>", intRowCount);
                              //The Item in line number % does not have a matching Item Code. Please enter a valid Item or choose from the Help available (91057)
                              return false;
                        }
                        else //Launch the statistics screen
                        {
                              var strFileName = "STATISTICS3.ASP?FromScreen=SALESORDER&pharmacode=" + strItemCode
                              On_LaunchHelpLocal(strFileName, "STATISTICS")
                              break;
                        }
                  }
                  else if (strItemType == "B")
                  {
                        blnAtleastOneRowIsChecked      = true
                        blnChemicalsChecked                  = true
                  }      
                  
                  rowNode = objMLRows.nextNode;
            }
            
      
            /** Select Atleast One Row to launch Item Statistics **/
            if (!blnAtleastOneRowIsChecked)
            {
                  alert("<%=errObject.getnthdescription(errFileName,63)%>")
                  return false
            }
            /** Chemicals cannot be used for launching Item Statistics Screen **/
            if (blnChemicalsChecked)
            {
                  alert("<%=errObject.getnthdescription(errFileName,1285)%>")
                  return false
            }
      }
      
      /*************************************************************
            Function to read the values from the Sales Order Screen       
      **************************************************************/
      function On_FILLVALUESFROMCALLINGSCREEN(strFlag)
      {
            var intRowCounter                  = 0
            var intRowCtrInCurrentForm      = 1
            var nRecordCount                  = 0;
            var strMode                              = "<%=Trim(ACTION)%>"
            var objPOGrid                        = eval(divPurchaseOrder.getGridRef());
            
            if(strFlag == 'ONLOAD')
            {
                  // If the mode of action is fetch and the screen is called from some other screen, then fetch is called
                  if (strMode != "" && strFromScreen != "")
                  {
                        On_CallXMLHTTPAfterValidations("FETCH");
                        strFocusIsOn = "";
                        return false;
                  }
            
                  // If the mode of action is nothing and the screen is called from TRANSMISSIONLOG screen
                  if (strMode == "")
                  {
                        if (strFromScreen == "TRANSMISSIONLOG3")
                        {
                              /** Loop to get the Selected Records from the First Multiline of Transmission Log Screen **/
                              eval("window.parent.opener.divNotDeletedLines").filters = ""
                              eval("window.parent.opener.divNotDeletedLines").filters = "chkSelect $ieq$ '0' or chkSelect $ieq$ ''"
                              rstLocal = eval("window.parent.opener.divNotDeletedLines").getDataRS()
                              
                              // Calculate no. of rows and add rows if neccessary..
                              nRecordCount            = rstLocal.length
                              objPOGrid.MaxRows      = parseFloat(nRecordCount)>objPOGrid.MaxRows?nRecordCount:objPOGrid.MaxRows
                              
                              while (!rstLocal.EOF)
                              {
                                    if (Trim(rstLocal("txtItemCode").value) != "")
                                    {
                                          divPurchaseOrder.setCellValue("sprITEMTYPE",intRowCtrInCurrentForm,"I")
                                          divPurchaseOrder.setCellValue("sprHIDDENITEMCODE",intRowCtrInCurrentForm,rstLocal("txtItemCode").value)
                                          divPurchaseOrder.setCellValue("sprITEMDESCRIPTION",intRowCtrInCurrentForm,rstLocal("txtItemDescription").value)
                                          divPurchaseOrder.setCellValue("sprSTOCKQUANTITY",intRowCtrInCurrentForm,rstLocal("txtAvailableQuantity").value)
                                          divPurchaseOrder.setCellValue("sprMINSTOCKQUANTITY",intRowCtrInCurrentForm,rstLocal("txtMinimumQuantity").value)
                                          divPurchaseOrder.setCellValue("sprMAXSTOCKQUANTITY",intRowCtrInCurrentForm,rstLocal("txtMaximumQuantity").value)
                                          divPurchaseOrder.setCellValue("sprOPENORDERQUANTITY",intRowCtrInCurrentForm,rstLocal("txtOpenOrderQty").value)
                                          divPurchaseOrder.setCellValue("sprRATEINCHF",intRowCtrInCurrentForm,rstLocal("txtRateInCHF").value)
                                    
                                          intRowCtrInCurrentForm = parseFloat(intRowCtrInCurrentForm) + 1
                                    }
                                    rstLocal.MoveNext()
                              }                        

                              
                              /** Loop to get the Selected Records from the Second Multiline of Transmission Log Screen  **/
                              eval("window.parent.opener.divDeletedLines").filters = ""
                              eval("window.parent.opener.divDeletedLines").filters = "chkSelect $ieq$ '0' or chkSelect $ieq$ ''"
                              rstLocal = eval("window.parent.opener.divDeletedLines").getDataRS()
                              nRecordCount = 0
                              
                              // Calculate no. of rows and add rows if neccessary..
                              nRecordCount            = rstLocal.length
                              objPOGrid.MaxRows      = parseFloat(nRecordCount)>objPOGrid.MaxRows?nRecordCount:objPOGrid.MaxRows
                              
                              while (!rstLocal.EOF)
                              {
                                    if (Trim(rstLocal("txtItemCode").value) != "")
                                    {
            
                                          divPurchaseOrder.setCellValue("sprITEMTYPE",intRowCtrInCurrentForm,"I")
                                          divPurchaseOrder.setCellValue("sprHIDDENITEMCODE",intRowCtrInCurrentForm,rstLocal("txtItemCode").value)
                                          divPurchaseOrder.setCellValue("sprITEMDESCRIPTION",intRowCtrInCurrentForm,rstLocal("txtItemDescription").value)
                                          divPurchaseOrder.setCellValue("sprSTOCKQUANTITY",intRowCtrInCurrentForm,rstLocal("txtAvailableQuantity").value)
                                          divPurchaseOrder.setCellValue("sprMINSTOCKQUANTITY",intRowCtrInCurrentForm,rstLocal("txtMinimumQuantity").value)
                                          divPurchaseOrder.setCellValue("sprMAXSTOCKQUANTITY",intRowCtrInCurrentForm,rstLocal("txtMaximumQuantity").value)
                                          divPurchaseOrder.setCellValue("sprOPENORDERQUANTITY",intRowCtrInCurrentForm,rstLocal("txtOpenOrderQty").value)
                                          divPurchaseOrder.setCellValue("sprRATEINCHF",intRowCtrInCurrentForm,rstLocal("txtRateInCHF").value)
                                    
                                          intRowCtrInCurrentForm = parseFloat(intRowCtrInCurrentForm) + 1
                                    }
                                    rstLocal.MoveNext()
                              }
                        }
                  }
                  delete rstLocal            
            }
      }
      
      
      /*******************************************************************************
            Function to calculate the Bonus Quantity on Enter in Bonus Quantity Field
      ********************************************************************************/
      function On_CalculateBonusQuantity(intRowNumber)
      {
            var strQuery                  = ""
            var strFieldsList            = ""
            var strItemPharmaCode      = ""
            var intItemQuantity            = 0
            var nBonusColIndex            = divPurchaseOrder.getColIndex("sprBONUS")
            
            strItemPharmaCode            =  divPurchaseOrder.getCellValue("sprHIDDENITEMCODE",intRowNumber);
            intItemQuantity                  =  divPurchaseOrder.getCellValue("sprORDERQUANTITY",intRowNumber);
            divPurchaseOrder.setCellValue("sprBONUS",intRowNumber,"");
            
            strFieldsList = "sprBONUS,sprBONUS"
            
            if (strItemPharmaCode == "" || intItemQuantity == "" || isNaN(intItemQuantity)) return false
            
            strQuery += " SELECT TOP 1 CONVERT(INT, QtyDelivery_13) - CONVERT(INT, QtyInvoice_14) AS 'Bonus_Quantity', "
            strQuery += " CONVERT(INT, QtyDelivery_13) - CONVERT(INT, QtyInvoice_14) AS 'Bonus_Quantity' "
            strQuery += " FROM IIIGaldat_Pharmaceutical_Wholesalers_Sales_Info_ACACT05_View (NOLOCK) "
            strQuery += " WHERE       Phar_04 = '" + strItemPharmaCode + "' AND CONVERT(INT, QtyInvoice_14) < " + intItemQuantity
            strQuery += " GROUP BY Phar_04,QtyDelivery_13,QtyInvoice_14 "
            strQuery += " ORDER BY CONVERT(INT, QtyInvoice_14) DESC, CONVERT(INT, QtyDelivery_13) - CONVERT(INT, QtyInvoice_14) DESC "

            launchhelpEnter("HELPENTER.ASP?From=divPurchaseOrder&Grid=GRIDXML&fields=" + strFieldsList  + "&Query=" + strQuery + "&Database=Partner&QCD=0,0");
      
            objPURCHASEORDER.focus();
            objPURCHASEORDER.SetActiveCell(nBonusColIndex, intRowNumber)
      }
      
      /** Variables and Operations if Transmission is to be done **/
      var TransmissionStarted = false                  
      var TransmissionSuccess      = false
      var TransmissionMsg            = ""
      var IDF                              = ""
      var PhoneNumber                  = ""
      
      //Added by Venki for replacing the Cookies to Session Start
      //var ClientParams            = "<%=Request.Cookies("ClientParams")%>"
      var ClientParams            = "<%=Session("ClientParams")%>"
      //Added by Venki for replacing the Cookies to Session End

      var LangID                        = "<%=sLANGID%>"
      var Item_ResponseCode   = ""
      
//Modified VenkiRSL for PO Problem - 06May2003 TRIAMUNIII1.0S_016597 -- start      
      var noOfLinestoLog = 0
      var POLineItemstoLog = ""
//Modified VenkiRSL for PO Problem - 06May2003 TRIAMUNIII1.0S_016597 -- End      

      /*********************************************************
            Function to create the V50 Transmission Input File
      **********************************************************/
      function CreateInputV50File()
      {
/*            var IDF                              = Trim(divPurchaseOrder.getCellValue("CustomerIDF_Code"))
            var PhoneNumber                  = Trim(divPurchaseOrder.getCellValue("Phone_Number"))
            var ClientParams            = "<%=Session("ClientParams")%>"
            var LangID                        = "<%=sLANGID%>"
            
*/
            
            IDF                              = Trim(divPurchaseOrder.getCellValue("CustomerIDF_Code"))
            PhoneNumber                  = Trim(divPurchaseOrder.getCellValue("Phone_Number"))
            ClientParams            = "<%=Session("ClientParams")%>"
            LangID                        = "<%=sLANGID%>"

            /** Transmission with Error Handling **/                                    
            try
            {
                  fso = new ActiveXObject("Scripting.FileSystemObject")

                  /** Delete the previous Transmission's Response file **/
                  var LocalFileName = "c:\\iii\\v50\\ANSWER.DAT"
                  if (fso.FileExists(LocalFileName))       fso.DeleteFile(LocalFileName)
                                                
                  /** Preparing the Local File Path & Name based on the Customer IDF Code, Delete it if it already exists **/
                  LocalFileName = "c:\\iii\\v50\\" + IDF + ".v50"
                  if (fso.FileExists(LocalFileName)) fso.DeleteFile(LocalFileName)

                  var its = fso.CreateTextFile(LocalFileName,1,false)
                  its.WriteLine('C;2;W2250;GALINFO 1')

//Modified VenkiRSL for PO Problem - 06May2003 TRIAMUNIII1.0S_016597 -- start
                  noOfLinestoLog = 0
                  POLineItemstoLog = ""
                  datestr = getCurrentDate()
//Modified VenkiRSL for PO Problem - 06May2003 TRIAMUNIII1.0S_016597      -- End

                  divPurchaseOrder.filters = "";
                  var objPOMLDOM      = divPurchaseOrder.getXMLString();
            
                  // Return if there is no rows..
                  if ( objPOMLDOM == null ) return false;
            
                  var rstPOMLDetails      = objPOMLDOM.selectNodes("//row");
                  var nRowLength            = rstPOMLDetails.length
                  var nNoOfLines = 0            
                  for (var cntr = 1; cntr <= nRowLength; cntr ++)
                  {
                        var strITEMCODE = divPurchaseOrder.getCellValue("sprHIDDENITEMCODE",cntr)
                        var nQUANTITY      = divPurchaseOrder.getCellValue("sprORDERQUANTITY",cntr)
                        var str                  = ""
                        if (strITEMCODE != "")
                        {
                              str += "1;"
                              str += makelength(strITEMCODE, 7)
                              str += ";"
                              str += makelength(nQUANTITY, 4)
                              str += ";00;" + datestr
                              its.WriteLine(str)
                              nNoOfLines++
                        }
                        POLineItemstoLog = POLineItemstoLog + "::" + str //Added by VenkiRSL - 06May2003 TRIAMUNIII1.0S_016597
                              
                  }
                  
//Modified VenkiRSL for PO Problem - 06May2003 TRIAMUNIII1.0S_016597 -- start      
                  noOfLinestoLog = nNoOfLines
                  if(nNoOfLines == 0)
                  {
                        alert("<%=errObject.getnthdescription(errFileName,1130)%>")
                        its.Close()
                        return false
                  }                  
//Modified VenkiRSL for PO Problem - 06May2003 TRIAMUNIII1.0S_016597 -- End
                  
                  NoofLinesforComparition = makelength(nNoOfLines.toString(), 3)
                  lastline            = "E;00;" + NoofLinesforComparition
                  its.WriteLine(lastline)
                  its.Close()
            }
            catch(objException)
            {
                  TransmissionMsg = "<%=errObject.getnthdescription(errFileName,1130)%>"
                  return false
            }                              
            return true
      }      
            
      /**************************************************************
            Function to call PO Transmit on Load of PO Detail DIV
      ***************************************************************/      
      function On_LOADSUBMITFORTRANSMISSION()
      {
            if (strACTION == "TRANSMITPURCHASEORDERFETCH")
            {
                  // Step 1 : Create the Input file
                  if(CreateInputV50File())
                  {
                        // Step 2: Execute V50 EXE for Transmission
                        ExecuteV50Command(IDF, PhoneNumber, ClientParams, LangID)
                              
                        // Step 3: Read the anwer file and store as ItemCode1~ResponseCode1~~ItemCode2~ResponseCode2....                        
                        Item_ResponseCode = ReadV50AnswerFile()      
                  }
                  LogPODetailsInTextFile()            //Added by VenkiRSL - 06May2003 TRIAMUNIII1.0S_016597
                  document.frmPurchaseOrder.TransResponse.value = Item_ResponseCode
                  
                  /** Transmission status is Failure **/
                  if (!TransmissionSuccess)
                  {      
                        alert(TransmissionMsg)
                        document.frmPurchaseOrder.txtPOStatus.disabled = false;
                        document.frmPurchaseOrder.txtPOStatus.value = "6"
                        document.frmPurchaseOrder.txtPOStatus.disabled = true;
                        //document.frmPurchaseOrder.hidPOStatus.value = "6"
                  }
                  /** Transmission status is Transmitted **/
                  else
                  {
                        document.frmPurchaseOrder.txtPOStatus.disabled = false;
                        document.frmPurchaseOrder.txtPOStatus.value = "4"
                        document.frmPurchaseOrder.txtPOStatus.disabled = true;
                        //document.frmPurchaseOrder.hidPOStatus.value = "4"
                  }
            
                  document.frmPurchaseOrder.cboModeOfTransmission.disabled = false
                  On_CallXMLHTTPAfterValidations("TRANSMITPURCHASEORDERUPDATE");
                  return false;
            }
      }
      
      //Function LogPODetailsInTextFile() added by VenkiRSL for TRIAMUNIII1.0S_016597 - 06May2003
      /***********************************************************************************      
      Logging the PO Transmission details into flat files before and after PO Transmission
      ************************************************************************************/
      function LogPODetailsInTextFile()
      {
            var IDFNo      = Trim(divPurchaseOrder.getCellValue("CustomerIDF_Code"))
            var PONumbertmp      = document.frmPurchaseOrder.txtPONumber.value
            var filesys, newfolder, sourceFile, destinationFile
            filesys = new ActiveXObject("Scripting.FileSystemObject")
            
            if(!filesys.FolderExists("c:\\III"))
                  return

            if(!filesys.FolderExists("c:\\III\\V50"))
                  return

            var HistoryFolder = "c:\\III\\V50\\History"
            if(!filesys.FolderExists(HistoryFolder))
                newfolder = filesys.CreateFolder(HistoryFolder)
                                  
            var Curdate = getCurrentDate()
            var CurdateArry = Curdate.split(".")
            var dt                        = new Date()
            var hours                  = (dt.getHours().toString().length == 1)?("0" + dt.getHours().toString()):(dt.getHours().toString())
            var minutes                  = (dt.getMinutes().toString().length == 1)?("0" + dt.getMinutes().toString()):(dt.getMinutes().toString())
            var seconds                  = (dt.getSeconds().toString().length == 1)?("0" + dt.getSeconds().toString()):(dt.getSeconds().toString())
            var dateTimetmp = CurdateArry[2]+CurdateArry[1]+CurdateArry[0]+hours+minutes+seconds

            var DestinationFolder = HistoryFolder +"\\"+ dateTimetmp+"_"+PONumbertmp

            if(!filesys.FolderExists(DestinationFolder))
                newfolder = filesys.CreateFolder(DestinationFolder)       
            
            sourceFile = "c:\\III\\V50\\"+IDFNo+".v50"
            destinationFile = DestinationFolder+"\\"+IDFNo+".v50"
            if (filesys.FileExists(sourceFile) && filesys.FolderExists(DestinationFolder))
            {
                  filesys.MoveFile(sourceFile, destinationFile)
            }

            sourceFile = "c:\\III\\V50\\Answer.Dat"
            destinationFile = DestinationFolder+"\\Answer.Dat"
            if (filesys.FileExists(sourceFile) && filesys.FolderExists(DestinationFolder))
            {
                  filesys.MoveFile(sourceFile, destinationFile)
            }            
            if(filesys.FolderExists(DestinationFolder))
            {
                  var LogFileName = DestinationFolder+"\\Log.txt"
                  its = filesys.CreateTextFile(LogFileName,1,true)
                  its.WriteLine("Transmission Status : " + TransmissionSuccess)
                  its.WriteLine("Response text : " + Item_ResponseCode)
                  its.WriteLine("No of lines Read from ML : " + noOfLinestoLog)
                  its.WriteLine("PO Lines Read from ML : " + POLineItemstoLog)
      
                  its.Close()
            }            
      }
            

      /*******************************************************************
            Event to set the Deilvery Time when defaulting the Time Rules
      ********************************************************************/
      function On_ChangeDeliveryTime()
      {      
            var DeliveryTimeTemp = document.frmPurchaseOrder.hidDeliveryTime.value
            if (DeliveryTimeTemp == '')
            {
                  DeliveryTimeTemp = '23:59'
            }
            SetTimeValue(document.frmPurchaseOrder.txtDeliveryTime, DeliveryTimeTemp)
      }
      
      /************************************************************
            Function to Print Delivery Slip when launched from SO
            Changed by VenkiRSL:Reports : 20-Jan-2002
      *************************************************************/      
      function On_DeliverySlip()
      {
            var PONumber      = document.frmPurchaseOrder.txtPONumber.value
            intPOStatus            = Trim(divPurchaseOrder.getCellValue("PO_Status"))
            
            if(PONumber == "")
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,337)%>", "<%=lblPurchaseOrderNumber%>")
                  document.frmPurchaseOrder.txtPONumber.focus();
                  return false      
            }
            var strPrintFlag = Trim(document.frmPurchaseOrder.hidPrintFlag.value)
            
            // Validate if PO Status is empty
            if (intPOStatus == "")
            {
                  alert("<%=errObject.getnthdescription(errFileName,639)%>")
                  return false
            }
            // Validate that only authorised purchase orders can be printed
            if (intPOStatus != "3")
            {
                  alert("<%=errObject.getnthdescription(errFileName,956)%>")
                  return false
            }
            var size            = "directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,resizable=yes,height=200,width=310";      
            var ProcParams      = '<%=Triamun_Session("nPartnerId")%>' + ", '" + PONumber + "'"
            winReport            = window.open('../Reports/IIIRSL_Pharmacy_Delivery_CashierSlip.asp?ReportId=29&ParamCol='+ProcParams+'&PONumber='+PONumber , "Reports", size);
            winReport.focus();
      }

      /*******************************************************
            Function to print Report on press of Print Button
      *********************************************************/      
      function On_PrintReports()
      {
            var size = "directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,resizable=yes,height=200,width=310";
            var PONO = Trim(document.frmPurchaseOrder.txtPONumber.value)
            
            if(PONO == "")
            {
                  IIIalert("<%=errObject.getnthdescription(errFileName,337)%>", "<%=lblPurchaseOrderNumber%>")
                  document.frmPurchaseOrder.txtPONumber.focus();
                  return false      
            }
            else
            {
                  retval = isvalidCharSet(document.frmPurchaseOrder.txtPONumber.value);
                  if (retval == false)
                  {
                        IIIalert("<%=ErrObject.getnthdescription(Errfilename,305)%>","<%=lblPurchaseOrderNumber%>");
                        document.frmPurchaseOrder.txtPONumber.select();
                        return false;
                  }
            }
            ProcParams = '<%=Triamun_Session("nPartnerId")%>' + ", '" + PONO + "', '" +  '<%=Ucase(Triamun_Session("Language"))%>' +"'"
            winReport  = window.open('../Reports/Reports.asp?ReportId=1&ParamCol='+ProcParams , "Reports", size);
            winReport.focus();
      }

      /**************************************************************
            Function to fire on fetch of Item Details through Enter
      ***************************************************************/            
      function On_FetchItemDetails()
      {
            if (strItemHelpEnterRow == "") strItemHelpEnterRow = 0
            var nItemDescColIndex      = divPurchaseOrder.getColIndex("sprITEMDESCRIPTION");
            
            //Adda new line if the help enter is callled from last row of the GRID..
            if(objPURCHASEORDER.Maxrows == strItemHelpEnterRow)
            {
                  InsertSingleRow(objPURCHASEORDER, objPURCHASEORDER.ActiveRow)
            }
            
            
            /** Defaults the Previous Lines Quantity when scanning is done **/
            if ( (parseFloat(strItemHelpEnterRow) != 0) && (divPurchaseOrder.getCellValue("sprHIDDENITEMCODE",strItemHelpEnterRow) != "") )
            {
                  var tmpOrderQty = divPurchaseOrder.getCellValue("sprORDERQUANTITY",parseFloat(strItemHelpEnterRow)-1)
                  divPurchaseOrder.setCellValue("sprORDERQUANTITY",strItemHelpEnterRow,tmpOrderQty)
            }      
                  
            /** Set Focus in Next Row when some Records have been returned **/
            objPURCHASEORDER.focus();
            objPURCHASEORDER.SetActiveCell(nItemDescColIndex, (parseFloat(strItemHelpEnterRow)+1))
      }
      
      
      /***********************************************************************************
            Function for Showing Open Orders for the Item on click of Open Order Quantity
      ************************************************************************************/            
      function On_OPENPOQUANTITY(nCol,nRow,strColValue)
      {
            var nOPENQUANTITY            = strColValue
            var strItemCode                  = divPurchaseOrder.getCellValue("sprHIDDENITEMCODE",nRow);
            var strItemDescription      = divPurchaseOrder.getCellValue("sprITEMDESCRIPTION",nRow);
            
            if (nOPENQUANTITY != "" && nOPENQUANTITY > 0)
            {
                  var strFILENAME = "HELP.ASP?HELP_ID=105&StartText="+ nRow +"&Replace=" + <%=sPARTNERID%> + "," + strItemCode + "," + strItemDescription +  "&FilterValues=sprHIDDENITEMCODE,sprITEMDESCRIPTION&IgnoreSortFilters=YES"
                  launchhelp1(strFILENAME);
            }
      }


      var colNo_sprHIDDENCUSTOMERREFERENCES = 0;      
      function getColReference()      
      {
             colNo_sprHIDDENCUSTOMERREFERENCES = divPurchaseOrder.getColIndex("sprHIDDENCUSTOMERREFERENCES");
      }
      
      
      /******************************************
            Function to fire on Load of the form
      *******************************************/
      function SetDefaults(strFlag)
      {
            objPURCHASEORDER = document.all("sprPurchaseOrder")
            
            On_LOADSUBMITFORTRANSMISSION()                  // Fires after successful Fetch after Transmit Fetch
            On_FILLVALUESFROMCALLINGSCREEN(strFlag)      // Read From Screens if launched as a Sub Screen
            //On_LoadFUIFileOnBodyLoad()                  // Loads the FUI File On Body Load
            
            /** Freeze first Four Columns till Item Description Help **/
            objPURCHASEORDER.ColsFrozen      = divPurchaseOrder.getColIndex("sprHELPFORITEM");
            
            //OnLaunch fo the screen - Defaults value are set for the time ..
            /*if (strACTION == "")
            {
                  SetTimeValue(document.frmPurchaseOrder.txtOrderTime, divPurchaseOrder.getCellValue("PO_Time"))
                  SetTimeValue(document.frmPurchaseOrder.txtTransmissionTime, divPurchaseOrder.getCellValue("PO_Transmission_Time"))
                  SetTimeValue(document.frmPurchaseOrder.txtDeliveryTime, divPurchaseOrder.getCellValue("PO_Delivery_Time"))
            }*/
            
            
            /************************************************************************************************************
                  Disable the Mode of Transmission Combo if the PO Status is not in one of the following Cases
                  1.      Not      Empty ( Screen Launch )
                  2.      Not in Open Status
                  3.      Not in Authorised Status with Mode of Transmission as Modem
                  4.  Not in Failed Status with Mode of Transmission as Modem
            *************************************************************************************************************/
            var nPOSTATUS                        = Trim(divPurchaseOrder.getCellValue("PO_Status"))
            var strMODEOFTRANSMISSION      = Trim(divPurchaseOrder.getCellValue("PO_Transmission_Mode"))
            
            
            if (nPOSTATUS == "" || nPOSTATUS == "2" || (nPOSTATUS == "3" && strMODEOFTRANSMISSION == "A") ||
                  (nPOSTATUS == "6" && strMODEOFTRANSMISSION == "A"))
            {
                  document.frmPurchaseOrder.cboModeOfTransmission.disabled = false
            }
            else
            {
                  document.frmPurchaseOrder.cboModeOfTransmission.disabled = true
                  Allowupdate = false;
            }      
            
            /*** set focus on launch on the first field ***/
            //document.frmPurchaseOrder.txtPONumber.focus()
            
            /** Set the Focus to the Print Window if the Print Flag Update is a success **/
            if(Trim(divPurchaseOrder.getCellValue("Print_Flag")).toUpperCase() == 'Y')
            {
                  //set the button text to Reprint..
                  document.frmPurchaseOrder.cmdPrint.value = "<%=lblRePrint%>"
            
                  if(strACTION == 'PRINTPURCHASEORDER')
                  {
                        On_PrintReports()
                  
                        if (typeof(eval(winReport)) != "undefined")
                              winReport.focus();
                  }
            }
            else
            {
                  document.frmPurchaseOrder.cmdPrint.value = "<%=lblPrint%>"
            }
      }

</SCRIPT>


<!--------------------------------------------------------------------------------------------------------->
<!-------------------------------------  Event Handling for ML Grid --------------------------------------->

<SCRIPT LANGUAGE="JavaScript" FOR="sprPurchaseOrder" EVENT="ScriptKeyDown(KeyCode, Shift)">

      if (KeyCode == 40)
      {
            if(objPURCHASEORDER.ActiveRow == objPURCHASEORDER.MaxRows)
            {
                  var nItemDescColIndex      = divPurchaseOrder.getColIndex("sprITEMDESCRIPTION");
                  var nQtyColIndex            = divPurchaseOrder.getColIndex("sprORDERQUANTITY");
                  var nBonusColIndex            = divPurchaseOrder.getColIndex("sprBONUS");
                  var nPriceColIndex            = divPurchaseOrder.getColIndex("sprRATEINCHF");
                  var nSelColIndex            = divPurchaseOrder.getColIndex("sprSEL");
                  var nControlledColIndex      = divPurchaseOrder.getColIndex("sprCONTROLLED");
                  var nDeleteColIndex            = divPurchaseOrder.getColIndex("sprDELETE");
                  
                  if( (objPURCHASEORDER.ActiveCol == nItemDescColIndex) || (objPURCHASEORDER.ActiveCol == nQtyColIndex) || (objPURCHASEORDER.ActiveCol == nBonusColIndex) || (objPURCHASEORDER.ActiveCol == nPriceColIndex) || (objPURCHASEORDER.ActiveCol == nDeleteColIndex) || (objPURCHASEORDER.ActiveCol == nSelColIndex) || (objPURCHASEORDER.ActiveCol == nControlledColIndex))
                  {
                        //Insert a new Row
                        InsertSingleRow(objPURCHASEORDER, objPURCHASEORDER.ActiveRow)
                  }
            }
      }
      else if (KeyCode == 37 || KeyCode == 39)
      {
            SetFocusOnNextOrPreviousColumn(objPURCHASEORDER, KeyCode, objPURCHASEORDER.ActiveCol, objPURCHASEORDER.ActiveRow)
      }
      
</SCRIPT>


<SCRIPT LANGUAGE="JavaScript" FOR="sprPurchaseOrder" EVENT="ScriptKeyPress(nKeyAscii)">
      
      if (nKeyAscii == 13)
      {
            var nItemTypeColIndex      = divPurchaseOrder.getColIndex("sprITEMTYPE");
            var nItemDescColIndex      = divPurchaseOrder.getColIndex("sprITEMDESCRIPTION");
            var nRowNumber                  = objPURCHASEORDER.ActiveRow
            
            if(objPURCHASEORDER.ActiveCol == nItemDescColIndex)
            {
                  var strItemType            = divPurchaseOrder.getCellValue(nItemTypeColIndex,nRowNumber);
                  var strItemEANCode      = Trim(divPurchaseOrder.getCellValue(nItemDescColIndex,nRowNumber));
                  
                  if(strItemType != "" && strItemEANCode != "")
                        On_HelpOnEnterForItems(nRowNumber, nItemDescColIndex, strItemType, strItemEANCode)
            }
            else if(objPURCHASEORDER.ActiveCol == divPurchaseOrder.getColIndex("sprDELETE"))
            {
                  InsertSingleRow(objPURCHASEORDER, objPURCHASEORDER.ActiveRow)
            }
            else if(objPURCHASEORDER.ActiveCol == divPurchaseOrder.getColIndex("sprBONUS"))
            {
                  var strItemType            = divPurchaseOrder.getCellValue(nItemTypeColIndex,nRowNumber);
            
                  if (strItemType == "I")
                  {
                        On_CalculateBonusQuantity(nRowNumber)
                        return false
                  }            
            }
      }

</SCRIPT>


<!--------------------------------------------------------------------------------------------------------->
<!-------------------------------------  Event Handling for ML Grid --------------------------------------->

<SCRIPT>

      /* Function Calls Help for Item and basler Taxe, if the ... button is clicked */         
      function On_GridButtonClick()
      {
            var nCol                  = event.nCol;
            var nRow                  = event.nRow;
            var strFieldName      = event.FieldName;
            
            //----------- Help for Item and Basler Taxe ---------------------//
            if (strFieldName == "sprHELPFORITEM")
            {
                  HelpForItemOrChemical(nRow)
                  return false;
            }
            else if(strFieldName == "sprREFERENCE")
            {
            /****************************************************************************************************
                  To Launch the Customer Reference Sub Screen as a Modal Window when the Go Button is clicked
            *****************************************************************************************************/
            
                  var arrVALUES            = new Array();
                  
                  // Setting the Values to be passed to the SUB SCREEN
                  arrVALUES[0]            = nRow
                  arrVALUES[1]            = divPurchaseOrder.getCellValue("sprITEMDESCRIPTION",nRow);
                  arrVALUES[2]            = divPurchaseOrder.getCellValue("sprORDERQUANTITY",nRow);
                  arrVALUES[3]            = eval("divPurchaseOrder");
                  arrVALUES[4]            = "PURCHASEORDER";
                  
                  /** Validate that Item Description should be entered before launching the Customer Details sub screen **/            
                  if (arrVALUES[1] == "")
                  {
                        alert("<%=errObject.getnthdescription(errFileName, 1471)%>");
                        return false
                  }
                  
                  var arrRETURNVALUE      = showModalDialog("POCUSTOMERDETAILS3.ASP", arrVALUES, style="top:80;left:0;dialogHeight:600px;dialogWidth:1020px;scrollbars:none;help:no;status:no");
                  
                  if (arrRETURNVALUE[0] == "OK")
                  {
                        arrRETURNVALUE[1] =  escape(arrRETURNVALUE[1]);
                        divPurchaseOrder.setCellValue("sprHIDDENCUSTOMERREFERENCES",nRow,arrRETURNVALUE[1])
                        
                        // Button color is changed after setting values..
                        var objPOGrid      = eval(divPurchaseOrder.getGridRef())
                        var nColIndex      = divPurchaseOrder.getColIndex("sprREFERENCE");
                        
                        if(arrRETURNVALUE[1] != "")
                              Set_Button_Color(objPOGrid, nRow, nColIndex, "COLOR")
                        else
                              Set_Button_Color(objPOGrid, nRow, nColIndex, "NORMAL")
                        
                  }
                  return false;
            }
      }


      /* Function to calculate Total on change of Qty and Total */
      function On_CellChange()
      {
            var nCol = event.nCol;
            var nRow = event.nRow;
            var strFieldName = event.FieldName;
            
            if ( (strFieldName == "sprORDERQUANTITY") || (strFieldName == "sprBONUS") || (strFieldName == "sprRATEINCHF") )
            {
                  On_BlurCalculateTotals(nRow);
            }      
            else if(strFieldName == "sprITEMDESCRIPTION")
            {
                  On_ChangeItemDescription(nRow)      
            }
      }

      var Allowupdate = true;
      function validateTransmissionMode(objTxCboMode)
      {
            //if ( objTxCboMode.value == "A" ) objTxCboMode.value = "M"      
            var nPOSTATUS                        = Trim(divPurchaseOrder.getCellValue("PO_Status"))
            var strMODEOFTRANSMISSION      = Trim(divPurchaseOrder.getCellValue("PO_Transmission_Mode"))
            
            if (( nPOSTATUS == "3" ) || ( nPOSTATUS == "6" ))
            {
                  if (strMODEOFTRANSMISSION == "M")
                  {
                        objTxCboMode.value = "M"
                        objTxCboMode.disabled = true;
                        Allowupdate = false;
                  }
                  else
                  {      
                        if ( objTxCboMode.value = "M" ) Allowupdate = true;
                  }      
                        
            }
            
            return false;
      }
      
      function cmdItemAvailability_onClick()
      {
            /** To check that atleast one row exists in Multiline **/
            var nOrderQuantity = "";
            var nSelectColIndex                  = divPurchaseOrder.getColIndex("sprSEL");
            var nHidItemTypeColIndex      = divPurchaseOrder.getColIndex("sprITEMTYPE");
            var nItemTypeColIndex            = divPurchaseOrder.getColIndex("sprITEMTYPE");
            var nItemDescColIndex            = divPurchaseOrder.getColIndex("sprITEMDESCRIPTION");
            var nItemCodeColIndex            = divPurchaseOrder.getColIndex("sprHIDDENITEMCODE");
            var      nQuantityColIndex            = divPurchaseOrder.getColIndex("sprORDERQUANTITY");
            var nItemTypeColIndex            = nHidItemTypeColIndex + "~" + nItemTypeColIndex
            
            var strError      = CallProductAvailability("frmPurchaseOrder",objPURCHASEORDER,nSelectColIndex,nItemTypeColIndex,nItemDescColIndex,nItemCodeColIndex,nQuantityColIndex)
            if (strError != true)
            {
                  var strErrorArry      = strError.split("~")
                  var intErrorNum            = parseInt(strErrorArry[0])
                  if (strErrorArry.length == 3)
                  {
                        var intCol                  = parseInt(strErrorArry[1])
                        var intRow                  = parseInt(strErrorArry[2])
                  }

                  if (intErrorNum == "770")
                  {
                        alert("<%=errObject.getnthdescription(errFileName,770)%>");
                        objPURCHASEORDER.focus();
                        objPURCHASEORDER.SetActiveCell(intCol,intRow);
                        return false;
                  }      
                  if (intErrorNum == "1548")
                  {
                        alert("<%=errObject.getnthdescription(errFileName,1548)%>");
                        objPURCHASEORDER.focus();
                        objPURCHASEORDER.SetActiveCell(intCol,intRow);
                        return false;
                  }      
                  if (intErrorNum == "1549")
                  {
                        alert("<%=errObject.getnthdescription(errFileName,1549)%>");
                        objPURCHASEORDER.focus();
                        objPURCHASEORDER.SetActiveCell(intCol,intRow);
                        return false;
                  }      
                  if (intErrorNum == "436")
                  {
                        alert("<%=errObject.getnthdescription(errFileName,436)%>");
                        return false;
                  }      
            }

            var winHelp, strWindowName, strFileName;
            strWindowName      = "ProductAvailability";
            strFileName            = "ProductAvailability.asp?From=document.frmPurchaseOrder"      
            winHelp                  = window.open(strFileName, strWindowName, 'menubar=no,location=no,toolbar=no,resizable=yes,scrollbars=yes,top=80,left=0,width=1020,height=600');
            winHelp.focus();            
      }
      
</SCRIPT>

</HEAD>

<!-- Drawing Screen -->
<BODY ID="PURCHASEORDER3" CLASS="pgbody" ONCLICK="bodyHideAll()" ONLOAD="SetDefaults('ONLOAD')">

<%If varFromScreen = "" Then%>
      <!--#include file="../include/galmenu.asp"-->
<%End If%>

<FORM METHOD="POST" NAME="frmPurchaseOrder" ONSUBMIT="return On_Create()">

<%If varFromScreen <> "" Then%>
      <TABLE STYLE="width:954px">
            <TR ALIGN="right">
                  <TD CLASS="tdScreenTitle" NOWRAP><%=lblScreenTitle%></TD>
            </TR>
      </TABLE>
      <HR>
<%End If%>


<TABLE NAME="POHEADER" ID="POHEADER"> <!-- Table for PO Header and ML -->

<TR>
      <TD ALIGN="left" COLSPAN="9">
            
            <!-- Hidden Header Controls Starts -->
            <INPUT TYPE="hidden" NAME="mTimeStamp"                        VALUE="">
            <INPUT TYPE="hidden" NAME="mPOType"                              VALUE="">
            <INPUT TYPE="hidden" NAME="mNoOfLinesAutomatic"            VALUE="">
            <INPUT TYPE="hidden" NAME="mNoOfLinesManual"            VALUE="">
            <INPUT TYPE="hidden" NAME="mNoOfLinesCustomer"            VALUE="">
            <INPUT TYPE="hidden" NAME="mSalesOrderNo"                  VALUE="">
            <INPUT TYPE="hidden" NAME="mFromScreen"                        VALUE="">
            <INPUT TYPE="hidden" NAME="hidPrintFlag"                  VALUE="">
            <INPUT TYPE="hidden" NAME="hidStatusOfPOBeforeUpdate" VALUE="">
            <INPUT TYPE="hidden" NAME="hidOnFetchItemDetails" ONCHANGE="On_FetchItemDetails()">
            <INPUT TYPE="hidden" NAME="hidDeliveryTime"              ONCHANGE="On_ChangeDeliveryTime()">
            <INPUT TYPE="hidden" NAME="hidPODETAILDATA">
            <INPUT TYPE="hidden" NAME="hdnPDIExists"                  VALUE="">
            <!-- Hidden Header Controls Ends -->
                  
            <!--Begin :Interface 002:PO Transmission - Venki-->
            <INPUT TYPE="hidden" NAME="TransResponse">
            <INPUT TYPE="hidden" NAME="hidCustomerIDFCode"            VALUE="">
            <INPUT TYPE="hidden" NAME="hidPhoneNumber"                  VALUE="">
            <!--End :Interface 002:PO Transmission - Venki-->
            
            <!-- Hidden Control For Item availability Starts -->
            <INPUT TYPE="hidden" NAME="hidItemAvailability"      VALUE="">
            <!-- Hidden Control For Item availability Ends -->
                  
            <!-- License File for Time Picker & Grid Download Starts -->
            <OBJECT CLASSID="<%=lbltriamunlpk%>" VIEWASTEXT id=OBJECT1>
               <PARAM NAME="LPKPath" VALUE="../Download/Triamun.lpk">
            </OBJECT>
      </TD>
</TR>

<TR>
      <TD ALIGN="left" CLASS="tdtext"><%=lblPurchaseOrderNumber%></TD>
      <TD ALIGN="left" CLASS="tdtext"><INPUT TYPE="text" NAME="txtPONumber" MAXLENGTH="15" CLASs="tdEdit" SIZE="17" ONFOCUS="On_SetFocusValue('txtPONumber', '')" ONBLUR="On_SetFocusValue('', '')"></TD>
      <TD ALIGN="left" CLASS="tdHelp"><INPUT TYPE="button" NAME="cmdCCHForPONO" VALUE="..." ONCLICK="HelpForPONumber()" <%=GetAccessPermission("PURCHASEORDER3","FETCH")%>></TD>
      <TD ALIGN="left" CLASS="tdText"><INPUT TYPE="button" NAME="cmdFetch" CLASS="stdButton" VALUE="<%=lblFetch%>" ONCLICK="On_Fetch()" <%=GetAccessPermission("PURCHASEORDER3","FETCH")%>></TD>
      <TD ALIGN="left" CLASS="tdtext"></TD>
      <TD ALIGN="left" CLASS="tdHelp"></TD>
      <TD ALIGN="left" CLASS="tdtext"><%=lblStatus%></TD>
      <TD ALIGN="left" CLASS="tdtext">
            <!-- <INPUT TYPE="hidden" NAME="hidPOStatus" VALUE=""> -->
            <!-- <INPUT TYPE="text" NAME="txtPOStatus" CLASS="ctrlHdrReadOnly" READONLY TABINDEX="-1" VALUE="<%=GetQCDDESCRIPTIONFORCODE(POStatusQCD,Trim(varPOStatus))%>"> -->
            <SELECT NAME="txtPOStatus" CLASS="ctrlHdrReadOnly" DISABLED>
                  <OPTION VALUE="" SELECTED></OPTION>
                  <%      For varCtr = 0 To UBound(POStatusQCD)      'PO Status retrieved from QCD %>
                        <OPTION VALUE="<%=POStatusQCD(varCtr,0)%>"> <%=POStatusQCD(varCtr,1)%> </OPTION>
                  <%      Next %>       
            </SELECT>
            
      </TD>
      <TD ALIGN="left" CLASS="tdHelp"></TD>
</TR>

<TR><TD ALIGN="left" COLSPAN="9"><HR></TD></TR>

<TR>
      <TD ALIGN="left" CLASS="tdtext"><%=lblSupplier%></TD>
      <TD CLASS="tdtext"><INPUT TYPE="text" NAME="txtSupplierDescription" MAXLENGTH="40" ONCHANGE="On_ClearSupplierCode()" ID="<%=lblSupplier%>" ONFOCUS="On_SetFocusValue(name, '')" ONBLUR="On_SetFocusValue('', '');On_ValidateCharSet(this, this.id)" CLASS="tdEdit"><INPUT TYPE="hidden" NAME="txtSupplierCode"></TD>
      <TD ALIGN="left" CLASS="tdHelp"><INPUT TYPE="button" NAME="cmdCCHForSupplier" VALUE="..." ONCLICK="HelpForSupplier()"><LABEL ID="lblMandatoryRed">*</LABEL></TD>
      <TD ALIGN="left" CLASS="tdtext"><%=lblOrderDate%></TD>
      <TD ALIGN="left" CLASS="tdtext"><INPUT TYPE="text" ID="txtOrderDate" NAME="txtOrderDate" MAXLENGTH="10" CLASS="tdEdit" ID="<%=lblOrderDate%>" ONFOCUS="On_SetFocusValue('txtOrderDate', '')" ONBLUR="validateDate(this, this.id);On_SetFocusValue('', '')"></TD>
      <TD ALIGN="left" CLASS="tdHelp"><INPUT TYPE="button" NAME="cmdDatePickForOrderDate" VALUE="^" ONCLICK="Datepick('document.frmPurchaseOrder.txtOrderDate','<%=sLANGID%>')"><LABEL ID="lblMandatoryRed">*</LABEL></TD>
      <TD ALIGN="left" CLASS="tdtext"><%=lblOrderTime%></TD>
      <TD ALIGN="left" CLASS="tdtext"><OBJECT NAME="txtOrderTime" ID="txtOrderTime" CLASS="tdEdit" STYLE="left:0px;top:0px;height:24px" CLASSID="<%=lblTime%>" CODEBASE="../Download/MSCOMCT2.CAB" VIEWASTEXT>
                                                            <PARAM NAME="_ExtentX" VALUE="1826">
                                                            <PARAM NAME="_ExtentY" VALUE="900">
                                                            <PARAM NAME="_Version" VALUE="393216">
                                                            <PARAM NAME="MousePointer" VALUE="0">
                                                            <PARAM NAME="Enabled" VALUE="1">
                                                            <PARAM NAME="OLEDropMode" VALUE="0">
                                                            <PARAM NAME="CalendarBackColor" VALUE="-2147483643">
                                                            <PARAM NAME="CalendarForeColor" VALUE="-2147483630">
                                                            <PARAM NAME="CalendarTitleBackColor" VALUE="-2147483633">
                                                            <PARAM NAME="CalendarTitleForeColor" VALUE="-2147483630">
                                                            <PARAM NAME="CalendarTrailingForeColor" VALUE="-2147483631">
                                                            <PARAM NAME="CheckBox" VALUE="0">
                                                            <PARAM NAME="CustomFormat" VALUE="HH:mm">
                                                            <PARAM NAME="DateIsNull" VALUE="0">
                                                            <PARAM NAME="Format" VALUE="662831107">
                                                            <PARAM NAME="UpDown" VALUE="1">
                                                            <PARAM NAME="CurrentDate" VALUE="0.833333333333333">
                                                            <PARAM NAME="MaxDate" VALUE="2958465">
                                                            <PARAM NAME="MinDate" VALUE="-109205">      
                                                      </OBJECT></TD>
      <TD ALIGN="left" CLASS="tdHelp"><LABEL ID="lblMandatoryRed">*</LABEL></TD>
</TR>

<TR>
      <TD ALIGN="left" CLASS="tdtext"><%=lblModeOfPO%></TD>
      <TD ALIGN="left" CLASS="tdtext"><INPUT TYPE="text" NAME="txtModeOfPO" READONLY TABINDEX="-1" CLASS="ctrlhdrreadonly" VALUE=""></TD>
      <TD ALIGN="left" CLASS="tdHelp"></TD>
      <TD ALIGN="left" CLASS="tdtext"><%=lblTransmissionDate%></TD>
      <TD ALIGN="left" CLASS="tdtext"><INPUT TYPE="text" ID="<%=lblTransmissionDate%>" NAME="txtTransmissionDate" MAXLENGTH="10" CLASS="tdEdit" ONBLUR="validateDate(this, this.id)"></TD>
      <TD ALIGN="left" CLASS="tdHelp"><INPUT TYPE="button" NAME="cmdDatePickForTransmissionDate" VALUE="^" ONCLICK="Datepick('document.frmPurchaseOrder.txtTransmissionDate','<%=sLANGID%>')"><LABEL ID="lblMandatoryBlue">*</LABEL></TD>
      <TD ALIGN="left" CLASS="tdtext"><%=lblTransmissionTime%></TD>
      <TD ALIGN="left" CLASS="tdtext"><OBJECT NAME="txtTransmissionTime" ID="txtTransmissionTime" CLASS="tdEdit" STYLE="left:0px;top:0px;height:24px" CLASSID="<%=lblTime%>" CODEBASE="../Download/MSCOMCT2.CAB" VIEWASTEXT>
                                                            <PARAM NAME="_ExtentX" VALUE="1826">
                                                            <PARAM NAME="_ExtentY" VALUE="900">
                                                            <PARAM NAME="_Version" VALUE="393216">
                                                            <PARAM NAME="MousePointer" VALUE="0">
                                                            <PARAM NAME="Enabled" VALUE="1">
                                                            <PARAM NAME="OLEDropMode" VALUE="0">
                                                            <PARAM NAME="CalendarBackColor" VALUE="-2147483643">
                                                            <PARAM NAME="CalendarForeColor" VALUE="-2147483630">
                                                            <PARAM NAME="CalendarTitleBackColor" VALUE="-2147483633">
                                                            <PARAM NAME="CalendarTitleForeColor" VALUE="-2147483630">
                                                            <PARAM NAME="CalendarTrailingForeColor" VALUE="-2147483631">
                                                            <PARAM NAME="CheckBox" VALUE="0">
                                                            <PARAM NAME="CustomFormat" VALUE="HH:mm">
                                                            <PARAM NAME="DateIsNull" VALUE="0">
                                                            <PARAM NAME="Format" VALUE="662831107">
                                                            <PARAM NAME="UpDown" VALUE="1">
                                                            <PARAM NAME="CurrentDate" VALUE="0.833333333333333">
                                                            <PARAM NAME="MaxDate" VALUE="2958465">
                                                            <PARAM NAME="MinDate" VALUE="-109205">      
                                                      </OBJECT></TD>
      <TD ALIGN="left" CLASS="tdHelp"><LABEL ID="lblMandatoryBlue">*</LABEL></TD>
</TR>

<TR>
      <TD ALIGN="left" CLASS="tdtext"><%=lblModeOfTransmission%></TD>
      <TD ALIGN="left" CLASS="tdtext">
            <SELECT NAME="cboModeOfTransmission" CLASS="tdEdit" onbeforeupdate="validateTransmissionMode(this)">
                  <OPTION VALUE=""></OPTION>            
                  <%For cntr = 0 To UBound(POTransmissionMode,1)
                        if POTransmissionMode(cntr,0) = varPOTransmissionMode then%>
                              <OPTION VALUE="<%=POTransmissionMode(cntr,0)%>" SELECTED><%=POTransmissionMode(cntr,1)%></OPTION>
                        <%Else%>
                              <OPTION VALUE="<%=POTransmissionMode(cntr,0)%>"><%=POTransmissionMode(cntr,1)%></OPTION>
                        <%End If
                    Next%>
            </SELECT><LABEL ID="lblMandatoryRed">*</LABEL>
      </TD>
      <TD ALIGN="left" CLASS="tdHelp"></TD>
      <TD ALIGN="left" CLASS="tdtext"><%=lblDeliveryDate%></TD>
      <TD ALIGN="left" CLASS="tdtext"><INPUT TYPE="text" ID="<%=lblDeliveryDate%>" NAME="txtDeliveryDate" CLASS="tdEdit" MAXLENGTH="10" ID="<%=lblDeliveryDate%>" ONBLUR="validateDate(this, this.id)"></TD>
      <TD ALIGN="left" CLASS="tdHelp"><INPUT TYPE="button" NAME="cmdDatePickForDeliveryDate" VALUE="^" ONCLICK="Datepick('document.frmPurchaseOrder.txtDeliveryDate','<%=sLANGID%>')"><LABEL ID="lblMandatoryRed">*</LABEL></TD>
      <TD ALIGN="left" CLASS="tdtext"><%=lblDeliveryTime%></TD>
      <TD ALIGN="left" CLASS="tdtext"><OBJECT NAME="txtDeliveryTime" ID="txtDeliveryTime" CLASS="tdEdit" STYLE="left:0px;top:0px;height:24px" CLASSID="<%=lblTime%>" CODEBASE="../Download/MSCOMCT2.CAB" VIEWASTEXT>
                                                            <PARAM NAME="_ExtentX" VALUE="1826">
                                                            <PARAM NAME="_ExtentY" VALUE="900">
                                                            <PARAM NAME="_Version" VALUE="393216">
                                                            <PARAM NAME="MousePointer" VALUE="0">
                                                            <PARAM NAME="Enabled" VALUE="1">
                                                            <PARAM NAME="OLEDropMode" VALUE="0">
                                                            <PARAM NAME="CalendarBackColor" VALUE="-2147483643">
                                                            <PARAM NAME="CalendarForeColor" VALUE="-2147483630">
                                                            <PARAM NAME="CalendarTitleBackColor" VALUE="-2147483633">
                                                            <PARAM NAME="CalendarTitleForeColor" VALUE="-2147483630">
                                                            <PARAM NAME="CalendarTrailingForeColor" VALUE="-2147483631">
                                                            <PARAM NAME="CheckBox" VALUE="0">
                                                            <PARAM NAME="CustomFormat" VALUE="HH:mm">
                                                            <PARAM NAME="DateIsNull" VALUE="0">
                                                            <PARAM NAME="Format" VALUE="662831107">
                                                            <PARAM NAME="UpDown" VALUE="1">
                                                            <PARAM NAME="CurrentDate" VALUE="0.833333333333333">
                                                            <PARAM NAME="MaxDate" VALUE="2958465">
                                                            <PARAM NAME="MinDate" VALUE="-109205">
                                                      </OBJECT></TD>
      <TD ALIGN="left" CLASS="tdHelp"><LABEL ID="lblMandatoryRed">*</LABEL></TD>
</TR>      

<TR>
      <TD ALIGN="left" CLASS="tdtext"><%=lblSalesRep%></TD>
      <TD ALIGN="left" CLASS="tdtext"><INPUT TYPE="text" NAME="txtSalesRep" VALUE="" ID="<%=lblSalesRep%>" MAXLENGTH="40" CLASS="tdEdit" ONBLUR="On_ValidateCharSet(this, this.id)"></TD>
      <TD ALIGN="left" CLASS="tdHelp"></TD>
      <TD ALIGN="left" CLASS="tdtext"><%=lblTotalValue%></TD>
      <TD ALIGN="left" CLASS="tdtext"><INPUT TYPE="text" NAME="txtTotalValue" READONLY TABINDEX="-1" CLASS="ctrlhdrreadonly" STYLE="text-align:right"></TD>      
      <TD ALIGN="left" CLASS="tdHelp"></TD>
      <TD ALIGN="left" CLASS="tdtext"><%=lblTotalNumberOfLineItems%></TD>
      <TD ALIGN="left" CLASS="tdtext"><INPUT TYPE="text" NAME="txtTotalNoOfLineItems" VALUE="" READONLY CLASS="ctrlhdrReadOnly" STYLE="TEXT-ALIGN:RIGHT" TABINDEX="-1"></TD>
      <TD ALIGN="left" CLASS="tdHelp"></TD>
</TR>

<TR>
      <TD ALIGN="left" CLASS="tdtext"><%=lblRemark%></TD>
      <TD ALIGN="left" CLASS="tdtext" COLSPAN="7"><TEXTAREA NAME="txtRemarks" ROWS="2" CLASS="tdEditSpan7" ONKEYPRESS="return LimitTextArea(this, 500)"><%=varRemarks%></TEXTAREA></TD>
      <TD ALIGN="left" CLASS="tdHelp"></TD>
</TR>

</TABLE>

<!-- PO Detail Table -->
<TABLE>

<TR><TD ALIGN="left" COLSPAN="9"></TD></TR>
<TR><TD ALIGN="left" COLSPAN="9"></TD></TR>

<TR>
      <TD ALIGN="left" COLSPAN="9">
            <!-- #include file="DATAMAPPING_PURCHASEORDER.asp" -->
      </TD>
</TR>

<TR>
      <TD ALIGN="left" COLSPAN="9">
            <TABLE>
                  <TR ALIGN="left">
                        <TD ALIGN="left" STYLE="width:300px" CLASS="hdrText">
                              <INPUT TYPE="checkbox" NAME="chkSelectAllForControlled" ONCLICK="On_CheckUnCheckAllControlledCheckBoxes()">&nbsp;&nbsp;
                              <LABEL ID="lblCheckUncheckControlled"><%=lblSelectAllForControlled%></LABEL>
                        </TD>
                        <TD ALIGN="right" STYLE="width:650px" CLASS="hdrText">
                              <DIV ID="IDCreatedOn"><%=varRecordCreationLabel%></DIV>
                        </TD>
                  </TR>
            </TABLE>
      </TD>
</TR>

<!--
<TR>
      <TD ALIGN="left" CLASS="tdText"></TD>
      <TD ALIGN="right" CLASS="tdEditSpan7"><DIV ID="IDCreatedOn" ><%=varRecordCreationLabel%></DIV></TD>
      <TD ALIGN="left" CLASS="tdHelp"></TD>
</TR>
-->

<TR><TD ALIGN="left" COLSPAN="9"></TD></TR>
<TR><TD ALIGN="left" COLSPAN="9"></TD></TR>

<TR>
      <TD ALIGN="left" COLSPAN="9">
            <INPUT TYPE="submit" CLASS="stdButton" NAME="cmdCreate"      ID="functionKeyCreate" VALUE="<%=lblCreate%>" <%=GetAccessPermission("PURCHASEORDER3","CREATE")%>>
            <INPUT TYPE="button" CLASS="stdButton" NAME="cmdModify"      ID="functionKeyModify" VALUE="<%=lblModify%>" ONCLICK="return On_Modify()" <%=GetAccessPermission("PURCHASEORDER3","MODIFY")%>>
            <INPUT TYPE="button" CLASS="stdButton" NAME="cmdDelete"      ID="functionKeyDelete" VALUE="<%=lblDeleteTitle%>" ONCLICK="return On_Delete()" <%=GetAccessPermission("PURCHASEORDER3","DELETE")%>>
            <INPUT TYPE="button" CLASS="stdButton" NAME="cmdAuthorise" ID="functionKeyAuthorize" VALUE="<%=lblAuthorise%>" ONCLICK="return On_Authorise()" <%=GetAccessPermission("PURCHASEORDER3","AUTHORIZE")%>>
            <INPUT TYPE="button" CLASS="stdButton" NAME="cmdPrint" ID="functionKeyPrint" <%If Trim(varPrintFlag) = "Y" Then%>VALUE="<%=lblRePrint%>" <%Else%> VALUE="<%=lblPrint%>" <%End If%> ONCLICK="return On_Print()">
            <!--      <INPUT TYPE="reset"  CLASS="stdButton" NAME="cmdReset" VALUE="<%=lblReset%>"> -->
            <INPUT TYPE="button" CLASS="stdButton" NAME="cmdClear" ID="functionKeyClear" VALUE="<%=lblClear%>" ONCLICK="On_Clear()">
            
            <%If varFromScreen <> "" Then%>
                  <INPUT TYPE="button" CLASS="stdButton" NAME="cmdCancel" ID="functionKeyClose" VALUE="<%=lblClose%>" ONCLICK="window.close()">
            <%end if%>            
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <INPUT TYPE="button" CLASS="stdButton" NAME="cmdTransmit" ID="functionKeyTransmit" VALUE="<%=lblTransmit%>" ONCLICK="return On_Transmit()" <%=GetAccessPermission("PURCHASEORDER3","AUTHORIZE")%>>
            <INPUT TYPE="button" CLASS="scrButton" NAME="cmdShortClose" VALUE="<%=lblShortClose%>" ONCLICK="return On_ShortClose()" <%=GetAccessPermission("PURCHASEORDER3","AUTHORIZE")%>>
            <INPUT TYPE="button" CLASS="scrButton" NAME="cmdItemPrice" VALUE="<%=lblItemPrice%>" ONCLICK="On_ItemPrice()">
      </TD>
</TR>
<TR>
      <TD ALIGN="left" COLSPAN="9">
            <INPUT TYPE="button" CLASS="scrButton" NAME="cmdChangeSupplier" VALUE="<%=lblChangeSupplier%>" ONCLICK="return On_ChangeSupplier()">
            <INPUT TYPE="button" CLASS="scrButton" NAME="cmdTransmissionLog" VALUE="<%=lblTransmissionLog%>" ONCLICK="On_TransmissionLog()">      
            <INPUT TYPE="button" CLASS="scrButton" NAME="cmdPartnerDefinedData" VALUE="<%=lblPartnerDefinedData%>" ONCLICK="On_PartnerDefinedData()">
            <INPUT TYPE="button" CLASS="scrButton" NAME="cmdItemStatistics" VALUE="<%=lblStatistics%>" ONCLICK="return On_ItemStatistics()">
            <%'If varFromScreen = "SO" Or Trim(varSalesOrderNo) <> "" Then%>
            <INPUT TYPE="button" CLASS="scrButton" NAME="cmdDeliverySlip" VALUE="<%=lblDeliverySlip%>" ONCLICK="On_DeliverySlip()">
            <%'End If%>
            <INPUT TYPE="button" CLASS="scrButton" NAME="cmdItemAvailability" VALUE="<%=lblItemAvailability%>" ONCLICK="cmdItemAvailability_onClick()">
      </TD>
</TR>
</TABLE>

</FORM>

<SCRIPT LANGUAGE="VbScript">
      
      ' Tool Tip for ML Columns
      Sub sprPURCHASEORDER_ScriptTextTipFetch(Col,Row,MultiLine,TipWidth,TipText,ShowTip)

            ' If the column is zero
            If Col = 0 Then  Exit Sub

            ' Get the Col Name for the given col index..
            If CStr(Col) <> "" Then
                  strColName = divPurchaseOrder.getColName(Col)
            Else
                  strColName = ""      
            End If      
            
            If (strColName = "sprSEL" AND Row = 0) Then
                  TipText =  "<%=lblSelectTitle%>"
                  ShowTip = True
            End If

            If (strColName = "sprITEMTYPE" AND Row = 0) Then
                  TipText =  "<%=lblItemTypeTT%>"
                  ShowTip = True
            End If
            
            If (strColName = "sprSTOCKQUANTITY" AND Row = 0) Then
                  TipText =  "<%=lblStockQuantityTT%>"
                  ShowTip = True
            End If
            
            If (strColName = "sprMINSTOCKQUANTITY" AND Row = 0) Then
                  TipText =  "<%=lblMinStockQuantityTT%>"
                  ShowTip = True
            End If
            
            If (strColName = "sprMAXSTOCKQUANTITY" AND Row = 0) Then
                  TipText =  "<%=lblMaxStockQuantityTT%>"
                  ShowTip = True
            End If
            
            If (strColName = "sprOPENORDERQUANTITY" AND Row = 0) Then
                  TipText =  "<%=lblOpenOrderQuantityTT%>"
                  ShowTip = True
            End If

            If (strColName = "sprORDERQUANTITY" AND Row = 0) Then
                  TipText =  "<%=lblOrderQuantityTT%>"
                  ShowTip = True
            End If
            
            If (strColName = "sprBONUS" AND Row = 0) Then
                  TipText =  "<%=lblBonusTT%>"
                  ShowTip = True
            End If

            If (strColName = "sprTOTALQTY" AND Row = 0) Then
                  TipText =  "<%=lblTotalTT%>"
                  ShowTip = True
            End If
      
            If (strColName = "sprRATEINCHF" AND Row = 0) Then
                  TipText =  "<%=lblRateInCHFTT%>"
                  ShowTip = True
            End If

            If (strColName = "sprTOTALAMOUNT" AND Row = 0) Then
                  TipText =  "<%=lblValueOfLineTT%>"
                  ShowTip = True
            End If
            
            If (strColName = "sprREFERENCE" AND Row = 0) Then
                  TipText =  "<%=lblRefTT%>"
                  ShowTip = True
            End If
            
            If (strColName = "sprCONTROLLED" AND Row = 0) Then
                  TipText =  "<%=lblControlledTitle%>"
                  ShowTip = True
            End If
            
            If (strColName = "sprNONMOVINGITEM" AND Row = 0) Then
                  TipText =  "<%=lblNonMovingItemTitle%>"
                  ShowTip = True
            End If
            
            If (strColName = "sprDELETE" AND Row = 0) Then
                  TipText =  "<%=lblDeleteTitle%>"
                  ShowTip = True
            End If
            If (strColName = "sprSOURCE" AND Row = 0) Then
                  TipText =  "<%=lblSourceTT%>"
                  ShowTip = True
            End If
            If (strColName = "sprDELQTY" AND Row = 0) Then
                  TipText =  "<%=lblDelQtyTT%>"
                  ShowTip = True
            End If
            If (strColName = "sprPENDQTY" AND Row = 0) Then
                  TipText =  "<%=lblPendQtyTT%>"
                  ShowTip = True
            End If
      
      End Sub

</SCRIPT>

</BODY>
</HTML>


===server_purchaseorder3.asp====

<!-- #include FILE="../include/validateForXMLHTTP.inc"-->
<!--#include file="../sessionmanager.inc" -->

<%      If UCase(Triamun_Session("Language")) = "E" Then%>
            <!-- #include file="../include/english/Qcd1_e.inc"-->
<%      ElseIf UCase(Triamun_Session("Language")) = "G" Then%>
            <!-- #include file="../include/german/Qcd1_g.inc"-->
<%      ElseIf UCase(Triamun_Session("Language")) = "F" Then%>
            <!-- #include file="../include/french/Qcd1_f.inc"-->            
<%      End If

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' --------------------------------- SERVER SIDE VARIABLE DECLARATION -------------------------------------------
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim objDOMSERVERSIDE, objPURCHASEORDER, objPODetails, rstPURCHASEORDERHEADER, rstPODISCOUNTMESSAGE

Dim ACTION, varPOStatus, varPONumber, varPODETAIL, nROWCOUNTER, lblNonMovingItem, strRETURNVALUE
Dim errFileName, sPARTNERID, varPartnerName, varUserName, sCON, sLANGID
Dim nERRORNO, strERRORMESSAGE, varDISCOUNTMESSAGE, strERRORMESSAGETEMP, objRETURNVALUE
Dim varStatusOfPOBeforeUpdate, nCtr, strPODETAILDATA, varPOHEADER, varDaysForNonMovingItem
Dim varSupplierCode, varSupplierDescription, varPOTransmissionMode, varPODeliveryDate, varPODeliveryTime
Dim varPODate, varPOTime, varPOTransmissionTime, varFlagForPrinting, arrParamList


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ------------------------------------- GET SESSION VARIABLE --------------------------------------------------
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SET errObject                  = Application("ErrObject")
errFileName                        = Session("FEErrMsgFile")
sPARTNERID                        = Triamun_Session("nPartnerId")
varPartnerName                  = Triamun_Session("strPartnerName")
varUserName                        = Triamun_Session("strUserName")
sCON                              = Application("strODBC")
sLANGID                              = Triamun_Session("Language")
varDaysForNonMovingItem      = Session("PRT010")                        ' No of Days for an Item to become Non-Moving

If varDaysForNonMovingItem = "" Then varDaysForNonMovingItem = 0


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ----------------------------------- COMMENT HEADER FOR QUERY STRING VALUES ---------------------------------
'      Query String Variable Name            Value                                    Description
' ------------------------------------------------------------------------------------------------------------
'      ACTION                                          FETCH                                    Fetches a purchase order
'                                                      INSERTPURCHASEORDER                  Inserts a New Purchase Order
'                                                      MODIFYPURCHASEORDER                  Modifies an existing Purchase Order
'                                                      AUTHORISEPURCHASEORDER            Authorises an existing Purchase Order
'                                                      TRANSMITPURCHASEORDERFETCH  Transmits an Existing Purchase Order
'                                                      TRANSMITPURCHASEORDERUPDATE      Update the Transmission API Response Codes      
'                                                      PRINTPURCHASEORDER                  Prints an Existing Purchase Order      
'                                                      DELETEPURCHASEORDER                  Deletes an existing Purchase Order
'                                                      SHORTCLOSEPO                        Short Closes an existing Purchase Order
'                                                      FETCHDEFAULTVALUES                  Fetches deafulte values like supplier, on click of clear button


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ----------------------------------- Creating Server Side Objects --------------------------------------------
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

SET objDOMSERVERSIDE = Server.CreateObject("Microsoft.XMLDOM")
objDOMSERVERSIDE.load(Request)


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'------------------------------------- GET VALUES FROM HTTP ---------------------------------------------------      
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'Geting Header values from XML object passed from the browser..
ACTION                              = UCase(objDOMSERVERSIDE.selectSingleNode("//MODE").text)
lblNonMovingItem            = UCase(objDOMSERVERSIDE.selectSingleNode("//NONMOVINGITEMLABEL").text)


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'---------------------------------------- LOGIC FOR DIFFERENT MODES -------------------------------------------
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If ACTION = "INSERTPURCHASEORDER" Or ACTION = "MODIFYPURCHASEORDER" Or ACTION = "AUTHORISEPURCHASEORDER" Then
                  
      Set objPURCHASEORDER = Server.CreateObject("IIIPurchaseOrder.IIICallPurchaseOrder")
      strRETURNVALUE             = objPURCHASEORDER.UpdatePurchaseOrder(sCON, sPARTNERID, sLANGID, objDOMSERVERSIDE.xml, varPONumber, nERRORNO, strERRORMESSAGE)
      Set objPURCHASEORDER = NOTHING
      
      If nERRORNO > 0 Then
            strERRORMESSAGETEMP      = strERRORMESSAGE
            ACTION                        = "FETCH"
      End If
      
ElseIf ACTION = "DELETEPURCHASEORDER" Or ACTION = "PRINTPURCHASEORDER" Or ACTION = "SHORTCLOSEPO" _
      Or ACTION = "MODIFYTRANSMISSIONMODE" Then
                        
      Set objPURCHASEORDER = Server.CreateObject("IIIPurchaseOrder.IIICallPurchaseOrder")
      strRETURNVALUE             = objPURCHASEORDER.UpdatePurchaseOrder(sCON, sPARTNERID, sLANGID, objDOMSERVERSIDE.xml, varPONumber, nERRORNO, strERRORMESSAGE)
      Set objPURCHASEORDER = NOTHING
                        
      If nERRORNO > 0 Then
      
            strERRORMESSAGETEMP      = strERRORMESSAGE
            
            If ACTION = "PRINTPURCHASEORDER" Then varFlagForPrinting = "Y"
                              
            If ACTION = "DELETEPURCHASEORDER" Then
                  
                  'Clear all header and Detail fields execept and fetch the default values
                  
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Number").value                              = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Status").value                              = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Transmission_Date").value            = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Total_NoOfLines").value            = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Sales_Rep").value                              = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Remarks").value                              = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Time_Stamp").value                        = "00"
                  objDOMSERVERSIDE.selectSingleNode("//row/@CustomerIDF_Code").value                  = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Phone_Number").value                        = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Sales_Order_Number").value            = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Trans_Response").value                  = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Sales_Order_Number").value            = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Created_By").value                        = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Modified_By").value                        = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Created_On").value                        = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@Modified_On").value                        = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@PDI_EXISTS").value                        = ""
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Type").value                              = "M"
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Amount").value                              = "0.00"
                  objDOMSERVERSIDE.selectSingleNode("//row/@No_Of_Lines_Manual").value            = "0"
                  objDOMSERVERSIDE.selectSingleNode("//row/@No_Of_Lines_Automatic").value            = "0"
                  objDOMSERVERSIDE.selectSingleNode("//row/@No_Of_Lines_Customer").value            = "0"
                  objDOMSERVERSIDE.selectSingleNode("//row/@Print_Flag").value                        = varFlagForPrinting
                                    
                  ' Fetch default values ..
                  Call FetchPreferredWholesalerAndDeliveryTime()
                                    
                  objDOMSERVERSIDE.selectSingleNode("//row/@Vendor_Code").value                        = varSupplierCode
                  objDOMSERVERSIDE.selectSingleNode("//row/@Vendor_Description").value            = varSupplierDescription
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Transmission_Mode").value            = varPOTransmissionMode
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Delivery_Date").value                  = varPODeliveryDate
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Delivery_Time").value                  = varPODeliveryTime
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Date").value                              = varPODate
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Time").value                              = varPOTime
                  objDOMSERVERSIDE.selectSingleNode("//row/@PO_Transmission_Time").value            = varPOTransmissionTime
                  
            Else
                  ACTION      = "FETCH"
            End If
      End If
            
ElseIf ACTION = "TRANSMITPURCHASEORDERUPDATE" Then
                  
      Set objPURCHASEORDER = Server.CreateObject("IIIPurchaseOrder.IIICallPurchaseOrder")
      strRETURNVALUE             = objPURCHASEORDER.TransmitPurchaseOrderUsingXML(sCON, sPARTNERID, sLANGID, objDOMSERVERSIDE.xml, varPONumber, nERRORNO, strERRORMESSAGE)
      Set objPURCHASEORDER = NOTHING
      
      If nERRORNO > 0 Then
            strERRORMESSAGETEMP      = strERRORMESSAGE
            ACTION                        = "FETCH"
      End If

End If


'--------------------------------------------- F E T C H BLOCK -------------------------------------------------------->      
If ACTION = "FETCH" Then

      ' Clear the ML details before PO fetch, to avoid ML data passed to proc when 100 rows of update is called
      objDOMSERVERSIDE.selectSingleNode("//POMLDETAILS").text = ""

      ' Creating instance of PO Fetch Component
      SET objPURCHASEORDER      = Server.CreateObject("IIIPurchaseOrder.IIIFetchPurchaseOrder")
      strRETURNVALUE                  = objPURCHASEORDER.FetchPurchaseOrderDetails(sCON, sPARTNERID, sLANGID, objDOMSERVERSIDE.xml, varDaysForNonMovingItem, lblNonMovingItem, varPONumber, varDISCOUNTMESSAGE, varPOStatus, nERRORNO, strERRORMESSAGE)
      SET objPURCHASEORDER      = NOTHING
      
      If nERRORNO >= 0 Then
      
            strERRORMESSAGE            = strERRORMESSAGETEMP
      
            ' If there is discount for some items and the Po status is Open then display the discount message ..
            If Trim(varDISCOUNTMESSAGE) <> "" And CStr(varPOStatus) = "2" Then
                  strERRORMESSAGE = strERRORMESSAGE & "\n" & errObject.GetNthDescription(errFileName, 1431)
                  strERRORMESSAGE = Replace(strERRORMESSAGE, "%", "\n" & varDISCOUNTMESSAGE)
            End If
      
            Set objPODetails = Server.CreateObject("Microsoft.XMLDOM")
            objPODetails.loadXML(strRETURNVALUE)
            
            Set objDOMSERVERSIDE = objPODetails
      End If
      
      SET objPODetails = NOTHING
End If
'--------------------------------------------- END of F E T C H BLOCK -------------------------------------------------->      

'Begin :Interface 002:PO Transmission - Venki
If ACTION = "TRANSMITPURCHASEORDERFETCH" Then
      
      ' Creating instance of PO Fetch Component
      SET objPURCHASEORDER      = Server.CreateObject("IIIPurchaseOrder.IIIFetchPurchaseOrder")
      strRETURNVALUE                  = objPURCHASEORDER.FetchPurchaseOrderDetails(sCON, sPARTNERID, sLANGID, objDOMSERVERSIDE.xml, varDaysForNonMovingItem, lblNonMovingItem, varPONumber, varDISCOUNTMESSAGE, varPOStatus, nERRORNO, strERRORMESSAGE)
      SET objPURCHASEORDER      = NOTHING      

      ' If Fetch from Header was a Success do Detail Fetch
      If nERRORNO >= 0 Then
            
            Set objPODetails = Server.CreateObject("Microsoft.XMLDOM")
            objPODetails.loadXML(strRETURNVALUE)
            
            Set objDOMSERVERSIDE = objPODetails
      End If
      
      SET objPODetails = NOTHING

End If
'End :Interface 002:PO Transmission - Venki      


'----------------------------------------- DEFAULT VALUES FETCH BLOCK ------------------------------------------------>      
If ACTION = "FETCHDEFAULTVALUES" Then

            'Clear all header and Detail fields execept and fetch the default values
                  
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Number").value                              = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Status").value                              = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Transmission_Date").value            = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Total_NoOfLines").value            = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Sales_Rep").value                              = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Remarks").value                              = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Time_Stamp").value                        = "00"
            objDOMSERVERSIDE.selectSingleNode("//row/@CustomerIDF_Code").value                  = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Phone_Number").value                        = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Sales_Order_Number").value            = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Trans_Response").value                  = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Sales_Order_Number").value            = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Created_By").value                        = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Modified_By").value                        = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Created_On").value                        = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@Modified_On").value                        = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@PDI_EXISTS").value                        = ""
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Type").value                              = "M"
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Amount").value                              = "0.00"
            objDOMSERVERSIDE.selectSingleNode("//row/@No_Of_Lines_Manual").value            = "0"
            objDOMSERVERSIDE.selectSingleNode("//row/@No_Of_Lines_Automatic").value            = "0"
            objDOMSERVERSIDE.selectSingleNode("//row/@No_Of_Lines_Customer").value            = "0"
            objDOMSERVERSIDE.selectSingleNode("//row/@Print_Flag").value                        = "N"
                                    
            ' Fetch default values ..
            Call FetchPreferredWholesalerAndDeliveryTime()
                                    
            objDOMSERVERSIDE.selectSingleNode("//row/@Vendor_Code").value                        = varSupplierCode
            objDOMSERVERSIDE.selectSingleNode("//row/@Vendor_Description").value            = varSupplierDescription
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Transmission_Mode").value            = varPOTransmissionMode
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Delivery_Date").value                  = varPODeliveryDate
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Delivery_Time").value                  = varPODeliveryTime
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Date").value                              = varPODate
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Time").value                              = varPOTime
            objDOMSERVERSIDE.selectSingleNode("//row/@PO_Transmission_Time").value            = varPOTransmissionTime
End If


' ----------------------------- Save the Modified DOM Object -------------------------------------------------'
If Trim(strERRORMESSAGE) = "" Then
      strERRORMESSAGE = strERRORMESSAGETEMP
End If

objDOMSERVERSIDE.selectSingleNode("//ErrorNo").text                  = nERRORNO
objDOMSERVERSIDE.selectSingleNode("//ErrorMessage").text      = strERRORMESSAGE
      
objDOMSERVERSIDE.save(Response)
Response.End


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'      FUNCTION TO GET STATUS TO BE UPDATED OR TO SET BACK THE PREVIOUS STATUS AFTER AN INSERT/UPDATE FAILS STARTS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''      
Function GetOrSetStatusBasedOnMode(strACTION, strTYPE)
      Dim strRETURNVALUE
            
      strRETURNVALUE = ""
      If strTYPE = "GETPREVIOUSSTATUS" Then
            
            SELECT CASE strACTION
                  CASE  "INSERTPURCHASEORDER"                  : strRETURNVALUE = ""
                  CASE  "MODIFYPURCHASEORDER"                  : strRETURNVALUE = "2"
                  CASE  "DELETEPURCHASEORDER"                  : strRETURNVALUE = "2"
                  CASE  "AUTHORISEPURCHASEORDER"            : strRETURNVALUE = "2"
                  CASE  "PRINTPURCHASEORDER"                  : strRETURNVALUE = "3"
                  CASE  "SHORTCLOSEPO"                        : strRETURNVALUE = varStatusOfPOBeforeUpdate
                  CASE  "TRANSMITPURCHASEORDERUPDATE"      : strRETURNVALUE = varStatusOfPOBeforeUpdate
                  CASE  "MODIFYTRANSMISSIONMODE"            : strRETURNVALUE = "3"
            END SELECT
                  
      ElseIf strTYPE = "GETSTATUSFORUPDATE" Then
            
            SELECT CASE strACTION
                  CASE  "INSERTPURCHASEORDER"                  : strRETURNVALUE = "2"
                  CASE  "MODIFYPURCHASEORDER"                  : strRETURNVALUE = "2"
                  CASE  "DELETEPURCHASEORDER"                  : strRETURNVALUE = ""
                  CASE  "AUTHORISEPURCHASEORDER"            : strRETURNVALUE = "3"
                  CASE  "PRINTPURCHASEORDER"                  : strRETURNVALUE = "3"
                  CASE  "SHORTCLOSEPO"                        : strRETURNVALUE = 10
                  CASE  "TRANSMITPURCHASEORDERUPDATE"      : strRETURNVALUE = ""
                  CASE  "MODIFYTRANSMISSIONMODE"            : strRETURNVALUE = "3"
            END SELECT
                  
      End If
            
      GetOrSetStatusBasedOnMode = strRETURNVALUE
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'      FUNCTION TO GET STATUS TO BE UPDATED OR TO SET BACK THE PREVIOUS STATUS AFTER AN INSERT/UPDATE FAILS ENDS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''      

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'      FUNCTION TO GET THE FIRST PREFERRED WHOLESALER AND DEFAULT THE ORDER DATE/TIME & DELIVERY DATE/TIME STARTS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function FetchPreferredWholesalerAndDeliveryTime()

      varSupplierCode = Trim(Session("PRT016"))
      
      If varSupplierCode <> "" Then
      
            Dim arrParamList
            Redim arrParamList(3,3)            

            ' Input Parameter Partner_Id
            arrParamList(0,0) = "@Partner_Id"
            arrParamList(0,1) = "ANY_COUNT"
            arrParamList(0,2) = "adParamInput"
            arrParamList(0,3) = sPARTNERID
            
            ' Input Parameter Customer Vendor Code            
            arrParamList(1,0) = "@Customer_Vendor_Code"
            arrParamList(1,1) = "ANY_NAME"
            arrParamList(1,2) = "adParamInput"
            arrParamList(1,3) = varSupplierCode
            
            ' Input Parameter Language            
            arrParamList(2,0) = "Lang"
            arrParamList(2,1) = "ANY_FLAG"
            arrParamList(2,2) = "adParamInput"
            arrParamList(2,3) = sLANGID

            Set objPURCHASEORDER            = Server.CreateObject("IIIGenericDataAccess.IIIFetchGeneric")
            Set rstPURCHASEORDERHEADER      = Server.CreateObject("ADODB.RecordSet")
            Set rstPURCHASEORDERHEADER      = objPURCHASEORDER.FetchGenericDataAccessUsingSP(sCON, _
                                                                  "IIIFetch_Wholesaler_And_Delivery_Time_For_PO", arrParamList, _
                                                                  nERRORNO, strERRORMESSAGE)
                              
            strERRORMESSAGE                        = ""
            
            If CInt(nERRORNO) > 0 Then
            
                  varSupplierDescription  = rstPURCHASEORDERHEADER.fields("Customer_Vendor_Name")
                  varPOTransmissionMode      = rstPURCHASEORDERHEADER.fields("PO_Transmission_Mode")
                  varPODeliveryDate            = rstPURCHASEORDERHEADER.fields("Delivery_Date")
                  varPODeliveryTime            = rstPURCHASEORDERHEADER.fields("Delivery_Time")
                  varPODate                        = rstPURCHASEORDERHEADER.fields("Current_Date")
                  varPOTime                        = rstPURCHASEORDERHEADER.fields("Current_Time")
                  varPOTransmissionTime      = varPOTime
                        
                  rstPURCHASEORDERHEADER.Close()
                  Set rstPURCHASEORDERHEADER = Nothing
            End if
                  
            Erase arrParamList
            Set objPURCHASEORDER = Nothing
      End If
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'      FUNCTION TO GET THE FIRST PREFERRED WHOLESALER AND DEFAULT THE ORDER DATE/TIME & DELIVERY DATE/TIME ENDS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''      
%>

===validate.asp===

<!-- Version No : TRIAMUNIII1.0S_019825 -->
<%'@ language="VBScript" %>

<%
Response.Buffer = true
Response.Expires = -1
'Response.CacheControl  = "private"
Response.AddHeader "cache-control", "private"
'Response.AddHeader "pragma","no-cache"

Public Const SUCCESS = 99999
Public Const NATIVE_SQL_ERROR = 88888
Public Const IIISQL_VALIDATION_ERROR = 77777
Public Const IIIMTS_VALIDATION_ERROR = 66666

Public Const  nDELETED_ITEM_COLOUR                  = "Red"
Public Const  nCHAINED_ITEM_COLOUR                  = "#013399"
Public Const  nOUTOFSALE_ITEM_COLOUR            = "Red"
Public Const  nDEFAULT_ITEM_COLOUR                  = "Black"
Public Const  nDELETED_ITEM_COLOUR_GRID            = 255
Public Const  nCHAINED_ITEM_COLOUR_GRID            = 10040065
Public Const  nOUTOFSALE_ITEM_COLOUR_GRID      = 255
Public Const  nDEFAULT_ITEM_COLOUR_GRID            = 0
Public Const  MAXLENGTHFORPATIENTID                  = 100
Public Const  MAXLENGTHFORQUANTITY                  = 5
Public Const  MAXLENGTHVALUEFORQUANTITY            = 99999
Public Const  MAXLENGTHVALUEFORPRICE            = 9999999
Public Const  MAXLENGTHVALUEFORAMOUNT            = 999989900001

Public Const  nINACTIVE_PATIENT_COLOUR      = "Red"
Public Const  nACTIVE_PATIENT_COLOUR      = "Black"
Public Const  nINACTIVE_PATIENT_COLOUR_GRID      = 255
Public Const  nACTIVE_PATIENT_COLOUR_GRID   = 0

Public Const  NUMBEROFDECIMALPLACES                  = 2

Public Const BTNENABLEDCOLOR = "#003399"
Public Const BTNDISABLEDCOLOR = "#666666"
%>
<!-- #include file="qsort.asp" -->
<%
DIm Path, serverProcPath, strSecureStringHTTPS

            Path = Request.ServerVariables("script_name")
            dim c
            c = Instr(2,Path,"/")
            Path = Mid(Path,1,c)
            
      
            'Modified for SSL Implmentation
            strSecureStringHTTPS = Request.serverVariables("HTTPS")
            If strSecureStringHTTPS = "" Or UCase(strSecureStringHTTPS) = "OFF" Then
                  strSecureStringHTTPS = "http://"
            Else
                  strSecureStringHTTPS = "https://"
            End If
      
            serverProcPath =  strSecureStringHTTPS + Request.ServerVariables("server_name") +Path+"include/serverproc.asp"
            'serverProcPath = server.HTMLEncode(serverProcPath))
            
      if Session("Language") = "" then
            Session.Abandon
            Response.AddHeader "Refresh","0;URL="+Path+"Goto.asp?Link=No"      
            Response.End
      end if


Function Redirect( NewURL )
   If  Not IsEmpty( NewURL & "" )  Then
            Dim QuestionMark
          QuestionMark = Instr( NewURL, "?" )
            If QuestionMark = 0 Then
            Response.Redirect NewURL & "?" & NoCacheURL()
            Response.End
         Else
            Response.Redirect NEWURL & "&" & NoCacheURL()
            Response.End
         End If
      End If
End Function
   
Function NoCacheURL()
            On Error Resume Next
            
            'Randomize
            NoCacheURL = ".rnd=" & Server.URLEncode(now())
End Function


'Added by : Rajesh P.S
'Added on : 18/May/2001
'Purpose : Function to use along with timestamp varaible. Call this function on the timestamp fetched from the
'backend before storing it in the HTML/server side variant.

Function ConvertBinaryToString(bInput)
  Dim strInput, i
  For i = 1 To LenB(bInput)
    strInput = strInput & Right("00" & Hex(AscB(MidB(bInput, i, 1))), 2)
  Next
  ConvertBinaryToString = strInput
End Function

' Added by      : Murali P B
' Added on      : 13.01.2002
' Purpose      : Function to Format Time received using Request.Form from TimePicker ActiveX Control.
'                    Value Returned will be in HH:MM 24 Hour Format
Function GetTimeInRequiredFormat(strTimeValue)
      
      strTimeValue  = Trim(strTimeValue)
      Dim varTempPM
      
      If Mid(strTimeValue, 2, 1) = ":" Then strTimeValue = "0" & strTimeValue
      If Mid(strTimeValue, 5, 1) = ":" Then strTimeValue = Mid(strTimeValue,1,3) & "0" & Mid(strTimeValue,4,Len(strTimeValue))
      If UCase(Mid(strTimeValue, 10, 2)) = "PM" Then
            varTempPM = CDbl(Mid(strTimeValue,1,2))
            If varTempPM <> 12 Then varTempPM = CDbl(Mid(strTimeValue,1,2)) + 12
            strTimeValue = CStr(varTempPM) & Mid(strTimeValue,3,3)
      End If
      
      strTimeValue = Mid(strTimeValue,1,5)
      GetTimeInRequiredFormat = strTimeValue
      
End Function


'Added by Sandilyan R
'Added on 21 Feb 2002
'Purpose to Sort the given QCD array.
Function getQCDSortOrder(arrQCDSort)
      Dim rows,cols,i
            rows = UBOUND(arrQCDSort,1)
            cols = UBOUND(arrQCDSort,2)
            
      Dim arrNewQCDSort,sortString
            arrNewQCDSort = arrQCDSort
            
            QSort2 arrNewQCDSort, 1, 0, rows ' sort the entire array based on column 1

            sortString = ""
            
            For i = 0 to rows - 1
                  sortString  = sortString & arrNewQCDSort(i,0) & ","
            Next

            sortString  = sortString & arrNewQCDSort(rows,0)
            getQCDSortOrder      = sortString
End Function

'Added by Sandilyan R
'Added on 14 Mar 02
'Purpose get Permissions for Action buttons
Function GetAccessPermission(strSCREENCODE,strACTION)
      Dim ScreenAccess,bitFETCH,bitCREATE,bitMODIFY,bitAUTHORIZE,bitDELETE,bitSUBMIT,bitREVERSE
      Dim flagEnabled,flagDisabled
      
      flagEnabled = "ENABLED"
      
      if FromScreenSO = "SALESORDER" then
            flagDisabled = "DISABLED STYLE='BACKGROUND-COLOR: #666666'"
      else
            flagDisabled = "DISABLED"
      end if
      
      bitFETCH            = 1
      bitCREATE            = 2
      bitMODIFY            = 3
      bitAUTHORIZE      = 4
      bitDELETE            = 5
      bitSUBMIT            = 6
      bitREVERSE            = 7
      bitANY                  = -1
      
      strACTION       = UCASE(strACTION)
      ScreenAccess = SESSION(strSCREENCODE)
      
      IF ScreenAccess = "" THEN
            GetAccessPermission = flagDisabled
            EXIT FUNCTION
      END IF
      
      IF ( strACTION <> "ANY" ) THEN
            ScreenAccess = SESSION(strSCREENCODE)
            
            IF CINT(MID(ScreenAccess,Eval("bit"+strACTION),1)) > 0  THEN
                  GetAccessPermission = flagEnabled
            ELSE
                  GetAccessPermission = flagDisabled
            END IF      
      END IF
                  
      IF ( strACTION = "ANY" ) THEN                  
            
            IF ( MID(ScreenAccess,1,5)  AND  "11111" ) > 0  THEN            
                  GetAccessPermission = flagEnabled
            ELSEIF ( MID(ScreenAccess,6,5)  AND  "11111" ) > 0  THEN            
                        GetAccessPermission = flagEnabled
            ELSEIF ( MID(ScreenAccess,11,5)  AND  "11111" ) > 0  THEN            
                        GetAccessPermission = flagEnabled
            ELSE
                  GetAccessPermission = flagDisabled
            END IF      
      END IF      
End Function


' Added by      : Murali P B
' Added on      : 21.01.2002
' Purpose      : Function to get the Current Date and Time
Public Function GetServerDateAndTime(strDateOrTime, strVariable)
      If UCase(strDateOrTime) = "DATE" Then
            ' Get Current Date in 104 format
            If Trim(strVariable) = "" Then
                  strVariable      = Day(Now()) & "." & Month(Now()) & "." & Year(Now())
                  ' Setting Date in Right Format
                  If Mid(strVariable, 2, 1) = "." Then strVariable = "0" & strVariable
                  If Mid(strVariable, 5, 1) = "." Then strVariable = Mid(strVariable,1,3) & "0" & Mid(strVariable,4,Len(strVariable))
            End If
      ElseIf UCase(strDateOrTime) = "TIME" Then
            ' Get Current Date in 108 format
            If Trim(strVariable) = "" Then
                  strVariable      = Time()
                  strVariable = Left(strVariable, 5)
            End If
      End If
End Function

' Added by      : Venkataramanan M
' Added on      : 04.04.2002
' Purpose      : Function to decode encoded +
Public Function decodePlus(strValue)
      decodePlus = replace(strValue,"$*$","+")
End Function

' Added by       : Venkataramanan M
' Added on       : 13.08.2002
' Purpose       : Function to set Item Description colour in Table.js tables
Public function SetItemColour(TypeOfTable,TypeOfItem)

      if ( TypeOfTable = "HEADERCONTROL" or TypeOfTable = "REGULARTABLE" or TypeOfTable = "XMLTABLE" ) then
            if ( TypeOfItem = "DELETEDITEM" ) then
                  nColourToSet = nDELETED_ITEM_COLOUR
            elseif ( TypeOfItem = "CHAINEDITEM" ) then
                  nColourToSet = nCHAINED_ITEM_COLOUR
            elseif ( TypeOfItem = "OUTOFSALEITEM" ) then
                  nColourToSet = nOUTOFSALE_ITEM_COLOUR
            else
                  nColourToSet = nDEFAULT_ITEM_COLOUR      
            end if      
      elseif ( TypeOfTable = "GRID" ) then
            if ( TypeOfItem = "DELETEDITEM" ) then
                  nColourToSet = nDELETED_ITEM_COLOUR_GRID
            elseif ( TypeOfItem = "CHAINEDITEM" ) then
                  nColourToSet = nCHAINED_ITEM_COLOUR_GRID
            elseif ( TypeOfItem = "OUTOFSALEITEM" ) then
                  nColourToSet = nOUTOFSALE_ITEM_COLOUR_GRID
            else
                  nColourToSet = nDEFAULT_ITEM_COLOUR_GRID
            end if            
      end if            
                  
            Response.Write "STYLE='COLOR:" & nColourToSet & "'"
end function

' Added by       : Kiran Babu.D
' Added on       : 29.08.2003
' Purpose       : Function to get Item Description colour
Public Function IIIGetItemDescriptionColour(Deleted_Item_Flag, Chained_Item_Flag, OutOfSale_Item_Flag)
      If  (NOT IsNull(Trim(Deleted_Item_Flag))) And Trim(Deleted_Item_Flag) = "D"  Then
            Item_Flag = "DELETEDITEM"
      ElseIf  (NOT IsNull(Trim(Chained_Item_Flag))) And Trim(Chained_Item_Flag) <> "" Then
             Item_Flag = "CHAINEDITEM"
      ElseIf (NOT IsNull(Trim(OutOfSale_Item_Flag))) And Trim(OutOfSale_Item_Flag) = "H" Then
             Item_Flag = "OUTOFSALEITEM"
      Else
             Item_Flag = ""      
      End If
      
      IIIGetItemDescriptionColour      = Item_Flag
End Function

' Added by       : Chandrasekar S
' Added on       : 01.07.2003
' Purpose       : Function to Round a value to it uppervalue (e.g 1.125 to 1.13). This behaviour is same as javascript round
Public Function IIIRoundUp(dInputValue)

    Dim arrValue
    Dim dAfterDecimalValue
   
    ' 3.6 + 23.65 + .55 + 0.1-27.9 - In VB this calc. gives an exponential no.
    ' Exponentials were not handled in this function
    If InStr(CStr(dInputValue), "E") >= 1 Then
        dInputValue = Round(dInputValue, 2)
    End If

    If InStr(dInputValue, ".") = 0 Then
        IIIRoundUp = dInputValue
        Exit Function
    End If
   
    arrValue = Split(dInputValue, ".")
   
    If CStr(arrValue(1)) = "" And Len(CStr(arrValue(1))) = 2 Then
        IIIRoundUp = Round(CDbl(dInputValue), 2)
        Exit Function
    End If
   
    If Len(CStr(arrValue(1))) >= 3 Then
        dAfterDecimalValue = Mid(CStr(arrValue(1)), 1, 3)
        If InStrRev(dAfterDecimalValue, "5") = "3" Then
            dAfterDecimalValue = CStr(dAfterDecimalValue) + CStr(5)
            dInputValue = CStr(arrValue(0)) + "." + CStr(dAfterDecimalValue)
        End If
    End If
   
    IIIRoundUp = Round(CDbl(dInputValue), 2)

End Function



%>
<SCRIPT language="JavaScript" >
var encryptionsysparam = '<%=Session("ASP017")%>';
var Encryptionpassword      = '<%=Session("Encryptionpassword")%>';
var commonjsUserID            = '<%=Session("UserID")%>';

function InvokeServerProc(strMethodName,strParameters,strStoredProcedures)
{

      //This is to trigger server side method without reloading the page.
      if ( typeof(strParameters) == "undefined" )
      var strParameters = "";
      
      var QueryString = "";
            QueryString = QueryString + "<QUERYSTRING>";
            QueryString = QueryString + "<METHODNAME></METHODNAME>";
            QueryString = QueryString + "<PARAMETERS></PARAMETERS>";
            //Changes Added By Enian For CR BUG ID TRIAMUNIII1.0S_014098
            QueryString = QueryString + "<STOREDPROCEDURE></STOREDPROCEDURE>";
            //Changes Added By Enian For CR BUG ID TRIAMUNIII1.0S_014098
            QueryString = QueryString + "</QUERYSTRING>";
            
      var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
      var node=null;
            objXMLDoc.loadXML(QueryString);
      
      node = objXMLDoc.selectSingleNode("//METHODNAME");
      node.text  = strMethodName;
      
      
      node = objXMLDoc.selectSingleNode("//PARAMETERS");
      //Changes Added By Enian For CR BUG ID TRIAMUNIII1.0S_014098
      if ( typeof(strParameters) == 'object' )
            node.text  = strParameters.xml;
      else      
            node.text = strParameters;
            
      var strSP ='';
      if ( typeof(strStoredProcedures) == 'undefined' )
             strSP = '';
      else      
             strSP = strStoredProcedures;
            
      node = objXMLDoc.selectSingleNode("//STOREDPROCEDURE");
      node.text  = strSP;
      
      //Changes Added By Enian For CR BUG ID TRIAMUNIII1.0S_014098
      
      
      
      
      if (strMethodName == "")
      {
            alert("Please provide MethodName");
            return null;
      }
      
      var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      
      var serverPath = "<%=serverProcPath%>"
      xmlhttp.Open("POST",serverPath, false);
      xmlhttp.Send(objXMLDoc);

      if ( xmlhttp.statusText == "OK" )
      {
            objResultXML = xmlhttp.responseXML;
            if (objResultXML.xml == "" )
            {
                  return null;
            }
            else
            {      
                  if ( typeof(strStoredProcedures) != 'undefined' )
                        return objResultXML;
                  else
                        return objResultXML.xml;
            }      
      }
      else
      {
            alert(xmlhttp.statusText);
            return null;
      }      

}

//To trap F5 function and mouse down key - sans 02.Mar.02
document.attachEvent("onkeydown",fun_keytrap);

function fun_keytrap()
{
      var windowname;
      if (window.event.keyCode ==  116)
      {
            event.keyCode = ""
            window.event.returnValue=false;
      }
      // To trap Esc Key FIx for TRIAMUNIII1.0S_010817
      else if(window.event.keyCode == 27)
      {
            window.event.returnValue=false;
      }
      if (window.event.keyCode == 87)      //Ctrl + W (Logoff)
      {      
            if (window.event.ctrlKey)
            {            
                  windowname = parent.window.name;

                  if( windowname.toUpperCase() == "FRMPAGE")
                  {
                        if(window.confirm(getErrorMessage('1451')) == true)
                        {
                              window.event.returnValue      = true;
                              parent.window.parent.window.close();
                        }
                        else
                        {
                              window.event.keyCode = "";
                              window.event.returnValue      = false;
                        }
                        return;
                  }
                  if( windowname.toUpperCase() == "LOGIN")
                  {
                        if(window.confirm(getErrorMessage('1451')) == true)
                        {
                              window.event.returnValue      = true;
                              parent.window.close();
                        }
                        else
                        {
                              window.event.keyCode = "";
                              window.event.returnValue      = false;
                        }
                        return;
                  }      
            }
      }
      
}

//function to get the patient hdr
//added by sans on 12/june/2002
function getPatientHdr(strParameters,windowSizeProperties)
{
      var Parameter            = strParameters.split("@@")
      var intPatientId      = Parameter[0]
      
      // Mandatory check for the Patient Header
      if (Trim(intPatientId) == '') return false;

      if (parseFloat(intPatientId.length) < 19 && parseFloat(intPatientId) > 2147483647)
      {
            alert(getErrorMessage('16'))
            return false;      
      }
      
      var regExpr;
      regExpr = /[\\?"<>|`~!@#$&]/ig;
      
      if (regExpr.test(intPatientId))
      {
            alert(getErrorMessage('263'))
            return false;
      }

      var ArgumentCount      = intPatientId.split(",")
      var strInput            = intPatientId + "@@" + ArgumentCount.length
            
      var resultString = InvokeServerProc("FetchPatientHdr", strInput)
      var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
      var nodes =null;
      
      
      //parse the string to get the data
      objXMLDoc.loadXML(resultString);
            
      nodes =  objXMLDoc.selectNodes("//OUTPARAM")

      var len = nodes.length;
      var errno = nodes[len - 2].text;
      var errmsg = nodes[len - 1].text;
      
      if ( len > 2 )
      {      
            var PasswordReturn;
                        
            //For patient pwd check
            if ( (parseInt(errno) > 0 ) && (nodes[4].text == "N" ) )
            {
                  var strPatientId      = intPatientId
                  var varParameters      = new Array()
                  varParameters[0]      = nodes[2].text
                  varParameters[1]      = nodes[3].text
                  varParameters[2]      = true
                  varParameters[4]      = nodes[5].text
                  PasswordReturn            = window.showModalDialog("PatientPassword.asp?patientid="+strPatientId,varParameters,"center=yes;menubar=no;location=no;toolbar=no;scrollbars=yes;top=25;left=25;dialogWidth=275pt;dialogHeight=210pt;resizable=Yes;help:no;status:no;")

                  if (!PasswordReturn)            
                  {
                        //clear fields
                        nodes[0].text = ""
                        nodes[2].text = ""
                        nodes[3].text = ""
                        nodes[1].text = ""
                        nodes[4].text = ""
                  }
            }
      }
      else if ((len = 2) && (parseInt(errno) == -100))
      {
            if(typeof(windowSizeProperties)!="undefined")
            {
                  var windowSizeProperties   = 'menubar=no,location=no,toolbar=no,resizable=yes,scrollbars=no,top=150,left=30,width=920,height=400'
                  window.open(Parameter[1],"MedicationDetail",windowSizeProperties);      
            }
            else
                  launchhelp1(Parameter[1]);                        
                  return false
      }            
      return nodes;
}


//function to get the error msg from file
//added by sans on 12/june/2002
//Added for the defect TRIAMUNIII1.0S_010692 -- Sathish
function getErrorMessage(strParameters)
{
      var resultString = InvokeServerProc("GetErrorMsg()",strParameters)      


      var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
      var nodes =null;
      
      //parse the string to get the data
      objXMLDoc.loadXML(resultString );
            
      nodes =  objXMLDoc.selectSingleNode("//DETAILPART")
      
      return nodes.text
}

//function to get the PO Number for the Given sales order
//added by sankar on 10/july/2002
//Added for the defect TRIAMUNIII1.0S_009559
function getPONumber(strSONumber)
{
      var resultString = InvokeServerProc("GetPONumber()", strSONumber)      
      var PONum
      var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
      var nodes =null;
      //parse the string to get the data
      objXMLDoc.loadXML(resultString);
      nodes =  objXMLDoc.selectNodes("//OUTPARAM")
      var len = nodes.length;
      var errno = nodes[len - 2].text;
      var errmsg = nodes[len - 1].text;
      
      if (parseInt(errno) > 0)      
            PONum=nodes[0].text            
      else
            PONum=""      
            
      return PONum
}

function getStandardPosology(strPosologyCode)
{
      var resultString = InvokeServerProc("GetStandardPosology()", strPosologyCode)
      var PosologyText
      var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
      var nodes =null;
      
      //parse the string to get the data
      objXMLDoc.loadXML(resultString);
      nodes =  objXMLDoc.selectNodes("//OUTPARAM")

      var len = nodes.length;
      var errno = nodes[len - 2].text;
      var errmsg = nodes[len - 1].text;

      if (parseInt(errno) > 0)      
            PosologyText=nodes[0].text
      else
            PosologyText=""      
            
      return PosologyText
}

function getItemDetails(strItemInput)
{
      var resultString = InvokeServerProc("GetItemDetails", strItemInput)      
      var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
      var nodes =null;
      objXMLDoc.loadXML(resultString);
      nodes =  objXMLDoc.selectNodes("//OUTPARAM")
      return nodes
}

function checkMarquee()
{
      var objMarqueeList = null;

      if ( event.type == "unload" )
      {
            //code Change for TRIAMUNIII1.0S_012467
            try
            {
            if ( typeof(window.opener) == "object" )
                  objMarqueeList = window.opener.document.getElementsByTagName("MARQUEE")                  
            }
            catch(objException)
            {
            }
            //End of Code Change for TRIAMUNIII1.0S_012467
      
      }
      else
      {      
            //code Change for TRIAMUNIII1.0S_012467
            try
            {      
            if ( typeof(window.opener) == "object" )
            {
                  var objMarqueeList = window.opener.document.getElementsByTagName("MARQUEE")
                  var cntt = 0
                        for (cntt = 0; cntt <= objMarqueeList.length - 1; cntt++)
                        {
                              eval(objMarqueeList.item(cntt)).stop();
                        }
                  
                  if (objMarqueeList.length > 0 )      
                        window.attachEvent("onunload",checkMarquee);      
            }
            
            objMarqueeList = window.document.getElementsByTagName("MARQUEE")
            }
            catch(objException)
            {
            }      
            //End of code Change for TRIAMUNIII1.0S_012467
      }

      if (objMarqueeList == null) return;  
      
      for (cntt = 0; cntt <= objMarqueeList.length - 1; cntt++)
      {
            eval(objMarqueeList.item(cntt)).start();
      }
}
window.attachEvent("onload",checkMarquee);
var timeinterval = "";

function starttimer()
{
      Cookdel(0)
      timeinterval = window.setInterval("starttimer()", 7200000);
}
</SCRIPT>


===session_manager.asp===

<%
dim      strSMGRProcedureName,      arrSMGRParamList, Triamun_Session_Filled, SMGRSessionId, nSMGRERRORNO,      strSMGRERRORMESSAGE      
      
dim objSMGRDICTIONARY,rstSMGRSESSION, ObjSMGRFetchGeneric, varSMGRPARAMINPUT

Triamun_Session_Filled = 0


Function ReadSessionKey()       
      ReadSessionKey = Request.Cookies("triamunCookie")("SMGRSessionId")
End Function

'Sub WriteSessionKey(sSessionKey)       
'      Response.Cookies("triamunCookie")("SMGRSessionId") = sSessionKey
'      Response.Cookies("triamunCookie").Path = "/"
'End Sub

      'IIICreateSession()
public      Function Triamun_Session(SessionParam)
            ' If the session value requested has already been fetched in this page then give it else fetch all the values
            ' and cache. return the requested value      
            
            'response.write Triamun_Session_Filled
            'response.end

            If Triamun_Session_Filled <> 0 then
                Triamun_Session = objSMGRDICTIONARY.Item(SessionParam)
                  Exit Function
            End If      

            Set objSMGRDICTIONARY            =      Server.CreateObject("Scripting.Dictionary")                         
            Set ObjSMGRFetchGeneric            =      Server.CreateObject("IIIGenericDataAccess.IIIFetchGeneric")       
            Set rstSMGRSESSION                  =      Server.CreateObject("ADODB.RecordSet")
            varSPName                              =      "IIIFetch_user_Session"
      
            ReDim varSMGRPARAMINPUT(0, 3)
            
            SMGRSessionId = ReadSessionKey()
            
      
            If Trim(SMGRSessionId) = "" Then
                   Triamun_Session = ""
                   Exit Function
            End If
            
            varSMGRPARAMINPUT(0, 0) = "@Session_Id"
            varSMGRPARAMINPUT(0, 1) = "ANY_ERRMSG"
            varSMGRPARAMINPUT(0, 2) = "adParamInput"
            varSMGRPARAMINPUT(0, 3) = SMGRSessionId
            
'            sASPCONNECTION      =      ""
            nSMGRERRORNO            =      0
            strSMGRERRORMESSAGE      =      ""
                  
            Set rstSMGRSESSION = ObjSMGRFetchGeneric.FetchGenericDataAccessUsingSP(Cstr(Application("strCMNConn")), Cstr(varSPNAME), varSMGRPARAMINPUT, nSMGRERRORNO, strSMGRERRORMESSAGE)

            If nSMGRERRORNO > 0 Then
                  rstSMGRSESSION.MoveFirst
                  While Not rstSMGRSESSION.EOF

                        'varSMGRSessionId            = rstSMGRSESSION("Session_Id")
                        'varPARTNERID            = rstSMGRSESSION("Partner_Id")
                        'varPARTNERNAME            = rstSMGRSESSION("Partner_Name")
                        'varPARTNERADMINNAME = rstSMGRSESSION("Partner_Admin_Name")
                        'varPARTNERTYPE            = rstSMGRSESSION("Partner_Type")
                        'varPARTNERLICENCE      = rstSMGRSESSION("Partner_Licence")
                        'varPARTNERKANTON      = rstSMGRSESSION("Partner_Kanton")
                        'varSOFTWARELICENCE      = rstSMGRSESSION("Software_License")
                        'varSHOWGALDATALERT      = rstSMGRSESSION("Show_Galdat_alert")
                        'varLOGINLANGUAGE      = rstSMGRSESSION("Login_Language")
                        'varPARTNERDATABASE      = rstSMGRSESSION("Partner_Database")
                  
                                                
                        Call objSMGRDICTIONARY.Add("nPartnerId",            Cstr("" & rstSMGRSESSION("Partner_Id")))
                        Call objSMGRDICTIONARY.Add("strPartnerName",      Cstr("" & rstSMGRSESSION("Partner_Name")))
                        Call objSMGRDICTIONARY.Add("strPartnerAdminName",Cstr("" & rstSMGRSESSION("Partner_Admin_Name")))
                        Call objSMGRDICTIONARY.Add("strPartnerType",      Cstr("" & rstSMGRSESSION("Partner_Type")))
                        Call objSMGRDICTIONARY.Add("License_Type",            Cstr("" & rstSMGRSESSION("Partner_Licence")))
                        Call objSMGRDICTIONARY.Add("strPartnerKanton",      Cstr("" & rstSMGRSESSION("Partner_Kanton")))
                        Call objSMGRDICTIONARY.Add("strSoftwareLicense",Cstr("" & rstSMGRSESSION("Software_License")))
                        'Call objSMGRDICTIONARY.Add("nPartnerId",            Cstr("" & rstSMGRSESSION("Show_Galdat_alert")))
                        Call objSMGRDICTIONARY.Add("Language",                  Cstr("" & rstSMGRSESSION("Login_Language")))                        
                        Call objSMGRDICTIONARY.Add("TransactionDB",            Cstr("" & rstSMGRSESSION("Partner_Database")))
                        Call objSMGRDICTIONARY.Add("Encryptionpassword",Cstr("" & rstSMGRSESSION("Encryptionpassword")))
                        Call objSMGRDICTIONARY.Add("UserId",                  Cstr("" & rstSMGRSESSION("Partner_user_Id")))
                        Call objSMGRDICTIONARY.Add("strUserName",            Cstr("" & rstSMGRSESSION("Partner_user_Name")))

                        rstSMGRSESSION.MoveNext
                        
                  Wend
            End if      

            Set ObjSMGRFetchGeneric = Nothing
            Set rstSMGRSESSION = Nothing
            
            'If objSMGRDICTIONARY.Item("Language") = "G" Then
            '      Call objSMGRDICTIONARY.Add("FEErrMsgFile",      "../include/German/FEErr_g.Msg")
            'ElseIf objSMGRDICTIONARY.Item("Language") = "F" Then
            '      Call objSMGRDICTIONARY.Add("FEErrMsgFile",      "../include/French/FEErr_f.Msg")
            'ElseIf objSMGRDICTIONARY.Item("Language") = "E" Then
            '      Call objSMGRDICTIONARY.Add("FEErrMsgFile",      "../include/English/FEErr_e.Msg")
            'End If

            Triamun_Session_Filled = "1"

            If objSMGRDICTIONARY.Exists(SessionParam) Then
                  Triamun_Session = objSMGRDICTIONARY.Item(SessionParam)
            Else
                  Triamun_Session = ""
            End If            
            Triamun_Session = objSMGRDICTIONARY.Item(SessionParam)
            
      End Function

%>

Kindly explain me in detail as I am new to asp...

Regards

and Thanks for help in anticipation

Uma
0
Comment
Question by:umaexpert
1 Comment
 
LVL 28

Accepted Solution

by:
sybe earned 20 total points
Comment Utility
Come on, no one is going to read through 4000 lines of code. Please delete it and make it available for download. This is pointless.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now