// ROOT PATH
rootpath="/";

// ONLOAD
Event.observe(window, 'load', function() {
	// SET HOUR IN FORM ON CHANGE
	Event.observe($('heure-debut'), 'change', function() {
		for(i=7;i<=$('heure-debut').value;i++){$('heure-fin-'+i).hide();$('heure-fin-'+i+'-2').hide();}
		for(i=(parseInt($('heure-debut').value))+1;i<=22;i++){$('heure-fin-'+i).show();$('heure-fin-'+i+'-2').show();}
	});
	// SET LOGO LINK
	Event.observe($('logo'), 'click', function() {
		document.location.assign(rootpath);
	});
	// SET ADVERTISING
	for(i=1;i<=6;i++){ajax_loadContent('advertising0'+i,rootpath+'include/ajax/banner.php?p='+i);}
	// SET NEW
	//ajax_loadContent('nouveautes',rootpath+'include/ajax/new.php?');
	//SET HOUR IN FORM O NLOAD
	for(i=7;i<=$('heure-debut').value;i++){$('heure-fin-'+i).hide();}
	for(i=(parseInt($('heure-debut').value))+1;i<=22;i++){$('heure-fin-'+i).show();}
	//INIT SHADOWBOX
	Shadowbox.init({
		continuous: true,
		displayCounter: false,
		handleUnsupported: "remove",
		overlayOpacity: 0.9
	});
});

//COPYCONTACT
function copyContact(){
	$('prenom').value=$('ori_prenom').value;
	$('nom').value=$('ori_nom').value;
	$('adresse1').value=$('ori_adresse1').value+" "+$('ori_adresse2').value;
	$('cp').value=$('ori_cp').value;
	$('ville').value=$('ori_ville').value;
	$('email').value=$('ori_email').value;
	$('web').value=$('ori_web').value;
	$('tel').value=$('ori_tel').value;
	$('fax').value=$('ori_fax').value;
	$('gsm').value=$('ori_gsm').value;
}

//AJAX CALL WITH PROTOTYPE
function ajax_loadContent(where, url){
	new Ajax.Request(url,
		{
			method:'get',
			onSuccess: function(req){
				document.getElementById(where).innerHTML = req.responseText;
			},
			onFailure: function(){
				document.getElementById(where).innerHTML = "<p style='text-align:center;'>Error while loading ajax response</p>";
			}
		}
	);
}
function ajax_addContent(where, url){
	new Ajax.Request(url,
		{
			method:'get',
			onSuccess: function(req){
				document.getElementById(where).innerHTML = req.responseText
			}
		}
	);
}

// FORM VALIDATION
function validateForm(formname) { 
	var valid=new Validation(formname,{onSubmit:false,useTitles:true});
	return valid.validate();
}
