function verificaFrames(){
	return;
	if(parent.frames.length > 0){
		parent.location='index.php';
	}
}

function menuOver(id){
	var idd = document.getElementById(id);
	idd.style.cursor='pointer';
	idd.style.color = '#000000';
	idd.style.textDecoration="underline";
	
}
function menuOut(id){
	var idd = document.getElementById(id);
	idd.style.color = '#D4121A';
	idd.style.textDecoration="none";
}

function menuClick(url){
	location.href = url;
}

function overSimple(id){
	id.style.cursor="pointer";
}

function overRojo(id){
	id.style.cursor="pointer";
	id.style.color="#0000FF";
}
function outRojo(id){
	id.style.color="#D4121A";	
}

function validaRegistro(){
	if(document.registro.nombre.value == ""){
		alert("Ingresa tu nombre completo");
		document.registro.nombre.focus();
		return false;
	}
	if(document.registro.correo.value == ""){
		alert("Ingresa tu correo electronico");
		document.registro.correo.focus();
		return false;
	}
	if(document.registro.password1.value == ""){
		alert("Ingresa tu password para acceder al sistema");
		document.registro.password1.focus();
		return false;
	}
	if(document.registro.password2.value == ""){
		alert("Confirma tu password para acceder al sistema");
		document.registro.password2.focus();
		return false;
	}
	if(document.registro.password1.value != document.registro.password2.value){
		alert("La confirmación del password no coincide");
		document.registro.password1.value = "";
		document.registro.password2.value = "";
		document.registro.password1.focus();
		return false;
	}
	if(document.registro.calle.value == ""){
		alert("Ingresa tu domicilio iniciando por la calle");
		document.registro.calle.focus();
		return false;
	}
	if(document.registro.poblacion.value == ""){
		alert("Ingresa tu colonia o población");
		document.registro.poblacion.focus();
		return false;
	}
	if(document.registro.ciudad.value == ""){
		alert("Ingresa tu ciudad");
		document.registro.ciudad.focus();
		return false;
	}
	if(document.registro.provincia.value == ""){
		alert("Ingresa tu estado o provincia");
		document.registro.provincia.focus();
		return false;
	}
	if(document.registro.pais.value == ""){
		alert("Ingresa tu pais");
		document.registro.pais.focus();
		return false;
	}
	if(document.registro.cp.value == ""){
		alert("Ingresa tu código postal");
		document.registro.cp.focus();
		return false;
	}
	if(document.registro.telefono.value == ""){
		alert("Ingresa tu número telefónico de contacto");
		document.registro.telefono.focus();
		return false;
	}
	if(!document.registro.privacidad.checked){
		alert("Para continuar debe leer y aceptar las políticas de privacidad");
		document.registro.privacidad.focus();
		return false;
	}
	if(!document.registro.terminos.checked){
		alert("Para utilizar el servicio, debe estar de acuerdo con los términos y condiciones de uso");
		document.registro.terminos.focus();
		return false;
	}
	if(!document.registro.antispam.checked){
		alert("Para utilizar el servicio, debe aceptar la política de no tolerancia al spam");
		document.registro.antispam.focus();
		return false;
	}
	return true;
	
}

function validaConsulta(){
	if(document.consulta.nombre.value == ""){
		alert("Ingresa tu nombre completo");
		document.consulta.nombre.focus();
		return false;
	}
	if(document.consulta.correo.value == ""){
		alert("Ingresa tu correo electronico");
		document.consulta.correo.focus();
		return false;
	}
	if(document.consulta.asunto.value == ""){
		alert("Ingresa un asunto para el tema de tu consulta");
		document.consulta.asunto.focus();
		return false;
	}
	if(document.consulta.consulta.value == ""){
		alert("Indica tus dudas o consultas que deseas realizar");
		document.consulta.consulta.focus();
		return false;
	}
	return true;
}

function validaSugerencia(){
	if(document.plantilla.nombre.value == ""){
		alert("Ingresa tu nombre completo");
		document.consulta.nombre.focus();
		return false;
	}
	if(document.plantilla.correo.value == ""){
		alert("Ingresa tu correo electronico");
		document.consulta.correo.focus();
		return false;
	}
	return true;
}

function overMenu(id){
	id.style.cursor='pointer';
	id.style.color = '#999999';
}
function outMenu(id){
	id.style.color = '#FFFFFF';
}
function onClickMenu(url){
	parent.mainFrame.location = url;
}

function setToday(id){
	var hoy = new Date();
	document.getElementById(id).value = hoy.getFullYear() + "-" + (parseInt(hoy.getMonth()) + 1).toString() + "-" + hoy.getDate();
	
}
function setAnio(id){
	var hoy = new Date();
	document.getElementById(id).value = hoy.getFullYear();
	
}

function validaCliente(){
	
	if(document.registro.calle.value == ""){
		alert("Ingresa tu domicilio iniciando por la calle");
		document.registro.calle.focus();
		return false;
	}
	if(document.registro.poblacion.value == ""){
		alert("Ingresa tu colonia o población");
		document.registro.poblacion.focus();
		return false;
	}
	if(document.registro.ciudad.value == ""){
		alert("Ingresa tu ciudad");
		document.registro.ciudad.focus();
		return false;
	}
	if(document.registro.provincia.value == ""){
		alert("Ingresa tu estado o provincia");
		document.registro.provincia.focus();
		return false;
	}
	if(document.registro.pais.value == ""){
		alert("Ingresa tu pais");
		document.registro.pais.focus();
		return false;
	}
	if(document.registro.cp.value == ""){
		alert("Ingresa tu código postal");
		document.registro.cp.focus();
		return false;
	}
	if(document.registro.telefono.value == ""){
		alert("Ingresa tu número telefónico de contacto");
		document.registro.telefono.focus();
		return false;
	}
	return true;
	
}

