evalScripts = function(strIdElement) {
	var eltElement = $(strIdElement);
	
	if(!eltElement)
		return false;
	var aEltScripts = eltElement.getElementsByTagName("script");
	
	for (var i=0; i<aEltScripts.length; i++) {
		var eltScript=aEltScripts[i];
		eltScript.setAttribute("type", "text/javascript");
		if (eltScript.src && eltScript.src!="") {} 
		else {
			window.eval(eltScript.text);
		}
	}
};

validateQuestionnaire = function() {
	oParam = $('QuestionnaireForm').serialize(true);
	oParam.a = 'validateQuestionnaire';
	
	eltBody = document.body;
	eltBody.padding = 0;
	
	$('content').innerHTML = '';
	eltBody.innerHTML += _AJAX_LOADING_WITH_BACK;
	try{
	new Ajax.Request('/index.php', {
		method: 'POST',
		parameters: oParam,
		onComplete: function(oXmlResponse) {
			$('header').innerHTML += oXmlResponse.responseText;
			evalScripts($('header'));
		}
	});} catch(e) {alert(e);}
};

previewValidateQuestionnaire = function() {
	eltBody = document.body;
	eltBody.padding = 0;
	$('content').innerHTML = '';
	eltBody.innerHTML += _AJAX_LOADING_WITH_BACK;
	window.location.href = '/index.php?c=ProjectL4L&a=previewResults';
};

displayConversionForm = function(bClosablePopup, strConversionFunction) {
	if (bClosablePopup == undefined) {
		bClosablePopup = true;
	}
	if (strConversionFunction == undefined) {
		strConversionFunction = '';
	}
	
	Dialog.info('', {
		windowParameters: {
			className: 'alphacube',
			title: '',
			width: 200,
			height: 200,
			draggable: false,
			resizable: false,
			hideEffect:Element.hide,
			showEffect:Element.show,
			closable:bClosablePopup
		}
	});
	
	Dialog.setInfoMessage(_AJAX_LOADING);
	new Ajax.Request("/index.php", {
		 method: 'post',
		 asynchronous: true,
		 contentType: 'application/x-www-form-urlencoded',
		 encoding: 'UTF-8',
		 parameters: {a: 'executeConversion', convFunction: strConversionFunction},
		 onComplete: function(oHttpResponse) {
		 	Dialog.setInfoMessage(oHttpResponse.responseText);
		 	Windows.focusedWindow.updateWidth();
		 	Windows.focusedWindow.updateHeight();
		 	Windows.focusedWindow.showCenter();
			evalScripts('modal_dialog_message');
		 }
	});
};

displayConversionFormNoClosable = function() {
	displayConversionForm(false);
}

previewConversionForm = function() {
	Dialog.info('', {
		windowParameters: {
			className: 'alphacube',
			title: '',
			width: 365,
			height: 440,
			draggable: false,
			resizable: false,
			hideEffect:Element.hide,
			showEffect:Element.show
		}
	});
	
	Dialog.setInfoMessage(_AJAX_LOADING);
	oParam = {c: 'ProjectL4L', a:'previewConversion'};
	
	new Ajax.Request("/index.php", {
		 method: 'post',
		 asynchronous: true,
		 contentType: 'application/x-www-form-urlencoded',
		 encoding: 'UTF-8',
		 parameters: oParam,
		 onComplete: function(oHttpResponse) {
		 	Dialog.setInfoMessage(oHttpResponse.responseText);
			evalScripts('modal_dialog_message');
		 }
	});
};

validateConversion = function(strConversionFunction) {
	oParam = $('FormLinkConversion').serialize(true);
	oParam.a = 'executeConversion';
	oParam.convFunction = strConversionFunction? strConversionFunction : '';
	
	Dialog.setInfoMessage(_AJAX_LOADING);	
	new Ajax.Request("/index.php", {
		 method: 'post',
		 asynchronous: true,
		 contentType: 'application/x-www-form-urlencoded',
		 encoding: 'UTF-8',
		 parameters: oParam,
		 onComplete: function(oHttpResponse) {
		 	Dialog.setInfoMessage(oHttpResponse.responseText);
		 	Windows.focusedWindow.updateWidth();
		 	Windows.focusedWindow.updateHeight();
		 	Windows.focusedWindow.showCenter();
			evalScripts('modal_dialog_message');
		 }
	});
};

