﻿var name = "Notaires Jean-Luc LESUR & Emmanuel PLUQUET"

function setBigImg(big_img_class, small_img_class, duration) {
    $(small_img_class).mouseenter(function () {
        var selected = $(this).parent('a');
        if ($(big_img_class).attr('src') != selected.attr('href')) {
            $(big_img_class).stop().fadeOut(duration, function () {
                $(big_img_class).attr('src', selected.attr('href'));
                $(big_img_class).attr('title', selected.parent('a').attr('title'));
                $(big_img_class).attr('alt', selected.attr('alt'));
                $(big_img_class).parent('a').attr('href', selected.attr('src'));
                $(big_img_class).parent('a').attr('title', selected.parent('a').attr('title'));
                $(this).fadeTo(duration, 1, function () {
                    GLO_active = false;
                });
            });
        }
    });
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function keyPressedEnter(id, url_redirect) {
    $(id).keypress(function (e) {
        if (e.keyCode == '13') {
            location.href = url_redirect + $(id).val();
            return false;
        }
    });
}

function keyPressedEnterLogin(id, btnId) {
    $(id).keypress(function (e) {
        if (e.keyCode == '13') {
            $(btnId).click();
            return false;
        }
    });
}

function getPage() {
    var url = window.location.toString();
    //alert(typeof(url));
    var urlparts = url.split('/');
    var url_get = urlparts[urlparts.length - 1].split('?')
    return url_get[0];
}

function favoris() {
    if (navigator.appName != 'Microsoft Internet Explorer') {
        window.sidebar.addPanel(name, "http://www.marchiennes-notaires.fr", "");
    } else {
        window.external.AddFavorite("http://www.marchiennes-notaires.fr", name); 
    }
}

function imprime_zone(commande, obj, name) {
    var zi = " <style type=\"text/css\">a, img{border:none;} ";
    zi = zi + "#tabPanier{border: #801418 solid 1px;border-collapse: collapse;width: 560px;background-color:White;color:Black;}";
    zi = zi + "#tabPanier tr{";
    zi = zi + "border-collapse: collapse;";
    zi = zi + "text-align: center;";
    zi = zi + "border-right: none;";
    zi = zi + "border-left: none;";
    zi = zi + "}";
    zi = zi + "#tabPanier th";
    zi = zi + "{";
    zi = zi + "border: solid 1px #801418;";
    zi = zi + "border-collapse: collapse;";
    zi = zi + "border-top: none;";
    zi = zi + "}";
    zi = zi + "#tabPanier td";
    zi = zi + "{";
    zi = zi + "border: solid 1px #801418;";
    zi = zi + "border-collapse: collapse;";
    zi = zi + "border-bottom: none;";
    zi = zi + "}";
    zi = zi + "#tabPanier .cellCoteDroit";
    zi = zi + "{";
    zi = zi + "border: solid 1px #801418;";
    zi = zi + "border-collapse: collapse;";
    zi = zi + "border-bottom: none;";
    zi = zi + "border-right: none;";
    zi = zi + "}";
    zi = zi + "#tabPanier .cellCoteGoche";
    zi = zi + "{";
    zi = zi + "border: solid 1px #801418;";
    zi = zi + "border-collapse: collapse;";
    zi = zi + "border-bottom: none;";
    zi = zi + "border-left: none;";
    zi = zi + "}";
    zi = zi + ".textetitre2";
    zi = zi + "{";
    zi = zi + "font-size: 14px;";
    zi = zi + "}";
    zi = zi + ".textedescriptif";
    zi = zi + "{";
    zi = zi + "font-size: 14px;";
    zi = zi + "}";
    zi = zi + "</style><center><img src=\"<%=getUrlImgVideGrande %>\" alt=\"Logo " + name + "\" /></center>"
    zi = zi + document.getElementById(obj).innerHTML;

    var f = window.open("", "ZoneImpr", " width=600,toolbar=0, menubar=0, scrollbars=1, resizable=1,status=0, location=0, left=10, top=10");
    f.document.body.style.color = '#000000';
    f.document.body.style.backgroundColor = '#FFFFFF';
    f.document.body.style.padding = "10px";
    f.document.title = commande;
    f.document.body.innerHTML += zi;
    f.window.print();
    f.window.close();
    return true;
}

var GLO_animation = '';
var GLO_first = true;
var GLO_timer = 0;

function animateBanner(imgClasses, timeout, duration) {
    clearTimeout(GLO_animation);
    GLO_animation = '';
    //GLO_timer++;
    var selectedClassLabel = 'selected_img';
    var selectedClass = '.' + selectedClassLabel;
    var debug = false;
    if (GLO_first) {
        GLO_first = false;
        timeout = (timeout == undefined) ? 2000 : timeout * 1000;
        duration = (duration == undefined) ? 500 : duration;
        imgClasses = '.' + imgClasses;
        $(imgClasses).hide();
        $(imgClasses + ':first').addClass(selectedClassLabel);
        $(selectedClass).show();
        GLO_animation = setTimeout(function () { animateBanner(imgClasses, timeout, duration) }, timeout);
    } else {
        var nextImgId;
        nextImgId = ($(selectedClass).attr('id') == $(imgClasses + ':last').attr('id')) ? '#' + $(imgClasses + ':first').attr('id') : '#' + $(selectedClass).next(imgClasses).attr('id');
        $(selectedClass).fadeOut(duration, function () {
            $(selectedClass).removeClass(selectedClassLabel);
            $(nextImgId).addClass(selectedClassLabel);
            if (debug)
                $('#display').append($(selectedClass).attr('id') + ' & timeout = ' + timeout + '<br/>');
            GLO_animation = setTimeout(function () { animateBanner(imgClasses, timeout, duration) }, timeout);
        });
        $(nextImgId).fadeIn(duration);
    }
}

function redirect() {

    var currentLocation = document.location.href;
    var oldLocation = 'http://www.marchiennes-notaires.fr/';
    var newLocation = 'http://www.lesur-pluquet-marchiennes.notaires.fr/';
    if (currentLocation.indexOf(oldLocation) > -1) {
        window.location = currentLocation.replace(oldLocation, newLocation)
    }
}

function selectionnerSecteur(zone) {
    var valeur;
    zone = zone.substring(0, 2);
    //alert(zone);
    if (zone == "S1") {
        valeur = "Nord 2";
    } else if (zone == "S2") {
        valeur = "Sud 3";
    } else if (zone == "S3") {
        valeur = "Sud 2";
    } else if (zone == "S4") {
        valeur = "Nord 1";
    } else if (zone == "S5") {
        valeur = "Montaigu";
    } else if (zone == "S6") {
        valeur = "Sud 1";
    } else {
        valeur = "Indifférent";
    }

    //$('#header').append(valeur);
    var select = document.forms["aspnetForm"].elements["ctl00_DDLSector"];
    for (var i = 0; i < select.options.length; i++) {
        //$('#header').html(select.options[i].value + " / " + valeur)
        if (select.options[i].value == valeur) {
            select.options[i].selected = true;
        }
    }
}

$(document).ready(function () {
    redirect();
    var page = getPage().toLowerCase();
    //alert(page);
    var index = 'default.aspx';
    var recherche = 'recherche-immobilier-montaigu.aspx';
    var fiche = 'fiche-bien-immobilier-montaigu.aspx';
    var desinscription = 'desinscription-alerte-email-agence-le-patrimoine-montaigu.aspx';
    var login = 'login.aspx';
    //$('.lienBasSite').html(page);
    if (page == index || page == '') {
        animateBanner('imgDiapo', 6, 1600);
        $('.fancybox').fancybox();
    } else if (page == fiche) {
        $('.fiche_details_images_gauche a').each(function () {
            MM_preloadImages($(this).attr('href'));
        });
        setBigImg('.big_image_detail', '.small_image_detail', 500);
        $("a.big_image_lien").fancybox()
        $("a.small_image_lien").fancybox()
        $('.fiche_details_lien_tel').fancybox();
        $('.fiche_details_lien_financement').fancybox();
        $('.fiche_details').fadeIn();
        $('.big-loader').fadeOut();
    } else if (page == recherche) {
        $('#search-content').fadeIn();
        $('.big-loader').fadeOut();
    } else if (page == desinscription) {
        keyPressedEnterLogin('#ctl00_MainContent_TBNom', '#ctl00_MainContent_BUTENVOI');
        keyPressedEnterLogin('#ctl00_MainContent_TBEmail', '#ctl00_MainContent_BUTENVOI');
    } else if (page == login) {
        keyPressedEnterLogin('#ctl00_MainContent_TBlogin', '#ctl00_MainContent_ButConnect');
        keyPressedEnterLogin('#ctl00_MainContent_TBmdp', '#ctl00_MainContent_ButConnect');
    }
    $('.fancybox').fancybox();
    $('.footer_mentions').fancybox();
    //$('.footer_mentions').fancybox();
    keyPressedEnterLogin('#ctl00_TBReference', '#ctl00_ButOk2');

})
