bName = navigator.appName; bVer = parseInt(navigator.appVersion); var my_reg_iz = new sack(); var my_reg_v = new sack(); var obji = new Object(); var ideli; var objv = new Object(); var idelv; function sel_reg_iz(sel,obl,reg){ ideli = reg; if (typeof(sel)=='object') { var countryCode = sel.options[sel.selectedIndex].value; } else { var countryCode = sel; } document.getElementById(ideli).options.length = 0; if(countryCode.toString().length>0){ my_reg_iz.setVar("country", countryCode); my_reg_iz.setVar("obl", obl); my_reg_iz.setVar("mob", "i"); my_reg_iz.requestFile = "/getreg.php"; my_reg_iz.method = "GET"; my_reg_iz.onLoading = waitLoadi; my_reg_iz.onLoaded = waitLoadi; my_reg_iz.onInteractive = waitLoadi; my_reg_iz.onCompletion = createRegi; my_reg_iz.runAJAX(); } } function waitLoadi() { obji = document.getElementById(ideli); obji.options[0] = new Option('Загрузка...','0'); var resob=document.getElementById('sel_country_iz'); resob.disabled = true; } function createRegi() { obji = document.getElementById(ideli); var resob=document.getElementById('sel_country_iz'); resob.disabled = false; eval(my_reg_iz.response); } function sel_reg_v(sel,obl,reg){ idelv = reg; if (typeof(sel)=='object') { var countryCode = sel.options[sel.selectedIndex].value; } else { var countryCode = sel; } document.getElementById(idelv).options.length = 0; if(countryCode.toString().length>0){ my_reg_v.setVar("country", countryCode); my_reg_v.setVar("obl", obl); my_reg_v.setVar("mob", "v"); my_reg_v.requestFile = "/getreg.php"; my_reg_v.method = "GET"; my_reg_v.onLoading = waitLoadv; my_reg_v.onLoaded = waitLoadv; my_reg_v.onInteractive = waitLoadv; my_reg_v.onCompletion = createRegv; my_reg_v.runAJAX(); } } function waitLoadv() { objv = document.getElementById(idelv); objv.options[0] = new Option('Загрузка...','0'); var resob=document.getElementById('sel_country_v'); resob.disabled = true; } function createRegv() { objv = document.getElementById(idelv); var resob=document.getElementById('sel_country_v'); resob.disabled = false; eval(my_reg_v.response); } /* ------------------------------------------------- */ var addressbook_title; var addressbook = new Array(); var ajax = new sack(); var ob =new Object(); var all_res = 1; /* ------------------------------------------------ */ var dynamic_ab = {}; document.onclick = function (e) { if (typeof(e) == 'undefined') { // IE code e = window.event; } var obj; if (typeof(e.srcElement) != 'undefined') { obj = e.srcElement; } else if (typeof(e.target) != 'undefined') { obj = e.target; } if (typeof(obj) == 'undefined') { return; } for (var fieldname in dynamic_ab) { var ab = ab_get(fieldname); if (typeof(ab) != 'undefined') { if ((obj.id != 'dynamic_ab_'+fieldname) && (obj.id != fieldname)) { ab.hide(); } } } } function ab_keyup (field, e) { var ab = ab_get(field); switch (e.keyCode) { // action keys case 27: // Esc ab.hide(); return false; case 13: // Enter ab.insert(); return false; case 38: // Up case 40: // Down case 33: // Page Up case 34: // Page Down if (ab.is_show()) { return false; } else if (ab.found) { ab.show(); ab.movetop(); return false; } case 37: // Left case 39: // Right case 35: // End case 36: // Home return true; case 9: // Tab ab.hide(); return true; case 8: // Backspace default: ab.draw(); break; } } function ab_keydown (field, e) { var ab = ab_get(field); switch (e.keyCode) { case 27: // Esc ab.hide(); return false; case 38: // Up ab.moveup(); return false; case 40: // Down ab.movedown(); return false; case 33: // Page Up ab.movetop(); return false; case 34: // Page Down ab.movebottom(); return false; case 13: // Enter ab.insert(); return false; case 9: // Tab ab.hide(); return true; default: return true; } } function ab_keypress (field, e) { return (e.keyCode == 13) ? false : true; } function ab_click (field, e) { var ab = ab_get(field); if (ab.is_show()) { ab.hide(); } else if (ab.found) { ab.draw(); } } function ab_mouseover (field_name, index) { var ab = ab_get(field_name); ab.mouseover(index); } function ab_mouseclick (field_name, index) { var ab = ab_get(field_name); ab.insert(index); } function ab_get (field) { if (typeof(field) != 'object') { field = document.getElementById(field); } if (typeof(field.name) == 'undefined') { return false; } if (typeof(dynamic_ab[field.name]) == 'undefined') { dynamic_ab[field.name] = new AB(field); } return dynamic_ab[field.name]; } // AB object function AB (field) { this.ab = document.createElement('div'); this.ab.id = 'dynamic_ab_' + field.name; this.ab.className = 'dynamic_ab'; this.field = field; var div = document.createElement('div'); div.className = 'dynamic_ab_placeholder'; this.field.parentNode.appendChild(div); div.appendChild(this.ab); this.show = AB_show; this.hide = AB_hide; this.is_show = AB_is_show; this.draw = doit; this.select = AB_select; this.moveup = AB_moveup; this.movedown = AB_movedown; this.movetop = AB_movetop; this.movebottom = AB_movebottom; this.mouseover = AB_mouseover; this.insert = AB_insert; this.index = 0; this.search = ''; this.found = 0; this.is_drawing = false; //hidemask.length = addressbook.length; //this.items = addressbook.length; //this.hidemask = new Array(this.items); } function AB_show () { this.ab.style.display = 'block'; } function AB_hide () { this.ab.style.display = 'none'; } function AB_is_show () { return (this.ab.style.display == 'block') ? 1 : 0; } function AB_moveup () { if (this.is_show() && this.found) { var index = this.index; while (true) { index--; if (index < 0) { index = this.items - 1; } if (this.hidemask[index] == 0) { break; } } this.select(index); } } function AB_movedown () { if (this.is_show() && this.found) { var index = this.index; while (true) { index++; if (index >= this.items) { index = 0; } if (this.hidemask[index] == 0) { break; } } this.select(index); } } function AB_movetop () { if (this.is_show() && this.found) { var index = 0; while (true) { if (this.hidemask[index] == 0) { break; } index++; } this.select(index); } } function AB_movebottom () { if (this.is_show() && this.found) { var index = this.items - 1; while (true) { if (this.hidemask[index] == 0) { break; } index--; } this.select(index); } } function AB_mouseover (index) { this.select(index); } //------------------------------- function whenCompleted(){ AB_draw(ob); } function function_c(){ var a = 1; } function doit(){ ob = this; ob.index = 0; var mob; if (this.field.name=='sel_punkt_iz') { mob = document.getElementById('sel_region_iz'); } else { mob = document.getElementById('sel_region_v'); } addressbook = new Array(); ajax.encVar("zet", this.field.value); ajax.encVar("mob", mob.value); ajax.requestFile = "/ret_ar.php"; ajax.method = "GET"; ajax.execute = true; ajax.onCompletion = whenCompleted; if (this.field.value.length>3 && all_res == 1) { all_res = 0; ajax.runAJAX(); } else { AB_draw(ob); } } //------------------------------- function AB_draw (ob) { if (ob.is_drawing) { alert('busy'); return true; } // enter critical section ob.is_drawing = true; // get search pattern var search = ob.field.value; var insert_pos; if ((insert_pos = search.lastIndexOf(',')) > 0) { search = search.substr(insert_pos + 1); } search = search.replace(/^\s+/, ''); var re_space = new RegExp('\\S'); if (!re_space.test(search)) { ob.hide(); ob.search = ''; ob.found = 0; ob.is_drawing = false; return true; } if (search != this.search) { ob.search = search; var search_re = '(^|\\s|<|\\")' + search.replace(/([\\\^\$\*\+\?\{\}\.\(\)\|\[\]])/g, "\\$1"); var re = new RegExp(search_re, 'i'); var html = ''; var found = 0; ob.items = addressbook.length; ob.hidemask = new Array(this.items); // search for matches var matches = 0; for (var i in addressbook) { if (addressbook[i].search(re) != -1 && addressbook[i] != search && matches < 100) { found += 1; ob.hidemask[i] = 0; matches++; } else { ob.hidemask[i] = 1; } } ob.found = found; // select next visible matching item (if needed) if (found) { while (true) { if (ob.hidemask[ob.index] == 1) { ob.index++; if (ob.index >= this.items) { ob.index = 0; } } else { break; } } for (var i in addressbook) { if (ob.hidemask[i] == 0) { var item_html = html_escape(addressbook[i]); html += '
'+item_html+'
'; } } ob.ab.innerHTML = '
'+html+'
'+addressbook_title+':
'; ob.ab.childNodes[0].style.height = (found > 7) ? '12.8em': 'auto'; if (!ob.is_show()) { ob.show(); } } else { // hide addressbook ob.hide(); ob.ab.innerHTML = ''; } } else if (ob.found) { ob.show(); } // leave critical section ob.is_drawing = false; } function AB_select (index) { if (this.index == index) { return true; } if (index < 0 || index >= this.items) { return false; } var oldentry = document.getElementById('ab_entry_' + this.field.name + '_'+ this.index); if (typeof(oldentry) == 'object') { oldentry.className = ''; } var newentry = document.getElementById('ab_entry_' + this.field.name + '_'+ index); if (typeof(newentry) == 'object') { newentry.className = 'active'; if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Opera') == -1)) { newentry.focus(); // IE } else { newentry.childNodes[0].focus(); // Firefox } this.field.focus(); } this.index = index; return true; } function AB_insert () { if (!this.is_show()) { return false; } var value = this.field.value; var insert_pos = value.lastIndexOf(','); if (insert_pos > 0) { value = value.substr(0, insert_pos + 1); value += ' '; } else { value = ''; } value += addressbook[this.index]; this.hide(); this.index = 0; this.search = ''; this.found = 0; this.field.value = value; this.field.focus(); return true; } function html_escape (text) { var html = ''; for (var i=0; i < text.length; i++) { switch (text.charAt(i)) { case '&': html += '&'; break; case '"': html += '"'; break; case '>': html += '>'; break; case '<': html += '<'; break; case '%': html += '%'; break; case '\'': html += '''; break; default: html += text.charAt(i); break; } } return html; }