
// INDICE
//
// GENERAL			~ 30
// LOGIN - LOGOUT		~ 390
// MENSAJE			~ 440
// NUEVAS GRABACIONES		~ 510
// COMENTARIOS SHIUR		~ 740
// TIMER			~ 910
// USUARIOS			~ 940
// DISERTANTES			~ 1010
// DURACION			~ 1070
// BM GRABACIONES		~ 1100
// ABM CATEGORIAS		~ 1270
// MI CUENTA			~ 1420
// REGISTRACION			~ 1470
// PUBLICIDADES			~ 1520

//************************************************************ GENERAL


var height = 20; // height of the menu headers
var iheight = 15; // height of the menu_items

var bgc = "#0044EE" // background color of the item
var tc = "white" // text color of the item

var over_bgc = "silver";
var over_tc = "red";

var speed = 0;
var timerID = "";
var N = (document.all) ? 0 : 1;
var width = 192
var self_menu = new Array();

function write_menu()
	{
	smc = 0; // count the position of the self_menu
	document.write("<div style='position:absolute'>");
	mn = 0;
	mni = 1;
	start = -1;

	for(i=0;i<Link.length;i++)
		{
		la = Link[i].split("|");
		if (la[0] == "0")
			{
			if(start == 0)
				{
				document.write("</div>");
				h =  csmc * iheight;
				tmn = mn; //-h
				self_menu[smc] = new Array(tmn,h,0,-2);
				smc++;
				mn--;
				}
			csmc = 0;
			document.write("<div class='menue' style='top:"+mn+";height:"+height+"' id='down"+smc+"' onclick=location.href='novedades.php' onmausmuvjeje='pull_down("+smc+","+mni+")'> "+ la[1] + "</div>");
			self_menu[smc] = new Array(mn,height,0,mni);
			smc++;
			mni++;
			mn+=height;
			start = 1;
			}
		else
			{
			if(start == 1)
				{
				if(N)mn+=2;
				document.write("<div class='item_panel' id='down"+smc+"' style='top:"+mn+"'>");
				start = 0;
				}
			document.write("<a href='"+la[2]+"'");
			if (la[3] != "") document.write(" target='" + la[3] + "' ");
			document.write("><div class='item' id='d"+i+"' style='height:"+iheight);
			if (N) document.write(";width:150");
			document.write("' onmouseover='color(this.id)' onmouseout='uncolor(this.id)'>  "+ la[1] + "</div></a>");
			csmc++;
			}
		}
	if (start == 0)
		{
		document.write("</div>");
		h =  csmc * iheight;
		tmn = mn + 5; //-h
		self_menu[smc] = new Array(tmn,h,0);
		name = "down" + (self_menu.length-1);
		obj = document.getElementById(name);
		obj.style.borderBottomColor = "darkblue";
		obj.style.borderBottomWidth = 1;
		obj.style.borderBottomStyle = "solid";
		}
	document.write("</div>");
	}

function color(obj)
	{
	document.getElementById(obj).style.backgroundColor = over_bgc;
	document.getElementById(obj).style.color = over_tc
	}

function uncolor(obj)
	{
	document.getElementById(obj).style.backgroundColor = bgc;
	document.getElementById(obj).style.color = tc
	}

function pull_down(nr,c,accion)
	{
	if (timerID == "")
		{
		to = self_menu[nr+1][1]
		begin = nr + 2;
		if (timerID != "") clearTimeout(timerID);
		if (self_menu[nr+1][2] == 0)
			{
			if(accion=='abrir')
				{
				self_menu[nr+1][2] = 1;
				if(nr == self_menu.length-2) {to++;}
				epull_down(begin,to,0);
				}
			}
		else
			{
			if (accion=='cerrar')
				{
				to = 0;
				self_menu[nr+1][2] = 0;
				name = "down"+(nr+2);
				open_item = 0;
				for(i=0;i<nr;i++)
					{
					if(self_menu[i][2] == 1)
						{
						open_item += self_menu[i][1];
						}
					}
				if (N == false) {open_item-= (c*1)};
				if (nr== self_menu.length-2) {val = self_menu[self_menu.length-1][1];to=-1;}
				else  val = parseInt(document.getElementById(name).style.top) -(open_item)-(c*height);
				epull_up(begin,to,val);
				}
			}
		}
	}

function epull_down(nr,to,nowv)
	{
	name = "down" + (nr-1);
	obj = document.getElementById(name).style.clip = "rect(0,"+width+","+(nowv+1)+",0)";
	for (i=nr;i<self_menu.length;i++)
		{
		name = "down" + i;
		obj = document.getElementById(name);
		obj.style.top = parseInt(obj.style.top)+1;
		}
	nowv++;
	if(nowv < to) timerID = setTimeout("epull_down("+nr+","+to+","+nowv+")",speed);
	else
		{
		timerID = "";
		if (document.getElementById('tablamouse').value==0) {setTimeout("pull_down(0,1,'cerrar')",400);}
		}
	}

