// JavaScript Document
var URL = unescape(location.href)	
var xstart = URL.lastIndexOf("/") + 1
var xend = URL.length
var hereName = URL.substring(xstart,xend)
var url2=unescape(hereName)	
var xend2 = url2.lastIndexOf("?")
if (xend2>-1)
	{
	var final=hereName.substring(0,xend2)
	var nom_pagina=final.replace(/.php/,"")
	}
else
	{
	var nom_pagina=hereName.replace(/.php/,"")
	}
function mensajes()
{
var query = window.location.search.substring(1);
if (query=="we345hidq"){alert("Los datos ingresados son incorectos.")}
if (query=="endsessions"){alert("Por favor, Identifíquese.")}
if (query=="nofile"){alert("No se encuentra autorizado para descargar este archivo.")}

}
function tamano()
{
	if(document.form1.lst_tipos.value=="I")
	{
	document.getElementById('tam').style.display=""
	}
	else
	{
	document.getElementById('tam').style.display="none"
	}
	if(document.form1.lst_tipos.value=="A")
		{
		document.getElementById('descrimedia').style.display="none"
		document.getElementById('linkmedia').style.display="none"
		}
	else
		{
		document.getElementById('descrimedia').style.display=""
		document.getElementById('linkmedia').style.display=""
		}
}
function valida_archivos()
{
if(document.form1.txt_guardado.value==""){document.form1.txt_guardado.value=document.form1.txt_archivo.value}
if ((document.form1.txt_descripcion.value=="")|(document.form1.txt_guardado.value==""))
	{
	alert("Todos los datos son obligatorios.")
	}
else
	{
	var archivo=document.form1.txt_guardado.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".doc") & (extension != ".xls")))
		{
			alert("La extensión del archivo debe ser tipo Word o Excel.");
			document.form1.txt_guardado.value=""
		}
	else
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'archivos',document.form1.txt_descripcion.value,id		)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'archivos',document.form1.txt_descripcion.value,id)
			}
		}
	}
}

//ENTREVISTAS
function valida_entrevista()
{
if(document.form1.txt_guardado.value==""){document.form1.txt_guardado.value=document.form1.txt_archivo.value}
if ((document.form1.txt_titulo.value=="")|(document.form1.txt_guardado.value=="")|tinyMCE.getInstanceById('txt_descripcion').getHTML()=="")
	{
	alert("Debe ingresar el titulo de la entrevista.")
	}
else
	{
	var archivo=document.form1.txt_guardado.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".mp3") & (extension != ".MP3")))
		{
			alert("La entrevista debe ser un Archivo mp3.");
			document.form1.txt_guardado.value=""
		}
	else
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'entrevistas',document.form1.txt_titulo.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'entrevistas',document.form1.txt_titulo.value,id)
			}
		}
	}
}

