
/*

	fonctions diverses

*/


function cOn01(td){
	if(document.getElementById||(document.all && !(document.getElementById))){
		td.style.backgroundColor="#C00000";
	}
}
function cOn02(td){
	if(document.getElementById||(document.all && !(document.getElementById))){
		td.style.backgroundColor="#C00000";
	}
}
	function cOn03(td){
	if(document.getElementById||(document.all && !(document.getElementById))){
		td.style.backgroundColor="#C00000";
	}
}
function cOn04(td){
	if(document.getElementById||(document.all && !(document.getElementById))){
		td.style.backgroundColor="#C00000";
	}
}
function cOut01(td){
	if(document.getElementById||(document.all && !(document.getElementById))){
		td.style.backgroundColor="#000000";
	}
}
function cOut02(td){
	if(document.getElementById||(document.all && !(document.getElementById))){
		td.style.backgroundColor="#3C3C3C";
	}
}
function cOut03(td){
	if(document.getElementById||(document.all && !(document.getElementById))){
		td.style.backgroundColor="#6E6E6E";
	}
}
function cOut04(td){
	if(document.getElementById||(document.all && !(document.getElementById))){
		td.style.backgroundColor="#FFFFFF";
	}	
}


function datation () {
           var time=new Date();
           var date=time.getDate();
           var year=time.getYear();
		   if ( year < 1900 ) {
				year += 1900;
		   }
		   document.write("&nbsp;" + year + "-" + time.getMonth() + 1  + "-" + date);
}


function rediriger () {



}

var vu = new Object();

function voirsous (what) {
	if (vu[what] == 1) {
		document.getElementById('table' + what).style.display="none";
		vu[what] = 0;
	} else {
		document.getElementById('table' + what).style.display="block";
		vu[what] = 1;
	}

}

function afficheDate () {
           var months=new Array(13);
           months[1]="janvier";
           months[2]="février";
           months[3]="mars";
           months[4]="avril";
           months[5]="mai";
           months[6]="juin";
           months[7]="juillet";
           months[8]="août";
           months[9]="septembre";
           months[10]="octobre";
           months[11]="novembre";
           months[12]="décembre";
           var time=new Date();
           var lmonth=months[time.getMonth() + 1];
           var date=time.getDate();
           var year=time.getYear();
           if ( year < 1900) {
                year += 1900;
           }
           document.write("&nbsp;" + date + "&nbsp;" + lmonth + "&nbsp;" + year);
}

function gotopage (obj) {
      document.location.href=obj.value;
}

function buildSelect (datas) {
        var ls = '<form>';
        ls += '<select onchange="gotopage(this);">';        
        ls += '<option value="#">Choisir une catégorie</value>';
        for ( var rub in datas) {
            ls += '<option value="'+datas[rub]+'">'+rub+'</value>';
        }
        ls += "</select></form>";
        return ls;
}
var rubriqueliste = {
    'Bonnes affaires': '/bonnesaffaires/' ,
    'Emploi'        : '/emploi/',
    'Immobilier'    : '/immobilier/',
    'Auto Moto'     : '/auto-moto/'
};
    
        
function buildRubList ( blocs ) {
    for ( var i = 0; i < blocs.length; i++) {
        buildListe(blocs[i]);
    }
}

var listes = {};

function buildListe ( nomliste ) {
    if (  $(nomliste) ) {
        var liste = $(nomliste);
        var aliste = liste.getElementsByTagName('a');
        listes[nomliste] = liste;
        var ls = '<form><select onchange="gotopage(this);"> ';
        ls += '<option value="#">Aller &agrave;...</value>';
        for ( var i = 0; i < aliste.length; i++) {
            var texte = aliste[i].innerHTML;
            if ( aliste[i].innerHTML.length > 20 ) {
                texte = aliste[i].innerHTML.substr(0,20) + "...";
            }
            //ls += '<option value="'+aliste[i].href+'">'+ aliste[i].innerHTML +'</value>';
            ls += '<option value="'+aliste[i].href+'">'+ texte +'</value>';
        }
        ls +=  "</select></form>";
        $(nomliste).innerHTML = ls;
    }
}

