error_number="";

function trim(s) {
    return s.replace(/^\s+/, '').replace(/\s+$/, '');
}
function checkEmail(str) { 	
	var at="@" 
	var dot="." 
	var lat=str.indexOf(at) 
	var lstr=str.length 
	var ldot=str.indexOf(dot) 
	var lastpoint=str.lastIndexOf(dot);
	
	if (str.indexOf(at)==-1){ 
		return false;
		} 
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){  
		return false;
		} 
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ 
		return false; 
		} 
	if (str.indexOf(at,(lat+1))!=-1){ 
		return false;
		} 
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ 
		return false; 
		} 
	if (str.indexOf(dot,(lat+2))==-1){ 
		return false; 
		} 
	if (str.indexOf(" ")!=-1){  
		return false; 
		} 
	if ((str.substring(lastpoint+1,lstr)).length > 4) {
		return false;
		}
	return true 
} 

function verification(){

	var error = "";
	var email	=	document.getElementById("email").value;
	var title	=	document.getElementById("title").value;
	var content	=	document.getElementById("text_content").value;

	/*****check email****/
	email=trim(email);
	if(checkEmail(email)==false){
		error="Erreur de saisie : l'adresse email est incorrecte";
		}
		
	//check title
	if(title==""){
		error = "Erreur de saisie : le titre ne doit pas etre vide";
		}
		
	if(title.length <= 6){
		error = "Erreur de saisie : le titre est trop court";
		}

	//check content
	
	if (error==""){
		document.getElementById('form_annonce').submit();
		}
	else {
		displayError(error);
		}

}

function displayError(str){

	document.getElementById("error_msg").firstChild.nodeValue=str;
	document.getElementById("error_display").style.display="block";
}

function getIframeContent(){

	IE  = window.ActiveXObject ? true : false;
	url = "";		
  	if(IE){
  			edoc = window.frames['upload_image'].document;
			if(edoc.getElementById('img_url')!=null) url=edoc.getElementById('img_url').value;
  			}	
    else {
  			edoc = document.getElementById('upload_image').contentDocument;			
			if(edoc.getElementById('img_url')!=null) url=edoc.getElementById('img_url').value;			
			}	
	document.getElementById("img").value=url;			
}