function openwindow(url,name,width,height,ptop,pleft)
{
	window.open(url,name,'toolbar=0,menubar=0,scrollbars=yes,resizable=0,width=' + width + ',height=' + height + ',top=' + ptop + ',left=' + pleft);
}

function popup(url,name,width,height)
{
	pleft = (window.screen.availWidth - width) / 2;
	ptop = (window.screen.availHeight - height) / 2;
	openwindow(url,name,width,height,ptop,pleft);
}

function loaded(color)
{
	if (typeof(color) != "undefined") color = color;
	else color = "red";
	document.getElementById("nowLoading").innerHTML = "<font color='"+ color +"'>TRAITEMENT EN COURS</font>";
}

function verif(form,color)
{
	if(eval('document.'+form+'.entreprise'))
	{
		if( eval('document.'+form+'.entreprise.value') == "" )
		{
			alert("Vous n'avez pas saisi de nom d'entreprise");
			eval('document.'+form+'.entreprise.focus()');
			return;
		}
	}
	if(eval('document.'+form+'.nom'))
	{
		if( eval('document.'+form+'.nom.value') == "" )
		{
			alert("Vous n'avez pas saisi de nom");
			eval('document.'+form+'.nom.focus()');
			return;
		}
	}
	if(eval('document.'+form+'.mail'))
	{
		var email = eval('document.'+form+'.mail.value');
		if(email.indexOf("@") == "-1" || email.indexOf(".") == "-1" || email == "")
		{
			alert("Vous n'avez pas saisi d'email");
			eval('document.'+form+'.mail.focus()');
			return;
		}
	}
	if(eval('document.'+form+'.tel'))
	{
		tmp = eval('document.'+form+'.tel.value');
		if( tmp == "" || IsNumeric(tmp) == false || tmp.length < 10 )
		{
			alert("Vous n'avez pas saisi de numéro de téléphone");
			eval('document.'+form+'.tel.focus()');
			return;
		}
	}
	if(eval('document.'+form+'.message'))
	{
		if( eval('document.'+form+'.message.value') == "" )
		{
			alert("Vous n'avez pas saisi de message");
			eval('document.'+form+'.message.focus()');
			return;
		}
	}
	if(eval('document.nowLoading'))
	{
		loaded();
	}
	eval('document.'+form+'.submit()');
}

// check for valid numeric strings
function IsNumeric(strString)
{
	var strValidChars = "0123456789.- ";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;
	
	// test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) blnResult = false;
	}
	return blnResult;
}

function change_produit(id)
{
	if (typeof(id) != "undefined") valeur = id;
	else valeur = document.form.id_produit.value;
	if (valeur != -1) document.location="produits_fiche.php?id_produit=" + valeur;
}
