/*
 * CAMPAIGN
 * Open popupwindow for campaings
 */
function campaign(id){
	window.open("popup/campaign.php?id="+id, "campaign", "width=600, height=500");
}

function bigImage(id, w, h){
	window.open("popup/img.php?img="+id, "Hinweis","width="+w+", height="+h+", resizable=no");
}

/*
 * TABLES
 * Highlighting of table rows
 */
function changeTable(id, stat){
	id.style.backgroundColor = (stat == "in") ? "#FFFFFF" : "";
}
	
/*
 * ADDRESS
 * Load city via PLZ
 */
function doItAgain(element){
	if (element.options[element.selectedIndex].value  == "anders"){
		document.getElementById('town').style.display = "block";
	} else {
		document.getElementById('town').style.display = "none";
	}
}

function doIt(element, old_id){
	
	var zip = element.value;
	
	if (zip.length == 4){
		
		//erstellen des requests
		var req = null;
		try{
			req = new XMLHttpRequest();
		} catch (ms){
			try{
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (nonms){
				try{
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed){
					req = null;
				}
			}
		}
		
		if (req == null)  
			alert("Error creating request object!");
		
		//anfrage erstellen (GET, url ist localhost, 
		//request ist asynchron
		req.open("GET", '/includes/dynamic/zip.php?zip=' + zip, true);
		
		//Beim abschliessen des request wird diese Funktion ausgeführt
		req.onreadystatechange = function(){
			switch(req.readyState) {
				case 4:
					if(req.status!=200) { 
						alert("Fehler:"+req.status);
					} else {
						
						// leeren der list
						document.getElementById('select_zip').innerHTML = "";
							
						// aufbau der neuen liste
						var zips = req.responseText.split(",");
						var count = 0;
						if (req.responseText.length > 0){
							for (var i = 0; i < zips.length; i++){
								var detail = zips[i].split("#");
								document.getElementById('select_zip').options[i] = new Option(detail[1],detail[0]);
								if (old_id == detail[0]){
									document.getElementById('select_zip').options[i].selected = true;
								}
								count++;
							}
							
							// aktivieren der liste
							document.getElementById('select_zip').readonly = false;
							document.getElementById('town').style.display = "none";
														
						} else {
							
							document.getElementById('town').style.display = "block";
							
						}
						
						document.getElementById('select_zip').options[count] = new Option("Andere Stadt ...", "anders");
						if (old_id == -1){
							document.getElementById('select_zip').selectedIndex = count;
							doItAgain(document.getElementById('select_zip'));
						}
						
					}
					break; 
				default:
					return false;
					break;
			}
		};
	  
	  	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(null);
		
	}
	
} 

$(document).ready(function() {
	   
	$.datepicker.setDefaults($.datepicker.regional['de']);

	// datepicker for solar
	$("input[name='date']").datepicker({ 
		dateFormat: 'dd.mm.yy',
		changeMonth: true,
		changeYear: true,
		goToCurrent: true
	});
	
	// menu rollover
	$("#menu .menulink").hover(
	function(){
		var id = $(this).parent('div').attr('id');
		id = id.replace('menu', '');
		if( id > 1)
			$('#teaser'+id).addClass('active');
	}, 
	function(){
		var id = $(this).parent('div').attr('id');
		id = id.replace('menu', '');
		$('#teaser'+id).removeClass('active');
	});
	
});
