//Sección serviciosProductos
function marcarA(elemento){
	for (i = 1; i < 7; i++){
		if(i != elemento) document.getElementById('menuA' + i + 'a').style.backgroundPosition = '0px 0px';
	}
	document.getElementById('menuA' + elemento + 'a').style.backgroundPosition = '0px -79px';
	
	if(elemento == 1) $('#menuBinstalaciones').slideDown('slow'); 
	else $("#menuBinstalaciones").slideUp('slow');
	if(elemento == 5) $('#menuBtipos').slideDown('slow'); 
	else $("#menuBtipos").slideUp('slow');

	for(i = 1; i < 5; i++){
		document.getElementById('menuBinstalaciones' + i + 'a').style.color = '#636D41';
		document.getElementById('menuBinstalaciones' + i).style.backgroundColor = '#E1E3DA';
	}
	for(i = 1; i < 7; i++){
		document.getElementById('menuBtipos' + i + 'a').style.color = '#636D41';
		document.getElementById('menuBtipos' + i).style.backgroundColor = '#E1E3DA';
	}
	
	mostrarDatos('serviciosProductosContenido.php?seccion=' + elemento, 'texto2');
}
function marcarBinstalaciones(elemento){
	for (i = 1; i < 5; i++){
		if(i != elemento){
			document.getElementById('menuBinstalaciones' + i + 'a').style.color = '#636D41';
			document.getElementById('menuBinstalaciones' + i).style.backgroundColor = '#E1E3DA';
		}
	}
	document.getElementById('menuBinstalaciones' + elemento + 'a').style.color = '#fff';
	document.getElementById('menuBinstalaciones' + elemento).style.backgroundColor = '#636D41';
	
	ajaXCargar('instalacionesFotovoltaicasContenido.php?seccion=' + elemento, 'texto2');
}
function marcarBtipos(elemento){
	for (i = 1; i < 7; i++){
		if(i != elemento){
			document.getElementById('menuBtipos' + i + 'a').style.color = '#636D41';
			document.getElementById('menuBtipos' + i).style.backgroundColor = '#E1E3DA';
		}
	}
	document.getElementById('menuBtipos' + elemento + 'a').style.color = '#fff';
	document.getElementById('menuBtipos' + elemento).style.backgroundColor = '#636D41';
	
	ajaXCargar('tiposCubiertasContenido.php?seccion=' + elemento, 'texto2');
}

function mostrarDatos(fuente, capa){
	$('#' + capa).fadeOut('slow', function(){ajaXCargar(fuente, capa);});
	$('#' + capa).fadeIn('slow', function(){cargarCosas(fuente);});
}
function cargarCosas(fuente){
	//Cargar CKEditor
	delete CKEDITOR.instances['editor1'];
	fuente = fuente.substring(0,17);
	if (fuente == 'alta_noticias.php'){
		var editor = CKEDITOR.replace('editor1',{fullPage : false, height : '280px'});
	}
	
	//Cargar barra de scroll
	$('.scroll').jScrollPane();
}

//Seccion empresa
function mostrarWebFrancia(){
	document.getElementById('iframeFrancia').style.zIndex = 10;
	document.getElementById('iframeFrancia').src = 'http://www.tt-solar81.com';
}
//Seccion Q-cells
function mostrarWebQcells(){
	document.getElementById('iframeQcells').style.zIndex = 10;
	document.getElementById('iframeQcells').src = 'http://www.q-cells.com/en/index.html';
}

//Noticias vista públicas
function buscarNoticia(){
	var contenido = document.getElementById('contenidoBuscar').value;
	if(contenido == "") return;
	ajaXCargar('buscarNoticias.php?contenido=' + contenido, 'datos');
}

//Sección instalaciones
function mostrarDatosGalerias(fuente, capa){
	//document.getElementById('presentacionGaleria').style.display = 'none';
	ajaXCargar(fuente, capa);
	$('#presentacionGaleria').animate({
		width: '289px'
	}, 500, function(){
		//Cargar galería de fotos
		$("a.galeria").fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	600, 
			'overlayShow'	:	false
		});
	});
}
function fondo(){
	var num = Math.random() * 4; num = Math.round(num); num = num + 1;
	document.getElementById('contenedor').style.background = "url('../img/bucle/portada" + num + ".jpg') no-repeat center top";
}
function negrita(elemento){document.getElementById(elemento).style.fontWeight = 'bold';}
function normal(elemento){document.getElementById(elemento).style.fontWeight = 'normal';}

