//-----------------------------------------------------------------------------------------------//
// Fonctions
//-----------------------------------------------------------------------------------------------//

function GetId(Ctl) {
	return document.getElementById(Ctl)
}

//----------------------------------------------------------------------------------------------------------//
// Style des contrles des formulaires																		//
//----------------------------------------------------------------------------------------------------------//

function ClassChange(Ctl,Class) {
	Ctl.className = Class;
}

//----------------------------------------------------------------------------------------------------------//
// Captcha																									//
//----------------------------------------------------------------------------------------------------------//

function RefreshCaptcha() {
	var i = new Image();
	var d = new Date();
	i.src = '/Includes/Captcha.asp?Type=4&Dt=' + d.getHours().toString() + d.getMinutes().toString() + d.getSeconds().toString() ;
	GetId("Captcha").src =  i.src;
}

function init() {
	preLoad();  // Charge les images
}

window.onload = init;

//-----------------------------------------------------------------------------------------------//
// Gnral
//-----------------------------------------------------------------------------------------------//

var Images = new Array();

function preLoad() {
	var i = 0;
	Images[i++] = GetImage("/Images/Commun/Tab1Over.gif");
	Images[i++] = GetImage("/Images/Commun/Tab2Over.gif");
	Images[i++] = GetImage("/Images/Commun/Tab3Over.gif");
	Images[i++] = GetImage("/Images/Commun/Tab4Over.gif");
	
	Images[i++] = GetImage("/Images/Commun/Tab1Down.gif");
	Images[i++] = GetImage("/Images/Commun/Tab2Down.gif");
	Images[i++] = GetImage("/Images/Commun/Tab3Down.gif");
	Images[i++] = GetImage("/Images/Commun/Tab4Down.gif");
	
	Images[i++] = GetImage("/Images/Commun/btnVisualiser1Over.gif");
	Images[i++] = GetImage("/Images/Commun/btnVisualiser2Over.gif");
	Images[i++] = GetImage("/Images/Commun/btnVisualiser3Over.gif");
	Images[i++] = GetImage("/Images/Commun/btnRSSOver.gif");
	Images[i++] = GetImage("/Images/Commun/btnOkOver.gif");
	Images[i++] = GetImage("/Images/Commun/btnCaptchaOver.gif");
	
	Images[i++] = GetImage("/Images/Commun/Input2.gif");
}

function GetImage(Src) {
	Ctl = new Image();
	Ctl.src = Src;
	return Ctl;
}


function runcode(cs) {
   var old;
/*
   if (!document.PubsTvForm.EmailCheck.checked) {
    alert("Vous devez cocher la case !");
    return;
   }
*/
if (document.PubsTvForm.Email.value=="") {
    alert("Merci de saisir votre adresse e-mail !");
    return;
   }
   if (!isEmail(document.PubsTvForm.Email)) {
   	alert("Merci de saisir votre adresse e-mail !");
	return;
   }
   if (isEmail(document.PubsTvForm.Email)) {
     document.PubsTvForm.action="http://www.pubstv.com/Includes/" + cs;
     old =  document.PubsTvForm.action;
     document.PubsTvForm.submit();
     document.PubsTvForm.action = old;
   }
  }

function runcode1(cs) {
     var old, old1, old2;
	 Form = document.PubsTvForm;
	 if (Form.EmailDesinscr.value=='') {
		alert('Merci de saisir l\'adresse e-mail utilise pour l\'ouverture du compte.');
		return false;
	 }
	 if (!isEmail(Form.EmailDesinscr)) {
		alert('Merci de saisir une adresse e-mail valide !');
		return false;
	 }

     old =  document.PubsTvForm.action;
     old1 =  document.PubsTvForm.Email.value;
     old2 =  document.PubsTvForm.target;
     document.PubsTvForm.action="http://www.pubstv.com/Includes/" + cs;
	 document.PubsTvForm.Email.value = document.PubsTvForm.EmailDesinscr.value;
	 document.PubsTvForm.target = "_self";
     document.PubsTvForm.submit();
     document.PubsTvForm.action = old;
	 document.PubsTvForm.Email.value = old1;
	 document.PubsTvForm.target = old2;
  }

