// JavaScript Document

imgsrc=new Array(); 

imgsrc[1]='./jpg/a_ampliar1.gif';	

imgsrc[2]='./jpg/p_ampliar1.gif';

imgsrc[3]='./jpg/d_ampliar1.gif';

imgsrc[4]='./jpg/a_enlace1.gif';

imgsrc[5]='./jpg/p_enlace1.gif';

imgsrc[6]='./jpg/d_enlace1.gif';

imgsrc[7]='./jpg/p_buscar1.gif';

imgsrc[8]='./jpg/a_buscar1.gif';

imgsrc[9]='./jpg/a_Inicompra1.gif';

imgsrc[10]='./jpg/p_Inicompra1.gif';

imgsrc[11]='./jpg/a_ConDatos1.gif';

imgsrc[12]='./jpg/p_ConDatos1.gif';

img =new Array();

for (i=0; i< imgsrc.length; i++) {

	img[i]=new Image();

	img[i].src=imgsrc[i];

}

var ocultar;

var retardo;

function change(number, picture) {

	document.getElementById(picture).src=img[number].src;

}

function anadeEventos(event, elemId, func) {

 	elem = document.getElementById(elemId);

    if (elem.addEventListener){  

        elem.addEventListener(event,func,false);

	}

    else if (elem.attachEvent) { // IE DOM

         var r = elem.attachEvent("on"+event, func);

		return r;

    }

    else{

		throw 'No es posible añadir evento';

	}

}

function actualizarMenu(permisos){

	if(permisos=="empleado" || permisos=="IUT"){

			var enlace = document.createElement("a");

			enlace.href = "./CargadorcargaMenu.php?idmenu=6";

			enlace.id ="enlaceAdmin";

			enlace.target="cargador";

			enlace.style.color = '#D4002A';

			enlace.appendChild(document.createTextNode("Administración"));

			var nodolista = document.createElement("li");

			nodolista.id='elemen8';

			nodolista.appendChild(enlace);			

			switch(detectarNav()){

				case "IE":	

				opcionesMenu.appendChild(nodolista);

				break;

				case "FIREFOX":

				document.getElementById("opcionesMenu").appendChild(nodolista);

				break;

				default:

				alert('No se detecto el navegador');

				break;

			}

			// anadeEventos("mouseover", "enlaceAdmin" , "javascript:cambiaEstiloMenuSobre(this, 'elemen8')");

	}

}





function detectarNav() {

	 if (navigator.appName == "Microsoft Internet Explorer")

		return "IE";

	else{

		return "FIREFOX";

	}

}

function cambiaruta(seccion){

	var html = "<table> <tr><td>Bienvenido se encuentra en: ";

	switch(seccion){

		case 2:

			html += " <a href='javascript:cargaMenu(2)'> Publicaciones UIM</a></td></tr></table>";

			break;

		case 3:

			html += " <a href='javascript:cargaMenu(3)'> Centro Virtual</a></td></tr></table>";

			break;

		case 9:

			html += " <a href='javascript:cargaMenu(2)'> Publicaciones UIM</a> >> <a href='javascript:cargaNotEditorial(1)'> Noticias Editorial</a> </td></tr></table>";

			break;

		case 10:

			html += " <a href='javascript:cargaMenu(2)'> Publicaciones UIM</a> >> <a href='javascript:cargaSegEditorial(1)'> Noticias Seguimiento</a> </tr></table>";

			break;

		case 11:

			html += " <a href='javascript:cargaMenu(2)'> Publicaciones UIM</a> >> <a href='javascript:cargaPublicaciones()'> Publicaciones</a> </td></tr></table>";

			break;

		case 12:

			html += " Cambiame";

			break;

			

	}

	document.getElementById("ruta").innerHTML= html;

}

