/*
	=============================
	Equivalents de fonctions PHP 
	=============================
*/
function is_array( mixed_var ) 
{
    return ( mixed_var instanceof Array );
}
function str_replace(search, replace, subject) 
{
    var f = search, r = replace, s = subject;
    var ra = is_array(r), sa = is_array(s), f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while(j = 0, i--){
        while(s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f);
    }
     
    return sa ? s : s[0];
}

function trim( str, charlist ) 
{
    // *     example 1: trim('    Kevin van Zonneveld    ');
    // *     returns 1: 'Kevin van Zonneveld'
    // *     example 2: trim('Hello World', 'Hdle');
    // *     returns 2: 'o Wor'
    // *     example 3: trim(16, 1);
    // *     returns 3: 6
 
    var whitespace, l = 0, i = 0;
    str += '';
    charlist += '';
    
    if (!charlist) {
        whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
    } else {
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
    }
    
    l = str.length;
    for (i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(i);
            break;
        }
    }
    
    l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    
    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}

/*
	================================
	FIN Equivalents de fonctions PHP 
	================================
*/
function tradPub(txt,div)
{
	// Traduction via l'API de Google du titre
	google.language.translate(txt, "fr", "en", function(result) 
	{
        if (!result.error) 
        {
         	$(div).update(result.translation);
        }
	});
}

/* ---------------------- */
/* --- MENU DEROULANT --- */
/* ---------------------- */
var etat = 'open';
var element = '';

function menu(element)
{
	var ul = document.getElementById(element).getElementsByTagName("ul");
	var img = document.getElementById(element).getElementsByTagName("img");
	var val = document.getElementById(element).value;
	
	if(ul.length > 0)
	{
		for (var i=0; i<ul.length; i++)
		{
			if(ul[0].style.display == 'none')
			{
				ul[i].style.display = 'block';
				for (var nbrI=0; nbrI<img.length; nbrI++)
				{
					img[nbrI].style.display = 'block';
				}
				
				/*if(element == 'actualite')
					$(element+'A').className = 'btn2_over';
				else
					$(element+'A').className = 'btn_over';*/
			}
			else
			{
				ul[i].style.display = 'none';
				for (var nbrI=0; nbrI<img.length; nbrI++)
				{
					img[nbrI].style.display = 'none';
				}
				
				/*if(element == 'actualite')
					document.getElementById(element+'A').className = 'bouton3';
				else
					document.getElementById(element+'A').className = 'bouton';*/
			}
		}
	}
}

/* -------------------------------------------- */
/* --- GESTION DES SELECTS LIES AUX UNIVERS --- */
/* -------------------------------------------- */
function callChild(id,level,destruct)
{
	if(id != '')
	{
		new Ajax.Request('ajax.php',
		{
			method: 'post',
			parameters: 'id='+id+'&level='+level+'&destruct='+destruct,
			onSuccess: function(ajax)
			{
				$('divClass').replace(ajax.responseText);
			}
		});
	}
}

function afficheForm(pass)
{
	if(pass == 1)
	{
		document.getElementById('Toutlebloc').style.display = 'block';
		document.getElementById('divDetail').style.display = 'block';
	}
	else
	{
		document.getElementById('Toutlebloc').style.display = 'none';
		document.getElementById('divDetail').style.display = 'none';
	}
}

