﻿// JavaScript Document
function makeRequest(url, div) {
	if (!param)
	{
	var param = "";
	}
	var httpRequest = false;
	//alert(url);
	if (window.XMLHttpRequest) {
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) {
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
	}
}

	if (!httpRequest) {
		alert('Abandon :( Impossible de créer une instance XMLHTTP');
		return false;
	}
	var resultat = url.match(/\?/);
	var resultat2 = url.match(/\=/);
	
	if (resultat)
	{
		if (resultat2)
		{
			var url = url + "&d=" + (new Date()).getTime();
		}
		else
		{
			var url = url + "d=" + (new Date()).getTime();
		}
	}
	else
	{	
		var url = url + "?d=" + (new Date()).getTime();
	}
	
	httpRequest.onreadystatechange = function() { alertContents(httpRequest,div,url); };
	httpRequest.open('GET', url, true);
	httpRequest.send(null);
}

function alertContents(httpRequest,id,url)
	{
	
	if (httpRequest.readyState == 4)
		{
		if (httpRequest.status == 200)
			{
			document.getElementById(id).innerHTML = httpRequest.responseText;
			}
		else
			{
			alert('Un problème est survenu avec la requête.');
			}
		}
		if (httpRequest.readyState == 4) {
			if ((id == 'num' || id == 'cis')||(id == 'date' || id == 'etat'))  {
				if (document.getElementById('cnum'))
				{
				document.getElementById('cnum').focus();
				}
			}
		if (url == 'menu.php?act=ajouter')
			{
			initautosuggest();
			}
		}
	}

function recherchefocus() {
	document.getElementById('cnum').focus();
}

function get(obj)
	{
	var getstr = "&";
	for (i=0; i<obj.childNodes.length; i++)
		{
		if (obj.childNodes[i].tagName == "input")
			{
			if (obj.childNodes[i].type == "text")
				{
				getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
				}
			if (obj.childNodes[i].type == "checkbox")
				{
				if (obj.childNodes[i].checked)
					{
					getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
					}
				else
					{
					getstr += obj.childNodes[i].name + "=&";
					}
				}
			if (obj.childNodes[i].type == "radio")
				{
				if (obj.childNodes[i].checked)
					{
					getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
					}
				}
			}
		if (obj.childNodes[i].tagName == "select")
			{
			var sel = obj.childNodes[i];
			getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
			}
		}
		return getstr;

	}
	
function testform() 
	{
	if(document.getElementById('cis_id').value!="")
		if(document.getElementById('interv').value!="")
			return true;
	 alert("Formulaire incomplet ! (CIS et Intervenant obligatoire !)");
	 return false;
    }
	
function test(f) {
         if(f.nom.value!="")
			if(f.prenom.value!="")
				if(f.teld.value!="")
					return true;
         alert("Formulaire incomplet !");
         return false;
      }	