function cambiarutaIndex(seccion){

	var html = "<table> <tr><td>Bienvenido se encuentra en: ";

	switch(seccion){

		case 1:

			html += " <a href='./CargadorcargaMenu.php?idmenu=1' target='cargador'> Inicio </a></td></tr></table>";

			break;

		case 2:

			html += " <a href='./CargadorcargaMenu.php?idmenu=2' target='cargador'> Publicaciones UIM</a></td></tr></table>";

			break;

		case 3:

			html += " <a href='./CargadorcargaMenu.php?idmenu=3'  target='cargador'> Documentos UIM</a></td></tr></table>";

			break;

		case 4:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a></td></tr></table>";

			break;	

		case 5:

			html += " <a href='./CargadorcargaMenu.php?idmenu=5'  target='cargador'> Biblioteca UIM </a></td></tr></table>";

			break;	

		case 6:

			html += " <a href='./CargadorcargaMenu.php?idmenu=6'  target='cargador'> Administración </a></td></tr></table>";

			break;	

		case 7:

			html += " <a href='./CargadorcargaMenu.php?idmenu=7'  target='cargador'> Legislación </a></td></tr></table>";

			break;		

		

		case 9:

			html += " <a href='./CargadorcargaMenu.php?idmenu=2'  target='cargador'> Publicaciones UIM</a> >> <a href='http://www.uimunicipalistas.org/centrodoc/CargadorcargaMenu.php?idfuncion=4&idpag=1' target='cargador'> Novedades editoriales</a> </td></tr></table>";

			break;

		case 10:

			html += " <a href='./CargadorcargaMenu.php?idmenu=2'  target='cargador'> Publicaciones UIM</a> >> <a href='http://www.uimunicipalistas.org/centrodoc/CargadorcargaMenu.php?idfuncion=5&idpag=1' target='cargador'> Próximas Publicaciones</a> </tr></table>";

			break;

		case 11:

			html += " <a href='./CargadorcargaMenu.php?idmenu=2'  target='cargador'> Publicaciones UIM</a> >> <a href='./CargadorcargaMenu.php?idmenu=1'  target='cargador'> Publicaciones</a> </td></tr></table>";

			break;

		case 12:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=1' target='cargador' class='enlaceMateria'> Urbanismo y Medio Ambiente</a> </td></tr></table>";

			break;

		case 13:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=2' target='cargador' class='enlaceMateria'> Pobreza y exclusión social </a></td></tr></table>";

			break;

		case 14:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=3' target='cargador' class='enlaceMateria'> Pobreza y exclusión social </a></td></tr></table>";

			break;

		case 15:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=4' target='cargador' class='enlaceMateria'> Urbanismo y Medio Ambiente</a> </td></tr></table>";

			break;

		case 16:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=5' target='cargador' class='enlaceMateria'> Pobreza y exclusión social </a></td></tr></table>";

			break;

		case 17:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=6' target='cargador' class='enlaceMateria'> Pobreza y exclusión social </a></td></tr></table>";

			break;	

		case 18:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=7' target='cargador' class='enlaceMateria'> Urbanismo y Medio Ambiente</a> </td></tr></table>";

			break;

		case 19:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=8' target='cargador' class='enlaceMateria'> Pobreza y exclusión social </a></td></tr></table>";

			break;

		case 20:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=9' target='cargador' class='enlaceMateria'> Pobreza y exclusión social </a></td></tr></table>";

			break;

		case 21:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=10' target='cargador' class='enlaceMateria'> Urbanismo y Medio Ambiente</a> </td></tr></table>";

			break;

		case 22:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=11' target='cargador' class='enlaceMateria'> Pobreza y exclusión social </a></td></tr></table>";

			break;

		case 23:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=12' target='cargador' class='enlaceMateria'> Pobreza y exclusión social </a></td></tr></table>";

			break;	

		case 24:

			html += " <a href='./CargadorcargaMenu.php?idmenu=4'  target='cargador'> Enlaces </a> >> <a href='./CargadorcargaMenu.php?idfuncion=8&idenl=13' target='cargador' class='enlaceMateria'> Pobreza y exclusión social </a></td></tr></table>";

			break;

		case 25:

			html += " <a href='./CargadorcargaMenu.php?idmenu=5'  target='cargador'> Biblioteca UIM </a> >> <a href='http://www.uimunicipalistas.org/centrodoc/CargadorcargaMenu.php?idfuncion=9&idpag=1' target='cargador'> Noticias Biblioteca</a> </tr></table>";

			break;

		case 26:

			html += " <a href='./CargadorcargaMenu.php?idfuncion=10'  target='cargador'> Carrito </a></tr></table>";

			break;

		}

	parent.document.getElementById("ruta").innerHTML= html;

}

