/*function regexpsupported() {
	if(window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) return true;
	}
	return false;
}

function checkifmail(mail) {
	if(regexpsupported()) {
		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
		return (!r1.test(feld) && r2.test(feld));	
	}
	return true;
}*/

function validEmail(email) {
  var strReg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
  var regex = new RegExp(strReg);
  return(regex.test(email));
}

function checkracesignup(cys) {
	var missingfields = 0;
	var msg = "";

	if(window.document.SignUpForm.rid_i.selectedIndex < 0) {
		missingfields++;
		msg += "Regatta \n";
	}
	if(window.document.SignUpForm.name_i.value.length < 1) {
		missingfields++;
		msg += "Name \n"; 
	}
	if(window.document.SignUpForm.vorname_i.value.length < 1) {
		missingfields++;
		msg += "Vornamen \n"; 
	}
	/*
	if(window.document.SignUpForm.phone_i.value.length < 1) {
		missingfields++;
		msg += "Telefonnummer \n"; 
	}
	*/
	if(window.document.SignUpForm.mail_i.value.length < 1) {
		missingfields++;
		msg += "E-Mail-Adresse \n"; 
	}
	else if(!validEmail(window.document.SignUpForm.mail_i.value)) {
		missingfields++;
		msg += "Die angegebene E-Mail-Adresse ist nicht gültig! \n";
	} 
	
	if(window.document.SignUpForm.club_i.value.length < 1) {
		missingfields++;
		msg += "Club \n"; 
	}
	if(window.document.SignUpForm.sailnr_i.value.length < 1) {
		missingfields++;
		msg += "Segelnummer \n"; 
	}
	if( true /*window.document.SignUpForm.getElementById('boatclass_sel_i').value == "0"*/) {
		if(window.document.SignUpForm.boatclass_i.value.length < 1) {  //window.document.SignUpForm.boatclass_i.selectedIndex < 1
			missingfields++;
			msg += "Bootsklasse \n"; 
		}
	}
	else {
		if(window.document.SignUpForm.customclass_i.value.length < 1) {
			missingfields++;
			msg += "Bootsklasse \n"; 
		}
	}
	
	if((cys == true) && (window.document.SignUpForm.yardstick_i.value.length < 1)) {
		missingfields++;
		msg += "Yardstick \n"; 
	}
	if(window.document.SignUpForm.captcha_i.value.length < 1) {
		missingfields++;
		msg += "Sicherheitsüberprüfung \n"; 
	}
	if(window.document.SignUpForm.haftung_i.checked < 1) {
		missingfields++;
		msg += "Bitte den Haftungsausschluss akzeptieren! \n"; 
	}

	if(missingfields > 0) {
		alert("Bitte alle mit (*) gekennzeichneten Felder ausf"+unescape("%FC")+"llen:\n\n"+msg);
		return false;	
	}
	else {
		window.document.SignUpForm.action = window.document.SignUpForm.action+separator+'icuppid=11';		
		return true;
	}
}

function checkparticipant(cys) {
	var missingfields = 0;
	var msg = "";
	if(window.document.participantForm.rid_i.selectedIndex < 0) {
		missingfields++;
		msg += "Regatta \n"; 
	}
	if(window.document.participantForm.name_i.value.length < 1) {
		missingfields++;
		msg += "Name \n"; 
	}
	if(window.document.participantForm.vorname_i.value.length < 1) {
		missingfields++;
		msg += "Vornamen \n"; 
	}
	/*
	if(window.document.participantForm.phone_i.value.length < 1) {
		missingfields++;
		msg += "Telefonnummer \n"; 
	}
	*/
	if(window.document.participantForm.mail_i.value.length < 1) {
		missingfields++;
		msg += "E-Mail-Adresse \n"; 
	}
	else if(!validEmail(window.document.participantForm.mail_i.value)) {
		missingfields++;
		msg += "Die angegebene E-Mail-Adresse ist nicht gültig! \n";
	} 
	if(window.document.participantForm.club_i.value.length < 1) {
		missingfields++;
		msg += "Club \n"; 
	}
	if(window.document.participantForm.sailnr_i.value.length < 1) {
		missingfields++;
		msg += "Segelnummer \n"; 
	}
	if(window.document.participantForm.boatclass_i.selectedIndex < 0) {
		missingfields++;
		msg += "Bootsklasse \n"; 
	}
	if((cys == true) && (window.document.participantForm.yardstick_i.value.length < 1)) {
		missingfields++;
		msg += "Yardstick \n"; 
	}
	
	if(missingfields > 0) {
		alert("Bitte alle mit (*) gekennzeichneten Felder ausf"+unescape("%FC")+"llen:\n\n"+msg);
		return false;	
	}
	else return true;
}