$pas={
    display: function (todisplay) {
        for ( var i =0; i < todisplay.length ; i++) {
            if ($( todisplay[i])) {
                if ( $( todisplay[i]).style.display=='block' ) {
                    $( todisplay[i]).style.display='none';
                } else {
                    $( todisplay[i]).style.display='block';
                }
            }
        }
        return false;
    },
    plus:function () {
        return false;
    },
    popup:function () {
        return false;
    }
}

$pas.menus = {
    listes:{},
    buildRubList: function ( blocname, sousbloc ) {
        var bloc = $(blocname);
        var liste = bloc.getElementsByTagName('div');
        for ( var i = 0; i < liste.length; i++) {
            if (liste[i].className == sousbloc) {
                $pas.menus.buildListe(liste[i]);
            }
        }
    },
    buildListe: function ( blocliste ) {
        if (  blocliste ) {
           var h4liste = blocliste.getElementsByTagName('h4');
           var h4name = 'Aller &agrave;...';
           if (h4liste) {
                h4name = h4liste[0].innerHTML;
           }
            var aliste = blocliste.getElementsByTagName('a');
            //$pas.menus.listes[nomliste] = blocliste;
            var ls = '<form><select onchange="gotopage(this);"> ';
            ls += '<option value="#">'+h4name+'</value>';
            for ( var i = 0; i < aliste.length; i++) {
                var texte = aliste[i].innerHTML;
                if ( aliste[i].innerHTML.length > 20 ) {
                    texte = aliste[i].innerHTML.substr(0,20) + "...";
                }
                ls += '<option value="'+aliste[i].href+'">'+ texte +'</value>';
            }
            ls +=  "</select></form>";
            $(blocliste).innerHTML = ls;
        }
    },
    labelList: function (blocname) {
        var bloc = $(blocname);
        var aliste = bloc.getElementsByTagName('a');
        var ls = '<form><select onchange="gotopage(this);"> ';
        for ( var i = 0; i < aliste.length; i++) {
            var texte = aliste[i].innerHTML;
            if ( aliste[i].innerHTML.length > 20 ) {
                 texte = aliste[i].innerHTML.substr(0,20) + "...";
            }
            ls += '<option value="'+aliste[i].href+'">'+ texte  +'</value>';
        }
        ls +=  "</select></form>";
        $(blocname).innerHTML = ls;  
    }
}

$pas.tools={
    getAnchor: function () {
        var re = new RegExp("\#(.*)","im");
        $pas.tools.ancre = window.location.href.match(re);
        if ($pas.tools.ancre) {
            $pas.tools.ancres = $pas.tools.ancre[1].split('/');
        }
    }, 
    /**
            Function: $pas.tools.findAnchor
    **/
    findAnchor: function (anchor) {
        if (!$pas.tools.ancre) {
            $pas.tools.getAnchor();
        }
        if (!$pas.tools.ancres) {
            return '';
        }
        for (var i=0; i< $pas.tools.ancres.length;i++) {
            var re = new RegExp(anchor+"\d*","im");
            if (anchor == i || anchor.match(re)) {
                return $pas.tools.ancres[i];
            }
        }
        return '';
    },
    params:{},
    getParams: function () {
        if ( window.location.search ) {
            var pinfo = window.location.search.replace(/\?/,'');
            var res = pinfo.split(/&/);
            for (var i = 0;i < res.length ;i++ ) {
                var param = res[i].split(/=/);
                $pas.tools.params[ param[0] ] = param[1];
            }
        }
    },
    displayVillesbyRegJS: function (pays,cr1,cr) {
        //http://yvelines.lannonce.com/js/json/fr/frj/villes_78.js
        document.write('<script src="\/js\/json\/'+pays+'\/'+cr1+'\/villes_'+cr+'.js"><\/script>');
    },
    /*
     *  $pas.tools.displayRubriques
     *
     */
    displayRubriques: function () {
        
        
    },
    mouf: function () {
        var n= ['w','e','b','m','e','s','t','r','e'];
        var d  = [
        'o','n','l','y','2','0','0','6','.','l','a','n','n','o','n','c','e','.','c','o','m','?','s','u','b','j','e','c','t','=','[','P','A',']'
        ];
        return('<a class="lien02" href="mailto:'+ n.join('') + "&#64;" + d.join('')  +'">' + "me contacter" + '</a>');    
    }
}