function noticiasPublicaciones(id){

	wopen('./php/publicacionDetalle.php?id='+id, 'fuera',790,400);

}

// Esta funcion se encarga de activar los campos del formulario dependiendo 

function radioActiva(formu){

	if(formu.rad[0].checked==true){

		formu.elements[1].disabled=false;

		formu.elements[3].disabled=true;

		formu.elements[5].disabled=true;

		formu.elements[5].value = "";

		formu.elements[3].value = "";

	}

	else if(formu.rad[1].checked==true){

		formu.elements[1].disabled=true;

		formu.elements[3].disabled=false;

		formu.elements[5].disabled=true;

		formu.elements[1].value = "";

		formu.elements[5].value = "";

	}

	else if(formu.rad[2].checked==true){

		formu.elements[1].disabled=true;

		formu.elements[3].disabled=true;

		formu.elements[5].disabled=false;

		formu.elements[1].value = "";

		formu.elements[3].value = "";

	}

}

function radioActivaLeg(formu){

	if(formu.rad[0].checked==true){

		formu.elements[1].disabled=false;

		formu.elements[3].disabled=true;

		formu.elements[3].value = "";

	}

	else if(formu.rad[1].checked==true){

		formu.elements[1].disabled=true;

		formu.elements[3].disabled=false;

		formu.elements[1].value = "";

	}

}





function wopen(url, name, w, h){

	w += 32;

	h += 96;

	wleft = (screen.width - w) / 2;

	wtop = (screen.height - h) / 2;

	var win = window.open(url,

	name,

	'width=' + w + ', height=' + h + ', ' +

	'left=' + wleft + ', top=' + wtop + ', ' +

	'location=no, menubar=no, ' +

	'status=no, toolbar=no, scrollbars=yes, resizable=no');

	// Just in case width and height are ignored

	win.resizeTo(w, h);

	// Just in case left and top are ignored

	win.moveTo(wleft, wtop);

	win.focus();

}



function oculta_ayuda(){

	ocultar = document.getElementById("capaAyuda");

	clearTimeout(retardo);

	retardo = setTimeout("xHide('" + ocultar + "')",1000);

}



function muestra_retarda(){

	document.getElementById("capaAyuda").style.visibility = "visible";

	clearTimeout(retardo);

} 

function xHide(e) {

  	document.getElementById("capaAyuda").style.visibility='hidden';

}



function resultadoUpload(estado, file, tipo) {

	var dir = "";

	var ruta="";

	alert("tipo: "+tipo+ " estado:" + estado);

	switch(tipo){

		case 1:

		ruta = 'documentos/centrodoc/articulos/';

		dir = '../../documentos/centrodoc/articulos/';

		break;

	}

    var link = '<br /><br /><a href="verArchivos.php">Ver Archivo </a> - <a href="eliminarArchivos.php?id="'+tipo+'>Eliminar Archivo </a>';

    if (estado == 0){

		var mensaje = 'El Archivo <a href="' + dir + file + '" target="_blank">' + file + '</a> se ha subido al servidor correctamente' + link;

		switch(tipo){

		case 1:

			document.getElementById("UrlArticulo").value= ruta + file;

			document.getElementById("UrlArticulo").disabled=true;

		break;

		}

	}

    if (estado == 1) var mensaje = 'Error ! - El Archivo no llego al servdor' + link;

    if (estado == 2) var mensaje = 'Error ! - Solo se permiten Archivos tipo Imagen / Doc / Pdf / txt' + link;

    if (estado == 3) var mensaje = 'Error ! - No se pudo copiar Archivo. Posible problema de permisos en server' + link;

	if (estado == 4) var mensaje = 'Error ! - Su archivo pesa más de 4 Mb . Posible problema de permisos en server' + link;

    document.getElementById('formUpload').innerHTML=mensaje;

}



