function mostrar_consultas(consultas){
	window.location = BASEURL+"consultas/index.php?admin="+consultas; // solo admin
}

function marcar_leido(respiestaid){
	cargaDIVXML('spam_leido_marcar_'+respiestaid,'spam_leido_marcar_'+respiestaid,'marcando...','NO','');
	cargaXML(BASEURL+'consultas/admin-accion.php?marcar_leido='+respiestaid);
}



function buscar_mail(buscaren){
var buscar;
	buscar = document.getElementById('buscar').value;
	
	if(buscaren=="usuario"){
		window.location = BASEURL+"consultas/index.php?admin=userlist&buscar="+buscar+"&buscaren=usuario"; // solo admin
	}else{
		window.location = BASEURL+"consultas/index.php?buscar="+buscar+"&buscaren="+buscaren; // solo admin
	}
}

function guardarnombre(nombre){
	//window.location = "index.php?accion=perfil&nombre="+nombre;
	if(nombre.length == 0){
		alert('Debe ingresar su nombre!');
	return;
	}
	if(nombre.length <= 3){
		alert('El nombre es muy corto!');
	return;
	}
	if(document.getElementById('nombre') != null){
		document.getElementById('nombre').value = nombre;
	}
	
	cargaDIVXML('spannombre','spannombre','guardando...','NO','');
	cargaXML(BASEURL+"usuarios-panel.php?accion=perfil&nombre="+nombre);
}

function guardar_telefonos(){
	get_telefono = document.getElementById('frm_telefono').value;
	get_movil = document.getElementById('frm_movil').value;
	cargaDIVXML('save_telefono','save_telefono','guardando...','NO','');
	cargaXML(BASEURL+'usuarios-panel.php?accion=savepone&telefono='+get_telefono+'&movil='+get_movil);
}

function cambiaracceso_consulta(consultaID){ // solo admin

	if(document.getElementById('span_check_acceso').innerHTML=="publico"){
		acceso = "privado";
		img_acceso_url = "no-publico";
	}else{
		acceso = "publico";
		img_acceso_url = "publico";
	}

	document.getElementById('img_acceso').src = BASEURL+"consultas/images/"+img_acceso_url+".gif";

	cargaDIVXML('span_check_acceso','span_check_acceso','guardando...','NO','');
	cargaXML(BASEURL+'consultas/gestion.php?acceso_cambiar='+acceso+'&id='+consultaID);
}

function editar_key(IDconsulta,nocache){
if(document.getElementById('span_check_acceso').innerHTML!="publico"){
	alert('La consulta tiene que ser "publica"');
	return;
}
	cargaDIVXML('div_keywords','','cargando...','',''); cargaXML(BASEURL+'consultas/admin-accion.php?keywords='+IDconsulta+'&nocache='+nocache);
}

function cambiarestado_consulta(consultaID,estado){ // solo admin
	if(estado==''){
		alert('Estado no seleccionado!');
	return;
	}
	cargaDIVXML('spanestadoid_'+consultaID,'spanestadoid_'+consultaID,'guardando...','NO','');
	cargaXML('gestion.php?estado='+estado+'&consultaID='+consultaID);
}

function confirmadelete(tipo){ // solo admin
	if(confirm("CM Electónica\n¿Confirmas ELIMINAR esta "+tipo+"?")!=true){
		return false;
	}else{
		return true;
	}
}

function eliminar_consulta_respuesta(consultaID,tipo){ // solo admin
	if(tipo=="respuesta"){
		div = "div_respuesta_";
	}else{
		div = "div_consulta_";
	}
	cargaDIVXML( div+consultaID, div+consultaID,'eliminando...','NO','');
	cargaXML('gestion.php?eliminar='+consultaID+'&'+tipo+'=true');
}




function cambio_user_tipo(changeuserid,changetipo){ // solo admin
	cargaDIVXML('spanuserid_'+changeuserid,'spanuserid_'+changeuserid,'guardando...','NO','');
	cargaXML('admin-accion.php?admin=cambiousertipo&changeuserid='+changeuserid+'&changetipo='+changetipo);
}