function validaUsuario(pass){
	if(document.registro.passwordold.value == ""){
		alert("Ingresa tu password actual");
		document.registro.passwordold.focus();
		return false;
	}
	if(document.registro.passwordold.value != Base64Decode(pass)){
		alert("Tu password actual no es válido");
		document.registro.passwordold.value = "";
		document.registro.passwordold.focus();
		return false;
	}
	if(document.registro.password1.value == ""){
		alert("Ingresa tu nuevo password para acceder al sistema");
		document.registro.password1.focus();
		return false;
	}
	if(document.registro.password2.value == ""){
		alert("Confirma tu nuevo password para acceder al sistema");
		document.registro.password2.focus();
		return false;
	}
	if(document.registro.password1.value != document.registro.password2.value){
		alert("La confirmación del nuevo password no coincide");
		document.registro.password1.value = "";
		document.registro.password2.value = "";
		document.registro.password1.focus();
		return false;
	}
	
	return true;
}

function mostrarTiposUsuario(){
	var id = document.getElementById("tiposusuario");
	id.style.display = '';
	
}
function ocultarTipoUsuario(){
	var id = document.getElementById("tiposusuario");
	id.style.display = 'none';
}
function validaLogo(){
	if(document.registro.logo.value == ""){
		alert("Selecciona la imagen del logo que vas a subir al sistema");
		document.registro.logo.focus();
		return false;
	}
	document.registro.submit.disabled = 'yes';
	return true;
}

function overLink(id){
	id.style.cursor='pointer';
	id.style.fontWeight='bold';
}
function outLink(id){
	id.style.fontWeight='normal';
}
function onClickLink(url){
	parent.mainFrame.location = url;
}

function validaUsuarioNuevo(){
	if(document.registro.nombre.value == ""){
		alert("Ingresa el nombre completo del usuario");
		document.registro.nombre.focus();
		return false;
	}
	if(document.registro.correo.value == ""){
		alert("Ingresa el correo electronico del usuario");
		document.registro.correo.focus();
		return false;
	}
	if(document.registro.password1.value == ""){
		alert("Ingresa el password para el usuario");
		document.registro.password1.focus();
		return false;
	}
	if(document.registro.password2.value == ""){
		alert("Confirma el password del usuario");
		document.registro.password2.focus();
		return false;
	}
	if(document.registro.password1.value != document.registro.password2.value){
		alert("La confirmación del password no coincide");
		document.registro.password1.value = "";
		document.registro.password2.value = "";
		document.registro.password1.focus();
		return false;
	}
	
	return true;
}

function validaAutor(){
	if(document.registro.nombre.value == ""){
		alert("Ingresa el nombre del Autor");
		document.registro.nombre.focus();
		return false;
	}
	if(document.registro.correo.value == ""){
		alert("Ingresa el correo del Autor");
		document.registro.correo.focus();
		return false;
	}
	
	return true;
}

function eliminarAutor(idc, ida){
	if(confirm("Desea eliminar al autor?")){
		location.href='eliminar.php?idc=' + idc + '&ida=' + ida;
	}
	
}

function validaArticulo(){
	
	if(document.registro.fecha.value == ""){
		alert("Seleccione la fecha del artículo");
		return false;
	}
	if(document.registro.titulo.value == ""){
		alert("Ingresa el título del artículo");
		document.registro.titulo.focus();
		return false;
	}
	if(document.registro.autor.value == ""){
		alert("Seleccione un autor para el artículo, después podrá modificarlo");
		document.registro.autor.focus();
		return false;
	}
	if(document.registro.richEdit0.value == ""){
		alert("Ingresa el contenido inicial del artículo, después podrá modificarlo");
		return false;
	}
	return true;
}

function validaModificarArticulo(){
	
	if(document.registro.titulo.value == ""){
		alert("Ingresa el título del artículo");
		document.registro.titulo.focus();
		return false;
	}
	if(document.registro.autor.value == ""){
		alert("Seleccione un autor para el artículo, después podrá modificarlo");
		document.registro.autor.focus();
		return false;
	}
	return true;
}

function eliminarArticulo(idc, ida){
	if(confirm("Desea eliminar al artículo?")){
		location.href='eliminar.php?idc=' + idc + '&ida=' + ida;
	}
	
}


function centrarVentana(win, anchoVentana, altoVentana){
	var ancho = screen.availWidth;
	var alto = screen.availHeight;
	var x = (ancho - anchoVentana)/2;
	var y = (alto - altoVentana)/2 - 30;
	win.moveTo(x, y);
}

function abrirVentana(arch, titulo, ancho, alto){
	var parametros = "'directories=no, location=no, scrollbars=no, menubar=no, status=yes, resizable=no, width=" + ancho + ", height=" + alto + "'";
	var win = window.open(arch, titulo, parametros);
	centrarVentana(win, ancho, alto);
}
function abrirVentanaConScroll(arch, titulo, ancho, alto){
	var parametros = "'directories=no, location=no, scrollbars=yes, menubar=no, status=yes, resizable=no, width=" + ancho + ", height=" + alto + "'";
	var win = window.open(arch, titulo, parametros);
	centrarVentana(win, ancho, alto);
}

function insertarImagen(){
	abrirVentanaConScroll("imagen.php", "Imagen", 450, 650);
}
function guardarImagen(imagen, align, title, border, width, height, vspace, hspace){
	
	var tag = "<img src=" + imagen + "  align=" + align + " border=" + border + " ";
	if(title != "")
		tag += "title=" + title + " ";
		
	if(width != "")
		tag += "width=" + width + " ";
		
	if(height != "")
		tag += "height=" + height + " ";
		
	tag += "vspace=" + vspace + " hspace=" + hspace + ">";
	
	var ran = Math.random();
	var div = "<span id='" + ran + "'></span>";
	
	opener.editor.doCmd("insertHTML", div);
	
	opener.editor.editor.document.getElementById(ran).innerHTML = tag;
	
	window.close();
}

