/* JavaScript Document. summoned by index.php */

function emptyBox(id)
{
	if(document.forms['qcmCreator'].elements[id].value == "Tapez ici la question..." || document.forms['qcmCreator'].elements[id].value == "Tapez ici une reponse...")
	{
		document.forms['qcmCreator'].elements[id].value = "";
	}
}

function goTo(url)
{
	window.location.href = url;
}

function setFocus(id, element)
{
	if(!element)
	{
		document.getElementById(id).focus();
	}
	else
	{
		document.forms[id].elements[element].focus();
	}
}

function setSelection(form, element)
{
	document.forms[form].elements[element].select();
}

function submitForm(formName)
{
	document.forms[formName].submit();
}

function validateBackUp(id)
{
	document.forms['restore'].backUpId.value = id;
	submitForm('restore');
}

document.onmousemove = setXY;

function mouseX(evt)
{
	if (evt.pageX) 
	{
		return evt.pageX;
	}
	else if (evt.clientX)
	{
		return evt.clientX + (document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
	}
	else return null;
}

function mouseY(evt)
{
	if (evt.pageY)
	{
		return evt.pageY;
	}
	else if (evt.clientY)
	{
		return evt.clientY + (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
	}
	else return null;
}

function setXY(evt)
{
	X = mouseX(evt);
	Y = mouseY(evt);
}

function hover(id, forceSet)
{
	var className = document.getElementById(id).className;
	var index = className.indexOf('Hover');
	if(index === -1 && (!forceSet || forceSet=='y'))
	{
		document.getElementById(id).className = className+" "+className+"Hover";
	}
	else if(index !== -1 && (!forceSet || forceSet=='n'))
	{
		var spacePos = className.indexOf(' ');
		document.getElementById(id).className = className.substring(0, spacePos);
	}
}

function disableBox(form, element, forceSet)
{
	if(!forceSet)
	{
		document.forms[form].elements[element].disabled = !document.forms[form].elements[element].disabled;
	}
	else
	{
		document.forms[form].elements[element].disabled = (forceSet=='y')?true:false;
	}
	if(document.getElementById(element+'Delete'))
	{	
		hover(element+'Delete', forceSet);
	}
	return document.forms[form].elements[element].disabled?'y':'n';
}
function disableDiv(id, forceSet)
{
	var className = document.getElementById(id).className;
	var index = className.indexOf('Disabled');
	if(index === -1 && (!forceSet || forceSet=='y'))
	{
		document.getElementById(id).className = className+"Disabled";
	}
	else if(!forceSet || forceSet=='n')
	{
		document.getElementById(id).className = className.replace(/Disabled/g, "");
	}
	return (document.getElementById(id).className.indexOf('Disabled')===-1)?'n':'y';
}
function setBoxDisplay(id, forceSet)
{
	if(!forceSet)
	{
		document.getElementById(id).style.display = (document.getElementById(id).style.display=='none')?'':'none';
	}
	else
	{
		document.getElementById(id).style.display = (forceSet=='y')?'':'none';
	}
}

function concatenateKeyWords(keywords)
{
	return keywords.replace(/ /g, '+');
}

function replaceInnerText(id, newText)
{
	document.getElementById(id).innerHTML = newText;
}