function popup(page, PWidth, PHeight)
{
	popUp = window.open(page, 'popup1', 'toolbar=0,scrollbars=1,location=0,status=0,menubars=0,resizable=1,width='+PWidth+',height='+PHeight);
	popUp.window.moveTo((screen.width/2)-(parseInt(PWidth)/2), (screen.height/2)-(parseInt(PHeight)/2));
	popUp.window.focus();
}

function focusFirstField()
{
	$(":input:first").focus().select();
}

function updateClass(table)
{
	table.each(function(i) {
		if ($(this).hasClass("Editeur_Ligne") || $(this).hasClass("Editeur_Ligne2")) {
			$(this).removeClass("Editeur_Ligne").removeClass("Editeur_Ligne2").addClass((i - 1) % 2 == 0 ? "Editeur_Ligne" : "Editeur_Ligne2");
		}
	});
}

function boutonAjouter()
{
	// Bouton "ajouter
	$("#btnAjouter").css("cursor", "pointer");
	$("#btnAjouter").click(function() {
		//$("#ligneAjouter").show("slow");
		//$(this).hide();
		$("#ligneAjouter").css("display", "");
		$(this).parent().html("&nbsp;");
	});
}

function boutonEffacer()
{
	$(".btnEffacer").css("cursor", "pointer");
	$(".btnEffacer").click(function() {
		if (confirm(confDel))
		{
			var iDelete = $(this).attr("id").replace("effacer", "");
			$.post("effacerLigne.php", {i: iDelete});

			var tmp = $(this).parent().parent().parent();

			// efface le <tr>
			$(this).parent().parent().remove();

			updateClass( tmp.children() );
		}
	});
}

function num(control, e, decimal)
{
	var posPoint = 0;
	var decimalTmp = 0;
	var str = control.value;
	
	if(window.event) // IE
		var keynum = e.keyCode
	else
		var keynum = e.which

	var invalidDecimal = true;
	var okTopDecimal = false;
	
	if(decimal && (keynum == 46))
	{
		invalidDecimal = false;
		for (position = 0; position < str.length; position++)
		{
	   		chr = str.charAt(position)
	   		if (chr == ".")
			{
				invalidDecimal = true;
			}
		}
	}
	if(decimal)
	{
		for (position = 0; position < str.length; position++)
		{
			chr = str.charAt(position)
			if (chr == ".")
			{
				posPoint = position;
			}
			
			if (posPoint > 0)
			{
				decimalTmp = decimalTmp + 1;
				if(decimalTmp > decimal)
				{
					okTopDecimal = true;
				}
			}
		}
	}
	
	//si pas chiffre, backspace, delete, point ou virgule
	if (((keynum < 48) || (keynum > 57)) && (keynum != 0) && (keynum != 8) && invalidDecimal)
	{
		if(window.event) // IE
			event.returnValue = false;
		else
			e.preventDefault();
	}
	
	if(okTopDecimal && (keynum != 0) && (keynum != 8))
	{
		if(window.event) // IE
			event.returnValue = false;
		else
			e.preventDefault();
	}
}

function makeRequest(url, retHtml, champ) 
{
    http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
            // See note below about this line
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    http_request.open('GET', url, false);
    http_request.send(null);

	  if (http_request.status != 200)
	  {
	    r = "There was a problem with the request:";
	    alert(r + "\n\n" + http_request.statusText);
	  }
	  else if(retHtml)
	  {
	    return http_request.responseText;
	  }
	  else if(champ != '')
	  {
		document.getElementById(champ).innerHTML = http_request.responseText;
	  }
	  else
	  {
	    return true;
	  }
}