function guardarImagenBoletin(imagen, align, title, border, width, height, vspace, hspace){
	
	var tag = "<img src=" + imagen + "  align=" + align + " border=" + border + " ";
	if(title != "")
		tag += "title=" + title + " ";
		
	if(width != "")
		tag += "width=" + width + " ";
		
	if(height != "")
		tag += "height=" + height + " ";
		
	tag += "vspace=" + vspace + " hspace=" + hspace + ">";
	
	var ran = Math.random();
	var div = "<span id='" + ran + "'></span>";
	
	if(opener.document.getElementById('saludoEntry').style.display == ""){
		opener.editor1.doCmd('insertHTML', div);
		opener.editor1.editor.document.getElementById(ran).innerHTML = tag;
	}
	else{
		opener.editor2.doCmd('insertHTML', div);
		opener.editor2.editor.document.getElementById(ran).innerHTML = tag;
	}

	
	window.close();
}

function guardarImagenZona(imagen, align, title, border, width, height, vspace, hspace, zona){
	
	var tag = "<img src=" + imagen + "  align=" + align + " border=" + border + " ";
	if(title != "")
		tag += "title=" + title + " ";
		
	if(width != "")
		tag += "width=" + width + " ";
		
	if(height != "")
		tag += "height=" + height + " ";
		
	tag += "vspace=" + vspace + " hspace=" + hspace + ">";
	
	opener.document.getElementById('imagen'+zona).innerHTML = tag;
	
	window.close();
}

function validaNoticia(){
	
	if(document.registro.fecha.value == ""){
		alert("Seleccione la fecha de la noticia");
		return false;
	}
	if(document.registro.titulo.value == ""){
		alert("Ingresa el título de la noticia");
		document.registro.titulo.focus();
		return false;
	}
	if(document.registro.autor.value == ""){
		alert("Seleccione un autor para la noticia, después podrá modificarlo");
		document.registro.autor.focus();
		return false;
	}
	if(document.registro.richEdit0.value == ""){
		alert("Ingresa el contenido inicial de la noticia, después podrá modificarlo");
		return false;
	}
	return true;
}

function eliminarNoticia(idc, idn){
	if(confirm("Desea eliminar la Noticia?")){
		location.href='eliminar.php?idc=' + idc + '&idn=' + idn;
	}
	
}

function validaAnuncio(){
	
	if(document.registro.fecha.value == ""){
		alert("Seleccione la fecha del Anuncio");
		return false;
	}
	if(document.registro.titulo.value == ""){
		alert("Ingresa el título del Anuncio");
		document.registro.titulo.focus();
		return false;
	}
	if(document.registro.richEdit0.value == ""){
		alert("Ingresa el contenido inicial del Anuncio, después podrá modificarlo");
		return false;
	}
	return true;
}

function eliminarAnuncio(idc, ida){
	if(confirm("Desea eliminar el Anuncio?")){
		location.href='eliminar.php?idc=' + idc + '&ida=' + ida;
	}
	
}

function validaGrupo(){
	
	if(document.registro.nombre.value == ""){
		alert("Ingrese el nombre del grupo de contactos para correo");
		document.registro.nombre.focus();
		return false;
	}
	return true;
}
function eliminarGrupo(idc, idg){
	if(confirm("Desea eliminar el Grupo de contactos?")){
		location.href='eliminar.php?idc=' + idc + '&idg=' + idg;
	}
	
}

function validaSuscriptor(){
	
	if(document.registro.correo.value == ""){
		alert("Ingrese el correo del nuevo suscriptor");
		document.registro.correo.focus();
		return false;
	}
	return true;
}

function desmarcarCasillas(cant){
	for(i = 0; i < cant; i++){
		var id = document.getElementById("grupo" + i);
		id.checked = false;
	}
	
}
function desmarcarRadio(){
	var id = document.getElementById("singrupo");
	id.checked = false;
}

function eliminarSuscriptor(idc, ids, idg){
	if(confirm("Desea eliminar al suscriptor?")){
		location.href='eliminar.php?idc=' + idc + '&ids=' + ids + '&idg=' + idg;
	}
	
}

function mensajeSubirImagen(){
	var img = document.getElementById("imagenD");
	var msg = document.getElementById("mensajeD");
	
	img.style.display='none';
	msg.style.display='block';
}

function eliminarImagen(idc, idi){
	if(confirm("Desea eliminar la imágen del catálogo?")){
		location.href='eliminar.php?idc=' + idc + '&idi=' + idi;
	}
	
}

function validaBoletin(){
	
	if(document.registro.numero.value == ""){
		alert("Ingrese el numero de su boletín");
		document.registro.numero.focus();
		return false;
	}
	if(document.registro.anio.value == ""){
		alert("Ingrese el año de su boletín");
		document.registro.anio.focus();
		return false;
	}
	if(document.registro.fecha.value == ""){
		alert("Ingrese la fecha de su boletín");
		document.registro.fecha.focus();
		return false;
	}
	if(document.registro.nombre.value == ""){
		alert("Indique un nombre para su boletín");
		document.registro.nombre.focus();
		return false;
	}
	return true;
}
function eliminarBoletin(idc, idb){
	if(confirm("Desea eliminar este boletín?")){
		location.href='eliminar.php?idc=' + idc + '&idb=' + idb;
	}
	
}

function mostrarDiv(div, img, url){
	
	document.getElementById(img).src = url;
	document.getElementById(div).style.display='block';
}

function ocultarDivs(){
	document.getElementById("saludoEntry").style.display='none';
	document.getElementById("informacionEntry").style.display='none';
}


function asigna(id, propiedad, valor){
	if(document.layers) 
		eval('document.'+id+'.'+propiedad+'='+valor);
	if(document.all) 
		eval(id+'.style.'+propiedad+'='+valor);
	if(!document.all&&document.getElementById) 
		eval('document.getElementById("'+id+'").style.'+propiedad+'='+valor); 
} 

var poX=0, poY=0, poD=0, poA=0, poaX=0, poaY=0;

