app=function(){}
app.validate=function(){
	e=document.mainForm.elements;
	//alert(e.length);

	for(i=0;i<e.length;i++){
	//	alert(i);
	  e[i].style.background='';
	  try{
		if(e[i].getAttribute("req")&&e[i].value==""){		  
				e[i].style.background='#F07106';			
				alert(e[i].getAttribute("req")+" obligatoire!!");			
				e[i].focus();			    
			    return false;
			    break;
		}
	  }catch(e){
		  
	  }	

			
	}
	return true;	
    
}
app.validate.b =function(){
	if($("s_code_ID_COD").innerHTML==hex_md5($("s_code_ID").value.toUpperCase())){
		return true ;
	}else{
		//alert("Fuck code");
		//alert(app.my_condition+"-Fuck code-\n"+$("s_code_ID").value+"\n--"+hex_md5($("s_code_ID").value));
		alert(message_after_submit);
		$("s_code_ID").style.background="";
		$("s_code_ID").focus();
		return false;
	}
	
}
app.isValidEmail=function(o) {
   var str=o.value;
   o.style.background='';
   if( (str.indexOf(".") > 2) && (str.indexOf("@") > 0)){
     }else{
	     alert("Invalid couriel format!!");
	     o.value="";
	     o.style.background='#F07106';	     
	     return false;   
   }
}
app.valFloat=function (o){
    var ret="";
    if (o.value.charAt(o.value.length-1)=="0") return o.value;
    if (o.value.charAt(o.value.length-1)==".") return o.value;
      ret=parseFloat(o.value);
      if (isNaN(ret)) ret="";
       return ret
}
app.validateprice= function (o){
   if (o.name=="Price"){
       document.mainForm.PriceAlternative.selectedIndex=0;
   }else{
        document.mainForm.Price.value='';
   }
 }	
app.check_ob= function (o){
 max_admis=401;
// alert(o.value);
    var mystr=o.value;
	//alert(mystr.length);
	if (mystr.length>=max_admis){
		alert("Maximum 400 characters ");
	    o.value=mystr.substring(0,max_admis)
	    document.mainForm.cnt.value=(max_admis-1);
	    return false;
	}else{
	document.mainForm.cnt.value=mystr.length;
	return true;
	};
	 
 }
app.refresh_code=function(){
	document.getElementById("code_valid").src="include_common/unic_code_img.php?"+Math.random();
}
app.sender2=function(){
	if(app.validate()&&app.validate.b()){		
		newHTML = '<div class="border_preview" style="width:50%;height:300px"><div id="loader_container"><div id="loader"><div align="center">Loading annonce...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
		newHTML = newHTML + '<h2 class="title_h2">LOAD CONTENT </h2>'
		
    	newHTML = newHTML + '</div>'; 
    	$("register-table").style.display="none";
    	$("load_annonce").style.display="block";
	    $("load_annonce").innerHTML=newHTML;
	    animate();
		$('mainFormId').request({
		  method: 'post',
		  encoding: 'UTF-8',
		  onComplete:app.reponse 
		})
	   }
}

app.sender=function(){
	//if(app.validate()&&app.validate.b()){	
		$('mainFormId').submit();
	//}
}
app.senderOP=function(){
	//if(app.validate()&&app.validate.b()){
		newHTML = '<div class="border_preview_animate" style="width:90%;height:300px"><div id="loader_container"><div id="loader"><div align="center">Saving ADD ..</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
		newHTML = newHTML + '<h2 class="title_h2">Saving ADD </h2>'
		
    	newHTML = newHTML + '</div>'; 
    	$("register-table").style.display="none";
    	$("load_annonce").style.display="block";
	    $("load_annonce").innerHTML=newHTML;
	    app.t_id = setInterval(app.animate,60);
		$('mainFormId').request({
		  method: 'post',
		  onComplete:app.reponse 
		})
	//}
}
app.reponse=function(t){
	//alert(t.responseText);
	//$("ccc").innerHTML=t.responseText;
	if (t.responseText.trim()=="ok"){
      // alert('Form data saved!'+t.responseText);
       alert(const_msg_code_send);
      window.location="index.php";
    }else{
	     alert(message_after_submit);
	  // alert("Not saved");
	   //window.location.reload( true );
    }
     $("register-table").style.display="block";
    $("load_annonce").innerHTML="";
    app.remove_loading();
    $("register-table").style.width="100%";
    
  }
app.give_me_id=function(){
		new Ajax.Updater('s_code_ID_COD', 'read_cod.php');
} 

app.list=function(){
	
	    newHTML = '<div class="border_preview" style="width:50%;height:300px"><div id="loader_container"><div id="loader"><div align="center">Loading annonce...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
		newHTML = newHTML + '<h2 class="title_h2">LOAD CONTENT </h2>'
		
    	newHTML = newHTML + '</div>'; 
	    $("load_annonce").innerHTML=newHTML;	    
	   
	
}

app.animate=function(){	
        var elem = $('progress');
		if(elem != null) {
			    elem.innerHTML="";
			    elem.style.display="block";
			    im=document.createElement("img");
			    im.style.width="240px";
			    im.src="../images/progressbar_green.gif";
			    elem.appendChild(im);
		}
}

app.remove_loading=function(){ 
	 var elem = $('progress');
	if(elem != null) {
	  elem.innerHTML="";
	  elem.style.display="none";
  }
}
app.periodical_call=function(){ 
	
	
}
app.send_reply=function(){
	//if(app.validate()&&app.validate.b()){		
		//alert("intra");
		$('replyForm').request({
		  method: 'post',
		  onComplete:app.reponse_reply 
		})
	  }
app.reponse_reply=function(t){
	//$("reply_msg").style.display="none";
	//alert(message_after_reply);
	//alert(t.responseText);
	var response=t.responseText.trim();
	//alert(response.substring(0,5));
	//alert(response.substring(0,5));
	if(response.substring(0,5)=="error")
	{
		response=response.replace("error:","");
		$("errorMsg").innerHTML=response;
		$("errorMsg").style.display="block";
	}else{
		$("replyContent").innerHTML=response;
	}
}
app.check_ob_reply= function (o){
 max_admis=401;
// alert(o.value);
    var mystr=o.value;
	//alert(mystr.length);
	if (mystr.length>=max_admis){
		alert("Maximum 400 characters ");
	    o.value=mystr.substring(0,max_admis);
	    document.replyForm.cnt.value=(max_admis-1);
	    return false;
	}else{
	document.replyForm.cnt.value=mystr.length;
	return true;
	};
	 
 }
app.SetImgUplVal= function (nr_img,i){
	//alert(i+" nn "+nr_img);
	var _p="include_common/load_image_ad_tmp.php?n=";
	var _add=(parseInt(nr_img)-1).toString();
	var el="i"+_add;
	$(el).value=i;
	//alert(_p+i);
	$("uplImg"+(parseInt(nr_img)-1).toString()).src=_p+i;
} 