//Funcion para envio de formulario, donde form es el atributo name del mismo

function guardar(action, formulario){


	resultado=megavalidacion(formulario);

	if (resultado!=false)

	{

		if(formulario=="contacto")

		{

		envia_correo(action);

		}

		else

		{

			if(document.forms[formulario].TelefonoFijo.value == '' && document.forms[formulario].TelefonoMovil.value == '')

				alert('Debes completar uno de los campos de telefono');

			else

				envia_datos(action);

		}		


	}

	else

	{

		alert('Hay datos incorrectos y/o campos obligatorios sin rellenar');

	}

	resultado="";

}

function blanco(){

  this.className="ok";

}


//Funciones para contenedor de carga en procesos AJAX

function aparecer()

{	

	if(document.getElementById("procesandomsg"))

		document.getElementById("procesandomsg").style.display = "block";

}



function desvanecer()

{

	//document.getElementById("procesandomsg").style.display = "none";

	//fader.fadeOut();

}

//Funciones que devuelven dimensiones y scroll del area de contenido del navegador

function f_clientWidth() {

	return f_filterResults (

		window.innerWidth ? window.innerWidth : 0,

		document.documentElement ? document.documentElement.clientWidth : 0,

		document.body ? document.body.clientWidth : 0

	);

}

function f_clientHeight() {

	return f_filterResults (

		window.innerHeight ? window.innerHeight : 0,

		document.documentElement ? document.documentElement.clientHeight : 0,

		document.body ? document.body.clientHeight : 0

	);

}

function f_scrollTop() {

	return f_filterResults (

		window.pageYOffset ? window.pageYOffset : 0,

		document.documentElement ? document.documentElement.scrollTop : 0,

		document.body ? document.body.scrollTop : 0

	);

}

function f_scrollLeft() {

    return f_filterResults (

        window.pageXOffset ? window.pageXOffset : 0,

        document.documentElement ? document.documentElement.scrollLeft : 0,

        document.body ? document.body.scrollLeft : 0

    );

}



