function salto(lala){
	url = document.location.href ;                          
	// División en trozos con la barra como delimitador.    
	partes = url.split('/');                                
	// Obtención del nombre de la página y sus parámetros.                    
	document.getElementById(lala).action=partes[partes.length-1];
	document.getElementById(lala).submit();
}

function ocultaTabla(lala,lala2,limit){
	imgMas = new Image(8,8);
	imgMas.src='imagenes/ico_abrir.gif';
	imgMenos = new Image(8,8);
	imgMenos.src='imagenes/ico_menos.gif';
	
	if(document.getElementById(lala).style.display=='none'){
		for(i=1;i<=limit;i++) {
			if(i<10){
				document.getElementById('tabla_0'+i).style.display='none';
				document.getElementById('img_0'+i).src=imgMas.src;
			}
			else {
				document.getElementById('tabla_'+i).style.display='none';
				document.getElementById('img_'+i).src=imgMas.src;
			}
		}
		document.getElementById(lala).style.display='block';
		document.getElementById(lala2).src=imgMenos.src;
	}
	else {
		document.getElementById(lala).style.display='none';
		document.getElementById(lala2).src=imgMas.src;
	}
}

function ocultaTabla2(id){
	if(document.getElementById(id).style.display=='none'){
		document.getElementById(id).style.display='block';
	}
	else {
		document.getElementById(id).style.display='none';
	}
}

function LlamarAjaxx(dir,div)
{
	aj1 = new ajax();
	aj1.get(dir,div);
}
function BlanquearAjaxx(div)
{
	aj1 = new ajax();
	aj1.limpiar(div);
}

function LlamarAjaxxPost(dir,datos,div){
	aj1 = new ajax();
	aj1.post(dir,datos,div);
}

function $v(id){
	return document.getElementById(id).value;
}

function validar_entero(valor){
	var numero = parseInt(valor);
	
	if(isNaN(valor)){
		numero = 0;
		alert("debe ser un valor entero");
	}
	else if(numero!=valor) alert("el numero fue simplificado");
	
	return numero;
}
function validar(cadena,nombre_reales){
	var array=cadena.split(",");
	var array_2=nombre_reales.split(",");
	var pasa = true;
	for (x=0;x<array.length;x++){
		if(($v(array[x])=='' || $v(array[x])=='0')&& pasa == 1) { 
			alert('Complete el campo '+array_2[x]+'. ');
			pasa = false;
		}
	}
	return pasa;
}

function cambio_action(id,direccion){
	document.getElementById(id).action=direccion;
	document.getElementById(id).submit();
}

function validar_mail(valor)
{
	//filtro viejo: /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		return (true);
	} else {
		alert('La direccion de email es incorrecta.');
		return (false);
	}
}

function validar_hibrido(cadena,nombre_reales,mail){
	var pasa = false;
	if(validar_mail(mail)){
		pasa = validar(cadena,nombre_reales)
	}
	return pasa;
}

function validar_info_cliente(cadena,nombre_reales,mail){
	if(validar_hibrido(cadena,nombre_reales,mail)) return confirm('Confirma que los datos son correctos?');
	else return false;
}

function contar_caracteres(id,limite_min,limite_max){
	if(limite_min!=0 && limite_max != 0){
		
		if($v(id).length > limite_min && $v(id).length < limite_max){
			return true;
		}
		else {
			return false;
		}
	}
	else{
		if(limite_min!=0){
			if($v(id).length >= limite_min){
				return true;
			}
			else {
				return false;
			}
		}
		else{
			if($v(id).length <= limite_max){
				return true;
			}
			else {
				return false;
			}
		}
	}
}


function diferencia_fechas(fecha){
	aux = fecha.split('-');
	today=new Date();
	var limite=new Date(aux[2], (aux[1]-1), aux[0]);
	var one_day=1000*60*60*24;
	
	return Math.ceil((limite.getTime()-today.getTime())/(one_day));
}
function validar_fechas(id,cantidad){
	var vuelve = true;
	
	for(var i = 0; i <= (cantidad-1); i++){
		if(diferencia_fechas($v(id+'['+i+']'))<=0) vuelve=false;
	}
	return vuelve;
}

function cambio_action_validando_fechas(id_form,direccion,id_fechas,cantidad){
	if(validar_fechas(id_fechas,cantidad)){
		document.getElementById(id_form).action=direccion;
		document.getElementById(id_form).submit();
	}
	else alert('La fecha esta mal!!!');
}

function conMayusculas(field) {
	field.value = field.value.toUpperCase()
}