function resultadoUploadMod(estado, file, tipo) {

	var ruta="";	

	switch(tipo){

		case 1:

		ruta = 'documentos/centrodoc/articulos/';

		document.getElementById('UrlArticulo').value= ruta + file;

		break;

		case 4:

		case 5:

		ruta = 'documentos/centrodoc/trabajos/';

		document.getElementById('UrlTrabajo').value= ruta + file;

		break;

		case 6:

		ruta = 'documentos/centrodoc/anales/';

		document.getElementById('documento').value= ruta + file;

		break;

		

	}

    if (estado == 0 || estado == 5){

		if(estado==0){

			var mensaje = 'El Archivo se ha subido al servidor correctamente' ;

		}

		if(estado==5){

			var mensaje = 'El Archivo se ha subido al servidor correctamente.  No se ha podido borrar el fichero antiguo.';

		}

	}

    if (estado == 1){

		var mensaje = 'Error ! - El Archivo no llego al servidor' ;

	}

    if (estado == 2){

		var mensaje = 'Error ! - Solo se permiten Archivos tipo: .doc , .pdf y powerpoint' ;

	}

    if (estado == 3){

		var mensaje = 'Error ! - No se pudo copiar Archivo. Posible problema de permisos en server' ;

	}

	if (estado == 4){

		var mensaje = 'Error ! - Su archivo pesa más de 4 Mb . Posible problema de permisos en server';

	}



    document.getElementById('cambio').innerHTML=mensaje;

	document.getElementById('urlfile').innerHTML= "Su documento se cargo correctamente.";

	

}



function compruebaCambioUrl(formu, op){

	switch(op){

		case 1:

		if(formu.UrlArticulo.value=='http://' || formu.UrlArticulo.value==''){

			document.getElementById("fileUpload").disabled=false;

		}

		else{

			document.getElementById("fileUpload").disabled=true;

		}

		break;

		case 6:

		if(formu.documento.value=='http://' || formu.documento.value==''){

			document.getElementById("fileUpload").disabled=false;

		}

		else{

			document.getElementById("fileUpload").disabled=true;

		}

		break;

	}

}

function activaFile(formu, op){

	switch(op){

		case 1:

		if(formu.urlofile[0].checked){

			document.getElementById("fileUpload").disabled=true;

			document.getElementById("UrlArticulo").disabled=false;

			

		}

		else{

			document.getElementById("UrlArticulo").disabled=true;

			document.getElementById("fileUpload").disabled=false;

			document.getElementById("UrlArticulo").value='http://';

		}

		case 3:

		if(formu.urlofile[0].checked){

			document.getElementById("fileUpload").disabled=true;

			document.getElementById("trabajo").disabled=false;

			

		}

		else{

			document.getElementById("trabajo").disabled=true;

			document.getElementById("fileUpload").disabled=false;

			document.getElementById("trabajo").value='http://';

		}

		case 4:

		case 5:

		if(formu.urlofile[0].checked){

			document.getElementById("fileUpload").disabled=true;

			document.getElementById("UrlTrabajo").disabled=false;

			

		}

		else{

			document.getElementById("UrlTrabajo").disabled=true;

			document.getElementById("fileUpload").disabled=false;

			document.getElementById("UrlTrabajo").value='http://';

		}

		case 6:

		if(formu.urlofile[0].checked){

			document.getElementById("fileUpload").disabled=true;

			document.getElementById("documento").disabled=false;

			

		}

		else{

			document.getElementById("documento").disabled=true;

			document.getElementById("fileUpload").disabled=false;

			document.getElementById("documento").value='http://';

		}

		case 8:

		if(formu.urlofile[0].checked){

			document.getElementById("fileUpload").disabled=true;

			document.getElementById("documento").disabled=false;

			

		}

		else{

			document.getElementById("documento").disabled=true;

			document.getElementById("fileUpload").disabled=false;

			document.getElementById("documento").value='http://';

		}

	}

}

function cambiaOtros(formu){

	if(formu.rango.value=="Otros"){

		formu.Otros.disabled=false;	

	}

	else{

		formu.Otros.value="";

		formu.Otros.disabled=true;

	}

	if(formu.Materia.value=="Otros"){

		formu.Otros2.disabled=false;	

	}

	else{

		formu.Otros2.value="";

		formu.Otros2.disabled=true;

	}

}



function nl2br(str) {

   return str.replace(/\n/g,"<br>");

}

