function verificarNota()
{
	var f = document.getElementById('form_nota');
	var titulo = document.getElementById('titulo').value;
	var texto = document.getElementById('texto').value;
	if ((titulo == "") || (texto == ""))
		alert("Al menos el titulo y el texto deben estar completos");
	else
		f.submit();
}

function hablitarImagenes()
{
	var check = 'checkImagen';
	var titulo = 'tituloImagen';
	var ruta = 'rutaImagen';
	with (document.formAudioVisual)
	{ 
	    var indice = String(selectImagen.selectedIndex);
	    var nro = selectImagen.options[selectImagen.selectedIndex].text;
	}
	habilitarComponentes(check,titulo,ruta,nro);
}

function hablitarVideos()
{
	var check = 'checkVideo';
	var titulo = 'tituloVideo';
	var ruta = 'rutaVideo';
	with (document.formAudioVisual)
	{ 
	    var indice = String(selectVideo.selectedIndex);
	    var nro = selectVideo.options[selectVideo.selectedIndex].text;
	}
	habilitarComponentes(check,titulo,ruta,nro);
}

function hablitarAudio()
{
	var check = 'checkAudio';
	var titulo = 'tituloAudio';
	var ruta = 'rutaAudio';	
	with (document.formAudioVisual)
	{ 
	    var indice = String(selectAudio.selectedIndex);
	    var nro = selectAudio.options[selectAudio.selectedIndex].text;
	}
	habilitarComponentes(check,titulo,ruta,nro);
}

function habilitarComponentes(check,titulo,ruta,nro)
{
	var i;
	var incremento = 1;
	i = 1;
	if (document.getElementById(check).checked)
	{
		for (i;i <= nro;i++)
		{
			
			document.getElementById(titulo+incremento).disabled = false;
			document.getElementById(ruta+incremento).disabled = false;
			incremento++;
		}
	}
	else
	{
		for (i;i <= nro;i++)
		{
			document.getElementById(titulo+incremento).disabled = true;
			document.getElementById(ruta+incremento).disabled = true;
			incremento++;
		}
	}
	
}

function rearmarVideos()
{
	
	var titulo = 'Video';
	with (document.formAudioVisual)
	{ 
	    var indice = String(selectVideo.selectedIndex);
	    var nro = selectVideo.options[selectVideo.selectedIndex].text;
	}
	var i;
	document.getElementById('videoHidden').value = nro;
	var divsub;
	var incremento = 1;
	for (i=1;i<=15;i++)
	{
		divsub = document.getElementById(titulo+incremento);
		if (i <= nro)
	        divsub.style.display = '';
	    else
	        divsub.style.display = 'none';     
		incremento++;
	}
	
	hablitarVideos();
}

function rearmarImagenes()
{
	var titulo = 'Imagen';
	with (document.formAudioVisual)
	{ 
	    var indice = String(selectImagen.selectedIndex);
	    var nro = selectImagen.options[selectImagen.selectedIndex].text;
	}
	var i;
	document.getElementById('imagenHidden').value = nro;
	var divsub;
	var incremento = 1;
	for (i=1;i<=15;i++)
	{
		divsub = document.getElementById(titulo+incremento);
		if (i <= nro)
	        divsub.style.display = '';
	    else
	        divsub.style.display = 'none';     
		incremento++;
	}
	hablitarImagenes();
}

function rearmarAudio()
{
	var titulo = 'Audio';
	with (document.formAudioVisual)
	{ 
	    var indice = String(selectAudio.selectedIndex);
	    var nro = selectAudio.options[selectAudio.selectedIndex].text;
	}
	var i;
	document.getElementById('audioHidden').value = nro;
	var divsub;
	var incremento = 1;
	for (i=1;i<=15;i++)
	{
		divsub = document.getElementById(titulo+incremento);
		if (i <= nro)
	        divsub.style.display = '';
	    else
	        divsub.style.display = 'none';     
		incremento++;
	}
	hablitarAudio();
}

function verificarImagenes()
{
	var f = document.getElementById('formAudioVisual');
	var nro = document.getElementById('imagenHidden').value;
	var i;
	var ruta = 'rutaImagen';
	for (i=1;i<=nro;i++)
	{
		if (document.getElementById(ruta+i).value != "")
		{
			var imagen = document.getElementById(ruta+i).value;
			var cant = imagen.length;
			var ext = imagen.substring(cant - 3);
			if ((ext != "jpg") && ((ext != "JPG")))
			{
				alert("La extension de la imagen " + i +" no es valida, debe ser .jpg.");
				return false;
			}
		}
	}
return true;
}



