var DIRECCION = "http://www.salesboyoli.org/index.php/"
//var DIRECCION = "http://192.168.0.2/sales/index.php/";
//var DIRECCION = "http://200.66.99.187/sales/index.php/";
//var DIRECCION = "http://bazaar.lunarbreeze.com/~sales20/";
function borrarCom(idCom){
	limpiarCampo('txtMensaje');	
	if(confirm("¿Estás seguro(a) de querer borrar el Comunicado?")){
		window.location = DIRECCION +"AdminComControl/borrarCom/"+idCom;
	}
}

function borrarExp(idExp){
	//limpiarCampo('txtMensaje');
	if(confirm("¿Estás seguro(a) de querer borrar el Expediente?")){
		window.location = DIRECCION +"AdminExpControl/borrarExp/"+idExp;
	}
}

function borrarCarta(idCarta){
	limpiarCampo('txtMensaje');
	if(confirm("¿Estás seguro(a) de querer borrar la Carta?")){
		window.location = DIRECCION +"AdminCartasControl/borrarCarta/"+idCarta;
	}
}

function borrarUser(idUser){
	if(confirm("¿Estás seguro(a) de querer borrar el Usuario?")){
			window.location = DIRECCION +"AdminUserControl/borrarUser/"+idUser;
		}
}

function borrarCir(idCir){
	if(confirm("¿Estás seguro(a) de querer borrar la circular?")){
		window.location = DIRECCION +"AdminCirControl/borrarCirular/"+idCir;
	}
}

function borrarImg(idImg){
	if(confirm("¿Estás seguro(a) de querer borrar la imagen?")){
		//window.location = DIRECCION +"AdminControl/borrarCirular/"+idCir;
		xajax_borrarImagen(idImg);
	}
}

function borrarUser(idUser,tipoUser){
	if(confirm("¿Estás seguro(a) de querer borrar el usuario?")){
		window.location = DIRECCION +"AdminUserControl/borrarUsuario/"+idUser+"/"+tipoUser;
		
	}
}
function borrarMedio(idUser){
	if(confirm("¿Estás seguro(a) de querer borrar?")){
		window.location = DIRECCION +"AdminPMControl/borrarMedio/"+idUser;
		
	}
}

var activo = '';
var pres	= false;
function activarMateriales(div){
	if(pres){
		if(activo == div){
			window.document.getElementById(activo).style.display='none';
			pres= false;
			activo = '';
		}else{
			window.document.getElementById(div).style.display='inline';
			window.document.getElementById(activo).style.display='none';		
			activo = div;		
		}
	}else{
		window.document.getElementById(div).style.display='inline';
		activo = div;
		pres = true;
	}
}
var activo2 = '';
var pres2	= false;
function activarMateriales2(div){
	if(pres2){
		if(activo2 == div){
			window.document.getElementById(activo2).style.display='none';
			pres2= false;
			activo2 = '';
		}else{
			window.document.getElementById(div).style.display='inline';
			window.document.getElementById(activo2).style.display='none';		
			activo2 = div;		
		}
	}else{
		window.document.getElementById(div).style.display='inline';
		activo2 = div;
		pres2 = true;
	}
}
var activoC = '';
var presC	= false;
function activarMaterialesC(div){
	if(presC){
		if(activoC == div){
			window.document.getElementById(activoC).style.display='none';
			presC= false;
			activoC = '';
		}else{
			window.document.getElementById(div).style.display='inline';
			window.document.getElementById(activoC).style.display='none';		
			activoC = div;		
		}
	}else{
		window.document.getElementById(div).style.display='inline';
		activoC = div;
		presC = true;
	}
}
function activarMaterialesExtra(idDiv){
	div = window.document.getElementById(idDiv).style.display;
	//alert(idDiv+"--"+div);
	if(window.document.getElementById(idDiv).style.display == "none"){
		window.document.getElementById(idDiv).style.display = "inline";
	}else{
		window.document.getElementById(idDiv).style.display = "none";
	}
}

function limpiarCampo(id){
	document.getElementById(id).innerHTML="";
}

function getAllNodes(idTabla){
	var tabla  = document.getElementById(idTabla);
	for(var i= 1; i<tabla.rows.length; i++){
		 tabla.deleteRow(i);
	}	
}

function getUsersAdministrador(){
	getAllNodes('tablaUser');
	
	var tabla  = document.getElementById('tablaUser');
	var cont = tabla.rows.length;			
				
    var nmb=document.createElement('input');
    nmb.type= 'text';
	nmb.name= 'nombre';
	nmb.className = 'input200';
	
	tabla.insertRow(1);
	tabla.rows[1].insertCell(0);
	tabla.rows[1].cells[0].innerHTML='Nombre:';
	tabla.rows[1].cells[0].style.textAlign='right';	
	tabla.rows[1].insertCell(1);
	tabla.rows[1].cells[1].style.textAlign='left';
	tabla.rows[1].cells[1].appendChild(nmb);

	//cont = tabla.rows.length;
	//cont++;
	
	var mail=document.createElement('input');
    mail.type= 'text';
	mail.name= 'mail';
	mail.className = 'input200';
	
	tabla.insertRow(2);
	tabla.rows[2].insertCell(0);
	tabla.rows[2].cells[0].innerHTML='Mail:';
	tabla.rows[2].cells[0].style.textAlign='right';
	tabla.rows[2].insertCell(1);
	tabla.rows[2].cells[1].style.textAlign='left';
	tabla.rows[2].cells[1].appendChild(mail);
}

