var contactForm = new Object() ; 

function validateContactForm()
{
	if( isContactFormValid() ) 
		ajaxSendContactMessage() ;
}

function isContactFormValid() 
{	
	var errorMsg = "" ; 
		
	formValidator.add( {"value": contactForm.email, "command":"email", "msg":"<li>email isn't valid</li>"}) ; 
	formValidator.add( {"value": contactForm.object, "command":"filled", "msg":"<li>The object is empty</li>"}) ; 
	formValidator.add( {"value": contactForm.message, "command":"filled", "msg":"<li>The message is empty</li>"}) ; 
	
	errorMsg = formValidator.checkIt() ;
	formValidator.clear() ; 
	if( errorMsg == "" ) {
		alert( 'Validation ok : ['+contactForm.email+']['+contactForm.object+']['+contactForm.message+']' ) ; 
		return true ; 
	}else {

		pmpInfo( '<ul>'+errorMsg+'</ul>' ) ; 
		return false ; 		
	}
}

function ajaxSendContactMessage()
{	
	var pars = $H(contactForm).toQueryString(); 
	contactForm.ajaxRes = false ;	
	
	new Ajax.Request(cpath+'modules/'+moduleName+'/scripts/sendContactMessage.php', { method:'post',
		postBody: $H(contactForm).toQueryString() ,
	  	onCreate: function(requestObj){
			//alert('create');
	    },
	  	onSuccess: function(requestObj){					
			var str = requestObj.responseText ;
			str.evalScripts() ; 
			Dialog.cancelCallback();
			
        	if( contactForm.ajaxRes  ){
	        	pmpInfo('Your message  will be send to '+contactForm.contact) ; 	        	 
	        }else {
	        	pmpInfo('Technical Problem to send the message.') ; 		        
	        }
			contactForm = new Object(); 	        
	    },
	    onFailure: function(requestObj){
	    	alert('an error occured.') ; 
	    }
	});	
}