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

function buscar_mail(mail){
		window.location = BASEURL+"consultas/index.php?buscarmail="+mail+"&buscaren="+document.getElementById('buscaren').value; // 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 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
}