function Distribucion(nombre, lisdes, maxuni, maxpas, maxeda, capmax, capmin, maxadu, maxnin, chkuni, totadu, totnin, chkeda) {this.nombre = nombre;this.lisdes = (lisdes != null) ? lisdes : new Array('NºHabs', 'Adl.', 'Edad Ni&ntilde;o', 'Total', 'adulto', 'adultos', 'y', 'ni&ntilde;o', 'ni&ntilde;os', 'El numero total de unidades no puede ser mayor de', 'La distribucion seleccionada supera la capacidad maxima de la habitacion de {0} pasajeros', 'El numero total de pasajeros no puede ser mayor de', 'en' , 'habitaci&oacute;n', 'habitaciones', 'Hab', 'El numero total de adultos debe ser de {0}', 'El numero total de niños debe ser de {0}', 'El numero total de pasajeros no puede ser menor de {0}', 'y', 'de', 'a&ntilde;os');this.maxuni = (maxuni != null) ? maxuni : 9;this.maxpas = (maxpas != null) ? maxpas : 9;this.capmin = (capmin != null) ? capmin : 1;this.capmax = (capmax != null) ? capmax : 4;this.maxnin = (maxnin != null) ? maxnin : 2;this.minadu = ((this.capmin - this.maxnin) > 0) ? this.capmin - this.maxnin : 1;this.maxadu = (maxadu != null) ? maxadu : 4;this.maxeda = (maxeda != null) ? maxeda : 17;this.totadu = (totadu != 0) ? totadu : null;this.totnin = (totnin != 0) ? totnin : null;this.chkuni = (chkuni != null) ? chkuni : 'N';this.chktot = 'S';this.chkeda = (chkeda != null) ? chkeda : 'N';this.accionSeleccion;this.get = function(id) { return document.getElementById(this.nombre + 'tr' + id);};this.writeDistribucion = function() { var maxnin = (this.maxnin > 1) ? this.maxnin : 2; var c = '', d = ''; var defsel = 'class="verdana_9_oscuro_naranja_input" onchange="' + this.nombre + '.valida(index)">'; var idxeda = this.lisdes[2].indexOf('?'); c += '<table id="' + this.nombre + 'tb" class="verdana_10_oscuro" width="1" border="0" cellpadding="0" cellspacing="0">'; c += ' <tr style="padding-bottom: 1px">'; c += ' <td align="center" valign="bottom">' + ((this.chkuni == 'S') ? this.lisdes[0] : '') + '</td>'; c += ' <td align="center" valign="bottom"> ' + this.lisdes[1] + '</td>'; for (var x = 1; x <= maxnin; x++) { if (idxeda != -1) { c += ' <td>' + this.lisdes[2].replace('?', x) + '</td>'; } else { c += ' <td>' + this.lisdes[2] + ' ' + x + '</td>'; } } c += ' <td colspan="' + (this.capmax + 1) + '"/></tr>'; c += ' <tr height="1">'; c += ' <td class="fondo_oscuro" colspan="' + (maxnin + 3 + this.capmax) + '" width="100%"/></tr>'; if (this.chkuni == 'S') { d += ' <td>'; d += ' <select id="' + this.nombre + 'tr0uni" ' + defsel; for (var x = 0; x <= this.maxuni; x++) { d += ' <option>' + x + '</option>';} d += ' </select></td>';} else { d += ' <td align="center"><div style="width: 40px">' + this.lisdes[15] + ' nhab</div></td>';} d += ' <td>'; d += ' <select id="' + this.nombre + 'tr0adu" ' + defsel;if ((this.chkuni != 'S') && (this.capmin > 0)) { d += ' <option>0</option>';} for (var x = this.minadu; x <= this.maxadu; x++) { d += ' <option>' + x + '</option>';} d += ' </select></td>';for (var x = 0; x < maxnin; x++) { d += ' <td>'; d += ' <select id="' + this.nombre + 'tr0nin' + x + '" ' + defsel; d += ' <option>--</option>'; for (var y = 1; y <= this.maxeda; y++) { d += ' <option>' + y + '</option>'; } d += ' </select></td>';} for (var x = 0; x < this.capmax; x++) { d += ' <td id="' + this.nombre + 'tr0img' + x + '" valign="bottom"/>';} d += ' <td id="' +this.nombre + 'tr0ref"/>'; var regexp = new RegExp(this.nombre + 'tr0', 'g'); c += '<tr id="' + this.nombre + 'tr0" style="padding-top: 2px">' + d.replace(/index/g, '0').replace(/nhab/g, '1') + '<tr id="' + this.nombre + 'tr1" style="padding-top: 2px">' + d.replace(regexp, this.nombre + 'tr1').replace(/index/g, '1').replace(/nhab/g, '2') + '<tr id="' + this.nombre + 'tr2" style="padding-top: 2px;padding-bottom: 2px">' + d.replace(regexp, this.nombre + 'tr2').replace(/index/g, '2').replace(/nhab/g, '3'); c += ' <tr height="1">'; c += ' <td class="fondo_oscuro" colspan="' + (maxnin + 3 + this.capmax) + '" width="100%"/></tr>'; c += ' <tr>'; c += ' <td id="' + this.nombre + 'trtotnom" valign="top"/>'; c += ' <td id="' + this.nombre + 'trtotval" colspan="' + (maxnin + 2 + this.capmax) + '"/></tr>'; c += '</table>'; document.write(c); var img = document.createElement('IMG'); img.src = 'images/ico_hab.gif'; var td;for (var x = 0, y; x < 3; x++) { for (y = 0; y < this.capmax; y++) {var copy = img.cloneNode (false);copy.setAttribute ('id', this.nombre + 'tr' + x + '_img' + y); this.get(x + 'img' + y).appendChild(copy); } if (this.maxnin < 2) this.get(x + 'nin1').disabled = true; if (this.maxnin < 1) this.get(x + 'nin0').disabled = true; } };this.getNum = function(tipo, idx, valor) { if ((tipo == 'uni') && (this.chkuni == 'N')) return 1; var sl = this.get(idx + tipo); var v = sl.options[sl.selectedIndex].text; return (valor) ? parseInt((v != '--') ? v : 0) : (v != '--') ? 1 : 0;};this.validaDIS = function(idx) { var err = false; var nin = 0; var adu = this.getNum('adu', idx, true); for (var x = 0; x < this.maxnin; x++) { if (this.getNum('nin' + x, idx, false) > 0) { if ((adu + nin + 1) > this.capmax) { this.get(idx + 'nin' + x).options[0].selected = true; err = true; } else { nin++ } } } var uni = this.getNum('uni', idx, true); if ((uni == null) || (uni == '0')) adu = nin = 0; this.actualizaIMG(idx, adu, nin); return err;};this.validaUNI = function(idx) { var err = false; if ((this.getNum('uni', 0, true) + this.getNum('uni', 1, true) + this.getNum('uni', 2, true)) > this.maxuni) { this.get(idx + 'uni').options[0].selected = true; err = true; } return err;};this.validaPAS = function(idx) { var err = false; var pas = 0; for (var x = 0; x < 3; x++) { pas += this.getNum('adu', x, true); for (var y = 0; y < this.maxnin; y++) { pas += this.getNum('nin' + y, x, false); } } if (pas > this.maxpas) { err = true; this.get(idx + 'adu').options[0].selected = true; for (var x = 0; x < this.maxnin; x++) { this.get(idx + 'nin' + x).options[0].selected = true; } } return err;};this.valida = function(idx) { if (this.validaUNI(idx)) alert(this.lisdes[9] + ' ' + this.maxuni); if (this.validaPAS(idx)) alert(this.lisdes[11] + ' ' + this.maxpas); if (this.validaDIS(idx)) alert(this.lisdes[10].replace(/\{0\}/, this.capmax)); this.resumen(); if (this.accionSeleccion != null) this.accionSeleccion(this);};this.actualizaIMG = function(idx, adu, nin) { var tp; var img; for (var x = 0; x < this.capmax; x++) { img = this.get(idx + '_img' + x); if (x < adu) tp = 'A'; else if (x < (adu + nin)) tp = 'N'; else tp = '?'; img.setAttribute('width', (tp == 'A') ? '9' : '7'); img.setAttribute('height', (tp == 'A') ? '18' : '12'); img.className = (tp == '?') ? 'fondo_blanco' : 'fondo_naranja'; }};this.resumen = function() { var uni, adu = 0, nin = 0, hab = 0, numadu, numnin; var eda = ''; for (var x = 0; x < 3; x++) { uni = this.getNum('uni', x, true); if (uni > 0) { numadu = this.getNum('adu', x, true); numnin = 0; for (var y = 0; y < this.maxnin; y++) { numnin += this.getNum('nin' + y, x, false); if (this.getNum('nin' + y, x, true) != '0') { if (eda != '') eda += ', '; eda += this.getNum('nin' + y, x, true); } } adu += numadu * uni; nin += numnin * uni; if ((numadu + numnin) > 0) hab += uni; } } if (this.chkeda == 'S') { var idx = eda.lastIndexOf(','); if (idx != -1) { eda = eda.substring(0, idx) + ' ' + this.lisdes[19] + eda.substring(idx + 1); } if (eda != '') eda = this.lisdes[20] + ' ' + eda + ' ' + this.lisdes[21]; } else { eda = ''; } var tdnom = this.get('totnom'); var tdval = this.get('totval'); if (((adu + nin) > 0) && (this.chktot == 'S')) { tdnom.innerHTML = this.lisdes[3] + ': '; tdval.innerHTML = adu + ' ' + this.lisdes[(adu == 1) ? 4 : 5] + ((nin > 0) ? ' ' + this.lisdes[6] + ' ' + nin + ' ' + this.lisdes[(nin == 1) ? 7 : 8] : '') + ((eda != '') ? '<br/>' + eda : '') + ((hab > 0) ? '<br/>' + this.lisdes[12] + ' ' + hab + ' ' + this.lisdes[(hab == 1) ? 13 : 14] : ''); } else { tdnom.innerHTML = '?'; tdval.innerHTML = '?'; } return adu + nin;};this.inicializa = function(valor) { for (var x = 0; x < 3; x++) { if (this.chkuni == 'S') this.get(x + 'uni').options[0].selected = true; this.get(x + 'adu').options[0].selected = true; for (var y = 0; y < this.maxnin; y++) { this.get(x + 'nin' + y).options[0].selected = true; } } var dato; var distri; for (var x = 0; x < 3; x++) { if (valor != null) { if (valor.indexOf('D') != -1) { distri = valor.substring(0, valor.indexOf('D')); valor = valor.substring(valor.indexOf('D') + 1); } else { distri = valor; valor = null; } dato = distri.split('A'); if ((dato.length > 0) && (this.chkuni == 'S')) { if ((dato[0] >= 0) && (dato[0] < this.get(x + 'uni').options.length)) this.get(x + 'uni').options[dato[0]].selected = true; } dato[1] = dato[1] - this.minadu + 1; if ((dato.length > 1) && (dato[1] >= 0) && (dato[1] < this.get(x + 'adu').options.length)) this.get(x + 'adu').options[dato[1]].selected = true; for (var y = 0; (y < this.maxnin) && ((y + 2) < dato.length); y++) { if (!this.get(x + 'nin' + y).disabled && (dato[y + 2] >= 0) && (dato[y + 2] < this.get(x + 'nin' + y).options.length)) { this.get(x + 'nin' + y).options[dato[y + 2]].selected = true; } } } this.validaUNI(x); this.validaDIS(x); this.validaPAS(x); } this.resumen(); };this.estado = function() { var estado = ''; for (var x = 0; x < 3; x++) { estado += this.getNum('uni', x, true) + 'A' + this.getNum('adu', x, true); for (var y = 0; y < this.maxnin; y++) { estado += 'A' + this.getNum('nin' + y, x, true); } if (x != 2) estado += 'D'; } return estado; };this.esValido = function() { var uni = 0, adu = 0, nin = 0; for (var x = 0; x < 3; x++) { uni += this.getNum('uni', x, true); adu += this.getNum('adu', x, true) * this.getNum('uni', x, true); for (var y = 0; y < this.maxnin; y++) { nin += this.getNum('nin' + y, x, false) * this.getNum('uni', x, true); } } if ((this.totadu != null) && (this.totadu != adu)) { alert(this.lisdes[16].replace(/\{0\}/, this.totadu)); return false; } if ((this.totnin != null) && (this.totnin != nin)) { alert(this.lisdes[17].replace(/\{0\}/, this.totnin)); return false; } if ((adu + nin) < this.capmin) { alert(this.lisdes[18].replace(/\{0\}/, this.capmin)); return false; } return (uni > 0);}; this.activar = function(activar) { for (var x = 0; x < 3; x++) { if (this.chkuni == 'S') this.get(x + 'uni').disabled = !activar; this.get(x + 'adu').disabled = !activar; for (var y = 0; y < this.maxnin; y++) { this.get(x + 'nin' + y).disabled = !activar; } }};this.referencia = function(idx) { return this.get(idx + 'ref');}; }