// JavaScript Document
function IsEmailValid(checkThisEmail, lng)
{
    var myEMailIsValid = true;
    var myAtSymbolAt = checkThisEmail.indexOf("@");
    var myLastDotAt = checkThisEmail.lastIndexOf(".");
    var mySpaceAt = checkThisEmail.indexOf(" ");
    var myLength = checkThisEmail.length;
    
    
    // at least one @ must be present and not before position 2
    // @yellow.com : NOT valid
    // x@yellow.com : VALID
    
    if (myAtSymbolAt < 1 )
	{myEMailIsValid = false}
    
    
    // at least one . (dot) afer the @ is required
    // x@yellow : NOT valid
    // x.y@yellow : NOT valid
    // x@yellow.org : VALID
    
    if (myLastDotAt < myAtSymbolAt)
	{myEMailIsValid = false}
    
    // at least two characters [com, uk, fr, ...] must occur after the last . (dot)
    // x.y@yellow. : NOT valid
    // x.y@yellow.a : NOT valid
    // x.y@yellow.ca : VALID
    
    if (myLength - myLastDotAt <= 2)
	{myEMailIsValid = false}
    
    
    // no empty space " " is permitted (one may trim the email)
    // x.y@yell ow.com : NOT valid
    
    if (mySpaceAt != -1)
	{myEMailIsValid = false}
    
    
    if (myEMailIsValid == false)
	{
	    var msg = "Votre email "+checkThisEmail+" n'est pas valide !"; 
	    if (lng == 'EN') msg = "Your email "+checkThisEmail+" is not valid !"; 
	    if (lng == 'ES') msg = "Su correo electrónico "+checkThisEmail+" no es válido !"; 
		if (lng == 'CN') msg = "你不是有效的电子邮件 "+checkThisEmail+" !";
		if (lng == 'IT') msg = "Il vostro email "+checkThisEmail+" è non valido!";
		if (lng == 'DE') msg = "Dein email "+checkThisEmail+" ist unzulässig!";
		if (lng == 'TR') msg = "";

	    alert(msg);
	}
    return myEMailIsValid;
}
function IsUrlValid(v, lng)
{
    len = v.length;
    ind = v.indexOf("http://");
    dot = v.indexOf(".");
    if ((dot != -1) && (ind == 0) && (len > 12))
	return true;
    var msg = " n est pas une url valide !"; 
    if (lng == 'EN') msg = " is not a valid url !";     
    if (lng == 'ES') msg = " no es un URL válido !"; 
	if (lng == 'CN') msg = " 不是一个有效的URL !";
	if (lng == 'IT') msg = " non è un URL valido !";
	if (lng == 'DE') msg = " ist nicht ein gültiges URL !";
	if (lng == 'TR') msg = "";
    
    alert(v+msg);
    return false;
}
function IsTitleValid(t, lng)
{
    len = t.length;
    if (len >= 4) return true;
    var msg = "Le titre est trop court"; 
    if (lng == 'EN') msg = "Title is too short";     
    if (lng == 'ES') msg = "El título es demasiado corto";  
	if (lng == 'CN') msg = "标题太短";
	if (lng == 'IT') msg = "Il titolo è troppo corto";
	if (lng == 'DE') msg = "Titel ist zu kurz";
	if (lng == 'TR') msg = "";
	
    alert(msg);
    return false;
}
function IsDescValid(t, lng)
{
    len = t.length;
    if (len >= 20) return true;
    var msg = "La description est trop courte"; 
    if (lng == 'EN') msg = "Your description is too short";     
    if (lng == 'ES') msg = "La descripción es demasiado corta";     
	if (lng == 'CN') msg = "你描述太短";
	if (lng == 'IT') msg = "La vostra descrizione è troppo corta";
	if (lng == 'DE') msg = "Deine Beschreibung ist zu kurz";
	if (lng == 'TR') msg = "";
	
    alert(msg);
    return false;
}
function IsKeyword(k1, k2, k3, k4, lng)
{
    if (k1.length > 0 || k2.length > 0 || k3.length > 0 || k4.length > 0)
	return true;
    var msg = "Veuillez saisir au moins un mot clef"; 
    if (lng == 'EN') msg = "You must declare at least one keyword";     
    if (lng == 'ES') msg = "Quiere entender al menos una palabra clave";   
	if (lng == 'CN') msg = "你必须申报至少一个关键字";
	if (lng == 'IT') msg = "Dovete dichiarare almeno una parola chiave";
	if (lng == 'DE') msg = "Du mußt mindestens ein Schlüsselwort erklären";
	if (lng == 'TR') msg = "";
	
    alert(msg);
    return false;
}
function checkandsubmit(name, lng){
    // verif du titre
    ok = IsTitleValid(document.forms[name].title.value, lng);
    if (ok == false) return(3);
    // verif de l url
    ok = IsUrlValid(document.forms[name].url.value, lng);
    if (ok == false) return(2);
    // verif de la description
    ok = IsDescValid(document.forms[name].description.value, lng);
    if (ok == false) return(4);
    // verif de la presence d un mot clef au moins
    ok = IsKeyword(document.forms[name].keyword1.value, document.forms[name].keyword2.value, document.forms[name].keyword3.value, document.forms[name].keyword4.value, lng);
    if (ok == false) return(4);
    // verif de l email
    ok = IsEmailValid(document.forms[name].email.value, lng);
    if (ok == false) return(1);
    submitit(name);
    return(0);
}
function submitit(name){
	if(document.forms[name].cgv.checked == false) 
	alert('Vous devez accepter les conditions générales d\'utilisation.');
	else
	document.forms[name].submit();
	}
