function CreateList(num) {
	for (i=1; i <= num; i++)
	{

		var actions = (i == 1) ? 'class="selected" id="first"' : '';

		var txt = '<a href="#" ' + actions + '></a>';

		$('idsteps').insert((new Element ("li").update(txt)));

	}
}

function prevStep(id, recs) {

	for(p=(recs-1); p >= 0; p--) {


		var li = $(id).childNodes[p];
		var sel = li.firstChild.className;

		if (sel == "selected")
		{
			li.firstChild.className = "";
			$(id).childNodes[p-1].firstChild.className = 'selected';


			if (sel == "selected" && (p-1) == (recs - (recs-(p-1)))) {

				var s = p;

				$('idarticle_title').innerHTML = "Regroupement de crédits " + s;
				$('idimg_text').innerHTML = "Text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s;
			}

			if (p == (recs - 1))
			{
				$('idright_arrow').style.display = "";
			}

			if (p == 1)
			{
				$('idleft_arrow').style.visibility = "hidden";
			}

			return;
		}
	}
}

function nextStep(id, recs) {
	for (n=0; n < recs-1; n++)
	{
		var li = $(id).childNodes[n];
		var sel = li.firstChild.className;

		if (n == 0)
		{
			$('idleft_arrow').style.visibility = "visible";
		}

		if (sel == "selected")
		{
			li.firstChild.className = "";
			$(id).childNodes[n+1].firstChild.className = "selected";

			if (sel == "selected") {
				var s = n+2;
				$('idarticle_title').innerHTML = "Regroupement de crédits " + s;
				$('idimg_text').innerHTML = "Text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s + " text " + s;
			}

			if (n == recs-2)
			{
				$('idright_arrow').style.display = "none";
			}
			else {
				break;
			}

		}



	}
}

function openForPrint(content){
	var options='scrollbars=yes,resizable=yes, width=700,height=540, left=0 ,top=0';
	imgWin=window.open('about:blank','',options);
	with (imgWin.document)
		{
			writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
			writeln('<html>\n<head>\n<title>Head title<\/title>');
			writeln('<\/head>\n<body onload="self.focus(); print();" >');

			writeln('<table  cellspacing="0" cellpadding="0" align="left" border="0" style="font-size:11px; font-family: tahoma, sans-serif; margin-top:10px;"><tr><td class="bord">');
			writeln('\t'+ content +'\n<\/td><\/tr><tr><td class="bord">');


			writeln('<p style="margin-top: 20px;">');
			writeln('<\/td><\/tr><\/table><br /><\/body>\n<\/html>');
			close();
		}//end with
}//end func


function showOrHide(id){
	var word = (!$(id).hasClassName("scroll")) ? 'addClassName' : 'removeClassName';
	$(id)[word]('scroll');
	$(id).scrollTop = 0;
	var msg = (word != 'addClassName') ? "Lire la suite" : "Fermer";
	$('idlire').update(msg);
	$$('a.mention')[0][word]('down_arrow');
}

function showOrHideNewsletter(id){
	var word = (!$(id).hasClassName("scroll")) ? 'addClassName' : 'removeClassName';
	$(id)[word]('scroll');
	$(id).scrollTop = 0;
	var msg = (word != 'addClassName') ? "Lire la suite" : "Fermer";
	$('idlire2').update(msg);
	$$('a.mention2')[0][word]('down_arrow');
}

function _getScroll(){
	if(typeof(window.pageYOffset) == 'number') {
		x = window.pageXOffset;
		y = window.pageYOffset;
	} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	} else if(document.documentElement) {
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	return Array(x,y);
}

function close_popup(link){

	var popup = getMainDivPopup(link);

	if (popup != null)
		popup.style.display = 'none';


	$('fog').setStyle({display: 'none'});
}

/* parcour le dom en remontant vers body et retourne un élément DIV ayant la classe "popup" ou null */
function getMainDivPopup(node)
{
	var popupClassReg = /(^(popup ))|( popup )|(( popup)$)|(^(popup)$)/
    if (node.nodeName.toUpperCase() == "BODY") {
        return null;
    }
    else if (node.nodeName.toUpperCase() == "DIV" && popupClassReg.test(node.className)) {
		return node;
    }
    else {
        return getMainDivPopup(node.parentNode);
    }
}