function mostrarImagenOriginal(img, w, h){
	
	document.getElementById("imgImagenOriginal").src = "";
	
	var evento = window.event;
	if(evento == null)
		evento = arguments[0];
	
	document.getElementById("imgImagenOriginal").src = img;
	
	document.getElementById("imgImagenOriginal").style.width = w;
	document.getElementById("imgImagenOriginal").style.height = h;
	asigna('imagenOriginal', 'width', w);
	asigna('imagenOriginal', 'height', h);
	
	var pos = posicionDelRaton(evento);
	
	asigna('imagenOriginal', 'left', poX);
	asigna('imagenOriginal', 'top', poY);
	
	asigna('imagenOriginal','display','""'); 
}

function ocultarImagenOriginal(){
	document.getElementById("imgImagenOriginal").src = "";
	asigna('imagenOriginal','display','"none"'); 
}

function posicionDelRaton(e){ 
	if(document.all){
		poX=event.x+document.body.scrollLeft; 
		poY=event.y+document.body.scrollTop;
		poD=document.body.offsetWidth-poX; 
		poA=document.body.offsetHeight-poY; 
		if(poD>0&&poD<imagenOriginal.offsetWidth)
			poX=document.body.scrollLeft+event.x-imagenOriginal.offsetWidth;
		else
			poX=document.body.scrollLeft+event.x;
		if(poA>0&&poA<imagenOriginal.offsetHeight)
			poY=document.body.scrollTop+event.y-imagenOriginal.offsetHeight;
		else
			poY=document.body.scrollTop+event.clientY;
	}
	else{
		poX=e.pageX; 
		poY=e.pageY;
		poD=window.innerWidth-poX; 
		poA=window.innerHeight-poY; 
		if(document.getElementById){ 
			if(poD>0&&poD<document.getElementById('imagenOriginal').offsetWidth)
				poX=e.pageX-document.getElementById('imagenOriginal').offsetWidth;
			else 
				poX=e.pageX; 
			if(poA>0&&poA<document.getElementById('imagenOriginal').offsetHeight)
				poY=e.pageY-document.getElementById('imagenOriginal').offsetHeight;
			else 
				poY=e.pageY;
		} 
		else{
			if(poD>0&&poD<document.imagenOriginal.document.width)
			poX=e.pageX-document.imagenOriginal.document.width;
		else 
			poX=e.pageX; 
			if(poA>0&&poA<document.imagenOriginal.document.height)
				poY=e.pageY-document.imagenOriginal.document.height;
		else 
			poY=e.pageY;
		} 
	} 
} 


function seleccionarPlantilla(idb, page){

	document.location.href= page + "?idb=" + idb + "&idcat=" + document.registro.categoria.options[document.registro.categoria.selectedIndex].value;
}

function continuar(){
	var id = document.getElementById("continuar");
	id.style.display = "";
	document.registro.submit.click();
}
function mostrar(idName){
	parent.editor1.field.innerText = "";
	parent.editor2.field.innerText = "";
	var id = parent.document.getElementById(idName);
	id.style.display = '';
}

var tituloN = new Array();
var cuerpoN = new Array();
var autorN = new Array();
var correoN = new Array();

var titulo = new Array();
var cuerpo = new Array();
var autor = new Array();
var correo = new Array();
var descripcion = new Array();

var tituloAN = new Array();
var cuerpoAN = new Array();
var linkAN = new Array();

function vistaPreviaBoletin(){
	var estilos =  window.frames['boletinFrame'].document.getElementsByTagName("style")[0].innerHTML;
	estilos = "<style>" + estilos + "</style>";

	document.getElementById("htmlContenido").innerHTML = base64Encode(estilos + window.frames['boletinFrame'].document.getElementById("contenidoBoletin").innerHTML);
	abrirVentanaConScroll("vistaprevia.php", "boletin", 690, 780);

}

function eliminarTags(){
	
	if(document.getElementById("instruccion") != null){
		document.getElementById("instruccion").innerText = "";
		document.getElementById("instruccion").innerHTML = "";
	}
	
	if(document.getElementById("enlaceSaludo") != null){
		document.getElementById("enlaceSaludo").innerText = "";
		document.getElementById("enlaceSaludo").innerHTML = "";
	}
	
	if(document.getElementById("enlaceArticulos") != null){
		document.getElementById("enlaceArticulos").innerText = "";
		document.getElementById("enlaceArticulos").innerHTML = "";
	}
	
	if(document.getElementById("enlaceInformacion") != null){
		document.getElementById("enlaceInformacion").innerText = "";
		document.getElementById("enlaceInformacion").innerHTML = "";
	}
	
	if(document.getElementById("enlaceNoticias") != null){
		document.getElementById("enlaceNoticias").innerText = "";
		document.getElementById("enlaceNoticias").innerHTML = "";
	}
	
	if(document.getElementById("enlaceAnuncios") != null){
		document.getElementById("enlaceAnuncios").innerText = "";
		document.getElementById("enlaceAnuncios").innerHTML = "";
	}
	var enlaces = document.getElementsByName("enlace");
	if(enlaces != null){
		for(i = 0; i < enlaces.length; i++){
			if(enlaces[i] != "[object HTMLInputElement]")
				enlaces[i].innerHTML = "";
		}
	}
}



function clickConfiguracion(img, elem){
	var seccion = document.getElementById(elem);
	var imagen = document.getElementById(img);
	
	if(seccion.style.display == "none"){
		imagen.src="../../images/menos_negro.gif";
		seccion.style.display="block";
	}
	else{
		imagen.src="../../images/mas_negro.gif";
		seccion.style.display="none";
	}
	
}

function cambiarColor(seccion, color){
	window.frames['boletinFrame'].document.getElementById(seccion).style.backgroundColor = color;
}
function cambiarFuente(selector, seccion){
	fuente = document.getElementById(selector).options[document.getElementById(selector).selectedIndex].value;
	switch(fuente){
		case "Verdana":
			fuente = "Verdana, Arial, Helvetica, sans-serif";
			break;
		case "Arial":
			fuente = "Arial, Helvetica, sans-serif";
			break;
		case "Helvetica":
			fuente = "Georgia, 'Times New Roman', Times, serif";
			break;
		case "sans-serif":
			fuente = "'Times New Roman', Times, serif";
			break;
		
	}
	window.frames['boletinFrame'].document.getElementById(seccion).style.fontFamily = fuente;
}