validatePreviewConversion = function() {
	oParam = $('FormLinkConversion').serialize(true);
	oParam.c = 'ProjectL4L';
	oParam.a = 'previewConversion';
	oParam.format = 'html';
	
	Dialog.setInfoMessage(_AJAX_LOADING);	
	new Ajax.Request("/index.php", {
		 method: 'post',
		 asynchronous: true,
		 contentType: 'application/x-www-form-urlencoded',
		 encoding: 'UTF-8',
		 parameters: oParam,
		 onComplete: function(oHttpResponse) {
		 	Dialog.setInfoMessage(oHttpResponse.responseText);
			evalScripts('modal_dialog_message');
		 }
	});
};

displaySendToFriendForm = function() {
	Dialog.info('', {
		windowParameters: {
			className: 'alphacube',
			title: '',
			width: 200,
			height: 200,
			draggable: false,
			resizable: false,
			hideEffect:Element.hide,
			showEffect:Element.show
		}
	});
	
	Dialog.setInfoMessage(_AJAX_LOADING);
	new Ajax.Request("/index.php", {
		 method: 'post',
		 asynchronous: true,
		 contentType: 'application/x-www-form-urlencoded',
		 encoding: 'UTF-8',
		 parameters: {a: 'executeSendToFriend'},
		 onComplete: function(oHttpResponse) {
		 	Dialog.setInfoMessage(oHttpResponse.responseText);
		 	Windows.focusedWindow.updateWidth();
		 	Windows.focusedWindow.updateHeight();
		 	Windows.focusedWindow.showCenter();
			evalScripts('modal_dialog_message');
		 }
	});
};

validateSendToFriend = function() {
	oParam = $('FormLinkSendToFriend').serialize(true);
	oParam.a = 'executeSendToFriend';
	
	Dialog.setInfoMessage(_AJAX_LOADING);	
	new Ajax.Request("/index.php", {
		 method: 'post',
		 asynchronous: true,
		 contentType: 'application/x-www-form-urlencoded',
		 encoding: 'UTF-8',
		 parameters: oParam,
		 onComplete: function(oHttpResponse) {
		 	Dialog.setInfoMessage(oHttpResponse.responseText);
		 	Windows.focusedWindow.updateWidth();
		 	Windows.focusedWindow.updateHeight();
		 	Windows.focusedWindow.showCenter();
			evalScripts('modal_dialog_message');
		 }
	});
};

validatePreviewSendToFriend = function() {
	oParam = $('FormLinkSendToFriend').serialize(true);
	oParam.c = 'ProjectL4L';
	oParam.a = 'previewSendToFriend';
	
	Dialog.setInfoMessage(_AJAX_LOADING);	
	new Ajax.Request("/index.php", {
		 method: 'post',
		 asynchronous: true,
		 contentType: 'application/x-www-form-urlencoded',
		 encoding: 'UTF-8',
		 parameters: oParam,
		 onComplete: function(oHttpResponse) {
		 	Dialog.setInfoMessage(oHttpResponse.responseText);
			evalScripts('modal_dialog_message');
		 }
	});
};

var oTimer;

displayValidationMessage = function() {
	$('FooterMessage').hide();
	Effect.Appear('InformationValidation', { duration: 1.0 });
	oTimer = new PeriodicalExecuter(hideValidationMessage, 7);
};

hideValidationMessage = function() {
	Effect.Fade('InformationValidation', {
		duration: 1.0,
		afterFinish: function() {
			$('FooterMessage').show();
		}
	});
	if(oTimer) oTimer.stop();
};