//Intranet
function descargar(file, bloqueado){
	var bloquear;
	if(bloqueado == 0)	bloquear = confirm('¿Desea bloquear el archivo tras la descarga?');
	else bloquear = false;
	window.location = "descargar.php?file=" + file + "&block=" + bloquear;
}
function crearUsuario(cant, tipo){
	//alert(tipo);
	var control = true;
	var usuario = document.getElementById('usuario').value;
	var pass1 = document.getElementById('contrasena1').value;
	var pass2 = document.getElementById('contrasena2').value;
	var nombre = document.getElementById('nombre').value;
	for(var i = 0; i < cant; i++){
		if(usuario == document.getElementById('listaUsuarios' + i).value) control = false;
	}
	if(usuario == "" || control == false){
		document.getElementById('usuario').style.backgroundColor = "#FFEFF3";
		document.getElementById('usuario').style.borderColor = "#BF173D";
		return;
	}
	if(pass1 == ""){
		document.getElementById('contrasena1').style.backgroundColor = "#FFEFF3";
		document.getElementById('contrasena1').style.borderColor = "#BF173D";
		return;
	}
	if(pass2 == ""){
		document.getElementById('contrasena2').style.backgroundColor = "#FFEFF3";
		document.getElementById('contrasena2').style.borderColor = "#BF173D";
		return;
	}
	if(pass1 != pass2){
		document.getElementById('contrasena1').style.backgroundColor = "#FFEFF3";
		document.getElementById('contrasena1').style.borderColor = "#BF173D";
		document.getElementById('contrasena2').style.backgroundColor = "#FFEFF3";
		document.getElementById('contrasena2').style.borderColor = "#BF173D";
		return;
	}
	if(nombre == ""){
		document.getElementById('nombre').style.backgroundColor = "#FFEFF3";
		document.getElementById('nombre').style.borderColor = "#BF173D";
		return;
	}
	
	document.getElementById('formAltaUsers').submit();
}
function updateUsuario(cant){
	var control = true;
	var usuario = document.getElementById('usuario').value;
	var nombre = document.getElementById('nombre').value;
	for(var i = 0; i < cant; i++){
		if(usuario == document.getElementById('listaUsuarios' + i).value) control = false;
	}
	if(usuario == "" || control == false){
		document.getElementById('usuario').style.backgroundColor = "#FFEFF3";
		document.getElementById('usuario').style.borderColor = "#BF173D";
		return;
	}
	if(nombre == ""){
		document.getElementById('nombre').style.backgroundColor = "#FFEFF3";
		document.getElementById('nombre').style.borderColor = "#BF173D";
		return;
	}
	
	document.getElementById('formDatos').submit();
}
function eliminarUsuario(id){
	var resp;
	resp = confirm("Confirme que desea eliminar el usuario");
	if(resp == true){
		window.location = "eliminarUsuarios.php?idu=" + id;
	}
}
function subirArchivo(){
	document.getElementById('subirFichero').disabled = true;
	document.getElementById('subir').submit();
}
function subirFichero(){
	ajaXCargar('subir_archivos.php', 'contenidoIntranet');
	setTimeout("otra()", 1000);
}
function otra(){
	$('input:file').MultiFile({
		STRING: {
			remove: '<img style="border:none;" src="../img/trash2.png" height="16" width="16" alt="X"/>'
		}
	});
}
function cambiarContrasena(){
	var control = true;
	var vieja = hex_md5(document.getElementById('contrasenaVieja').value);
	var actual = document.getElementById('actualOculta').value;
	if(vieja != actual){
		document.getElementById('contrasenaVieja').style.backgroundColor = "#FFEFF3";
		document.getElementById('contrasenaVieja').style.borderColor = "#BF173D";
		return;
	}
	
	var nueva1 = document.getElementById('contrasena1').value;
	var nueva2 = document.getElementById('contrasena2').value;
	if(nueva1 == ""){
		document.getElementById('contrasena1').style.backgroundColor = "#FFEFF3";
		document.getElementById('contrasena1').style.borderColor = "#BF173D";
		control = false;
	}
	if(nueva2 == ""){
		document.getElementById('contrasena2').style.backgroundColor = "#FFEFF3";
		document.getElementById('contrasena2').style.borderColor = "#BF173D";
		control = false;
	}
	if(nueva1 != nueva2){
		document.getElementById('contrasena1').style.backgroundColor = "#FFEFF3";
		document.getElementById('contrasena1').style.borderColor = "#BF173D";
		document.getElementById('contrasena2').style.backgroundColor = "#FFEFF3";
		document.getElementById('contrasena2').style.borderColor = "#BF173D";
		return;
	}
	
	if(control == true){document.getElementById('formDatos').submit();}
}
function colorOriginal(cuadro){
	document.getElementById(cuadro).style.backgroundColor = '#FFFFFF';
	document.getElementById(cuadro).style.borderColor = '#377F5C';
}
function guardarNoticia(){
	var control = true;
	var control2;
	/*var datos = CKEDITOR.instances.editor1.getData();
	alert(datos);
	control = false;
	document.getElementById('titular').value = datos;*/
	
	if(document.getElementById('titular').value == ""){
		document.getElementById('titular').style.backgroundColor = '#FFEFF3';
		document.getElementById('titular').style.borderColor = '#BF173D';
		control = false;
	}
	if(document.getElementById('tags').value == ""){
		document.getElementById('tags').style.backgroundColor = '#FFEFF3';
		document.getElementById('tags').style.borderColor = '#BF173D';
		control = false;
	}
	/*if(control == true && (datos == "" || datos = '<br />')){
		control2 = confirm("¿Seguro que desea publicar la noticia en blanco?");
		if(control2 == false){control = false;}
	}*/

	if(control == true){document.getElementById('formNoticia').submit();}
}
function create(template, vars, opts){
	return $mensajes.notify("create", template, vars, opts);
}
function nombre(id){
	var resp;
	resp = confirm("Confirme que desea eliminar la noticia");
	if(resp == true){
		window.location = "eliminar_noticias.php?idn=" + id;
	}
}

function eliminarFichero(id){
	var resp;
	resp = confirm("Confirme que desea eliminar el fichero");
	if(resp == true){
		window.location = "eliminarFicheros.php?idf=" + id;
	}
}