/**
    classe $pas.annonces

    Affichage des annonces

    #g0/l0
    g : donne le bloc à afficher s'il existe
    l : donne le nombre d'annonces par bloc, 10 par défaut

**/
$pas.annonces={
    blocs:{},
    tabid:'youhou',
    liste: new Object(),
    limit:10,
    bloc:0,
    initDisplay: function (tabid) {
        if (tabid) {
            $pas.annonces.tabid = tabid;
        }
        $pas.annonces.liste = $($pas.annonces.tabid);
        $pas.annonces.countPAS();
        $pas.annonces.getLimit();
        $pas.annonces.numeroteLines();
        $pas.annonces.afficheBloc(1);
        var menu = $pas.annonces.buildMenu(1);
        document.write(menu);
    },
    afficheBloc: function (bloc,pub) {
        var liste = $pas.annonces.liste.getElementsByTagName('tr');
        var nbtd = 0;

        for (var i = 1;i < liste.length;i++) {
            var id = liste[i].id;
            if (nbtd == 0) {
                nbtd = liste[i].getElementsByTagName('td').length;
            }
            if ( $pas.annonces.blocs[bloc] &&  $pas.annonces.blocs[bloc][id]) {
               liste[i].style.display='';
            } else {
                if (bloc == 0) {
                    liste[i].style.display='';
                } else {
                    liste[i].style.display='none';
                }
            }
        }
        if (pub && pub == 1 && bloc != 0) {
           var script= document.createElement('script');
           script.type= 'text/javascript';
           script.src= 'js/titre.js';
           //document.getElementById('ajstitre').appendChild(script);
        }
        return true;
    },
    buildMenu: function () {
        var ls = '<div class="painside">';
        ls += 'Autres annonces dans cette page: ';
        
        for (var bloc in $pas.annonces.blocs) {
            ls += '<a href="#g'+bloc+'/l'+$pas.annonces.limit+'" onclick="$pas.annonces.afficheBloc('+bloc+',1);">'+bloc+'</a> | ';
        }
        ls += ' <a href="#g0'+'/l'+$pas.annonces.limit+'" onclick="$pas.annonces.afficheBloc(0,1);">Toutes les annonces</a></div>';
        return ls;
    },
    numeroteLines: function () {
        var liste = $pas.annonces.liste.getElementsByTagName('tr');
        var ap=1;
        var j = 1;
        for (var i = 1;i < liste.length;i++) {
            var id = "pas"+ap;
            liste[i].id=id;
            if ($pas.annonces.blocs[j]) {
                $pas.annonces.blocs[j][id]={'id':id};
            } else {
                $pas.annonces.blocs[j] = {};
                $pas.annonces.blocs[j][id]={'id':id};
            }
            //remove blocs
            if ((ap % $pas.annonces.limit) == 0) {
                j += 1;
            }            
            ap++;
        }
    },
    hasEnoughPAS: function () {
        if ($pas.annonces.nbPAS > 10) {
            $pas.annonces.splitable = true;
        }
    },
    countPAS: function () {
        var count = 0;
        var liste = $pas.annonces.liste.getElementsByTagName('tr');
        $pas.annonces.nbPAS = liste.length;
    },
    changeLimit: function () {
        $pas.annonces.getLimit();
    },
    getLimit: function () {
        var ancre = $pas.tools.findAnchor('g');
        var re = new RegExp("l(.*)","im");
        var res = ancre.match(re);
        if (res && res[1]) {
            $pas.annonces.limit=res[1];
        }
    }
}

/*
 *  class: dans les annonces
*/
$pas.annonce = {
    init: function () {
        
    }
}

$pas.depot = {
    affiche: function (to,from) {
        if ( $(to) &&  $(to).innerHTML == '' ) {
            $(to).innerHTML = $(from).innerHTML;
            $(to).style.margin="0 10% 0 10%";
            $(to).style.padding="5px";
            $(to).style.border="1px solid #C0C0C0";
            $(from).style.background="#FFD363";

        } else {
            if ($(to)) {
                $(to).innerHTML = '';
                $(to).style.margin="0 0 0 0";
                $(to).style.padding="0";
                $(to).style.border="0";
                $(from).style.background="";
            }
        }
    }
}


