/**
* @author kriss
* @author marko
*/
var selBGColor = '#E1F5C0';
var unselBGColor = '#FFFFFF';
var selFGColor = '#3E3F41';
var unselFGColor = '#3E3F41';
var isIE  = document.all && document.all.item
var fnListOnMouseover 	= new Function();
var fnListOnMouseout  	= new Function();
var fnListOnMousedown 	= new Function();
var fnOnHintEnter 		= new Function();
var fnOnHintTab 		= new Function();
var fnOnHintDown 		= new Function();
var fnOnHintUp 			= new Function();
var iCount = 0;
function getHint(obj, event, startChr,rangeChr , url){
obj.setAttribute('blockResponse','0');
if(!event) var event = window.event;
//var objName = obj.id;
var objName = obj.getAttribute('id');
var xmlRequest = null;
var cur_div = obj.getAttribute('cur_div');
var delKey = false;
var chr = '';
var div_list = $(objName+'_o');
// div list style
obj.setAttribute("maxlength",255);
obj.setAttribute("autocomplete",'off');
if ( div_list.style.width == null || div_list.style.width.stripAllWhite() == "" ) {
div_list.style.width = obj.style.width;
}
if(event.keyCode == 8 || event.keyCode == 46) delKey = true;
if(!delKey) chr = String.fromCharCode(event.keyCode).toLowerCase();
switch(event.keyCode){
case 17: //ctrl
return;
break;
case 18: //alt
return;
break;
case 9://tab
//$('var1').value ='cur_dive='+cur_div+'len='+cur_div.length+' typeof='+ (typeof cur_div) + '  isNaN='+ isNaN(cur_div) + 'Number=' + Number(cur_div) + 'null='+ (cur_div==null?'true':'false') +'  cur_dive >=0 '+( cur_div >= 0 ? 'true' : 'false') ;
if ((isIE && typeof cur_div == 'number' && cur_div >=0) || (!isIE && cur_div !='' && div_list.childNodes[cur_div] != null) || (isIE && cur_div !='' && div_list.childNodes[cur_div] != null)){
if ( div_list.childNodes.length > 0 ) {
$(obj.id+'_key').value = div_list.childNodes[cur_div].getAttribute('a').replace(/&amp;/gi,"&");
obj.value = div_list.childNodes[cur_div].innerHTML;
obj.value = (obj.value).strip().replace(/&amp;/gi,"&");
obj.value = obj.value.replace(/<img.*>/gi, '');
hideBoxHint(obj);
try{
fnOnHintTab(obj);
}catch(e){}
}
obj.focus();
}
return;
break;
case 13://enter
if ((isIE && typeof cur_div == 'number' && cur_div >=0) || (!isIE && cur_div !='' && div_list.childNodes[cur_div] != null) || (isIE && cur_div !='' && div_list.childNodes[cur_div] != null)){
if (div_list.childNodes.length == 0) return true;
$(obj.id+'_key').value = div_list.childNodes[cur_div].getAttribute('a').replace(/&amp;/gi,"&");
obj.value = div_list.childNodes[cur_div].innerHTML;
obj.value = obj.value.strip().replace(/&amp;/gi,"&");
obj.value = obj.value.replace(/<img.*>/gi, '');
hideBoxHint(obj);
try{
fnOnHintEnter(obj);
}catch(e){}
}
//$('var1').value = cur_div;
return;
break;
case 40://down
if(div_list.childNodes.length == 0) return true;
if ((isIE && typeof cur_div == 'number' && cur_div >=0) || (!isIE && cur_div !='') || (isIE && cur_div !='')){
div_list.childNodes[cur_div].style.background = unselBGColor;
div_list.childNodes[cur_div].style.color = unselFGColor;
++cur_div;
}
if(cur_div == '' || cur_div == null) {obj.setAttribute('cur_div',0); cur_div=0;}
if( cur_div > div_list.childNodes.length - 1 ) cur_div = 0;
//$('var1').value = cur_div;
div_list.childNodes[cur_div].style.background = selBGColor;
div_list.childNodes[cur_div].style.color = selFGColor;
obj.setAttribute('cur_div',cur_div);
try{
fnOnHintDown(obj);
}catch(e){}
return;
break;
case 38://up
if(isNaN(cur_div) || cur_div == null || cur_div=='') {obj.setAttribute('cur_div',0); cur_div=0;}
if(div_list.childNodes.length==0) return true;
div_list.childNodes[cur_div].style.background=unselBGColor;
div_list.childNodes[cur_div--].style.color=unselFGColor;
if(cur_div<0) cur_div = div_list.childNodes.length - 1;
//$('var1').value = cur_div;
div_list.childNodes[cur_div].style.background=selBGColor;
div_list.childNodes[cur_div].style.color=selFGColor;
obj.setAttribute('cur_div',cur_div);
try{
fnOnHintUp(obj);
}catch(e){}
return;
break;
}
// do nothing
if(event.keyCode < 32 && event.keyCode != 8) return true;
//if(event.keyCode==27 || event.keyCode==16  || event.keyCode==35 || event.keyCode==36 || event.keyCode==37 || event.keyCode==39) return true;
// get where letters
var strTmp = (obj.value+chr).strip();
var where = '';
if (strTmp.length > startChr) where = strTmp.substr(startChr,strTmp.length);
var allowGetXml = false;
if (strTmp.length >= startChr + rangeChr) {
allowGetXml = true;
}else{
hideBoxHint(obj);
}
if((delKey && allowGetXml) || (!delKey && allowGetXml)){
try{
xmlRequest = newXMLobject();
xmlRequest.open("GET", url + encodeURIComponent(where), true);
xmlRequest.onreadystatechange = function(){
if(xmlRequest.readyState == 4){
if (xmlRequest.status != 200) {
return;
}
var divContent = '';
var nL = xmlRequest.responseXML.getElementsByTagName("hi");
if ( nL.length > 0 ) {
for(i=0;i<nL.length;i++){
if(nL[i].nodeName!='#text') {
//divContent += "<div input_name='"+ obj.id +"' "+(i==0 ? 'style=\'background:' + selBGColor + '; color:' + selFGColor + '\'' : '')+" a='"+nL[i].getAttribute('a')+"' onmousedown='fnHMouseClick(this,"+i+");' onmouseover='fnHMouseOver(this,"+i+")' onmouseout='fnHMouseOut(this,"+i+")'>" + nL[i].getAttribute('d') +"</div>";
divContent += "<div input_name='"+ obj.id +"' a='"+nL[i].getAttribute('a')+"' onmousedown='fnHMouseClick(this,"+i+");' onmouseover='fnHMouseOver(this,"+i+")' onmouseout='fnHMouseOut(this,"+i+")'>" + nL[i].getAttribute('d') +"</div>";
}
}
} else {
// BACK COMPATIBILITY WITH KAYAK
var nL = xmlRequest.responseXML.getElementsByTagName("i");
for(i=0;i<nL.length;i++){
if(nL[i].nodeName!='#text') {
try {
divContent += "<div input_name='"+ obj.id +"' a='"+nL[i].nextSibling.nextSibling.nextSibling.firstChild.nodeValue+"' onmousedown='fnHMouseClick(this,"+i+");' onmouseover='fnHMouseOver(this,"+i+")' onmouseout='fnHMouseOut(this,"+i+")'>" + nL[i].nextSibling.nextSibling.firstChild.nodeValue +"</div>";
} catch(eeee){}
}
}
// /BACK COMPATIBILITY WITH KAYAK
}
div_list.innerHTML = divContent;
if(divContent != "") {
//div_list.style.display = "block";
div_list.showDiv(false,true); //enable shim for this div
$(obj.id+'_key').value = 0;
}else{
$(obj.id+'_key').value = 0;
hideBoxHint(obj);
}
obj.setAttribute('cur_div','');
if((url.split('?')[0] == '/waynflights.html') && (div_list.getElementsByTagName('div')[0])){
fnHSelectFirst(div_list.getElementsByTagName('div')[0], 0);
}
//$('var1').value = '';
xmlRequest = null;
}
}
xmlRequest.send(null);
}catch(err){
alert('smartxml:'+err);
}
}else{
if((delKey && where.length==1) || (!delKey && where.length==0)) {
hideBoxHint(div_list.id,obj);
}
}
}
function fnHMouseOut(div, cur_div){
var obj = $(div.getAttribute('input_name'));
div.style.background = unselBGColor;
div.style.color = unselFGColor;
obj.setAttribute('cur_div','');
//$('var1').value = '';
try{
fnListOnMouseout(obj);
}catch(e){}
}
function fnHMouseOver(div, cur_div){
var obj = $(div.getAttribute('input_name'));
if (obj.getAttribute('cur_div') != null && !isNaN(obj.getAttribute('cur_div')) && obj.getAttribute('cur_div') != ''){
div.parentNode.childNodes[obj.getAttribute('cur_div')].style.background = unselBGColor;
div.parentNode.childNodes[obj.getAttribute('cur_div')].style.color = unselFGColor;
}
div.style.background = selBGColor;
div.style.color = selFGColor;
obj.setAttribute('cur_div',cur_div);
//$('var1').value = cur_div;
var div_list = div.parentNode;
$(div.getAttribute('input_name')+'_key').value = div_list.childNodes[cur_div].getAttribute('a').replace(/&amp;/gi,"&");
obj.value = div_list.childNodes[cur_div].innerHTML.replace(/&amp;/gi,"&");
obj.value = obj.value.replace(/<img.*>/gi, '');
obj.value = obj.value.strip();
try{
fnListOnMouseover(obj);
}catch(e){}
}
function fnHMouseClick(div, cur_div){
var div_list = div.parentNode;
var obj = $(div.getAttribute('input_name'));
//var objName = obj.id;
//var div_list = $(objName+'_o');
//	alert(div_list.childNodes.length);
$(div.getAttribute('input_name')+'_key').value = div_list.childNodes[cur_div].getAttribute('a').replace(/&amp;/gi,"&");
obj.value = div_list.childNodes[cur_div].innerHTML.replace(/&amp;/gi,"&");
obj.value = obj.value.replace(/<img.*>/gi, '');
obj.value = obj.value.strip();
hideBoxHint(obj);
//$('var1').value = cur_div;
try{
fnListOnMousedown(obj);
}catch(e){}
}
function hideBoxHint(obj){
try {
obj.setAttribute('blockResponse','1');
} catch(e){}
var divLName = obj.id+'_o';
if ($(divLName) != null){
divL = $(divLName);
//divL.style.display = 'none';
divL.hideDiv();
divL.innerHTML = '';
}
}
function fnHSelectFirst(div, cur_div){
var obj = $(div.getAttribute('input_name'));
if (obj.getAttribute('cur_div') != null && !isNaN(obj.getAttribute('cur_div')) && obj.getAttribute('cur_div') != ''){
div.parentNode.childNodes[obj.getAttribute('cur_div')].style.background = unselBGColor;
div.parentNode.childNodes[obj.getAttribute('cur_div')].style.color = unselFGColor;
}
div.style.background = selBGColor;
div.style.color = selFGColor;
obj.setAttribute('cur_div',cur_div);
var div_list = div.parentNode;
$(div.getAttribute('input_name')+'_key').value = div_list.childNodes[cur_div].getAttribute('a').replace(/&amp;/gi,"&");
try{
fnListOnMouseover(obj);
}catch(e){}
}
function hintOnBlur(obj){
if (obj.id == undefined){
obj = obj.inputObject
}
var cur_div = obj.getAttribute('cur_div');
var div_list = $(obj.id+'_o');
if ((isIE && typeof cur_div == 'number' && cur_div >=0) || (!isIE && cur_div !='' && div_list.childNodes[cur_div] != null) || (isIE && cur_div !='' && div_list.childNodes[cur_div] != null)){
if ( div_list.childNodes.length > 0 ) {
$(obj.id+'_key').value = div_list.childNodes[cur_div].getAttribute('a').replace(/&amp;/gi,"&");
obj.value = div_list.childNodes[cur_div].innerHTML;
obj.value = (obj.value).strip().replace(/&amp;/gi,"&");
hideBoxHint(obj);
}
}
}