function epull_up(nr,to,nowv)
	{
	name = "down" + (nr-1);
	obj = document.getElementById(name).style.clip = "rect(0,"+width+","+nowv+",0)";
	for (i=nr;i<self_menu.length;i++)
		{
		name = "down" + i;
		obj = document.getElementById(name);
		obj.style.top = parseInt(obj.style.top)-1;
		}
	nowv--;
	if(nowv > to) timerID = setTimeout("epull_up("+nr+","+to+","+nowv+")",speed);
	else
		{
		timerID = "";
		}
	}

function startup(nr)
	{
	write_menu();
	if (nr != 0)
		{
		for(i=0;i<self_menu.length;i++)
			{
			if(self_menu[i][3] == nr) pull_down(i,nr)
			i==self_menu.length;
			}
		}
	}


function CargaPagina(URL)
	{
	window.location = URL   
	}

function ejecutar()
	{
	document.si.contraconf.value='1';
	document.si.submit();
	}

function valid(f)
	{
	!(/^[0-9]*$/i).test(f.value)?f.value = f.value.replace(/[^0-9]/ig,''):null;
	}

function fechas(f)
	{
	!(/^[0-9-/]*$/i).test(f.value)?f.value = f.value.replace(/[^0-9/-]/ig,''):null;
	}

function seg(texto)
	{
	texto = texto.replace("<","[");	
	return texto
	}

function in_array(needle, haystack)
	{
	for (var i = 0; i < haystack.length; i++)
		{
		if (haystack[i] == needle)
			{
			return true;
			}
		}
	return false;
	}

function numbersonly(e)
	{
	var unicode=e.charCode? e.charCode : e.keyCode
	var caracteresEspeciales = new Array('8','46','37','38','39','40');
	if (in_array(unicode,caracteresEspeciales) == false)
		{
		if (unicode<48||unicode>57)
			{
			return false;
			}
		}
	}

function ReplaceEnters(texto, conbr)
	{
	if (conbr)
		{
		pat = new RegExp(String.fromCharCode(13),"g")
		pat2 = new RegExp(String.fromCharCode(10),"g")
		texto = texto.replace(pat, "");
		texto = texto.replace(pat2, "[br]");
		}
	else
		{
		texto = texto.replace(/<br>/g, String.fromCharCode(13));
		}
	return texto
	}

function ReplaceEntersMostrar(texto, conbr)
	{
	if (conbr)
		{
		pat = new RegExp(String.fromCharCode(13),"g")
		pat2 = new RegExp(String.fromCharCode(10),"g")
		texto = texto.replace(pat, "");
		texto = texto.replace(pat2, "<br>");
		}
	else
		{
		texto = texto.replace(/<br>/g, String.fromCharCode(13));
		}
	return texto
	}

function isEmailAddress(theElement)
	{
	var s = theElement.value;
	var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
	return true;
	else
	theElement.focus();
	return false;
	}

//FECHA//
var dtCh= "/";
var minYear=1950;
var maxYear=2015;
function isInteger(s)
	{
	var i;
	for (i = 0; i < s.length; i++)
		{
	        var c = s.charAt(i);
        	if (((c < "0") || (c > "9"))) return false;
		}
	return true;
	}
function stripCharsInBag(s, bag)
	{
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++)
		{
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
		}
	return returnString;
	}
function daysInFebruary (year)
	{
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
function DaysArray(n)
	{
	for (var i = 1; i <= n; i++)
		{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
		}
	return this
	}
function isDate(dtStr)
	{
	if (dtStr!='dd/mm/aaaa' && dtStr!='')
		{
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strDay=dtStr.substring(0,pos1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++)
			{
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
			}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		if (pos1==-1 || pos2==-1)
			{
			alert("El formato de fecha debe ser : dd/mm/aaaa")
			return false
			}
		if (strMonth.length<1 || month<1 || month>12)
			{
			alert("Por favor ingrese un mes válido")
			return false
			}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
			{
			alert("Por favor ingrese un día válido")
			return false
			}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
			{
			alert("Por favor ingrese un año valido de cuatro dígitos entre "+minYear+" y "+maxYear)
			return false
			}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
			{
			alert("Por favor ingrese una fecha válida")
			return false
			}
		}
	return true
	}
//HASTA ACA FECHA//


//------------------------------------------------------------------------/ LOGIN - LOGOUT


function entrar(nombre,clave,recordar)
	{
	if (nombre!="" && clave!="")
		{
		xmlHttp=GetXmlHttpObject();
		var url="todos.php";
		url=url+"?funcion=entrar&nombre="+nombre+"&clave="+clave+"&recordar="+recordar;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function(){subentrar()}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		}
	else
		{
		if (nombre=="")
			{
			document.getElementById('mensajetop').innerHTML="Ingrese su nombre de usuario";
			}
		else
			{
			document.getElementById('mensajetop').innerHTML="Ingrese su contraseña";
			}
		}
	function subentrar()
		{
		if (xmlHttp.readyState==4)
			{
			//alert(xmlHttp.responseText);
			if (xmlHttp.responseText=="0")
				{
				location.href="";
				}
			else
				{
				if (xmlHttp.responseText=="1")
					{
					document.getElementById('mensajetop').innerHTML="Contraseña mal ingresada";
					}
				if (xmlHttp.responseText=="2")
					{
					document.getElementById('mensajetop').innerHTML="Nombre de usuario mal ingresado";
					}
				}
			}
		}
	}

function recordarno()
	{
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=recordarno";
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subrecordarno();}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);			
	function subrecordarno()
		{
		if (xmlHttp.readyState==4)
			{
			location.href="index.php";
			}
		}
	}


