page=0; function trythese() { var returnValue; for (var i = 0, length = arguments.length; i < length; i++) { var lambda = arguments[i]; try { returnValue = lambda(); break; } catch (e) {} } return returnValue; } function AjaxUpdater(id, url, cbFunc) { var transport = trythese( function() {return new XMLHttpRequest()}, function() {return new ActiveXObject('Msxml2.XMLHTTP')}, function() {return new ActiveXObject('Microsoft.XMLHTTP')} ); if (! cbFunc) cbFunc = {}; if (transport) { transport.onreadystatechange = function() { if ((transport.readyState == 4) && (transport.status == 200)) { document.getElementById(id).innerHTML=transport.responseText; } switch (transport.readyState) { case 0: if (cbFunc.uninitialized) cbFunc.uninitialized(); break; case 1: if (cbFunc.loading) cbFunc.loading(); break; case 2: if (cbFunc.loaded) cbFunc.loaded(); break; case 3: if (cbFunc.interactive) cbFunc.interactive(); break; case 4: if (cbFunc.complete) cbFunc.complete(); break; } } transport.open("GET",url,true); transport.send(null); } } function request(url) { new AjaxUpdater("foo", url, {"loading": function () { document.getElementById('wait').innerHTML='...'; document.getElementById('wait').style.visibility = "visible"; }, "complete": function() { document.getElementById('wait').style.visibility = "hidden"; var obj; obj = document.getElementById('favurl'); if (obj) { obj.value = location.protocol+"//"+location.host+location.pathname+makequery()+"&p="+page; } }}); } function loaddefault() { new AjaxUpdater('pr', "../search/"+"sel.php?v=null", {"complete": loadchild }); if (location.search != "") { var req; req = "../search/"+"ts.php"+location.search; request(req); } } function loadchild() { var req; var obj; obj = document.getElementById('pc'); req = "../search/"+"sel.php?v="+obj.options[obj.selectedIndex].value; new AjaxUpdater("ch", req); } function makequery() { var req; var obj; obj = document.getElementById('pc'); req = "?pc="+URLencode(obj.options[obj.selectedIndex].value)+"&cc="; obj = document.getElementById('cc'); req += URLencode(obj.options[obj.selectedIndex].value)+"&q="; obj = document.getElementById('qu'); req += URLencode(obj.value); return req; } function search() { var req; req = "../search/"+"ts.php"+makequery()+"&p=0"; request(req); page=0; } function move(pc,cc,q,p) { var req; page = p; req = "../search/"+"ts.php?pc="+pc+"&cc="+cc+"&q="+q+"&p="+p; request(req); page=p; } // URLEncode function URLencode(str){ // Unicode to URL encoded UTF-8 var i, encoded_str, char_code, padded_str; encoded_str = ""; for (i = 0; i < str.length; i++){ char_code = str.charCodeAt(i); if (char_code == 0x20){ // space -> "+" encoded_str += "+";} else { // else 1 if (((0x30 <= char_code) && (char_code <= 0x39)) || ((0x41 <= char_code) && (char_code <= 0x5a)) || ((0x61 <= char_code) && (char_code <= 0x7a))){ // [0-9a-z-A-Z] // no escape encoded_str += str.charAt(i); } else if ((char_code == 0x2a) || (char_code == 0x2e) || (char_code == 0x2d) || (char_code == 0x5f)) { // [.-_] // no escape encoded_str += str.charAt(i); } else { // else 2 // for internal unicode to UTF-8 // Ref. http://homepage3.nifty.com/aokura/jscript/utf8.html // Ref. http://homepage1.nifty.com/nomenclator/unicode/ucs_utf.htm if ( char_code > 0xffff ) { encoded_str += "%" + ((char_code >> 18) | 0xf0).toString(16).toUpperCase(); encoded_str += "%" + (((char_code >> 12) & 0x3f) | 0x80).toString(16).toUpperCase(); encoded_str += "%" + (((char_code >> 6) & 0x3f) | 0x80).toString(16).toUpperCase(); encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase(); } else if ( char_code > 0x7ff ) { encoded_str += "%" + ((char_code >> 12) | 0xe0).toString(16).toUpperCase(); encoded_str += "%" + (((char_code >> 6) & 0x3f) | 0x80).toString(16).toUpperCase(); encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase(); } else if ( char_code > 0x7f ) { encoded_str += "%" + (((char_code >> 6) & 0x1f) | 0xc0).toString(16).toUpperCase(); encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase(); } else { // for ascii padded_str = "0" + char_code.toString(16).toUpperCase(); encoded_str += "%" + padded_str.substr(padded_str.length - 2, 2); } } // else 2 } // else 1 } // for return encoded_str; }