﻿// Fichier JScript
var loadingTimer,loadingFrame=1;

function afficheContact(){

    showLoading();
    var pos = getViewport();
    $("#popContact").css({'display': 'block'});
    $("#popContact #contact_msgSend").css({'display': 'none'});
    $("#popContact #contact_msgEnCours").css({'display': 'none'});
    $("#popContact_content").css({'left': ((pos[0] - 450) / 2 + pos[2]), 'top': ((pos[1] - 400) / 2 + pos[3])});
    return false;
}

function maskContact(){
     $("#fancy_loading").hide();
     $("#popContact").css({'display': 'none'});
	 return false;
}

$(document).ready(function()
{

	if(jQuery.checkbox)
	{
	   $('#popContact input:radio').checkbox({empty:'/js/jquery-checkbox.1.3.0b1/empty.png'});
	}
   var path="";//"~/xdmnbckdr/";
 
   //////////////////// AFFICHER LA POP UP DE LOGIN ////////////////////////////////  

    $("#contact_ok").click(function() {
        var result = checkForm();
        if (result == true){
            $("#popContact #contact_msgSend").css({'display': 'none'});
            var _nom = $("#contact_last_name").val();
            var _prenom = $("#contact_first_name").val();
            var _company = $("#contact_company").val();
            var _phone = $("#contact_phone").val();
            var _country = $("#contact_country").val();
            var _email = $("#contact_email").val();
            var _msg = $("#contact_msg").val();
            
            
           _mail = $("#popForgotPassword #email").val()
           
           $("#popContact #contact_msgEnCours").css({'display': 'block'});
           
            $.ajax({
                type : 'POST',
                url  : path+'contact.aspx',
                data : {nom:_nom,prenom:_prenom,company:_company,phone:_phone,country:_country,email:_email,msg:_msg},
                success: function(result) {
                    //alert(result);
                    if(result=="send"){
                        //envoi effectué
                        maskContact();
                    }
                    else{
                        //échec d'envoi de l'email
                        $("#popContact #contact_msgSend").css({'display': 'block'});
                    }
                }
            });  
           }
           else{
            $("#popContact #contact_msgEnCours").css({'display': 'none'});
            $("#popContact #contact_msgSend").css({'display': 'block'});
           }
		   return false;
    });    
   
});

function checkForm(){
    var okForm = true
    
    if ($("#contact_last_name").val() == "") {
        okForm = false;
    }
    if ($("#contact_first_name").val() == "") {
        okForm = false;
    }
    if ($("#contact_email").val() == "") {
        okForm = false;
    }        
    if ($("#contact_msg").val() == "") {
        okForm = false;
    }      
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = $("#contact_email").val();
   if(reg.test(address) == false) {
       okForm = false;
   }    
   
    return okForm;
}



//////////////////// LOADING ////////////////////////////////

function animateLoading() {
    if (!$("#fancy_loading").is(':visible')){
        clearInterval(loadingTimer);
        $("#fancy_overlay").hide();
        return;
    }

    $("#fancy_loading > div").css('top', (loadingFrame * -40) + 'px');

    loadingFrame = (loadingFrame + 1) % 12;
};    
function showLoading() {
    $("#fancy_overlay").show();
    clearInterval(loadingTimer);

    var pos = getViewport();

    $("#fancy_loading").css({'left': ((pos[0] - 40) / 2 + pos[2]), 'top': ((pos[1] - 40) / 2 + pos[3])}).show();
    loadingTimer = setInterval(animateLoading, 66);
};
function getViewport() {
    return [$(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];  
}


