﻿//
var xml_path = '/extension/joa/design/joa/medias/xml/';
window.addEvent("load", function(e) {
	// global settings for all forms
	fSetAlertOptions({
		bAlertOnBlur: false, 
		
		width: 210,
		fOnErrorShow: function(sInput) {
			if ($$(".alertSpace").length == 0) {
				var oBox = $$(".alertClassBox");
				if (oBox.length != 0) {
					new Element("span").addClass("alertSpace").setStyles({
						"height" : oBox[0].getCoordinates().height
					}).injectBefore($(sInput).getParent());
				//	oBox[0].setStyle("margin-top", -oBox[0].getCoordinates().height-20);
				}
			}
		}, 
		fOnErrorHide: function(sInput) {
			$$(".alertSpace").each(function(el){
				el.remove();
			});
		}
	});
	// Here I defined the elements for all the forms, in one simple array
	var oForms=[
		{formId:'frmNewsletter',submitId:'frmNewsletterSubmit', xml:xml_path+'newsletters.xml'},
		{formId:'frmContact',submitId:'frmContactSubtmit', xml:xml_path+'contactez.xml'},
		{formId:'frmRejoignez',submitId:'frmRejoignezSubtmit', xml:xml_path+'rejoignez.xml'},
		{formId:'frmRecommander',submitId:'frmRecommanderSubtmit', xml:xml_path+'recommander.xml'}
		
		//,		{formId:'formTrouvezCasino',submitId:'formSearchButton', xml:xml_path+'search.xml'}
	]
	// create alerts for forms
	initFormAlerts(oForms);

});

//This function get the forms array and add the alert class for each form
function initFormAlerts(oForms) {
	for (iInc=0;iInc<oForms.length;iInc++){
		//alert($(oForms[iInc].submitId));
		if ($(oForms[iInc].submitId) && $(oForms[iInc].formId)) {
			new fValiderAlert(oForms[iInc].xml, oForms[iInc].submitId, {});
		}
	}
}