function verificarAudio()
{
	var f = document.getElementById('formAudioVisual');
	var nro = document.getElementById('audioHidden').value;
	var i;
	var ruta = 'rutaAudio';
	for (i=1;i<=nro;i++)
	{
		if (document.getElementById(ruta+i).value != "")
		{
			var audio = document.getElementById(ruta+i).value;
			var cant = audio.length;
			var ext = audio.substring(cant - 3);
			if ((ext != "mp3") && (ext != "MP3") && (ext != "wma") && (ext != "WMA"))
			{
				alert("La extension del archivo de audio " + i +" no es valida, debe ser .mp3 o .wma.");
				return false;
			}
		}
	}
return true;
}

function verificarVideo()
{
	var f = document.getElementById('formAudioVisual');
	var nro = document.getElementById('videoHidden').value;
	var i;
	var ruta = 'rutaVideo';
	for (i=1;i<=nro;i++)
	{
		if (document.getElementById(ruta+i).value != "")
		{
			var video = document.getElementById(ruta+i).value;
			var cant = video.length;
			if ((cant >= 22) || (cant >=20)) //Youtube
			{
				var url =video.substring(0,22);
				if (url != 'http://www.youtube.com')
				{
					url = video.substring(0,20);
					if (url != 'http://www.vimeo.com')
					{
						alert("La URL del archivo de audio " + i +" no es valida, debe ser de youtube o de vimeo.");
						return false;
					}
				}
			}
			else
				{
					alert("La URL del archivo de audio " + i +" no es valida, debe ser de youtube o de vimeo.");
					return false;
				}
		}
	}
return true;
}

function verificarAudiovisuales(llamador)
{	
	var f = document.getElementById('formAudioVisual');
	var valido = verificarImagenes();
	if (valido)
	{
		if (llamador == 1)  //llamo desde nota2.html
		{
			valido = verificarAudio();
			if (valido)
			{
				valido = verificarVideo();
				if (valido)
					f.submit();
				
			}
		}
		else //llamo desde galeria2.html
		{
			valido = verificarVideo();
				if (valido)
					f.submit();
		}
	}
}

function verificarAudiovisualesModificados(llamador)
{	
	var f = document.getElementById('formAudioVisual');
	var valido = verificarImagenModificada();
	if (valido)
	{
		if (llamador == 1)  //llamo desde nota2.html
		{
			valido = verificarAudioModificado();
			if (valido)
			{
				valido = verificarVideoModificado();
				if (valido)
					f.submit();
				
			}
		}
		else //llamo desde galeria2.html
		{
			valido = verificarVideoModificado();
				if (valido)
					f.submit();
		}
	}
}

function verificarImagenModificada()
{
	var f = document.getElementById('formAudioVisual');
	var ruta = 'rutaImagen';
	if (document.getElementById(ruta).value != "")
	{
		var imagen = document.getElementById(ruta).value;
		var cant = imagen.length;
		var ext = imagen.substring(cant - 3);
		if ((ext != "jpg") && ((ext != "JPG")))
		{
			alert("La extension de la imagen no es valida, debe ser .jpg.");
			return false;
		}
	}
	return true;
}

function verificarAudioModificado()
{
	var f = document.getElementById('formAudioVisual');
	var ruta = 'rutaAudio';
	if (document.getElementById(ruta).value != "")
	{
		var audio = document.getElementById(ruta).value;
		var cant = audio.length;
		var ext = audio.substring(cant - 3);
		if ((ext != "mp3") && (ext != "MP3") && (ext != "wma") && (ext != "WMA"))
		{
			alert("La extension del archivo de audio no es valida, debe ser .mp3 o .wma.");
			return false;
		}
	}
	return true;
}

function verificarVideoModificado()
{
	var f = document.getElementById('formAudioVisual');
	var ruta = 'rutaVideo';
	if (document.getElementById(ruta).value != "")
	{
		var video = document.getElementById(ruta).value;
		var cant = video.length;
		if ((cant >= 22) || (cant >=20)) //Youtube
		{
			var url =video.substring(0,22);
			if (url != 'http://www.youtube.com')
			{
				url = video.substring(0,20);
				if (url != 'http://www.vimeo.com')
				{
					alert("La URL del archivo de audio no es valida, debe ser de youtube o de vimeo.");
					return false;
				}
			}
		}
		else
			{
				alert("La URL del archivo de audio no es valida, debe ser de youtube o de vimeo.");
				return false;
			}
	}
	return true;
}

function modificarAudiovisualesBoton(item,idItem,nota){
	var f = document.getElementById('formAudioVisual');
	if (item == 1)
		document.getElementById('item').value = "i";
	else if (item == 2)
			document.getElementById('item').value = "v";
		else if (nota == 1)
			document.getElementById('item').value = "a";

	document.getElementById('idItem').value = idItem;
	f.submit();
}

function confirmacionVolver(php)
{
	if(confirm("Si vuelve a la pantalla anterior perdera todos los archivos audiovisuales cargados. \n Desea continuar de todas formas?")) 
		javascript:window.location=php;
}


function cancelarNota(url)
{
	if(confirm("Si cancela, toda la informacion cargada se perdera.\n Desea continuar de todas formas?")) 
		javascript:window.location=url;
}