function CojerValorCookie(indice) { //indice indica el comienzo del valor var galleta = document.cookie; //busca el final del valor, dado por ;, a partir de indice var finDeCadena = galleta.indexOf(";", indice); //si no existe el ;, el final del valor lo marca la longitud total de la cookie if (finDeCadena == -1){ finDeCadena = galleta.length; } return unescape(galleta.substring(indice, finDeCadena)); } function CojerCookie(nombre) { var galleta = document.cookie; //construye la cadena con el nombre del valor var arg = nombre + "="; var alen = arg.length; //longitud del nombre del valor var glen = galleta.length; //longitud de la cookie var i = 0; while (i < glen) { var j = i + alen; //posiciona j al final del nombre del valor if (galleta.substring(i, j) == arg){ //si en la cookie estamo ya en nombre del valor return CojerValorCookie(j); //devuleve el valor, que esta a partir de j } i = galleta.indexOf(" ", i) + 1; //pasa al siguiente if (i == 0){ break; //fin de la cookie } } return null //no se encuentra el nombre del valor } function GuardarCookie (nombre, valor) { //crea la cookie: incluye el nombre y la ruta donde esta guardada cada valor esta separado por ; y un espacio document.cookie = nombre + "=" + escape(valor) + "; path=/"; } function mostrarDetalleOld(codigo, producto, ficha){ window.open("detalle.do?codigo="+ codigo + "&producto=" + producto + "&ficha=" + ficha, "mywindow","menubar=0,resizable=1,width=800,height=350,scrollbars=yes"); } function mostrarDetalle(codigo, producto, ficha){ document.DetalleForm.codigo.value = codigo; document.DetalleForm.producto.value = producto; document.DetalleForm.ficha.value = ficha; document.DetalleForm.submit(); } function carrito(start, limit){ document.CarritoForm.metodo.value = 'mostrar'; document.CarritoForm.start.value = start; document.CarritoForm.limit.value = limit; document.CarritoForm.submit(); } function factura(start, limit){ document.FacturaForm.metodo.value = 'mostrar'; document.FacturaForm.start.value = start; document.FacturaForm.limit.value = limit; document.FacturaForm.submit(); } function facturas(start, limit){ document.FacturaForm.metodo.value = 'listado'; document.FacturaForm.start.value = start; document.FacturaForm.limit.value = limit; document.FacturaForm.submit(); } function abrirFactura(report){ window.open(report); } //Metodo para Solicitar factura function solicitarFactura (start, limit, codigo, codigoFactura) { document.FacturaForm.metodo.value = 'listado'; document.FacturaForm.facSolicitada.value = "S"; document.FacturaForm.start.value = start; document.FacturaForm.limit.value = limit; document.FacturaForm.codigo.value = codigo; document.FacturaForm.codigoFactura.value = codigoFactura; document.FacturaForm.submit(); } // ----------------------------------------------------------------------------- // sortTable(id, col, rev) // // id - ID of the TABLE, TBODY, THEAD or TFOOT element to be sorted. // col - Index of the column to sort, 0 = first column, 1 = second column, // etc. // rev - If true, the column is sorted in reverse (descending) order // initially. // // Note: the team name column (index 1) is used as a secondary sort column and // always sorted in ascending order. // ----------------------------------------------------------------------------- function sortTable(id, col, rev) { // Get the table or table section to sort. var tblEl = document.getElementById(id); // The first time this function is called for a given table, set up an // array of reverse sort flags. if (tblEl.reverseSort == null) { tblEl.reverseSort = new Array(); // Also, assume the team name column is initially sorted. tblEl.lastColumn = 1; } // If this column has not been sorted before, set the initial sort direction. if (tblEl.reverseSort[col] == null) tblEl.reverseSort[col] = rev; // If this column was the last one sorted, reverse its sort direction. if (col == tblEl.lastColumn) tblEl.reverseSort[col] = !tblEl.reverseSort[col]; // Remember this column as the last one sorted. tblEl.lastColumn = col; // Set the table display style to "none" - necessary for Netscape 6 // browsers. var oldDsply = tblEl.style.display; tblEl.style.display = "none"; // Sort the rows based on the content of the specified column using a // selection sort. var tmpEl; var i, j; var minVal, minIdx; var testVal; var cmp; for (i = 0; i < tblEl.rows.length - 1; i++) { // Assume the current row has the minimum value. minIdx = i; minVal = getTextValue(tblEl.rows[i].cells[col]); // Search the rows that follow the current one for a smaller value. for (j = i + 1; j < tblEl.rows.length; j++) { testVal = getTextValue(tblEl.rows[j].cells[col]); cmp = compareValues(minVal, testVal); // Negate the comparison result if the reverse sort flag is set. if (tblEl.reverseSort[col]) cmp = -cmp; // Sort by the second column (team name) if those values are equal. //if (cmp == 0 && col != 1) // cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]), // getTextValue(tblEl.rows[j].cells[1])); // If this row has a smaller value than the current minimum, remember its // position and update the current minimum value. if (cmp > 0) { minIdx = j; minVal = testVal; } } // By now, we have the row with the smallest value. Remove it from the // table and insert it before the current row. if (minIdx > i) { tmpEl = tblEl.removeChild(tblEl.rows[minIdx]); tblEl.insertBefore(tmpEl, tblEl.rows[i]); } } // Make it look pretty. makePretty(tblEl, col); // Restore the table's display style. tblEl.style.display = oldDsply; return false; } //----------------------------------------------------------------------------- // Functions to get and compare values during a sort. //----------------------------------------------------------------------------- // This code is necessary for browsers that don't reflect the DOM constants // (like IE). if (document.ELEMENT_NODE == null) { document.ELEMENT_NODE = 1; document.TEXT_NODE = 3; } function getTextValue(el) { var i; var s; // Find and concatenate the values of all text nodes contained within the // element. s = ""; for (i = 0; i < el.childNodes.length; i++) if (el.childNodes[i].nodeType == document.TEXT_NODE) s += el.childNodes[i].nodeValue; else if (el.childNodes[i].nodeType == document.ELEMENT_NODE && el.childNodes[i].tagName == "BR") s += " "; else // Use recursion to get text within sub-elements. s += getTextValue(el.childNodes[i]); return normalizeString(s); } function compareValues(v1, v2) { var f1, f2; // If the values are numeric, convert them to floats. f1 = parseFloat(v1); f2 = parseFloat(v2); if (!isNaN(f1) && !isNaN(f2)) { v1 = f1; v2 = f2; } // Compare the two values. if (v1 == v2) return 0; if (v1 > v2) return 1 return -1; } // Regular expressions for normalizing white space. var whtSpEnds = new RegExp("^\\s*|\\s*$", "g"); var whtSpMult = new RegExp("\\s\\s+", "g"); function normalizeString(s) { s = s.replace(whtSpMult, " "); // Collapse any multiple whites space. s = s.replace(whtSpEnds, ""); // Remove leading or trailing white space. return s; } //----------------------------------------------------------------------------- // Functions to update the table appearance after a sort. //----------------------------------------------------------------------------- // Style class names. var rowClsNm = "alternateRow"; var colClsNm = "sortedColumn"; // Regular expressions for setting class names. var rowTest = new RegExp(rowClsNm, "gi"); var colTest = new RegExp(colClsNm, "gi"); function makePretty(tblEl, col) { var i, j; var rowEl, cellEl; // Set style classes on each row to alternate their appearance. for (i = 0; i < tblEl.rows.length; i++) { rowEl = tblEl.rows[i]; rowEl.className = rowEl.className.replace(rowTest, ""); if (i % 2 != 0) rowEl.className += " " + rowClsNm; rowEl.className = normalizeString(rowEl.className); // Set style classes on each column (other than the name column) to // highlight the one that was sorted. for (j = 2; j < tblEl.rows[i].cells.length; j++) { cellEl = rowEl.cells[j]; cellEl.className = cellEl.className.replace(colTest, ""); if (j == col) cellEl.className += " " + colClsNm; cellEl.className = normalizeString(cellEl.className); } } // Find the table header and highlight the column that was sorted. var el = tblEl.parentNode.tHead; rowEl = el.rows[el.rows.length - 1]; // Set style classes for each column as above. for (i = 2; i < rowEl.cells.length; i++) { cellEl = rowEl.cells[i]; cellEl.className = cellEl.className.replace(colTest, ""); // Highlight the header of the sorted column. if (i == col) cellEl.className += " " + colClsNm; cellEl.className = normalizeString(cellEl.className); } } function valida_nif_cif_nie(cif, tipo) { // Devuelve: 1 = NIF ok, 2 = CIF ok, 3 = NIE ok, -1 = NIF bad, -2 = CIF bad, -3 = NIE bad, 0 = ??? bad, -4 = Longitud invalida if (cif == "" || cif == null || cif.length < 9 || cif.length > 9) { return -4; } cif = cif.toUpperCase(); var num = new Array(); for (var i = 0; i < 9; i ++) { num[i] = cif.substr(i, 1); } // si no tiene un formato valido devuelve error if (cif.search(/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/) == -1) { alert("No tiene un formato valido"); return 0; } // comprobacion de NIFs estandar if (tipo == 2){ if (cif.search(/(^[0-9]{8}[A-Z]{1}$)/) != -1) { if (num[8] == 'TRWAGMYFPDXBNJZSQVHLCKE'.substr(cif.substr(0, 8) % 23, 1)) { return 1; } else { return -1; } } } // algoritmo para comprobacion de codigos tipo CIF if (tipo == 8){ var suma = new Number(num[2]) + new Number(num[4]) + new Number(num[6]); for (i = 1; i < 8; i += 2) { var a = 2 * num[i]; var b = a.toString().substr(0,1); var c = a.toString().substr(1,1); suma += new Number(b) + new Number(c); } var n = 10 - new Number(suma.toString().substr(suma.toString().length - 1, 1)); // comprobacion de NIFs especiales (se calculan como CIFs) if (cif.search(/^[KLM]{1}/) != -1) { if (num[8] == String.fromCharCode(64 + n)) { return 1; } else { return -1; } } // comprobacion de CIFs if (cif.search(/^[ABCDEFGHJNPQRSUVW]{1}/) != -1) { if (num[8] == String.fromCharCode(64 + n) || num[8] == n.toString().substr(n.toString().length - 1, 1)) { return 2; } else { return -2; } } } if (tipo == 3){ // comprobacion de NIEs // T if (cif.search(/^[T]{1}/) != -1) { if (num[8] == cif.search(/^[T]{1}[A-Z0-9]{8}$/)) { return 3; } else { return -3; } } // XYZ if (cif.search(/^[XYZ]{1}/) != -1) { if (num[8] == 'TRWAGMYFPDXBNJZSQVHLCKE'.substr(cif.replace('X', '0').replace('Y','1').replace('Z','2').substr(0, 8) % 23, 1)) { return 3; } else { return -3; } } } // si todavia no se ha verificado devuelve error return 0; } function esValido(valor, tipo) { // Devuelve: 1 = NIF ok, 2 = CIF ok, 3 = NIE ok, -1 = NIF bad, -2 = CIF bad, -3 = NIE bad, 0 = ??? bad, -4 = Longitud invalida var a = valida_nif_cif_nie(valor, tipo); switch (a) { case 1: return "NIF"; break; case 2: return "CIF"; break; case 3: return "NIE"; break; case -1: return "El documento introducido no es válido"; break; case -2: return "El documento introducido no es válido"; break; case -3: return "El documento introducido no es válido"; break; case 0: return "El documento introducido no es válido"; break; case -4: return "La longitud del documento no es correcta"; break; } } function recomboJson(accion, formulario, desplegable, cod, ejecutar) { j.ajax({ url: accion, data : { pcodigo: cod }, async: false, beforeSend: function () { var json = {'results': [{'codigo': '', 'nombre': 'cargando...'}]}; recargaCombo(desplegable, json.results); }, success: function(json) { recargaCombo(desplegable, json.results); } }); if (ejecutar != null && ejecutar != undefined && ejecutar != '') { eval(ejecutar); } /* new Ajax.Request(accion, { method: 'post', parameters: { pcodigo: cod }, onSuccess: function(transport, ejecutar){ var json = transport.responseText.evalJSON(true); recargaCombo(desplegable, json.results); }, onLoading: function(){ var json = {'results': [ {'codigo': '', 'nombre': 'cargando...'} ]}; recargaCombo(desplegable, json.results); }, onException: function(){ alert('Algo a pasao!'); } }); */ } function recargaCombo(idCombo, resultados){ var combo = $(idCombo); while(combo.options.length > 0){ combo.remove(combo.options[combo.options.length]); } combo.options.add(new Option("", "")); for(var i=0; i 0){ combo.remove(combo.options[combo.options.length]); } } function recomboJsonMunicipios(accion, formulario, desplegable, cod){ var resultado = false; new Ajax.Request(accion, { asynchronous: false, method: 'post', parameters: { pcodigo: cod }, onSuccess: function(transport){ var json = transport.responseText.evalJSON(true); resultado = recargaComboMunicipios(desplegable, json.results); }, onLoading: function(){ var json = {'results': [ {'codigo': '', 'nombre': 'cargando...'} ]}; recargaCombo(desplegable, json.results); } }); return resultado; } function recargaComboMunicipios(idCombo, resultados){ var combo = $(idCombo); while(combo.options.length > 0){ combo.remove(combo.options[combo.options.length]); } //combo.options.add(new Option("", "")); for(var i=0; i 0) return true; else return false; } function cargaDialogo(nombre){ var altoDialog = (jQuery(window).height() - (jQuery(window).height() * 0.7)); var anchoDialog = (jQuery(window).width() - (jQuery(window).width() * 0.8)); jQuery(nombre).dialog({ autoOpen: false, beforeClose: function () {}, buttons: [ { id: "cancelar", text: "Cerrar", click: function() { jQuery(this).dialog('close'); }, icons: {primary: "ui-icon-pencil"} } ], close: function () {}, draggable: true, height: altoDialog, modal: true, resizable: false, width: anchoDialog }); } function openDialog(dialogName){ var _dialog = jQuery(dialogName); _dialog.dialog('open'); _dialog.scrollTop(0); } var j = jQuery.noConflict(); /* function mostrarCargando(info) { j( "#dialog-cargando" ).html( '

' + info.toLowerCase() + "

" + 'cargando, un momento por favor

' + '' + '

' ); j( "#dialog" ).dialog( "destroy" ); j( "#dialog-cargando" ).dialog({ resizable: false, modal: true, height: 200, width: 300, draggable: false, closeOnEscape: false, dialogClass: 'no-close-no-title' }); } j(function() { j('a').click(function() { var href = $(this).href; if (href != '') mostrarCargando('') }); }); */