function SwitchImg(Ctl,Etat,Type) {
	if (typeof(Type)=='undefined') {
		GetId(Ctl).src = "/Images/Commun/" + Ctl + Etat + ".gif";
	} else {
		switch(Type) {
			case 0:  GetId(Ctl).src = "/Images/Commun/btnOk" + Etat + ".gif"; break;
			case 1:  GetId(Ctl).src = "/Images/Commun/btnVisualiser1" + Etat + ".gif"; break;
			case 2:  GetId(Ctl).src = "/Images/Commun/btnVisualiser2" + Etat + ".gif"; break;
			case 3:  GetId(Ctl).src = "/Images/Commun/btnVisualiser3" + Etat + ".gif"; break;
			case 4:  GetId(Ctl).src = "/Images/Commun/btnRSS" + Etat + ".gif"; break;
			case 5:  GetId(Ctl).src = "/Images/Commun/btnCaptcha" + Etat + ".gif"; break;
			case 6:  GetId(Ctl).src = "/Images/Commun/btnFermer" + Etat + ".gif"; break;
			case 7:  GetId(Ctl).src = "/Images/Commun/PanelL/" + Ctl + Etat + ".gif"; break;
			case 8:  GetId(Ctl).src = "/Images/Commun/btnValider" + Etat + ".gif"; break;
			case 9:  GetId(Ctl).src = "/Images/Inscription/btnInscription" + Etat + ".gif"; break;
			case 10: GetId(Ctl).src = "/Images/Inscription/btnForum" + Etat + ".gif"; break;
			case 11: GetId(Ctl).src = "/Images/Commun/btnInscription" + Etat + ".gif"; break;
			case 12: GetId(Ctl).src = "/Images/Commun/btnRetourPageAccueil" + Etat + ".gif"; break;
			case 13: GetId(Ctl).src = "/Images/Commun/btnInscription1" + Etat + ".gif"; break;
			case 14: GetId(Ctl).src = "/Images/Inscription/btnInscription1" + Etat + ".gif"; break;
		}
	}
}

//-----------------------------------------------------------------------------------------------//
// Ticker actualits
//-----------------------------------------------------------------------------------------------//

	var scrollerdelay='3000';
	var scrollerheight='105px';

	var messages = new Array()
	var ie=document.all
	var dom=document.getElementById

	if (messages.length>2) { i=2 } else { i=0 };

	function move(whichdiv){
		tdiv=eval(whichdiv)
		if (parseInt(tdiv.style.top) >0 && parseInt(tdiv.style.top)<=5) 
		{
			tdiv.style.top = 0+"px"
			setTimeout("move(tdiv)",scrollerdelay)
			setTimeout("move2(second_obj)",scrollerdelay)
			return
		}

		if (parseInt(tdiv.style.top)>=tdiv.offsetHeight*-1) 
		{
			tdiv.style.top=parseInt(tdiv.style.top)-5+"px"
			setTimeout("move(tdiv)",50)
		} else {
			tdiv.style.top=parseInt(scrollerheight)+"px"
			tdiv.innerHTML=messages[i]
			if (i==messages.length-1) { i=0 } else { i++ }
		}
	}

	function move2(whichdiv) {
		tdiv2=eval(whichdiv)
		if (parseInt(tdiv2.style.top)>0&&parseInt(tdiv2.style.top)<=5) 
		{
			tdiv2.style.top=0+"px"
			setTimeout("move2(tdiv2)",scrollerdelay)
			setTimeout("move(first_obj)",scrollerdelay)
			return
		}
		if (parseInt(tdiv2.style.top)>=tdiv2.offsetHeight*-1) 
		{
			tdiv2.style.top=parseInt(tdiv2.style.top)-5+"px"
			setTimeout("move2(second_obj)",50)
		} else {
			tdiv2.style.top=parseInt(scrollerheight)+"px"
			tdiv2.innerHTML=messages[i]
			if (i==messages.length-1) { i=0 } else { i++ }
		}
	}

	function startscroll() {
		if (document.getElementById("First")!=null) {
			first_obj = ie  ? First  : document.getElementById("First");
			second_obj = ie ? Second : document.getElementById("Second");
			first_obj.innerHTML=messages[0];
			second_obj.innerHTML=messages[1];
			move(first_obj);
			second_obj.style.top = scrollerheight;
			second_obj.style.visibility = 'visible';
		}
	}

	if (window.addEventListener)
		window.addEventListener("load", startscroll, false)
	else if (window.attachEvent) 
		window.attachEvent("onload", startscroll)
	else if (ie||dom) 
		window.onload=startscroll
		
//-----------------------------------------------------------------------------------------------//
// Notice lgale
//-----------------------------------------------------------------------------------------------//

function GetWidth() { return (document.all) ? document.body.clientWidth : window.innerWidth - 19; }
function GetHeight() { return (document.all) ? document.body.clientHeight : window.innerHeight - 19; }

