// JavaScript Document
var FTA = {
	
	submitFrm : function(){
		
		
		
		
		if(FormValidate.validate('ftaFrm',true,function(){})){
			
			myLightWindow.activateWindow(
				{
					href: '/common/loading.asp',
					height : 220,
					width : 350,
					loadingAnimation : false
				}
			);
			
			
			_onSuccessHandler  = this._submitFrm.bind(this);
			options = { 
					method: 'post',
					parameters: $('ftaFrm').serialize(true),
					onSuccess: _onSuccessHandler
			 };
			 

			setTimeout(function(){new Ajax.Request('/_ScriptLibrary/fta/request/request.asp',options)},4000);
			
		}else{
			$('successBox').hide();	
			this.cleanErrorBox();
			FormValidate.badValidators.each(function(v){
				li = '<li>'+ v.options.message +'</li>';
				$('ulerrormessage').insert({ bottom: li});
			});
						
			this.showErrorBox();
		}
		
		
	},
	
	cleanErrorBox : function(){
		childs = $('ulerrormessage').childElements();
		childs.each(function(item) 
			{   
				item.remove();
			}
		); 	
	},
	
	showErrorBox : function(){
		$('errorBox').show();
		new Effect.ScrollTo('errorBox');	
	},
	
	_submitFrm : function(responseRequest){
		rows = String(responseRequest.responseText).evalJSON();
		if(rows.done == 1){
			//$('errorBox').hide();
			window.location.href = 'thanks.asp';
		}else{
			//window.location.href = '/common/500.asp?ErrorMessage=An arror is occured when creating your application please contact the system administrator at <a href="marco@globulebleu.com">marco@globulebleu.com</a>';	
		}
	},
	
	_updateCV: function(){
		html = '<a href="http://csa.profilegroup.com/_Uploads/'+ fileController.upload_newFileName +'" target="_blank" class="ph-myjobLightBlue" style="display:block">'+ $('cvmessage').innerHTML +'</a>';
		$('cvfilename').value = fileController.upload_newFileName;
		$('cvcontainer').update(html);
	},
	
	submitFrmReference : function(){
		
		if(FormValidate.validate('referenceFrm',true,function(){})){
			_onSuccessHandler  = this._submitFrmReference.bind(this);
			options = { 
					method: 'post',
					parameters: $('referenceFrm').serialize(true),
					onSuccess: _onSuccessHandler
			 };
					  
			new Ajax.Request('/_ScriptLibrary/fta/request/request.asp',options);		
		}else{
			FormValidate.badValidators.each(function(v){
				$('errorBox').update(v.options.message);
			});
						
			this.showErrorBox();
		}
		
		
	},
	
	_submitFrmReference : function(responseRequest){
		rows = String(responseRequest.responseText).evalJSON();
		if(rows.done == 1){
			window.location.href = 'form.asp';
		}else{
			html = $('ErrorMessage').innerHTML;	
			//$('errorBox').update('Le code introduit est incorrecte');	
			$('errorBox').update(html);	
			this.showErrorBox();
		}
	}
	
}