function borrarMesaCalendario(mid)
{
	if(mid)
	{
		toUrl = urllocal+'admin/borrarmesacalendario/es/1/';
		var objAjax = new Request({
	   	method: 'post',
	       url:toUrl,
	       data:{'mid':mid},
	       onRequest: function(){},
	       onSuccess: function(texto, xmlrespuesta){
				window.location.reload();
			},
	       onFailure: function(){alert('Error');}
	   }).send();
	}else{
		return;
	}
}

function borrarCalendario(id)
{
	if(id)
	{
		toUrl = urllocal+'admin/borrarcalendario/es/1/';
		var objAjax = new Request({
	   	method: 'post',
	       url:toUrl,
	       data:{'cId':id},
	       onRequest: function(){},
	       onSuccess: function(texto, xmlrespuesta){
				window.location.reload();
			},
	       onFailure: function(){alert('Error');}
	   }).send();
	}else{
		return;
	}
}

function borrarPonencia(pId)
{
	if(pId)
	{
		toUrl = urllocal+'envioabstracts/borrarponencia/es/1/';
		var objAjax = new Request({
	   	method: 'post',
	       url:toUrl,
	       data:{'pId':pId},
	       onRequest: function(){},
	       onSuccess: function(texto, xmlrespuesta){
				window.location.reload();
			},
	       onFailure: function(){alert('Error al buscar');}
	   }).send();
	}else{
		return;
	}
}

function changePass()
{
	ape = $('ape').value;
	usu = $('usu').value;
	if(ape && usu)
	{
		$('botoncito').disabled="true";
		toUrl = urllocal+'site/cambiarpass/es/1/';
		var objAjax = new Request({
	   	method: 'post',
	       url:toUrl,
	       data:{'usu':usu,'ape':ape},
	       onRequest: function(){},
	       onSuccess: function(texto, xmlrespuesta){
				$('resp').set('html',texto);
			},
	       onFailure: function(){alert('Error al buscar');}
	   }).send();
	}else{
		alert('Debe completar todos los campos');
		return;
	}
}

function getNewPass()
{
	toUrl = urllocal+'site/getnewpass/es/';
	name = 'getNewPass';
	opciones = 'left=350,top=80,width=400,height=300,scrollbars=1,scroll=yes,toolbar=1,resizable=0';
	var myRef = window.open(toUrl,name,opciones);
}

function verTutorial()
{
	toUrl = urllocal+'ventanas/tutorial/es/';
	name = 'verTutorial';
	opciones = 'left=350,top=80,width=800,height=500,scrollbars=1,scroll=yes,toolbar=1,resizable=0';
	var myRef = window.open(toUrl,name,opciones);
}

function cambiaTitulo(absId)
{
	tit = $('titulo').value;
	if(tit)
	{
		modificarTitulo(absId,tit);
	}else{
		alert('El titulo no puede estar vacio');
	}	
}

function modificarTitulo(absId,tit)
{
	toUrl = urllocal+'ventanas/cambiartitulo/es/1/abstract/'+absId+'/titulo/'+tit+'/';
	var objAjax = new Request({
	   	method: 'get',
	       url:toUrl,
	       onRequest: function(){},
	       onSuccess: function(texto, xmlrespuesta){
				window.opener.location.reload();
				window.close();
			},
	       onFailure: function(){alert('Error al buscar');}
	   }).send();
}

function cambiarTitulo(absId)
{
	toUrl = urllocal+'envioabstracts/cambiartitulo/es/1/abstract/'+absId+'/';
	name = 'varTitulo';
	opciones = 'left=350,top=80,width=650,height=100,scrollbars=1,scroll=yes,toolbar=1,resizable=0';
	var myRef = window.open(toUrl,name,opciones);
}

function showNotaMesa(mId)
{
	toUrl = urllocal+'envioabstracts/notamesa/es/1/mesa/'+mId+'/';
	name = 'varNotaMesa';
	opciones = 'left=350,top=80,width=650,height=500,scrollbars=1,scroll=yes,toolbar=1,resizable=0';
	var myRef = window.open(toUrl,name,opciones);
}

function showNota(absId)
{
	toUrl = urllocal+'envioabstracts/nota/es/1/abstract/'+absId+'/';
	name = 'varNota';
	opciones = 'left=350,top=80,width=650,height=500,scrollbars=1,scroll=yes,toolbar=1,resizable=0';
	var myRef = window.open(toUrl,name,opciones);
}