function cambairTextoIdentificador(id){
	var ident = window.frames['boletinFrame'].document.getElementById(id);
	var valor = prompt("Identificador: ", ident.innerText);
	ident.innerText = valor;
}

function cambiarSize(selector, seccion){
	size = document.getElementById(selector).options[document.getElementById(selector).selectedIndex].value;
	
	window.frames['boletinFrame'].document.getElementById(seccion).style.fontSize = size + "px";
}

function cambiarColorFuente(seccion, color){
	window.frames['boletinFrame'].document.getElementById(seccion).style.color = color;
}

function cambiarFondoAN(seccion, color){
	
	var elementos = window.frames['boletinFrame'].document.getElementsByName(seccion);
	for(i = 0; i < elementos.length; i++){
		elemento = elementos[i];
		elemento.style.backgroundColor = color;
	}
}

function cambiarFuenteAN(selector, seccion){
	fuente = document.getElementById(selector).options[document.getElementById(selector).selectedIndex].value;
	switch(fuente){
		case "Verdana":
			fuente = "Verdana, Arial, Helvetica, sans-serif";
			break;
		case "Arial":
			fuente = "Arial, Helvetica, sans-serif";
			break;
		case "Helvetica":
			fuente = "Georgia, 'Times New Roman', Times, serif";
			break;
		case "sans-serif":
			fuente = "'Times New Roman', Times, serif";
			break;
		
	}
	var elementos = window.frames['boletinFrame'].document.getElementsByName(seccion);
	for(i = 0; i < elementos.length; i++){
		elemento = elementos[i];
		elemento.style.fontFamily = fuente;
	}
}


function cambiarSizeAN(selector, seccion){
	size = document.getElementById(selector).options[document.getElementById(selector).selectedIndex].value;
	
	var elementos = window.frames['boletinFrame'].document.getElementsByName(seccion);
	for(i = 0; i < elementos.length; i++){
		elemento = elementos[i];
		elemento.style.fontSize = size + "px";
	}
}

function cambiarColorFuenteAN(seccion, color){
	
	var elementos = window.frames['boletinFrame'].document.getElementsByName(seccion);
	for(i = 0; i < elementos.length; i++){
		elemento = elementos[i];
		elemento.style.color = color;
	}
}


function panelConfiguracion(){
	var logo = window.frames['boletinFrame'].document.getElementById("logo");
	var headerImg = window.frames['boletinFrame'].document.getElementById("headerIMG");
	var cuerpo = window.frames['boletinFrame'].document.getElementById("cuerpo");
	var estilo = window.frames['boletinFrame'].document.getElementById("estilo");
	var cabecera = window.frames['boletinFrame'].document.getElementById("cabecera");
	var identificador = window.frames['boletinFrame'].document.getElementById("identificador");
	var introduccion = window.frames['boletinFrame'].document.getElementById("introduccion");
	var noticias = window.frames['boletinFrame'].document.getElementById("noticiasDiv");
	var anuncios = window.frames['boletinFrame'].document.getElementById("anunciosDiv");
	var contenido = window.frames['boletinFrame'].document.getElementById("contenidoDiv");
	var articulos = window.frames['boletinFrame'].document.getElementById("articulosDiv");
	var despedida = window.frames['boletinFrame'].document.getElementById("despedidaDiv");
	
	if(cuerpo != null){
		document.getElementById("configuracionTexto").style.display='block';
	}
	
	if(logo != null){
		document.getElementById("configuracionLogo").style.display='block';
	}
	if(headerImg != null){
		document.getElementById("configuracionHeaderImg").style.display='block';
	}
	
	if(estilo != null){
		document.getElementById("configuracionEstilo").style.display='block';
	}
	
	if(cabecera != null){
		font = window.frames['boletinFrame'].document.getElementById("encabezado").style.fontFamily;
		size = window.frames['boletinFrame'].document.getElementById("encabezado").style.fontSize;
		background = window.frames['boletinFrame'].document.getElementById("encabezado").style.backgroundColor;
		color = window.frames['boletinFrame'].document.getElementById("encabezado").style.color;
		
		//alert(font + " - " + size + " - " + color + " - " + background);
		document.getElementById("configuracionEncabezado").style.display='block';
	}
	
	if(identificador != null){
		font = window.frames['boletinFrame'].document.getElementById("identificador").style.fontFamily;
		size = window.frames['boletinFrame'].document.getElementById("identificador").style.fontSize;
		color = window.frames['boletinFrame'].document.getElementById("identificador").style.color;
		
		document.getElementById("configuracionIdentificador").style.display='block';
	}
	
	if(noticias != null){
		/*font = window.frames['boletinFrame'].document.getElementById("titulonoticia").style.fontFamily;
		size = window.frames['boletinFrame'].document.getElementById("titulonoticia").style.fontSize;
		color = window.frames['boletinFrame'].document.getElementById("titulonoticia").style.color;
		*/
		document.getElementById("configuracionNoticias").style.display='block';
	}
	
	if(articulos != null){
		/*font = window.frames['boletinFrame'].document.getElementById("tituloarticulo").style.fontFamily;
		size = window.frames['boletinFrame'].document.getElementById("tituloarticulo").style.fontSize;
		color = window.frames['boletinFrame'].document.getElementById("tituloarticulo").style.color;
		*/
		document.getElementById("configuracionArticulos").style.display='block';
	}
	if(anuncios != null){
		/*font = window.frames['boletinFrame'].document.getElementById("tituloarticulo").style.fontFamily;
		size = window.frames['boletinFrame'].document.getElementById("tituloarticulo").style.fontSize;
		color = window.frames['boletinFrame'].document.getElementById("tituloarticulo").style.color;
		*/
		document.getElementById("configuracionAnuncios").style.display='block';
	}
}

