function checkDate(date) {
	var time = new Date();
	
	var startDate = "20.10"+time.getFullYear();
	var endDate = "03.03"+(time.getFullYear()+1);
	
	if ( date.search(/[0-3]{1}[0-9]{1}\.[01]{1}[0-9]{1}\.[12]{1}[0-9]{3}/)==-1) {
		alert('Bitte geben Sie ein Datum im Format dd.mm.YYYY an.');
		return false;
	}
}

function isChildOf(id,elem) {
	var obj = document.getElementById(id);
	var isChild = false;
	var i=0;
	while (elem != document && i++<30) {
		if (elem == obj) {
			return true;
		}
		elem = elem.parentNode;
	}
	return isChild;
}

function getIEFormValues(id) {
	var data = "<xjxquery><q>";
	var aDivs = document.getElementsByTagName("input");
	var x = 0;
	for (var i=0;i<aDivs.length;i++) {
		if (isChildOf(id,aDivs[i])) {
			if (x++ != 0) {
				data += "&";
			}
			data += aDivs[i].name+"="+encodeURI(aDivs[i].value);
			continue;
		}
	}
	var aDivs = document.getElementsByTagName("select");
	for (var i=0;i<aDivs.length;i++) {
		if (isChildOf(id,aDivs[i])) {
			if (x++ != 0) {
				data += "&";
			}
			data += aDivs[i].name+"="+encodeURI(aDivs[i].value);
			continue;
		}
	}
	data += "</q></xjxquery>";
	return data;
}

function addOption(selectId, txt, val) {
    obj = document.getElementById(selectId);
	if (!document.all) {
		var objOption = new Option(txt, val);
		obj.options[document.getElementById(selectId).length] = objOption;
    } else {
		var objOption = document.createElement("option");
		obj.options.add(objOption);
		objOption.innerText = txt;
		objOption.value = val;
    }
}

function selOption(selectId, val) {
    obj = document.getElementById(selectId);
	if (!document.all) {
		for (i=0;i<document.getElementById(selectId).length;i++) {
			if (obj.options[i].value == val) {
				obj.options[i].selected=true;
			}
		}
    } else {
    	for (i=0;i<document.getElementById(selectId).length;i++) {
    		if (obj.options[i].value == val) {
				obj.options[i].selected=true;
			}
		}
    }
}

function clearList(selectId) {
   	document.getElementById(selectId).length = 0;
}

// This function gets called when the end-user clicks on some date.
function ownSelectHandler(cal, date) {
  checkDate(date);
  cal.sel.value = date; // just update the date in the input field.
  //if (cal.sel.id == "sel1" || cal.sel.id == "sel3")
    // if we add this call we close the calendar on single-click.
    // just to exemplify both cases, we are using this only for the 1st
    // and the 3rd field, while 2nd and 4th will still require double-click.
    cal.callCloseHandler();
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function ownCloseHandler(cal) {
	cal.hide(); // hide the calendar
}