/********************** EDITOR ***************************/
var command = "";
function InitToolbarButtons() {

  var kids = document.getElementsByTagName('DIV');
  for (var i=0; i < kids.length; i++) {
    if (kids[i].className == "imagebutton") {
      kids[i].onmouseover = tbmouseover;
      kids[i].onmouseout = tbmouseout;
      kids[i].onmousedown = tbmousedown;
      kids[i].onmouseup = tbmouseup;
      kids[i].onclick = tbclick;
    }
  }
}


function tbmousedown(e){
  var evt = e ? e : window.event; 

  this.firstChild.style.left = 2;
  this.firstChild.style.top = 2;
  this.style.border="inset 1px";

  if (evt.returnValue) {
    evt.returnValue = false;
	
  } else if (evt.preventDefault) {
    evt.preventDefault( );
	
  } else {

    return false;
  }
}

function tbmouseup(){
  this.firstChild.style.left = 2;
  this.firstChild.style.top = 2;
  this.style.border="solid 1px";
}

function tbmouseout(){
  this.className="comMouseOut";
}

function tbmouseover(){
	this.className="comMouseOver";
}

function tbclick(){

 if (this.id == "switchmode") {
	 if(document.getElementById('frm_edit').style.display == 'none'){
		ver_codigo();
	 }else{
		pegar_codigo();
	 }

	return;
  }

 if (this.id == "herramientas_full") {
	if(document.getElementById('img_herramientas_full').src ==  BASEURL+'consultas/images/si_full.gif'){
		document.getElementById('img_herramientas_full').src = BASEURL+'consultas/images/no_full.gif';
		document.getElementById('div_herramientas_full').style.display = 'none';
	}else{
		document.getElementById('img_herramientas_full').src = BASEURL+'consultas/images/si_full.gif';
		document.getElementById('div_herramientas_full').style.display = '';
	}
	return;
  }
  
 if (this.id == "createlink") {
    var szURL = prompt("Enter a URL:", "http://");
    if ((szURL != null) && (szURL != "")) {
      document.getElementById('edit').contentWindow.document.execCommand("CreateLink",false,szURL);
    }
  } else if (this.id == "createimage") {
    imagePath = prompt('Enter Image URL:', 'http://');
    if ((imagePath != null) && (imagePath != "")) {
      document.getElementById('edit').contentWindow.document.execCommand('InsertImage', false, imagePath);
    }
  } else {
    document.getElementById('edit').contentWindow.document.execCommand(this.id, false, null);
  }
}


function Start() {

	if(document.getElementById('edit')==null){
		return;
	}
	//frm_perfiluser
	var div_ogj;
	if(document.getElementById('frm_consulta')!=null){
		div_ogj = document.getElementById('frm_consulta');
	}
	if(document.getElementById('frm_perfiluser')!=null){
		div_ogj = document.getElementById('frm_perfiluser');
	}
	
	if(div_ogj!=null){
	
		// si no es iexplorer
		var nombre = navigator.appName
		if (nombre == "Microsoft Internet Explorer"){
		}else{
			div_ogj.style.display='block';
			if(document.getElementById('botonrespuesta')!=null){
				document.getElementById('botonrespuesta').style.display='none';
			}
		}
		
		document.getElementById('edit').contentWindow.document.designMode = "on";
		try {
		document.getElementById('edit').contentWindow.document.execCommand("undo", false, null);
		}  catch (e) {
		alert("Error este modulo no soporta tu version de Mozilla.");
		}
		InitToolbarButtons();
	}
}

function frm_pasar_data(){
	document.getElementById('frm_edit').value = document.getElementById('edit').contentWindow.document.body.innerHTML;
}