/* ---------------------------------------------------------- */
/* --- GESTION DU FORMULAIRE EN FONCTION DE LA CATEGORIE --- */
/* ---------------------------------------------------------- */
function callForm(catForm)
{
	// Dans le cas om l'on choisi la sous-catégorie "autre"
	if(catForm == "773")
	{
		oldCatForm = catForm;
		catForm = $('parentN3').value;
		idrubrique = catForm;
	}
	else
	{
		oldCatForm = catForm;
		idrubrique = catForm;
	}
	
	// Formulaire dynamique
	new Ajax.Request('ajax.php',
	{
		method: 'post',
		parameters: 'catForm='+catForm+'&action=divDetail',
		onSuccess: function(ajax)
		{
			$('divDetail').update(ajax.responseText);
		}
	});
	
	// Dans le cas om l'on choisi la sous-catégorie "autre"
	if(oldCatForm == "773") $('sousCategAutre').style.display = "block";
	else $('sousCategAutre').style.display = "none";
	
	// Description Française
	new Ajax.Request('ajax.php',
	{
		method: 'post',
		parameters: 'catForm='+catForm+'&action=divDesc',
		onSuccess: function(ajax)
		{
			$('divDesc').update(ajax.responseText);
		}
	});
	
	// Photo
	new Ajax.Request('ajax.php',
	{
		method: 'post',
		parameters: 'catForm='+catForm+'&action=photo',
		onSuccess: function(ajax)
		{
			$('photo').update(ajax.responseText);
		}
	});
	
	// Video
	new Ajax.Request('ajax.php',
	{
		method: 'post',
		parameters: 'catForm='+catForm+'&action=video',
		onSuccess: function(ajax)
		{
			$('divVideo').update(ajax.responseText);
		}
	});
	
	// Coordonnées perso
	new Ajax.Request('ajax.php',
	{
		method: 'post',
		parameters: 'catForm='+catForm+'&action=coordperso',
		onSuccess: function(ajax)
		{
			$('divCoordPerso').update(ajax.responseText);
		}
	});
	
	// Coordonnées société
	new Ajax.Request('ajax.php',
	{
		method: 'post',
		parameters: 'catForm='+catForm+'&action=coordsociete',
		onSuccess: function(ajax)
		{
			$('divCoordSociete').update(ajax.responseText);
		}
	});
	
	$('annonceForm').onsubmit = checkForm;
}

/* --------------------------------------------------- */
/* --- GESTION DE LA TRADUCTION DANS LE FORMULAIRE --- */
/* --------------------------------------------------- */
function callTraduction(type,lang)
{
	var lang = $("langFront").value;
	
	// Traduction automatique
	if(type =="auto")
	{
		var titleTrad = document.getElementById('titre').value;
		
		if(lang == "fr")
		{
			var lang1 = "fr";
			var lang2 = "en";
			var langG1 = "fr";
			var langG2 = "en";
		}
		else
		{
			var lang1 = "en";
			var lang2 = "fr";
			var langG1 = "fr";
			var langG2 = "en";
		}
		
		if(titleTrad != '')
		{
			// On lance l'ajax pour aller chercher l'affichage des autres champs du formulaire dynamique
			new Ajax.Request('ajax.php',
			{
				method: 'post',
				parameters: 'idrubrique='+idrubrique+'&TypeTraduction='+type,
				onSuccess: function(ajax)
				{
					$('traduc').update(ajax.responseText);
				}
			});
			
			// Affichage du block titre en anglais
			$('PubliTitreEn').style.display = "block";
			$('titreEn').style.display = "block";
			
			// Traduction via l'API de Google du titre
			google.language.translate(titleTrad, lang2, lang1, function(result) 
			{
		        if (!result.error) 
		        {
		          $('PubliTitreEn').value = result.translation;
		        }
			});
		}
		else 
		{
			if(lang == "EN") alert("Please enter a title in the ad.");
			else alert("Veuillez rentrer un titre à l'annonce.");
		}
	}
	
	// Pas de traduction
	if(type =="no")
	{
		// Titre en Anglais
		$('PubliTitreEn').style.display = "none";
		$('titreEn').style.display = "none";
		
		// On efface tous les champs formulaires qui ont été dupliqués en Anglais	
		new Ajax.Request('ajax.php',
		{
			method: 'post',
			parameters: 'suppTrad=on&idrubrique='+idrubrique+'&TypeTraduction='+type,
			onSuccess: function(ajax)
			{
				$('traduc').update(ajax.responseText);
			}
		});
	}
	
	// Traduction manuelle
	if(type =="manuel")
	{
		var titleTrad = $('titre').value;
		
		new Ajax.Request('ajax.php',
		{
			method: 'post',
			parameters: 'suppTrad=on&idrubrique='+idrubrique+'&TypeTraduction='+type,
			onSuccess: function(ajax)
			{
				$('traduc').update(ajax.responseText);
			}
		});
		
		// Titre en Anglais
		$('PubliTitreEn').style.display = "block";
		$('titreEn').style.display = "inline";
	}
}


