//semaphor variables
var submittingBasket = false;
var submittingOrder = false;

// Submit the form after modifying, validating or deleting the basket
function submitBasket (action)
{
	if (submittingBasket == false)
	{
		submittingBasket = true;
		document.forms.basketForm.task.value = action;
		document.forms.basketForm.submit();
	}
}

// Submit the order from the results list
function submitOrder ()
{
	if (submittingOrder == false)
	{
		submittingOrder = true;
		document.forms.orderList.submit();
	}
}

function submitForm (formName)
{
	document.forms[formName].submit();
}

function confirmSending ()
{
	if (document.getElementById("errorSending"))
	{
		document.getElementById("errorSending").style.display = "none";
	}
	document.getElementById("formSending").style.display = "none";
	document.getElementById("confirmSending").style.display = "block";
	return false;
}

function cancelSending ()
{
	if (document.getElementById("errorSending"))
	{
		document.getElementById("errorSending").style.display = "none";
	}
	document.getElementById("formSending").style.display = "block";
	document.getElementById("confirmSending").style.display = "none";
}

function validateSending ()
{
	document.forms.sendStatement.submit();
}

function openContactWindow ()
{
	window.open ("contacterHorizon.html", "contactHorizon", config="height=550, width=700, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no, top=190, left=230");
	return false;
}

function openHelpWindow (page, hauteur, scroll)
{
	window.open (page, "helpCelf", config="height="+hauteur+", width=750, toolbar=no, menubar=no, scrollbars="+scroll+", resizable=no, location=no, directories=no, status=no, top=190, left=230");
	return false;
}

var ns6=document.getElementById&&!document.all

function restrictinput (maxlength, e, placeholder)
{
	if (window.event && event.srcElement.value.length >= maxlength)
		return false
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength)
	{
		var pressedkey=/[a-zA-Z0-9\.\,\/]/ 
		if (pressedkey.test(String.fromCharCode(e.which)))
			e.stopPropagation()
	}
}

function countlimit(maxlength,e,placeholder)
{
	var theform=eval(placeholder)
	var lengthleft = maxlength - theform.value.length
	if (lengthleft < 0)
	 lengthleft = 0
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder))
	{
		if (lengthleft<=0)
			theform.value = theform.value.substring(0,maxlength)
		placeholderobj.innerHTML=lengthleft
	}
}

function displaylimit(thename, theid, thelimit)
{
	var theform=theid!=""? document.getElementById(theid) : thename
	var limit_text='<span id="'+theform.toString()+'">'+thelimit+'</span> caract&egrave;res restants / <i>characters left</i>'
	if (document.all||ns6)
		document.write(limit_text)
	if (document.all)
	{
		eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
		eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
	}
	else if (ns6)
	{
		document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
		document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
	}
}

