function CrearAJAX() {
	
	var re = false;
	
	try {
		re = new ActiveXObject('Msxml2.XMLHTTP');
	} catch(e1) {
		try {
		re = new ActiveXObject('Microsoft.XMLHTTP');
	} catch(e2) {
		re = false;
	}
	}
	
	if(!re && (typeof XMLHttpRequest != 'undefined' || window.XMLHttpRequest)) {
		re = new XMLHttpRequest();
	}
		
	return re;
}

var ajax = CrearAJAX();

function procesar(id) {
	var rand = Math.random(9999);
	var dire = id + '.php?rand=' + rand;
	
	ajax.open('GET', dire, true);
	ajax.onreadystatechange = tab;
	ajax.send(null);
}


function tab() {
	if(ajax.readyState != 4) {
		document.getElementById('content').innerHTML = "Cargando...";
	} else {
		document.getElementById('content').innerHTML = ajax.responseText;
	}
}


function hideshow(which){
if (!document.getElementById)
return
if (which.style.display=="block")
which.style.display="none"
else
which.style.display="block"
}


function addText( text, text2, id )
{
    diff = document.getElementById('charEnd').value - document.getElementById('charStart').value;
    document.getElementById( id ).value = document.getElementById( id ).value.substr( 0, document.getElementById('charStart').value ) + text + document.getElementById( id ).value.substr( document.getElementById('charStart').value, diff ) + text2 + document.getElementById( id ).value.substr( document.getElementById('charEnd').value );
    document.getElementById( id ).focus();
    CharPos( id );
    return true;
}

function getCharPos( id )
{
    var charPos = new Object();
    var element = document.getElementById( id );
    if( document.all ){
        var range = document.selection.createRange();
        var stored_range = range.duplicate();
        stored_range.moveToElementText( element );
        stored_range.setEndPoint('EndToEnd', range );
        charPos.start = stored_range.text.length - range.text.length;
        charPos.end = charPos.start + range.text.length;
    }
    else
    {
        charPos.start = element.selectionStart;
        charPos.end = element.selectionEnd;
	}
    charPos.length = charPos.end - charPos.start;
    return charPos;
}

function CharPos( id )
{
    var charPos = getCharPos( id );
    document.getElementById('charStart').value = charPos.start;
    document.getElementById('charEnd').value = charPos.end;

} 

function Addsimpletext( text, id )
{
	document.getElementById( id ).value += text;	
}


function acteditor( titulo, texto, id, which)
{
		which.style.display="block"

	while (texto.indexOf("<br />") != -1) {
		texto = texto.replace("<br />","\n");
	}
	while (texto.indexOf("<comilla>")!=-1) {
		texto = texto.replace("<comilla>","'");
	}
	while (texto.indexOf("<intrdrch>")!=-1) {
		texto = texto.replace("<intrdrch>","¿");
	}
	while (texto.indexOf("<cr1>")!=-1) {
		texto = texto.replace("<cr1>","ç");
	}
	while (texto.indexOf("<cr2>")!=-1) {
		texto = texto.replace("<cr2>","¡");
	}
	while (texto.indexOf("<cr3>")!=-1) {
		texto = texto.replace("<cr3>","´");
	}
	while (texto.indexOf("<cr4>")!=-1) {
		texto = texto.replace("<cr4>",'"');
	}
	while (texto.indexOf("<cr5>")!=-1) {
		texto = texto.replace("<cr5>",'ª');
	}
	while (texto.indexOf("<cr6>")!=-1) {
		texto = texto.replace("<cr6>",'\\');
	}
	while (texto.indexOf("<cr7>")!=-1) {
		texto = texto.replace("<cr7>",'·');
	}
	while (texto.indexOf("<cr8>")!=-1) {
		texto = texto.replace("<cr8>",'Ç');
	}
	while (texto.indexOf("<cr9>")!=-1) {
		texto = texto.replace("<cr9>",'¬');
	}
	while (texto.indexOf("<cr10>")!=-1) {
		texto = texto.replace("<cr10>",'¨');
	}
	while (texto.indexOf("<cr11>")!=-1) {
		texto = texto.replace("<cr11>",'º');
	}
	while (texto.indexOf("<cr12>")!=-1) {
		texto = texto.replace("<cr12>",'ñ');
	}
	while (texto.indexOf("<cr13>")!=-1) {
		texto = texto.replace("<cr13>",',');
	}
	document.getElementById('noticia').value = texto;
	document.getElementById('tituloup').value = titulo;
	document.getElementById('idup').value = id;
	
}

function seguro( titulo, id )
{
var x=window.confirm('¿Esta seguro de que desea eliminar la noticia con el titulo "'+titulo+'"?')
if (x)
location.href="funciones.php?q=eliminar&id="+id;	
}


function limpiar ( id, valued )
{
if(document.getElementById( id ).value==valued) {
	document.getElementById( id ).value = "";	
}
}

function verifica( id, valuex )
{
if( document.getElementById( id ).value == ""){
    document.getElementById( id ).value = valuex;
}
}

function cerrarfull ( which , idimg)
{
if (which.style.display=="block") {
which.style.display="none"
} else {
which.style.display="block"
}


}

function changepass ( id )
{
var newpass = prompt("Introduzca la nueva contraseña","********");
		if(newpass!=null)
		{
			location.href="funciones.php?id="+id+"&acc=changepass&newpass="+newpass;
		}
}

function checkv() {

if(document.getElementById("name").value == "") {
alert("Por favor digite un nombre");
return (false);
} 
if(document.getElementById("name").value == " ") {
alert("Por favor digite un nombre");
return (false);
}
if(document.getElementById("mail").value == "") {
alert("Por favor digite un email");
return (false);
}
if(document.getElementById("mail").value == " ") {
alert("Por favor digite un email");
return (false);
}
if(document.getElementById("mail").value == "Email") {
alert("Por favor digite un email");
return (false);
}
if(document.getElementById("imagen").value == "Imagen") {
alert("Por favor adjunte una imagen");
return (false);
}
if(document.getElementById("name").value == "Nombre") {
alert("Por favor digite un nombre");
return (false);
}
if(!escorreo(document.getElementById("mail"))) {
alert("Debes escribir un correo valido");
return (false);
}
return (true);
}

function escorreo(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
return false;
}

	   function inserttext(text)
        {
            opener.document.getElementById('imagen').value += text;
        }

              
     
    

