function loadXML(url) {
   // This function accepts a file name and returns an XML document.
   // Note we're doing no error checking.

   var AJAX = null;                                 // Initialize the AJAX variable.
   if (window.ActiveXObject){
      // Since IE has so much trouble with responseXML
      // we'll load the XML with the XMLDOM activeX object
      var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      // Handle ready state changes ( ignore them until readyState = 4 )
      xmlDoc.onreadystatechange= function() { if (xmlDoc.readyState!=4) return false; }
      // This is a synchronous call!   The script will stall until the document
      // has been loaded.
      xmlDoc.async="false";
      xmlDoc.load(url);
      return xmlDoc.documentElement;
   }
  
   // Initialize the AJAX object.
   if (window.XMLHttpRequest) {  AJAX=new XMLHttpRequest(); }  

   // Handle ready state changes ( ignore them until readyState = 4 )
   AJAX.onreadystatechange= function() { if (AJAX.readyState!=4) return false; }
   // we're passing false so this is a syncronous request.
   // The script will stall until the document has been loaded.
   AJAX.open("GET", url, false);
   AJAX.send(null);
   return AJAX.responseXML;
}

function crawlXML(doc) {                             // Crawls an XML document
   if(doc.hasChildNodes()) {                         // If present element has children
   if ((doc.tagName!="voyages") & (doc.tagName!="voyage"))
      _xmlStr+='<ul><li>'+doc.tagName+'> ';       // Display current tag name
      for(var i=0; i<doc.childNodes.length; i++) {   // for each child node on current level
         crawlXML(doc.childNodes[i]);                // Call this function recursively
      }                                              // end for loop
      _xmlStr+='</li></ul>';                         // Close the list item.
   } else {                                          // current element has no children
      _xmlStr+=doc.nodeValue;                        // So display the value of the data
   }                                                 // End childNode check
}                                                    // End crawlXML


function formatdate(dateunformated){
dateformated="";
dateformated=dateunformated.slice(6,8)+"-"+dateunformated.slice(4,6)+"-"+dateunformated.slice(0,4)+" "+dateunformated.slice(8,10)+":"+dateunformated.slice(10,12)+":"+dateunformated.slice(12,14);
	return dateformated;
	
}

function extractfilename(pathname){
	startingpt=pathname.lastIndexOf("/")
	endpt=pathname.indexOf(".")
	filename=pathname.slice(startingpt+1,endpt)
	return filename
}

function extractfullfilename(pathname){
	startingpt=pathname.lastIndexOf("/")
	endpt=pathname.length
	filename=pathname.slice(startingpt+1,endpt)
	return filename
}

function switchcodediv(divid) {
	if (document.getElementById(divid).style.display=="none") {
		document.getElementById(divid).style.display='block'; 
		document.getElementById('img_'+divid).src='/images/flecheb.gif';
	}
	else {
		document.getElementById(divid).style.display='none'; 
		document.getElementById('img_'+divid).src='/images/fleched.gif';
	}
}

function openListenSound(wavid) {
	window.open('/servtel/getsound.php?path='+wavid,'Ecoute','menubar=no,scrollbars=no,status=no,resizable=no,width=300,height=60');
	
}

function openViewVideo(vidid) {
	window.open('/servtel/getvideo.php?path='+vidid,'Ecoute','menubar=no,scrollbars=no,status=no,resizable=no,width=300,height=300');
	
}


function deleteSound(thecode,thepath) {
	window.open('/servtel/delsound.php?code='+thecode+'&filename='+thepath,'Suppression','menubar=no,scrollbars=no,status=no,resizable=no,width=400,height=150');
}

function delcode(thecode,thename,indb) {
if (confirm('Etes vous sur de vouloir supprimer le code ' + thecode +' ?\n'+thename))
document.location='servtel/servtel.php5?pagename=gestioncodes&indb='+indb+'&delcode='+thecode;
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr,txtDescr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert(txtDescr+"Le format de la date doit être : jj/mm/aaaa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert(txtDescr+"Le mois entré n'est pas valide")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert(txtDescr+"Le jour entré n'est pas valide")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert(txtDescr+"L'année n'est pas valide, il faut entré les 4 chiffres d'une année")
		return false
		
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert(txtDescr+"Merci d'entrer une date valide")
		return false
	}
return true
}