//************************************************************ MENSAJE

function mandarmensaje(nombre,telefono,email,mensaje)
	{
	validacion=0;
	if (nombre.value=="")
		{
		nombre.style.background='#eeaa99';
		nombre.style.borderColor='#eeaa99';
		validacion = 1;
		}
	else
		{
		nombre.style.background='#ffffff';
		nombre.style.borderColor='';
		}
	if (email.value=="")
		{
		email.style.background='#eeaa99';
		email.style.borderColor='#eeaa99';
		validacion = 1;
		}
	else
		{
		if (isEmailAddress(email))
			{
			email.style.background='#ffffff';
			email.style.borderColor='';
			}
		else
			{
			email.style.background='#eeaa99';
			email.style.borderColor='#eeaa99';
			alert('E-mail mal ingresado');
			validacion = 1;
			}
		}
	if (mensaje.value=="")
		{
		mensaje.style.background='#eeaa99';
		mensaje.style.borderColor='#eeaa99';
		validacion = 1;
		}
	else
		{
		mensaje.style.background='#ffffff';
		mensaje.style.borderColor='';
		}
	if (validacion==0)
		{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			{
			alert ("Your browser does not support AJAX!");
			return;
			}
		var url="todos.php";
		url=url+"?funcion=mandarmensaje&nombre="+nombre.value+"&telefono="+telefono.value+"&email="+email.value+"&mensaje="+ReplaceEnters(mensaje.value, true);
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function(){submandarmensaje();}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		function submandarmensaje()
			{ 
			if (xmlHttp.readyState==4)
				{
				document.getElementById('respuesta').innerHTML='El mail ha sido enviado correctamente.<br>Será respondido a la brevedad.';
				}
			}
		}
	}

//************************************************************ NUEVAS GRABACIONES

function guardarpaso1()
	{
	document.getElementById("espere").innerHTML="Mientras se sube el archivo complete los datos del Shiur";
	document.getElementById('primerpaso').style.display='none';
	document.getElementById('segundopaso').style.display='inline-block';
	document.getElementById('rigidopaso').style.marginLeft=500;
	document.getElementById('pasos').innerHTML='Segundo paso';
	document.getElementById('pasosv').onclick = function() {document.getElementById('segundopaso').style.display='none';document.getElementById('primerpaso').style.display='inline-block';this.innerHTML='';document.getElementById('pasos').innerHTML='Primer paso';}
	document.getElementById('pasosv').innerHTML='Volver atrás';
	}

function guardarpaso2(titulo,oradores)
	{
	if (titulo.length<4)
		{
		if (titulo=='')
			{
			alert('Escriba un título por favor');
			}
		else
			{
			alert('El título debe tener mínimamente 5 letras');
			}
		}
	else
		{
		var selectedArray = new Array();
		var selObj = oradores;
		var i;
		var count = 0;
		for (i=0; i<selObj.options.length; i++)
			{
			if (selObj.options[i].selected)
				{
				selectedArray[count] = selObj.options[i].value;
				count++;
				}
			}
		if (count==0)
			{
			alert('Elija un orador');
			}
		else
			{
			segtitulo=seg(titulo);
			xmlHttp=GetXmlHttpObject();
			var url="todos.php";
			url=url+"?funcion=chequearrep&titulo="+segtitulo+"&oradores="+selectedArray;
			url=url+"&sid="+Math.random();
			xmlHttp.onreadystatechange = function(){vienecodigo(titulo);}
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			function vienecodigo(titulo)
				{
				if (xmlHttp.readyState==4)
					{
					if (xmlHttp.responseText==1)
						{
						alert('Nombre de grabación usado. Por favor escriba otro.');
						}
					else
						{
						document.getElementById('deftitulo').innerHTML=titulo;
						document.getElementById('segundopaso').style.display='none';
						document.getElementById('tercerpaso').style.display='inline-block';
						document.getElementById('pasos').innerHTML='Tercer paso';
						document.getElementById('pasosv').onclick = function() {document.getElementById('tercerpaso').style.display='none';document.getElementById('segundopaso').style.display='inline-block';document.getElementById('pasos').innerHTML='Segundo paso';document.getElementById('pasosv').onclick = function() {document.getElementById('segundopaso').style.display='none';document.getElementById('primerpaso').style.display='inline-block';document.getElementById('pasos').innerHTML='Primer paso';this.innerHTML='';}}
						}
					}
				}
			}
		}
	}

