//--------------------------------------------------------
// Fonctions
//--------------------------------------------------------

function verif_numeric(variable)
{
   var exp = new RegExp("^[0-9]+$","g");
   return exp.test(variable);
}

function is_mail(email)
{
	var reg = /^[\w.-]+@[\w.-]+\.\w{1,4}$/;
     var reg2 = /[.@]{2,}/;
     return ((reg.exec(email)!=null) && (reg2.exec(email)==null));
}

function test_tel(tel)
{
	if(verif_numeric(tel))
	{
		if(tel.length == 10) return true;
		else return false
	}
	else return false;
}

function verif_champs(titre,nom,prenom,fonction,societe,tel,email,adresse_pers,adresse_pro)
{
		if(titre == "0")
		{
			alert("Vous devez specifier un Titre");
			document.inscription.titre.focus();
			titre_ok = 0;
		}
		else
		{
			document.inscription.titre.style.borderColor="";
			titre_ok = 1;
		}

		if(nom=="")
		{
			document.inscription.nom.style.borderColor="red";
			document.inscription.nom.focus();
			nom_ok = 0;
		}
		else
		{
			document.inscription.nom.style.borderColor="";
			nom_ok = 1;
		}

		if(prenom=="")
		{
			document.inscription.prenom.style.borderColor="red";
			document.inscription.prenom.focus();
			prenom_ok = 0;
		}
		else
		{
			 document.inscription.prenom.style.borderColor="";
			 prenom_ok = 1;
		}

		if(fonction=="")
		{
			document.inscription.fonction.style.borderColor="red";
			document.inscription.fonction.focus();
			fonction_ok = 0;
		}
		else
		{
			 document.inscription.fonction.style.borderColor="";
			 fonction_ok = 1;
		}

		if(societe=="")
		{
			document.inscription.societe.style.borderColor="red";
			document.inscription.societe.focus();
			societe_ok = 0;
		}
		else
		{
			document.inscription.societe.style.borderColor="";
			societe_ok = 1;
		}

		if(adresse_pers =="" && adresse_pro == "")
		{
			alert("Vous devez entrer au moins une adresse");
			document.inscription.rue_pro.style.borderColor="red";
			document.inscription.rue_pro.focus();
			document.inscription.cp_pro.style.borderColor="red";
			document.inscription.ville_pro.style.borderColor="red";
			document.inscription.rue_pers.style.borderColor="blue";
			document.inscription.cp_pers.style.borderColor="blue";
			document.inscription.ville_pers.style.borderColor="blue";
			adresses_ok = 0;
		}
		else
		{
			adresses_ok = 1;
		}

		if(tel =="")
		{
			document.inscription.tel.style.borderColor="red";
			document.inscription.tel.focus();
			tel_ok = 0;
		}
		else
		{
			document.inscription.tel.style.borderColor="";
			tel_ok = 1;
		}

		 if(email == "" || !is_mail(email))
		{
			document.inscription.email.style.borderColor="red";
			document.inscription.email.focus();
			email_ok = 0;
		}
		else
		{
			document.inscription.email.style.borderColor="";
			email_ok = 1;
		}
		if(titre_ok==1 && nom_ok==1 && prenom_ok==1 && fonction_ok==1 && societe_ok==1 && tel_ok==1 && email_ok==1 && adresses_ok==1) return true;
		else return false;
}
function Check_box() {
	var checkbox = document.inscription.elements["college"];
	if(checkbox == undefined) return true;
	else
	{
		var isChecked = false;
		for (var i=0; i<checkbox.length; i++)
		{
			if (checkbox[i].checked == true)
			{
				isChecked = true;
				break;
			}
		}

		if (isChecked == false)
		{
			alert('Vous devez choisir un coll?ge d\'appartenance');
			return false;
		}
		else
		{
			return true;
		}
	}
}


// Fonction de check / uncheck de checkbox
/*
*	@nomCheckBox : passer 'this.name', recupere le nom de la serie de checkboxes
*	@numBox : recupere quelle box a ?t? cliqu?e pour d?cocher les autres
*	exemple : checkUncheck(this.name, 0);
*/
function checkUncheck(nomCheckBox, numBox){
	var choix = eval("document.forms[0]."+nomCheckBox);
	if(numBox == 0)
	{
     choix[0].checked == true;
     for (i = 1; i < choix.length; i++) choix[i].checked = false;
    }
    else
    {
     for (i = 0; i < choix.length; i++)
     {
     	if(i != numBox)	choix[i].checked = false;
     	else choix[i].checked = true;
     }
    }
}

