// JavaScript Document


var coche=0;

// cochage ou decochage des checkbox pour impression d'affaires
function checkall(){
var i;
coche++;
if (coche%2!=0){

f=document.forms.f_mail;

 for (i=0;i<f.elements.length;i++)
 								{
     if(f.elements[i].type=='checkbox') f.elements[i].checked=true ;				
										
								}


}else{

 for (i=0;i<f.elements.length;i++)
 								{
     if(f.elements[i].type=='checkbox') f.elements[i].checked=false ;				
										
								}
								}
}

function swap_bg (id,file_bg){
     document.getElementById('c'+id).style.background='url(images/structure/'+file_bg+'.gif)';  
}


function control_check(){
f=document.getElementById('f_modif');

if (f.o_pub.checked==true) f.o_pub.value=1; else f.o_pub.value=0;
  

}

function choixScat(f,sc){
c=document.getElementById(f);
idv=c.elements[sc].options[c.elements[sc].selectedIndex].value;
document.getElementById('scat').value=idv;

}
function choixCat(f){

c=document.getElementById(f);
idv=c.elements['o_cat'].options[c.elements['o_cat'].selectedIndex].value;

                
    for (j=10;j<28;j++){
   document.getElementById('sc'+j).style.visibility="hidden";
  }               
 
  if (idv!=''){
  
   document.getElementById('sc'+idv).style.visibility="visible";

  }else{
   document.getElementById('scat').value='';
         }             
             
  


}

function secure_session(t){
  
   setTimeout("window.location.href='?timeout';",t);  
}


function isNum(f,c){
  
   v=document.getElementById(f).elements[c].value;
   
   
   if (isNaN(v)) 
    {
      alert('Le prix doit être de type numérique !') ;
      return false;
    }else{
     return true;
     }
}




function photomx(dir,p) {
photo=window.open(dir+"./getsnapLH.php?p="+p,"photo","top="+((screen.height)/2-300)+",left="+((screen.width)/2-300)+",resizable=yes,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,width=600,height=600");
}
function killobjet(n,o){
var input=confirm('Vous êtes sur le point de supprimer '+n+' : '+o+' !\nVoulez-vous vraiment effectuer cette action ?');
if (input==true)
	{
		return(true);
	}
else {
		return(false);
	}
    }

function delart(p){
var input=confirm('Tu es sur le point de supprimer cet article !\nEs-tu sur ?\n\n Si oui clique sur OK sinon Annule...');
if (input==true)
	{
		document.location.href='?del=1&id='+p;
	}
else {
		return(false);
	}
    }
function checkF(f){
val=trim(f.titre.value);
if (val==""){
alert('Le titre de ton article doit être renseigné !');return false;
}

Nom = navigator.appName;
if (Nom == 'Microsoft Internet Explorer') {
t=window.frames['iarea'].document.body.innerHTML;
}else{
t=document.getElementById('iarea').contentWindow.document.body.innerHTML;
}
f.texte.value=t;



}
function opentchat(p,b){
// action= voir , modif , suppression, ajout
// i=0 si action==ajout thetchat.php?pseudo="+p,"
if (b==2){ alert('Vous ne pouvez pas envoyer un message tchat à : '+p+' car vous l\'avez bloqué !!');
}else if (b==3){ alert('Vous ne pouvez pas envoyer un message tchat à : '+p+' car il/elle vous a bloqué...');
}else{
chat=window.open("thetchat.php?pseudo="+p,"tchat","resizable=no,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,width=650,height=445");
chat.focus();

}
}
function ReductMode(){
window.open("winreduct.php","WR","top=0,left="+((screen.width)-345)+",resizable=no,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,width=345,height=650");
window.close();
document.location='index.php';


}
function opentchatall(){
chatall=window.open("tchatall.php?a=tchat","tchatall","resizable=no,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,width=670,height=600");

}
function emptymess(f){
if (f.elements['message'].value==''){ alert('Aucun message à envoyer');
return false;}
else if (f.message.value.length>500){alert('Votre message contient trop de caractères !\n(500 maximum)');
return false;}
else{f.elements['mess'].value=f.elements['message'].value;
					f.elements['message'].value='';}
}

function trim(val) {
     var retour = ""
     for(i=0;i < val.length;i++)
         if(val.charAt(i) != " ") {
             retour += val.charAt(i)
         }
     return retour
}

