// --------------------------------------------------------------------------------------------------- Funsiones Varias
function buscar(para) {
	tabla    = document.getElementById('campo').value;
	criterio = document.getElementById('buscar').value;
	url = 'fichas-busca.php?buscarpor='+tabla+'&iguala='+criterio+'&para='+para;
	llamarasincrono(url,'respuesta','')
	}
	
function ficha(php,id) {
	document.getElementById('mensaje').style.display="none";
	url = php+'.php?id='+id;
	llamarasincrono(url,'respuesta','')
	}

function ccolor(col) {
	document.getElementById(col).style.color='#ffffff';
	document.getElementById(col).style.backgroundColor='#990000';
	}

function estoyseguro() {
	if (document.getElementById('seguro').checked) {
		document.getElementById('bdele').disabled='';
		} else {
		document.getElementById('bdele').disabled='disabled';
		}
}

// ----------------------------------------------------------------- ULtimas Plazas
function ultimasplazas() {
    ultplazas = document.getElementById('disp_ultimas').value;
    if  (ultplazas == 'S') {
        // Clock = setInterval("cierraultimasplazas()",100)
        // setTimeout("cierraultimasplazas()",15000);
        document.getElementById('aviso').style.display="block";   
        // cierraultimasplazas(); 
    }
}

function cierraultimasplazas() {
    document.getElementById('aviso').style.display="none";
    // clearInterval(Clock);
}

// --------------------------------------------------------------------------------------------------  Funciones Edicion
function editContenido(id) {
	url = 'adm_contenidoedit.php?id='+id;
	location.href=url;
	}
	
function leeItems(seccion) {
	url = 'adm_contenido.php?seccion='+seccion;
	location.href=url;
	}

function deleContenido(secc,id,itemid) {
	if (itemid != 0) {
		if (confirm('Esta seguro de eliminar contenido?')) {
			document.getElementById('mensaje').style.display="block";
			url = 'adm_delecont.php?secc='+secc+'&id='+id;
			llamarasincrono(url,'mensaje','');
			}
		} else {
			alert('No puede eliminar contenido principal de sección');
		}
	}


function listaCS(secc) {
	if (document.getElementById('okReg').checked) {
		clearInterval(Clock);
		url = 'adm_cont.php?secc='+secc;
		llamarasincrono(url,'divItem','')	
		}   
	}


function cargarFoto(id,nom) {
	url = 'adm_fotocont.php?id=' + id + '&nom=' + nom ;
	x = window.open(url,'Foto','width=600,height=245,toolbar=no,location=no,status=no,resizable=no');
	}
	
function seccionLee(seccion) {
	url = 'adm_contenido.php?seccion='+seccion;
	location.href=url;
	}
	

function newItem() {
	document.getElementById('divItem').style.display="block";
	}
	
function saveItem() {
	error = '';
	seccion		= document.getElementById('seccion').value;
	nitem		= document.getElementById('item').value;
	subtitem	= document.getElementById('subitem').value;
	enlace		= document.getElementById('descripcion').value;
	titulo		= document.getElementById('titulo').value;
	
	if 	(isNaN(nitem) || isNaN(subtitem))  { error += 'Item y SubItem deben ser valores numericos \n'; }
	if 	(nitem == 0 )    { error += 'Item "0" solo se puede usar para contenido principal de sección \n'; }
	if 	(enlace == '' )  { error += 'Debe ingresar Desc. Menu \n' }
	
	if  (error != '')    { 
			alert(error); 
		} else {
			document.getElementById('divItem').style.display="none";
			post = 'seccion='+seccion+'&item='+nitem+'&subitem='+subtitem+'&descripcion='+enlace+'&titulo='+titulo;
			document.getElementById('mensaje').style.display="block";
			url = 'adm_saveitem.php';
			llamarasincrono(url,'mensaje',post)	
		}
	}
	
	function Recarga(secc,nitem,subitem,enlace,titulo) {
		if (document.getElementById('okReg').checked) {
			clearInterval(Clock);
			url = 'adm_cont.php?secc='+secc+'&item='+nitem+'&subitem='+subtitem+'&descripcion='+enlace;
			url += '&titulo='+titulo;
			llamarasincrono(url,'divItem2','')	
			}   
		}
		
function esPrincipal() {
	if (document.getElementById('principal').checked) {
		document.getElementById('item').disabled="disabled";
		document.getElementById('subitem').disabled="disabled";
		document.getElementById('descripcion').disabled="disabled";
		document.getElementById('titulo').disabled="disabled";
		document.getElementById('item').value = '0';
		document.getElementById('subitem').value = '0';
		document.getElementById('descripcion').value = 'Intro';
		document.getElementById('titulo').value = 'Intro';
		} else {   
		document.getElementById('item').disabled="";
		document.getElementById('subitem').disabled="";
		document.getElementById('descripcion').disabled="";
		document.getElementById('titulo').disabled="";
		}
	}

function editPermiso(idper) {
	url = 'adm_permisoedit.php?id='+idper;
	location.href=url;
}

//------------------------------------------------------------------------------------------------
// Browser Slide-Show script.
// With image cross fade effect for those browsers that support it.
var slideCache = new Array();
function RunSlideShow(pictureName,imageFiles,displaySecs) {
    var imageSeparator = imageFiles.indexOf(";");
    var nextImage = imageFiles.substring(0,imageSeparator);
    if (document.all) {
        document.getElementById(pictureName).style.filter="blendTrans(duration=2)";
        document.getElementById(pictureName).filters.blendTrans.Apply();
    }
    document.getElementById(pictureName).src = nextImage;
    
    if (document.all) {
        document.getElementById(pictureName).filters.blendTrans.Play();
    }
    var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)
    + ';' + nextImage;
    setTimeout("RunSlideShow('"+pictureName+"','"+futureImages+"',"+displaySecs+")",displaySecs*1000);
    
    // Cache the next image to improve performance.
    imageSeparator = futureImages.indexOf(";");
    nextImage = futureImages.substring(0,imageSeparator);
    if (slideCache[nextImage] == null) {
        slideCache[nextImage] = new Image;
        slideCache[nextImage].src = nextImage;
    }
}
