$(document).ready(function() {
    
    $('.hover').hover(function(){       
       $(this).attr("src", $(this).attr('src').replace(".png", "_hover.png"));
    }, function(){
        $(this).attr("src", $(this).attr('src').replace("_hover.png", ".png"));
    });
    
    $('.btn_savoir_plus').click(function(){
        $(".info_moteur").hide();
        $('.btn_savoir_plus').parent().parent().parent().children("dd.contenu_ent").removeClass("contenu_ent_click");
        $('.btn_savoir_plus').parent().parent().parent().children("dd.btn_download").hide();
        $('.btn_savoir_plus').parent().show();
        $(this).parent().parent().parent().parent().find('p.texteLegal').html(tarif);
        $curr =  $(this).parent();
        $curr.hide();
        $curr.parent().parent().children("dd.contenu_ent").addClass("contenu_ent_click");
        $curr.parent().parent().children("dd.btn_download").show(500);
//        $curr.parent().parent().next().slideDown();    
        return false;
    });

    $('.btnmin').click(function(){
        $(".info_moteur").hide();
        $('.btn_savoir_plus').parent().parent().parent().children("dd.contenu_ent").removeClass("contenu_ent_click");
        $('.btn_savoir_plus').parent().parent().parent().children("dd.btn_download").hide();
        $('.btn_savoir_plus').parent().show();
        $('p.texteLegal').html(mentions);
        $(this).parent().find('p.texteLegal').html(tarif);
        $curr =  $(this).find('.savoir_plus a');
        $curr.hide();
        $curr.parent().parent().children("dd.contenu_ent").addClass("contenu_ent_click");
        $curr.parent().parent().children("dd.btn_download").show(500);
//        $curr.parent().parent().next().slideDown();
        return false;
    });
    
    $('#clickBilan').click(function(){
	$('#liste_acte').hide();
	$('#liste_bilan').show(500);
	return false;
    });
    
       $('#clickActeNum').click(function(){
	$('#liste_bilan').hide();
	$('#liste_acte').show(500);
	return false;
    });
    
    $('.validation').click(function(){
        if(isFlextelOK()){
            $curr = $(this).parent();
            $curr.parent().children("dd.contenu_ent").removeClass("contenu_ent_click");
            $curr.parent().children('dd.savoir_plus').children('a').show();
            $curr.parent().parent().find('p.texteLegal').html(mentions);
            $curr.hide();
            return false;
        }
        $nom_entreprise = $(this).attr("rel");
        $rcs = $(this).parent('dd').attr("id");
        $("#my_result").hide();
        $('#page_install').show(500);
        $('#entreprise_choisi').html($nom_entreprise);
        $chemin = $('#chemin_exe').attr('value');
        $('#charge_exe').attr('src',$chemin);
        $chemin_image = './view/component/generate_btn.php?nom=' + $nom_entreprise;
        $('#btn_minitel_generate').attr('src',$chemin_image);
        document.getElementById('texte').style.display = "none";
        $url = './view/component/pose_cookie_result.php?rcs=' + $rcs;
        $.ajax({
	    type: "GET",
	    url: $url,
	    dataType : 'html',
	    success: function(msg){
		//alert(msg);					   
	    },
	    error: function(error){
		//alert('pas pouet');							
	    }
	});
        return false;
    });
    
    $('.validation_online').click(function(){
        $nom_entreprise = $(this).attr("rel");
        $rcs = $(this).parent('dd').attr("id");
        $("#my_result").hide();
        $('#page_install').show(500);
        $('#entreprise_choisi').html($nom_entreprise);
        $chemin = $('#chemin_exe').attr('value');
        $('#charge_exe').attr('src',$chemin);
        $chemin_image = './view/component/generate_btn.php?nom=' + $nom_entreprise + "&online";
        $('#btn_minitel_generate').attr('src',$chemin_image);
        $(".info_moteur:first").insertAfter("#btn_minitel_generate").css('marginLeft','105px').width('505px').show();
        //Cookies.set('ClickedRcsBeforeExe', $rcs, 365);
        return false;
    });
    
    $("#no_result_online").click(function() {
        $('#entreprise_choisi').html('que vous cherchez');
        $("#contenu_droit h2:first, #contenu_droit .modif_recherche_online, #no_result_online").hide();
        $('#page_install').show(500);
        $chemin = $('#chemin_exe').attr('value');
        $('#charge_exe').attr('src',$chemin);
    });
    $('span.prix_minitel a').click(function(){

    });
    
/* FLEXWEB : tout commenter laisse  if(checkFlextelCompat())
        { if(isFlextelOK()){ return false; } }
        $lien_minitel = 'http://www.ulysse-service.fr/w22stat/info-societe.com.php';
        $('#charge_minitel').attr('src',$lien_minitel);
        return false;*/
    $('.lance_minitel').click(function(){
        if(checkFlextelCompat())
        {
            if(!$("#btn_minitel_generate").hasClass('clicked'))
            {   
                $("#btn_minitel_generate").addClass('clicked');
                $("#btn_minitel_generate").attr('src','./image/btn_minitel/btn_flextel_02.png');
            }
            else
            {
                if(isFlextelOK()){
                    $("#btn_minitel_generate").attr('src','./image/btn_minitel/btn_flextel_01.png');
                    $("#btn_minitel_generate").removeClass('clicked');
                    $("#map_help").click(function() { });
                    return false;
                }
            }
            return false;
        }
        $lien_minitel = 'http://www.ulysse-service.fr/w22stat/info-societe.com.php';
        $('#charge_minitel').attr('src',$lien_minitel);
        return false;
    });

/* FLEXWEB : tout commenter laisse  if(checkFlextelCompat())
        { if(isFlextelOK()){ return false; } }
        $lien_minitel = 'http://www.ulysse-service.fr/mac/info-societe.com.php';
        $('#charge_minitel').attr('src',$lien_minitel);
        return false;*/
    $('.lance_minitel_mac').click(function(){
        if(checkFlextelCompat())
        {
            if(!$("#btn_minitel_generate").hasClass('clicked'))
            {
                $("#btn_minitel_generate").addClass('clicked');
                $("#btn_minitel_generate").attr('src','./image/btn_minitel/btn_flextel_02.png');
            }
            else
            {
                if(isFlextelOK()){
                    $("#btn_minitel_generate").attr('src','./image/btn_minitel/btn_flextel_01.png');
                    $("#btn_minitel_generate").removeClass('clicked');
                    $("#map_help").click(function() { });
                    return false;
                }
            }
            return false;
        }
        
        $lien_minitel = 'http://www.ulysse-service.fr/mac/info-societe.com.php';
        $('#charge_minitel').attr('src',$lien_minitel);
        return false;
    });

/* FLEXWEB : tout commenter laisse  if(checkFlextelCompat())
        { window.open('http://www.info-societe.com/help/cgu.html','Info', 'status=no, scrollbars=yes, toolbar=yes, menubar=no, width=666px, height=329px, top=250px, left='+(screen.width/2-287)+'px');
                return false; } else { window.open('http://www.info-societe.com/page/pinfo.php?d','Info', 'status=no, scrollbars=yes, toolbar=yes, menubar=no, width=666px, height=329px, top=250px, left='+(screen.width/2-287)+'px');
        }
        return false;*/
    $("#map_help").click(function() {
        if(checkFlextelCompat()) {
            if(!$("#btn_minitel_generate").hasClass('clicked')) {
                $("#btn_minitel_generate").addClass('clicked');
                $("#btn_minitel_generate").attr('src','./image/btn_minitel/btn_flextel_02.png');
            }
            else
            {
                window.open('http://www.info-societe.com/help/cgu.html','Info', 'status=no, scrollbars=yes, toolbar=yes, menubar=no, width=666px, height=329px, top=250px, left='+(screen.width/2-287)+'px');
                return false;
            }
        }
        else
        {
            window.open('http://www.info-societe.com/page/pinfo.php?d','Info', 'status=no, scrollbars=yes, toolbar=yes, menubar=no, width=666px, height=329px, top=250px, left='+(screen.width/2-287)+'px');
        }
        return false;
    });

/* FLEXWEB : tout commenter laisse  if(checkFlextelCompat())
        { if(isFlextelOK()){ return false; } } */
    $('.lance_exe').click(function(){
        if(checkFlextelCompat())
        {
            if(!$("#btn_minitel_generate").hasClass('clicked'))
            {
                $("#btn_minitel_generate").addClass('clicked');
                $("#btn_minitel_generate").attr('src','./image/btn_minitel/btn_flextel_02.png');
                $("#texte").html(tarifV2);
                $("#tarif").show();
                
            }
            else
            {
                if(isFlextelOK()){
                    $("#btn_minitel_generate").attr('src','./image/btn_minitel/btn_flextel_01.png');
                    $("#texte").html(mentionV2);
                    $("#tarif").hide();
                    $("#btn_minitel_generate").removeClass('clicked');
                    $("#map_help").click(function() { });
                    return false;
                    
                }
            }
            return false;
        }
        
        $lien_minitel = $('#url_exe').attr('href');
        $('#charge_minitel').attr('src',$lien_minitel);
         $('#page_install').show(500);
        return false;
    });
    
     $('.lance_exe_ol').click(function(){
        $lien_ol = $('#url_exe').attr('href');
        $('#charge_minitel').attr('src',$lien_ol);
         $('#page_install').show(500);
        return false;
    });
    
    $('#btn_abo_cooke').click(function(){
        $('#btn_abo_cooke').hide();
        $('#texteformule').hide();
        $('#frame_wha').show();
        $('#frame_wha').attr('src','http://www.info-societe.com/bilanWha');
        $('#frame_wha').css('display','block');
        $("#phraseWHA").css('display', 'block');
        $("#phraseWHA a").css('display', 'inline');
        return false;
    });

    $("#linkCGU").click(function(e){
        openAboWhaCgu();
        e.preventDefault();
    });

    $("#gestionAbo").click(function(e){
        openAboWhaCgu();
        e.preventDefault();
    });

        $('#btn_abo_cooke_online').click(function(){
            $('#abo_form_online').submit();
            return false;
        });
    
    
    $('#btn_online').click(function(){
           $('#page_install').show(500);
    });
    
    if($("#nom").length)
    {
        $("#nom").focus();
    }

    $(".liste_resultat").click(function(e){
        document.location.href = $(this).find('.savoir_plus a').attr('href');
    });
    
});

