// JavaScript Document

 var b = new Array();
 b[0] = new Image(); b[0].src = "images/valide.gif";
 b[1] = new Image(); b[1].src = "images/invalide.gif";

function changeSymboleValidation(page) {
	document.images[2].src = b[0].src;
	if ((page.elements["debut"].value=="") || (page.elements["fin"].value=="")) { document.images[2].src = b[1].src}
	else  { document.images[2].src = b[0].src }
	
}

function validerForme() {
if (document.images[2].src== b[0].src) {
	document.getElementById('formulaire').submit();
}
}

function setColor(obj, fg, bg)
{

  if (obj.style)
  {
    obj.style.color = fg;
    obj.style.backgroundColor = bg;
  }
}

function OpenPopUp(MyFile,MyWindow,MyWidth,MyHeight)
//MyFile :	  nom du fichier contenant le code HTML du pop-up
//MyWindow :	  nom de la fenêtre (ne pas mettre d'espace)
//MyWidth :	  entier indiquant la largeur de la fenêtre en pixels
//MyHeight :	  entier indiquant la hauteur de la fenêtre en pixels

{	  
var ns4 = (document.layers)? true:false; 	  //NS 4
var ie4 = (document.all)? true:false;	  //IE 4
var dom = (document.getElementById)? true:false;	  //DOM
var xMax, yMax, xOffset, yOffset;;	  

    if (ie4 || dom)
        {
        xMax = screen.width;
        yMax = screen.height;
        }
    else if (ns4)
        {
        xMax = window.outerWidth;
        yMax = window.outerHeight;
        }
    else
        {
        xMax = 800;
        yMax = 600;
        }
    xOffset = (xMax - MyWidth)/2;
    yOffset = (yMax - MyHeight)/2;
    window.open(MyFile,MyWindow,'width='+MyWidth
+',height='+MyHeight
+',screenX='+xOffset
+',screenY='+yOffset
+',top='+yOffset
+',left='+xOffset
+',scrollbars=yes,resizable=no,toolbar=0,location=no,status=no,menuBar=no,copyhistory=no,directories=no,close=no');
}

function setColor(obj, fg, bg)
{

  if (obj.style)
  {
    obj.style.color = fg;
    obj.style.backgroundColor = bg;
  }
}
// AJAX
function getResponse2(target, groupname, url) {
  AjaxRequest.get(
    {
      'url':url
	  ,'onSuccess':function(req){ document.getElementById(target).textContent=req.responseText; }
      ,'groupName':groupname                    // Assigns this request to the group passed in
      ,'onGroupBegin':AjaxRequestGroupBegin     // Map to the function called when this group starts
      ,'onGroupEnd':AjaxRequestGroupEnd         // Map to the function called when this group ends
 	  ,'onLoaded':AjaxRequestGroupLoading
   }
  );
}
// Simple functions to update the page
function makeActive(o) { o.innerHTML = "Active"; o.style.backgroundColor = "#00ff00"; }
function makeLoading(o) { o.innerHTML = "Loaded..."; o.style.backgroundColor = "#00ff00"; }
function makeInactive(o) { o.innerHTML = "Inactive"; o.style.backgroundColor = "#ff0000"; }

// Functions called by group begin/end
function AjaxRequestGroupBegin(groupName) {makeActive(document.getElementById("act"+groupName)); }
function AjaxRequestGroupEnd(groupName) { makeInactive(document.getElementById("act"+groupName)); }
function AjaxRequestGroupLoading(groupName) { makeLoading(document.getElementById("act"+groupName)); }









function fileDownload(url, div) {
	var maDiv=document.getElementById(div);
	maDiv.innerHTML = "<img src=\"images/bouttonFRAMUp.gif\" width=\"10\" height=\"10\" alt=\"e\" />";
	
	//maDiv.style.backgroundColor = "#00ff00";
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','14');
      //tempIFrame.setAttribute('onLoad',setupLoader('14'));
	  tempIFrame.setAttribute('src',url);
	  tempIFrame.setAttribute('DOM:Loaded', alert('loaded'));
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
//	ifrm.onload=setupLoader(this);
//	ifrm.src=url;
	maDiv.appendChild(tempIFrame);
	var image=document.createElement('img');
	image.setAttribute('src','images/bouttonPOPSUp.gif');
	tempIFrame.appendChild(image);
	//maDiv.innerHTML = "Inactive"; maDiv.style.backgroundColor = "#ff0000";
	//WaitStats4Checking(tempIFrame.id);
}

function WaitStats4Checking(ifrm){
	f=document.getElementById(ifrm);
	if (f.readyState == "complete"){
			alert(f.readyState);
	}
	else{
	setTimeout("WaitStats4Checking("+ifrm+")",50);
	}
}








var IFrameObj; // our IFrame object
function callToServer(url) {
  if (!document.createElement) {return true};
  var IFrameDoc;
  var URL = url;
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
}
function handleResponse(msg) {
  alert(msg)
}


//

function handleStateChange(frmid){
            alert("Changed"); 
            switch(document.getElementById('14').readyState)
            {
                case "complete":
					alert("complete");
                    toggleLoading(false);
                    break;
                case "loading":
					alert("loading");
					break;
                case "interactive":
                case "uninitialized":
                    toggleLoading(true);
                    break;
                default:
                    toggleLoading(false);
					alert("defaut");
                    break;
            } 
        }
        
        function setupLoader(frmid){ 
		alert('setuploader');
            var objIFrame = window.document.getElementById(frmid); 
            if (objIFrame.addEventListener) { 
                objIFrame.addEventListener('DOMContentLoaded', handleStateChange, false);
				alert('addEventListener');
            }else if (objIFrame.attachEvent) {
				alert('attachEvent');
                objIFrame.attachEvent ('onreadystatechange',handleStateChange);
            }else{
				alert('onclose');
                objIFrame.onclose=temp(); 
            } 
        } 
        
        function toggleLoading(isVisible)
        {
			alert(isVisible);
            objProgress = document.getElementById("14");
            if(isVisible)
            {
                objProgress.style.display = "block";
            }
            else
            {
                objProgress.style.display = "none";
            }
        }
	

function contient() {
	var contents=document.getElementById('14').content.length;
	alert(contents);
	return;
	alert('found contents of myiframe:' + contents);alert(document.getElementById('14').status);
	if(contents){
		alert('found contents of myiframe:' + contents);
			if(contents.documentElement){
				if(contents.documentElement.innerHTML){
					alert("Found contents: " +contents.documentElement.innerHTML);
					if(contents.documentElement.innerHTML.indexOf("Content-Type") > -1){
						openMediumWindow("woot.html", "mypopup");
					}
				}
			}
	}
}