/* ----------------------------------------------- */
/* ----- GESTION DE LA TRADUCTION DES CHAMPS ----- */
/* ----------------------------------------------- */
function callTraductionChamp(type,div,divValue,template,lang)
{
	if(type =="auto")
	{
		if(lang == "fr")
		{
			var lang1 = "fr";
			var lang2 = "en";
			var langG1 = "fr";
			var langG2 = "en";
		}
		else
		{
			var lang1 = "fr";
			var lang2 = "en";
			var langG1 = "en";
			var langG2 = "fr";
		}
		
		var inputValue = $(divValue).value;
		var champInput = str_replace("[" + lang1 + "]","[" + lang2 + "]",divValue);
		
		if(trim(inputValue) != '')
		{
			var maTraduction;
			
			$(div).style.display = 'block';
			
			// Si la chaine envoyer est numérique
			if(!isNaN( inputValue ))
			{
				// Mise à jour de la valeur
				$(champInput).value = inputValue;
			}
			else
			{
				// Traduction via l'API de Google de l'élément
				google.language.translate(inputValue, langG1, langG2, function(result) 
				{
			        if (!result.error) maTraduction = result.translation;
			        else maTraduction = "Le service de traduction est indisponible actuellement.";
					
			        // Mise à jour de la valeur
					$(champInput).value = maTraduction;
						
				});
			}
		}
	}
	if(type =="no")
	{
		if(div != "reponse12[en]" && div != "reponse14[en]") $(div).style.display = 'none';
	}
	if(type =="manuel") $(div).style.display = 'block';

}

function callTraductionSelect(div,divValue,lang,arg,id)
{
	if($('traducAuto').checked == true)
	{
		if(lang == "fr")
		{
			var lang1 = "fr";
			var lang2 = "en";
		}
		else
		{
			var lang1 = "en";
			var lang2 = "fr";
		}
		if(arg == 'false') var inputValue = divValue;
		else
		{
			var inputValue = $(divValue).value;
		}
		if(lang == 'fr') var champInput = str_replace("[" + lang1 + "]","[" + lang2 + "]",div);
		else var champInput = div;
		
		if(inputValue != '')
		{
			$(champInput).style.display = 'block';
			new Ajax.Request('ajax.php',
			{
				method: 'post',
				parameters: 'id='+id+'&txt='+inputValue+'&tradSelect=ok',
				onSuccess: function(ajax)
				{
					// Mise à jour de la valeur
					$(champInput).value = ajax.responseText;
				}
			});
		}
	}
}

/* -------------------------- */
/* --- GESTION DES PHOTOS --- */
/* -------------------------- */
function callPhoto()
{
	var i;
	var j;
	var k;
	for(i=1;i<4;i++)
	{
		j = i + 1;
		if(document.getElementById('divPhoto' + i).style.display == 'block' && document.getElementById('divPhoto' + j).style.display == 'none')
		{
			
			document.getElementById('divPhoto' + j).style.display = 'block';
			if(j == 4) document.getElementById('ajoutPhoto').style.display = 'none';
			break;
		}
	}
}

/* -------------------------- */
/* --- AFFICHAGE DES PHOTOS - */
/* -------------------------- */

function affichPhoto(page,photo,id,type)
{
	new Ajax.Request('ajax.php',
	{
		method: 'post',
		parameters: 'page='+page+'&photo='+photo+'&id='+id+'&type='+type+'&affichPhoto=ok',
		onSuccess: function(ajax)
		{
			$('diapo_photos').replace(ajax.responseText);
		}
	});
}

function affichZoom(url)
{
	document.documentElement.style.overflow = 'hidden';
	$('cache').style.display = 'block';
	$('popup').style.display = 'block';
	$('popup').style.backgroundImage = "url('"+url+"')";
	//document.getElementById('popup').style = "background: url('"+url+"') center center no-repeat";
}

function suppZoom()
{
	document.documentElement.style.overflow = 'visible';
	$('cache').style.display = 'none';
	$('popup').style.display = 'none';
}

/*Fonctions concernant l'ajaxbox*/
function ajaxbox_init()
{
	box = new Ajaxbox();
	box.overlay.onclick = function() { box.hide(); }
}