function GetPos(Ctrl, Axis)
{
	var Pos = 0;
	while (Ctrl) { if (Ctrl.tagName == 'BODY') { break; } Pos += (Axis=='X') ? Ctrl.offsetLeft: Ctrl.offsetTop; Ctrl = Ctrl.offsetParent; }
	return Pos;
}
function SwapNotice() {
	GetId('Notice').style.display = (GetId('Notice').style.display=='' ? 'none' : '');

	X = (GetWidth()-450)/2;
	Y = GetPos(GetId('NoticeLine'),'Y') - GetId('Notice').offsetHeight;
	
	GetId('Notice').style.left = parseInt(X) + 'px';
	GetId('Notice').style.top = parseInt(Y)+1 + 'px';
}

function OpenCredits() {
	GetId('Video').style.display = 'none';
	GetId('Credits').style.display = '';
}

function CloseCredits() {
	GetId('Video').style.display = '';
	GetId('Credits').style.display = 'none';
}

function OpenRecommand() {
	Form = document.PubsTvForm;
	
	if (Form.RecommandEmail.value=='' || Form.RecommandEmail.value=='E-mail du destinataire...') {
		alert('Merci de saisir l\'e-mail du destinataire.');
		return false;
	}
	if (!isEmail(Form.RecommandEmail)) {
		alert('Merci de saisir une adresse e-mail valide !');
		return false;
	}			
	GetId('Video').style.display = 'none';
	GetId('Recommand').style.display = '';
}			

function CloseRecommand() {
	GetId('Foo').src ="about:blank";
	GetId('Video').style.display = '';
	GetId('Recommand').style.display = 'none';
}

function CloseConfirmationRecommand() {
	GetId('Video').style.display = '';
	GetId('ConfirmationRecommand').style.display = 'none';
	clearInterval(Counter);
}

function CloseConfirmationNote() {
	GetId('Video').style.display = '';
	GetId('ConfirmationNote').style.display = 'none';
	clearInterval(Counter);
}

function GetMail(Ctrl, Address, Domain, Tld) {
	window.location = "mailto:" + Address + '@' + Domain + '.' + Tld;
}

//-----------------------------------------------------------------------------------------------//
// Gestion des formulaires
//-----------------------------------------------------------------------------------------------//