function estiloSika(color, img){
	window.frames['boletinFrame'].document.getElementById("headerIMG").src = img;
	cambiarColorFuenteAN('tituloarticulo', '#000000');
	cambiarColorFuenteAN('titulonoticia', '#000000');
	cambiarColorFuenteAN('cuerpoarticulo', '#000000');
	cambiarColorFuenteAN('cuerponoticia', '#000000');
	cambiarFondoAN('titulonoticia', color);
	cambiarFondoAN('tituloarticulo', color);
	
}
function insertarLogo(logo){
	window.frames['boletinFrame'].document.getElementById("logo").innerHTML = "<img src='" + logo + "'><br><br>";	
}
function removerLogo(){
	window.frames['boletinFrame'].document.getElementById("logo").innerHTML = "";	
}

function cambiarEstilo(color, host){
	var bg = "http://" + host + "header1.gif";
	var img = "url('http://" + host + "header1.gif')";
	var noticias = "#4AD0F6";
	var anuncios = "#014E69";

	switch(color){
		case "azul":
			img = "url('http://" + host + "header1.gif')";
			bg = "http://" + host + "header1.gif";
			noticias = "#4AD0F6";
			anuncios = "#014E69";
			break;
		case "rojo":
			img = "url('http://" + host + "header2.gif')";
			bg = "http://" + host + "header2.gif";
			noticias = "#9C0324";
			anuncios = "#630218";
			break;
		case "verde":
			img = "url('http://" + host + "header3.gif')";
			bg = "http://" + host + "header3.gif";
			noticias = "#287702";
			anuncios = "#1C5403";
			break;
	}

	window.frames['boletinFrame'].document.getElementById("headerId").background = bg;
	window.frames['boletinFrame'].document.getElementById("headerId").style.backgroundImage = img;
	window.frames['boletinFrame'].document.getElementById("estiloAnuncios").style.backgroundColor = anuncios;
	
	var elementos = window.frames['boletinFrame'].document.getElementsByName("estiloNoticias");
	
	for(i = 0; i < elementos.length; i++){
		elemento = elementos[i];
		elemento.style.color = noticias;
	}
	
}

function actualizarCodigoIframe(host, idcName, idc, idgName, idg){
	var url = "<div align='center' style='text-align:center; '>\n<iframe\n src='http://" + host + "/suscripcion/index.php?" + idcName + "=" + idc + "'\n frameborder='0'\n scrolling='no'\n width='150'\n height='120'>\n</iframe>\n</div>";
	
	if(idg != "")
		url = "<div align='center' style='text-align:center; '>\n<iframe\n src='http://" + host + "/suscripcion/index.php?" + idcName + "=" + idc + "&" + idgName + "=" + idg + "'\n frameborder='0'\n scrolling='no'\n width='150'\n height='120'>\n</iframe>\n</div>";
	
	document.getElementById("codigoiframe").value = url;	
}

function actualizarCodigoPersonalizado(host, idcName, idc, idgName, idg){
	
	var url = "<form name='suscripcion' action='http://" + host + "/suscripcion/guardar.php' method='post'>\n<input type='hidden' name='" + idcName + "' value='" + idc + "'>\n<div align='center' style='text-align:center; '>\n<table width='140' border='1' cellpadding='2' cellspacing='0' style='border-width:1px; border-color:#999999; '>\n<tr>\n<td>\n<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n<tr>\n<td class='titulo'>Suscribete a nuestro bolet&iacute;n</td>\n</tr>\n<tr>\n<td style='text-align:left; '>Nombre</td>\n</tr>\n<tr>\n<td><input type='text' name='nombre' size='23'></td>\n</tr>\n<tr>\n<td style='text-align:left; '>Correo</td>\n</tr>\n<tr>\n<td><input type='text' name='correo' size='23'></td>\n</tr>\n<tr>\n<td style='text-align:center; '><input type='submit' name='submit' value='Suscribir' style='text-align:center; '></td>\n</tr>\n</table>\n</td>\n</tr>\n</table>\n</div>\n</form>";
	
	if(idg != "")
		url = "<form name='suscripcion' action='http://" + host + "/suscripcion/guardar.php' method='post'>\n<input type='hidden' name='" + idcName + "' value='" + idc + "'>\n<input type='hidden' name='" + idgName + "' value='" + idg + "'>\n<div align='center' style='text-align:center; '>\n<table width='140' border='1' cellpadding='2' cellspacing='0' style='border-width:1px; border-color:#999999; '>\n<tr>\n<td>\n<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n<tr>\n<td class='titulo'>Suscribete a nuestro bolet&iacute;n</td>\n</tr>\n<tr>\n<td style='text-align:left; '>Nombre</td>\n</tr>\n<tr>\n<td><input type='text' name='nombre' size='23'></td>\n</tr>\n<tr>\n<td style='text-align:left; '>Correo</td>\n</tr>\n<tr>\n<td><input type='text' name='correo' size='23'></td>\n</tr>\n<tr>\n<td style='text-align:center; '><input type='submit' name='submit' value='Suscribir' style='text-align:center; '></td>\n</tr>\n</table>\n</td>\n</tr>\n</table>\n</div>\n</form>";
	
	document.getElementById("codigopersonalizado").value = url;	
}

