var CHANNEL = "channel";

//Common Vars
var TITLE = "title";
var DESCRIPTION = "description";
var PUBDATE = "pubDate";
var CATEGORY = "category";
var LINK = "link";

//Channel Specific Vars
var LANGUAGE = "language";
var COPYRIGHT = "copyright";
var MANAGINGEDITOR = "managingEditor";
var WEBMASTER = "webMaster";
var LASTBUILDDATE = "lastBuildDate";
var GENERATOR = "generator";
var DOCS = "docs";
var TTL = "ttl";
var RATING = "rating";
var IMAGE = "image";
var ITEM = "item";

//Image Specific Vars
var URL="url";
var WIDTH="width";
var HEIGHT="height";

//Item Specific Vars
var AUTHOR="author";
var COMMENTS="comments";
var ENCLOSURE="enclosure";
var GUID="guid";
var SOURCE="source";

//Enclosure Specific Vars
var LENGTH="length";
var TYPE="type";

function Channel()
{
    this.title = null;
    this.link = null;
    this.description = null;
    this.language = null;
    this.copyright = null;
    this.managingEditor = null;
    this.webMaster = null;
    this.pubDate = null;
    this.lastBuildDate = null;
    this.category = null;
    this.generator = null;
    this.docs = null;
    this.ttl = null;
    this.rating = null;
    this.images = null;
    this.items = null;

    this.populate = populate;
    
    function populate(feedXML)
    {
        var channel = getNthOccurance(feedXML, CHANNEL, 0);
        this.title = getData(channel, TITLE);
        this.link = getData(channel, LINK);
        this.description = getData(channel, DESCRIPTION);
        this.language = getData(channel, LANGUAGE);
        this.copyright = getData(channel, COPYRIGHT);
        this.managingEditor = getData(channel, MANAGINGEDITOR);
        this.webMaster = getData(channel, WEBMASTER);
        this.pubDate = getData(channel, PUBDATE);
        this.lastBuildDate = getData(channel, LASTBUILDDATE);
        this.category = getData(channel, CATEGORY);
        this.generator = getData(channel, GENERATOR);
        this.docs = getData(channel, DOCS);
        this.ttl = getData(channel, TTL);
        this.rating = getData(channel, RATING);
        
        var images = getAllOccurances(channel, IMAGE);
        var imagesLen = images.length;
        var imageArray = new Array();
        for(i=0;i<imagesLen;i++)
        {
            imageArray[i] = new Image();
            imageArray[i].populate(getNthOccurance(channel, IMAGE, i));
        }
        this.images = imageArray;
                
        var items = getAllOccurances(channel, ITEM);        
        var itemsLen = items.length;
        var itemArray = new Array();
        for(i=0;i<itemsLen;i++)
        {
            itemArray[i] = new Item();
            itemArray[i].populate(getNthOccurance(channel, ITEM, i));
        }
        this.items = itemArray;
    }
    
}

function Image()
{
    this.url = null;
    this.title = null;
    this.link = null;
    this.width = null;
    this.height = null;
    this.description = null;
    
    this.populate = populate;
    
    function populate(imageSubTree)
    {
        if(imageSubTree)
        {
            this.url = getData(imageSubTree, URL);
            this.title = getData(imageSubTree, TITLE);
            this.link = getData(imageSubTree, LINK);
            this.width = getData(imageSubTree, WIDTH);
            this.height = getData(imageSubTree, HEIGHT);
            this.description = getData(imageSubTree, DESCRIPTION);
        }
    }
}