function emptych(f){
c=document.getElementById(f);
longueur=trim(c.qs.value).length;
if (longueur==0){ alert('Vous n\'avez tapé aucun mot !\n\nN\'hésitez pas à consulter l\'aide pour affiner votre recherche...');
return false;}
}


function enabledep(f){
c=document.getElementById(f);
if (c.elements['o_pays'].options[c.elements['o_pays'].selectedIndex].text=='France'){

	c.o_dept.disabled=false; } else { c.o_dept.disabled=true;c.elements['o_dept'].selectedIndex=0;}


}
function choixdep(f){
c=document.getElementById(f);
if (c.elements['departement'].options[c.elements['departement'].selectedIndex].value==''){
   alert("Choisissez un département svp !");
   return false;
   }else{
   return true;
   }
}
function seeCal(f){
c=document.getElementById(f);
dep = c.elements['departement'].options[c.elements['departement'].selectedIndex].text;
depv = c.elements['departement'].options[c.elements['departement'].selectedIndex].value;
if (depv=="")  {alert("Choisissez un département svp !");return false;}else{
dep = dep.replace(/ /g,'-');
dep = dep.toLowerCase();
jour = c.elements['date'].options[c.elements['date'].selectedIndex].value;
//if (jour=="") jour='null';
url = 'liste-brocantes-vide-greniers-'+jour+'-'+dep+'.html';
document.location.href=url;
//alert(url);
}
   
}

function abortimg(numim){
document.images['im'+numim].src='images/pixel.gif';
//document.images['im'+numim].width=0;
//document.images['im'+numim].height=0;
return true;
}

function chgim1(numim){
document.images[numim].src='images/med2.gif';
return false;
}
function chgim2(numim){
document.images[numim].src='images/med.gif';
return false;
}
function charteok(f){
c=document.getElementById(f);
if (c.cgu.checked){return true;}else{alert('Vous devez avoir lu et accepté les conditions d\'utilisation pour valider l\'inscription !');return false;}

}
function voircharte(){
use=window.open("charte.html","charte","top="+((screen.height)/2-125)+",left="+((screen.width)/2-250)+",toolbar=0,location=0,status=0,menubar=0,scrollbars=1,width=500,height=250");

}
function openblog(){
window.open("espaceperso/myblog.php","myblog","top="+((screen.height)/2-300)+",left="+((screen.width)/2-345)+",toolbar=0,location=0,status=0,menubar=0,scrollbars=1,width=690,height=600");

}
function viewblog(p){
window.open("espaceperso/blog.php?p="+p,"blog","top="+((screen.height)/2-300)+",left="+((screen.width)/2-345)+",toolbar=0,location=0,status=0,menubar=0,scrollbars=1,width=690,height=600");

}

function putinto(){
f=document.getElementById('f_mail');

if (f.who.options[f.who.selectedIndex].value!=-2){
f.mail_pseudo.value=f.who.options[f.who.selectedIndex].text;
}else{
f.mail_pseudo.value='';
}
}
function ChFlag(f){
var fg="";
f=document.getElementById(f);
if ((f.elements['o_pays'].options[f.elements['o_pays'].selectedIndex].text=="Choisissez dans la liste")||(f.elements['o_pays'].options[f.elements['o_pays'].selectedIndex].text=="Autre")){
fg="images/flag/no_flag.gif";
document.getElementById('flag').src=fg;
}else {
var fg="images/flag/"+f.o_pays.options[f.o_pays.selectedIndex].text.toLowerCase()+".gif";
document.getElementById('flag').src=fg;
}
}
function control_acc(n)
{
var nb=7;
	for(i = 1; i <= nb; i++)
        {
        	if((document.getElementById(i).style.visibility = 'visible')&&(i != n))
                {
                document.getElementById(i).style.visibility = 'hidden';
                }
        }
}
function control_artistes(n)
{
var nb=26;
	for(i = 1; i <= nb; i++)
        {
        	if((document.getElementById(i).style.visibility = 'visible')&&(i != n))
                {
                document.getElementById(i).style.visibility = 'hidden';
                }
        }
}