function openFlexTelPopup(){
    src = "http://www.aiwg.fr/flextel-web/?service=0836290007" ;
    var newWindow = window.open(src,'FlexTel', 'width=1070,height=662,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no');
    //showModalDialog(src, "", "dialogWidth=660; dialogHeight=662; center=yes; resizable=false;");
    if(newWindow){
         return true;
    }
}
function openFlextelModal(){
    Cookies.set("__societeFlextelCook", "1", 365);
//     FLEXWEB
//     FlexwebMgr.launchFlexweb('http://www.aiwg.fr/flexweb-infosociete/',850);
//     FlexwebMgr.launchFlexwebFullScreen('http://www.aiwg.fr/flexweb-infosociete/');
    
    src = "http://www.aiwg.fr/flextel-web/?service=0836290007";
    $.modal('<iframe id="simpleIframe" src="' + src + '" height="680" width="1070" style="border:0px; margin: 0px; padding :0px;" frameborder="0">', {
        containerCss:{
            height:"690px",
            width:"1070px",
            backgroundColor:"#d0d0d0"
        },
        overlayClose :false,
        onShow: function() {
            window.setTimeout("leTimeout()",1000);                
        },
        onClose: function(){
            this.close();
            openWha();
        }
    });

    return true;
}

function leTimeout() {
    $("#simpleIframe").tabIndex=0;
    $("#simpleIframe").focus();
}

