﻿var rblDidAdvancePayment;  
var rblDidPayment;
var lbTransportToTrip;
 function setEneble(sender,idRblDidAdvancePayment,idRblDidPayment,idLbTransportToTrip){
     
       
         var options = sender.options; 
         var noValue = true;
         rblDidAdvancePayment =  document.getElementById(idRblDidAdvancePayment);
         rblDidPayment = document.getElementById(idRblDidPayment);
         lbTransportToTrip = document.getElementById(idLbTransportToTrip);
         
          for (var i = options.length - 1; i > 0 ; i--)
          {
                    
                
              if (options[i].selected == true)
                {
                   
                    noValue = false;
                    
                }
          }
          
         rblDidAdvancePayment.disabled = noValue;
         rblDidPayment.disabled = noValue;
     
     }
     
     var xmlHttp = null;        
     
     window.onload = function() {            
        loadXmlHttp();        
     }     
     
        
     function selectChildren(sender) {            
        //Please use your Service's host URL   
        
        var url = window.location.protocol + "//" + window.location.host + "/system/controls/Ajax.asmx/GetChildrenValue";

         
        //var parentValue = sender.children[sender.selectedIndex].value;
        
        var parentValue = "";
        
        var options = sender.options;
        
        for (var i = options.length - 1; i > 0 ; i--)
          {
              if (options[i].selected == true)
                {
                    parentValue += options[i].value + "|";
                    
                    
                }
          }
 
                   
        sendRequest(url, parentValue);        
     }  
           
     function loadXmlHttp() {            
        if (window.XMLHttpRequest) { 
        // IE7, Mozilla, Safari, Opera, etc.                
            xmlHttp = new XMLHttpRequest();            
        } 
        else if (window.ActiveXObject) {                
        try {                    
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
        // IE 5.x and 6                
        }                
        catch (e) { }            
        }        
     }        
     function sendRequest(url, parentValue) 
     {            
        if (xmlHttp) 
        {                // Open HTTP connection to url. 
           xmlHttp.open("POST", url, true); // 
           //true = async                
          // Define the callback function for async call
          xmlHttp.onreadystatechange = onCallback;
          // Specify form data in request body
         xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); 
                                  // Send request without any additional parameters                
         xmlHttp.send("parentValue=" + parentValue);            
         }        
    }
 
    function onCallback() {
     // Check for the completed status            
     if (xmlHttp.readyState == 4) {                
        // Check for successful server response                
         if (xmlHttp.status == 200) {                    
                fillDDL(xmlHttp.responseXML.documentElement);                
          }                
          else {                    
           // HTTP error                    
           alert('Error: ' + xmlHttp.status);                
          }            
      }          
    }        
    
    function fillDDL(xml) 
    {
      lbTransportToTrip.innerHTML = "";
      
      if(xml.text!=undefined)
      {
      if (xml.text == "") {          
          lbTransportToTrip.options.add(new Option("Brak transportu do wyjazdu", "0"));
          lbTransportToTrip.disabled = true; 
         return;            
      }
      var a = xml.text.split("|");            
      var idName;
        for (i = 0; i < a.length; i++) {                
        
             idName = a[i].split(";");
              if(idName[0]!=""){
                 lbTransportToTrip.options.add(new Option(idName[1], idName[0]));
                 lbTransportToTrip.disabled = false;
                }
                 }     
                 
  
     }
     else if(xml.textContent!=undefined)
     {
     
     if (xml.textContent == "") {          
          lbTransportToTrip.options.add(new Option("Brak transportu do wyjazdu", "0"));
          lbTransportToTrip.disabled = true; 
         return;            
      }
      var a = xml.textContent.split("|");            
      var idName;
        for (i = 0; i < a.length; i++) {                
        
             idName = a[i].split(";");
             
             if(idName[0]!=""){
                lbTransportToTrip.options.add(new Option(idName[1], idName[0]));
                lbTransportToTrip.disabled = false;
             }
          }   
     
     
     }
  } 
  
  
  /*zapamietaj listbox ttt*/       
  
  function RemeberSelectedItem(hfId,lstbId){
  
    if(document.getElementById(lstbId).selectedIndex!=-1){
        var id = document.getElementById(lstbId).options[document.getElementById(lstbId).selectedIndex].value;
        document.getElementById(hfId).value = id;
    }
  }
         
