// JavaScript Document

function insertext(text){

        document.getElementsByTagName('textarea')[0].value+=" "+ text;

        document.getElementsByTagName('textarea')[0].focus();

}



function CNreadCookie() {



	var CNname = CNGetCookie('CNname');

	var CNmail = CNGetCookie('CNmail');

	

	if(CNname != null){ document.getElementById('name').value = CNname; }

	if(CNmail != null){ document.getElementById('mail').value = CNmail; }



}



function CNforget() {

	

	var expDate = new Date();

	

	CNSetCookie('name', '', expDate);

	CNSetCookie('CNpass', '', expDate);

	CNSetCookie('CNname', '', expDate);

	CNSetCookie('CNmail', '', expDate);

	

	

	document.comment.name.value = '';

	document.comment.mail.value = '';

	

	alert("Toda tu informacion ha sido borrada!");



}



function CNSubmitComment() {



if(document.getElementById('CNremember').checked){

        var expDays = 365;

        var expDate = new Date();

        expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * expDays));



        CNSetCookie('CNname', document.getElementById('name').value, expDate);

        CNSetCookie('CNmail', document.getElementById('mail').value, expDate);

}



return true;

}

function CNRememberPass(pass) {

        var expDays = 365;

        var expDate = new Date();

        expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * expDays));

        CNSetCookie('CNpass', pass, expDate);

}

function CNGetCookieVal (offset) {

	var endstr = document.cookie.indexOf (";", offset);

	if (endstr == -1)

		endstr = document.cookie.length;

	return unescape(document.cookie.substring(offset, endstr));

}



function CNGetCookie (name) {

	var arg = name + "=";

	var alen = arg.length;

	var clen = document.cookie.length;

	var i = 0;

	while (i < clen) {

		var j = i + alen;

		if (document.cookie.substring(i, j) == arg)

		return CNGetCookieVal (j);

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) break;

	}

	return null;

}



function CNSetCookie (name, value) {

	var argv = CNSetCookie.arguments;

	var argc = CNSetCookie.arguments.length;

	var expires = (argc > 2) ? argv[2] : null;

	var path = (argc > 3) ? argv[3] : null;

	var domain = (argc > 4) ? argv[4] : null;

	var secure = (argc > 5) ? argv[5] : false;

	document.cookie = name + "=" + escape (value) +

		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +

		((path == null) ? "" : ("; path=" + path)) +

		((domain == null) ? "" : ("; domain=" + domain)) +

		((secure == true) ? "; secure" : "");

}





function login(){

	var pass=(document.getElementById('pass'))?document.getElementById('pass').value:'';

	var query=document.passwordForm.query.value;

	var rem=(document.passwordForm.CNrememberPass.checked)?'1':'';

	sndReq(query+'&password='+pass+'&CNrememberPass='+rem);

}

function Comentar(){

	var subaction=(document.comment.subaction)?document.comment.subaction.value:'';

	var name=(document.getElementById('name'))?document.getElementById('name').value:'';

	var mail=(document.getElementById('mail'))?document.getElementById('mail').value:'';

	var id=(document.comment.id)?document.comment.id.value:'';

	var ucatshow=(document.comment.ucatshow)?document.comment.ucatshow.value:'';

	var show=(document.comment.show)?document.comment.show.value:'';	

	var comments=(document.getElementsByTagName('textarea')[0])?document.getElementsByTagName('textarea')[0].value:'';

	var rem=(document.getElementById('CNremember').checked)?'1':'';

	sndReq('noticias&subaction='+escape(subaction)+'&id='+escape(id)+'&ucatshow='+escape(ucatshow)+'&comments='+escape(comments)+'&show='+escape(show)+'&name='+escape(name)+'&mail='+escape(mail))+'&CNremember='+rem;

	CNSubmitComment();

}

var http = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();

var sel=null;

var sel2;

function sndReq(action) {

	document.getElementById('mainContent').innerHTML="Cargando";

    http.open('GET', 'back.php?ir='+action+'&date='+ (new Date()).getTime());

	http.send(null);

    http.onreadystatechange = function(){

		//document.getElementById('estado').innerHTML+=".";

		if(http.readyState == 4){

			//document.getElementById('estado').innerHTML="";

			document.getElementById('mainContent').innerHTML=http.responseText;

		}

	}

   

}

function cargar(que, el){

	if (sel)

		sel.className="inactivo";

	sel=el;

	sel.className="activo";

	sndReq(que);

}

function esmue(id){

	var cosa=document.getElementById(id);

	if(cosa.style.display=='block'){

		cosa.style.display='none';

	}

	else{

		if(sel2!=null)

			sel2.style.display='none';

		cosa.style.display='block';

		sel2=cosa;

	}

}