var finalizo = false;
var intervalos;
function enviarBoletin(cantGpos, estatus, cantSusc, idcliente, fechaReg){
	cantGpos++;

	if(document.envioForm.idb.options[document.envioForm.idb.selectedIndex].value == ""){
		alert("Seleccione el boletín que desea enviar");
		return false;
	}
	
	var grupo = false;
	for(i = 0; i < cantGpos; i++){
		if(document.getElementById("grupo" + i).checked){
			grupo = true;
			break;
		}
	}
	
	
	datosFecha = fechaReg.split("/");
	fechaRegistro = new Date(datosFecha[2], datosFecha[1] - 1, datosFecha[0], 0,0,0,0);
	fechaPrecios = new Date(2009, 6, 18, 0,0,0,0);
	fechaVence = new Date();
	fechaVence.setTime(parseInt(fechaRegistro.getTime() + (15*24*60*60*1000)));
	
	hoy = new Date();
	
	fechaFormato = fechaVence.getDate() + "_" + (fechaVence.getMonth() + 1) + "_" + fechaVence.getYear();
		
	if(!grupo){
		alert("Seleccione al menos un grupo de suscriptores");
		return false;
	}
	
	if(estatus == "vencio"){
		alert("Su cuenta ha exedido el numero de envíos permitidos durante el periodo de prueba.\n");
		alert("Para continuar enviando boletines/newsletters debe contratar el servicio de acuerdo a la cantidad de contactos que tienes en su base de datos");
		return false;
	}
	
	if(estatus == "suspendido"){
		alert("Su cuenta esta suspendida, para poder reactivarla siga las instrucciones de la pagina de inicio.\n");
		location.href="../inicio.php";
		return false;
	}
	
	if((fechaRegistro < fechaPrecios) && (estatus == "registro") && (cantSusc > 50) && (idcliente != 1946)){
		document.location.href='contratar.php';
		return false;
	}
	else if((fechaRegistro > fechaPrecios) && (fechaVence > hoy) && (estatus == "registro") && (cantSusc > 500) && (idcliente != 1946)){
		document.location.href='contratar.php?estatus=cantidad&fecha=' + fechaFormato;
		return false;
	
	}
	else if((fechaRegistro > fechaPrecios) && (fechaVence < hoy) && (estatus == "registro") && (cantSusc > 5) && (idcliente != 1946)){
		document.location.href='contratar.php?estatus=vencio';
		return false;
	}
	
	
	//INICIA PROCESO DE ENVIO DE BOLETINES
	//Inhabilitamos boton de envio
	document.getElementById("EnviarButton").disabled=true;
	
	//Eliminamos tags
	var idbol = document.envioForm.idb.options[document.envioForm.idb.selectedIndex].value;
	var parametros = "'directories=no, location=no, scrollbars=no, menubar=no, status=yes, resizable=no, width=" + 20 + ", height=" + 20 + "'";
	var win = window.open('sintags.php?idb=' + idbol, 'boletin', parametros);
	win.moveTo(screen.availWidth - 20, screen.availHeight - 20);
	
	intervalos = setInterval(verificaEliminacionTags, 1000);
}

function verificaEliminacionTags(){
	if(finalizo){
		clearInterval(intervalos);
		document.envioForm.action = "iniciaEnvio.php";
		document.envioForm.submit();
	}
}

function finalizoCarga(){
	var elementosStyle = document.getElementsByTagName("STYLE");
	var estilos =  "";
	if((elementosStyle != null) && (elementosStyle.length > 0)){
		estilos =  elementosStyle[0].innerHTML;
	}
	estilos = "<HTML><HEAD><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'><STYLE type='text/css'>" + estilos + "</STYLE></HEAD><BODY>";
	opener.document.getElementById("htmlContenido").innerHTML = base64Encode(estilos + document.getElementById("contenidoHTML").innerHTML + "</BODY></HTML>");
	opener.finalizo=true;
	window.close();
}

var orden = 0;
var ordenN = 0;
var ordenA = 0;
function estableceOrden(seccion, check, id){
	var ord = 0;
	if(document.getElementById(check).checked){
		ord = incrementar(seccion);
		document.getElementById(id).value = ord;
	}else{
		decrementar(seccion);
		document.getElementById(id).value = "";
	}
}
function incrementar(seccion){
	var ord = 0;
	switch(seccion){
		case "articulos":
			orden++;
			ord = orden;
			break;
		case "noticias":
			ordenN++;
			ord = ordenN;
			break;
		case "anuncios":
			ordenA++;
			ord = ordenA;
			break;
	}
	return ord;
}
function decrementar(seccion){
	switch(seccion){
		case "articulos":
			orden--;
			break;
		case "noticias":
			ordenN--;
			break;
		case "anuncios":
			ordenA--;
			break;
	}
}

function validarContacto(){
	if(document.contacto.asunto.value == ""){
		alert("Indique el asunto de la solicitud");
		document.contacto.asunto.focus();
		return false;
	}
	if(document.contacto.descripcion.value == ""){
		alert("Indique una breve descripcion de la solicitud");
		document.contacto.descripcion.focus();
		return false;
	}
	return true;
	
}
function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}

function setScrollTo(s){
	if(window.pageYOffset != null)
		window.pageYOffset = s;
	else if(document.body.scrollTop != null)
		document.body.scrollTop = s;
	else if(document.documentElement.scrollTop != null)
		document.documentElement.scrollTop = s;
	window.scrollTo(0,s);
}
function marcarSuscriptoresTodos(campo, cantidad){
	var h = getScrollHeight();
	var inputs = document.getElementsByTagName("input"); 
    for(var i=0; i<inputs.length; i++) { 
        if(inputs[i].type == "checkbox")  { 
            inputs[i].checked = true;
        } 
    } 
	setScrollTo(h);
}

function marcarTodos(campo, cantidad){
	for(i = 1; i <= cantidad; i++){
		id = document.getElementById(campo + i);
		if(id != null)
			id.checked = true;
	}
	
}

function desmarcarSuscriptoresTodos(campo, cantidad){
	var h = getScrollHeight();
	var inputs = document.getElementsByTagName("input"); 
    for(var i=0; i<inputs.length; i++) { 
        if(inputs[i].type == "checkbox")  { 
            inputs[i].checked = false;
        } 
    } 
	
	setScrollTo(h);
}

function desmarcarTodos(campo, cantidad){
	for(i = 1; i <= cantidad; i++){
		id = document.getElementById(campo + i);
		if(id != null)
			id.checked = false;
	}
}