// Affichage de l'image
function ajaxbox_show_image(url, w, h)
{
	box.show();
	box.update('<img id="ajaxbox-image" src="'+url+'" width="'+w+'" height="'+h+'" onclick="box.hide();" onload="this.style.visibility = \'visible\'" />');
	return false;
}

// Affichage de la vidéo
function ajaxbox_show_video(url)
{
	box.show();

	new Ajax.Request('/ajax-video.php',
	{
		method: 'post',
		parameters: 'url='+url,
		onSuccess: function(ajax)
		{
			box.update(ajax.responseText);
		}
	});
	
	/*var swf = new SWFObject(url, "ajaxbox-video", "425", "355", "8", "#ffffff");
	swf.addParam("menu", "false");
	//swf.addParam("wmode", "transparent");
	swf.write("ajaxbox");
	
	box.update();*/
}

// Fermeture de la box
function ajaxbox_hide()
{
	box.hide();
}
/*Fin des Fonctions concernant l'ajaxbox*/


//Affichage de la Video en popup
function affichVideo()
{
	document.documentElement.style.overflow = 'hidden';
	$('cache').style.display = 'block';
	$('video').style.display = 'block';
	//document.getElementById('popup').style = "background: url('"+url+"') center center no-repeat";
}

//Supprimer la popup video
function suppVideo()
{
	document.documentElement.style.overflow = 'visible';
	$('cache').style.display = 'none';
	$('video').style.display = 'none';
}

//Vérifie les champs du formulaire
function checkForm()
{
	var lang = $("langFront").value;
	var field = $(this).elements;
	var check = true;
	var checkcgv = false;

	for (var i=0; i<field.length; i++)
	{
		if(
			$(field[i]).name != 'photo0' && 
			$(field[i]).name != 'photo1' && 
			$(field[i]).name != 'photo2' && 
			$(field[i]).name != 'doc1' && 
			$(field[i]).name != 'doc2' && 
			$(field[i]).name != 'doc3' && 
			$(field[i]).name != 'doc4' && 
			$(field[i]).name != 'PubliPhoto1' && 
			$(field[i]).name != 'PubliPhoto2' && 
			$(field[i]).name != 'PubliPhoto3' && 
			$(field[i]).name != 'PubliPhoto4' && 
			$(field[i]).name != 'PubliPhoto5')
		{
			var item = $(field[i]);
			item.value = trim(item.value);
	
			if (item.hasClassName('required') && (item.value == '' || item.value == '0'))
			{
				item.addClassName('error');
				check = false;
			}
			else item.removeClassName('error');
		}
		
		if($(field[i]).name == 'forfait')
		{
			var item = $(field[i]);
			item.value = trim(item.value);
	
			if (item.hasClassName('required') && item.checked == true)
			{
				check = true;
			}
		}
	}
	
	if(check == false)
	{
		if(lang == "EN") alert("Please complete all fields marked with a *");
		else alert("Veuillez renseigner les champs marqué d'une *");
			
		return check;
	}
	else	
	{
		//On verifie que les cgv ont été acceptées
		checkcgv = CheckCgv();
		if(checkcgv == true) validate();
		return checkcgv;
	}
}

//Trim les champs
function trim(str)
{
	return str.replace(/^\s+|\s+$/g, '');
}

//Supprime Publication,cv,annuaire et circuit
function SupprimPub(id,type)
{
	if(confirm("Etes vous sur de vouloir supprimer la fiche "+type+" n°"+id))
	{
		new Ajax.Request('/ajax.php',
		{
			method: 'post',
			parameters: 'idsupp='+id+'&type='+type+'&SupprimPub=ok',
			onSuccess: function(ajax)
			{
				if(ajax.responseText)
				{
					alert("La fiche "+type+" n°"+id+" n'a pas été supprimé");
					return false;
				}
				else
				{	
					//alert("Votre fiche "+type+" n°"+id+" a été correctement supprimée");
					document.location.replace("/publication.php");
				}
			}
		});
	}
}

function envoimail(id,type)
{
	 var email = prompt("Entrez l'adresse mail de votre ami","");
	 if(email != "")
	 new Ajax.Request('/ajax.php',
		{
			method: 'post',
			parameters: 'email='+email+'&id='+id+'&type='+type+'&EnvoiMail=ok',
			onSuccess: function(ajax)
			{
				if(ajax.responseText == 'ok')
				{
					alert("Votre mail à été envoyé");
					return false;
				}
				else alert("Le mail n'a pas été envoyé");
			}
		});
}


