var savedhtml = new Array();
var savedattachment = new Array();
var fielddisable = new Array();

function determineSkipQuestions(attrib, properties, skip, attribtype)
{
  var propertyarray = properties.split("|");
  var skiparray = skip.split("|");
  var disabledarray = new Array();
  
  if (attribtype == "radio")
  {
    var selectedvalue = attrib.value;
  }
  else
  {
    var selectedvalue = attrib.options[attrib.selectedIndex].value;
  } 
  
  for (var i=0;i<propertyarray.length; i++)
  {
    if (skiparray[i] != "")
    {
      var skips = skiparray[i].split(",");
    }
    else
    {
      var skips = new Array();
    }
    
    for (var j =0;j<skips.length;j++)
    {
      if (skips[j] != "")
      {
        var skipstring = skips[j].split(".");
        if (selectedvalue == propertyarray[i])
        {
          disable = true;
          bgcolor = '#CCCCCC';
        }
        else
        {
          disable = false;
          bgcolor = '#FFFFFF';
        }
        
        if (((!disable && typeof(disabledarray[skips[j]]) != "number") && (!disable && fielddisable[skips[j]] == attrib.name)) || disable)
        {
          skipQuestion(skipstring[0], skipstring[1], disable, bgcolor, 'entryform');
        }
        if (disable)
        { 
          disabledarray[skips[j]] = 1;
          if (fielddisable[skips[j]] == null) fielddisable[skips[j]] = attrib.name;
        }
        if (!disable && fielddisable[skips[j]] == attrib.name && typeof(disabledarray[skips[j]]) != "number")
        {
          fielddisable[skips[j]] = null;
        }
      }
    }
  }
}

function skipQuestion(type, attrib, disable, bgcolor, formname)
{
  switch (type)
  {
    case "attachment":
      var obj = document.getElementById(attrib);
      var obj3 = document.getElementById('uploadref_'+attrib);
      var obj4 = document.getElementById('uploadmax');
      if (disable)
      {
        if (obj.innerHTML != 'Er kunnen momenteel geen bestanden worden geupload')
        {
          savedattachment[attrib] = new Array();
          savedattachment[attrib]['html'] = obj.innerHTML;
          savedattachment[attrib]['uploadref'] = obj3.innerHTML;
          savedattachment[attrib]['uploadmax'] = obj4.innerHTML;
          obj3.innerHTML = "";
          obj4.innerHTML = "";
          obj.innerHTML = "Er kunnen momenteel geen bestanden worden geupload";
        }
      }
      else
      {
        if (savedattachment[attrib]['html'] != null)
        {
          obj.innerHTML = savedattachment[attrib]['html'];
          obj3.innerHTML = savedattachment[attrib]['uploadref'];
          obj4.innerHTML = savedattachment[attrib]['uploadmax'];
        }  
      }  
      break;
    case "atkdummyattribute":
    case "hiddenattribute":
      var obj = document.getElementById(attrib);
      if (disable) obj.style.display = 'none';
      else obj.style.display = 'inline';
      break;
    case "formdateattribute":
      var obj = document.getElementById(attrib+"[day]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      var obj = document.getElementById(attrib+"[month]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      var obj = document.getElementById(attrib+"[year]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      break;
    case "formdatetimeattribute":    
      var obj = document.getElementById(attrib+"[day]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      var obj = document.getElementById(attrib+"[month]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      var obj = document.getElementById(attrib+"[year]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      var obj = document.getElementById(attrib+"[hours]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      var obj = document.getElementById(attrib+"[minutes]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      var obj = document.getElementById(attrib+"[seconds]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      break;
    case "atkdurationattribute":    
      var obj = document.getElementById(attrib+"[hours]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      var obj = document.getElementById(attrib+"[minutes]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      break;   
    case "formradioattribute":
      var obj = eval('document.'+formname+'.'+attrib);
      for (var i=0;i<obj.length;i++)
      {
        obj[i].disabled = disable;
      }
      break;
    case "formtableattribute":
      var obj = document.getElementById('div_'+attrib);
      var obj3 = eval('document.'+formname+'.cmdAddRow_' + attrib);
      var obj4 = eval('document.'+formname+'.cmdDeleteRow_' + attrib);
      if (disable)
      {
        savedhtml[attrib] = obj.innerHTML;
        obj.innerHTML = "Deze tabel kan momenteel niet worden bewerkt";
      }
      else
      {
        if (savedhtml[attrib] != "" && savedhtml[attrib] != null) obj.innerHTML = savedhtml[attrib];
        init('tblGrid_'+attrib, 'div_'+attrib);
      }  
      if (typeof(obj3) == "object") obj3.disabled = disable;
      if (typeof(obj4) == "object") obj4.disabled = disable;
      break;
    case "atktimeattribute":    
      var obj = document.getElementById(attrib+"[hours]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      var obj = document.getElementById(attrib+"[minutes]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      var obj = document.getElementById(attrib+"[seconds]");
      obj.disabled = disable;
      obj.style.backgroundColor = bgcolor;
      break;
    case "atkmultiselectattribute":  
      var elements = document.getElementsByName(attrib+'[]');
      for (k=0;k<elements.length;k++)
      {
        elements[k].disabled = disable;
      }
      break;      
    case "numberedfile":
      var obj = eval('document.'+formname+'.' + attrib);
      var obj2 = eval('document.'+formname+'.'+attrib+'_postfilesnumber');
      if (typeof(obj) == "object")
      {
        obj.disabled = disable;
        obj.style.backgroundColor = bgcolor;
      }
      if (typeof(obj2) == "object")
      {
        obj2.disabled = disable;
        obj2.style.backgroundColor = bgcolor;
      }
      break;
    default:
      var obj = eval('document.'+formname+'.' + attrib);
      if (typeof(obj) == "object")
      {
        obj.disabled = disable;
        obj.style.backgroundColor = bgcolor;
      }  
      break;
  }
}