function f_filterResults(n_win, n_docel, n_body) {

	var n_result = n_win ? n_win : 0;

	if (n_docel && (!n_result || (n_result > n_docel)))

		n_result = n_docel;

	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


//Funcion para expandir las tablas
function desplegar(id)
{
	if(document.getElementById(id).style.display=='none') {
			document.getElementById(id).style.display='block';
	}
	else{ 
			document.getElementById(id).style.display='none';
	}
}
function ver_detalle(id_pedido)
{
	if(document.getElementById(id_pedido).style.display=='none') {
			document.getElementById(id_pedido).style.display='block';
			document.getElementById('img'+id_pedido).src='imagenes/flechada.gif';
	}
	else{ 
			document.getElementById(id_pedido).style.display='none';
			document.getElementById('img'+id_pedido).src='imagenes/flechado.gif';
	}
}
function ver_detalle2(id_pedido){
	
	if(document.getElementById(id_pedido).style.display=='none') {
			document.getElementById(id_pedido).style.display='block';
			document.getElementById('img'+id_pedido).src='imagenes/azul2.gif';
	}
	else{ 
			document.getElementById(id_pedido).style.display='none';
			document.getElementById('img'+id_pedido).src='imagenes/azul1.gif';
	}
}
function ver_detalle3(id_pedido){
	
	if(id_pedido == 'submenutcp'){
		location.href="index.php?dir=central/conexiontcpip.php";
	}
	else{
		location.href="index.php?dir=central/conexiongprs.php";
	}
	
	if(document.getElementById(id_pedido).style.display=='none') {
			document.getElementById(id_pedido).style.display='block';
	}
	else{ 
			document.getElementById(id_pedido).style.display='none';
	}

}
function abierto(menu){
	//location.href="index.php?dir=central/conexiontcpip.php"
	document.getElementById(menu).style.display='block';
}
function CambiaColor(esto,texto){
	 esto.style.color=texto;
}
function MarcarOpcion(esto){
	document.getElementById(esto).style.color='#f8c013';
}
function MarcarOpcion2(esto,aquello){
	document.getElementById(esto).style.color='#f8c013';
	document.getElementById(aquello).style.color='#f8c013';
}
function MarcarOpcion3(esto,aquello,masalla){
	document.getElementById(esto).style.color='#f8c013';
	document.getElementById(aquello).style.color='#f8c013';
	document.getElementById(masalla).style.color='#f8c013';
}
function borrarimagen(id){
	respuesta = document.getElementById('noticiasform');
	envia('administrador/gestornoticias.php','id='+document.getElementById('id').value
			+'&actuar=borrarimg');
	//location.href="administrador/borrarimagen.php?id="+id;
}
function contactofun(remitente,email,asunto,mensaje,empresa,telefono,cargo,destinatario){
	//alert(remitente+','+email+','+asunto+','+mensaje+','+empresa+','+telefono+','+cargo+','+destinatario);
	//alert(document.getElementById('remitente').value);
	//document.getElementById('remitente').value = remitente;
	//document.contacto.remitente.value = remitente;
	respuesta = document.getElementById('recortado');
	envia('inicio/contacto.php','rem ='+ remitente
		  );
	//location.href="administrador/borrarimagen.php?id="+id;
}

function contar(form,name) {
  n = document.forms[form][name].value.length;
  t = 1500;
  if (n > t) {
    document.forms[form][name].value = document.forms[form][name].value.substring(0, t);
  }
  else {
    document.forms[form]['result'].value = t-n;
  }
}

function cambiar_imagen(imagen) {
  var fotoP = document.getElementById('pri').src;
  document.getElementById('pri').src = document.getElementById(imagen).src
  document.getElementById(imagen).src = fotoP;
}
/* INCIDENCIAS */
function incidenciasde(valor){
	respuesta = document.getElementById('inci');
	envia('clientes/ajax/ver.php','incidenciade='+valor);
}
function incidenciaspa(valor){
	respuesta = document.getElementById('inci');
	envia('clientes/ajax/ver.php','incidenciapa='+valor);
}
function incidenciasestado(valor){
	respuesta = document.getElementById('inci');
	envia('clientes/ajax/ver.php','incidenciaestado='+valor);
}
function nuevoasocmaster(ocultar,mostrar){
	document.getElementById(ocultar).style.display='none';
	document.getElementById(mostrar).style.display='block';
	if(mostrar == 'NM')
	{
		respuesta = document.getElementById('inputempresa');
		envia('clientes/ajax/selectEmpresa.php','mostrar='+mostrar);
	}
	else
	{
		respuesta = document.getElementById('inputempresa');
		envia('clientes/ajax/selectEmpresa.php','mostrar='+mostrar);
	}
}
function actualizarmaster(nuevovalor){
	respuesta = document.getElementById('master');
	envia('clientes/ajax/selectEmpresa.php','empresa='+nuevovalor);
}
function buscar_inci(){
	respuesta = document.getElementById('inci');
	envia('clientes/ajax/ver.php','incidencia='+document.incidencias.num_incidencia.value
		  +'&fecha_ini='+document.incidencias.fechaini.value
		  +'&fecha_fin='+document.incidencias.fechafin.value);
}

/* incidencias */
function cambiacolor(capa,color){
		capa.style.background=color;
}
function cambiacolorBorde(capa,color){
		capa.style.borderColor=color;
}
function recoger_incidencia(id){
	document.getElementById('ocultaI').style.display='block';
	respuesta = document.getElementById('ocultaI');
	envia('clientes/ajax/recoger_incidencia.php','id_incidencia='+id);
}
function mostrar_incidencia(id){
	document.getElementById('ocultaI').style.display='block';
	respuesta = document.getElementById('ocultaI');
	envia('clientes/ajax/mostrar_incidencia.php','id_incidencia='+id);
}
function modificar_incidencia(id,orden)
{
	respuesta = document.getElementById('contenido');
	envia('clientes/ajax/mod_incidencia.php','id_incidencia='+id
		  +'&prioridad='+document.atender_inc.prioridad.value
		  +'&solucion='+document.atender_inc.solucion.value
		  +'&estados='+document.atender_inc.estados.value
		  +'&orden='+orden
		  +'&refitm='+document.atender_inc.refitm.value
		   +'&solucionado_por='+document.atender_inc.solucionado_por.value
		  +'&accion=modificar');
}
function b_incidencia(id){
	respuesta = document.getElementById('inci');
	envia('clientes/ajax/b_incidencia.php','id_incidencia='+id);
}
function ver_tlf(empresa){
	respuesta = document.getElementById('telefonos');
	envia('clientes/ajax/ver_tlf.php','empresa='+empresa);
}
function ocultar_master(id){
	if(id == 2){
		document.getElementById('masterS').disabled = 'disabled';
		document.getElementById('nivel').disabled = 'disabled';
		document.getElementById('empresa').value = 'itm sistemas';
	}
	else{
		document.getElementById('masterS').disabled = '';
		document.getElementById('nivel').disabled = '';
		document.getElementById('empresa').value = '';
	}
}
function borrar_usuario(id){
	respuesta = document.getElementById('recortado');
	envia('clientes/ajax/borrar_usuario.php','id_usuario='+id);
}
function editar_usuario(id){
	document.getElementById('oculta').style.display='block';
	respuesta = document.getElementById('oculta');
	envia('clientes/ajax/editar_usuario.php','id_usuario='+id);
}
function cerrar_ventana(ventana)
{
	document.getElementById(ventana).style.display='none';
	location.href='clientes.php?dir=clientes/listar.php';
}
function modificar_usuario(id)
{
	respuesta = document.getElementById('contenidoU');
	envia('clientes/ajax/actualiza.php','id_usuario='+id
		  +'&nombre='+document.mod_usuario.nombre.value
		  +'&contrasena='+document.mod_usuario.contrasena.value
		  +'&empresa='+document.mod_usuario.empresa.value
		  +'&email='+document.mod_usuario.email.value
		  +'&master='+document.mod_usuario.master.value
		  +'&departamento='+document.mod_usuario.departamento.value
		  +'&nombre_completo='+document.mod_usuario.nombre_completo.value
		  +'&movil='+document.mod_usuario.movil.value
		  +'&nivel='+document.mod_usuario.nivel.value
		  +'&telefono='+document.mod_usuario.telefono.value
		  +'&accion=modificar');
}
function cambio_empresa(empresa)
{
	respuesta = document.getElementById('master');
	envia('clientes/ajax/actualiza.php','empresa='+empresa
		 +'&accion=CE');				
}
function cambio_nivel(nivel,empresa)
{
	if(nivel == 1){
		respuesta = document.getElementById('masterTD');
		envia('clientes/ajax/actualiza.php','nivel='+nivel
			+'&empresa='+empresa
			+'&accion=CN');
	}
	else{
		
		respuesta = document.getElementById('masterTD');
		envia('clientes/ajax/actualiza.php','nivel='+nivel
			+'&empresa='+empresa
			+'&accion=CN');
	}
}
function cerrar_ventanaI(ventana)
{
	document.getElementById(ventana).style.display='none';
}
function modificar_incidencia(id,orden)
{
	respuesta = document.getElementById('contenido');
	envia('clientes/ajax/mod_incidencia.php','id_incidencia='+id
		  +'&prioridad='+document.atender_inc.prioridad.value
		  +'&solucion='+document.atender_inc.solucion.value
		  +'&orden='+orden
		  +'&refitm='+document.atender_inc.refitm.value
		  +'&estados='+document.atender_inc.estados.value
		  +'&solucionado_por='+document.atender_inc.solucionado_por.value
		  +'&accion=modificar');
}
function modificar_incidencia(id)
{
	respuesta = document.getElementById('contenido');
	envia('clientes/ajax/mod_incidencia.php','id_incidencia='+id
		  +'&prioridad='+document.atender_inc.prioridad.value
		  +'&solucion='+document.atender_inc.solucion.value
		  +'&estados='+document.atender_inc.estados.value
		  +'&solucionado_por='+document.atender_inc.solucionado_por.value
		  +'&accion=modificar');
}
function agregar_historico(id,incidencia)
{
	respuesta = document.getElementById('historico');
	envia('clientes/ajax/anadir_historico.php','id_orden='+id
		  +'&fecha_historico='+document.getElementById('fecha_historico').value
		  +'&id_incidencia='+incidencia
		  +'&comentario='+document.getElementById('comentario').value
		  +'&horas='+document.getElementById('horas').value
		  +'&empleado='+document.getElementById('empleado').value
		  +'&desplazamiento='+document.getElementById('desplazamiento').checked
		  +'&accion=historico');
}
function borrar_historico(id,orden,incidencia)
{
	respuesta = document.getElementById('historico');
	envia('clientes/ajax/anadir_historico.php','id_historico='+id
		+'&id_orden='+orden
		+'&id_incidencia='+incidencia
		+'&accion=B_historico');
}
function generar_informe(){
respuesta = document.getElementById('respuesta');
envia('clientes/ajax/generar_informes.php','fechaini='+document.generarinformes.fechaini.value
	+'&fechafin='+document.generarinformes.fechafin.value
	+'&mail='+document.generarinformes.mail.checked
	+'&mantenimientos='+document.generarinformes.informes[0].checked
	+'&incidencias='+document.generarinformes.informes[1].checked
	+'&resolucion='+document.generarinformes.informes[2].checked
	+'&tecnica='+document.generarinformes.informes[3].checked
	);
}
function cerrar_popup(capa){
	document.getElementById(capa).style.display = "none";
}