function guardarpaso3(titulo)
	{
	document.getElementById('deftitulodos').innerHTML=titulo;
	document.getElementById('pasos').innerHTML='Cuarto paso';
	document.getElementById('pasosv').onclick = function() {document.getElementById('cuartopaso').style.display='none';document.getElementById('tercerpaso').style.display='inline-block';document.getElementById('pasos').innerHTML='Tercer paso';document.getElementById('pasosv').onclick = function() {document.getElementById('tercerpaso').style.display='none';document.getElementById('segundopaso').style.display='inline-block';document.getElementById('pasos').innerHTML='Segundo paso';document.getElementById('pasosv').onclick = function() {document.getElementById('segundopaso').style.display='none';document.getElementById('primerpaso').style.display='inline-block';document.getElementById('pasos').innerHTML='Primer paso';this.innerHTML='';}}}
	document.getElementById('tercerpaso').style.display="none";
	document.getElementById('deftitulodos').innerHTML=titulo;
	document.getElementById('cuartopaso').style.display="inline-block";
	}

function seleccarpeta()
	{
	document.getElementById("colorcarpeta").style.color='red'
	document.getElementById("colorcategoria").style.color='gray'
	document.getElementById("carpocat").value='0'
	}

function seleccategoria()
	{
	document.getElementById("colorcarpeta").style.color='gray'
	document.getElementById("colorcategoria").style.color='red'
	document.getElementById("carpocat").value='1'
	}

function pasarcarpocat(nombre,codigo)
	{
	if (document.getElementById("carpocat").value==0)
		{
		document.getElementById('carpeta').value=nombre;
		document.getElementById('codcarpeta').value=codigo;
		}
	else
		{
		if (document.getElementById("categoria").value=='')
			{
			document.getElementById('categoria').value = nombre;
			document.getElementById('codcategoria').value=codigo;
			}
		else
			{
			divisioncategorias = document.getElementById('categoria').value.split(",");
			divisioncodcategorias = document.getElementById('codcategoria').value.split(",");
			codcategoriafinal = ''
			categoriafinal = ''
			i=0;
			aparecio=0;
			while (divisioncodcategorias[i]!=undefined)
				{
				if (codigo==divisioncodcategorias[i])
					{
					aparecio=1;
					}
				else
					{
					if (codcategoriafinal!='')
						{
						codcategoriafinal = codcategoriafinal + ','
						categoriafinal = categoriafinal + ','
						}
					codcategoriafinal = codcategoriafinal + divisioncodcategorias[i];
					categoriafinal = categoriafinal + divisioncategorias[i];
					}
				i=i+1;
				}
			if (aparecio==0) 
				{
				codcategoriafinal=codcategoriafinal + ',' + codigo;
				categoriafinal=categoriafinal + ',' + nombre;
				}
			document.getElementById('categoria').value = categoriafinal;
			document.getElementById('codcategoria').value = codcategoriafinal;
			}
		}
	}

function guardarpaso4(titulo,carpeta,categorias,oradores,descripcion,fuente,fechad,fecham,fechay,idioma,privado,orden,traducido,traduccion,archivo)
	{
	if (carpeta=='')
		{
		alert('Debe elegir una categoría');
		}
	else
		{
		document.getElementById('pasos').innerHTML='Finalización';
		document.getElementById('pasosv').innerHTML='';
		document.getElementById('cuartopaso').style.display="none";
		document.getElementById("espere").innerHTML="Muchas gracias por ingresar los datos.<br>Por favor aguarde mientras se sube el archivo.";
		document.getElementById('rigidopaso').style.marginLeft=0;
		if (document.getElementById('termino').value=="0")
			{
			document.getElementById('termino').value="1";
			}
		else
			{
			var selectedArray = new Array();
			var selObj = oradores;
			var i;
			var count = 0;
			for (i=0; i<selObj.options.length; i++)
				{
				if (selObj.options[i].selected)
					{
					selectedArray[count] = selObj.options[i].value;
					count++;
					}
				}
			xmlHttp=GetXmlHttpObject();
			var url="todos.php";
			url=url+"?funcion=guardartodo&titulo="+titulo+"&oradores="+selectedArray+"&descripcion="+descripcion+"&fuente="+fuente+"&fechad="+fechad+"&fecham="+fecham+"&fechay="+fechay+"&idioma="+idioma+"&privado="+privado+"&orden="+orden+"&traducido="+traducido+"&traduccion="+traduccion+"&carpeta="+carpeta+"&categorias="+categorias+"&archivo="+archivo;
			url=url+"&sid="+Math.random();
			xmlHttp.onreadystatechange = function(){subguardarpaso4();}
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			}
		}
	function subguardarpaso4()
		{
		if (xmlHttp.readyState==4)
			{
			parent.document.getElementById('quintopaso').style.display="inline-block";
		//alert(xmlHttp.responseText);
			}
		}
	}

