// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in national phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in a national phone no.
var minDigitsInIPhoneNumber = 9;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


function isValidEmail(str) {

   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}


function checknumber(){
var x= document.mail_form.CodePostal.value
var anum=/(^\d+$)|(^\d+\.\d+$)/ 
if (anum.test(x))
testresult=true
else{
testresult=false
}
return (testresult)
}




function verifSelection() {if (document.mail_form.Media.value == "") {
alert("Bitte geben Sie den Titel Ihres Mediums/Redaktion ein")
return false
} if (document.mail_form.Nom.value == "") {
alert("Bitte geben Sie Ihren Namen ein")
return false
} if (document.mail_form.Prenom.value == "") {
alert("Bitte geben Sie Ihren Vornamen ein")
return false
}
if (document.mail_form.Rue.value == "") {
alert("Bitte geben Sie Ihre Adresse ein")
return false
}
if (document.mail_form.CodePostal.value == "") {
alert("Bitte geben Sie eine gültige PLZ ein")
return false
}
if (checknumber(document.mail_form.CodePostal.value)==false) {
alert("Bitte geben Sie eine gültige PLZ ein")
return false
} 
if (document.mail_form.Ville.value == "") {
alert("Bitte geben Sie eine Stadt ein")
return false
}
if (document.mail_form.Adresse.value == "") {
alert("Bitte geben Sie eine gültige E-Mail Adresse ein")
return false
}


invalidChars = " /:,;'"

for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
badChar = invalidChars.charAt(i)

if (document.mail_form.Adresse.value.indexOf(badChar,0) > -1) {
alert("Votre adresse e-mail contient des caractères invalides. Veuillez vérifier.")

return false
}
}

atPos = document.mail_form.Adresse.value.indexOf("@",1)			// there must be one "@" symbol
if (atPos == -1) {
alert('Ihre E-Mail Adresse enthält kein "@-Zeichen"')

return false
}

if (document.mail_form.Adresse.value.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
alert('Il ne doit y avoir qu\'un signe "@". Veuillez vérifier.')

return false
}

periodPos = document.mail_form.Adresse.value.indexOf(".",atPos)

if (periodPos == -1) {					// and at least one "." after the "@"
alert('Bitte fügen Sie nach dem "@-Zeichen" einen Punkt ein')

return false
}

if (periodPos+3 > document.mail_form.Adresse.value.length)	{		// must be at least 2 characters after the 
alert('Il doit y avoir au moins deux caractères après le signe ".". Veuillez vérifier.')

return false
}


if (document.mail_form.telephone.value == "") {
alert("Bitte geben Sie eine gültige Tel. Nr. ein")
return false
} if (checkInternationalPhone(document.mail_form.telephone.value)==false) {
alert("Bitte geben Sie eine gültige Tel. Nr. ein")
return false
} 
}
