var idEncartAffiche = '';

function getEvenements(target, start){
	switch(target){
		case 'today':
			var cible = 'getListToday.php';
			break;
		
		case 'tomorow':
			var cible = 'getListTomorow.php';
			break;
		
		default:
			var cible = 'getListMonth.php';
	}
	
	new Ajax.Updater(
					 	'evenements',
						'/ajax/evenements/'+cible,
						{
							method:'post',
							parameters:'start='+start
						}
					);
}

/*
function thisMovie(movieName) {
   if (window.document[movieName])
      {
          return window.document[movieName];
      }
      if (navigator.appName.indexOf("Microsoft Internet")==-1)
      {
        if (document.embeds && document.embeds[movieName])
          return document.embeds[movieName];
      }
      else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
      {
        return document.getElementById(movieName);
      }
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
*/
 function thisMovie(movieName) {
	if (window.document[movieName]){
		return window.document.getElementById(movieName);
    }
	
    if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
    }
    else {
	    return document[movieName];
    }
} 


function afficherFormAjoutCommentaireBillet(){
	$('form_ajout_commentaire_billet').style.display = 'block';
}


function valid_form_recherche(){
	if($('champ_rechercher').value!=''){
		window.location = 'http://www.cap24.com/search.php?search=' + $('champ_rechercher').value;
	}
}

function taguer_cette_page(){
	alert("ce bouton fait appel a la fonction javascript 'taguer_cette_page' contenu dans 'scripts.js'");
}

function hoverEncartStreaming(id,categ,emission){
		
	outEncartStreaming();
	
	idEncartAffiche = id;
	
	new Ajax.Request(
					'ajax/getContenuInfobulle.php',
					{
						method:'post',
						parameters:'idEncart='+id+'&categorie='+categ+'&emission='+emission,
						onComplete:remplirInfobulle
					}
				);
	
}

function remplirInfobulle(requete){
	$('contenuInfobulle'+idEncartAffiche).innerHTML = requete.responseText;
	$('contenuInfobulleIE'+idEncartAffiche).innerHTML = requete.responseText;
	$('infobulle_encart'+idEncartAffiche).style.display = 'block';
	$('contenuInfobulleIE'+idEncartAffiche).style.display = 'block';
}

function outEncartStreaming(){
	
	idEncartAffiche = '';
	
	$('infobulle_encart1').style.display = 'none';
	$('infobulle_encart2').style.display = 'none';
	$('infobulle_encart3').style.display = 'none';
	$('infobulle_encart4').style.display = 'none';
	
	$('contenuInfobulleIE1').style.display = 'none';
	$('contenuInfobulleIE2').style.display = 'none';
	$('contenuInfobulleIE3').style.display = 'none';
	$('contenuInfobulleIE4').style.display = 'none';
}

function afficheLiveGrand(){
	fermerStreaming();
	var top=(screen.height-480)/2;
	var left=(screen.width-640)/2;
	window.open('streaming.php','','top='+top+',left='+left+',width=640,height=480,menubar=no,scrollbars=no,statusbar=no,resizable=no');
}

function afficherCGU(){
	var top=(screen.height-480)/2;
	var left=(screen.width-640)/2;
	window.open('cgu.html','','top='+top+',left='+left+',width=640,height=480,menubar=no,scrollbars=yes,statusbar=no,resizable=no');
}

function envoiMessageChat(){
	
	alert("ce bouton fait appel a la fonction javascript 'envoiMessageChat' contenu dans 'scripts.js' et renvoi le contenu du champ de saisie pour les messages du chat...");
	alert(document.getElementById('champEnvoiChat').value);
}

function rechercheAvancee(){
	document.form_recherche_avancee.submit();
}

function rechercheAvancee2(){
	if($('recherche_caroussel').value!=''){
		document.form_caroussel.submit();
	}
}

function afficheEvenements(type,page){
	alert("ce bouton fait appel a la fonction javascript 'afficheEvenements' contenu dans 'scripts.js' lorsque il est cliqué et envoi la variable 'type' : "+type+", ainsi que le numéro de page : "+page);
}

function startStreaming(){
	
	new Ajax.Request(
					 	'ajax/getBrowser.php',
						{
							method:'post',
							parameters:'type=1',
							onComplete:doAfficherStreaming
						}
					);
}

function doAfficherStreaming(requete){
	$('leStreaming').innerHTML = requete.responseText;
	$('preStreaming').style.display = 'none';
	$('leStreaming').style.display = 'block';
}

function fermerStreaming(){
	$('leStreaming').innerHTML = '';
	$('preStreaming').style.display = 'block';
	$('leStreaming').style.display = 'none';
	var preStreaming = new SWFObject('/flash/preStreaming.swf', 'preStreaming', '368', '276', '8','#000000');
	preStreaming.addParam('wmode','transparent');
	preStreaming.write('preStreaming');
}

