function Enfocar (Campo,Forma) 
{ 
	document.forms[Forma].elements[Campo].focus(); 
} 

function Validacion (Campo, Mensaje, Forma, Tipo, Cantidad, Longitud)
{
	switch (Tipo) 
	{
		case 'Combo': 
			if (document.forms[Forma].elements[Campo].selectedIndex == 0)
			{
				alert( 'Se debe seleccionar ' + Mensaje);
				Enfocar(Campo,Forma);
				return false;
			}
			break;
		case 'Opcion': 
			Marcado = false;
			for (i=0; i<Cantidad; i++)
			{
				if (document.forms[Forma].elements[Campo][i].checked)
					
				{
					Marcado = true;
				}
			}
			if (!(Marcado))	
			{
				alert('Se debe indicar ' + Mensaje);
				return false;
			}	
			break;
		case 'Marca': 
			Marcado = false;
			for (i=0; i<Cantidad; i++)
			{
				if (document.forms[Forma].elements[Campo][i].checked)
					
				{
					Marcado = true;
				}
			}
			if (!(Marcado))	
			{
				alert('Se debe indicar ' + Mensaje);
				return false;
			}	
			break;
		case 'Texto': 
			if (trim(document.forms[Forma].elements[Campo].value)== "" || document.forms[Forma].elements[Campo].value.length == 0)
			{
				document.forms[Forma].elements[Campo].value ="";
				alert( 'Se debe indicar ' + Mensaje);
				Enfocar(Campo,Forma);
				return false;
			}
			document.forms[Forma].elements[Campo].value =trim(document.forms[Forma].elements[Campo].value);
			break;
		case 'TextoHtmlArea': 
			if (trim(document.forms[Forma].elements[Campo].value) == "")
			{
				alert( 'Se debe indicar ' + Mensaje);
				return false;
			}
			document.forms[Forma].elements[Campo].value =trim(document.forms[Forma].elements[Campo].value);
			break;
		case 'TextoLongitudMayor':
			if (document.forms[Forma].elements[Campo].value.length < Longitud)
			{
				alert( Mensaje + ' debe ser mayor o igual que ' + Longitud);
				Enfocar(Campo,Forma);
				return false;
			}
			break;
		case 'TextoLongitudMenorHtmlArea':
			if (document.forms[Forma].elements[Campo].value.length > Longitud)
			{
				alert( Mensaje + ' debe ser menor o igual que ' + Longitud);
				return false;
			}
			break;
		case 'TextoLongitudMenor':
			if (document.forms[Forma].elements[Campo].value.length > Longitud)
			{
				alert( Mensaje + ' debe ser menor o igual que ' + Longitud);
				Enfocar(Campo,Forma);
				return false;
			}
			break;
		case 'Numero': 
			var numValor = new Number(document.forms[Forma].elements[Campo].value) ;
			var er_numero =/[0-9]+/;
			if (isNaN(numValor) || (numValor < 1) || !(er_numero.test(numValor)))
			{
				alert( Mensaje + ' debe ser un valor numérico');
				Enfocar(Campo,Forma);
				return false;
			}
			break;
		case 'Correo': 
			if (document.forms[Forma].elements[Campo].value.search("@") == -1)
			{
				alert( 'Correo electrónico NO válido');
				Enfocar(Campo,Forma);
				return false;
			}
			break;
	}
	return true;
}

function mostrarNombreMes(mes)
{
	var	nombre = '';
	switch (mes) 
	{
		case 1:
				nombre = 'Enero';
				break;
		case 2:
				nombre = 'Febrero';
				break;
		case 3:
				nombre = 'Marzo';
				break;
		case 4:
				nombre = 'Abril';
				break;
		case 5:
				nombre = 'Mayo';
				break;
		case 6:
				nombre = 'Junio';
				break;
		case 7:
				nombre = 'Julio';
				break;
		case 8:
				nombre = 'Agosto';
				break;
		case 9:
				nombre = 'Septiembre';
				break;
		case 10:
				nombre = 'Octubre';
				break;
		case 11:
				nombre = 'Noviembre';
				break;
		case 12:
				nombre = 'Diciembre';
				break;
	}

	return nombre;
}

function mostrarNombreDiaSemana(diasemana)
{
	var	nombre = '';
	switch (diasemana) 
	{
		case 0:
				nombre = 'Domingo';
				break;
		case 1:
				nombre = 'Lunes';
				break;
		case 2:
				nombre = 'Martes';
				break;
		case 3:
				nombre = 'Miércoles';
				break;
		case 4:
				nombre = 'Jueves';
				break;
		case 5:
				nombre = 'Viernes';
				break;
		case 6:
				nombre = 'Sábado';
				break;
	}

	return nombre;
}

function mostrarFechaActual()
{
	var fecha=new Date();
	var diames=fecha.getDate();
	var diasemana=mostrarNombreDiaSemana(fecha.getDay());
	var mes=mostrarNombreMes(fecha.getMonth() + 1 );
	var ano=fecha.getFullYear();
	document.write(diasemana + ' ' + diames + ' de ' + mes + ' de ' + ano);

}

function limpiarCampo(campo)
{
	campo.value ="";	
}

function cambiaImagen(indice)
{
		document.getElementById("fotoGaleria").src = "images/upload/" + arrImagenes[indice];

		indiceActual = indice;
		if (indiceActual >= totalImagenes)
		{
			document.getElementById("siguiente").style.visibility = "hidden";
		}
		else
		{
			document.getElementById("siguiente").style.visibility = "visible";			
		}			
		if (indiceActual > 0)
		{
			document.getElementById("anterior").style.visibility = "visible";
		}
		else 
		{
			document.getElementById("anterior").style.visibility = "hidden";				
		}
}

function expandirFoto()
{
	imagen = new Image();
	imagen.src ="images/upload/" + arrImagenes[indiceActual];
	fotoSource=imagen.src;
	foto=imagen;
    newWindow=window.open(fotoSource,'newWin','toolbar=no,location=no,status=no,menubar=no,width='+foto.width+',height='+foto.height);
    newWindow.document.write('<html><head><title>Galería de Fotos<\/title><\/head><body background="'+fotoSource+'"><\/body><\/html>');
    newWindow.resizeBy(foto.width-newWindow.document.body.clientWidth,foto.height-newWindow.document.body.clientHeight);
    newWindow.focus();
}


function IrUrl(url)
{
		document.location = url;
}

function SoloNumeros(e){
	var unicode=e.charCode? e.charCode : e.keyCode;
	if (unicode!=8){
		if (unicode<48||unicode>57)
			return false;
	}
	
}

function cambiarUrl(url)
{
	parent.document.location = url;	
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

