// JavaScript Document
//////////////////////////////////////options bbcode /////////////////////////////////
var imageTag = false;
var theSelection = false;
// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);
// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]');
imageTag = false;


function cite(idT,pseudo){
	document.getElementById('Fcontrib').style.display='block';
	
	document.f_topic.c_texte.value = "[citation][gras]["+pseudo+" a écrit][/gras]" + document.getElementById('T'+idT).innerHTML + "[/citation]\n\n";
	document.f_topic.c_texte.scrollTop= 10000;
	document.f_topic.c_texte.focus();
	
}
// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}
// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}
// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}
function checkForm() {
	formErrors = false;
		if (document.post.titre.value.length < 2) {
		formErrors = "Vous devez entrer un titre avant de poster.";
	}
		if (document.post.message.value.length < 2) {
		formErrors = "Vous devez entrer un message avant de poster.";
	}
	if (formErrors) {
		alert(formErrors);
		return false;
	} else {
		bbstyle(-1);
		//formObj.preview.disabled = true;
		//formObj.submit.disabled = true;
		return true;
	}
}
function emoticon(text) {
	var txtarea = document.f_topic.c_texte;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}
function bbfontstyle(bbopen, bbclose) {
	var txtarea = document.f_topic.c_texte;
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			txtarea.value += bbopen + bbclose;
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		txtarea.focus();
		return;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbopen, bbclose);
		return;
	}
	else
	{
		txtarea.value += bbopen + bbclose;
		txtarea.focus();
	}
	storeCaret(txtarea);
}
function bbstyle(bbnumber) {
	var txtarea = document.f_topic.c_texte;
	txtarea.focus();
	donotinsert = false;
	theSelection = false;
	bblast = 0;
	if (bbnumber == -1) { // Close all open tags & default button names
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			txtarea.value += bbtags[butnumber + 1];
			buttext = eval('document.post.addbbcode' + butnumber + '.value');
			eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return;
	}
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	}
	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}
	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];
				buttext = eval('document.post.addbbcode' + butnumber + '.value');
				eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}
			txtarea.focus();
			return;
	} else { // Open tags
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];
			lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
			document.post.addbbcode14.value = "Img";	// Return button back to normal state
			imageTag = false;
		}
		// Open tag
		txtarea.value += bbtags[bbnumber];
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(bbcode,bbnumber+1);
		eval('document.post.addbbcode'+bbnumber+'.value += "*"');
		txtarea.focus();
		return;
	}
	storeCaret(txtarea);
}
// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;
	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}
// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}
////////////////////////////////////////////// fin bbcode //////////////////////////////////////
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 swap_img (id,file_bg){
     document.getElementById(id).src='./images/'+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 printFiche(dir,ets){

  print=window.open(dir+"./print_fiche.php?r="+ets,"fiche","top=0,left=0,resizable=yes,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,width=810,height=600");
}

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 diap(file){

    lay = document.getElementById("visio");
    lay.innerHTML ="";
    lay.style.width='650px';
    lay.style.height='400px';
    lay.style.display='block'; 
    tab = file.split('/');
    lay.innerHTML = "<img src='../getsnapHL.php?w=400&p=" + file + "' class='bdr' /><br />" + tab[1];
}

function diapOn(file){

    lay = document.getElementById('visio');
    lay.style.display='none';    
    
     wt  = document.getElementById('wait');
     
     wt.innerHTML='Chargement de l\'image en cours...';
    
    
    lay.style.display='block';  
    
    lay.innerHTML ="<img onload=\"wt.innerHTML='';\"  src='./getsnapLH.php?w=480&p=" + file + "' class='bdr' />"; 
    
 

}

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,w,pic) {
photo=window.open(dir+"./getsnapLH.php?w="+w+"&pic="+pic,"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 photoHC(pic) {
photo=window.open(pic,"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 marcheMap(ville) {
map=window.open("./map_marche.php?ville="+ville,"marche","top="+((screen.height)/2-250)+",left="+((screen.width)/2-250)+",resizable=yes,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,width=540,height=540");
}

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 abortimg(numim){
document.images[numim].src='../images/delete.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 OpenTab(a,t){
window.open("../frames/opentab.php?a="+a+"&t="+t,"tab","top=0,left=0,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,width=20,height=20");

}
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 putHart(){
f=document.getElementById('f_tab');
if (f.elements['c_art'].options[f.elements['c_art'].selectedIndex].value!=-2){
f.elements['Nart'].value=f.elements['c_art'].options[f.elements['c_art'].selectedIndex].text;
}else{
f.elements['Nart'].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)
{

document.getElementById('C').style.display = 'none';
document.getElementById('C+').style.display = 'none';
document.getElementById('D').style.display = 'none';
document.getElementById('Eb').style.display = 'none';
document.getElementById('E').style.display = 'none';
document.getElementById('F').style.display = 'none';
document.getElementById('F+').style.display = 'none';
document.getElementById('G').style.display = 'none';
document.getElementById('G+').style.display = 'none';  
document.getElementById('A').style.display = 'none';
document.getElementById('Bb').style.display = 'none';  
document.getElementById('B').style.display = 'none';    	

document.getElementById(n).style.display = 'block';    	

}

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  : \n\n - Supprimer tous les mails que avez envoyé aux autres membres\n - Supprimer ou rendre propriétaire BpZik.com de toutes les contributions concernant les artistes auxquelles vous avez participé : \n\tComme :\n\t\tLes tablatures\n\t\tLes bios\n\t\tLes actus\n\t\tLes concerts\n\t\tLes discographies etc.\n\n\n - Supprimer tous sujets de discussions et messages postés dans les forums.\n\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;
}

}
