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.title != null)
		return e.title;
	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.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 = mensaje1;


	if (empty_fields) {
		msg += mensaje2 + empty_fields + "\n";

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

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


/////////////////////////////////////////////////
function valida_CUIT(numero)
{
	var i;
	var result = false;
	var cuit = new String(numero);
	var vector_ref = new String("5432765432");
	var ordenref=0;
	var suma = 0;
	var resto;
	var verificador

	for(i=0;i<(cuit.length);i++)
	{
		if(!isNaN(parseInt(cuit.charAt(i))))
		{
			if(ordenref<10)
			{
				suma = suma + (parseInt(cuit.charAt(i)) *
parseInt(vector_ref.charAt(ordenref++)));
			}
			else
			{
				if(ordenref == 10)
				{
					verificador=parseInt(cuit.charAt(i));
					ordenref++;
				}
				else
				{

					alert (mensaje3);
					return false;
				}
			}
		}
	}
	if(suma > 0)
	{
		resto = suma % 11;
		if (resto > 1)
		{
			resto = 11 - resto;
		}
		if( resto == verificador)
		{
			result = true;
		}
	}
	if(!result)
	{
		alert(mensaje4);
	}
	return result;
}
