String.prototype.stripSpaces = function( ){ return this.replace( /\s/g, "" ); };

function SendCode(ref)
{
	var IcodeValeur=$('Icode').value.stripSpaces().toUpperCase();
	$('Icode').value=IcodeValeur;
	if( IcodeValeur.length==0){ IcodeValeur="§" }
	new AjaxEOL('/Ajax',{postBody:'_action_=ajax&ref='+ref+'&valeur='+IcodeValeur}).request();
}

function submitOnEnter(evt){
 evt = (evt) ? evt : event;
 var target = (evt.target) ? evt.target : evt.srcElement;
 var form = target.form;
 var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
 if (charCode == 13 || charCode == 3) {form.submit();}
 return true;
}

function submitViaEnter(evt){
 evt = (evt) ? evt : event;
 var target = (evt.target) ? evt.target : evt.srcElement;
 var form = target.form;
 var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
 if (charCode == 13 || charCode == 3) {
 	SendCode('listing');
 	return false;
 } 
 return true;
}


var Inputs = function()
{
	if( $chk( $('Datas') ) )
	{
	var list = $$('input.ILangue');
	list.each(
		function(element)
		{
			var SpanEl=element.getParent().getPrevious().getFirst();
			
			var fxOn = new Fx.Styles(SpanEl, {duration:300, wait:false});
			var fxOff = new Fx.Styles(SpanEl, {duration:300, wait:false});
			element.addEvent('focus', function(){fxOn.start({'color':'#19c709' }); });
			element.addEvent('blur', function(){fxOff.start({'color': '#aff11d'}); });
		}
	);
	}
}

var Boutons = function()
{
	if( $chk( $('Boutons') ) )
	{
	var list = $$('#Boutons div');
	list.each(
	function(element)
	{
		var fxOn = new Fx.Styles(element, {duration:100, wait:false});
		var fxOff = new Fx.Styles(element, {duration:400, wait:false});

		element.addEvent('mouseenter', function(){fxOn.start({'background-color': '#99B901','color':'#fff' }); });
		element.addEvent('mouseleave', function(){fxOff.start({'background-color': '#99B901','color': '#cbcbcb'}); });
 
	});
	}
}