function montre(n)
{
	
		document.getElementById(n).style.visibility = 'visible';
		document.getElementById(n).style.width = '435px';
		document.getElementById(n).style.height = '200px';
		document.getElementById(n).style.left = '178px';	
		document.getElementById(n).style.top = '300';	
   	document.getElementById(n).src='_flashtchat.php';

}
function montre2(n,w,h)
{

		document.getElementById(n).style.visibility = 'visible';
		document.getElementById(n).style.width = w+'em';
		document.getElementById(n).style.height = h+'em';
		
}
function Hide2(n)
{
    document.getElementById(n).src='';
		document.getElementById(n).style.visibility = 'hidden';
		document.getElementById(n).style.width = '0px';
		document.getElementById(n).style.height = '0px';
		
}

function confirmation(){
var input=confirm('Vous allez annuler votre saisie !');
if (input==true)
	{
		return(true);
	}
else {
		return(false);
	}
    }
function killcompte(){
var input=confirm('Vous êtes sur le point de supprimer votre compte !\nCeci aura pour effet de supprimer également tous les mails que avez envoyé aux autres membres...\nAinsi que votre blog et toutes les photos qu\'il contient...\nAprès la suppression vous serez automatiquement redirigé vers la page d accueil\nVoulez-vous vraiment fermer votre compte ?');
if (input==true)
	{
		return(true);
	}
else {
		return(false);
	}
    }

// verification d'un formulaire pour des champs text, vides, débutant par un espace
// et caractères speciaux
function verifannonce(f)

{
 var ex=/[0-9A-Za-z]/;
 var exmail=/\s/;
 var exmail2=/[.]/;
 var dep=/[^0-9]/;
 var errmail='Une erreur est survenue dans votre adresse mail !\nElle doit être du type : \nvotrenom@votrefournisseur.xxx';
 var mail=f.elements['email'].value;
 var tabmail=mail.split(/@/);
 	
  		if (dep.test(f.elements['departement'].value)){
							alert('Le champs Département ne doit contenir que des chiffres !\nVeuillez vérifier SVP...');return false;											
										}
																																									
if ((tabmail.length!=2)||(exmail.test(mail))||(exmail2.test(tabmail[1])==false)){alert(errmail);return false ;}
        if
				(f.elements['choix'].options[f.elements['choix'].selectedIndex].value=="vide" ){	
				  alert('Vous n\'avez pas renseigné le champs : Type d\'annonce !');
							 return false;
							 						}
						
 /*        if
			(f.elements['contact'].options[f.elements['contact'].selectedIndex].value==0){
                             alert('Vous n\'avez pas renseigné le champs '+f.elements['contact'].name+' !');
							 return false;
						}
        if
			(f.elements['type'].options[f.elements['type'].selectedIndex].value==0){
                             alert('Vous n\'avez pas renseigné le champs '+f.elements['type'].name+' !');
							 return false;
						}
*/
    for (i=0;i<f.elements.length;i++){
		if ( ((f.elements[i].type=='text')||(f.elements[i].type=='password')) && (f.elements[i].value=='') ){
							alert('Le champs '+f.elements[i].name+' est vide !');return false;											
										}
		if 
			( ((f.elements[i].type=='text')||(f.elements[i].type=='password')) && f.elements[i].value.charAt(0)==' '){
							alert('Le champs '+f.elements[i].name+' ne peut commencer par un espace !');return false;	
						}

   }
   
       for (k=2;k<5;k++){

          for (j=0;j<(f.elements[k].value.length);j++){
 if (ex.test(f.elements[k].value.charAt(j))==false){
 alert('Seuls les chiffres et les lettres non accentuées sont autorisés pour les champs :\n - Prénom\n- Pseudo\n- mot de passe');
 return false;}
                          }
						}  
						  

  		if (f.elements['texte'].value=='' || f.elements['texte'].value.charAt(0)==' '){
							alert('Vous n\'avez pas rempli votre annonce ou celle-ci commence par un espace !\nVeuillez vérifier SVP...');return false;											
										}

		if ((f.elements['texte'].value.length)>255){
		alert('Votre annonce dépasse les 255 caractères !\nVeuillez vérifier SVP...');return false;}											

}


function hidepub(r){
if (r!='a1') {
if (location.search!=''){
document.location.href = location.pathname + location.search + "&pl=a1"  ;
}
else
{
document.location.href = location.pathname + "?pl=a1"  ;

}
return true;
//document.write('yiyiyiyiyiyiyiyiyiy');
//r=1;
}

}

