var Nav = navigator;
var Agent = ' ' + Nav.userAgent.toLowerCase();
var Version = Nav.appVersion;

var Netscape = Agent.indexOf('mozilla') > 0;
if (Agent.indexOf('compatible') > 0) Netscape = false;
var Explorer = Agent.indexOf('msie') > 0;
var VMajeure = parseInt( Version );
var VMineure = parseFloat( Version );

function GetCookie(NomCookie) {
  var dc = document.cookie;
  var prefix = NomCookie + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1)   {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else  begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function SetCookie(NomCookie, Valeur, options) {
	var expiration;
	if ("number" == typeof options) {
		expiration = new Date();
		expiration.setTime(expiration.getTime() + options*24*60*60*1000);
	} else {
		options = options||{};
		expiration = options.date?options.date:new Date();
		var offset = 0;
		if ("number" == typeof options.days) offset += options.days*24*60*60*1000;
		if ("number" == typeof options.hours)	offset += options.hours*60*60*1000;
		if ("number" == typeof options.minutes) offset += options.minutes*60*1000;
		if (offset) 	expiration.setTime(expiration.getTime() + offset);
		if (options.midnight) expiration.setHours(0, 0, 0, 0);
	}
	var Domaine = DomaineCookie();
	if (Domaine != "")	Domaine = "; domain=" + Domaine;
	document.cookie = NomCookie + "=" + escape(Valeur) + "; expires=" + expiration.toGMTString() + Domaine + "; path=/";
}

function SetCookieDure(NomCookie, Valeur, Dure) {
	if ("number" != typeof Dure)	Dure = 1;
	SetCookie(NomCookie, Valeur, {minutes:Dure});
}

function DomaineCookie() {
	var acDomains = ["fan-de-cinema"];
	var Domaine = window.location.hostname;
	var domaineIndex = -1;
	for (var i = 0; i<acDomains.length; i++)	domaineIndex = Math.max(domaineIndex, Domaine.indexOf(acDomains[i]));
	if ( (-1 == domaineIndex) && Netscape && 4 == VMajeure)	return "";
	else return "." + Domaine.substr(domaineIndex);
}

function rafraichir_cine() {
	document.execute.action="http://www.fan-de-cinema.com/sorties_cinema.html";
	document.execute.target="php";
	document.execute.submit();
}
function rafraichir_dvd() {
	document.execute.action="http://www.fan-de-cinema.com/sorties_dvd.html";
	document.execute.target="php";
	document.execute.submit();
}
function rafraichir_prog() {
	document.execute.action="http://flux.fan-de-cinema.com/cinemas/"+execute.salle.options[execute.salle.selectedIndex].value+".html";
	document.execute.target="php";
	document.execute.submit();
	if(document.all) document.all['pageHtml'].value='<'+'?php include("http://flux.fan-de-cinema.com/cinemas/'+execute.salle.options[execute.salle.selectedIndex].value+'.html");?'+'>';
	else if(document.getElementById) document.getElementById('pageHtml').value='<'+'?php include("http://flux.fan-de-cinema.com/cinemas/'+execute.salle.options[execute.salle.selectedIndex].value+'.html");?'+'>';
}
function salleSelect(listebox) {
	document.execute.action="http://flux.fan-de-cinema.com/cinemas/"+listebox.options[listebox.selectedIndex].value+".html";
	document.execute.target="php";
	document.execute.submit();
	if(document.all) document.all['pageHtml'].value='<'+'?php include("http://flux.fan-de-cinema.com/cinemas/'+listebox.options[listebox.selectedIndex].value+'.html");?'+'>';
	else if(document.getElementById) document.getElementById('pageHtml').value='<'+'?php include("http://flux.fan-de-cinema.com/cinemas/'+listebox.options[listebox.selectedIndex].value+'.html");?'+'>';
	
}
function villeSelect(listebox) {
	document.execute.action="";
	document.execute.target="_self";
	document.execute.submit();
}
function deptSelect(listebox) {
	document.execute.action="";
	document.execute.target="_self";
	document.execute.submit();
}
function selectChoix(num) {
	document.location.href="/services/php.html?choix="+num;
}

var timerID=0;
function affMax() {
    document.getElementById("affiche").style.display="inline";
    timerID = setInterval("hideMax()", 1000);
}
function hideMax() {
    clearInterval(timerID);
    document.getElementById("affiche").style.display="none";
}

function affStar() {
    document.getElementById("photoStar").style.display="inline";
    timerID = setInterval("hideStar()", 1000);
}
function hideStar() {
    clearInterval(timerID);
    document.getElementById("photoStar").style.display="none";
}


var tooltip = {
    id:"tooltip",
    offsetx : -50,
    offsety : 10,
    _x : 0,
    _y : 0,
    _tooltipElement:null,
    _saveonmouseover:null
}
tooltip.show = function (htmlelement,image) {
	if(document.getElementById){
        this._tooltipElement = document.getElementById(this.id);
	} else if ( document.all ) {
        this._tooltipElement = document.all[this.id].style;
	}

    this._saveonmouseover = document.onmousemove;
    document.onmousemove = this.mouseMove;

    this._tooltipElement.innerHTML = '<img src="'+image+'" />';

    this.moveTo(this._x + this.offsetx , this._y + this.offsety);

    if(this._tooltipElement.style){
        this._tooltipElement.style.visibility ="visible";
    }else{
        this._tooltipElement.visibility = "visible";
    }
    return false;
}
tooltip.hide = function (htmlelement) {
    if(this._tooltipElement.style) {
        this._tooltipElement.style.visibility ="hidden";
    } else {
        this._tooltipElement.visibility = "hidden";
    }
    document.onmousemove=this._saveonmouseover;
}
tooltip.mouseMove = function (e) {
    if (e == undefined)  e = event;
    if ( e.pageX != undefined) { // gecko, konqueror,
        tooltip._x = e.pageX;
        tooltip._y = e.pageY;
    } else if(event != undefined && event.x != undefined && event.clientX == undefined) { // ie4 ?
        tooltip._x = event.x;
        tooltip._y = event.y;
    } else if(e.clientX != undefined ) { // IE6,  IE7, IE5.5
        if(document.documentElement) {
            tooltip._x = e.clientX + ( document.documentElement.scrollLeft || document.body.scrollLeft);
            tooltip._y = e.clientY + ( document.documentElement.scrollTop || document.body.scrollTop);
        } else {
            tooltip._x = e.clientX + document.body.scrollLeft;
            tooltip._y = e.clientY + document.body.scrollTop;
        }
    } else {
        tooltip._x = 0;
        tooltip._y = 0;
    }
    tooltip.moveTo( tooltip._x +tooltip.offsetx , tooltip._y + tooltip.offsety);

}

tooltip.moveTo = function (xL,yL) {
    if(this._tooltipElement.style){
        this._tooltipElement.style.left = xL +"px";
        this._tooltipElement.style.top = yL +"px";
    } else {
        this._tooltipElement.left = xL;
        this._tooltipElement.top = yL;
    }
}

function sendMail() {
    if(document.getElementById){
        if(document.getElementById("request").innerHTML=="") {
            document.getElementById("request").innerHTML=sendMailForm;
        } else {
            document.getElementById("request").innerHTML="";
        }
    } else if ( document.all ) {
        if(document.all["request"].style.innerHTML=="") {
            document.all["request"].style.innerHTML=sendMailForm;
        } else {
            document.all["request"].style.innerHTML="";
        }
    }
}

function toolbarLoad() {
    if(document.getElementById){
        document.getElementById("tbright").innerHTML=toolbar;
    } else if ( document.all ) {
        document.all["tbright"].style.innerHTML=toolbar;
    }
}
function mbrbarLoad() {
    if(document.getElementById){
        document.getElementById("tbleft").innerHTML=mbrbar;
    } else if ( document.all ) {
        document.all["tbleft"].style.innerHTML=mbrbar;
    }
}

function proposer(q,u,f) {
    switch (q) {
        case "erreur": fenetre=window.open("http://membres.fan-de-cinema.com/signaler.php?u="+u+"&f="+f,"Perso","resizable=yes, hotkeys=no,  directories=no, location=no, menubar=no, toolbars=no, status=no, scrollbars=yes");break;
        case "video": fenetre=window.open("http://membres.fan-de-cinema.com/video.php?u="+u+"&f="+f,"Perso","resizable=yes, hotkeys=no,  directories=no, location=no, menubar=no, toolbars=no, status=no, scrollbars=yes");break;
        case "affiche": fenetre=window.open("http://membres.fan-de-cinema.com/affiche.php?u="+u+"&f="+f,"Perso","resizable=yes, hotkeys=no,  directories=no, location=no, menubar=no, toolbars=no, status=no, scrollbars=yes");break;
        case "wallpaper": fenetre=window.open("http://membres.fan-de-cinema.com/wallpaper.php?u="+u+"&f="+f,"Perso","resizable=yes, hotkeys=no,  directories=no, location=no, menubar=no, toolbars=no, status=no, scrollbars=yes");break;
        case "critique": fenetre=window.open("http://membres.fan-de-cinema.com/critique.php?u="+u+"&f="+f,"Perso","resizable=yes, hotkeys=no,  directories=no, location=no, menubar=no, toolbars=no, status=no, scrollbars=yes");break;
    }
	fenetre.focus();
}

function webmaster ()  {
    if(testContact()) document.contact.submit();
}

function testContact() {
  if (document.contact.Nom.value == "")
  {
    alert("Veuillez saisir votre nom!");
    document.contact.Nom.focus();
    return (false);
  }

  if (document.contact.Nom.value.length < 2)
  {
    alert("Veuillez saisir au moins 2 caractères!");
    document.contact.Nom.focus();
    return (false);
  }

  if (document.contact.Texte.value == "")  {
    alert("Veuillez saisir l'objet de votre message!");
    return (false);
  }

  if (document.contact.Texte.value.length < 2)
  {
    alert("Veuillez saisir au moins 2 caractères!");
    return (false);
  }

  if (document.contact.Mail.value == "")
  {
    alert("Veuillez saisir votre adresse mail!");
    document.contact.Mail.focus();
    return (false);
  }

  RE = /^[A-Za-z0-9\.\-_]+[@][A-Za-z0-9\-\.]+[\.]([A-Za-z]+)?$/;
  if (! RE.test(document.contact.Mail.value) )
  {
   alert("L'adresse email saisie n'est pas valide !");
   document.contact.Mail.focus();
   return false;
  }

  return (true);
}
function majJavascript() {
	document.parametres.target="resultat";
	document.parametres.action="http://www.fan-de-cinema.com/rss/testjs.php";
	document.parametres.submit();
	document.parametres.target="source";
	document.parametres.action="http://www.fan-de-cinema.com/rss/scriptjs.php";
	document.parametres.submit();
}
function newsletter ()  {
    if(testnewsletter()) document.sub_form.submit();
}

function testnewsletter() {
  if (document.sub_form.email_addr.value == "")
  {
    alert("Veuillez saisir votre adresse mail!");
    document.sub_form.email_addr.focus();
    return (false);
  }

  RE = /^[A-Za-z0-9\.\-_]+[@][A-Za-z0-9\-\.]+[\.]([A-Za-z]+)?$/;
  if (! RE.test(document.sub_form.email_addr.value) )
  {
   alert("L'adresse email saisie n'est pas valide !");
   document.sub_form.email_addr.focus();
   return false;
  }
  if (document.sub_form.Secret.value == "")
  {
    alert("Veuillez saisir le code anti-spam !");
    document.sub_form.Secret.focus();
    return (false);
  }

  return (true);
}