function valida_novedades()
{
if ((document.form1.txt_titulo.value=="")|(document.form1.txt_fecha.value==""))
	{
	alert("Debe ingresar el Título y la Fecha de publicación del artículo.")
	}
else
	{
	var archivo=document.form1.txt_imagen.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".jpg")) & ((extension != ".gif"))  )
		{
			alert("La archivo debe ser una imágen  .jpg o .gif");
		}
	else	
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'novedades',document.form1.txt_titulo.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'novedades',document.form1.txt_titulo.value,id)
			}
		}
	}
}	
function valida_encuestas()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'encuestas',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'encuestas',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_encuesta_detalle()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción de la opción.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'encuesta_detalles',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'encuesta_detalles',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_agenda()
{

if ((document.form1.txt_titulo.value==""))
	{
	alert("Debe ingresar el título de la agenda.")
	}
else
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'agenda',document.form1.txt_titulo.value,id		)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'agenda',document.form1.txt_titulo.value,id)
		}
		
	}
}
function valida_becas()
{

if ((document.form1.txt_titulo.value==""))
	{
	alert("Debe ingresar el título de la beca.")
	}
else
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'becas',document.form1.txt_titulo.value,id		)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'becas',document.form1.txt_titulo.value,id)
		}
		
	}
}
function valida_premios()
{

if ((document.form1.txt_titulo.value==""))
	{
	alert("Debe ingresar el título del premio.")
	}
else
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'premios',document.form1.txt_titulo.value,id		)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'premios',document.form1.txt_titulo.value,id)
		}
		
	}
}
function valida_categoria_links()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'categoria_links',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'categoria_links',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_links()
{

if ((document.form1.txt_descripcion.value=="")|(document.form1.txt_link.value=="")|(document.form1.lst_categoria.value==0))
	{
	alert("Todos los datos son obligatorios.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'links',document.form1.txt_link.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'links',document.form1.txt_link.value,id)
		}
	}
}
function valida_empresas()
{
if ((document.form1.txt_razonsocial.value=="")|(document.form1.txt_domicilio.value=="")|(document.form1.txt_localidad.value=="")|(document.form1.txt_telefono1.value=="")|(document.form1.txt_descripcion.value=="")|(document.form1.txt_email.value==""))
	{
	alert("Todos los datos (*) son obligatorios.")
	}
else
	{
	var archivo=document.form1.txt_logo.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".gif") & (extension != ".jpg")))
		{
			alert("La extensión del archivo debe ser tipo jpg o gif.");
		}
	else
		{
		q=document.form1.txt_email.value;
		var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
		if(b.test(q)==false)
			{
			alert ("La dirección de email es incorrecta")
			}
		else
			{
			if (document.form1.txt_id.value!="")
				{
				accion="updt"
				id=document.form1.txt_id.value
				busca_duplicado(accion,'empresas',document.form1.txt_razonsocial.value,id)
				}
			else
				{
				accion="add"
				id=document.form1.txt_id.value
				busca_duplicado(accion,'empresas',document.form1.txt_razonsocial.value,id)
				}
			}
		}
	}
}
function valida_servicios()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Todos los datos son obligatorios.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'servicios',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'servicios',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_listas()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Todos los datos son obligatorios.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'lista_emails',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'lista_emails',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_lista_detalle()
{

if ((document.form1.txt_destinatario.value=="")|(document.form1.txt_email.value==""))
	{
	alert("Todos los datos son obligatorios.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	q=document.form1.txt_email.value;
	var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
	if(b.test(q)==false)
		{
		alert ("La dirección de email es incorrecta")
		}
	else	
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'lista_detalle',document.form1.txt_email.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'lista_detalle',document.form1.txt_email.value,id)
			}
		}
	}
}
function valida_news()
{
if ((document.form1.txt_asunto.value=="")|(document.form1.lst_incgrupos.length==0))
	{
	alert("Debe ingresar el asunto del News y al menos un grupo a quien enviarlo.")
	}
else
	{
	/*recopilo noticias agrgadas*/
	var can = (document.getElementById('lst_incnoticias').length)
	var noticias=''
	if (can>0)
		{
		for (var g=0; g < can;g++)
			{
			if (noticias!='')
				{sep="@"}
			else
				{sep=""}
			noticias=noticias+sep+document.form1.lst_incnoticias[g].value
			}
		}
	/*recopilo agenda agrgadas*/
	var can = (document.getElementById('lst_incagenda').length)
	var agenda=''
	if (can>0)
		{
		for (var g=0; g < can;g++)
			{
			if (agenda!='')
				{sep="@"}
			else
				{sep=""}
			agenda=agenda+sep+document.form1.lst_incagenda[g].value
			}
		}
	/*recopilo grupos agrgadas*/
	var can = (document.getElementById('lst_incgrupos').length)
	var grupos=''
	if (can>0)
		{
		for (var g=0; g < can;g++)
			{
			if (grupos!='')
				{sep="@"}
			else
				{sep=""}
			grupos=grupos+sep+document.form1.lst_incgrupos[g].value
			}
		}
		
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
		    //busca_duplicado(accion,'newsletters',document.form1.txt_asunto.value,id)
			document.form1.action="comandos.php?accion=updt_newsletters&pag=newsletters.php&noticias="+noticias+"&agenda="+agenda+"&grupos="+grupos+"&id="+id	;
			document.form1.submit();
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			//busca_duplicado(accion,'newsletters',document.form1.txt_asunto.value,id)
			document.form1.action="comandos.php?accion=add_newsletters&pag=newsletters.php&noticias="+noticias+"&agenda="+agenda+"&grupos="+grupos;
			document.form1.submit();
			}
	}

}
function valida_banners()
{
if ((document.form1.txt_imagen.value=="")|(document.form1.txt_link.value==""))
	{
	alert("Todos los datos son obligatorios.")
	}
else
	{
	var archivo=document.form1.txt_imagen.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".jpg")) & ((extension != ".gif"))  )
		{
			alert("La archivo debe ser una imágen  .jpg o .gif");
		}
	else	
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'new_banners',document.form1.txt_link.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'new_banners',document.form1.txt_link.value,id)
			}
		}
	}
}	
function valida_grlbanners()
{
if ((document.form1.txt_imagen.value=="")|(document.form1.txt_link.value==""))
	{
	alert("Todos los datos son obligatorios.")
	}
else
	{
	var archivo=document.form1.txt_imagen.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".jpg")) & ((extension != ".gif"))  )
		{
			alert("La archivo debe ser una imágen  .jpg o .gif");
		}
	else	
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'banners',document.form1.txt_link.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'banners',document.form1.txt_link.value,id)
			}
		}
	}
}	
function updt_archivos(foco,valores)
{

mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
var can = (document.getElementById('lst_estado').length)
opt=''
if ((arr[2])=='PRI'){ar="Privado"}
if ((arr[2])=='PUB'){ar="Público"}
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_estado[g].text;
		   if (ar==tex)
		 	{opt=g}
		 }
	}

