
/**
 *	Canvia el color de fons i els textos inicials dels inputs quan hi ha els events focus i blur
 *
 *	@param (string) sId ID de l'input
 *	@param (string) sEvent Tipus d'event (focus o blur)
 *	@param (string) content Text inicial de l'input
 */
function focusInputText(sId, sEvent, content)
{
	var obj = document.getElementById(sId);
	if (!obj) return;
	if (sEvent == "focus"){
		obj.setAttribute("class", "textFocus");
		obj.setAttribute("className", "textFocus");
		if (obj.value == content) {
			obj.value = "";
		}
	}
	else if (sEvent == "blur"){
		obj.setAttribute("class", "text");
		obj.setAttribute("className", "text");
		if (obj.value == "") {
			obj.value = content;
		}
	}
}
function focusInputPassword(sId, sEvent, content)
{
	var obj = document.getElementById(sId);
	var obj_visible = document.getElementById(sId+"_visible");
	if (!obj) return;
	if (sEvent == "focus")
	{
		obj_visible.style.display = "none";
		obj.style.display = "inline";
		obj.focus();

		obj.setAttribute("class", "textFocus");
		obj.setAttribute("className", "textFocus");
		if (obj.value == content) {
			obj.value = "";
		}
	}
	else if (sEvent == "blur")
	{
		obj.setAttribute("class", "text");
		obj.setAttribute("className", "text");
		if (obj.value == "")
		{
			obj_visible.style.display = "inline";
			obj.style.display = "none";

			//obj.value = content;
		}
	}
}
function focusInputTextarea(sId, sEvent, content)
{
	var obj = document.getElementById(sId);
	if (!obj) return;
	if (sEvent == "focus"){
		obj.setAttribute("class", "textFocus");
		obj.setAttribute("className", "textFocus");
		if (obj.value == content) {
			obj.value = "";
		}
	}
	else if (sEvent == "blur"){
		obj.setAttribute("class", "text");
		obj.setAttribute("className", "text");
		if (obj.value == "") {
			obj.value = content;
		}
	}
}


function focusInputData(sId, sEvent, content, extraClass)
{
	var obj = document.getElementById(sId);
	if (!obj) return;
	if (sEvent == "focus"){
		obj.setAttribute("class", "inputDataFocus "+extraClass);
		obj.setAttribute("className", "inputDataFocus "+extraClass);
		if (obj.value == content) {
			obj.value = "";
		}
	}
	else if (sEvent == "blur"){
		obj.setAttribute("class", "inputData "+extraClass);
		obj.setAttribute("className", "inputData "+extraClass);
		if (obj.value == "") {
			obj.value = content;
		}
	}
}


function boldText(idComp)
{
	document.execCommand("bold", false, null);
	if(navigator.appName=="Microsoft Internet Explorer")
		document.getElementById("editor").focus();
	passaText(idComp);
}
function italicsText(idComp)
{
	document.execCommand("italic", false, null);
	if(navigator.appName=="Microsoft Internet Explorer")
		document.getElementById("editor").focus();
	passaText(idComp);
}
function linkText(idComp)
{
	uri=promptSafe(idma["introduce direccion"],"");
	if(uri=="")
	{
		if(navigator.appName=="Microsoft Internet Explorer")
			document.getElementById("editor").focus();
		return;
	}

	document.execCommand("createlink", false, uri);
	if(navigator.appName=="Microsoft Internet Explorer")
		document.getElementById("editor").focus();
	passaText(idComp);
}

function passaText(idComp)
{
	document.getElementById(idComp).value = document.getElementById("editor_"+idComp).innerHTML;
}

var FormsComponents = Array();
function submitForm(idForm)
{
	// Reseguim tots els fills per esborrar el text inicial dels camps (Treure els valors per defecte)
	// Els components estan a FormsComponents
	if(typeof FormsComponents[idForm] != "undefined"){
		for(var i=0; i<FormsComponents[idForm].length; i++)
		{
			//alert(FormsComponents[idForm]["compId"]);
			var comp = document.getElementById(FormsComponents[idForm][i]["compId"]);
			/*if(!comp){
				alert(FormsComponents[idForm][i]["compId"]);
			}*/
			if(comp && comp.value == FormsComponents[idForm][i]["defVal"])
			{
				comp.value = "";
			}
		}
	}

	var frm = document.getElementById("form_" + idForm);
	frm.style.display = "none";
	document.getElementById("tictactoe_" + idForm).style.display = "block";
//	goTO("tictactoe_" + idForm);
//	document.getElementById("form_" + idForm).submit();
}
function goTO(nameAnchor)
{
	//alert("TODO: a forms.js, acabar d'arreglar problemes amb #");
	//alert("TODO: Els problemes venen el segon cop que es fa submit!");
	var fixurl;
	if(window.location.hash){
		fixurl = window.location.href.replace( /.+#(.*)/, nameAnchor);
	}
	else {
		fixurl = window.location + "#" + nameAnchor;
	}
	//alert(fixurl);
	window.location = fixurl;
}

var IdFormulariSubmit = "";
function enviaCasilla(str,obj, idFormulari)
{
	obj.style.backgroundImage="url("+nh+"img/x-rojo.gif)";
	obj.style.backgroundRepeat="no-repeat";
	obj.style.backgroundPosition="center";
	inpt=document.getElementById("casilla").value=str;
	tempstr=rand.replace("/","_");
	var aleatorio=aleat();
	var uri="action=enviaCasilla&rand="+tempstr+"&casillaCorrecta="+aleatorio+"&casilla="+str;
	consultaHttp(PROCESS_PATH+"process3enraya.php",uri);
	IdFormulariSubmit = idFormulari;
}
function tractaEnviaCasilla(xmldoc)
{
	if(html_unescape(xml_unescape(xml_consultaDada(xmldoc.getElementsByTagName('envio').item(0))))=="correcto")
	{
		if(IdFormulariSubmit != ""){
			document.getElementById(IdFormulariSubmit).submit();
			IdFormulariSubmit = "";
			return;
		}
	}
	else
	{
		rand=html_unescape(xml_unescape(xml_consultaDada(xmldoc.getElementsByTagName('rand').item(0))));
		document.getElementById("rand").value=rand;
		var tablero=xmldoc.getElementsByTagName('fila');
		for(i=0;i<tablero.length;i++)
		{
			var j=0;
			while(j<3)
			{
				var valor=xml_unescape(xml_consultaDada(tablero[i].getElementsByTagName('casilla').item(j)));
				if(valor==1)
				{
					document.getElementById("id_"+i+"-"+j).style.backgroundImage="url("+nh+"img/x-rojo.gif)";
					document.getElementById("id_"+i+"-"+j).innerHTML="";
				}
				else if(valor==2)
				{
					document.getElementById("id_"+i+"-"+j).style.backgroundImage="url("+nh+"img/cero.gif)";
					document.getElementById("id_"+i+"-"+j).innerHTML="";
				}
				else
				{
					document.getElementById("id_"+i+"-"+j).innerHTML="";
					document.getElementById("id_"+i+"-"+j).style.backgroundImage="";
					document.getElementById("id_"+i+"-"+j).innerHTML="<a href='javascript:void(0);' onClick='enviaCasilla(\""+i+"-"+j+"\",this, \""+IdFormulariSubmit+"\");' class='tresenraya'></a>";
				}
				j++;
			}
		}
	}
}
