// JavaScript Document


 //Video Display Popping windows
function popWindow(url)
{
 	popz=window.open(url,'popup','toolbar=no, scrollbars=yes, resizable=yes, status=no, location=no, directories=no, menubar=no, width=479, height=337, top=20, left=20');
		popz.focus();
}

var xmlDoc;
function importXML(url)
{
    $('offres').update('Chargement en cours...');
    
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = parseXML;
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) parseXML()
		};
 	}
	else
	{
		$('offres').update('Your browser can\'t handle this script');
		return;
	}
	xmlDoc.load('/proxy.php?url='+url);
}

var listAnnonces = new Array();
function parseXML() {
    // Lecture des annonces fournies dans le flux XML
    annonces = xmlDoc.getElementsByTagName('annonce');
    
    for(i=0; i<annonces.length; i++) {
        annonce = annonces[i];
        newAnnonce = new Array();
        
        // Chaque tag est une entrée du tableau
        for(j=0; j<annonce.childNodes.length; j++) {
            elmt = annonce.childNodes[j];
            if (elmt.childNodes.length && elmt.nodeName.substr(0, 1) != '#') {
                newAnnonce[elmt.nodeName] =  purifyNode(elmt.nodeName, elmt.firstChild.nodeValue);
            }
        }
        
        // Cas de la société : vide vaut Solic
        if (typeof(newAnnonce.societe) == 'undefined' || newAnnonce.societe == '')
            newAnnonce['societe'] = "Solic Groupe";
        
        // Ajout du lien vers la fiche descriptive
        newAnnonce['lien'] = '/index.php/fre/Candidat/Ils-recrutent/Offre?id='+newAnnonce.id;
        
        listAnnonces[listAnnonces.length] = newAnnonce;
    }
    
    // Appel à la fonction d'affichage des annonces propre à la page
    updateOffres();
}

function purifyNode(name, string) {
    // nl2br
    string = string.replace(/\n/g, '<br/>');
    
    // Cas de la date : YYYY-MM-DD HH:MM:SS => DD/MM/YYYY
    if (name.startsWith('date'))
        string = string.truncate(10, '').split('-').reverse().join('/');
    
    return(string);
}