

var imgloading = new Image(64, 64);
var imgfailed = new Image(64, 57);

imgloading.src = "../_img/ajax/rellotge.gif";
imgfailed.src = "../_img/ajax/failed.jpg";

/*
*  Es hat mit dem Kalendar zu tun
*/

function checknDays(idc, my){
	var date = new Date();
	var tmparr = my.split('-');
	var control = document.getElementById(idc);
	var ndays = 32 - new Date(tmparr[1], tmparr[0]-1, 32).getDate();
	var noptions = control.options.length;
	if(ndays != noptions){
		if(ndays > noptions){
			for(n = noptions; n <= ndays; n++){
				var option = document.createElement('option');
				option.value = n;
				option.text = n;
				control.add(option, null);
			}
		}else{
			for(n = noptions; n >= ndays; n--){
				control.remove(n);
			}
		}
	}	
}

function setDate(dmy, inhalt, idx){
	var tmparr = dmy.split('-');
	if(inhalt == 'inhaltcale'){
		cd = document.getElementById('dentrada' + idx); 
		cmy = document.getElementById('mentrada' + idx);
		inhalt = 'cale';
	}else{
		cd = document.getElementById('dsortida' + idx); 
		cmy = document.getElementById('msortida' + idx);
		inhalt = 'cals';
	}
	noptions = cd.length;
	for(x = 0;  x < noptions; x++){
		if(tmparr[0] == cd.options[x].value){
			cd.options[x].selected = true;
			break;
		}
	}
	noptions = cmy.length;
	my = tmparr[1] + '-' + tmparr[2];
	for(x = 0;  x < noptions; x++){
		if(my == cmy.options[x].value){
			cmy.options[x].selected = true;
			break;
		}
	}
	document.getElementById(inhalt).style.visibility = 'hidden';
}

function getDate(tp, idx){
	if(tp == 0)
		return (document.getElementById('dentrada' + idx).value + '-' + document.getElementById('mentrada' + idx).value);
	else
		return (document.getElementById('dsortida' + idx).value + '-' + document.getElementById('msortida' + idx).value);
}

function showCalendar(csw, inhalt, dmy, idx){
	if(inhalt != null){
		var tmparr = dmy.split('-');
		divcal = document.getElementById(csw);
		switch(idx){ // nur für Reservierung
			case '1':
				divcal.style.marginTop = "109px";
				break;
			case '2':
				divcal.style.marginTop = "350px";
				break;
			case '3':
				divcal.style.marginTop = "565px";
				break;
			case '4':
				divcal.style.marginTop = "775px";
				break;
			case '5':
				divcal.style.marginTop = "990px";
				break;				
		}
		divcal.style.visibility = 'visible';
		var d = new Date(tmparr[2], tmparr[1]-1, tmparr[0]);
		var date = "&amp;date=" + Math.floor(d.getTime()/1000);
		pagecal('minical.php', "inhalt=" + inhalt + date + "&amp;idx=" + idx, inhalt);
	}else{
 		document.getElementById(csw).style.visibility = 'hidden';
	}
}

/*
*  Ende Kalendar
*/


function pagecal(url, params, tute){
	var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP"): new XMLHttpRequest();
	if (x){
		x.onreadystatechange = function(){
			el = document.getElementById(tute);
			el.innerHTML = "<p class=\"txtac pt70\"><img id=\"ldimg\" width=\"35\" height=\"35\" /></p>";
			 setCalProgress(0);
			if (x.readyState == 4){
				if(x.status == 200){
					el.innerHTML = x.responseText;
				 }else{
					x.abort();
					setCalProgress(x.status);
				}
			}
		}
		if(params != null) url += "?" +  params;
		x.open("GET", url, true);
		x.send(null);
	}
}

function setCalProgress(error){
	document.getElementById('ldimg').src = error ? imgfailed.src : imgloading.src;
}