function guardartodo(titulo,oradores,descripcion,fuente,fechad,fecham,fechay,idioma,privado,orden,traducido,traduccion,carpeta,categorias,archivo)
	{
	parent.document.getElementById('rigidopaso').style.display='none';
	if (parent.document.getElementById('termino').value=="0")
		{
		parent.document.getElementById('termino').value="2";
		parent.document.getElementById('elarchivo').value=archivo;
		}
	else
		{
		var selectedArray = new Array();
		var selObj = oradores;
		var i;
		var count = 0;
		for (i=0; i<selObj.options.length; i++)
			{
			if (selObj.options[i].selected)
				{
				selectedArray[count] = selObj.options[i].value;
				count++;
				}
			}
		xmlHttp=GetXmlHttpObject();
		var url="todos.php";
		url=url+"?funcion=guardartodo&titulo="+titulo+"&oradores="+selectedArray+"&descripcion="+descripcion+"&fuente="+fuente+"&fechad="+fechad+"&fecham="+fecham+"&fechay="+fechay+"&idioma="+idioma+"&privado="+privado+"&orden="+orden+"&traducido="+traducido+"&traduccion="+traduccion+"&carpeta="+carpeta+"&categorias="+categorias+"&archivo="+archivo;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function(){subguardartodo();}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		}
	function subguardartodo()
		{
		if (xmlHttp.readyState==4)
			{
			parent.document.getElementById('quintopaso').style.display="inline-block";
		//alert(xmlHttp.responseText);
			}
		}
	}

function traeroradores(codigo)
	{
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=oradores&codigo="+codigo;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){traerdatos();}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	function traerdatos()
		{ 
		if (xmlHttp.readyState==4)
			{
			var ifrm = document.getElementById('datostraidos');
			ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
			ifrm.document.open();
			ifrm.document.write(xmlHttp.responseText);
			ifrm.document.close();
			}
		}
	}


//------------------------------------------------------------------------/ COMENTARIOS EN SHIUR

function borrarcom(tabla,linea,str,nombre)
	{
	var entrar = confirm('¿Está seguro que desea borrar el comentario de "' + nombre + '"?')
	if (entrar)
		{
		xmlHttp=GetXmlHttpObject();
		var url="todos.php";
		url=url+"?funcion=borrarcom&codigo="+str;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function(){subborrarcom(tabla,linea);}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);			
		function subborrarcom(tabla,linea)
			{
			if (xmlHttp.readyState==4)
				{
				document.getElementById(tabla).deleteRow(linea);
				}
			}
		}
	}

function agregarcomentario(tabla,nombre,comentario,grabacion,admin)
	{
	seguridad = 0;
	if (nombre=='')
		{
		alert('Ingrese un nombre');
		seguridad = 1;
		}
	if (seguridad==0 && comentario=='')
		{
		alert('Ingrese un comentario');
		seguridad = 1;
		}
	else
		{
		if (seguridad=="0")
			{
			var oRows = document.getElementById(tabla).getElementsByTagName('tr');
			var iRowCount = oRows.length;
			if (iRowCount<5) {document.getElementById('primerotabla').style.display='inline-block';}
			var cantrows = iRowCount - 0;
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
				{
				alert ("Your browser does not support AJAX!");
				return;
				} 
			var url="todos.php";
			url=url+"?funcion=agregarcom&grabacion="+grabacion+"&nombre="+nombre+"&comentario="+ReplaceEnters(comentario, 1);
			url=url+"&sid="+Math.random();
			xmlHttp.onreadystatechange = function(){agregadocomentario(tabla,nombre,ReplaceEntersMostrar(comentario,1),admin);}
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);			
			}
		}
	}

function agregadocomentario(tabla,nombre,comentario,admin)
	{ 
	if (xmlHttp.readyState==4)
		{
		palabra = unescape(xmlHttp.responseText);
		result = palabra.split("sep");
		fecha = result[0];
		codigo = result[1];
		var oRows = document.getElementById(tabla).getElementsByTagName('tr');
		var iRowCount = oRows.length;
		var w1=document.getElementById(tabla).insertRow(iRowCount-6);
		var u=w1.insertCell(0);
		var v=w1.insertCell(1);
		var w=w1.insertCell(2);
		var x=w1.insertCell(3);
		if (admin)
			{
			var y=w1.insertCell(4);
			var z=w1.insertCell(5);
			}
		u.innerHTML=nombre+'<br>'+fecha;
		w.innerHTML=comentario;
		if (oRows.length % 2 == 1)
			{
			u.style.background="FBFBFF";
			v.style.background="FBFBFF";
			w.style.background="FBFBFF";
			x.style.background="FBFBFF";
			if (admin)
				{
				y.style.background="FBFBFF";
				z.style.background="FBFBFF";
				}
			}
		else
			{
			u.style.background="F0F0FF";
			v.style.background="F0F0FF";
			w.style.background="F0F0FF";
			x.style.background="F0F0FF";
			if (admin)
				{
				y.style.background="F0FBFF";
				z.style.background="F0FBFF";
				}
			}
		if (admin)
			{
			y.innerHTML='<a href="javascript:;" id=""><img src="imagenes/modificar.jpg"></a>';
			z.innerHTML="<a href=javascript:; id="+codigo+" onclick=borrarcom('"+tabla+"',this.parentNode.parentNode.rowIndex,this.id,'"+nombre+"')><img src=imagenes/borrarf.jpg></a>";
			}
		}
	}

