var retCounter = new Array;
var zeilen = new Array();
var anzZeilen;

var calendar = null;
function showCalendar(id, ele) {
  var calendar = document.getElementById(id);
  
  var element = document.getElementById(ele);
  var elem=element,tagname="",x=0,y=0;
  
  while ((typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined"))
  {
    y+=elem.offsetTop;     /* Offset des jeweiligen Elements addieren */
    x+=elem.offsetLeft;    /* Offset des jeweiligen Elements addieren */
    tagname=elem.tagName.toUpperCase(); /* tag-Name ermitteln, Grossbuchstaben */

    if (tagname=="BODY")
      elem=0;

    if (typeof(elem)=="object")
      if (typeof(elem.offsetParent)=="object")
        elem=elem.offsetParent;
  }
  position=new Object();
  calendar.style.left = x + "px";
  calendar.style.top   = (y + 18) + "px";
  calendar.style.display = "block";
  
  if (window.ActiveXObject) { /* for IE6 */
      var calendarFrame = document.getElementById(id+'Frame');
      calendarFrame.style.left = calendar.style.left;
      calendarFrame.style.top = calendar.style.top;
      calendarFrame.style.width = calendar.offsetWidth;
      calendarFrame.style.display = calendar.style.display;
      
  }
}

 
function hideCalendar(id) {
    if(id == 'both') {
        hiddenCalendar = document.getElementById('toCalendar');
        hiddenCalendar.style.display = "none";
        hiddenCalendar = document.getElementById('fromCalendar');
        hiddenCalendar.style.display = "none";
        if (window.ActiveXObject) { /* for IE6 */
            hiddenFrame = document.getElementById('toCalendarFrame');
            hiddenFrame.style.display = "none";
            hiddenFrame = document.getElementById('fromCalendarFrame');
            hiddenFrame.style.display = "none";
        }
    } else {
        hiddenCalendar = document.getElementById(id+'Calendar');
        hiddenCalendar.style.display = "none";
        if (window.ActiveXObject) { /* for IE6 */
            hiddenFrame = document.getElementById(id+'CalendarFrame');
            hiddenFrame.style.display = "none";
        }
    }
  
}


function calendarChangeVon(stamp){
    var miliStamp = stamp * 1000;
    var thatDate = new Date(miliStamp);
    var tag = thatDate.getDate();
    var monat = thatDate.getMonth() + 1;
    var year = thatDate.getFullYear();
    
    if(tag<10) {
        tag = '0' + tag;
    }
    
    if(monat<10) {
        monat = '0' + monat;
    }
    
    hideCalendar('both');
    
    
    document.forms.searchForm.from.value = stamp;
    document.forms.searchForm.fromdate.value = tag+'.'+monat+'.'+year;
    
    
    /*
    for(i=0; i<document.forms.searchForm.from.length; i++){
        if(document.forms.searchForm.from.options[i].value==stamp){
            document.forms.searchForm.from.selectedIndex=i;
        }
    }
    */
}
               
function calendarChangeBis(stamp){
    var miliStamp = stamp * 1000;
    var thatDate = new Date(miliStamp);
    var tag = thatDate.getDate();
    var monat = thatDate.getMonth() + 1;
    var year = thatDate.getFullYear();
    
    if(tag<10) {
        tag = '0' + tag;
    }
    
    if(monat<10) {
        monat = '0' + monat;
    }
    
    hideCalendar('both');
    
    
    document.forms.searchForm.to.value = stamp;
    document.forms.searchForm.todate.value = tag+'.'+monat+'.'+year;
    /*
    for(i=0; i<document.forms.searchForm.to.length; i++){
        if(document.forms.searchForm.to.options[i].value==stamp){
            document.forms.searchForm.to.selectedIndex=i;
        }
    }
    */
}
               
function getDayForCalendar(fromType){
    if(fromType=='von'){
        /*var stamp = document.forms.searchForm.from.options[document.forms.searchForm.from.selectedIndex].value;*/
        var stamp = document.forms.searchForm.from.value;
    } else {
        /*var stamp = document.forms.searchForm.to.options[document.forms.searchForm.to.selectedIndex].value;*/
        var stamp = document.forms.searchForm.to.value;
    }
    return stamp;
}
               
               
function bgDay(thisDay)
{
	var i;
	for(i=1; i<=31; i++){
	    if(document.getElementById("day"+i)){
	        if(i==thisDay){
	            document.getElementById("day"+thisDay).style.backgroundColor = "#FFFFFF";
	        }else{
	            document.getElementById("day"+i).style.backgroundColor = "#CCCCCC";
	            /*alert(typeof(document.getElementById("day"+i)));*/
	        }
	    }
	}
	
}



function changeDatF(){
    var elemTo = document.forms.searchForm.to;
    var elemFrom = document.forms.searchForm.from;
    var elemToDate = document.forms.searchForm.todate;
    var elemFromDate = document.forms.searchForm.fromdate;
    
    if(elemTo.value<elemFrom.value) {
        elemTo.value = elemFrom.value;
        elemToDate.value = elemFromDate.value;
    }
    
    /*
    if(document.forms.searchForm.to.selectedIndex<document.forms.searchForm.from.selectedIndex){
        document.forms.searchForm.to.selectedIndex = document.forms.searchForm.from.selectedIndex;
    }
    */
}