function showListado(listado)
{
	toUrl = urllocal+'listados/'+listado+'/es/1/';
	name = 'varListado';
	opciones = 'left=350,top=80,width=650,height=500,scrollbars=1,scroll=yes,toolbar=1,resizable=0';
	var myRef = window.open(toUrl,name,opciones);
}

function saveCambiarTematica()
{
	toUrl = urllocal+'ventanas/cambiartematica/es/1/abstract/'+$('aId').value+'/tematica/'+$('tematica_id').value+'/';
	var objAjax = new Request({
	   	method: 'get',
	       url:toUrl,
	       onRequest: function(){},
	       onSuccess: function(texto, xmlrespuesta){
				alert('Se ha modificado correctamente');
				window.opener.location.reload();
				window.close();
			},
	       onFailure: function(){alert('Error al buscar');}
	   }).send();
}

function showAbstractCompleto(aId)
{
	toUrl = urllocal+'ventanas/verabstractcompleto/es/1/abstract/'+aId+'/';
	name = 'verCompleto';
	opciones = 'left=350,top=80,width=650,height=500,scrollbars=1,scroll=yes,toolbar=1,resizable=0';
	var myRef = window.open(toUrl,name,opciones);
}

function buscarAbsUsu(n)
{
	uId = $('u'+n).value;
	toUrl = urllocal+'ventanas/getusuabstracts/es/1/uId/'+uId+'/n/'+n+'/';
	var objAjax = new Request({
	   	method: 'get',
	       url:toUrl,
	       onRequest: function(){},
	       onSuccess: function(texto, xmlrespuesta){$('ab'+n).set('html', texto);},
	       onFailure: function(){alert('Error al buscar');}
	   }).send();
}

function validarGI()
{
	if($('gi').checked)
	{
		if(
		($('proy').value == '') ||
		($('inst').value == '') ||
		($('fina').value == '') ||
		($('dirp').value == '') ||
		($('dura').value == ''))
		{
			alert('Debe completar todos los datos');
			return false;
		}
	}
	return true;
}

function showGi()
{
	if($('gi').checked)
	{
		$('a1').style.display = '';
		$('a2').style.display = '';
		$('a3').style.display = '';
		$('a4').style.display = '';
		$('a5').style.display = '';
	}else{
		$('a1').style.display = 'none';
		$('a2').style.display = 'none';
		$('a3').style.display = 'none';
		$('a4').style.display = 'none';
		$('a5').style.display = 'none';
	}
}

function guardarCoautor()
{
	var uId = $('usuario_id').value;
	var aId = $('aId').value;
	var nCo = $('nCo').value;
	toUrl = urllocal+'ventanas/guardarcoautor/es/1/usuario/'+uId+'/aId/'+aId+'/nCo/'+nCo+'/';
		var objAjax = new Request({
	    	method: 'get',
	        url:toUrl,
	        onRequest: function(){},
	        onSuccess: function(texto, xmlrespuesta){
	        	window.opener.location.reload();
	        	window.close();
	        },
	        onFailure: function(){alert('Error al buscar');}
	    }).send();
}

function borrarCoautor(aId,nCo)
{
	toUrl = urllocal+'ventanas/borrarcoautor/es/1/aId/'+aId+'/nCo/'+nCo+'/';
		var objAjax = new Request({
	    	method: 'get',
	        url:toUrl,
	        onRequest: function(){},
	        onSuccess: function(texto, xmlrespuesta){
	        	window.location.reload();
	        },
	        onFailure: function(){alert('Error al buscar');}
	    }).send();
}

function agregarNewCoautor()
{
	var aId = $('aId').value;
	var nCo = $('nCo').value;
	var ape = $('ape').value;
	var nom = $('nom').value;
	var mail = $('mail').value;
	var tdoc = $('tdoc').value;
	var ndoc = $('ndoc').value;
	if((ape == '') || (nom == '') || (mail == '') || (tdoc == '') || (ndoc == ''))
	{
		alert('Complete todos los campos');
		return;
	}
	toUrl = urllocal+'ventanas/agregarcoautor/es/1/ape/'+ape+'/nom/'+nom+'/mail/'+mail+'/tdoc/'+tdoc+'/ndoc/'+ndoc+'/aId/'+aId+'/nCo/'+nCo+'/';
		var objAjax = new Request({
	    	method: 'get',
	        url:toUrl,
	        onRequest: function(){},
	        onSuccess: function(texto, xmlrespuesta){
	        	alert(texto);
	        	window.opener.location.reload();
	        	window.close();
	        },
	        onFailure: function(){alert('Error al buscar');}
	    }).send();
}

