function showAlert(tekst) {
  alert(tekst);
}

function ConfirmLink(question,redirect) {
if (confirm(question)) {
  document.location.href(redirect);
  }
}

function sendForm(question, v) { 
if (confirm(question)) {
  document.vismailsformular.strfunction.value = (v); 
  document.vismailsformular.submit(); 
  }
} 

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
  field.value = field.value.substring(0, maxlimit);
else 
  countfield.value = maxlimit - field.value.length;
}

function ValidateEmail(strEmail) {
	if ((strEmail!="") && (VECharPos(strEmail)) && (VECountAts(strEmail)) && (VEIligalChars(strEmail))) {
	 	return true;
	 }
	 else {
	 	return false;
	 }
}

function VECharPos(strEmail) {
	if ((strEmail.indexOf("@",0) > 0) && (strEmail.indexOf(".",strEmail.indexOf("@",1) + 2) != "-1") && (strEmail.indexOf(".",0) >= 1) && (strEmail.charAt(strEmail.length-1) != "@") && (strEmail.charAt(strEmail.length-1) != ".")) {
		return true;
	} else {
		return false;
	}
}

function VECountAts(strEmail) {
	if (strEmail.indexOf("@",(strEmail.indexOf("@",0)+1)) == "-1") {
		return true;
	}
	else {
		return false;
	}
}

var VELegalChars = "abcdefghijklmnopqrstuvwxyz0123456789.@-_";
function VEIligalChars(strEmail) {
	for (i=0;i<strEmail.length;i++) {
		if (VELegalChars.indexOf((strEmail.toLowerCase()).charAt(i),0) == "-1") {
			return false;
		}
	}
	return true;
}

/*function trim(strText) { 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}
*/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function beregn() {
	var rk=0
	var tot=0
	if ($("mj").checked || $("mn").checked) {
  	for (n=1;n<=5;n++) {
  		if (trim($("a"+n).value)!="") {
  			rk++;
  		  $("b"+n).value=$("pris"+n).innerHTML;	
  		  tot+=parseInt($("b"+n).value);
  		}
  		else
  		{ 
  			$("b"+n).value=""
  		}
  	}
 	  $("tot").value=tot
 	  if (rk>3) {
 	  	alert("Du har tilmeldt dig for mange rękker");
 	  return false
 	  }
 	  return true;
  }
  else
  {
  	alert("Angiv medlem/ikke medlem!")
  	$("klub").focus()
  	return(false)
  }
}
function setpris(med) {
	$("BLOK").style.display="block";
	if (med==1) {
		$("pris1").innerHTML=175;
		$("pris2").innerHTML=175;
		$("pris3").innerHTML=125;
		$("pris4").innerHTML=125;
		$("pris5").innerHTML=125;
	} else {
		$("pris1").innerHTML=250;
		$("pris2").innerHTML=250;
		$("pris3").innerHTML=200;
		$("pris4").innerHTML=200;
		$("pris5").innerHTML=200;
	}
	for (n=1;n<=5;n++) {
		$("b"+n).readOnly=true;
	}
	$("tot").readOnly=true;
  $("BEREGN SELV").style.display="none"; 
  beregn()
}

function checkfelter() {
	var felter=$("required").value;
	var felt
	aReq=felter.split(",")
	for (n=0;n<aReq.length;n++) {
		felt=document.getElementsByName(aReq[n])[0]
		if (trim(felt.value)=="") {
		  alert("Feltet "+aReq[n]+" skal udfyldes");
		  felt.focus();
		  return false;
		}
	}
	for (n=3;n<=6;n++) {
		if (trim($("a"+n).value)>"" && trim($("d"+n).value)=="") {
			alert("Skriv makkers navn");
			$("d"+n).focus()
			return false
		}
	}
	return true;
}

