function setFileName(theForm, input, valor)
{
	if ( (input == null) || (input == "") ||
		 (valor == null) || (valor == "") )
		return;

	var aspl = valor.split("\\");
	var str;

	document.form.encoding = "multipart/form-data";
	document.form.action = "{POST}abm_det.asp?tabla={TABLA}&id={ROW_ID}&volver={VOLVER}&preset={PRESET}";
	str = "";

	if (aspl.length > 0) {
		str = aspl[aspl.length - 1];
	}
	var p = 'theForm.' + input.substr(2) + '.value="' + str + '"';
	eval(p);
}

function isblank (o)
{
	if (o == null) return true;
		
	var s;
	s = o.value;

	if ((s == null) || (s == ""))
		return true;

	for (var i=0;i<s.length;i++) {
		var c = s.charAt(i);
		if (o.type == "select") 
		{
			if (o.options[o.selectedIndex].value == "") return false;  
		} else {
			if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
		}
	}
	return true;
}



/////////////////////////////////////////////////////////////////////
function checkRequiredOK(e)
{
	if (((e.type == "text") ||
		(e.type == "textarea") ||
		(e.type == "password") ||
		(e.type == "select-one")) && 
		!e.optional)
	{
		if (isblank(e) || (e.type == "select-one" && e.value == 0))
		{
			return false;
		}
	}
	
	return true;
}

function getName(e)
{
	if (e.nombre != null)
		return e.nombre;
	else
		return e.name;
}
/////////////////////////////////////////////////////////////////////
function verify(f)
{
	var msg;
	var empty_fields = "";
	var errors = "";
	
	for (var i=0;i<f.length;i++) 
	{
		var e = f.elements[i];
		
		if (!checkRequiredOK(e))
		{
			if (empty_fields == "")
			{
				f.elements[i].focus();
				empty_fields = "\n";
			}

			empty_fields += "\n- " + getName(e);
			continue;
		}
			
		
		if (e.name == "tel") {

			nrotelef = e.value;
			permitidos = "(0123456789)-+ ";

			for (var m=0; m < nrotelef.length;m++){
				actual = nrotelef.charAt(m);
				if(permitidos.indexOf(actual) == -1){
						errors+="El teléfono es erróneo.";
						break;
				}
			}
		}
		
		
		if (e.date && !isblank(e))
		{
			var d = e.value.split("-");
			var error;
			error = '';

			if ((e.length < 8) || (d.length != 3) ||
				isNaN(parseFloat(d[0])) ||
				isNaN(parseFloat(d[1])) ||
				isNaN(parseFloat(d[2])) ||
				(d[0] < 1) || (d[0] > 31) ||
				(d[1] < 1) || (d[1] > 12) ||
				(d[2] < 1900)) {

				if (errors == "") 
				{
					f.elements[i].focus();
					errors = "\n";
				}
				errors += "\n- " + "Fecha incorrecta: " + getName(e) + ". El formato es dd-mm-aaaa.";
			}
		}
		
		if (e.numeric || (e.min != null) || (e.max != null))
		{
			if (isblank(e)) 
				continue;
			var v = parseFloat(e.value);
			if (isNaN(v) ||
				((e.min != null) && (v < e.min)) ||
				((e.max != null) && (v > e.max))) {

				if (errors == "") 
				{
					f.elements[i].focus();
					errors = "\n";
				}

				errors += "- El campo " + getName(e) + " debe ser numérico.";

				if (e.min != null)
					errors += " mayor que " + e.min;
				if (e.max != null && e.min != null)
					errors += " y menor que " + e.max;
				else if (e.max != null)
					errors += " menor que " + e.max;
				errors += ".\n";
			}
		}
	}

	if (!empty_fields && !errors) return true;

	msg = "Se detectaron los siguientes errores. Por favor corríjalos e intente nuevamente.\n\n";

	if (empty_fields) {
		msg += "Los siguientes campos obligatorios están vacíos: " + empty_fields + "\n";

		if (errors) msg += "\n";
	}

	msg += errors;
	alert(msg);
	return false;
}