function leercom(str)
	{
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=leercom&codigo="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subescribir(str);}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function escribircom(str,nombre,fecha,comentario)
	{
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=escribircom&codigo="+str+"&nombre="+nombre+"&fecha="+fecha+"&comentario="+comentario;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subescribir(str);}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function subescribir(str) 
	{
	if (xmlHttp.readyState==4)
		{
		palabra = unescape(xmlHttp.responseText);
		acordatemayusculas = palabra.split("division1");
		document.getElementById("nombre"+str).innerHTML=acordatemayusculas[0];
		document.getElementById("fecha"+str).innerHTML=acordatemayusculas[1];
		document.getElementById("comentario"+str).innerHTML=acordatemayusculas[2];
		document.getElementById("modificar"+str).innerHTML=acordatemayusculas[3];
		}
	}


//************************************************** TIMER (con carga pagina)


function escuchado(a)
	{
	var t=setTimeout('aumentar("'+a+'")',40000);
	}

function aumentar(str,escuchar)
	{
	//alert(escuchar);
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=escuchados&codigo="+str+"&recibir="+escuchar;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){masescuchados();}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function masescuchados()
	{ 
	if (xmlHttp.readyState==4)
		{
		//alert(xmlHttp.responseText);
		//document.getElementById("grabacion").innerHTML= xmlHttp.responseText;
		}
	}


//****************************************************************// USUARIOS


function borrarusu(str,titulo)
	{
	var entrar = confirm('¿Está seguro que desea borrar al usuario "' + titulo + '"?')
	if (entrar)
		{
		var pagina = "abmusuarios.php?borrar="+str
		setTimeout('CargaPagina("'+pagina+'")', 1)
		}
	}

function leerusu(str)
	{ 
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=cosausuleer&codigo="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subusuario(str);}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function escribirusu(str,usuario,nombre,apellido,contra,email,institucion,pais,nacimiento,nivel)
	{
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=cosausuescribir&codigo="+str+"&usuario="+usuario+"&nombre="+nombre+"&apellido="+apellido+"&clave="+contra+"&email="+email+"&institucion="+institucion+"&nacimiento="+nacimiento+"&nivel="+nivel+"&pais="+pais;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subusuario(str);}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function subusuario(str) 
	{ 
	if (xmlHttp.readyState==4)
		{
		palabra= unescape(xmlHttp.responseText);
		acordatemayusculas = palabra.split("division1");
		document.getElementById("usuario"+str).innerHTML=acordatemayusculas[0];
		document.getElementById("nombre"+str).innerHTML=acordatemayusculas[1];
		document.getElementById("apellido"+str).innerHTML=acordatemayusculas[2];
		document.getElementById("contra"+str).innerHTML=acordatemayusculas[3];
		document.getElementById("email"+str).innerHTML=acordatemayusculas[4];
		document.getElementById("institucion"+str).innerHTML=acordatemayusculas[5];
		document.getElementById("pais"+str).innerHTML=acordatemayusculas[6];
		document.getElementById("nacimiento"+str).innerHTML=acordatemayusculas[7];
		document.getElementById("nivel"+str).innerHTML=acordatemayusculas[8];
		document.getElementById("modificar"+str).innerHTML=acordatemayusculas[9];
		}
	}


//****************************************************************// DISERTANTES

function borrardis(str,titulo,nombre,apellido)
	{
	var entrar = confirm('¿Está seguro que desea borrar al disertante "' + titulo + ' ' + nombre + ' ' + apellido + '"?')
	if (entrar)
		{
		var pagina = "abmdisertantes.php?borrar="+str
		setTimeout('CargaPagina("'+pagina+'")', 1)
		}
	}

function leerdis(codigo)
	{
	document.getElementById('titulohacer').innerHTML="Modificar";
	document.getElementById('posibilidad').style.display="inline-block";
	document.getElementById('codigomod').value = codigo;
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=leerdis&codigo="+codigo;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subdisertantes();}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function subdisertantes() 
	{
	if (xmlHttp.readyState==4)
		{
		palabra = unescape(xmlHttp.responseText);
	//alert(xmlHttp.responseText);
		acordate = palabra.split("division1");
		document.getElementById("titulop").value=acordate[0];
		document.getElementById("nombre").value=acordate[1];
		document.getElementById("apellido").value=acordate[2];
		document.getElementById("descripcion").value=acordate[3];
		document.getElementById("sexo").value=acordate[4];
		document.getElementById("fotomos").src='img/fotos/'+acordate[5];
		document.getElementById("fotomos").style.display='inline-block';
		}
	}


//************************************************************ DURACION

function asignar(duracion,codigo)
	{ 
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=duracion&duracion="+duracion+"&codigo="+codigo;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subasignar(codigo);}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	function subasignar()
		{ 
		if (xmlHttp.readyState==4)
			{
			document.getElementById("duracion"+codigo).innerHTML= xmlHttp.responseText;
			}
		}
	}


//****************************************************************// BM GRABACIONES

function cursorsi(event)
	{
	if (document.frmSend.mouse.value>=1)
		{
		document.getElementById('grab').style.visibility="visible";
		document.getElementById('grab').style.position="absolute";
		document.getElementById('grab').style.left=event.clientX+10;
		document.getElementById('grab').style.top=event.clientY;
		disableselect
		}
	}
function cursorno(event)
	{
	document.frmSend.mouse.value='0'
	document.getElementById('grab').style.visibility="hidden";
	}

function sobrecategoriaa(vinculo)
	{
	if (document.frmSend.mouse.value>0)
		{
		vinculo.style.color='red';
		}
	}

function sobrecategoriab(vinculo)
	{
	vinculo.style.color='';
	}

function sobrecategoriac()
	{
	if (document.frmSend.mouse.value!=0)
		{
		var graraton = document.frmSend.mouse.value;
		var catraton = document.frmSend.catmouse.value;
		var entrar = confirm('¿Está seguro que desea pasar la grabación "' + document.frmSend.auxmouse.value + '" a la categoria "' + document.frmSend.gramouse.value + '"?')
		if (entrar)
			{
			document.frmSend.traspaso.value='1';
			document.frmSend.mouse.value = graraton;
			document.frmSend.catmouse.value = catraton;

			xmlHttp=GetXmlHttpObject();
			var url="todos.php";
			url=url+"?funcion=traspaso&catmouse="+frmSend.catmouse.value+"&mouse="+frmSend.mouse.value;
			url=url+"&sid="+Math.random();
			xmlHttp.onreadystatechange = function(){subsobrecategoria();}
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			function subsobrecategoria()
				{
				if (xmlHttp.readyState==4)
					{
					location.href="abmgrabaciones.php";
					}
				}
			}
		}
	}

function traergrabacion(codigo)
	{
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=traergrabacion&codigo="+codigo;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subtraergrabacion(codigo);}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	function subtraergrabacion(codigo)
		{
		if (xmlHttp.readyState==4)
			{
			document.getElementById('modifcurso').style.display='inline-block';
			palabra = unescape(xmlHttp.responseText);
			resultado = palabra.split("zp7qy");
			document.getElementById("titulo").value=resultado[0];
			document.getElementById("titulocabeza").innerHTML=resultado[0];
			document.getElementById("descripcion").innerHTML=resultado[1];
			document.getElementById("fuente").value=resultado[2];
			document.getElementById("fecha").value=resultado[3];
			document.getElementById("idioma").value=resultado[4];
			document.getElementById("codcarpeta").value=resultado[5];
			document.getElementById("carpeta").value=resultado[6];
			document.getElementById("codcategoria").value=resultado[7];
			document.getElementById("categoria").value=resultado[8];
			disertantes = resultado[9].split(",");
			for (j=0;j<document.getElementById('disertantes').options.length;j++)
				{
				document.getElementById('disertantes')[j].selected=false;
				for (i=0;i<disertantes.length;i++)
					{
					if (document.getElementById('disertantes').options[j].value==parseInt(disertantes[i]))
						{
						document.getElementById('disertantes')[j].selected=true;
						}
					}
				}
			document.getElementById("modificar").onclick = function() {guardargrabacion(codigo,document.getElementById('titulo').value,document.getElementById('descripcion').innerHTML,document.getElementById('fuente').value,document.getElementById('fecha').value,document.getElementById('idioma').value,document.getElementById('codcarpeta').value,document.getElementById('codcategoria').value,document.getElementById('disertantes'));}
			document.getElementById("paraeliminar").onclick = function() {if (confirm('¿Seguro desea eliminar el curso?')) bajargrabacion(codigo);}
			}
		}
	}

function guardargrabacion(codigo,titulo,descripcion,fuente,fecha,idioma,carpeta,categorias,disertantes)
	{
	var disertantestodos = new Array();
	j = 0;
	for (i=0; i<disertantes.options.length; i++)
		{
		if (disertantes.options[i].selected)
			{
			disertantestodos[j] = disertantes.options[i].value;
			j++;
			}
		}
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=guardargrabacion&codigo="+codigo+"&titulo="+titulo+"&descripcion="+descripcion+"&fuente="+fuente+"&fecha="+fecha+"&idioma="+idioma+"&carpeta="+carpeta+"&categorias="+categorias+"&disertantes="+disertantestodos;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subguardargrabacion();}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	function subguardargrabacion()
		{
		if (xmlHttp.readyState==4)
			{
			//alert(xmlHttp.responseText);
			location.href="abmgrabaciones.php";
			}
		}
	}

function bajargrabacion(codigo)
	{
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=bajargrabacion&codigo="+codigo;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subbajargrabacion();}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	function subbajargrabacion()
		{
		if (xmlHttp.readyState==4)
			{
			//alert(xmlHttp.responseText);
			location.href="abmgrabaciones.php";
			}
		}
	}

//****************************************************************// ABM CATEGORIAS

function cursorsicat(event)
	{
	if (document.getElementById('categoria').value>=1)
		{
		document.getElementById('grab').style.visibility="visible";
		document.getElementById('grab').style.position="absolute";
		document.getElementById('grab').style.left=event.clientX+10;
		document.getElementById('grab').style.top=event.clientY;
		disableselect
		}
	}
function cursornocat(event)
	{
	document.getElementById('categoria').value='0'
	document.getElementById('grab').style.visibility="hidden";
	}

function pasarcategoria()
	{
	if (document.getElementById('categoria').value!=0)
		{
		var graraton = document.getElementById('categoria').value;
		var catraton = document.getElementById('anterior').value;
		var entrar = confirm('¿Está seguro que desea pasar la grabación "' + document.getElementById('nomcategoria').value + '" a la categoria "' + document.getElementById('nomanterior').value + '"?')
		if (entrar)
			{
			xmlHttp=GetXmlHttpObject();
			var url="todos.php";
			url=url+"?funcion=traspasodos&catmouse="+catraton+"&mouse="+graraton;
			url=url+"&sid="+Math.random();
			xmlHttp.onreadystatechange = function(){subpasarcategoria();}
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			function subpasarcategoria()
				{
				if (xmlHttp.readyState==4)
					{
					location.href="abmcategorias.php";
					}
				}
			}
		}
	}

function traercategoria(codigo)
	{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	var url="todos.php";
	url=url+"?funcion=traercategoria&codigo="+codigo;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subtraercategoria(codigo);}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	function subtraercategoria(codigo)
		{
		if (xmlHttp.readyState==4)
			{
			document.getElementById('modifcurso').style.display='inline-block';
			palabra = unescape(xmlHttp.responseText);
			resultado = palabra.split("zp7qy");
			document.getElementById("titulo").value=resultado[0];
			document.getElementById("titulocabeza").innerHTML=resultado[0];
			document.getElementById("descripcion").innerHTML=resultado[1];
			document.getElementById("codcarpeta").value=resultado[2];
			document.getElementById("carpeta").value=resultado[3];
			document.getElementById("modificar").onclick = function() {guardarcategoria(codigo,document.getElementById('titulo').value,document.getElementById('descripcion').innerHTML,document.getElementById('codcarpeta').value);}
			if (resultado[4]==1)
				{
				document.getElementById("paraeliminar").onclick = function() {alert('No se puede borrar la carpeta hasta eliminar o mover los cursos que contiene');}
				}
			else
				{
				document.getElementById("paraeliminar").onclick = function() {if (confirm('¿Seguro desea eliminar la categoría?')) bajarcategoria(codigo);}
				}
			}
		}
	}

function guardarcategoria(codigo,titulo,descripcion,carpeta)
	{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	var url="todos.php";
	url=url+"?funcion=guardarcategoria&codigo="+codigo+"&titulo="+titulo+"&descripcion="+descripcion+"&carpeta="+carpeta;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subguardarcategoria();}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	function subguardarcategoria()
		{
		if (xmlHttp.readyState==4)
			{
			if(xmlHttp.responseText.length>10)
				{
				alert(xmlHttp.responseText);
				}
			else
				{
				location.href="abmcategorias.php";
				}
			}
		}
	}

function bajarcategoria(codigo)
	{
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=bajargrabacion&codigo="+codigo;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subbajarcategoria();}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	function subbajarcategoria()
		{
		if (xmlHttp.readyState==4)
			{
			//alert(xmlHttp.responseText);
			location.href="abmcategorias.php";
			}
		}
	}


//****************************************************************// MI CUENTA

function leercue(str)
	{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	var url="todos.php";
	url=url+"?funcion=cosacueleer&codigo="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subcuenta(str);}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function escribircue(str,usuario,nombre,apellido,contra,email,pais,nacimiento,cantidad,recibir)
	{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	var url="todos.php";
	url=url+"?funcion=cosacueescribir&codigo="+str+"&usuario="+usuario+"&nombre="+nombre+"&apellido="+apellido+"&clave="+contra+"&email="+email+"&cantidad="+cantidad+"&nacimiento="+nacimiento+"&recibir="+recibir+"&pais="+pais;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subcuenta();}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}

function subcuenta() 
	{ 
	if (xmlHttp.readyState==4)
		{
		palabra = unescape(xmlHttp.responseText);
		acordatemayusculas = palabra.split("division1");
		document.getElementById("usuario").innerHTML=acordatemayusculas[0];
		document.getElementById("nombre").innerHTML=acordatemayusculas[1];
		document.getElementById("apellido").innerHTML=acordatemayusculas[2];
		document.getElementById("contra").innerHTML=acordatemayusculas[3];
		document.getElementById("email").innerHTML=acordatemayusculas[4];
		document.getElementById("pais").innerHTML=acordatemayusculas[5];
		document.getElementById("nacimiento").innerHTML=acordatemayusculas[6];
		document.getElementById("cantidad").innerHTML=acordatemayusculas[7];
		document.getElementById("recibir").innerHTML=acordatemayusculas[8];
		document.getElementById("modificar").innerHTML=acordatemayusculas[9];
		}
	}


//****************************************************************// REGISTRACION


//****************************************************************// PUBLICIDADES


function pubentrada(codigo)
	{
	xmlHttp=GetXmlHttpObject();
	var url="todos.php";
	url=url+"?funcion=entrada&codigo="+codigo;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){subpubentrada()}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	function subpubentrada()
		{
		if (xmlHttp.readyState==4)
			{
			if (xmlHttp.responseText.length>15) alert(xmlHttp.responseText);
			}
		}
	}

//****************************************************************//

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
