﻿
var AD_LastNoduSelect = null;
var cloneObj = null;

function LoadDocument() {
    AD_LoadPub();
}

function AD_LoadPub() {
    if (document.getElementById("plb")) document.getElementById("plb").innerHTML = "<IFRAME BORDER=\"0\" frameborder=\"0\" ID=\"iDetail\" SCROLLING=\"NO\" SRC=\"/Pages/pub/pubnet-LB.htm\" WIDTH=\"728\" HEIGHT=\"90\" allowtransparency=\"true\"></></IFRAME>";
    if (document.getElementById("pbb")) document.getElementById("pbb").innerHTML = "<IFRAME BORDER=\"0\" frameborder=\"0\" ID=\"iDetail\" SCROLLING=\"NO\" SRC=\"/Pages/pub/pubnet-BB.htm\" WIDTH=\"300\" HEIGHT=\"275\" allowtransparency=\"true\"></IFRAME>";
    if (document.getElementById("psk")) document.getElementById("psk").innerHTML = "<IFRAME BORDER=\"0\" frameborder=\"0\" ID=\"iDetail\" SCROLLING=\"NO\" SRC=\"/Pages/pub/pubnet-SK.htm\" WIDTH=\"160\" HEIGHT=\"600\" allowtransparency=\"true\"></IFRAME>";
}

function AD_LoadPubT() {
    setTimeout('AD_LoadPub();', 700);
}

function AD_getBase() {
    $('.ListingLeft a,.ListingRight a').bind("click", function(e) {
        AD_Select(this);
        return false;
    });
}
var ggDiv = null;
function AD_Select(e) {
    if (e == AD_LastNoduSelect) return;
    $(e).parent().toggleClass('on');
    $(AD_LastNoduSelect).parent().toggleClass('on');
    AD_LastNoduSelect = $(e);

    //Buy online
    if ($get('TopInfo').className == "TopInfo" || $get('TopInfo').className == "TopInfoD") {

        if ($('#ggPubSrc iframe').length == 1) {
            cloneObj = $('#ggPubSrc iframe');
        }
        
        $('#ggPubSrc').show();
        $('#TopInfo').html($('#' + e.id.replace('nd', 'ident')).html());
        if (document.getElementById('ggPubDest') == null) {
            ggDiv = document.createElement('div');
            ggDiv.id = 'ggPubDest';
            ggDiv.style.position = 'relative';
            ggDiv.style.left = '110px';
            document.body.appendChild(ggDiv);
            $('#ggPubDest').appendTo('#TopInfo');
            AD_AjustInfo('#ggPubDest');
        }

        if ($get(e.id.replace('nd', 'img')).width > 0)
            AD_AjustIMG(e.id.replace('nd', 'img'));
        else
            setTimeout('AD_AjustIMG("' + e.id.replace('nd', 'img') + '")', 1000);

    }

    //PJ
    if ($get('TopInfo').className == "TopInfoMaps") {
        var re = new RegExp("ImgUrl:([^\\|]*)\\|Name:([^\\|]*)\\|Lat:([^\\|]*)\\|Long:([^\\|]*)\\|URL:([^\\|]*)\\|");
        var m = re.exec($get(e.id.replace('nd', 'ident')).innerHTML);

        if ($("#ggPubSrc iframe").length == 1)
            cloneObj = $("#ggPubSrc iframe");

        var map = new GMap2(document.getElementById('map'), { mapTypes: [G_PHYSICAL_MAP, G_NORMAL_MAP] });
        map.addControl(new GMapTypeControl());
        map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(m[3], m[4]), 7);

        map.openInfoWindowHtml(map.getCenter(), '<div class="InfoWindowC"><div style="height:13px; overflow:hidden;border"><a style="font-size:11px;color: rgb(42,90,138);padding: 0px;margin: 0px;" href="' + m[5] + '">' + m[2] + '</a></div><div class="clear-Info"></div><a href="' + m[5] + '"><img border="0" src="' + m[1] + '" width=72 height=52"></a><div style="position:absolute;left:80px;" id="ggPubDest"></div></div>');

        AD_AjustInfo('#ggPubDest');
    }

    return false;
}

function AD_AjustInfo(x) {
    if ($("#ggPubSrc iframe").length == 1) {
        if ($(x).length == 0)
            setTimeout('AD_AjustInfo("'+x+'");', 1000);
        else 
        {
            $("#ggPubSrc iframe").appendTo(x);
            $(x).html($(x).html());
        }
    }
    else
        $(cloneObj).appendTo(x);
}

function AD_SelectFirst() {
    if ($('.ListingLeft a').length > 0)
        AD_Select($('.ListingLeft a')[0]);
}

function AD_AjustIMG(img) {
    if (img && $get(img)) {
        if ($get(img).width > 102 || $get(img).width == 0) $get(img).width = 102;
        if ($get(img).height > 78 || $get(img).height == 0) $get(img).height = 78;
    }

    setTimeout('AD_AjustIMG("' + img + '")', 1000);
}

function ThickBoxShow(x) {
    PACS.WebServices.ADTools.GetFullUrl(x, CallUrl_EventAsync);
}

function CallUrl_EventAsync(arg, cont, e) {
    if (arg) {
        tb_show('Site similaire', arg + "?TB_iframe=true&height=500&width=810", 'false');
    }
}

/*AUTO COMPLETE HOME PAGE*/
var Tourist_ClientItemSelected = function(sender, e) {
    PACS.WebServices.ADTools.GetTouristURL(e.get_value(), All_EventAsync);
}

function SearchTourist(e) {
    if (e.value != "")
        PACS.WebServices.ADTools.GetTouristURL(e.value, All_EventAsync);
}

var Cars_ClientItemSelected = function(sender, e) {
    PACS.WebServices.ADTools.GetCarsURL(e.get_value(), All_EventAsync);
}

function SearchCars(e) {
    if (e.value != "")
        PACS.WebServices.ADTools.GetCarsURL(e.value, All_EventAsync);
}

function All_EventAsync(arg, cont, e) {
    if (arg) {
        if (arg == 'null') {
            alert('Aucun résultat');
            return;
        }
        document.location = arg;
    }
}


$(document).ready(function() {

    $('.SimSites li').click(function(e) {
        var sr = $(this).children('h6').html();
        var re = new RegExp("<(.|\\n)+?>", "g");
        sr = sr.replace(re, '');
        $('.searchform :text').val(noaccent(sr));
        document.forms[0].submit();
    });

    $('.mrss').click(function(e) {
        $('.searchform :text').val(noaccent(this.title));
        document.forms[0].submit();
    });

});


function switchContent(source, dest) {
    $('#' + dest).html($('#' + source).html());
}

function searchGG(sr) {
    $('.searchform :text').val(noaccent(sr));
    document.forms[0].submit();
}

function noaccent(chaine) {
    temp = chaine.replace(/[àâä]/gi, "a")
    temp = temp.replace(/[éèêë]/gi, "e")
    temp = temp.replace(/[îï]/gi, "i")
    temp = temp.replace(/[ôö]/gi, "o")
    temp = temp.replace(/[ùûü]/gi, "u")
    return temp
}

function WebClick(ad){
	$('.searchform :text').val(noaccent(ad));
    document.forms[0].submit();
}