function verif_form()
{
	var titre = document.inscription.titre.value;
	var nom = document.inscription.nom.value;
	var prenom = document.inscription.prenom.value;
	var fonction = document.inscription.fonction.value;
	var societe = document.inscription.societe.value;
	var tel = document.inscription.tel.value;
	var email = document.inscription.email.value;
	var adresse_pers = document.inscription.rue_pers.value;
	var adresse_pro = document.inscription.rue_pro.value;
	if(Check_box()) college = 1;
	else college = 0;
	if(verif_champs(titre,nom,prenom,fonction,societe,tel,email,adresse_pers,adresse_pro) && college == 1) return true;
	else return false;
	/*return true*/
}
// Boucle de validation
function validateForm(form) {
	if (isNotEmpty(form.nom)) {
		if (isNotEmpty(form.prenom)) {
			if (isNotEmpty(form.eMail)) {
                if (isEMailAddr(form.eMail)) {
                    if (isNumber(form.dateNaissance)) {
						if (isLen8(form.dateNaissance)) {
							return true;
						}
					}
				}
			}
		}
	}
	return false;
}

function verif_form_colloque()
{
	var titre = document.inscription.titre.value;
	var nom = document.inscription.nom.value;
	var prenom = document.inscription.prenom.value;
	var fonction = document.inscription.fonction.value;
	var societe = document.inscription.societe.value;
	var tel = document.inscription.tel.value;
	var email = document.inscription.email.value;
	var adresse_pers = document.inscription.rue_pers.value;
	var adresse_pro = document.inscription.rue_pro.value;
	var categorie = document.inscription.categorie.value;
	if(categorie == '0') alert("Vous devez choisir une categorie de tarif");
	if(verif_champs(titre,nom,prenom,fonction,societe,tel,email,adresse_pers,adresse_pro) && categorie != '0') return true;
	else return false;
}

function uncheck(form,qui)
{
	eval("document."+form+"."+qui+".checked=false");
}

function my_submit(action,qui,page)
{
	location.href=page+"?action="+action+"&id="+qui;
}

function changeCouleur(qui,couleur)
{
	qui.bgColor = couleur;
}
//--------------------------------------------------------
// Fonctions mise en forme de phpbb ver 2.0.8
//					www.phpbb.com
//--------------------------------------------------------

// Startup variables
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);

// Helpline messages
b_help = "Texte gras: [b]texte[/b] (alt+b)";
i_help = "Texte italique: [i]texte[/i] (alt+i)";
u_help = "Texte soulign?: [u]texte[/u] (alt+u)";
q_help = "Citation: [quote]texte cit?[/quote] (alt+q)";
c_help = "Afficher du code: [code]code[/code] (alt+c)";
l_help = "Liste: [list]texte[/list] (alt+l)";
o_help = "Liste ordonn?e: [list=]texte[/list] (alt+o)";
p_help = "Ins?rer une image: [img]http://image_url/[/img] (alt+p)";
w_help = "Ins?rer un lien: [url]http://url/[/url] ou [url=http://url/]Nom[/url] (alt+w)";
a_help = "Fermer toutes les balises BBCode ouvertes";
s_help = "Couleur du texte: [color=red]texte[/color] Astuce: #FF0000 fonctionne aussi";
f_help = "Taille du texte: [size=x-small]texte en petit[/size]";

// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('[g]','[/g]','[i]','[/i]','[s]','[/s]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]');
imageTag = false;

// Shows the help messages in the helpline window
function helpline(help) {
	document.ma_news.helpbox.value = eval(help + "_help");
}


// 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 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();
}

the_txt ="";
function recup(qui){
	the_txt =qui;
}

function bbstyle(bbnumber) {
	//recup du texte du message
	var txtarea = eval('document.ma_news.'+the_txt);

	txtarea.focus();
	donotinsert = false;
	theSelection = false;
	bblast = 0;

	//recup du code de mise en forme et test (gras, etc..)
	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);
}
//Fonction
	function generate(nomChps)
	{
		// Si deja genere, on vide
		if(document.getElementById(nomChps).value != "") document.getElementById(nomChps).value = "";
		var letters = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9");
		var buf = "";
		for(t = 0; t < 10; t++)
		{
			alea = parseInt(Math.random()*59);
			buf+= letters[alea];
		}
		document.getElementById(nomChps).value = buf;
	}

// Fonction de confirmation de suppression
function confirmSuppr(lienPageSuppr) {
	var result = confirm("Etes-vous certain de vouloir supprimer cet enregistrement ?");
	if(result) document.location.href = lienPageSuppr;
}