function getUsersCliente(){
	getAllNodes('tablaUser');
}

function enviaCartanueva(){
	var oEditor = FCKeditorAPI.GetInstance( 'estadoActual' ) ;
	//var contenidoFCK = window.document.myform.contenidoCarta;
	var contenidoFCK = document.getElementById('contenidoCarta');
	contenidoFCK.value="";	
	contenidoFCK.value=oEditor.GetXHTML().replace('<br type="_moz" />', '');
	//contenidoFCK.value=trim(contenidoFCK.value);
	
	window.document.myform.submit();
}


function previoAlert(){

    seleccionado = 0;
	for(i=0;i<3;i++)
	{
	  if(window.document.myform.pAudiencia[i].checked==true){
	  	seleccionado = 1;
	    break;
	  }
	}
	
	var fecha;
	if(seleccionado == 1){
		if(window.document.myform.pAudiencia[i].value == "Por confirmar"){
			fecha = "Por confirmar";
		}else{
			fecha = (window.document.myform.proxFecha.value != "") ? window.document.myform.proxFecha.value+" a las: " +window.document.myform.horas.value + ":" + window.document.myform.minutos.value + " "
					+ window.document.myform.formatoHora.value : 'Sin asignar';
		
		}
	}else{
		fecha = (window.document.myform.proxFecha.value != "") ? window.document.myform.proxFecha.value+" a las: " +window.document.myform.horas.value + ":" + window.document.myform.minutos.value + " "
					+ window.document.myform.formatoHora.value : 'Sin asignar';
		window.document.myform.pAudiencia[0].checked = true;
		mostrarDatosProxAudiencia(false);
	}
	if(confirm("¿Los datos están correctos? \n próxima Audiencia: " + fecha )){
		window.document.myform.submit();
	}
	
}


function reenviarPDFAdmin(idExp, idCliente){
	var mails = prompt("Introduce los correos electrónicos separados por comas");
	
	if (mails != '' && mails!=null){
		//window.location = DIRECCION +"adminControl/reenviarMail/"+idExp+"/"+idCliente+"/"+ mails;
		xajax_reenviarMail(idExp, idCliente, mails);
	}else if(mails==null){
		
	}else{
		alert('Escribe al menos un correo electrónico');
	}
}

function mostrarDatosProxAudiencia(valor){
	//alert(valor);
	if(valor=="Fecha"){
		document.getElementById("etiquetaPAudiencia").style.display = "inline";
		document.getElementById("datosPAudiencia").style.display = "inline";
	}else{
		document.myform.proxFecha.value = "";
		document.myform.minutos.value = "";
		document.myform.horas.value = "";
		document.myform.formatoHora.value = "";
		document.getElementById("etiquetaPAudiencia").style.display = "none";
		document.getElementById("datosPAudiencia").style.display = "none";
	}
}

function mostrarRenglonMail(valor){
	if(valor == true){
		document.getElementById("etiquetaCorreo").style.display = "none";
		document.getElementById("datosCorreo").style.display = "none";
		document.getElementById("noEnviar").value= true;
		document.getElementById("noEnviarMail").value= true;
	}else{
		document.getElementById("etiquetaCorreo").style.display = "inline";
		document.getElementById("datosCorreo").style.display = "inline";
		document.getElementById("noEnviar").value= false;
		document.getElementById("noEnviarMail").value= false;
	}
}

function mostrarDatosJunta(valor){
	//alert(valor);
	
	if(valor=="JUNTA"){
		document.getElementById("etiquetaJunta").style.display = "inline";
		document.getElementById("datosJunta").style.display = "inline";
	}else{
		document.getElementById("etiquetaJunta").style.display = "none";
		document.getElementById("datosJunta").style.display = "none";
	}
}

/*
	Codigo para adjuntar el FCKEDITOR
*/

window.onload = function()
{
	// Automatically calculates the editor base path based on the _samples directory.
	// This is usefull only for these samples. A real application should use something like this:
	 //oFCKeditor.BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
	//var sBasePath = 'http://192.168.0.2/sales/system/application/views/js/fckeditor/';
	//var sBasePath = 'http://200.66.99.187/sales/system/application/views/js/fckeditor/';
	//var sBasePath = 'http://bazaar.lunarbreeze.com/~sales20/';
	var sBasePath = 'http://www.salesboyoli.org/system/application/views/js/fckeditor/';
	
	var oFCKeditor = new FCKeditor('estadoActual') ;
	oFCKeditor.BasePath	= sBasePath ;
	oFCKeditor.Config['CustomConfigurationsPath'] = sBasePath + 'myconfig.js' ;

	// Let's use a custom toolbar for this sample.
	oFCKeditor.ToolbarSet	= 'Plugin' ;
	oFCKeditor.Width	= 450 ;
	oFCKeditor.Height	= 200 ;
	oFCKeditor.ReplaceTextarea() ;
}

function validar_form_users(){
	if(document.myform._submit.value ="editar"){
		if(document.myform.contrasenia.value != ""){
			if(document.myform.contrasenia.value == document.myform.conf_contrasenia.value){
				document.myform.submit();
			}else{
				alert("La nueva contraseña nueva no coincide");
			}
		}else{
			document.myform.submit();
		}
	}
}