if (opt)
	{
	var selObj = document.getElementById('lst_estado');
	selObj.options[opt].selected =opt
	}
document.form1.txt_guardado.value=arr[3]
}

//ENTREVISTAS
function updt_entrevistas(foco,valores)
{
	mue_form(foco)
	valores=valores.replace(/ª/g,"'")
	valores=valores.replace(/ç/g,'"')
	arr=valores.split("|")
	document.form1.txt_id.value=arr[0]
	document.form1.txt_titulo.value=arr[1]
	var descripcion=arr[2]
	tinyMCE.getInstanceById('txt_descripcion').setHTML(descripcion)
	document.form1.txt_guardado.value=arr[3]
}

function updt_novedades(foco,valores)
{
mue_form(foco)
valores=valores.replace(/ª/,"'")
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_titulo.value=arr[1]
document.form1.txt_fecha.value=arr[2]
copete=arr[3]
detalle=arr[4]
//document.form1.txt_copete.value=copete
//document.form1.txt_detalle.value=detalle
tinyMCE.getInstanceById('txt_copete').setHTML(copete)
tinyMCE.getInstanceById('txt_detalle').setHTML(detalle)
document.form1.txt_finaliza.value=arr[5]
}
function updt_encuestas(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_encuesta_detalles(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}

function updt_becas(foco,valores)
{

mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_titulo.value=arr[1]
tinyMCE.getInstanceById('txt_descripcion').setHTML(arr[2])
tinyMCE.getInstanceById('txt_requisitos').setHTML(arr[3])
}
function updt_agenda(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_titulo.value=arr[1]
tinyMCE.getInstanceById('txt_descripcion').setHTML(arr[2])
document.form1.txt_fecha.value=arr[3]
}
function updt_premios(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_titulo.value=arr[1]
tinyMCE.getInstanceById('txt_descripcion').setHTML(arr[2])
}
function updt_categoria_links(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_links(foco,valores)
{

mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
document.form1.txt_link.value=arr[2]
var can = (document.getElementById('lst_categoria').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_categoria[g].text;
		   if (arr[3]==tex)
		 	{opt=g}
		 }
	}

if (opt)
	{
	var selObj = document.getElementById('lst_categoria');
	selObj.options[opt].selected =opt
	}
}
function updt_empresas(foco,valores)
{

mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_razonsocial.value=arr[1]
document.form1.txt_domicilio.value=arr[2]
document.form1.txt_localidad.value=arr[3]
document.form1.txt_telefono1.value=arr[4]
document.form1.txt_telefono2.value=arr[5]
document.form1.txt_fax.value=arr[6]
document.form1.txt_url.value=arr[7]
document.form1.txt_descripcion.value=arr[8]
document.form1.txt_email.value=arr[9]
}
function updt_servicios(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_listas(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_lista_detalle(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_destinatario.value=arr[1]
document.form1.txt_email.value=arr[2]
}
function updt_news(id)
{
window.open("newsletters.php?id="+id, "_parent")
}
function updt_banners(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_link.value=arr[2]
}
function updt_grlbanners(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_link.value=arr[2]
}
function ocu_form()
{
document.getElementById('alta_modi').style.display="none"
document.getElementById('marco').style.display="none"
}

function mue_form(foco)
{
document.getElementById('alta_modi').style.display="block"
document.getElementById(foco).focus()
document.getElementById('marco').style.display="none"
var foto=document.getElementById('tdimg')
if (foto){document.getElementById('tdimg').innerHTML=""}
if (nom_pagina=="media"){document.getElementById('tam').style.display="none"}

if (nom_pagina=='novedades')
	{
	tinyMCE.getInstanceById('txt_copete').setHTML("")
	tinyMCE.getInstanceById('txt_detalle').setHTML("")
	document.form1.txt_titulo.value=""
	}
	else
	{
	if (nom_pagina=='agenda')
		{
		tinyMCE.getInstanceById('txt_descripcion').setHTML("")
		document.form1.txt_titulo.value=""
		}
	else
		{
		if (nom_pagina=='becas')
			{
			tinyMCE.getInstanceById('txt_descripcion').setHTML("")
			tinyMCE.getInstanceById('txt_requisitos').setHTML("")
			document.form1.txt_titulo.value=""
			}
		else
			{
			if (nom_pagina=='premios')
				{
				tinyMCE.getInstanceById('txt_descripcion').setHTML("")
				document.form1.txt_titulo.value=""
				}
			else
				{
				if (nom_pagina=='entrevistas')
					{
					tinyMCE.getInstanceById('txt_descripcion').setHTML("")
					document.form1.txt_titulo.value=""
					document.form1.txt_id.value=""
					}
				else
					{
					document.forms[0].reset()
					}
				}
			}
		}
	}
}
function mue_form2()
{
window.open("newsletters.php?id=0", "_parent")
}
function alta_news(val)
{
if (val>-1)
	{
	mue_form('txt_asunto')
	if(val>0){document.form1.txt_id.value=val}
	}
}
function asignaclase()
{
if (nom_pagina=='novedades') {document.getElementById('novedades').className = 'current'}
if (nom_pagina=='agenda') {document.getElementById('agenda').className = 'current'}
if (nom_pagina=='becas') {document.getElementById('becas').className = 'current'}
if (nom_pagina=='premios') {document.getElementById('premios').className = 'current'}
if (nom_pagina=='newsletters') {document.getElementById('newsletters').className = 'current'}
if (nom_pagina=='entrevistas') {document.getElementById('entrevistas').className = 'current'}
}
function validausu()
{
if ((document.form_usuario.usuario.value=="" )|(document.form_usuario.clave.value==""))
	{
	alert("Debes ingresar el Usuario y la Clave.")
	document.form_usuario.usuario.focus()
	}
else
	{
	document.form_usuario.submit()
	}
}
function intro() 
{
	var x=event.keyCode
	if (x==13)  
	{
	validausu();
	return true;
	}
}
function intro_forms(event) 
{
	var x=event.keyCode
	if (x==13)  
	{
	if (nom_pagina=="clientes"){valida_clientes()}
	if (nom_pagina=="directores"){valida_clientes()}
	if (nom_pagina=="peliculas"){valida_peliculas()}
	if (nom_pagina=="media"){valida_media()}
	if (nom_pagina=="novedades"){valida_novedades()}
	return true;
	}
}
function intro_busca(pagina) 
{
	var x=event.keyCode
	if (x==13)  
	{
	buscar(pagina);
	return true;
	}
}
function eliminar(cod,tabla,campo,archivo)
{
var eli = confirm("¿Deseas eliminar el Registro?");
if (eli== true)
{
var URL = unescape(location.href)	
var xstart = URL.lastIndexOf("/") + 1
var xend = URL.length
var pagina = URL.substring(xstart,xend)
pag=pagina.replace(/&/gi,"|")
sql="delete from "+tabla+" where "+campo+"="+cod
nav=pag.lastIndexOf("totalRows_"+nom_pagina+"=")
caracteres=nom_pagina.length
if (nav>-1)
	{
	numero=pag.substring(nav+11+caracteres,nav+10+caracteres+3)
	final=parseInt(numero)-1
	va="totalRows_"+nom_pagina+"="+numero
	pag=pag.replace(va,"totalRows_"+nom_pagina+"="+final)
	}
window.open('comandos.php?accion=delete&sql='+sql+'&file='+archivo+'&pag='+pag , '_parent')
}
}

function buscar(pagina)
{
if(document.getElementById('txt_busca').value=="")
{
alert("Tienes que ingresar el dato a buscar.")
document.getElementById('txt_busca').focus()
}
else
{
window.open(pagina+'?valor='+document.getElementById('txt_busca').value , '_parent')
}
}
function oculta_submen()
{
document.getElementById('marco').style.display="none"
}
function muestra_submen()
{
document.getElementById('marco').style.display=""
}
function orden(op,campo)
{
obj = document.getElementById(op);
var top=obj.offsetTop 
var left=obj.offsetParent.offsetLeft 
var query = window.location.search.substring(1);
var esta=document.getElementById('alta_modi').style.display
document.getElementById('marco').style.left=left+240+'px'
if (esta=="")	
	{
	document.getElementById('marco').style.top=top+370+'px'
	}
else
	{
	document.getElementById('marco').style.top=top+260+'px'	
	}
muestra_submen()
col="<div><div id=item><ul><li><a href=javascript:ira('asc','"+campo+"') onclick=oculta_submen()>Ordenar Ascendente</a></li></ul></div><div id=item2><ul><li><a href=javascript:ira('desc','"+campo+"')  onclick=oculta_submen()>Ordenar Descendente</a></li></ul></div>"
document.getElementById('interior').innerHTML=col
}
function ira(orden,campo)
{
var URL = unescape(location.href)	
var xstart = URL.lastIndexOf("/") + 1
var xend = URL.length
var pagina = URL.substring(xstart,xend)
var query1=pagina.lastIndexOf("?")	
if (query1<0)
	{pag=pagina+"?ord="+orden+"&campo="+campo}
else
	{
	var inicio=pagina.lastIndexOf("?ord=")	
	if (inicio>0)
		{
			if (orden=='asc') {pag=pagina.replace(/ord=desc/, "ord=asc")}
	    	if (orden=='desc') {pag=pagina.replace(/ord=asc/, "ord=desc")}
		}
	else
		{
		var inicio=pagina.lastIndexOf("&ord=")	
			if (inicio>0)
			{
				if (orden=='asc') {pag=pagina.replace(/ord=desc/, "ord=asc")}
	    		if (orden=='desc') {pag=pagina.replace(/ord=asc/, "ord=desc")}
			}
			else
			{		
			pag=pagina+"&ord="+orden+"&campo="+campo
			}
		}
	}
var inicio=pag.lastIndexOf("campo=")	
if (inicio>0){pag=pag.substring(0,inicio-1)+"&campo="+campo}
window.open(pag, '_parent')
}
function control_errores(x,valores)
{
if (x>0){document.getElementById('alta_modi').style.display=""}	
if (x==1)
	{
	val=valores.split("|")
	document.form1.txt_descripcion.value=val[1]
	document.form1.txt_id.value=val[0]
	alert("La imágen no debe superar los "+val[2]+".")
	}
if (x==2)
	{
	alert("El email fué enviado con éxito.")
	}
if (x==5)
	{
	val=valores.split("|")
	document.form1.txt_descripcion.value=val[1]
	document.form1.txt_descripcion.value=val[2]
	document.form1.txt_id.value=val[3]
	alert("La entrevista no debe superar los "+val[4]+".")
	}	
}
function duplicado_cmd() { 
	if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
			 var a=http.responseText
			 if (a<1)
			 {
				var URL = unescape(location.href)	
				var xstart = URL.lastIndexOf("/") + 1
				var xend = URL.length
				var pagina = URL.substring(xstart,xend)
				pag=pagina.replace(/updt=1/, "updt=0")
				pag=pagina.replace(/add=1/, "add=0")
				accion1=pag.lastIndexOf("add")
				accion2=pag.lastIndexOf("updt")
				if (accion1>-1){accion="add"}
				if (accion2>-1){accion="updt"}
				pag=pag.replace(/&/gi,"|")
				//alert("comandos.php?accion="+accion+"_clientes&pag="+pag)
				nav=pag.lastIndexOf("totalRows_"+nom_pagina+"=")
				caracteres=nom_pagina.length
				if ((nav>-1) && (document.form1.txt_id.value==""))
					{
						numero=pag.substring(nav+11+caracteres,nav+10+caracteres+3)
						final=parseInt(numero)+1
						va="totalRows_"+nom_pagina+"="+numero
						pag=pag.replace(va,"totalRows_"+nom_pagina+"="+final)
					}
					
					if (document.form1.txt_id.value!="")
						{
						accion="updt_"+nom_pagina+"&id="+document.form1.txt_id.value
						}
						else
						{
						accion="add_"+nom_pagina
						}
					//alert(nom_pagina)
					document.form1.action="comandos.php?accion="+accion+"&pag="+pag
					document.form1.submit();
			 }
			 else
			 {
				alert("Ya existe un registro similar.") 
			 }
			 enProceso = false;
			}
			
       }
    }
}
function busca_duplicado(comando,modulo,valor,id)
{
if (!enProceso && http) 
	{
   	   var url = "includes/duplicado.php?comando="+comando+"&modulo="+modulo+"&valor="+valor+"&id="+id
	   http.open("GET", url, true);
	   http.onreadystatechange = duplicado_cmd;
       enProceso = true;
       http.send(null);
    }
}

