﻿// JScript File

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function chr(AsciiNum)
{
	return String.fromCharCode(AsciiNum)
}

function validate_AddItemForm() 
{
    q=document.forms[0].q.value.toString();
    id_art=document.forms[0].id.value.toString();
    if (q.length != 0)
    {
        document.location ='ShowCaddie.aspx?id_art='+id_art+'&q='+q+'&topic=0&cmd=AddItem';
    }
}


function validate_ContactForm() 
{
    var s = document.forms[0].email.value.toString();
    var l = s.length;
    if (l == 0) {
        alert("L'e-mail ne peut être vide !");
        return(false);
    }
    if (l < 6) {
        alert("L'e-mail est une chaîne de caractères trop courte !");
        return(false);
    }
    if (s.indexOf("@") == -1) {
        alert("L'e-mail n'est pas valide !");
        return(false);
    }
    if (!((s.charAt(l-3) == ".")||(s.charAt(l-4) == ".")||(s.charAt(l-5) == "."))) {
        alert("L'e-mail ne contient pas un nom de domaine correct !");
        return(false);
    }

    var error_string = "Les champs suivants doivent être remplis :\n";
    var error_flag = false;
    var f = document.forms[0];
    if(f.nom.value.toString().length == 0) {
        error_flag = true;
        error_string += "     Nom\n";
    }
     
        
    if(f.message.value.toString().length == 0) {
        error_flag = true;
        error_string += "     Message\n";
    }
    if(error_flag) {
        alert(error_string);
        return false;
    } else 
            {	document.forms[0].submit();
            return true;
    }
}