function checkFlextelCompat(){
    return (swfobject.hasFlashPlayerVersion("9.0.124"));
}


function isFlextelOK(){
    if(checkFlextelCompat()) return openFlextelModal();
    return false;
}

function showHelp() {
    if(checkFlextelCompat() && !Cookies.get('syn')){
        window.open('http://www.info-societe.com/help/cgu.html','Info', 'status=no, scrollbars=yes, toolbar=yes, menubar=no, width=666px, height=329px, top=250px, left='+(screen.width/2-287)+'px');
    }
    else {
        window.open('http://www.info-societe.com/page/pinfo.php?d','Info', 'status=no, scrollbars=yes, toolbar=yes, menubar=no, width=666px, height=329px, top=250px, left='+(screen.width/2-287)+'px');
    }
    return false;
}

function openAboWhaCgu() {
    window.open('http://www.aiwg.fr/wha/cgu.html ','_blank', 'width=975,height='+screen.height+',top=0,left='+((screen.width-975)/2)+',scrollbars=1,location=0,status=0,resizable=0');
}

var openWha = function() {
    $.modal('<iframe id="whaiframe" src="iframe-wha.php" style="border: 0; width: 600px; height: 550px; overflow: hidden;"></iframe>', {
        containerCss: {
            width: "600px",
            height: "560px"
        },
        autoResize: true,
        autoPosition: true,
        overlayClose: true
    });
}