/***ajax*///
function getHTTPObject()
{
 var xmlhttp = null;
 //Internet Explorer
 try
 {
  xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
 }
 catch (e)
 {
  try
  {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  catch (e)
  {
   xmlhttp = null;
  }
 }

 //Mozilla y Safari

 if ((xmlhttp == null) && (typeof XMLHttpRequest != 'undefined'))
 {
  try
  {
   xmlhttp = new XMLHttpRequest();
  }
  catch (e)
  {
   xmlhttp = null;
  }
 }
 return xmlhttp;
}
var enProceso = false; // lo usamos para ver si hay un proceso activo
var http =  getHTTPObject(); // Creamos el objeto XMLHttpRequest
function solonumeros() {
if (event.keyCode < 48  || event.keyCode >  57)  {
	if (event.keyCode != 44 ){
	event.keyCode = 0;
	return true;
}}
}
function formateo(control)
{
var val=document.getElementById(control).value
//var val=document.form2.importe.value 
var val=val.replace(".","") 
var val=val.replace(".","") 
var val=val.replace(".","") 
var cant=val.length 
var esta=val.search(",") 
if (esta<0){ 
if (cant==0) document.getElementById(control).value='' 
if (cant==4) document.getElementById(control).value=val.substr(0,1) + "." + val.substr(1,15) 
if (cant==5) document.getElementById(control).value=val.substr(0,2) + "." + val.substr(2,15) 
if (cant==6) document.getElementById(control).value=val.substr(0,3) + "." + val.substr(3,15) 
if (cant==7) document.getElementById(control).value=val.substr(0,1) + "." + val.substr(1,3) + "." + val.substr(4,15) 
if (cant==8) document.getElementById(control).value=val.substr(0,2) + "." + val.substr(2,3) + "." + val.substr(5,15) 
}
}
function notifica(id,presu)
{
var eli = confirm("Usted esta por enviar un email al cliente "+"\n"+"con la dirección web para acceder a visualizar el Presupuesto."+"\n"+"¿Desea hacerlo?");
if (eli== true)	
	{
	 window.open("presupuestonotifica.php?id="+id+"&presu="+presu , "_parent")
	}
}
/*funciones de agrgados de combos news*/
function addd(lst,lstinc)
{
var m=document.form1[lst].value
if (m==0){
	alert("Debe selecionar una noticia.");}
else{

	var can = (document.getElementById(lstinc).length)
	var indice1 = document.form1[lst].selectedIndex; 
	var texto=document.form1[lst][indice1].text;
	var error =0
		if (can>0)
			{
			for (var g=0; g < can;g++)
				 {
				var tex=document.form1[lstinc][g].text;
				var valor=document.form1[lstinc][g].value;
				if ((texto==tex))
					{
					error=1
					break;
					}
				else
					{
					error=0
					}
				}	
			
			}
		else
			{
			error=0
			}
		
	
		if (error==0)
			{		
			var valor = document.form1[lst].value;
			var new_option = new Option(texto, valor, false, false);
			document.getElementById(lstinc).options[can] = new_option;
			var selObj = document.getElementById(lst);
			selObj.options[0].selected = 1
			}
		else
			{
			if(m<100000)
				{
				alert("El Item que desea agregar ya existe!.");
				}
			var selObj = document.getElementById(lst);
			selObj.options[0].selected = 1
			}
	}
}
function quit(lst,lstinc)
{
var indi =  document.form1[lst].selectedIndex; 
if (indi==-1){
alert("No hay ningún item seleccionado!.")}
else
{
document.getElementById(lstinc).options[indi] = null;
var selObj = document.getElementById(lst);
selObj.options[0].selected = 1
}
}
function enviar_news(id)
{
var eli = confirm("Realmente desea enviar el Newsletter");
if (eli== true)	
	{
	window.open("news_envio.php?id="+id, "_parent")
	}
}
function exito(m)
{
	if(m==1)
	{
		alert("El News fué enviado con éxito")
	}
}
function valida_eve_galeria()
{
if ((document.form1.txt_imagen.value=="" && document.form1.txt_id.value=="")|(document.form1.txt_titulo.value==""))
	{
	alert("Todos los datos son obligatorios.");
	}
else
	{
	var archivo=document.form1.txt_imagen.value;
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase();
	if ((extension != "") & ((extension != ".jpg")) & ((extension != ".gif")) & ((extension != ".png")) )
		{
			alert("El archivo debe ser una imagen  .jpg, .gif o .png");
		}
	else	
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt";
			id=document.form1.txt_id.value;
			busca_duplicado(accion,'galeria_eventos',document.form1.txt_titulo.value,id);
			}
		else
			{
			accion="add";
			id=document.form1.txt_id.value;
			busca_duplicado(accion,'galeria_eventos',document.form1.txt_titulo.value,id);
			}
		}
	}
}