function Command(Action, Param1, Param2)
{	
	Form = document.PubsTvForm;

	switch (Action.toUpperCase()) {
		case 'FIND': 
			if (Form.Query.value=='' || Form.Query.value=='Mots cls...') return false;
			Form.action = '/publicite/afrecherche-0-0/pubs.html';
			Form.submit();
			break;
		case 'CHANGENOTE':
			var Note = parseInt(Form.Note.value);
			if (Param1==0 && Note>=1) Note -= 1
			if (Param1==1 && Note<10) Note += 1
			Form.Note.value = Note;
			GetId('NoteCounter').src = '/Images/Commun/Video/Note' + (Note<10 ? '0' : '') + Note + '.gif';
			break;
		case 'LOGIN':
			if (Form.UserId.value=='' || Form.UserId.value=='Identifiant' ||
				Form.Pw.value=='' || Form.Pw.value=='PasswordPubsTV') {
				alert('Merci de saisir votre identifiant et votre mot de passe.');
				return false;
			}
			Form.action = '/connexion.html';
			Form.submit();
			break;
		case 'LOGIN_1':
            // Debut Ajout AF IS 22.10.2007
            if (Form.UserId_1.value=='' || Form.UserId_1.value=='Identifiant' ||
				Form.Pw_1.value=='' || Form.Pw_1.value=='PasswordPubsTV') {
				alert('Merci de saisir votre identifiant et votre mot de passe.');
				return false;
			}
			Form.UserId.value = Form.UserId_1.value;
			Form.Pw.value   = Form.Pw_1.value;
			Form.action = '/connexion.html';
			Form.submit();
            // Fin Ajout AF IS 22.10.2007
			break;
		case 'LOGOUT':
			Form.action = '/deconnexion.html';
			Form.submit();
			break;
		case 'RESET':
			Form.Action.value = 'RESET';
			Form.submit();
			break;
		case 'LOSTPW':
			if (Form.LostUserEmail.value=='') {
				alert('Merci de saisir l\'adresse e-mail utilise pour l\'ouverture du compte.');
				return false;
			}
			if (!isEmail(Form.LostUserEmail)) {
				alert('Merci de saisir une adresse e-mail valide !');
				return false;
			}
			Form.action = '/oubli.html';
			Form.submit();
			break;
		case 'SUBSCRIBE':
			//if ((Form.Nom.value=='') || (Form.Prenom.value=='') || (Form.Jour.value=='') || (Form.Mois.value=='') ||
			//   (Form.Annee.value=='') || (Form.UserEmail.value=='') || (Form.UserIdentifiant.value=='') || (Form.MotDePasse.value=='') || 
			//   (Form.Captcha.value=='')) {
			//   alert('Merci de saisir l\'ensemble des lments obligatoires.\nCes lments sont suivis d\'un astrisque (*).');
			//   return false;
			//}
			if ((Form.UserEmail.value=='') || (Form.MotDePasse.value=='') || 
			   (Form.Captcha.value=='')) {
			   alert('Merci de saisir l\'ensemble des éléments obligatoires.\nCes éléments sont suivis d\'un astrisque (*).');
			   return false;
			}

			if (!isEmail(Form.UserEmail)) {
			   alert('Merci de saisir une adresse e-mail valide !');
			   return false;
			}

			//if (!isDate(Form.Jour.value, Form.Mois.value, Form.Annee.value)) {
			//   alert('Merci de saisir une date de naissance valide !');
			//   return false;
			//}

			if (Form.MotDePasse.value.length<6) {
			   alert('Le mot de passe doit faire au minimum 6 caractres !');
			   return false;
			}
			if (Form.MotDePasse.value != Form.MotDePasse2.value) {
			   alert('Le mot de passe et sa confirmation ne correspondent pas !');
			   return false;
			}
			if (!Form.CGV.checked) {
				alert('Vous devez confirmer les conditions générales de vente\navant de pouvoir valider votre inscription');
				return false;
			}
		
			Form.action = '/inscription.html';
			Form.submit();
			break;
		case 'UNSUBSCRIBE':
			if (Form.UserEmail.value=='') {
				alert('Merci de saisir l\'adresse e-mail utilise pour l\'ouverture du compte.');
				return false;
			}
			if (!isEmail(Form.UserEmail)) {
				alert('Merci de saisir une adresse e-mail valide !');
				return false;
			}
			//if (Form.desinscrSite.checked) {
			  Form.action = '/desinscription.html';
			  Form.submit();
			//} else if (Form.desinscrNewsletter.checked) {
			//   // Desinscription only for a newsletter
            //  runcode1('UnSubscribe.asp');
            //}
			break;
		case 'UNSUBSCRIBENEWS':
			if (Form.UserEmail.value=='') {
				alert('Merci de saisir l\'adresse e-mail utilise pour l\'ouverture du compte.');
				return false;
			}
			if (!isEmail(Form.UserEmail)) {
				alert('Merci de saisir une adresse e-mail valide !');
				return false;
			}
			Form.action = '/desinscriptionnews.html';
			Form.submit();
			break;
		case 'SENDMAIL':
			if (Form.UserEmail.value=='') {
				alert('Merci de saisir votre adresse e-mail.');
				return false;
			}
			if (!isEmail(Form.UserEmail)) {
				alert('Merci de saisir une adresse e-mail valide !');
				return false;
			}
			if (Form.CodePostal.value!='' && !isCP(Form.CodePostal)) {
				alert('Merci de saisir un code postal correct !');
				return false;
			}
			if (Form.Message.value=='') {
				alert('Merci de saisir le contenu de votre message !');
				return false;
			}
			Form.action = '/envoimessage.html';
			Form.submit();
			break;
		case 'SENDRECOMMAND':
			Form.target = 'Foo';
			Form.action = '/recommander.html';
			Form.submit();

			GetId('Recommand').style.display = 'none';
			GetId('Video').style.display = 'none';
			GetId('Decompte1').innerHTML = '<b>10</b> secondes';
			GetId('ConfirmationRecommand').style.display = '';
			CurrentCount = 0
			Counter = setInterval("CloseConfirmationTiming(1,10)",1000);
			break;
		case 'SETNOTE':
			Form.NouvelleNote.value = (Number(Form.Note.value)+(Param1*Param2))/(Param2+1);
			Form.target = 'Foo';
			Form.action = '/vote.html';
			Form.submit();

			GetId('Video').style.display = 'none';
			GetId('Decompte2').innerHTML = '<b>10</b> secondes';
			GetId('ConfirmationNote').style.display = '';
			CurrentCount = 0
			Counter = setInterval("CloseConfirmationTiming(2,10)",1000);
			break;
	}
}

var Counter;
var CurrentCount;

function CloseConfirmationTiming(IdCounter, MaxCount) {
	CurrentCount+=1; 
	GetId('Decompte' + IdCounter).innerHTML = '<b>' + (MaxCount-CurrentCount) + '</b> seconde' + (CurrentCount!=9 ? 's' : '');
	if (CurrentCount==10) {
		if (IdCounter==1) {
			CloseConfirmationRecommand();
		} else {
			CloseConfirmationNote();
		}
	}
}


