﻿
/*Method to display and hide the contents of Left Navigation UDI based on the menu item selected.*/
function ShowLeftNav(obj)
            {
                    switch(obj)
                    {
                    case "intlc":
                      ShowMenu('icustom','isubscriber','itriangle','i-udi');
                      ShowBackgroundChange('intlcustom');
                      break;
                    case "intls":
                      ShowMenu('icustom','isubscriber','itriangle','i-udi');
                      ShowBackgroundChange('intlsubscriber');
                      break;
                    case "nac":
                      ShowMenu('nacustom','nasubscriber','natriangle','na-udi');
                      ShowBackgroundChange('namericacustom');
                      break;
                    case "nas":
                      ShowMenu('nacustom','nasubscriber','natriangle','na-udi');
                      ShowBackgroundChange('namericasubscriber');
                      break;
                    default:
                      ShowMenu('icustom','isubscriber','itriangle','i-udi');
                      ShowBackgroundChange('intlcustom');
                    }
            }
/*Function to hide and show the contents of Left Navigation UDI*/
function ShowMenu(obj1,obj2,obj3,obj4)  
       {
        var arrC = new Array('icustom','isubscriber','nacustom','nasubscriber');
        var arrP = new Array('itriangle','natriangle');
        var arrA = new Array ('i-udi','na-udi')
        for (i = 0; i < arrC.length; i++)
         {
             if ((arrC[i] == obj1) || (arrC[i] == obj2))
             {
               document.getElementById(arrC[i]).style.display ='block';
             }
             else
             {
              document.getElementById(arrC[i]).style.display ='none';
             }
         } 
         for (i = 0; i < arrP.length; i++)
         {
             if ((arrP[i] == obj3))
             {
               document.getElementById(arrP[i]).src = "/images/triangle_yellow.gif";
             }
             else
             {
              document.getElementById(arrP[i]).src = "/images/triangle_white2.gif";
             }
         }
          for (i = 0; i < arrA.length; i++)
         {
             if ((arrA[i] == obj4))
             {
               document.getElementById(arrA[i]).style.color = "#ffcc66";  
             }
             else
             {
              document.getElementById(arrA[i]).style.color = "#FFFFFF";  
             }
         }
      }
 /*Changes the Background Image of the Left Navigation in the UDI*/            
function ShowBackgroundChange(obj1)
      {
      var arrD = new Array('intlcustom', 'intlsubscriber', 'namericacustom','namericasubscriber');
      for (i = 0; i < arrD.length; i++)
         {
             if ((arrD[i] == obj1))
             {
                  document.getElementById(arrD[i]).style.backgroundImage = "url(/images/orange_highlight.gif)"; 
             }
            else
            {
                 document.getElementById(arrD[i]).style.backgroundImage = "url(/images/pixel_grey.gif)"; 
            }
                
        }
      
      }
      /* Function to open the PopUpLookUpUDI page and display its content*/
function doLookUp(ddlField,ddlOperator,txtValue,rowIndex,intlna)
    {
        var winOptions = 'scrollbars=yes,resizable=no,fullscreen=no,channel mode=no,status=no,toolbar=no,menubar=no,location=no,directories=no,height=400,width=400'
        var dField = document.getElementById(ddlField);
        var dFieldValue = dField.options[dField.selectedIndex].value;
        var dFieldArray = dFieldValue.split("|");
        var dFieldIndex = dFieldArray[0];
        var target = 'LookUp';
        var newwindow = window.open("/PopUpLookUpUDI/"+intlna+"/"+ dFieldIndex + "/" + txtValue+ "/" + rowIndex + "/", target, "width=500,height=400,left=0,top=0,scrollbars=no,toolbar=no,scrollbars=yes,resizable=no");
        if (window.focus)
         {
            newwindow.focus();
         }
    }
     /* Function to Empty the text box value when the respectice field value is selected*/
     function ChangeOptionsOperator(cmbOpt,txtVal,hdnField)
    {
        var dFieldValue = cmbOpt.options[cmbOpt.selectedIndex].value;
        hdnField.value = dFieldValue;
        
        if((dFieldValue == "") || (dFieldValue == "null") || (dFieldValue == "not null") )
        txtVal.value = "";
    }
    
    /*Function to assign the respective values to the Operators selected.*/
    function ChangeDisplayFieldValue( cmbField, cmbOpt, txtVal,hdnField, btnPop)
    {
        var dFieldValue = cmbField.options[cmbField.selectedIndex].value;
        
        var arrValue = dFieldValue.split("|");
        var dataType = arrValue[1];
        var btnTip = arrValue[2];
     
        ClearOptions(cmbOpt);
        
        if(dataType.toLowerCase() == 'number')
        {
            PopulateNumericOperator(cmbOpt);
        }
        else
        {
            PopulateVarchar2Operator(cmbOpt);
        }
        hdnField.value = "";
        txtVal.value = "";
        btnPop.title  = "available : "+btnTip;
    }
    /*Populates the respective Varchar Operators*/
    function PopulateVarchar2Operator( cmbOpt)
    {
        ClearOptions(cmbOpt);
        var optionIndex = 0;
        var arrIndex;
        for(arrIndex = 0;arrIndex < 54 ;arrIndex = arrIndex+3)
        {
            if(ListOperatorsNumericVarchar[arrIndex + 2] == 'V')
            {
                var value = ListOperatorsNumericVarchar[arrIndex];
                var text = ListOperatorsNumericVarchar[arrIndex + 1];
                var option = new Option(text,value); 
                
                cmbOpt.options[optionIndex] = option;
                
                optionIndex ++;
            }
        }
    }
    /*Populates the respective Numeric Operators.*/
     function PopulateNumericOperator(cmbOpt)
    {
        ClearOptions(cmbOpt);
        var optionIndex = 0;
        var arrIndex;
        for(arrIndex = 0;arrIndex < 54 ;arrIndex = arrIndex+3)
        {
            if(ListOperatorsNumericVarchar[arrIndex + 2] == 'N')
            {
                var value = ListOperatorsNumericVarchar[arrIndex];
                var text = ListOperatorsNumericVarchar[arrIndex + 1];
                var option = new Option(text,value); 
                cmbOpt.options[optionIndex] = option;
                optionIndex ++;
            }
        }
       
    }
    /*Clears the content of the Operator Dropdown*/
    function ClearOptions(cmbOpt)
    {
        var totalOptions = cmbOpt.options.length;
        for (var loop=0; loop <totalOptions; loop++) 
        {
            cmbOpt.options[loop] = null; // remove the option
        }
    }
  /*Function to display the items present in database for a particular field. */  
   function lookupOnMouseOver(cmbField,btnPop)
   {
   var dFieldValue = cmbField.options[cmbField.selectedIndex].value;
    var arrValue = dFieldValue.split("|");
    var dataType = arrValue[1];
    var btnTip = arrValue[2];
    btnPop.title  = "available : "+btnTip;
   }

