function URLEnc(texto){

	var codificado = texto.replace(/ /g,"-");
	codificado = codificado.replace(/á/g,"a");
	codificado = codificado.replace(/é/g,"e");
	codificado = codificado.replace(/í/g,"i");
	codificado = codificado.replace(/ó/g,"o");
	codificado = codificado.replace(/ú/g,"u");
	codificado = codificado.replace(/à/g,"a");
	codificado = codificado.replace(/è/g,"e");
	codificado = codificado.replace(/ì/g,"i");
	codificado = codificado.replace(/ò/g,"o");
	codificado = codificado.replace(/ù/g,"u");
	codificado = codificado.replace(/ñ/g,"n");
	codificado = codificado.replace(/ä/g,"a");
	codificado = codificado.replace(/ë/g,"e");
	codificado = codificado.replace(/ï/g,"i");
	codificado = codificado.replace(/ö/g,"o");
	codificado = codificado.replace(/ü/g,"u");
	codificado = codificado.replace(/ñ/g,"n");
	codificado = codificado.toLowerCase();
	return codificado;
};

function verifica_busqueda(){
	if(document.oForm.busqueda.value==''){
		alert('Introduzca una palabra a buscar');
		return false;
	}
	if(document.oForm.busqueda.value.length < 2){
		alert('Introduzca almenos 2 letras en el campo de búsqueda');
	}
	document.oForm.submit();
}

function busca_empresas(frm,categoria){
	var poblacion = frm.poblacion.value;
	if(poblacion == "todas"){
		var x = document.getElementById("provincia");
		poblacion = URLEnc(x.options[x.selectedIndex].text);
		var busqueda = "/"+categoria+"-en-"+poblacion;
	}else{
		var busqueda = "/"+categoria+"-en-"+poblacion;
	}

	document.location = busqueda+"/"
}

/* FUNCIONES ADJUNTOS*/
	
function myShowUI() {
	var btnSubmit = document.getElementById("btnSubmit");
	var txttipo = document.getElementById("tipo");
	var txtdescripcioncas = document.getElementById("descripcioncas");
	var txtdescripcioncat = document.getElementById("descripcioncat");
	
	btnSubmit.onclick = doSubmit;
/*	btnSubmit.disabled = false;
	
	txttipo.onchange = validateForm;
	txtdescripcioncas.onchange = validateForm;
	txtdescripcioncat.onchange = validateForm;
	txtFileName.onchange = validateForm;  */
	
	
	SWFUpload.swfUploadLoaded.apply(this);  // Let SWFUpload finish loading the UI.
	validateForm();
}

function validateForm() {
	
}

function fileBrowse() {
	var txtFileName = document.getElementById("txtFileName");
	txtFileName.value = "";

	this.cancelUpload();
	this.selectFile();
}


// Called by the submit button to start the upload
function doSubmit(e) {
	/* IF PARA CONTROLAR SI ES UN ADJUNTO DE NOTICIA O DE TICKET*/
	if(document.getElementById("descripcioncas")){
		var descripcioncas = document.getElementById("descripcioncas").value;
		var descripcioncat = document.getElementById("descripcioncat").value;
		var tipo = document.getElementById("tipo").value;
	}else{
		var descripcion = document.getElementById("descripcion").value;
	}
	var txtFileName = document.getElementById("txtFileName").value;
	var hidFileID = document.getElementById("hidFileID").value;
	var resume_degraded = document.getElementById("resume_degraded").value;
	/* IF PARA PODER USAR EL UPLOAD EN LOS TICKETS SIN CONTROLAR ESTOS CAMPOS*/
	if(document.getElementById("descripcioncas")){
		document.forms[0].urladjunto.value=txtFileName;
		if(document.forms[0].trapi){
			var nombre = document.getElementById("nombre").value;
			if(nombre==""){
			alert("Introdueixi el Nom");
			return false;
			}
		
		}
		
		if(tipo=="sel"){
			alert("Seleccioni el tipus d'adjunt");
			return false;
		}
	}else{
		if(descripcion==""){
			alert("Introdueixi la descripció");
			return false;
		}
		if(txtFileName==""){
			alert("Seleccioni un arxiu per adjuntar");
			return false;
		}
		document.forms[0].urladjunto.value=txtFileName;
	}
	//carga(tipo);
	e = e || window.event;
	if (e.stopPropagation) e.stopPropagation();
	e.cancelBubble = true;
	
	try {
		if(document.forms[0].txtFileName){
			if(document.forms[0].txtFileName.value == "" && document.forms[0].modifica.value == ""){
				alert("Esculli l'arxiu que vulgui adjuntar");
				return false;
			}
			
			if(document.forms[0].txtFileName.value == "" && document.forms[0].modifica.value != ""){
				//alert("Si sale esto, es porque es una modificacion sin cambiar el archivo");
			   document.forms[0].submit();
			}else{
				swf_upload_control.startUpload();
			}
		}else{
			swf_upload_control.startUpload();
		}

	} catch (ex) {

	}
	return false;
}

 // Called by the queue complete handler to submit the form
function uploadDone() {
	try {
		if(document.forms[0].txtFileName){
			document.forms[0].submit();
		}else{
			document.forms[1].submit();
		}
	} catch (ex) {
		alert("Error submitting form");
	}
}


function deleteadj(tipo,idadj,iddoc){
	 if(!confirm("Està segur de voler eliminar l'adjunt?")) {
		 return false;
	 }else{ 
		document.location="/" + tipo + "/alta/adj/?id=" + iddoc + "&idadj="+idadj+"&option=delete";
	 }   
	
}

function modifyadj(tipo,idadj,iddoc){
	if(!confirm("Está seguro de voler modificar l'adjunt?")) {
		 return false;
	}else{ 
		document.location="/" + tipo + "/alta/adj/?id=" + iddoc + "&idadj="+idadj+"&option=modify";
	}
}

/* FIN FUNCIONES ADJUNTOS*/
