/*
	This is the property of EnterWeb (EW), registrered trademark (TM). All rights reserved.
	This content is protected by copyright law and international treaties.
	Unauthorized reproduction or distribution of this material, or any portion of it, 
	may result in severe civil and criminal penalties, and will be prosecuted to the
	maximum extent possible under the law. Copyright 2003 EnterWeb Corp.
*/

function validateEmail(nyhedstjeneste) {
    //var frm = document.forms["formularNyhedsbrev"];
    var frm = document.forms[nyhedstjeneste];
    //alert(frm.email.value);
    var error = 0;

    if (frm.email.value == "")
	{
	    alert("Fyld venligst E-mail feltet ud!");
	    frm.email.focus();
	    frm.email.select();
	    //return false;
	    error = 1;
	    //alert("første:" + error);
	}
    
	else {
	    /*Control for non acceptables signs, examples:[space/:,;]*/
	    if (error == 0) {
	        unAcceptableSigns = " /:,;"
	        for (i = 0; i < unAcceptableSigns.length; i++) {
	            aFailureSign = unAcceptableSigns.charAt(i);
	            if (frm.email.value.indexOf(aFailureSign, 0) > -1) {
	                //alert("Din Email indeholder følgende ikke tilladte tegn!: " + '" ' + aFailureSign + ' "');
	                alert("Din E-mail indeholder ikke tilladte tegn!");
	                frm.email.focus();
	                frm.email.select();
	                //return false;
	                error = 1;
	            }
	        }
	    }
	    
	    /*Control for emails examples: "@dukeaol.com" and "duke.aol.com"*/
	    if (error == 0) {
	        posistionOfAtSign = frm.email.value.indexOf("@", 1);
	        if (posistionOfAtSign == -1) {
	            alert("Your email contains no @ sign, or it is wrong placed!");
	            frm.email.focus();
	            frm.email.select();
	            //return false;
	            error = 1;
	        }
	    }

	    /*Control for no more than one @ sign, example: duke@@aol.com duke@a@ol.com*/
	    if (error == 0) {
	        if (frm.email.value.indexOf("@", posistionOfAtSign + 1) != -1) {
	            alert("Your email's contains two @ sign!");
	            frm.email.focus();
	            frm.email.select();
	            //return false;
	            error = 1;
	        }
	    }

	    /*Control for containing a dot "." after the @ sign*/
	    if (error == 0) {
	        dotPosistion = frm.email.value.indexOf(".", posistionOfAtSign);
	        if (dotPosistion == -1) {
	            alert("Your email contains no dot after the @ sign!");
	            frm.email.focus();
	            frm.email.select();
	            //return false;
	            error = 1;
	        }
	    }

	    /*Control that there are at least two character's after the dot*/
	    if (error == 0) {
	        if (dotPosistion + 3 > frm.email.value.length) {
	            alert("Emails have at least two character's after the dot!");
	            frm.email.focus();
	            frm.email.select();
	            //return false;
	            error = 1;
	        }
	    }
	} //end else

    if  (error == 0) {
	    frm.submit();
	}
	//return true;
}