function ver_codigo(){
	document.getElementById('edit').style.display = 'none';
	document.getElementById('frm_edit').style.display = '';
	document.getElementById('frm_edit').value = document.getElementById('edit').contentWindow.document.body.innerHTML;
	document.getElementById('switchmode').style.backgroundColor = "#e8fde3";
	//document.getElementById('tb_editor').style.backgroundColor = "#f8cdd5";
}

function pegar_codigo(){
	document.getElementById('edit').style.display = '';
	document.getElementById('frm_edit').style.display = 'none';
	document.getElementById('edit').contentWindow.document.body.innerHTML = document.getElementById('frm_edit').value;
	document.getElementById('switchmode').style.backgroundColor="#e1e1e2";
	//document.getElementById('tb_editor').style.backgroundColor = "#e1e1e2";
}
/******************************************************************/
function change_titulo(accion,titulo,id){
	if(accion != 'enviar'){
		document.getElementById('frm_titulo').style.display = '';
		document.getElementById('div_titulo').innerHTML = '';
	}else{
		document.getElementById('frm_titulo').style.display = 'none';
		cargaDIVXML('div_titulo','div_titulo','guardando...','NO','');
		cargaXML('gestion.php?edicion=titulo&titulo='+titulo+'&id='+id);
	}
}

function mover_consulta(moverid,mover_de_id,tipo){
//alert(consultaid)
	window.location = BASEURL+"consultas/index.php?admin=mover&moverid="+moverid+"&mover_de_id="+mover_de_id+"&tipo="+tipo; // solo admin
}


function abrir_autorespuestas(consultaid,nocache){
	
	if(document.getElementById('div_respuesta')!=null){
		document.getElementById('div_respuesta').style.display = 'none';
	}

	cargaDIVXML('div_autorespuestas','div_autorespuestas','preparando...','NO','');
	cargaXML(BASEURL+"consultas/autorespuestas.php?consultaid="+consultaid+"&nocache="+nocache);
}

function autorespuestas_consulta(consultaid,autorespuestaid){
	cargaDIVXML('div_autorespuestas','div_autorespuestas','preparando...','NO','');
	cargaXML(BASEURL+"consultas/autorespuestas.php?autorespuesta_id="+autorespuestaid+"&consultaid="+consultaid);
}

function reenvio_mail_confirmar(consultaid){ // solo admin
	if(confirm("CM Electónica\n¿Confirmas REENVIAR este mail "+consultaid+"?")!=true){
		return false;
	}else{
		return true;
	}
}
function reenviar_mail(date_clave){ // solo admin
	cargaDIVXML( "div_reenvio_"+date_clave, "div_reenvio_"+date_clave,' -> reenviando e-mail...','NO','');
	cargaXML('http://www.cmelectronica.com.ar/phpmailer-gmail/send-mail-respuesta-reenvio-'+date_clave+'.gif');
	//<img src="http://www.cmelectronica.com.ar/phpmailer-gmail/send-mail-respuesta-<?= $date; ?>.gif" width="1" height="1" />
}



function edit_notas(IDconsulta){
	
	document.getElementById('notas_txt').style.display = 'block';
	document.getElementById('span_notas_txt').style.display = 'none';
	/*
	if(accion != 'enviar'){
		
		document.getElementById('div_titulo').innerHTML = '';
	}else{
		document.getElementById('frm_titulo').style.display = 'none';
		cargaDIVXML('div_titulo','div_titulo','guardando...','NO','');
		cargaXML('gestion.php?edicion=titulo&titulo='+titulo+'&id='+id);
	}
	*/
}
function edit_notas_save(IDconsulta){
	var notas_txt;
	
	document.getElementById('span_notas_txt').style.display = 'block';

	notas_txt = document.getElementById('notas_txt').innerHTML;
	document.getElementById('notas_txt').style.display = 'none';
	//document.getElementById('frm_titulo').style.display = 'none';
	cargaDIVXML('span_notas_txt','span_notas_txt','guardando...','NO','');
	cargaXML('admin-accion.php?edit_notas=edit&notas_txt='+notas_txt+'&IDconsulta='+IDconsulta);

}
