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

function reloadCaptcha(){
    var currentTime = new Date();
    document.getElementById("codeimage").src='captcha.do?'+currentTime;
}

function preRegAction(sessionid){
    document.getElementById("proc").style.display = "inline";
    $.ajax({
        type: "POST",
        url: "preRegAction.do",
        data: "sid="+sessionid+"&nick="+document.registerForm.nickname.value+"&mail1="+document.registerForm.email1.value+"&mail2="+document.registerForm.email2.value+"&password="+document.registerForm.password.value+"&mysexe="+document.registerForm.mysexe.value+"&myday="+document.registerForm.myday.value+"&mymonth="+document.registerForm.mymonth.value+"&myyear="+document.registerForm.myyear.value+"&myip="+document.getElementById("myip").value,
        success: function(msg){
            document.getElementById("proc").style.display = "none";
            type=msg.getElementsByTagName("type")[0].firstChild.nodeValue;
            if(type=="error"){
               var   message=msg.getElementsByTagName("message")[0].firstChild.nodeValue;
                $('#notification_err').fadeIn(1);
                $('#cgu').fadeOut(1);
                // document.getElementById("notification_err").style.display = "inline";
                // document.getElementById("cgu").style.display = "none";
                document.getElementById("message_err").innerHTML=message;
               
                setTimeout("$('#notification_err').fadeOut(1000);",2000);
                setTimeout("$('#cgu').fadeIn(500);",3200);

            }else if(type=="accepted"){
                document.getElementById("reg_form").style.display = "none";
                document.getElementById("reg_captcha").style.display = "inline";
            }
        }
    });
}
function ignoreInvite(){
    $.ajax({
        type: "POST",
        url: "IgnoreInviteFriends.do",
        data: "",
        success: function(msg){
            gotostep2();
        }
    });
}
function verifCaptchaAction(sessionid){
    document.getElementById("proc").style.display = "inline";
    $.ajax({
        type: "POST",
        url: "verifCaptcha.do",
        data: "sid="+sessionid+"&captcha="+document.getElementById("captcha_response").value,
        success: function(msg){
           var   type=msg.getElementsByTagName("type")[0].firstChild.nodeValue;
            if(type=="error"){
                message=msg.getElementsByTagName("message")[0].firstChild.nodeValue;
                $('#notification_err').fadeIn(1);
                $('#cgu').fadeOut(1);
                // document.getElementById("notification_err").style.display = "inline";
                // document.getElementById("cgu").style.display = "none";
                document.getElementById("message_err").innerHTML=message;

                setTimeout("$('#notification_err').fadeOut(1000);",2000);
                setTimeout("$('#cgu').fadeIn(500);",3200);
            }else if(type=="accepted"){
                if(document.getElementById("accept_emails").checked==true){
                    document.getElementById('acceptemails').value='true';
                }else{
                    document.getElementById('acceptemails').value='false';
                }
                document.getElementById('lacaptcha').value=document.getElementById("captcha_response").value;
                document.forms['registerForm'].submit();
            }
            
        }
    });
}

function showstep(step){
    if(step=='2'){
        gotostep2();
    }else if(step=='3'){
        gotostep3();
    }else{
        gotostep1();
    }

}

function gotostep1(){
    document.getElementById("wizard_step1").style.display = "inline";
    document.getElementById("wizard_step2").style.display = "none";
    document.getElementById("wizard_step3").style.display = "none";
    document.getElementById("wizard").className = "etape1";
}
function gotostep2(){
    document.getElementById("wizard_step1").style.display = "none";
    document.getElementById("wizard_step2").style.display = "inline";
    document.getElementById("wizard_step3").style.display = "none";
    document.getElementById("wizard").className = "etape2";
}
function gotostep3(){
    document.getElementById("wizard_step1").style.display = "none";
    document.getElementById("wizard_step2").style.display = "none";
    document.getElementById("wizard_step3").style.display = "inline";
    document.getElementById("wizard").className = "etape3";
}
function gotorooms(){
    
    document.location="home.html";
    
}
function register_step1(sessionid){
    document.getElementById("proc1").style.display = "inline";
    $.ajax({
        type: "POST",
        url: "Register_Step1.do",
        data: "sid="+sessionid+"&invitemail="+document.getElementById("invitemail").value+"&invitepassword="+document.getElementById("invitepassword").value,
        success: function(msg){
            document.getElementById("proc1").style.display = "none";
           var   message=msg.getElementsByTagName("message")[0].firstChild.nodeValue;
            if(message=="error1"){
                document.getElementById("notification_err1").style.display = "inline";
                document.getElementById("message_err").innerHTML="Vous devez remplir tout les champs.";
            }else if(message=="error2"){
                document.getElementById("notification_err1").style.display = "inline";
                document.getElementById("message_err").innerHTML="Adresse E-MAIL incorrecte.";
            }else {
                gotostep2();
            }
        }
    });
}

function register_step2(sessionid){
    var name=document.getElementById("name").value;
    var sname=document.getElementById("sname").value;
    var country=document.getElementById("country").value;
    var departement=document.getElementById("departement").value;
    var interest_male=document.getElementById("interest_male").checked ;
    var interest_female=document.getElementById("interest_female").checked ;
    var loocking_freind=document.getElementById("loocking_freind").checked ;
    var loocking_meeting=document.getElementById("loocking_meeting").checked ;
    var loocking_relationship=document.getElementById("loocking_relationship").checked ;
    $.ajax({
        type: "POST",
        url: "Register_Step2.do",
        data:"sid="+sessionid+"&name="+name+"&sname="+sname+"&country="+country+"&departement="+departement+"&interest_male="+interest_male+"&interest_female="+interest_female+"&loocking_freind="+loocking_freind+"&loocking_meeting="+loocking_meeting+"&loocking_relationship="+loocking_relationship,
        success: function(msg){
            document.getElementById("proc2").style.display = "none";
           var   message=msg.getElementsByTagName("message")[0].firstChild.nodeValue;
            if(message=="cf_name"){
                document.getElementById("notification_err2").style.display = "inline";
                document.getElementById("message_err2").innerHTML="Vous devez saisir votre nom.";
            }else if(message=="cf_sname"){
                document.getElementById("notification_err2").style.display = "inline";
                document.getElementById("message_err2").innerHTML="Vous devez saisir votre prénom.";
            }else if(message=="cf_departement"){
                document.getElementById("notification_err2").style.display = "inline";
                document.getElementById("message_err2").innerHTML="Vous devez saisir votre département.";
            }else if(message=="cf_interest"){
                document.getElementById("notification_err2").style.display = "inline";
                document.getElementById("message_err2").innerHTML="Vous devez préciser si vous étes interssé par les hommes ou les femmes ou bien les deux a la fois.";
            }else if(message=="cf_loocking"){
                document.getElementById("notification_err2").style.display = "inline";
                document.getElementById("message_err2").innerHTML="Vous devez préciser la nature de la (ou les) relation(s) que vous chercher.";
            }else {
                gotostep3();
            }
        }
    }); 
}
function register_step3(sessionid){
    var filename=document.getElementById("frm_file").value;
    if(filename==''){
        document.getElementById("notification_err3").style.display = "inline";
        document.getElementById("message_err3").innerHTML="Veuillez choisir une image puis cliquez sur enregistrer";
    }else{
        document.forms['frm_upload'].submit();
    }
}