function cambiaMiembro(formu){

	if(formu.EsMiembro[0].checked){

		document.getElementById("numeroMiembro").style.color ='#FF0000';

		document.getElementById("campoPassword").style.color ='#FF0000';

		if(detectarNav()=="IE"){

			document.getElementById("opacidad").style.filter = 'alpha(opacity=50)';	

		}

		else{

			document.getElementById("opacidad").style.opacity =  '0.50';

		}

		formu.IdParticipante.disabled=false;

		formu.Password.disabled=false;

		formu.Validar.disabled=false;

		formu.Apellidos.disabled=true;

		formu.Nombre.disabled=true;

		formu.Domicilio.disabled=true;

		formu.Localidad.disabled=true;

		formu.CodigoPostal.disabled=true;

		formu.Provincia.disabled=true;

		formu.Estado.disabled=true;

		formu.Pais.disabled=true;

		formu.Email.disabled=true;

		formu.img_amp_0.disabled=true;

		

	}

	else{

		document.getElementById("numeroMiembro").style.color ='#000000';

		document.getElementById("campoPassword").style.color ='#000000';

		if(detectarNav()=="IE"){

			document.getElementById("opacidad").style.filter = 'alpha(opacity=100)';

		}

		else{

			document.getElementById("opacidad").style.opacity =  '1';

		}

		formu.IdParticipante.value="";

		formu.Password.value="";

		formu.Validar.disabled=true;

		formu.IdParticipante.disabled=true;	

		formu.Password.disabled=true;

		formu.Apellidos.disabled=false;

		formu.Nombre.disabled=false;

		formu.Domicilio.disabled=false;

		formu.Localidad.disabled=false;

		formu.CodigoPostal.disabled=false;

		formu.Provincia.disabled=false;

		formu.Estado.disabled=false;

		formu.Pais.disabled=false;

		formu.Email.disabled=false;

		formu.img_amp_0.disabled=false;

	}

}



function validar_correo(correo) {

  var largo=correo.split('@').length;

  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(correo)) {

    return (true)

  } else {

    alert("La dirección de email " + correo + " es incorrecta.");

    return (false);

  }

}

function lTrim(sStr){

	while (sStr.charAt(0) == " ") 

		sStr = sStr.substr(1, sStr.length - 1);

		return sStr;

}

function rTrim(sStr){

	while (sStr.charAt(sStr.length - 1) == " ") 

		sStr = sStr.substr(0, sStr.length - 1);

		return sStr;

}	

function allTrim(sStr){

	return rTrim(lTrim(sStr));

}

function cambiaPrecioEnvio(formu){

	var preciotrans=0;

	var total

	var precios=formu.ocultotrans.value.split('/');

	

	for(var i=0, j=0; i<formu.cant.value; i++, j+=6){

		var sumazona = j + parseInt(formu.zona.value);

		if(formu.formaEnvio[1].checked==true){

			sumazona +=3;

		}

		preciotrans += parseFloat(precios[sumazona]);

	}

	preciotrans = preciotrans /100;

	var total = parseFloat(formu.subtotal.value) +  preciotrans - parseFloat(formu.descuento.value);

	// alert("Subtotal" + formu.subtotal.value);

	// alert("Total: "+ total);

	preciotrans = roundOff(preciotrans, 2);

	parent.document.getElementById("gastos").innerHTML = preciotrans + " €";

	if(parseInt(formu.zona.value)==0){

		total += parseFloat(formu.iva.value);

		total = redondear(total);

		parent.document.getElementById("total").innerHTML = total + " €";

	}

	else{

		total = redondear(total);

		parent.document.getElementById("total").innerHTML = total + " €";

	}

	

}

function redondear(num)

{ 		

	var original=parseFloat(num);

	if ((original*100%100)>=0.5)

	{

		var result=Math.round(original*100)/100+0.00;

	}

	else

	{

		var result=Math.round(original*100)/100; 		

	}

	return result;

}

function roundOff(value, precision)

{

value = "" + value //convert value to string

precision = parseInt(precision);



var whole = "" + Math.round(value * Math.pow(10, precision));



var decPoint = whole.length - precision;



if(decPoint != 0)

{

result = whole.substring(0, decPoint);

result += ".";

result += whole.substring(decPoint, whole.length);

}

else

{

result = whole;

}

return result;

} 