function verificaAccion(accion, grupo){
	var idA = document.getElementById(accion);
	var idG = document.getElementById(grupo);
	if((idA.options[idA.selectedIndex].value == "mover") || (idA.options[idA.selectedIndex].value == "copiar"))
		idG.style.display = "";
	else
		idG.style.display = "none";
}

function accionSuscriptoresSeleccionados(cantidad, accion){
	var sel = false;
	for(i = 1; i <= cantidad; i++){
		id = document.getElementById("suscriptor" + i);
		if((id != null) && (id.checked == true)){
			sel = true;
			break;
		}
	}
	
	if(!sel){
		alert("Debe seleccionar al menos un suscriptor");
		return;
	}
	
	var idA = document.getElementById(accion);
	if(idA.options[idA.selectedIndex].value == "eliminarBD"){
		if(confirm("Esta seguro que desea eliminar definitivamente de la base de datos a los suscriptores seleccionados?")){
			document.selgrupo.action = "eliminarBDSeleccionados.php";
			document.selgrupo.submit();
		}
		else
			return;
	}
	if(idA.options[idA.selectedIndex].value == "eliminarG"){
		if(confirm("Esta seguro que desea eliminar de este grupo a los suscriptores seleccionados?")){
			document.selgrupo.action = "eliminarGSeleccionados.php";
			document.selgrupo.submit();
		}
		else
			return;
	}
	if(idA.options[idA.selectedIndex].value == "mover"){
		document.selgrupo.action = "moverSeleccionados.php";
		document.selgrupo.submit();
	}
	if(idA.options[idA.selectedIndex].value == "copiar"){
		document.selgrupo.action = "copiarSeleccionados.php";
		document.selgrupo.submit();
	}
}

function mostrarSuscriptores(inicio, fin, idg){
	var rp = document.getElementById("rp").value;
	location.href='index.php?inicio=' + inicio + '&fin=' + fin + '&rp=' + rp + '&idg=' + idg;
}

function contratar(cliente, lang){
	var tipo = document.getElementById("tipo").value;
	var pago = document.getElementById("pago").value;
	
	if((tipo == "")){
		if(lang == "english")
			alert("Choose the service to buy");
		else
			alert("Seleccione el esquema de servicio a contratar");
		return;		
	}
	tipo = parseInt(tipo);
	if((pago == "")){
		if(lang == "english")
			alert("Choose the payment frequency");
		else
			alert("Seleccione el esquema de pago");
		return;		
	}
	
	var servicio = -1;
	
	switch(tipo){
		case 500:
			if(pago == "mensual")
				servicio = 0;
			else
				servicio = 0;
			break;
		case 1500:
			if(pago == "mensual")
				servicio = 1;
			else
				servicio = 3;
			break;
		case 3000:
			if(pago == "mensual")
				servicio = 4;
			else
				servicio = 5;
			break;
		case 5000:
			if(pago == "mensual")
				servicio = 6;
			else
				servicio = 7;
			break;
		case 10000:
			if(pago == "mensual")
				servicio = 8;
			else
				servicio = 9;
			break;
		case 30000:
			if(pago == "mensual")
				servicio = 10;
			else
				servicio = 11;
			break;
		default:
			servicio = 1;
		
	}
	var url = "";
	if(servicio == 0)
		url = "../index.php";
	else
		url = "https://www.2checkout.com/2co/buyer/purchase?sid=1300119&product_id=" + servicio + "&quantity=1&utype=" + cliente + "&lang=" + lang;
	
	parent.location = url;
}


function cambiarIdioma(lang){
	var frame = parent.document.getElementById("contratar");
	if(lang == "english")
		frame.src = "frames/nuevo_en.php";
	else
		frame.src = "frames/nuevo.php";
	
}
function contratarNuevo(){
	var servicio = -1;
	for(i = 0; i < 12; i++){
		if(document.formaServicio.servicio[i].checked)
			servicio = document.formaServicio.servicio[i].value;
	}
	if(servicio == -1){
		alert("Seleccione el plan de contratación y forma de pago");
		return;
	}
	var url = "";
	if(servicio == 0){
		url = "../index.php";
	}else{
		url = "https://www.2checkout.com/2co/buyer/purchase?sid=1300119&product_id=" + servicio + "&quantity=1";
	}
	parent.parent.location = url;
	
}

function contratarCliente(){
	var servicio = 0;
	for(i = 0; i < 24; i++){
		if(document.formaServicio.servicio[i].checked)
			servicio = document.formaServicio.servicio[i].value;
	}
	if(servicio == 0){
		alert("Seleccione el plan de contratación y forma de pago");
		return;
	}
	var cliente = document.formaServicio.idc.value;
	var usuario = document.formaServicio.idu.value;
	var nombre = document.formaServicio.nombre.value;
	var correo = document.formaServicio.correo.value;
	var url = "https://www.2checkout.com/2co/buyer/purchase?sid=1300119&product_id=" + servicio + "&quantity=1&card_holder_name=" + nombre + "&email=" + correo + "&utype=cliente&idc=" + cliente + "&idu=" + usuario;
	if(servicio == 1)
		url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=M6CE7BZS4U74J";
	if(servicio == 3)
		url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Y9YHGK9VUJB8E";
	if(servicio == 4)
		url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SR46FEKFK7YYS";
	if(servicio == 5)
		url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=S5FH2GK2DK2ZE";
	if(servicio == 6)
		url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Q5NWPTQYVT3M6";
	if(servicio == 7)
		url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PKALDEL5JCJFS";
	if(servicio == 8)
		url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SCV6C3BH8458Q";
	if(servicio == 9)
		url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9RWDT8YC44F44";
	if(servicio == 16)
		url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8X5LEJ7JTHSRJ";
	//if(servicio == 20)
		//url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=59T9QGATDL85C";
		
	parent.parent.location = url;
	
}

function mostrarRegistro(){
	id = document.getElementById("imgContinuar");
	id.src = "../../images/registrate.gif";
}
function mostrarCompra(){
	id = document.getElementById("imgContinuar");
	id.src = "../../images/2cocc06.gif";
}