function checkparticipantadd(cys) {
	if(checkparticipant(cys)) {
		window.document.participantForm.action = window.document.participantForm.action+separator+'icupact=participantadd';
		return true;
	}
	else return false;
}

function checkparticipantedit(cys) {
	if(checkparticipant(cys)) {
		window.document.participantForm.action = window.document.participantForm.action+separator+'icupact=participantedit';
		return true;
	}
	else return false;
}

function checkparticipanteditselected() {
	var fi = 0;
	for(fi=0;fi<window.document.participantsList.elements.length - 3;fi++) {
		if(window.document.participantsList.elements[fi].checked) {
			window.document.participantsList.action=window.document.participantsList.action+separator+'icuppid=13';
			return true;
		}
	}
	alert("Kein Teilnehmer ausgewählt!");	
	return false;
}

function checkparticipantcontact() {
	var missingfields = 0;
	var msg = "";

	if(window.document.participantContact.name_i.value.length < 1) {
		missingfields++;
		msg += "Name \n"; 
	}
	if(window.document.participantContact.vorname_i.value.length < 1) {
		missingfields++;
		msg += "Vornamen \n"; 
	}
	if(window.document.participantContact.mail_i.value.length < 1) {
		missingfields++;
		msg += "E-Mail-Adresse \n"; 
	}
	else if(!validEmail(window.document.participantContact.mail_i.value)) {
		missingfields++;
		msg += "Die angegebene E-Mail-Adresse ist nicht gültig! \n";
	} 
	/*
	if(window.document.participantContact.phone_i.value.length < 1) {
		missingfields++;
		msg += "Telefonnummer \n"; 
	}
	*/
	/*
	if(window.document.participantContact.text_i.value.length < 1) {
		missingfields++;
		msg += "Text \n"; 
	}
	*/	
	if(missingfields > 0) {
		alert("Bitte alle mit (*) gekennzeichneten Felder ausf"+unescape("%FC")+"llen:\n\n"+msg);
		return false;	
	}
	else return true;
}

function checkrace() {
	var missingfields = 0;
	var msg = "";
	
	if(window.document.raceForm.name_i.value.length < 1) {
		missingfields++;
		msg += "Bezeichnung \n"; 
	}
	if(window.document.raceForm.host_i.value.length < 1) {
		missingfields++;
		msg += "Ausrichter \n"; 
	}
	if(window.document.raceForm.date_from_i.value.length < 1) {
		missingfields++;
		msg += "Datum \n"; 
	}
	/*
	if(window.document.raceForm.participants_i.value.length < 1) {
		missingfields++;
		msg += "Teilnehmerzahl \n"; 
	}
	*/
	if(window.document.raceForm.period_i.value.length < 1) {
		missingfields++;
		msg += "Meldefrist \n"; 
	}
	/*
	if(window.document.raceForm.starttime_i.value.length < 1) {
		missingfields++;
		msg += "Startzeit \n"; 
	}
	*/
	if(window.document.raceForm.boatclass_sel_i.checked) {
		if(window.document.raceForm.boatclass_i.selectedIndex < 0) {
			missingfields++;
			msg += "Bootsklasse \n"; 
		}
	}
	else {
		if(window.document.raceForm.boatclass_customclass_i.length < 1) {
			missingfields++;
			msg += "Bootsklasse \n"; 
		}
	}
	if(missingfields > 0) {
		alert("Bitte alle mit (*) gekennzeichneten Felder ausf"+unescape("%FC")+"llen:\n\n"+msg);
		return false;	
	}
	else return true;
}

