function PageInit()
{
	FormValidate.title = "Veuillez corriger les erreurs suivantes :";
	
	initFormValidation();
}

function initFormValidation()
{
	// All forms having the 'formvalidate' class will have validators built and submit event handled.
	$A($$('form.formvalidate')).each(function(f) {
	
		FormValidate.buildValidators(f.id);
		
		f.observe('submit', function(e, f) {
					
			if(!FormValidate.validate(f.id, true, showFormError.bind(FormValidate)))
			{
				Event.stop(e);
				return false;
			}
			
			return true;
		}.bindAsEventListener(this, f));
		
	});
}

function showFormError(containerForm, showError, badValidators)
{
    var str = '<strong>The following fields are incorrects:</strong><br/><ol>';
    badValidators.each(function(v){
      str += '<li>' + v.options.message + '</li>';
    });
    str += '</ol>';
    $('errorMsg').update(str);
    $('errorMsg').show();
    
    new Effect.ScrollTo('errorMsg');
}

var FocusField =
{
	_current: null,              

	init: function() 
	{
		$$('#something input').each(function(element) 
		{
			Event.observe(element, 'click', FocusField.highlight.bindAsEventListener(FocusField));
		});

		$$('#something textarea').each(function(element) 
		{
			Event.observe(element, 'click', FocusField.highlight.bindAsEventListener(FocusField));
		});
	},             
	
	highlight: function(evt) 
	{
		var element = Event.element(evt);
		var parent = element;
		if (this._current != parent) 
		{
			parent.addClassName('focused');
			if (this._current) 
			{
				this._current.removeClassName('focused');
			}
		
			this._current = parent;
		}
	}
}



function changeMedia(divId,videoId)
{

	var flashvars = {};
	var params = {file : "/media/flash/"+videoId+".flv&autostart=true&skin=/media/flash/silver.swf&autostart=true"};
	var attributes = { wmode : "transparent" , allowscriptaccess : "always", allowfullscreen: true};
	swfobject.embedSWF("/media/flash/player.swf", divId, "630", "390", "9", flashvars, params, attributes);

 }
