/*
Editable combo boxes support
*/
function displayComboEditable(dateFieldName, itemsArray){
  var targetDateField = document.getElementsByName (dateFieldName).item(0);
  var displayBelowThisObject = targetDateField;
 
 // if(!msie){
    displayBelowThisObject = document.getElementById ("desktop");
    var x = displayBelowThisObject.offsetLeft + displayBelowThisObject.clientWidth / 2  - 50;
    var y = displayBelowThisObject.offsetTop  + displayBelowThisObject.clientHeight / 2 - 50;
 // }
/* 
  if(msie){
    var x = displayBelowThisObject.offsetLeft;
    var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;
    var z = displayBelowThisObject.scrollTop; 
    var l = displayBelowThisObject.scrollLeft; 
  }
 */
  // deal with elements inside tables and such
  var parent = displayBelowThisObject;
  while (parent.offsetParent) {
    parent = parent.offsetParent;
    x += parent.offsetLeft;
    y += parent.offsetTop ;
   /* if(msie){
      z += parent.scrollTop ;
      l += parent.scrollLeft ;
    }*/
  }
  /*if(msie){
    x -= l;
    y -= z;
  }*/
  drawComboEditable(targetDateField, x, y, itemsArray);
}

function drawComboEditable(targetDateField, x, y, itemsArray){
  if (!document.getElementById(datePickerDivID)) {
    var newNode = document.createElement("div");
    newNode.setAttribute("id", datePickerDivID);
    newNode.setAttribute("class", "dpDiv");
    newNode.setAttribute("style", "visibility: hidden;");
    document.body.appendChild(newNode);
  }
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.position = "absolute";
  pickerDiv.style.left = x + "px";
  pickerDiv.style.top = y + "px";
  pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
  pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block");
  pickerDiv.style.zIndex = 10000;
 
  refreshComboEditable(targetDateField.name, itemsArray);
}

function refreshComboEditable(dateFieldName, itemsArray){
  var html = "<TABLE class=dpTable>";
  html += "<TR class=dpTR>";
  html += "<TD class=dpTD>";
  html += "<SELECT id=comboEditable size=5>";
  for(i = 0; i < itemsArray.length; i++){
    html += "<option>" + itemsArray[i] + "</option>";
  }  
  html += "</SELECT>";
  html += "</TD>";
  html += "</TR>";
 
  html += "<TR class=dpTR>";
  html += "<TD class=dpButtonTD>";
  html += "<button class='dpTodayButton' onClick='updateComboEditableField(\"" + dateFieldName + "\",true);'>" + langButtonSelect + "</button>&nbsp;";
  html += "<button class='dpTodayButton' onClick='updateComboEditableField(\"" + dateFieldName + "\");'>" + langClose + "</button>";
  html += "</TD>";
  html += "</TR>";

  html += "</TABLE>";
 
  document.getElementById(datePickerDivID).innerHTML = html;
  adjustiFrame();
}


function updateComboEditableField(comboFieldName, fillValue){
  var targetComboField = document.getElementsByName (comboFieldName).item(0);

  var list = document.getElementById("comboEditable");
  var selIndex = list.selectedIndex;
  if(fillValue){
    if (selIndex == -1) {
    }else{
      targetComboField.value = list[selIndex].text;
    }    
  }

  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.visibility = "hidden";
  pickerDiv.style.display = "none";
 
  adjustiFrame();
  targetComboField.focus();
}