function Item()
{
    this.title = null;
    this.link = null;
    this.description = null;
    this.author = null;
    this.category = null;
    this.comments = null;
    this.enclosure = null;
    this.guid = null;
    this.pubDate = null;
    this.source = null;
    
    this.populate = populate;
    
    function populate(itemSubTree)
    {
        if(itemSubTree)
        {
            this.title = getData(itemSubTree, TITLE);
            this.description = getData(itemSubTree, DESCRIPTION);
            this.link = getData(itemSubTree, LINK);
            this.author = getData(itemSubTree, AUTHOR);
            this.category = getData(itemSubTree, CATEGORY);
            this.comments = getData(itemSubTree, COMMENTS);
            var tempEncl = new Enclosure();
            tempEncl.populate(getNthOccurance(itemSubTree, ENCLOSURE, 0));
            this.guid = getData(itemSubTree, GUID);
            this.pubDate = getData(itemSubTree, PUBDATE);
            this.source = getData(itemSubTree, SOURCE);
        }
    }
}

function Enclosure()
{
    this.url = null;
    this.length = null;
    this.type = null;
    
    this.populate = populate;
    
    function populate(enclosureSubTree)
    {
        if(enclosureSubTree)
        {
            this.url = getData(enclosureSubTree, URL);
            this.length = getData(enclosureSubTree, LENGTH);
            this.type = getData(enclosureSubTree, TYPE);
        }
    }
}

function getAllOccurances(xmlText, tagName)
{
    return xmlText.getElementsByTagName(tagName);
}

function getNthOccurance(xmlText, tagName, n)
{
    return getAllOccurances(xmlText, tagName)[n];
}

function getData(xmlText, tagName)
{
    var currTag = getNthOccurance(xmlText, tagName, 0);
    if(currTag) 
    {
        if(currTag.firstChild)
            return currTag.firstChild.nodeValue;
        else
            return null;
    }
    else
    {
        return "No Data";
    }
}



function objet() {
	this.length = objet.arguments.length
	for (var i = 0; i < this.length; i++) this[i+1] = objet.arguments[i]
	}
	
	var nom = new objet ("centrale.jpg", "Entreprise.jpg", "Plasma.jpg", "soud.jpg", "Image1chaud.jpg", "jetdeau.jpg", "Image1soud.jpg", "Image2chaud.jpg", "Image2con.png", "Image5tuya.jpg", "Image2pole.jpg", "Image2soud.jpg", "Image3con.jpg", "Image4tuya.jpg", "PlateformeP.jpg", "sous marin.jpg", "train.jpg");                           
	var numero = Math.floor((nom.length)*Math.random()+1);

function changer() {
	document.image.src = "Image/Visionneuse/"+nom[numero];
	numero += 1;
	if (numero == nom.length + 1) numero = 1;
	setTimeout("changer()", 5000);
}

function chargement() {
	document.getElementById("sousMenuDomaines").style.display = "none" ;
	document.getElementById("sousMenuNosPartenaires").style.display = "none" ;
	document.getElementById("sousMenuDD").style.display = "none" ;
}

function montrerDomaines() {
	chargement() ;
	document.getElementById("sousMenuDomaines").style.display = "" ;
}

function montrerNosPartenaires() {
	chargement() ;
	document.getElementById("sousMenuNosPartenaires").style.display = "" ;
}

function montrerDD() {
	chargement() ;
	document.getElementById("sousMenuDD").style.display = "" ;
}

function HorlogeDynamique() {

											var DateActuel = new Date();

											// on se base sur le gmt +2 en attribuant sa valeur à la variable DateActuel
											DateActuel.setHours(DateActuel.getHours()+2);

											//formatage de l'affichage
											Horloge = "&nbsp;"+DateActuel.toGMTString();
											Horloge2 = "&nbsp;"+DateActuel.toGMTString();
											Horloge = Horloge.substring(0, Horloge.length - 13)+"&nbsp;";
                                            Horloge2 = Horloge2.substring(32, Horloge.length - 6)+"&nbsp;";
											
													//test de compatibilité de navigateur web
													if (document.getElementById) {
																					document.getElementById("date").innerHTML = Horloge+Horloge2;
																				 }
	                                        //interval pour renvoyer l'heure en temps réel
											setTimeout("HorlogeDynamique()", 1000);
							
										}
//var i = 1										
//function chargePage() {
//if(i==3){
//document.body.style.display = "" ;
//}
//else{
//i++;
//setTimeout("chargePage()", 1000);
//}
//}

