// Functions (C)Julian Schmalzl

function GmoveTo(location, lang) {
	if (location == "marche") {
		map.panTo(new GLatLng(43.43079554067942, 13.280303478240966));
		if (lang == "de") {
		map.openInfoWindowHtml(new GLatLng(43.43079554067942, 13.280303478240966), 'Via Palombare Incatenate 9<br />'
											 +	'I-62011 Cervidone di Cingoli<br />'
											 +	'Prov. Macerata - Marken');
		} else {
		map.openInfoWindowHtml(new GLatLng(43.43079554067942, 13.280303478240966), 'Via Palombare Incatenate 9<br />'
											 +	'I-62011 Cervidone di Cingoli<br />'
											 +	'Prov. Macerata - Marche');

		}
	} else {
		map.panTo(new GLatLng(46.50602090539099, 11.337257623672485));
        if (lang == "de") {
		map.openInfoWindowHtml(new GLatLng(46.50602090539099, 11.337257623672485), 'Fagenstarsse 5c1<br />'
											 +	'I-39100 Bozen - Südtirol'); 
		} else {
		map.openInfoWindowHtml(new GLatLng(46.50602090539099, 11.337257623672485), 'Via Fago 5c1<br />'
											 +	'I-39100 Bolzano - Alto Adige'); 

		}
	}
}

function CalcCheck(risult) {
		ck = true;
		var z1 = parseInt(document.getElementById("zulu1").innerHTML);
		var z2 = parseInt(document.getElementById("zulu2").innerHTML);
		var calc = z1 + z2;
		if (risult != calc) {
			ck = false;
		}
		return ck;
}

function CheckContact(lang)	{
		var name = "";
		var mail = "";
		var calc = "";
		var check = true;
		
		name = document.getElementById("cname").value;
		mail = document.getElementById("cmail").value;
		calc = document.getElementById("ccalc").value;
		
			if (name == "") {
				if (lang == "de") {
					document.getElementById("cnameout").innerHTML = "(Namen eingeben!)";
				} else {
					document.getElementById("cnameout").innerHTML = "(inserire un nome)";
				}
				check = false;
			} else {
				document.getElementById("cnameout").innerHTML = "";
			}
			if (mail == "") {
				if (lang == "de") {
					document.getElementById("cmailout").innerHTML = "(Adresse eingeben!)";
				} else {
					document.getElementById("cmailout").innerHTML = "(inserire un indirizzo)";
				}
				check = false;
			} else {
				if (mail.search("@") < 0) {
					if (lang == "de") {
					document.getElementById("cmailout").innerHTML = "(ungültige Adresse)";
					} else {
					document.getElementById("cmailout").innerHTML = "(indirizzo invalido)";
					}
					check = false;
				} else {
				document.getElementById("cmailout").innerHTML = "";
				}
			} 
			if (calc != "") {
				if (!CalcCheck(calc)) {
					if (lang == "de") {
						document.getElementById("ccalcout").innerHTML = "(ungültige Kontrollnummer)";
					} else {
						document.getElementById("ccalcout").innerHTML = "(numero di controllo invalido)";
					}
					check = false;
				}
			} else {
				if (lang == "de") {
					document.getElementById("ccalcout").innerHTML = "(Kontrollzahl eingeben)";
				} else {
					document.getElementById("ccalcout").innerHTML = "(inserire numero di controllo)";
				}
					check = false;				
			}
		if (!check) contactRefresh();
		return check;
}

function contactRefresh() {
		document.getElementById("zulu1").innerHTML = Math.round(Math.random()*49);
		document.getElementById("zulu2").innerHTML = Math.round(Math.random()*49);
		document.getElementById("mailstatus").innerHTML = '';
		document.getElementById("ccalc").value = '';
}

function mouseOver(id)	{
		id.style.opacity = '1.0';
        id.style.filter = 'alpha(opacity=100)';
        return;	
}

function mouseOut(id){
        id.style.opacity = '0.60';
        id.style.filter = 'alpha(opacity=60)';
        return;
}

function loadImage(pic)	{
		image = new Image();
		image.src = "galerie/large/" + pic;
	//	image.onload = zoomPic();
		window.setTimeout("zoomPic()", 500);
}

function zoomPic()	{
		var widthN = 0;
		var heightN = 0;
		var position = 0;
		if (screen.width <= 1280)	{
				widthN = 800;
				heightN = 600;
		} else {
				widthN = 800;
				heightN = 800;
		}
		if (image.width > image.height) {
				heightN	= Math.floor(widthN * image.height / image.width);
		} else if (image.height > image.width)	{
				widthN = Math.floor(heightN * image.width / image.height);
		}
		position = Math.floor(((screen.width / 2) - widthN / 2) - 12);
		document.getElementById("zoomedpic").width = widthN;
		document.getElementById("zoomedpic").height = heightN;
		document.getElementById("zoomedpic").src = image.src;
		document.getElementById("zoompic").style.left = position + "px"; 
		document.getElementById("zoompic").style.visibility = 'visible'; 
}

function closeZoom()	{
		document.getElementById("zoompic").style.visibility = 'hidden'; 
		image = null;
}