function OnFocus(Ctl, Txt) 		{ if (Ctl.value == Txt) Ctl.value = ''; CurrentCtl = Ctl.name; }
function OnBlur(Ctl, Txt)  		{ if (Ctl.value == '') Ctl.value = Txt; }

//-----------------------------------------------------------------------------------------------//
// Gestion des formulaires
//-----------------------------------------------------------------------------------------------//

function HeadLine(IdCtl, State) {
	GetId('H2_' + IdCtl).style.backgroundColor = (State==true) ? "#E2E7E8" : "#C9CFD2";
	GetId('H3_' + IdCtl).style.backgroundColor = (State==true) ? "#E2E7E8" : "#FFFFFF";
	GetId('H4_' + IdCtl).style.backgroundColor = (State==true) ? "#E2E7E8" : "#ECF1F2";
	GetId('H5_' + IdCtl).style.backgroundColor = (State==true) ? "#E2E7E8" : "#FFFFFF";
	GetId('H6_' + IdCtl).style.backgroundColor = (State==true) ? "#E2E7E8" : "#C9CFD2";
	GetId('H7_' + IdCtl).style.backgroundColor = (State==true) ? "#F1F4F5" : "#F9FBFB";
}

//-----------------------------------------------------------------------------------------------//
// Gestion des champs de formulaires
//-----------------------------------------------------------------------------------------------//

function isEmail(obj) { // vrif validit email par REGEXP
      var reg = /^[A-Za-z0-9._-]+@[A-Za-z0-9.-]{2,}[.][A-Za-z]{2,4}$/
      return((reg.exec(obj.value)!=null))
}

function isCP(obj) {
	if (isNaN(obj.value)==false && obj.value.length==5)  return true;
	else return false;
}

function isBi(a)
{
 a=a/4; if (a!=Math.ceil(a)) return false;
 a=a/25; if (a!=Math.ceil(a)) return true;
 a=a/10; if (a!=Math.ceil(a)) return false;
 return true;
}

function isDate(j,m,a)
{
 if (m<1 || m>12) return false;
 if (j<1 || j>(30+(Math.abs(m-7.5)+0.5)%2)) return false;
 if (m!=2) return true;
 if (j<=(isBi(a)?29:28)) return true;
 return false;
}


  var showPopupOnExit = true;
  var tmpDomainName = "www.pubstv.com";
  var tmpDomainLen = tmpDomainName.length;
  function doNotShowPopupOnExit() { showPopupOnExit = false; }
  
  function popupOnExit() {
   var showpopup = true;
   if (document.all) {
    var tmp, tmpSiteName, tmpSiteLen;
    tmpSiteName = "http://"+tmpDomainName;
    tmpSiteLen = tmpSiteName.length;
    if (document.activeElement) {
     if (document.activeElement.href)  {
      tmp = document.activeElement.href;
	  if (tmp.substr(0,tmpSiteLen)==tmpSiteName) showpopup = false;
     } else if (document.activeElement.type=="submit") showpopup = false;
    }
   }
      

   if (showpopup) funcOnExit();
 }
  
  function funcOnExit() {
  /* 
	if (showPopupOnExit) { 
    	window.open("http://www.woopami.com/","woopami");
   	}
   */
  }

function updatelinks() {
  var all_links = document.links; 
  for (i=0; i<=(document.links.length-1); i++) {
    //alert(document.links[i].hostname+ "->"+tmpDomainName);
    if ((document.links[i].hostname).substr(0,tmpDomainLen)==tmpDomainName || (document.links[i].target!="" && document.links[i].target!="_self")) (document.links[i]).addEventListener("click", doNotShowPopupOnExit, false);
  }
  var all_forms = document.forms;
  for (i=0; i<=(document.forms.length-1); i++)
    (document.forms[i]).addEventListener("submit", doNotShowPopupOnExit, false);
}

  //if (!document.all) window.onload = updatelinks;
  //window.onunload = popupOnExit;
  
 
//-----------------------------------------------------------------------------------------------//
// Gestion player flash
//-----------------------------------------------------------------------------------------------//
 
function resizeVFP(w,h) {
	var p;
	
	p = GetId("playerIE");
	if (p!=null) {
		p.width = w;
		p.height = h;
	}

	p = GetId("playerFF");
	if (p!=null) {
		p.width = w;
		p.height = h;
	}
}

function fixFlash(s) {
	//s = GetId(s);
	//s.outerHTML = s.outerHTML;
}

function fixFlash1(s) { document.write(s); }
