function str2Array(lista,separador)
{
	var campo = "";
	var MyArray = new Array()
	  
	for (var c=0;c<lista.length;c++){
		if(lista.substr(c,1) == separador){ MyArray.push(campo);campo="";}
	  else campo = campo + lista.substr(c,1);
	}
	MyArray.push(campo);
	
	
	return MyArray;
}

function Validacion(form,lista)
{	
		//alert("Entra ValidaForm: " + form + "-"+lista);
		var MyArray = new Array();
		MyArray=str2Array(lista,'|')

		var CamposKo = "";
		var strRazon = "";
		var Cont = 0;
		//alert("MyArray.length:" + MyArray.length);
		for (c=0;c<MyArray.length;c++)
		{
			var MyCampo = new Array();
			MyCampo=str2Array(MyArray[c],';')
			var strTipo = MyCampo[0].substr(0,3);
			var el = null;
			var strTituloCampo = "";
		
			//expresion regular emails
			var reg_exp=/^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/
		
			// instancio el objeto actual
			el = document.getElementById(MyCampo[0]);
			//el = form[MyCampo[0]];
			//alert(MyCampo[0] + "-" + el);
		
			// defino el ttulo por si el valor no corresponde
			if(MyCampo.length == 1)
				strTituloCampo = MyCampo[0].substr(3,(MyCampo[0].length - 3));
			else
				strTituloCampo = MyCampo[1];
				
			strTituloCampo = strTituloCampo.replace("_"," ");
			
			// empiezo a comprovar campos
			if(strTipo == "txt" || strTipo == "pwd" )    // texto obligatorio
			{
				if( (el.value.length<1))
				{
					CamposKo += strTituloCampo + strRazon + "\n";
				}
			}
			else if(strTipo == "int")  	     // es un nmero
			{
				if (isNaN(el.value) || el.value.length == 0)    //el mtodo "isNaN" comprueba si el valor No es un nmero
				{
					CamposKo += strTituloCampo + Traducciones(intIdIdioma, 6) + strRazon + "\n";
				}
			}
			else if(strTipo == "eml")       // es un email
			{
				if(!reg_exp.test(el.value))
				{
					CamposKo += strTituloCampo + Traducciones(intIdIdioma, 5) + strRazon + "\n";
				}
			}
			else if(strTipo == "rdo")       // es un Radio
			{
				var blnObjSelected = false;
				
				for(var i=0;i<el.length;i++)
				{
					if(el[i].checked == true) blnObjSelected = true;
				}
				
				if(!blnObjSelected) CamposKo += strTituloCampo + Traducciones(intIdIdioma, 3) + strRazon + "\n";
			}
			else if(strTipo == "cbo")       // es un ComboBox
			{
				if(el.selectedIndex < 1 ) CamposKo += strTituloCampo + Traducciones(intIdIdioma, 4) + strRazon + "\n";
			}
			else if(strTipo == "chk")       // es un Checkbox
			{
				if(!el.checked) CamposKo += strTituloCampo + strRazon + "\n";
			}
			
			strRazon = "";
		}
			
		if(CamposKo != "")
		{
			var msg = Traducciones(intIdIdioma, 1) + CamposKo + Traducciones(intIdIdioma, 2);
			alert(msg);
			return false;
		}
		else
		{
			//var el = document.getElementById(document.Form[0].name);
			//el.submit();
			return true;
		} 
}

function ExisteCadena(strCadena,strCaracter){
	var devuelve = false;
	for (c=0;c<strCadena.length;c++){
		if(strCadena.substr(c,1) == strCaracter){
		devuelve = true;
		 c = strCadena.length;
	  }     
	}
	return devuelve
}

function Traducciones(IdIdioma, intFrase)
{
	var traducciones = new Array(2);
	traducciones[0] = new Array(6);
	traducciones[1] = new Array(6);

	traducciones[0][0] = "ATENCIÓN!\nLos siguientes campos son obligados: \n\n";
	traducciones[0][1] = "\n\nRectifique por favor.";
	traducciones[0][2] = " (tiene que seleccionar una opción)";
	traducciones[0][3] = " (tiene que seleccionar una opción)";
	traducciones[0][4] = " (no válido)";
	traducciones[0][5] = " (número no válido)";
	
	traducciones[1][0] = "ATENCIÓ!\nEls segents camps son obligats: \n\n";
	traducciones[1][1] = "\n\nRectifiqui si us plau.";
	traducciones[1][2] = " (ha de seleccionar una opció)";
	traducciones[1][3] = " (ha de seleccionar una opció)";
	traducciones[1][4] = " (no válid)";
	traducciones[1][5] = " (número no válid)";
	
	return traducciones[IdIdioma - 1][intFrase - 1];

}