function checkraceadd() {
	if(checkrace()) {
		window.document.raceForm.action = window.document.raceForm.action+separator+'icupact=raceadd';
		return true;
	}
	else return false;
}

function checkraceedit() {
	if(checkrace()) {
		window.document.raceForm.action = window.document.raceForm.action+separator+'icupact=raceedit';
		return true;
	}
	else return false;
}

function checkuser() {
	var missingfields = 0;
	var msg = "";

	if(window.document.userForm.username_i.value.length < 1) {
		missingfields++;
		msg += "Benutzername \n"; 
	}
	if(window.document.userForm.vorname_i.value.length < 1) {
		missingfields++;
		msg += "Vorname \n"; 
	}
	if(window.document.userForm.nachname_i.value.length < 1) {
		missingfields++;
		msg += "Nachname \n"; 
	}
	if(window.document.userForm.password_i.value.length < 1) {
		missingfields++;
		msg += "Passwort \n"; 
	}	
	
	if(missingfields > 0) {
		alert("Bitte alle mit (*) gekennzeichneten Felder ausf"+unescape("%FC")+"llen:\n\n"+msg);
		return false;	
	}
	else return true;
}

function checkuseradd() {
	if(checkuser()) {
		window.document.userForm.action = window.document.userForm.action+separator+'icupact=useradd';
		return true;
	}
	else return false;
}

function checkuseredit() {
	if(checkuser()) {
		window.document.userForm.action = window.document.userForm.action+separator+'icupact=useredit';
		return true;
	}
	else return false;
}

function checkparticipantdel() {
	var selected = 0;
	for(fi=0;fi<window.document.participantsList.elements.length - 4;fi++) {
		if(window.document.participantsList.elements[fi].checked) selected++;
	}
	if(selected > 0) {
		if(confirm("Wollen sie den/die markierten Teilnehmer wirklich löschen?")) {
			window.document.participantsList.action = window.document.participantsList.action+separator+'icupact=participantdel';
			return true;
		}
	}
	else alert("Kein Teilnehmer ausgewählt!");	
	return false;
}

function checkraceeditselected() {
	var fi = 0;
	for(fi=0;fi<window.document.raceList.elements.length - 4;fi++) {
		if(window.document.raceList.elements[fi].checked) {
			window.document.raceList.action=window.document.raceList.action+separator+'icuppid=5';
			return true;
		}
	}
	alert("Keine Regatta ausgewählt!");	
	return false;
}

function checkracedel() {
	var selected = 0;
	for(fi=0;fi<window.document.raceList.elements.length - 4;fi++) {
		if(window.document.raceList.elements[fi].checked) selected++;
	}
	if(selected > 0) {
		if(confirm("Wollen sie die markierte Regatta wirklich löschen?")) {
			window.document.raceList.action = window.document.raceList.action+separator+'icupact=racedel';
			return true;
		}
	}
	else alert("Keine Regatta ausgewählt!");	
	return false;
}

function checkuserdel() {
	if(confirm("Wollen sie die markierte User wirklich löschen?")) {
		window.document.UserForm.action = window.document.UserForm.action+separator+'icupact=userdel';
		return true;
	}
	else return false;
}

function limittextarea(){
	var tempstr = window.document.SignUpForm.comment_i.value;
	if(tempstr.length > 255 ) tempstr = tempstr.substring(0,255);
	window.document.SignUpForm.comment_i.value = tempstr;
	return;
}

function jumpMenuSignUp(targ,indexfile){
  eval(targ+".location="+indexfile+"'"+separator+"icuppid=20&rid="+ window.document.SignUpForm.rid_i.options[window.document.SignUpForm.rid_i.selectedIndex].value+"'");
  return;
}

function jumpMenuRaceResults(targ,indexfile,rid){
  eval(targ+".location="+indexfile+"'"+separator+"icuppid=28&rid="+rid+"'");
  return;
}
