function calcDate(strDayPart, strMonthPart, strYearPart, strFormName) {
	
	if ((document.getElementById(strYearPart).value != -1) &&
		(document.getElementById(strMonthPart).value != -1)) {
		intDayCount = getMonthsDays(document.getElementById(strMonthPart).value, strMonthPart, strYearPart);
		setMaxDays(intDayCount, strFormName, strDayPart);
	}
	if  (document.getElementById(strYearPart).value != '-1') {
		document.getElementById(strMonthPart).disabled=false;
		document.getElementById(strMonthPart).className='';
	}
	if  (document.getElementById(strMonthPart).value != '-1') {
		document.getElementById(strDayPart).disabled=false;
		document.getElementById(strDayPart).className='';
	}
	
}

function getMonthsDays(intMonth, strMonthPart, strYearPart) {
	intSelectedMonth = document.getElementById(strMonthPart).value;
	if (intSelectedMonth == '-1') {
		return 31;
	}
	if (
		(intSelectedMonth == '1') ||
		(intSelectedMonth == '3') ||
		(intSelectedMonth == '5') ||
		(intSelectedMonth == '7') ||
		(intSelectedMonth == '8') ||
		(intSelectedMonth == '10') ||
		(intSelectedMonth == '10')
		) {
		return 31;
	}
	if (
		(intSelectedMonth == '4') ||
		(intSelectedMonth == '6') ||
		(intSelectedMonth == '9') ||
		(intSelectedMonth == '11')
		) {
		return 30;
	}
	if (intSelectedMonth == '2') {
		if (checkLeapYear(document.getElementById(strYearPart).value)) {
			return 29;
		} else {
			return 28;
		}
	}
}

function setMaxDays(intDayCount, strFormName, strDayPart) {

	var elSel = document.getElementById(strDayPart);
	var prevCount = elSel.length;
	
	while(elSel.length>0) {
		elSel.options[elSel.length-1]=null;
	}
	
	for (intX = 1; intX <= intDayCount; intX++) {
		elOptNew = document.createElement('option');
		elOptNew.text = intX;
	    elOptNew.value = intX;
	    try {
	        elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
	    }
	    catch(ex) {
	    	elSel.add(elOptNew); // IE only
	    }
	}

}



function checkLeapYear(Jahr) {
	SJahr = Jahr%4;
	SHJahr = Jahr%100;
	S4Jahr = Jahr%400;
	STag = ((S4Jahr == "0") ? (1) : ((SHJahr == "0") ? (0) : ((SJahr == "0") ? (1) : (0))));
	if (STag == 1) {
		return true;
	} else {
		return false;
	}
}


function unlock(strDayPart, strMonthPart, strYearPart) {
	if  (document.getElementById(strYearPart).value != '-1') {
		document.getElementById(strMonthPart).disabled=false;
		document.getElementById(strMonthPart).className='';
	}
	if  (document.getElementById(strMonthPart).value != '-1') {
		document.getElementById(strDayPart).disabled=false;
		document.getElementById(strDayPart).className='';
	}
}



function update_voucher() {
		
	regid = document.getElementById('cityid').value;

	var xmlHttp;
	try
		{
		xmlHttp=new XMLHttpRequest();
		}
	catch (e)
		{
		try
			{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch (e)
			{
			try
				{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch (e)
				{
				alert("AJAX kaputt??");
				return false;
				}
			}
		}
	xmlHttp.onreadystatechange=function()
	    {
	    if(xmlHttp.readyState==4)
			{
			strResponse = xmlHttp.responseText;
			if (strResponse.substring(0,3) == '200') {
					/*
					 * Für diese Stadt gibt es Gutscheine
					 */
					document.getElementById('voucher').value = strResponse.substring(4);
					document.getElementById('voucherimage').src = 'fileadmin/groups/shared/stadtinfo'+regid+'.png';
					document.getElementById('voucherinfo').style.display = 'block';
					
				} else {
					/*
					 * Für diese Stadt gibt es keine Gutscheine
					 */
					document.getElementById('voucher').value = '';
					document.getElementById('voucherinfo').style.display = 'none';
				}
			}
	    }
	xmlHttp.open("GET","http://www.enjoy4.de/fileadmin/scripts/voucherupdate.php?regid="+regid,true);
	xmlHttp.send(null);
	
}