//Affichage d'un bloc div
function affichDiv(div,nb,type,autre)
{
	new Ajax.Request('ajax.php',
	{
		method: 'post',
		parameters: 'div='+div+'&nb='+nb+'&type='+type+'&autre='+autre+'&affichDiv=ok'+$('cvForm').serialize(),
		onSuccess: function(ajax)
		{
			$(div).replace(ajax.responseText);
		}
	});
}

// Box pour les cv
// Option : palmares / partenaire / vehicule / photo
// Mode : si l'on est en mode création ou modification (crea / modif)
// Id : identifiant du CV modifié
// IdSpe : identifiant propre à l'option choisie
function ajaxbox_show_cv(option,mode,idSpe)
{
	box.show();
	
	id = $('idCVOld').value;
	
	// Si on en est à l'étape de création, on met un ID tmp
	if(id == "")
	{
		id = -(Math.floor(Math.random() * 10000));
		$('idCVOld').value = id;
	}
	
	typeCV = $('typeCV').value;
	
	// On va chercher les informations à afficher via un objet Ajax Request
	new Ajax.Request('ajax-cv.php',
	{
		method: 'post',
		parameters: 'option='+option+'&mode='+mode+'&id='+id+'&idSpe='+idSpe+'&action=aff&typeCV='+typeCV,
		onSuccess: function(ajax)
		{
			box.update(ajax.responseText);
			initUpload('/ajax-cv.php','pr1');
		}
	});
}

// Traitement CV
function submitFormCV(idp)
{
	// Traitement des données via un objet Ajax Request
	new Ajax.Request('ajax-cv.php',
	{
		method: 'post',
		parameters: 'action=trait&'+$('formCV').serialize(),
		onSuccess: function(ajax)
		{
			var idSpeVar = ajax.responseText;
			var optionBis = $('option').value;
			var idBis = $("id").value;
			var typeCVVar = $("typeCV").value
			
			// Récupère le titre
			if(optionBis == "photo" || optionBis == "partenaire")
			{
				titrePhotoVar = $("autreTitre").value;
			}
			else  titrePhotoVar = 'null';
			
			// Récupère le lien
			if(optionBis == "partenaire") lienPhotoVar = $("autreLien").value;
			else  lienPhotoVar = 'null';
			
			// Upload de la photo
			if(optionBis != "pilote")
			{
				if( idp != '' || idp != undefined )
				{
					var instance = swfu[idp];
					if( instance.getStats().files_queued >= 1 )
					{
						instance.setPostParams({
							id: idBis,
							idSpe: idSpeVar,
							titrePhoto: titrePhotoVar,
							lienPhoto: lienPhotoVar,
							option: optionBis,
							typeCV: typeCVVar,
							mode: $('mode').value,
							action: 'upload'
						});
						
						instance.uploadProgress = function()
						{
							$(instance.customSettings.uploadbtn).value = "Uploading...";
						}
						instance.uploadComplete = function()
						{
							alert("L'image a bien été sauvegardé.");
							majCV(optionBis,idBis);
							box.hide();
							
						}
						instance.startUpload(upload);
					}
					else
					{
						// Mise à jour da la div palmares
						majCV($('option').value,$("id").value);
						
						// Fermeture de la box
						box.hide();
					}
				}
				else
				{
					// Mise à jour da la div palmares
					majCV($('option').value,$("id").value);
					
					// Fermeture de la box
					box.hide();
				}
			}
			else
			{
				// Mise à jour da la div palmares
				majCV($('option').value,$("id").value);
				
				// Fermeture de la box
				box.hide();
			}
			
			
		}
	});
	
	//majCV($('option').value,$("id").value);
}

