function TopPos(Control) {
  var pos;
  pos=Control.offsetTop;
  while (Control.offsetParent) {
    Control=Control.offsetParent;
    pos=pos+Control.offsetTop;
  }
  return pos;
}

function LeftPos(Control) {
  var pos;
  pos=Control.offsetLeft;
  while (Control.offsetParent) {
    Control=Control.offsetParent;
    pos=pos+Control.offsetLeft;
  }
  return pos;
}

function closeopendropdown(winname) {
  if (document.body.opendialog!=null && winname!="modaldialog") {			
	  if (winname=="close") {	  
	    closedialog();	    
	  }
	  return false;
  }
  if (document.body.opendropdown!=null) {
    ToogleDropdown();    
    return false;
  } else {
    return true;
  }
}

function changefilter() {  
  event.srcElement.changed="1";
}

function filterkeypress() {
  if (event.keyCode==13) {
    event.srcElement.blur();
    event.srcElement.parentElement.lastChild.click();
  }
}

function ToogleDropdown() {  

  if (document.body.opendropdown!=null) {    
    
    document.body.opendropdown.style.display="none";        
    if (document.body.criteriachanged!=null) {
      setloading();
      document.body.criteriachanged.submit();
    }    
    document.body.opendropdown=null;
    modalbackground.style.display="none";
    if (document.body.printobj!=null) {
      document.body.printobj.showViewer();
    }
  } else {
    event.cancelBubble=true;
    var Dimension=event.srcElement.parentElement;
    if (Dimension.className!="Dimension") {Dimension=Dimension.parentElement};
    if (Dimension.className!="Dimension") {Dimension=Dimension.parentElement};
    var DropDown=document.getElementById(Dimension.dropdown);
    
    if (document.body.printobj!=null) {            
      document.body.printobj.hideViewer();
    }
    if (document.body.opendropdown!=DropDown) {
      document.body.opendropdown=null;
      if (DropDown.style.display=="block") {
        DropDown.style.display="none";
      } else {
        var filterinput=Dimension.getElementsByTagName("input")[2];
        var filtervalue=Dimension.getElementsByTagName("input")[0];
        
        if (!DropDown.loaded || filterinput.changed=="1") {
        
          DropDown.loaded=true;          
        
          if (filterinput.changed=="1") {            
            filtervalue.value=filterinput.value;
          } else {
            filtervalue.value="";
          }
        
          filtervalue.form.submit();        
        }         
        
        var leftpos=LeftPos(Dimension.lastChild);
        var toppos=(TopPos(Dimension.lastChild)+Dimension.lastChild.offsetHeight);    
        
        DropDown.style.pixelLeft=leftpos;      
        DropDown.style.pixelTop=toppos;        
        modalbackground.style.display="block";        
        DropDown.style.display="block";                
        document.body.appendChild(DropDown.removeNode(true));        
        var tmpwidth=DropDown.offsetWidth;
        if (tmpwidth==0) {
          tmpwidth=DropDown.currentStyle.width.replace('px','');
        }
        
        if (tmpwidth+DropDown.offsetLeft>document.body.clientWidth) {
          leftpos=(document.body.clientWidth-tmpwidth);
          DropDown.style.pixelLeft=leftpos;
        }
        
        
        document.body.opendropdown=DropDown;
      }
    } else {
      document.body.opendropdown=null;
      if (document.body.printobj!=null) {
        document.body.printobj.showViewer();
      }
    }
  }
}

