/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function emailcheck(str) {

    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
//	   alert("Invalid E-mail ID")
       return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
//	   alert("Invalid E-mail ID")
       return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
//	    alert("Invalid E-mail ID")
        return false
    }

     if (str.indexOf(at,(lat+1))!=-1){
//	    alert("Invalid E-mail ID")
        return false
     }

     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
//	    alert("Invalid E-mail ID")
        return false
     }

     if (str.indexOf(dot,(lat+2))==-1){
//	    alert("Invalid E-mail ID")
        return false
     }
    
     if (str.indexOf(" ")!=-1){
//	    alert("Invalid E-mail ID")
        return false
     }

    if (str.substring(lstr-1,lstr)==dot) {
        return false
    }

     return true					
    }


function validateform_en() {
    var err="";
    var foc="";
    if (document.getElementById("givenname").value=="") {err+="Given Name\n"; if (foc=="") {foc="nev";}}
    if (document.getElementById("familyname").value=="") {err+="Family Name\n";if (foc=="") {foc="cegnev";}}
    if (document.getElementById("phone").value=="") {err+="Phone/Mobile number\n";if (foc=="") {foc="cim";}}
    if (!emailcheck(document.getElementById("email").value)) {err+="The given e-mail address is not valid!\n";if (foc=="") {foc="email";}}
    if (err!="") {
	alert("Please fill the following informations:\n"+err);
	document.getElementById(foc).focus();
    } else {
	document.getElementById("rfiform").submit();
    }
}

function validateform_dk() {
    var err="";
    var foc="";
    if (document.getElementById("givenname").value=="") {err+="Fornavn\n"; if (foc=="") {foc="nev";}}
    if (document.getElementById("familyname").value=="") {err+="Efternavn\n";if (foc=="") {foc="cegnev";}}
    if (document.getElementById("phone").value=="") {err+="Telefon/Mobil\n";if (foc=="") {foc="cim";}}
    if (!emailcheck(document.getElementById("email").value)) {err+="The given e-mail address is not valid!\n";if (foc=="") {foc="email";}}
    if (err!="") {
	alert("Please fill the following informations:\n"+err);
	document.getElementById(foc).focus();
    } else {
	document.getElementById("rfiform").submit();
    }
}