// Mise à jour des div
// Option : palmares / partenaire / vehicule / photo
// Id : identifiant du CV modifié
function majCV(option,id)
{
	var div;
	typeCV = $('typeCV').value;
	
	// Definition de la div à mettre à jour
	if(option == "palmares") div = 'divPalmares';
	if(option == "photo") div = 'divPhoto';
	if(option == "partenaire") div = 'divPartenaire';
	if(option == "vehicule") div = 'divVehicule';
	if(option == "pilote") div = 'divPiloteCV';
	
	// On va chercher les informations à afficher via un objet Ajax Request
	new Ajax.Request('ajax-cv.php',
	{
		method: 'post',
		parameters: 'option='+option+'&id='+id+'&action=maj&typeCV='+typeCV,
		onSuccess: function(ajax)
		{
			$(div).update(ajax.responseText);
		}
	});
}

// Mise à jour de l'ordre
// Option : palmares / partenaire / vehicule / photo
// Id : identifiant du CV modifié
// IdSpe : identifiant propre à l'option choisie
// Etat : monter ou descendre
function ordreCV(option,id,idSpe,etat)
{
	// On va chercher les informations à afficher via un objet Ajax Request
	new Ajax.Request('ajax-cv.php',
	{
		method: 'post',
		parameters: 'option='+option+'&id='+id+'&idSpe='+idSpe+'&etat='+etat+'&action=order',
		onSuccess: function(ajax)
		{
			majCV(option,id);
		}
	});
}

// Supression d'un modules
function suppCV(option,id,idSpe)
{
	var messageSupp = "null";
	
	new Ajax.Request('ajax-cv.php',
	{
		method: 'post',
		parameters: 'action=suppMess',
		onSuccess: function(ajax)
		{
			messageSupp = ajax.responseText;
			if(confirm(messageSupp + ' ?'))
			{
			
				// On va chercher les informations à afficher via un objet Ajax Request
				new Ajax.Request('ajax-cv.php',
				{
					method: 'post',
					parameters: 'option='+option+'&id='+id+'&idSpe='+idSpe+'&action=supp',
					onSuccess: function(ajax)
					{
						alert('L\'élément a bien été supprimé.');
						majCV(option,id);
					}
				});
			}
		}
	});
}

// Initialisation des modules palmares / partenaire / vehicule / photo
function initCV(id)
{
	majCV('palmares',id);
	majCV('photo',id);
	majCV('partenaire',id);
	majCV('vehicule',id);
	majCV('pilote',id);
}

// Initialisation des modules palmares / partenaire / vehicule / photo
function initCircuit(id)
{
	//majCV('palmares',id);
	majCV('photo',id);
	majCV('partenaire',id);
	majCV('pilote',id);
}

function voirImgCV(type)
{
	if(type == 'off') $('loupeImg').style.display = "none";
	else $('loupeImg').style.display = "block";
}

function changePalmares(type)
{
	if(type == 'Course') $('palmares[course]').value = "Classement qualification : X\nClassement final : X";
	else $('palmares[course]').value = "Classement général X\nX course X victoire X podiums X pôles X MT";
}



function callTraductionBis(type,lang,idrubrique)
{
	var lang = $("langFront").value;
	
	// Traduction automatique
	if(type =="auto")
	{
		var titleTrad = document.getElementById('titre').value;
		
		if(lang == "fr")
		{
			var lang1 = "fr";
			var lang2 = "en";
			var langG1 = "en";
			var langG2 = "fr";
		}
		else
		{
			var lang1 = "en";
			var lang2 = "fr";
			var langG1 = "fr";
			var langG2 = "en";
		}
		
		if(titleTrad != '')
		{
			// On lance l'ajax pour aller chercher l'affichage des autres champs du formulaire dynamique
			new Ajax.Request('ajax.php',
			{
				method: 'post',
				parameters: 'idrubrique='+idrubrique+'&TypeTraduction='+type,
				onSuccess: function(ajax)
				{
					$('traduc').update(ajax.responseText);
				}
			});
			
			// Affichage du block titre en anglais
			$('PubliTitreEn').style.display = "block";
			$('titreEn').style.display = "block";
			
			// Traduction via l'API de Google du titre
			google.language.translate(titleTrad, langG1, langG2, function(result) 
			{
		        if (!result.error) 
		        {
					$('PubliTitreEn').value = result.translation;
		        }
			});
		}
		else 
		{
			if(lang == "EN") alert("Please enter a title in the ad.");
			else alert("Veuillez rentrer un titre à l'annonce.");
		}
	}
	
	// Pas de traduction
	if(type =="no")
	{
		// Titre en Anglais
		$('PubliTitreEn').style.display = "none";
		$('titreEn').style.display = "none";
		
		// On efface tous les champs formulaires qui ont été dupliqués en Anglais	
		new Ajax.Request('ajax.php',
		{
			method: 'post',
			parameters: 'suppTrad=on&idrubrique='+idrubrique+'&TypeTraduction='+type,
			onSuccess: function(ajax)
			{
				$('traduc').update(ajax.responseText);
			}
		});
	}
	
	// Traduction manuelle
	if(type =="manuel")
	{
		var titleTrad = $('titre').value;
		
		new Ajax.Request('ajax.php',
		{
			method: 'post',
			parameters: 'suppTrad=on&idrubrique='+idrubrique+'&TypeTraduction='+type,
			onSuccess: function(ajax)
			{
				$('traduc').update(ajax.responseText);
			}
		});
		
		// Titre en Anglais
		$('PubliTitreEn').style.display = "block";
		$('titreEn').style.display = "inline";
	}
}

