function goToPage(pageID) {
	self.location.href = "online_veranstaltung.html?eventID="+pageID;
}

function displayGallery(url, top, left, width, height) {
	var Win = window.open(url,"displayGallery",'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height + ',location=no,resizable=no,scrollbars=no,menubar=no,toolbar=no,status=no');
}
function displayPresentation(top, left, width, height) {
	if (document.gallery.ppt.selectedIndex == 1) {
		document.location.href = document.gallery.ppt.options[document.gallery.ppt.selectedIndex].value;
	}
	else {
		if ((document.gallery.ppt.selectedIndex != 0) && (document.gallery.ppt.selectedIndex != 3)) {
			var Win = window.open('powerpoint/powerpoint-browser.html?src='+document.gallery.ppt.options[document.gallery.ppt.selectedIndex].value,"displayPresentation",'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height + ',location=no,resizable=no,scrollbars=no,menubar=no,toolbar=no,status=no');
		}
		document.gallery.ppt.selectedIndex = 0;
	}
}
function displayConditions(url, top, left, width, height) {
	var Win = window.open(url,"displayConditions",'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height + ',location=no,resizable=no,scrollbars=yes,menubar=no,toolbar=no,status=no');
}

function popup_antrag_ausfuellen(new_href) {
	var popup = window.open("popup.html","popup","left=0,top=0,width=800,height=600,scrollbars=yes,resizable=no,location=no,menubar=no,status=no,toolbar=no");
	popup.focus();

	document.location.href = new_href;
}

function popup () {
	var popup = window.open("../../popup.html","popup","left=0,top=0,width=675,height=600,scrollbars=yes,resizable=no,location=no,menubar=no,status=no,toolbar=no");
}

function isValidEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1) return false

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false

	if (str.indexOf(at,(lat+1))!=-1) return false

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false

	if (str.indexOf(dot,(lat+2))==-1) return false

	if (str.indexOf(" ")!=-1) return false

	return true
}

function TrimString(sInString) {
	sInString = sInString.replace( /^\s+/g, "" );// strip leading
	return sInString.replace( /\s+$/g, "" );// strip trailing
}

function validateForm2(objFrm) {
	var arrFields = new Array();
	arrFields[0] = "vorname_1";
	arrFields[1] = "name_1";
	arrFields[2] = "strasse_1";
	arrFields[3] = "plz_1";
	arrFields[4] = "ort_1";

	var arrFields2 = new Array();
	arrFields2[0] = "vorname_2";
	arrFields2[1] = "name_2";
	arrFields2[2] = "strasse_2";
	arrFields2[3] = "plz_2";
	arrFields2[4] = "ort_2";

	person1 = ((objFrm.addPerson_1) ? objFrm.addPerson_1.checked : false);
	person2 = ((objFrm.addPerson_2) ? objFrm.addPerson_2.checked : false);
	
	errorEmail = "";
	
	if(person1) {
		var errMsg = "";
		var error = false;

		for(var i in arrFields) {
			strVal = new String(objFrm.elements[arrFields[i]].value);
			strVal = TrimString(strVal);
			if(strVal.length == 0) {
				error = true;
				errMsg += "Ihre Angaben waren nicht vollständig. Bitte füllen Sie die mit Stern (*) gekennzeichneten Felder aus.\n";
				break;
			}
		}
		
		if(objFrm.newsletter_1 && objFrm.newsletter_1.checked) {
			if(isValidEmail(objFrm.email_1.value) === false) {
				error = true;
				errorEmail = "Bitte tragen Sie Ihre E-Mail-Adresse ein, um den Newsletter zu abonnieren.\n";		
			}
		}		
		
	}

	if(person2) {
		var errMsg = "";
		var error = false;

		for(var i in arrFields2) {
			strVal = new String(objFrm.elements[arrFields2[i]].value);
			strVal = TrimString(strVal);
			if(strVal.length == 0) {
				error = true;
				errMsg += "Ihre Angaben waren nicht vollständig. Bitte füllen Sie die mit Stern (*) gekennzeichneten Felder aus.\n";
				break;
			}
		}

		if(objFrm.newsletter_2 && objFrm.newsletter_2.checked) {
			if(isValidEmail(objFrm.email_2.value) === false) {
				error = true;
				errorEmail = "Bitte tragen Sie Ihre E-Mail-Adresse ein, um den Newsletter zu abonnieren.\n";		
			}
		}
	}

	if(error)
		alert(errMsg+errorEmail);
	else {
		objFrm.toSubmit.value = 4;
		objFrm.submit();
	}
}

function validateForm(objFrm) {
	var arrFields = new Array();
	arrFields[0] = "vorname";
	arrFields[1] = "name";
	arrFields[2] = "strasse";
	arrFields[3] = "plz";
	arrFields[4] = "ort";

	var errMsg = "";
	var error = false;
	for(var i in arrFields) {
		strVal = new String(objFrm.elements[arrFields[i]].value);
		strVal = TrimString(strVal);
		if(strVal.length == 0) {
			error = true;
			errMsg += "Ihre Angaben waren nicht vollständig. Bitte füllen Sie die mit Stern (*) gekennzeichneten Felder aus.\n";
			break;
		}
	}

	var counter = objFrm.counter.value;
	var ifChecked = false;
	if(objFrm.event[0]) {
		for(i = 0; i < counter; i++) {
			if(objFrm.event[i].checked) {
				ifChecked = true;
				break;
			}
		}
	}
	else {
		if(objFrm.event.checked) {
			ifChecked = true;
		}
	}
	
	if(!ifChecked) {
		error = true;
		errMsg += "Bitte wählen Sie eine Veranstaltung aus!\n";
	}
	
	if(objFrm.anrede[0].checked === false && objFrm.anrede[1].checked === false) {
		error = true;
		errMsg += "Bitte wählen Sie eine Anrede aus.\n";
	}

	if(objFrm.newsletter && objFrm.newsletter.checked) {
		if(isValidEmail(objFrm.email.value) === false) {
			error = true;
			errMsg += "Bitte tragen Sie Ihre E-Mail-Adresse ein, um den Newsletter zu abonnieren.\n";		
		}
	}

	if(error) {
		alert(errMsg);
	}
	else {
		objFrm.toSubmit.value = 1;
		objFrm.submit();
	}
}
/*
function getFlashMovieObject(id) {
   	return window.document["flips_"+id];
}


function sendDataToFlashMovie(id) {

	var flashMovie = getFlashMovieObject(id);
	flashMovie.SetVariable("/:message", id);
	flashMovie.SetVariable("/:ID", id);
	flashMovie.SetVariable("ID", id);
}
*/

function goToForm(eventID) {
	document.location = "online_veranstaltung.html?eventID="+eventID;
}

function openSelectorLink(targetlink) {
	if(targetlink == "nothing") {
		document.forms["selector"].reset();
		document.forms["selector"].elements[0].blur();
		return;
	} else if (targetlink.substring(0,7) == "http://") {
  		window.open(targetlink, "_blank");
	} else {
		if (document.getElementsByTagName("base")[0].href) {
			document.location.href = document.getElementsByTagName("base")[0].href+targetlink;
		} else {
			document.location.href = targetlink;
		}
		document.forms["selector"].reset();
		document.forms["selector"].elements[0].blur();
	}
}

