// JScript File

function creerRequete(nom){
	var xmlRequete = null
	if(window.XMLHttpRequest){ // Firefox
		xmlRequete = new XMLHttpRequest();
		addRequete(nom, xmlRequete);
	}else if(window.ActiveXObject){ // Internet Explorer
		xmlRequete =new ActiveXObject("Microsoft.XMLHTTP");
		addRequete(nom, xmlRequete);
	}else{ // XMLHttpRequest non supporté par le navigateur
		popup_alerte("", "Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		//return;
	}
}

function Requete(_name) {
	this.name = _name;
}

function addRequete (_name, _XmlHttpRequest) {
	ListeRequete[_name] =_XmlHttpRequest;
}

var ListeRequete = new Requete("home");
var _callback;
var _website = "http://www.mytaratata.com/";
var webserviceMember = _website+"services/memberservice.aspx";




// checke le cookie MYTARATATA
// de la forme : MYTARATATA=<TaratataMember><UID>1</UID><Email>frederic.catteau@rappcollinsparis.fr</Email><Nom>catteau</Nom><CP>76000</CP><Sexe>Femme</Sexe><DateNaissance>25/09/1980</DateNaissance><KewegoNom /></TaratataMember>

// callback  / function(isOk,message)
//      isOk    =>  MAJ OK  (booleen)
//      message =>  Message Erreur
//              NO_ID       pas d'id taratata
//              NO_KEWEGOID pas de clé kewego (nom d'auteur)
//              NO_COOKIE   pas de cookie
// 
function updateKewego(callback){
    _callback=callback;
	creerRequete("updateKewego");
	var requete = ListeRequete["updateKewego"];			
	var url = webserviceMember;
	requete.open("POST", url, true);
	requete.onreadystatechange = function(){
        kewego();
	}
	requete.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	requete.send("operation=checkcookie");
}

function generateHeader(){
    var header = '';
    header += '<div style="width: 1061px;height: 66px;display: block;" >\n';
    header += '<div style="width: 264px;height: 49px;margin:9px 0 0 0; float:left;"><a href="'+_website+'default.aspx"><img src="'+_website+'images/general/logo.gif" width="264" height="49" alt="Logo My Taratata" border="0" /></a>\n</div>\n</div>';
    header += '<div style="width: 1061px;height: 28px;margin:0;padding:11px 0 21px 0;display: block;">';
    header += '<span style="width: 220px;height: 28px;margin:0;float: left;"><a href="'+_website+'Pages/univers.aspx"><img src="'+_website+'images/general/univers_taratata.gif" width="220" height="28" alt="L\'univers Taratata" border="0" /></a></span>\n';
    header += '<span style="width: 158px;height: 28px;margin:0;float: left;"><a href="'+_website+'Pages/programme.aspx"><img src="'+_website+'images/general/les_emissions.gif" width="158" height="28" alt="Les émissions" border="0" /></a></span>\n';
    header += '<span style="width: 203px;height: 28px;margin:0;float: left;"><a href="'+_website+'Pages/artistes_multimedia.aspx"><img src="'+_website+'images/general/artistes_multimedia.gif" width="203" height="28" alt="artiste &amp; multimédia" border="0" /></a></span>\n';
    header += '<span style="width: 201px;height: 28px;margin:0;float: left;"><a href="http://video.mytaratata.com"><img src="'+_website+'images/general/ttes_videos.gif" width="201" height="28" alt="Toutes les videos" border="0" /></a></span>\n';
    header += '<span style="width: 165px;height: 28px;margin:0;float: left;"><a href="'+_website+'Pages/Perso_default.aspx"><img src="'+_website+'images/general/mon_taratata.gif" width="165" height="28" alt="Mon Taratata" border="0" /></a></span></div>';
    document.write(header);
}
function generateFooter(){
/*
width:890px; height:110px; margin:20px 0 15px 0; font:normal 11px Arial; color:#FFFFFF; float:left; background-color:#151515;
*/
    var footer = '';
	footer += '<div id="ml" style="width:890px; height:110px; margin:20px 0 15px 0; font:normal 11px Arial; color:#FFFFFF; float:left; background-color:#151515;">';
		footer += '<div style="padding:5px 0 20px 15px;">';
			footer += '<strong>Taratata,</strong> est une production <a href="http://www.airprod.com/airprodcom/index.htm" target="_blank" style="color:#FFFFFF; text-decoration:none;"><strong>Air Productions,</strong></a> diffus&eacute; sur France 4 (TNT) et France 2, goupill&eacute; par <strong>Nagui,</strong> d&eacute;goupill&eacute; par <strong>Pullicino,</strong> &eacute;clair&eacute; par <strong>Bourdon</strong> et mix&eacute; par <strong>Cramer.</strong><br />';
			footer += '<span style="float:left; margin:0 5px 0 0;"><img style="padding:0 5px 0 0;" src="'+_website+'images/home/revoir_emission/voir_fleche_emission.gif" width="4" height="7" alt="" /><a href="mailto:taratata@airprod.com" style="color:#FFFFFF; text-decoration:none">Contactez nous</a></span>';
			footer += '<span style="float:left; margin:0 10px 0 0;"><img style="padding:0 5px 0 0;" src="'+_website+'images/home/revoir_emission/voir_fleche_emission.gif" width="4" height="7" alt="" /><a href="'+_website+'Pages/mentionsLegales.aspx" style="color:#FFFFFF; text-decoration:none">Mentions l&eacute;gales</a></span>';
		footer += '</div>';
		footer += '<div style="background-color:#000000;"><img src="'+_website+'images/general/shizm.gif" width="20" height="4" alt="" /></div>';
		footer += '<div>';
			footer += '<span style="float:left;"><a href="http://www.france4.fr" target="_blank"><img src="'+_website+'images/general/france4.gif" width="41" height="55" alt="Logo france 4" border="0" /></a></span>';
			footer += '<span style="float:left;"><a href="http://www.france2.fr" target="_blank"><img src="'+_website+'images/general/france2.gif" width="41" height="55" alt="Logo france 2" border="0" /></a></span>'; 
			footer += '<span style="float:left; width:58px; height:55px;">';
			footer += '<!--a href="http://www.europe2.fr" target="_blank"><img src="'+_website+'images/general/europe2.gif" width="58" height="55" alt="Logo france 4" border="0" /></a--></span>';
			
			footer += '<span style="float:left; margin:0 5px 0 560px;"><img src="'+_website+'images/general/logoteeshirt.gif" width="47" height="55" alt="Logo teeShirt" border="0" /></span>';
			footer += '<div style="margin:15px 15px 0 0; float:left; width:100px;">';
				footer += '<span><img style="padding:0 5px 0 0;" src="'+_website+'images/home/revoir_emission/voir_fleche_emission.gif" width="4" height="7" alt="" /><a href="http://www.divao.com/taratata/pageaccueil.php?a=1&id=" target="_blank" style="color:#FFFFFF; text-decoration:none;">La boutique</a></span><br />';
				footer += '<span><img style="padding:0 5px 0 0;" src="'+_website+'images/home/revoir_emission/voir_fleche_emission.gif" width="4" height="7" alt="" /><a href="http://www.airprod.com/forumtaratata/" target="_blank" style="color:#FFFFFF; text-decoration:none">Le forum</a></span>';
			footer += '</div>';
		footer += '</div>';
	footer += '</div>';
    document.write(footer);
}

function kewego(){
	var requete = ListeRequete["updateKewego"];
	if(requete.readyState ==4){
		if(requete.status ==200){
		   var reponse = requete.responseXML;
		   var code = "NOK";
		   if (isDefined(reponse.getElementsByTagName("code_erreur")))
		        code=reponse.getElementsByTagName("code_erreur")[0].firstChild.nodeValue;
		   if (isDefined(reponse.getElementsByTagName("code")))
		        code = "OK";       
		        
           var message =  "";
		   if (isDefined(reponse.getElementsByTagName("message_erreur")))
		        message=reponse.getElementsByTagName("message_erreur")[0].firstChild.nodeValue;           

            if (code=="OK")
                 _callback.apply(this,new Array(true,message));
            else
                _callback.apply(this,new Array(false,message));
		}else if(requete.status ==404){
		    _callback.apply(this,new Array(false,"404"));
		}
	}
}

function isDefined(element){
    if (element!=null && element[0]!=null && element[0].firstChild!=null)
        return true;
    else
        return false;
}