function updt_eve_galeria(foco,valores)
{
mue_form(foco);
arr=valores.split("|");
document.form1.txt_id.value=arr[0];
document.form1.txt_titulo.value=arr[2];
}

function updt_eventos(foco,valores)
{
mue_form(foco);
valores=valores.replace(/ª/g,"'");
valores=valores.replace(/ç/g,'"');	
arr=valores.split("|");
document.form1.txt_id.value=arr[0];
document.form1.txt_nombre.value=arr[1];
document.form1.txt_desde.value=arr[2];
document.form1.txt_hasta.value=arr[3];
}

function valida_eventos()
{
if ((document.form1.txt_nombre.value==""))
	{
	alert("Debe ingresar el nombre del evento.");
	}
else
	{
	var arrfecha = document.form1.txt_desde.value;
	arrfecha=arrfecha.split('/');
	var fecha1 = arrfecha[2]+arrfecha[1]+arrfecha[0];
	var arrfecha = document.form1.txt_hasta.value;
	arrfecha=arrfecha.split('/');
	var fecha2 = arrfecha[2]+arrfecha[1]+arrfecha[0];	
	if(fecha1>fecha2)
		{
		alert("Las fechas son incorrectas");
		}
	else
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt";
			id=document.form1.txt_id.value;
			busca_duplicado(accion,'eventos',document.form1.txt_nombre.value,id);
			}
		else
			{
			accion="add";
			id=document.form1.txt_id.value;
			busca_duplicado(accion,'eventos',document.form1.txt_nombre.value,id);
			}
			
		}
	}
}