/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function spp_popup(url)
{
    // Largeur et hauteur de la fenêtre
   	var popup_largeur	= 750;
   	var popup_hauteur	= 560;

    // Position haut et gauche de la fenêtre pour affichage centré dans l'écran
   	var popup_haut = ((screen.height - popup_hauteur)/2);
   	var popup_gauche = ((screen.width - popup_largeur)/2);

       // window.resizeTo(popup_largeur, popup_hauteur);
        //window.moveTo(popup_gauche, popup_haut);

        var win = window.open(url, "SPPLUS","status=yes,top="+popup_haut+",left="+popup_gauche+",width="+popup_largeur+",height="+popup_hauteur);
   	win.focus();
}

//Affiche les cgv en arrière plan
function afficher_cgv(url)
{
    window.opener.location = "http://www.idealangues.com/conditions-generales-conseil-achat-reservation-voyage-stage-sejour-linguistique-formation-anglais-fle-lille/";
    window.opener.reload();

    spp_popup(url);
}

//Efface l'invite de saisie du nom des étudiants du formulaire commission
function effacer_invite(message)
{
    if(document.getElementById("students").value == message)
        document.getElementById("students").value = "";
}

//Contrôle de validation du formulaire de la page index.php
function tester_formulaire_vente()
{
    //Initialisation
    var is_ok = true;
    var reg = new RegExp("^[a-zA-Z0-9\-_]+[a-zA-Z0-9\.\-_]*@[a-zA-Z0-9\-_]+\.[a-zA-Z\.\-_]{1,}[a-zA-Z\-_]+","i");
    var nom = document.getElementById("err_nom");
    var prenom = document.getElementById("err_prenom");
    var telephone = document.getElementById("err_telephone");
    var email = document.getElementById("err_email");
    var destination = document.getElementById("err_destination");
    var ecole = document.getElementById("err_ecole");
    var cgu = document.getElementById("err_cgu");

    //Nom
    nom.style.display = "none";
	document.getElementById("nom").value = js_trim(document.getElementById("nom").value);
    if(document.getElementById("nom").value == "") {nom.style.display = "inline"; is_ok = false;}

    //Prénom
    prenom.style.display = "none";
	document.getElementById("prenom").value = js_trim(document.getElementById("prenom").value);
    if(document.getElementById("prenom").value == "") {prenom.style.display = "inline"; is_ok = false;}

    //Telephone
    telephone.style.display = "none";
	document.getElementById("telephone").value = js_trim(document.getElementById("telephone").value);
    if(document.getElementById("telephone").value == "") {telephone.style.display = "inline"; is_ok = false;}
    if(!Verifchamp(document.getElementById("telephone").value, "telephone")) {telephone.style.display = "inline"; is_ok = false;}

    //email
    email.style.display = "none";
	document.getElementById("email").value = js_trim(document.getElementById("email").value);
    if(document.getElementById("email").value == "") {email.style.display = "inline"; is_ok = false;}
    if(!reg.test(document.getElementById("email").value)) {email.style.display = "inline"; is_ok = false;}

    //Destination
    destination.style.display = "none";
	document.getElementById("destination").value = js_trim(document.getElementById("destination").value);
    if(document.getElementById("destination").value == "") {destination.style.display = "inline"; is_ok = false;}

    //Ecole
    ecole.style.display = "none";
	document.getElementById("ecole").value = js_trim(document.getElementById("ecole").value);
    if(document.getElementById("ecole").value == "") {ecole.style.display = "inline"; is_ok = false;}

    //CGU
    cgu.style.display = "none";
    if(document.getElementById("cb_cgu").checked == false) {cgu.style.display = "inline"; is_ok = false;}

    return is_ok;
}

//Contrôle de validation du formulaire de la page ârtners_payment.php
function tester_formulaire_commission()
{
    //Initialisation
    var is_ok = true;
    var reg = new RegExp("^[a-zA-Z0-9\-_]+[a-zA-Z0-9\.\-_]*@[a-zA-Z0-9\-_]+\.[a-zA-Z\.\-_]{1,}[a-zA-Z\-_]+","i");
    var school = document.getElementById("err_school");
    var phone = document.getElementById("err_phone");
    var email = document.getElementById("err_email");
    var students = document.getElementById("err_students");
    var amount = document.getElementById("err_amount");
    var cgu = document.getElementById("err_cgu");

    //School
    school.style.display = "none";
	document.getElementById("school").value = js_trim(document.getElementById("school").value);
    if(document.getElementById("school").value == "") {school.style.display = "inline"; is_ok = false;}

    //Phone
    phone.style.display = "none";
	document.getElementById("phone").value = js_trim(document.getElementById("phone").value);
    if(document.getElementById("phone").value == "") {phone.style.display = "inline"; is_ok = false;}
    if(!Verifchamp(document.getElementById("phone").value, "telephone")) {phone.style.display = "inline"; is_ok = false;}

    //Email
    email.style.display = "none";
	document.getElementById("email").value = js_trim(document.getElementById("email").value);
    if(document.getElementById("email").value == "") {email.style.display = "inline"; is_ok = false;}
    if(!reg.test(document.getElementById("email").value)) {email.style.display = "inline"; is_ok = false;}

    //Students
    students.style.display = "none";
	document.getElementById("students").value = js_trim(document.getElementById("students").value);
    if(document.getElementById("students").value == "") {students.style.display = "inline"; is_ok = false;}

    //Amount
    amount.style.display = "none";
	document.getElementById("amount").value = js_trim(document.getElementById("amount").value);
    if(document.getElementById("amount").value == "") {amount.style.display = "inline"; is_ok = false;}
    if(!Verifchamp(document.getElementById("amount").value, "montant")) {amount.style.display = "inline"; is_ok = false;}

    //CGU
    cgu.style.display = "none";
    if(document.getElementById("cb_cgu").checked == false) {cgu.style.display = "inline"; is_ok = false;}
    
    return is_ok;
}

//N'autorise que la saisie de caractères spécifiques
function Verifchamp(champ, type)
{
    var ret;
    var nbrcar = champ.length;
    var goodcar;
    if(type == "telephone")
        goodcar = " +0123456789";
    else if(type == "montant")
        goodcar = ".0123456789";
    else
        goodcar = "";

    for(cnt=0; cnt<nbrcar ; cnt++)
    {
        var car = champ.substr(cnt,1);
        if(goodcar.indexOf(car) >= 0)
        {
            ret = true;
        }
        else
        {
            ret = false;
            break;
        }
    }
    return ret;
}

function limite(zone,max)
{
     if(zone.value.length>=max){zone.value=zone.value.substring(0,max);}
}

function js_trim(str)
{
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