function suppressionCompte(idclient,message)
{
	if(confirm(message))
	{
		new Ajax.Request('ajax.php',
		{
			method: 'post',
			parameters: 'suppCompte=ok&idclient='+idclient,
			onSuccess: function(ajax)
			{
				document.location.replace("/inscription.php?suppr=ok");
			}
		});
	}
}

/* ---------------------------------------------- */
/* --- GESTION DES SELECTS LIES AUX ANNUAIRES --- */
/* ---------------------------------------------- */

function selectCat(id)
{
	new Ajax.Request('ajax-annuaire.php',
	{
		method: 'post',
		parameters: 'actionAnn=cat&id='+id,
		onSuccess: function(ajax)
		{
			$('catSel').update(ajax.responseText);
		}
	});
}

function selectSousCat(id)
{
	new Ajax.Request('ajax-annuaire.php',
	{
		method: 'post',
		parameters: 'actionAnn=souscat&id='+id,
		onSuccess: function(ajax)
		{
			$('souscatSel').update(ajax.responseText);
		}
	});
}

function affPartCV(type,total)
{
	var numPart = parseInt($('numPart').value);
	var total = parseInt(total);
	
	numPartPrec = numPart - 1;
	numPartSuiv = numPart + 1;
	
	if(numPartSuiv == (total + 1)) numPartSuiv = 1;
	if(numPartPrec == 0) numPartPrec = total;
	
	if(type == 'suiv') num = numPartSuiv;
	else num = numPartPrec;
	
	$('numPart').value = num;
	
	for(i=1;i<=total;i++)
	{
		$('imgPart' + i).style.display = 'none';
	}
	$('imgPart' + num).style.display = 'block';
}

function DefilePhotoCV(totalPart)
{
	affPartCV('suiv',totalPart);
	setTimeout("DefilePhotoCV("+totalPart+")",3000);
}


function CheckCgv()
{
	var lang = $("langFront").value;
	
	if ($('cgv').checked == '')
	{
		if(lang == "EN") alert("Please checked the sell general condition");
		else alert("Veuillez accepter les conditions générales de vente");
			
		return false;
	}
	else return true;
}

function seeN3 (id)
{
	if($(id).style.display == 'block') $(id).style.display = 'none';
	else $(id).style.display = 'block';
}
function miseazero (lang)
{
	if(lang=='EN')
	{
		if($('inputRecherche').value == 'Type your request here') $('inputRecherche').value = '';
	}
	else
	{
		if($('inputRecherche').value == 'Tapez votre recherche ici') $('inputRecherche').value = '';
	}
}

function validate()
{
	box.show();
	box.update('<img src=\"./images/loading2.gif\" alt=\"\" />');
}

function openBlock()
{
	var blockTwo = $('blockTwo').style.display;
	
	if(blockTwo == 'block')
	{
		$('blockTwo').style.display = 'none';
		$('blockOne').style.backgroundImage = "url(/images/puce_flechOrange4.gif)";
	}
	else
	{
		$('blockTwo').style.display = 'block';
		$('blockOne').style.backgroundImage = "url(/images/puce_flechOrange3.gif)";
	}
}