// JavaScript Document

function sendForm(idioma, script)
{
	var php = (script=='CLUB' ? 'phplib/ClubAlta_ajx.php' : 'phplib/DonacioAlta_ajx.php');
	$("specialMessage").innerHTML = '';
	
	if (ValidarForm(idioma))
	{
		$("Enviar").disabled = 1;
		
		$Ajax(php, {metodo: $metodo.POST, tipo: $tipo.TEXTO, avisoCargando: 'peticio_ajax', parametros: $("form_info").serialize(), onfinish: formSent});
	}
}

function formSent(text)
{
	$("legal").checked = 0;
	$("specialMessage").innerHTML = text;
	
}

function CapitalizeText(obj,id)
{
    obj = obj.toLowerCase();
	c = obj.substr(0,1).toUpperCase();
	obj = c + obj.substr(1, obj.length-1);
	
	for (i=1; i<obj.length; i++)
	{
		if (obj.substr(i,1)==' ')
		{
			c = obj.substr(i+1,1).toUpperCase();
			obj = obj.substr(0,i+1) + c + obj.substr(i+2, obj.length-i-2);
		}
	}
			
    document.getElementById(id).value = obj;
}

function ValidarForm (idioma)
{
	var frm = document.forms['form_info'];

	if ((frm['nom'].value.length>0) && (frm['cognom1'].value.length>0) && (frm['nif'].value.length>0) && (frm['email'].value.length>0) && (frm['genere'].selectedIndex>0) && (frm['datanaix'].value.length>0) && (frm['domicili'].value.length>0) && (frm['poblacio'].value.length>0) && (frm['cp'].value.length>0))
		return true;
	else
	{
		$("specialMessage").innerHTML =  (idioma=='ca' ? "Formulari incomplet. Revisi, si us plau, els camps obligatoris." : "Formulario incompleto. Revise, por favor, los campos obligatorios.");
		return false;
	}
}

function loadEquips(edicio)
{
	var esport = $F("lstEsports");

	$Ajax("phplib/Programacio_Equips_fns.php", {metodo: $metodo.GET, tipo: $tipo.JSON, parametros: "Edicio=" + edicio + "&Esport=" + esport, onfinish: equipsRebuts});

}

function equipsRebuts (text)
{
	var resposta = eval("(" + text + ")");
	
	$("lstEquips").disabled= 0;
	$("lstEquips").length = resposta.Equips.length;
	
	for (i=0;i<resposta.Equips.length;i++)
	{
		$("lstEquips").options[i]=new Option(resposta.Equips[i][1], resposta.Equips[i][0]);
	}

	$("botNIF").disabled = 1;
	$("botEQP").disabled = 0;
	$("botCIF").disabled = 1;
	
	$("txtNIF").value = '';
	$("txtCIF").value = '';

}

function onFocusNIF ()
{
	$("txtCIF").value = "";
	$("lstEsports").value = "   ";
	
	$("botNIF").disabled = 0;
	$("botEQP").disabled = 1;
	$("botCIF").disabled = 1;

	$("lstEquips").disabled = 1;
}

function onFocusCIF ()
{
	$("txtNIF").value = "";
	$("lstEsports").value = "   ";

	$("botNIF").disabled = 1;
	$("botEQP").disabled = 1;
	$("botCIF").disabled = 0;

	$("lstEquips").disabled = 1;
}

function onFocusEQP ()
{
	$("botEQP").disabled = 0;
}

function arreglarCIF_NIF ()
{
	$("txtNIF").value = $F("txtNIF").replace('-', '').toUpperCase();
	$("txtCIF").value = $F("txtCIF").replace('-', '').toUpperCase();
	
	return true;
}



