var drawRegionsSelect = function (arr) {
	var tmpArrRegion = function (v) {
		var tmpArr = [], tmpSplit;
		for (var a in v) {
			tmpSplit = v[a].split('|');
			if (tmpSplit[1] === tmpSplit[2]) {
				tmpArr.push(tmpSplit[0] + '|' + tmpSplit[2] + '|' + tmpSplit[1]);
			}
		}
		tmpArr.sort();
		return tmpArr;
	}(arr);
	var tmpArrDestination = function (v) {
		var tmpArr = [], tmpSplit;
		for (var a in v) {
			tmpSplit = v[a].split('|');
			if (tmpSplit[1] !== tmpSplit[2]) {
				tmpArr.push(tmpSplit[0] + '|' + tmpSplit[2] + '|' + tmpSplit[1]);
			}
		}
		tmpArr.sort();
		return tmpArr;
	}(arr);
	var selectOpt1 = (document.getElementById('bengine').flugdauer.value !== '-1') ? 'selected="selected"' : '';
	var tmpArr = [];
	tmpArr.push('<select name="ziel_and_region" class="sel_width_310">');
	tmpArr.push('<option value="-1">dowolny</option>');
	for (var a in tmpArrRegion) {
		var tmpSplit = tmpArrRegion[a].split('|');
		if (
			(document.getElementById('bengine').flugdauer.value !== '-1') &&
			(document.getElementById('bengine').zielgebiets_kenner.value === '-1') &&
			(document.getElementById('bengine').flugdauer.value === tmpSplit[1])
		) {
			tmpArr.push('<option value="' + tmpSplit[1] + '|' + tmpSplit[2] + '" selected="selected">' + tmpSplit[0] + '</option>');
		} else {
			tmpArr.push('<option value="' + tmpSplit[1] + '|' + tmpSplit[2] + '">' + tmpSplit[0] + '</option>');
		}
		for (var b in tmpArrDestination) {
			var tmpSplit2 = tmpArrDestination[b].split('|');
			if (tmpSplit2[1] === tmpSplit[1]) {
				if (
					(document.getElementById('bengine').flugdauer.value !== '-1') &&
					(document.getElementById('bengine').zielgebiets_kenner.value !== '-1') &&
					(document.getElementById('bengine').zielgebiets_kenner.value !== document.getElementById('bengine').flugdauer.value) &&
					(document.getElementById('bengine').zielgebiets_kenner.value === tmpSplit2[2])
				) {
					tmpArr.push('<option value="' + tmpSplit2[1] + '|' + tmpSplit2[2] + '" selected="selected">  - ' + tmpSplit2[0] + '</option>');
				} else {
					tmpArr.push('<option value="' + tmpSplit2[1] + '|' + tmpSplit2[2] + '">  - ' + tmpSplit2[0] + '</option>');
				}
			}
		}
	}
	tmpArr.push('</select>')
	$('#ZielAndRegion').html(tmpArr.join(''));
        
};
window.onload = function () {
    
	drawRegionsSelect(TTREGS_654);
	setInterval(
		function () {
			document.getElementById('kalender1').value = document.getElementById('ktag').value+"."+document.getElementById('kmonat').value;
			document.getElementById('kalender2').value = document.getElementById('rueckktag').value+"."+document.getElementById('rueckkmonat').value;
		}, 50
	);
};