var Panels=function()
{
	if( $chk( $('BarreNav') ) )
	{
		var Decale=10;
		var Hauteur='80px';
		var Opacity='0.90';

		var BarreNav = $('BarreNav');
		
		// Index
		var PanelIndex = $('PanelIndex');
		var ItemIndex = $('ItemIndex');
		
		ItemIndex.addEvent('click', function(){ VersPage('site.index'); });
		PanelIndex.setStyles({'top':0,'left':0,'height':0, 'display':'none'});
		
		//var fxOnIndex=new Fx.Styles(PanelIndex, {duration:20, wait:false, transition:Fx.Transitions.Elastic.easeOut});
		//var fxOffIndex=new Fx.Styles(PanelIndex, {duration:20, wait:false});
		
		var slidePanelIndex=new Fx.Slide(PanelIndex,{duration: 100,transition: Fx.Transitions.Bounce.easeOut});
		//slidePanelIndex.hide();
		slidePanelIndex.show();
		ItemIndex.addEvent('mouseenter', function(e){e.stop();slidePanelIndex.slideIn();});
		ItemIndex.addEvent('mouseleave', function(e){e.stop();slidePanelIndex.slideOut();});

		/*
		var fxOnIndex=new Fx.Tween(PanelIndex, {duration:20, wait:false, transition:Fx.Transitions.Elastic.easeOut});
		var fxOffIndex=new Fx.Tween(PanelIndex, {duration:20, wait:false});

		ItemIndex.addEvent('mouseenter', function(){
			PanelIndex.setStyles({'top':BarreNav.getTop()+35,'left':Decale});
			PanelIndex.setStyles({'display':'','overflow':'hidden', color:'#fff', 'opacity':Opacity,'z-index':100, 'background-color':'#ccc', 'width':'240px', 'position':'absolute'});
			fxOnIndex.start({'height': Hauteur }); });
		ItemIndex.addEvent('mouseleave', function(){fxOffIndex.start({'height': '0px' }); });
		*/
		
		// Recherche
		var PanelRech = $('PanelRech');
		var ItemRech = $('ItemRech');
		
		ItemRech.addEvent('click', function(){ VersPage('site.search'); });
		PanelRech.setStyles({'top':0,'left':0,'height':0, 'display':'none'});

		var slidePanelRech=new Fx.Slide(PanelRech,{duration: 100,transition: Fx.Transitions.Bounce.easeOut});
		//slidePanelIndex.hide();
		slidePanelRech.show();
		ItemRech.addEvent('mouseenter', function(e){e.stop();slidePanelRech.slideIn();});
		ItemRech.addEvent('mouseleave', function(e){e.stop();slidePanelRech.slideOut();});

		/*
		//var fxOnRech=new Fx.Styles(PanelRech, {duration:20, wait:false, transition:Fx.Transitions.Elastic.easeOut});
		//var fxOffRech=new Fx.Styles(PanelRech, {duration:20, wait:false});
		var fxOnRech=new Fx.Tween(PanelRech, {duration:20, wait:false, transition:Fx.Transitions.Elastic.easeOut});
		var fxOffRech=new Fx.Tween(PanelRech, {duration:20, wait:false});

		ItemRech.addEvent('mouseenter', function(){
			PanelRech.setStyles({'top':BarreNav.getTop()+35,'left':Decale+240});
			PanelRech.setStyles({'display':'','overflow':'hidden', color:'#fff', 'opacity':Opacity,'z-index':100, 'background-color':'#ccc', 'width':'240px', 'position':'absolute'});
			fxOnRech.start({'height': Hauteur }); });
		ItemRech.addEvent('mouseleave', function(){fxOffRech.start({'height': '0px' }); });
		*/
		
		// Inscription
		var PanelInsc = $('PanelInsc');
		var ItemInsc = $('ItemInsc');

		ItemInsc.addEvent('click', function(){ VersPage('site.record'); });
		PanelInsc.setStyles({'top':0,'left':0,'height':0, 'display':'none'});
		
		/*
		//var fxOnInsc=new Fx.Styles(PanelInsc, {duration:20, wait:false, transition:Fx.Transitions.Elastic.easeOut});
		//var fxOffInsc=new Fx.Styles(PanelInsc, {duration:20, wait:false});
		var fxOnInsc=new Fx.Tween(PanelInsc, {duration:20, wait:false, transition:Fx.Transitions.Elastic.easeOut});
		var fxOffInsc=new Fx.Tween(PanelInsc, {duration:20, wait:false});

		ItemInsc.addEvent('mouseenter', function(){
			PanelInsc.setStyles({'top':BarreNav.getTop()+35,'left':Decale+480});
			PanelInsc.setStyles({'display':'','overflow':'hidden', color:'#fff', 'opacity':Opacity,'z-index':100, 'background-color':'#ccc', 'width':'240px', 'position':'absolute'});
			fxOnInsc.start({'height': Hauteur }); });
		ItemInsc.addEvent('mouseleave', function(){fxOffInsc.start({'height': '0px' }); });
		*/

		// Compte
		var PanelCpte = $('PanelCpte');
		var ItemCpte = $('ItemCpte');

		ItemCpte.addEvent('click', function(){ VersPage('site.account'); });
		PanelCpte.setStyles({'top':0,'left':0,'height':0, 'display':'none'});
		
		/*
		//var fxOnCpte=new Fx.Styles(PanelCpte, {duration:20, wait:false, transition:Fx.Transitions.Elastic.easeOut});
		//var fxOffCpte=new Fx.Styles(PanelCpte, {duration:20, wait:false});
		var fxOnCpte=new Fx.Tween(PanelCpte, {duration:20, wait:false, transition:Fx.Transitions.Elastic.easeOut});
		var fxOffCpte=new Fx.Tween(PanelCpte, {duration:20, wait:false});

		ItemCpte.addEvent('mouseenter', function(){
			PanelCpte.setStyles({'top':BarreNav.getTop()+35,'left':Decale+720});
			PanelCpte.setStyles({'display':'','overflow':'hidden', color:'#fff', 'opacity':Opacity,'z-index':100, 'background-color':'#ccc', 'width':'240px', 'position':'absolute'});
			fxOnCpte.start({'height': Hauteur }); });
		ItemCpte.addEvent('mouseleave', function(){fxOffCpte.start({'height': '0px' }); });
		*/
	}
}

var SendFormIns=function()
{
	if( $chk( $('frminscript') ) )
	{
		$('frminscript').addEvent('submit', function(e) {
			/**
			 * Prevent the submit event
			 */
			new Event(e).stop();
		 
			/**
			 * This empties the log and shows the spinning indicator
			 */
			var log = $('log').empty().addClass('ajax-loading');
		 
			/**
			 * send takes care of encoding and returns the Ajax instance.
			 * onComplete removes the spinner from the log.
			 */
			this.send({
				update: log,
				onComplete: function() {
					log.removeClass('ajax-loading');
				}
			});
		});
	}
}

function ValidateIns()
{
	var query=$('frminscript').toQueryString();
	var myAjax = new AjaxEOL('/Ajax', {method: 'get',data:'_action_=ajax&ref=vavins&'+query,
		oncomplete: function(){
			//
		}		
		}).request();
}

function LoginCompte()
{
	var query=$('frminscript').toQueryString();
	var myAjax = new AjaxEOL('/Ajax', {method: 'get',data:'_action_=ajax&ref=vavlog&'+query,
		oncomplete: function(){'alert("Vous êtes connecté...");'} }).request();
}
function MessageTo()
{
	$('MesDiv').setStyle('display', ''); 
	$('BtSend').setStyle('display', '');
	$('BtMess').setStyle('display', 'none');
}
function MessageSend()
{
	if(document.frmmes.message.value.trim() == '')
	{
		alert(' Contenu invalide... ');
		return;
	}
	$('BtSend').setStyle('display', 'none');
	document.frmmes.submit();
}

function ActiveList(Page, Mode)
{
	$('scContents').getElements('div[class=scItem]').each(function(el)
	{
		var vavCode = el.getProperty('vavCode');
		el.onclick = function(){VersPage(Page,vavCode, Mode)};
		el.onmouseover = function(){ el.addClass('overlist'); };
		el.onmouseout = function(){ el.removeClass('overlist'); };		
	});
}

if( window.ie6 === true)
	window.addEvent('load',function(){Boutons();Inputs();Panels();});
else
	window.addEvent('domready',function(){Boutons();Inputs();Panels();});