function connexionCompte2(){
		new Ajax.Request(
					 	'ajax/utilisateur/connexion.php',
						{
							method:'post',
							parameters:'identifiant='+$('identifiant').value+'&mdp='+$('mdp').value,
							onComplete:resConnexion2
						}
					);
}

function resConnexion2(requete){
	var docXML = requete.responseXML;
	
	if(docXML.getElementsByTagName('resultat')[0].firstChild.nodeValue == 'true'){
		var sURL = unescape(window.location.pathname);
		document.location.href = sURL;
	}
	else {
		$('erreurConnect').innerHTML = '<br>Votre identifiant ou votre mot de passe est incorrect.<br>Veuillez recommencer !';
	}
}


function connexionCompte(identifiant,mdp){
	new Ajax.Request(
					 	'http://www.cap24.com/ajax/utilisateur/connexion.php',
						{
							method:'post',
							parameters:'identifiant='+identifiant+'&mdp='+mdp,
							onComplete:resConnexion
						}
					);
}

function resConnexion(requete){
	var docXML = requete.responseXML;
	
	if(docXML.getElementsByTagName('resultat')[0].firstChild.nodeValue == 'true'){
		/*var sURL = unescape(window.location.pathname);
		document.location.href = sURL;*/
		window.location.reload(true);
	}
	else {
		erreurConnexion();
	}
}

function erreurConnexion(){
	thisMovie("theTopNav").erreurConnect();
}

function deconnexionMembre(){
	new Ajax.Request(
					 	'ajax/utilisateur/deconnexion.php',
						{
							method:'post',
							parameters:'mode=do',
							onComplete:deconnexionOk
						}
					);
}

function deconnexionOk(){
	window.location.reload(true);
}

function voirTousTags(){
	fermerStreaming();
	$('conteneur').style.overflow = 'hidden';
	$('fondTags').style.display = 'block';
	$('titreTags').style.display = 'block';
	$('tousTags').style.display = 'block';
	
	if (document.body){
		var haut = (document.body.clientHeight);
	}
	else {
		var haut = (window.innerHeight);
	}
	
	$('fermerTags').style.marginTop = Math.round(haut * 0.04) + 'px';
	$('conteneurTags').style.height = (Math.round(haut * 0.9) - 60) + 'px';
	
	new Ajax.Updater(
					 	'conteneurTags',
						'ajax/showAllTags.php'
					);
}


function fermerTousTags(){
	$('conteneur').style.overflow = 'auto';
	$('fondTags').style.display = 'none';
	$('titreTags').style.display = 'none';
	$('tousTags').style.display = 'none';
	startStreaming();
}

function redimensionnerContenu(){
	if (document.body){
		var haut = (document.body.clientHeight);
	}
	else {
		var haut = (window.innerHeight);
	}
	
	$('fermerTags').style.marginTop = Math.round(haut * 0.04) + 'px';
	$('conteneurTags').style.height = (Math.round(haut * 0.9) - 60) + 'px';
}

window.onresize = redimensionnerContenu;


function taguer(leType, lId){
	
	
	if($('champ_taguer').value!=''){
	
		new Ajax.Request(
							'ajax/taguer.php',
							{
								method:'post',
								parameters:'tag='+$('champ_taguer').value+'&type='+leType+'&id_edition='+lId,
								onComplete:taguerVideoOK
							}
						);
	}
}

function taguerVideoOK(requete){
	$('champ_taguer').value = '';
}



function addClickBanniere(id){
	new Ajax.Request(
					'ajax/addClickBanniere.php',
					{
						method:'post',
						parameters:'banniere='+id
					}
				);
}

function addVueBanniere(id){
	new Ajax.Request(
					'ajax/addVueBanniere.php',
					{
						method:'post',
						parameters:'banniere='+id
					}
				);
}


function afficheFormMdpPerdu(){
	$('formMdpPerdu').style.display = 'block';
}

function recevoirIdentifiants(){
	if($('mailMdpPerdu').value!=''){
		new Ajax.Request(
				'ajax/recevoirIdentifiants.php',
				{
					method:'post',
					parameters:'mail='+$('mailMdpPerdu').value,
					onComplete:doRecevoirIdentifiants
				}
			);
	}
	else {
		$('erreurConnect').style.display = 'block';
		$('erreurConnect').innerHTML = 'Veuillez idiquer votre e-mail.';
	}
}

function doRecevoirIdentifiants(){

	$('formMdpPerdu').style.display = 'none';
	$('erreurConnect').style.display = 'block';
	$('erreurConnect').innerHTML = 'Vos identifiants vous ont &eacute;t&eacute; envoy&eacute;s par e-mail.';
}

function stopError() {
	return true;
}

window.onerror=stopError; 