function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();
var httpScroll = createRequestObject();

function sndReq(action,icnum) {
    if (icnum == 0) {
	icnum=window.inum;
    } else {
	window.inum=icnum;
    }
    http.open('get', 'calendar/ajax/ajax_calendar_input.php?mydate='+action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
        //document.all.calendar_lib_span.innerHTML = response;
        document.getElementsByName('calendar_lib_span_'+inum)[0].innerHTML = response;
    }
}

function handleScrollResponse() {
    if(httpScroll.readyState == 4){
        var response = httpScroll.responseText;
        var update = new Array();
        //document.all.calendar_lib_span.innerHTML = response;
        window.location.hash = '#'+response;
    }
}

function pick(mydate) {
    show();
    //document.all.date_input.value = mydate;
    if (inum == 4) {
	//document.getElementsByName('searchstr')[0].value = 'datum:'+mydate;
	httpScroll.open('get', document.URL+'&searchdate='+mydate);
	//httpScroll.open('get', 'index.php?action=searchbydate&searchdate='+mydate);
	httpScroll.onreadystatechange = handleScrollResponse;
	httpScroll.send(null);
	//window.location.hash = '#341.52';
    } else {
	document.getElementsByName('geb_date_input_'+inum)[0].value = mydate;
    }
}

function show() {
    /*if(document.all.calendar_lib_span.style.visibility == "hidden")
        document.all.calendar_lib_span.style.visibility = "visible";
    else
        document.all.calendar_lib_span.style.visibility = "hidden"*/

    if (document.getElementsByName('calendar_lib_span_'+inum)[0].style.visibility == "hidden")
        document.getElementsByName('calendar_lib_span_'+inum)[0].style.visibility = "visible";
    else
        document.getElementsByName('calendar_lib_span_'+inum)[0].style.visibility = "hidden";

    if (inum != 4) {
	var q=1;
	
	for (q=1; q<=3; q++) {
	    if (q != inum) 
		document.getElementsByName('calendar_lib_span_'+q)[0].style.visibility = "hidden";
	}
    }
}

var inum=1;

