/*@file send.js
@brief Functions for email send's by ajax
@author Marcone Gledson de Almeida
@date 2007	
*/

	/*	@brief Function which sends the data via AJAX
		@param url with page's name that receive data (string)
		@param param with the data that will be passed via get
	*/
	function sendAjax(url, param){
	
		var metodo = 'GET';
		
		xmlhttp.open(metodo,url+param,true);
		xmlhttp.onreadystatechange = hw_ret;	//Este comando deve ficar após o open, por causa de bug do IE
		xmlhttp.send(null);
	
	}

	/*	@brief Check if an e-mail is validate or not
		@param e-mail string format
		@return true ou false, case validate or not
	*/
	function checkMail(mail){

		var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
		
		if ((mail == " ")|| (!er.test(mail))){
		
			return false;
		
		}else {
		
			return true;

		}
	
	}
	
	/*	@brief Create the prompt javascript for write e-mail address
		@param idPost the id of the post that will receive 
		@return true ou false, case validate or not
	*/
	function createBoxEmail(idPost, fileScriptName){
		
		
		var email  = prompt('Informe o e-mail para qual o Post sera enviado', ' ');

		if (checkMail(email)){
		
			if(email != null){
		
				sendAjax(fileScriptName, '?email='+email+'&idPost='+idPost);
		
			}
		}else{
		
			alert('E-mail invalido');
			
		}
		


	}