function evento(select)
{
	if (select.options[select.selectedIndex].value == "Pasaporte")
	{
		$('pais_id').style.visibility="";
		$('pais_id').style.height="auto";
	}else{
		$('pais_id').style.visibility="hidden";
		$('pais_id').style.height="1px";
	}
}

function validarLleno(text)
{
	if (text.value.length > 0)
		return true;
	else
		return false;
}

function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) 
    {
        return false;
    } 
    else 
    {
        return true;
    }
}

function validarInscripcion(form)
{
	res = validarLleno(form.nombre);
	res = res && validarLleno(form.apellido);
	res = res && validarLleno(form.mail);
	res = res && validarLleno(form.usuario);
	res = res && validarLleno(form.password);
	res = res && validarLleno(form.check_password);
	res = res && validarLleno(form.pertenencia);
	res = res && validarLleno(form.nro_doc);
	if(form.tipo_doc.value == "Pasaporte")
	{
		res = res && (form.pais_id.value > 0);
	}
	if (res)
	{
		if (isEMailAddr(form.mail))
		{	
			if (form.tipo_doc.value != 0)
			{
				if (form.password.value == form.check_password.value)
					return true;
				else
				{
					alert("Los password que intridujo no coinciden.");
					return false;
				}
			}
			else
			{
				alert("Debe introducir un tipo de documento.");
				return false;
			}
		}
		else
		{
			alert("Debe introducir una direccion de email correcta.");
			return false;
		}
	}
	else
	{
		alert("Debe completar todos los campos.");
		return false;
	}
}

function validarLogueoUsuarioAbstract(form)
{
	res = validarLleno(form.usuario);
	res = res && validarLleno(form.password);
	
	if (res)
		return true;
	else
	{
		alert("Debe completar los dos campos.");
		return false;
	}
}

function validarEnvioAbstract(form)
{
	if (!validarLleno(form.titulo))
	{
		alert("Debe introducir un titulo del abstract a enviar.");
		return false;
	}
	if (!validarLleno(form.abstract))
	{
		alert("Debe ingresar un texto introductorio en el cuadro de Abstract.");
		return false;
	}
	return true;
}

// Funcion para controlar el max de un textarea
function ismaxlength(obj)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}
// FIN Funcion para controlar el max de un textarea

function validarAsignaCoordinador(form)
{
	if (form.coordinadores.value == 0)
	{
		alert("Debe seleccionar un coordinador");
		return false;
	}
	else
		return true;
}

function validarCrearCoordinador(form)
{
	res = validarLleno(form.nombre);
	res = res && validarLleno(form.apellido);
	res = res && validarLleno(form.mail);
	res = res && validarLleno(form.usuario);
	res = res && validarLleno(form.password);
	res = res && validarLleno(form.check_password);
	
	if (res)
	{
		if (isEMailAddr(form.mail))
		{	
			if (form.password.value == form.check_password.value)
				return true;
			else
			{
				alert("Los password que intridujo no coinciden.");
				return false;
			}
		}
		else
		{
			alert("Debe introducir una direccion de email correcta.");
			return false;
		}
	}
	else
	{
		alert("Debe completar todos los campos.");
		return false;
	}
	
}

function agregarCoautor(id,nCo)
{
	toUrl = urllocal+'ventanas/addcoautores/es/1/abstract/'+id+'/nco/'+nCo+'/';
	name = 'adcoautor';
	opciones = 'left=350,top=80,width=400,height=500,scrollbars=1,scroll=yes,toolbar=1,resizable=0';
	var myRef = window.open(toUrl,name,opciones);
}

function buscarxNombre()
{
	if($('bnom').value)
	{
		toUrl = urllocal+'ventanas/buscarxnombre/es/';
		var objAjax = new Request({
	    	method: 'post',
	        url:toUrl,
	        data: {"nom":$('bnom').value},
	        onRequest: function(){},
	        onSuccess: function(texto, xmlrespuesta){$('tabla').set('html', texto);},
	        onFailure: function(){alert('Error al buscar');}
	    }).send();
	}
}

function cambiarTematica(aId)
{
	toUrl = urllocal+'admin/cambiartematica/es/1/abstract/'+aId+'/';
	name = 'changetematica';
	opciones = 'left=350,top=80,width=500,height=200,scrollbars=1,scroll=yes,toolbar=1,resizable=0';
	var myRef = window.open(toUrl,name,opciones);
}