Event.observe(window, 'load', function(){

	/*  */
	$$('form').each(function(elem){
		elem.getInputs('text').each(function(elem){
			elem.observe('click', function(){
				elem.select();
			});
		});
        elem.getInputs('password').each(function(elem){
            elem.observe('click', function(){
                    elem.select();
            });
    });

	});

	/* POPUP */
	$$('.popup_invoke').each(function(elem){
		elem.observe('click', function(){
			var to_show = 'popup_' + elem.rel;

			$$('.popup').each(function(el){
				if(el.hasClassName(to_show)){
					var xy = _getScroll();
					var dimensions = el.getDimensions();

					//console.log();
					var _top = xy[1] + 300 - dimensions.height/2 + 'px';
					el.setStyle({'display': 'block', 'top': _top});
					$('fog').setStyle({display: 'block'});
				}
			});
		});
	});


	/* recrute_engagements_1.htm */
	var active_tab = 1;
	if($('tab_1')){
		$('tab_1').observe('click', function(){
			if(active_tab != 1){
				$('page_1').toggle();
				$('page_2').toggle();
				$('tab_1').setStyle({backgroundPosition: '0px 0px'});
				$('tab_2').setStyle({backgroundPosition: '0px 50px'});
				active_tab = 1;
			}
		});
		$('tab_2').observe('click', function(){
			if(active_tab != 2){
				$('page_1').toggle();
				$('page_2').toggle();
				$('tab_2').setStyle({backgroundPosition: '0px 0px'});
				$('tab_1').setStyle({backgroundPosition: '0px 50px'});
				active_tab = 2;
			}
		});

		$('tab_1').setStyle({cursor: 'pointer'});
		$('tab_2').setStyle({cursor: 'pointer'});
	}



	/* services_bancaires_votre compte.htm */
	var animation = 'on'; // set to [on]  to enable animation
	$$('div.solution a.learn_more').each(function(el){
		if (el.href.lastIndexOf("#") == (el.href.length - 1) || el.href == "javascript:;") {
			el.observe('click', function(ev){

				$$('.block .more').each(function(e){
					//alert(e.style.display);
					if(e.visible()){
						if(animation == 'on'){
							Effect.SlideUp(e);
							Effect.Fade(e, { from: 1, to: 0  });
						}else{
							e.setStyle({display: 'none'});
						}

					}
				});
				$$('.original').each(function(e){
					if(e.style.display == 'none'){
						if(animation == 'on'){
							Effect.SlideDown(e);
							Effect.Fade(e, { from: 0, to: 1 });
						}else{
							e.setStyle({display: 'block'});
						}

					}
				});

				var parent = el.parentNode.parentNode;
				parent = $(parent);
				var divs = parent.select('div.more');
				var more_holder = divs.first();

				if(more_holder){
					if(animation == 'on'){
						Effect.SlideDown(more_holder);
						Effect.Fade(more_holder, { from: 0, to: 1 });
						Effect.SlideUp($(el.parentNode));
						Effect.Fade($(el.parentNode), {from: 1, to: 0  });
					} else {
						more_holder.setStyle({display: 'block'});
						$(el.parentNode).setStyle({display: 'none'});
					}
				}

				// stop the click event
				ev.stop();
			});
		}
	});
});

var defaultDay = "jour";
var defaultMonth = "mois";
var defaultYear = "année";

var dayFormat = "jj";
var monthFormat = "mm";
var yearFormat = "aaaa";

function addOnFocusEvent(elementId, defaultValue) {
	if (document.getElementById(elementId) != null) {
		if (document.getElementById(elementId).value == defaultValue) {
			document.getElementById(elementId).value = "";
		}
	}
}

function addOnBlurEvent(elementId, defaultValue) {
	if (document.getElementById(elementId) != null) {
		if (document.getElementById(elementId).value == "") {
			document.getElementById(elementId).value = defaultValue;
		}
	}
}
