function nuevoAjax(){ 
	var objeto=false; 

	if(window.XMLHttpRequest){
		objeto = new XMLHttpRequest(); 
	}else{ 
		try{
			objeto = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
		catch (e){
			alert('El navegador utilizado no cumple los requisitos para ver esta p&aacute;gina.');
		}
	}

	return objeto; 
}

function cargaContenido(ori){
	
		ajax=nuevoAjax();
		ajax.open("GET",ori, true);
		ajax.onreadystatechange=function() { 
			if ((ajax.readyState==4) && (ajax.status==200) ){ 
				document.getElementById('cuerpo').innerHTML=ajax.responseText;
				initLightbox();
			} 
			if (ajax.readyState==1) { 
				document.getElementById('cuerpo').innerHTML = "<div align='center'>Cargando...</div>";
			} 		
		}
		ajax.send(null);
}

function cargaContenido2(ori,valores, texto){
	
		ajax=nuevoAjax();
		ajax.open("POST",ori, true);
		ajax.onreadystatechange=function() { 
			if ((ajax.readyState==4) && (ajax.status==200) ){ 
				document.getElementById('error5').innerHTML=texto;
				document.getElementById('cuerpo').innerHTML=ajax.responseText;
			} 
			if (ajax.readyState==1) { 
				document.getElementById('cuerpo').innerHTML = "<div align='center'>Cargando...</div>";
			} 		
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(valores);
}

function cargaContenido3(ori,des, valores, texto){
	
		ajax=nuevoAjax();
		ajax.open("POST",ori, true);
		ajax.onreadystatechange=function() { 
			if ((ajax.readyState==4) && (ajax.status==200) ){ 
				document.getElementById(des).innerHTML=texto;
				document.getElementById(des).innerHTML=ajax.responseText;
			} 
			if (ajax.readyState==1) { 
				document.getElementById(des).innerHTML = "<div align='center'>Cargando...</div>";
			} 		
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(valores);
}

function cargaContenido4(ori){
	
		ajax=nuevoAjax();
		ajax.open("GET",ori, true);
		ajax.onreadystatechange=function() { 
			if ((ajax.readyState==4) && (ajax.status==200) ){ 
				document.getElementById('cuerpo').innerHTML=ajax.responseText;
			} 
			if (ajax.readyState==1) { 
				document.getElementById('cuerpo').innerHTML = "<div align='center'>Cargando...</div>";
			} 		
		}
		ajax.send(null);
}




function eMsg(msg,sColor,id){
    var div = document.getElementById(id);
    div.style.color=sColor;
    div.style.fontSize="10";
    //remove old messages
    if(div.hasChildNodes()){
        div.removeChild(div.firstChild);
    }
    div.appendChild(document.createTextNode(msg));

}



function validacion_usuario(m) {

var bien =true


	if (document.getElementById('nombre').value==''){
		eMsg("Debe introducir un Nombre de Usuario","red","error1")
		bien=false
	}else{
		eMsg("","red","error1")
	}
	
	if (document.getElementById('contra').value==''){
		eMsg("Debe introducir una Contraseña","red","error2")
		bien=false
	}else{
		eMsg("","red","error2")
		if (document.getElementById('contra').value != document.getElementById('contra2').value){
			eMsg("Error en la confirmaci&oacute;n de la contraseña","red","error3")
			bien=false
		}else{
			eMsg("","red","error3")
		}
	}

	if(bien==true){
		var texto=''
		if(m=='si'){
			var valores='modi=si&nombre='+document.getElementById('nombre').value+'&contra='+document.getElementById('contra').value+'&id='+document.getElementById('id').value
		}else{
			var valores='guardar=si&nombre='+document.getElementById('nombre').value+'&contra='+document.getElementById('contra').value
		}
		
		cargaContenido3('guardar_usuario.php','error5',valores,texto)
	}else{
		return bien	
	}

}

function eliminar (pagina,id){
	if (confirm('¿Esta seguro que desea eliminar este registro?')){

		var valores=pagina+"?eliminar=si&id="+id
		cargaContenido4(valores)		
	}	
}


function validacion_noticia(p) {

	var valores='guardar=si&fecha='+document.getElementById('txtDate').value+'&titulo='+document.getElementById('nombre').value+'&descrip='+document.getElementById('descrip').value+'&url='+document.getElementById('url').value+'&tipo='+document.getElementById('tipo').value
		
	cargaContenido3(p,'cuerpo',valores,'')


}
function validacion_noticia2(p) {

	var valores='guardar=si&fecha='+document.getElementById('txtDate').value+'&descrip='+document.getElementById('descrip').value+'&archivo='+document.getElementById('archivo').value+'&tipo='+document.getElementById('tipo').value
		
	cargaContenido3(p,'cuerpo',valores,'')


}

function correo(formulario){
	
	var valores='nombre='+formulario.nombre.value+'&apellidos='+formulario.apellidos.value+'&email='+formulario.email.value+'&asunto='+formulario.asunto.value+'&comentarios='+formulario.comentarios.value
	
	cargaContenido3('correo.php','cor',valores,'')
	
}

function editar(id){
	

	var newWindow;
	var pa='editar.php?id='+id
	newWindow = window.open(pa,'','height=280,width=650,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=yes')

}