var w="";
var pa=false;
var _oldInputFieldValue=""; // inputField value (set during call to google...)...(was ta)
var da=false;
var _currentInputFieldValue=""; // also inputField value (was g)
var G="";
var _eventKeycode=""; // event keycode... (was m)
var _highlightedSuggestionIndex=-1; // currently hightlighted suggestion index (was j)
var _highlightedSuggestionDiv=null; // currently highlisted suggestion div... (was h)
var _completeDivRows=-1; // completeDiv rows at time of keypress... (was Z)
var _completeDivDivList=null; // completeDiv div list at time of keypress (was za)
var _completeDivRows2=5; // was Ca... initially 5? not sure difference between this and _completeDivRows...
var q="";
var _divTag="div"; // Was Lb
var _spanTag="span"; // Was Bb
var _documentForm=null; // Form on html page... (was la...)
var _inputField=null; // Input field on form... (was a)
var _inputFieldCC=null; // Input field on form of CountryCode... new Field
var _inputFieldCityNameEn=null; // Input field on form of city... new Field
var _completeDiv=null; // document.completeDiv (was b)
var _menuDiv=null;
var _dateDiv=null;
var _submitButton=null; // submit button (was Xa)
var mb=null;
var X=null;
var _enString=null; // This becomes the string "en" (was ha)
var _cursorUpDownPressed=false;  // Was ra...
var kc=null;
var hc=null;
var _resultCache=new Object(); // This is a cache of results from google... (was Ua)
var ca=1;
var Aa=1;
var Y=false;
var _lastKeyCode=-1; // Gets set on keyDown... Was na... 
var Va=(new Date()).getTime();
var _hasXMLHTTP=false; // Gets set to true if XMLHTTP Supported (was Q)
var _xmlHttp=null; // This is the XMLHttp Object... (was k) 
var _completeSearchEnString=null; // Gets set to "/complete/search/?hl=en" (was sa)
var _completeSearchString=null; // Gets set to "/complete/search" ... (was E)
var B=null;
var aa=null;
var Ba=false;
var Ka=false;
var p=60;
var dHideMenu = null;
var _searchString=null; // Gets set to "search" in installAC (was ia)
var ya=null;
var _timeoutAdjustment=0; // timeout adjustment... (was W)... gets adjusted over time...
var oneMinute=60*1000;
var dateDelimiter=".";

InstallAC=function(frm,fld,sb,pn,rl,hd,sm,ufn){
  _documentForm=frm;
  _inputField=fld;
  _inputFieldCC=frm.countryCode;
  _inputFieldCityNameEn=frm.city;
  _submitButton=sb;
  if(!pn) {
    pn="search";
  }
  _searchString="";
  var Kb="en|";
  var Jb="zh-CN|zh-TW|ja|ko|vi|";
  if(!rl||Kb.indexOf(rl+"|")==-1) {
    rl="en";
  }
  _enString=escapeURI(rl);
  if(Jb.indexOf(_enString+"|")==-1){
    // We won't pass through here...
    X=true;
    Y=false;
    Ba=false
  }else{
    // but will come through here...
    X=false;
    if(_enString.indexOf("zh")==0) {
      // not here...
      Y=false;
    } else {
      // but here...
      Y=true;
    }
    Ba=true
  }
  // hd is not defined, so becomes false...
  if(!hd) {
    hd=false;
  }
  ya=hd;

  // sm not defined, so becomes the string "query"
  if(!sm) {
    sm="query";
  }
  w=sm;

  // ufn is not defined...
  mb=ufn;

  installACPartTwo()
}

// blurs focus, then sets focus again... 
// This is getting aclled when we press cursor up / cursor down...
// Was Yb...
function blurThenGetFocus(){
  _cursorUpDownPressed=true;
  _inputField.blur();
  setTimeout("setInputFieldFocus();",10);
  return
}

// setup a keydown event...
// Was Fb...
function setupKeydown1(){
/*
  if(document.createEventObject) {
    var y=document.createEventObject();
    y.ctrlKey=true;
    y.keyCode=70;
    document.fireEvent("onkeydown",y)
  }
  */
}

// Was Pb
function keyDownHandler(event){
	if(!event&&window.event) {
    event=window.event;
  }
  if(event) {
    _lastKeyCode=event.keyCode;
  }

  // We are backspacing here...
  if(event&&event.keyCode==8){
    if(X&&(_inputField.createTextRange&&(event.srcElement==_inputField&&(bb(_inputField)==0&&lb(_inputField)==0)))){
      cc(_inputField);
      event.cancelBubble=true;
      event.returnValue=false;
      return false
    }
  }
}

// Was Db..
function resizeHandler(){
  if(w=="url"){
    setInputFieldSize()
  }
  setCompleteDivSize(_completeDiv, _inputField)
}

// was ba...
function setCompleteDivSize(_completeDiv, _inputField, width){
  if(_completeDiv){
    _completeDiv.style.left=calculateOffsetLeft(_inputField)+"px";
    _completeDiv.style.top=calculateOffsetTop(_inputField)+_inputField.offsetHeight-1+"px";
		if (width==0)
			_completeDiv.style.width=calculateWidth()+"px"
		else
			_completeDiv.style.width=width
  }
}
// calculate width of inputField... Note browser specific adjustments...
// Was Ja()
function calculateWidth(){
  if(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1){
    return _inputField.offsetWidth-ca*2
  }else{
    return _inputField.offsetWidth
  }
}


// Called from InstallAC...
// was ac()
function installACPartTwo(){
	
  if(getXMLHTTP()){
    _hasXMLHTTP=true
  }else{
    _hasXMLHTTP=false
  }
//	_hasXMLHTTP=false;

  // pa init'd to false at the top of this file...
  if(pa) {
    _completeSearchString="complete";
  } else {
    _completeSearchString="/newDes/getCities.php"+_searchString;
  }

  _completeSearchEnString=_completeSearchString+"?hl="+_enString;
	_completeSearchEnString="/newDes/getCities.php"

  if(!_hasXMLHTTP){
    setCookie("qu","",0,_completeSearchString,null,null)
  }

  _documentForm.onsubmit=Fa;
  /*
  _inputField.autocomplete="off";
  _inputField.onblur=onBlurHandler;
  if(_inputField.createTextRange) {
    _inputField.onkeyup=new Function("return okuh(event);");
  } else {
    _inputField.onkeyup=okuh;
  }
  */
  _inputField.onsubmit=Fa;
  _currentInputFieldValue=_inputField.value;
  _oldInputFieldValue=_currentInputFieldValue;
  _completeDiv=document.createElement("DIV");
  _completeDiv.id="completeDiv";
  ca=1;
  Aa=1;
  _completeDiv.style.borderRight="black "+ca+"px solid";
  _completeDiv.style.borderLeft="black "+ca+"px solid";
  _completeDiv.style.borderTop="black "+Aa+"px solid";
  _completeDiv.style.borderBottom="black "+Aa+"px solid";
  _completeDiv.style.zIndex="1";
  _completeDiv.style.paddingRight="0";
  _completeDiv.style.paddingLeft="0";
  _completeDiv.style.paddingTop="0";
  _completeDiv.style.paddingBottom="0";
  setCompleteDivSize(_completeDiv, _inputField, 0);
  _completeDiv.style.visibility="hidden";
  _completeDiv.style.position="absolute";
  _completeDiv.style.backgroundColor="white";
//	_completeDiv.innerHTML="<p>Test test test test</p>";
  document.body.appendChild(_completeDiv);
  cacheResults("",new Array(),new Array());
  Gb(_completeDiv);
		
_dateDiv=document.createElement("DIV");
  _dateDiv.id="dateDiv";
  _dateDiv.style.zIndex="1";
  setCompleteDivSize(_dateDiv, document.f.date, "139px");
  _dateDiv.style.visibility="hidden";
  _dateDiv.style.position="absolute";
	_dateDiv.style.height="153px";
	_dateDiv.innerHTML=getCal((new Date()));
	
  document.body.appendChild(_dateDiv);
	
//  Gb(_dateDiv);
	
	_nightsDiv=document.createElement("DIV");
 	_nightsDiv.id="nightsDiv";
 	_nightsDiv.style.zIndex="1";
 	setCompleteDivSize(_nightsDiv, document.f.nights, "40px");
	_nightsDiv.style.visibility="hidden";
 	_nightsDiv.style.position="absolute";
	_nightsDiv.style.height="153px";
	_nightsDiv.style.overflowY="auto";
	_nightsDiv.innerHTML=getNights();
	
  document.body.appendChild(_nightsDiv);
//  Gb(_nightsDiv);
	
	_adultsDiv=document.createElement("DIV");
  _adultsDiv.id="adultsDiv";
  _adultsDiv.style.zIndex="1";
  setCompleteDivSize(_adultsDiv, document.f.NumberOfAdults, "25px");
  _adultsDiv.style.visibility="hidden";
  _adultsDiv.style.position="absolute";
	_adultsDiv.style.height="153px";
	_adultsDiv.innerHTML=getAdults();
	
  document.body.appendChild(_adultsDiv);
//  Gb(_adultsDiv);

	_menuDiv=document.getElementById("menuDiv");
	setCompleteDivSize(_menuDiv, document.getElementById("menuHREF"), "139px");
	
  var s=document.createElement("DIV");
  s.style.visibility="hidden";
  s.style.position="absolute";
  s.style.left="-100";
  s.style.top="-100";
  s.style.width="0";
  s.style.height="0";
  /*var M=document.createElement("IFRAME");
  M.completeDiv=_completeDiv;
  M.name="completionFrame";
  M.id="completionFrame";
  M.src=_completeSearchEnString;
  s.appendChild(M);*/
  document.body.appendChild(s);
  if(frames&&(frames["completionFrame"]&&frames["completionFrame"].frameElement)) {
    B=frames["completionFrame"].frameElement;
  } else {
    B=document.getElementById("completionFrame");
  }
  if(w=="url"){
    setInputFieldSize();
    setCompleteDivSize();
  }
  window.onresize=resizeHandler;
//document.onkeydown=keyDownHandler;
//	document.onclick=clickHandler;
	_inputField.onClick=clearInput;
  //setupKeydown1()
}

// Was Ob
function onBlurHandler(event){
  if(!event&&window.event) {
    event=window.event;
  }
  if(!_cursorUpDownPressed){
    hideCompleteDiv();
    // check if tab pressed...
    if(_lastKeyCode==9){
      setSubmitButtonFocus();
      _lastKeyCode=-1
    }
  }
  _cursorUpDownPressed=false
}

function okuh(e){
  _eventKeycode=e.keyCode;
  aa=_inputField.value;
  Oa()
}
// Was Xb...
function setSubmitButtonFocus(){
  _submitButton.focus()
}

// Was sfi..
function setInputFieldFocus(){
  _inputField.focus()
}
;

// strip CR from string...
// was Wb
function stripCRFromString(va){
  for(var f=0,oa="",zb="\n\r"; f<va.length; f++) {
    if (zb.indexOf(va.charAt(f))==-1) {
      oa+=va.charAt(f);
    } else {
      oa+=" ";
    }
  }
return oa
}

// Find span value with className = dc...
// Was Qa
function findSpanValueForClass(i,dc){
  var ga=i.getElementsByTagName(_spanTag);
  if(ga){
    for(var f=0; f<ga.length; ++f){
      if(ga[f].className==dc){
        var value=ga[f].innerHTML;
        if(value=="&nbsp;") {
          return"";
        } else{
          var z=stripCRFromString(value);
          return z
        }
      }
    }
  }else{
    return""
  }
}

// Return null if i undefined...
// otherwise return value of span cAutoComplete...
// was U
function valueOfCAutoComplete(i){
  if(!i) {
    return null;
  }
  return findSpanValueForClass(i,"cAutoComplete")
}

// function get value of span codeAutoComplete
function valueOfCodeAutoComplete(i){
  if(!i) {
    return null;
  }
  return findSpanValueForClass(i,"codeAutoComplete")
}
// function get value of span cityEnAutoComplete
function valueOfCityEnAutoComplete(i){
  if(!i) {
    return null;
  }
  return findSpanValueForClass(i,"cityEnAutoComplete")
}
// Return null if i undefined...
// otherwise return value of span dAutoComplete...
// was wa
function valueOfDAutoComplete(i){
  if(!i) {
    return null;
  }
  return findSpanValueForClass(i,"dAutoComplete")
}

// Was F
function hideCompleteDiv(){
  document.getElementById("completeDiv").style.visibility="hidden"
}
// Was cb
function showCompleteDiv(){
  document.getElementById("completeDiv").style.visibility="visible";
  setCompleteDivSize()
}

// This is a result caching mechanism...
// was Ma
function cacheResults(is,cs,ds){
  _resultCache[is]=new Array(cs,ds)
}

// We get the following javascript code dynamically returned from google:
// sendRPCDone(frameElement, "fast bug", new Array("fast bug track", "fast bugs", "fast bug", "fast bugtrack"), new Array("793,000 results", "2,040,000 results", "6,000,000 results", "7,910 results"), new Array(""));
function sendRPCDone(fr,is,cs,ds,pr,cc, cityEn)
{
  if(_timeoutAdjustment > 0) 
  {
    _timeoutAdjustment--;
  }
  var lc = (new Date()).getTime();
  if(!fr) 
  {
    fr = B;
  }
  cacheResults(is,cs,ds);
  var b = fr.completeDiv;
  b.completeStrings = cs;
  b.displayStrings = ds;
  b.prefixStrings = pr;
  b.countryCodes = cc;
  b.cityNames = cityEn;
  displaySuggestedList(b, b.completeStrings, b.displayStrings, b.countryCodes, b.cityNames);
  Pa(b, valueOfCAutoComplete);
  if(_completeDivRows2 > 0) 
  {
    b.height = 16 * _completeDivRows2 + 4;
  } 
  else 
  {
    hideCompleteDiv();
  }
}

function Oa(){
  // 38 is up cursor key, 40 is down cursor key...
  if(_eventKeycode==40||_eventKeycode==38) {
    blurThenGetFocus();
  }
  var N=lb(_inputField);
  var v=bb(_inputField);
  var V=_inputField.value;
  if(X&&_eventKeycode!=0){
    if(N>0&&v!=-1) {
      V=V.substring(0,v);
    } 
    if(_eventKeycode==13||_eventKeycode==3){ 
      var d=_inputField; 
      if(d.createTextRange){
        var t=d.createTextRange();
        t.moveStart("character",d.value.length);
        t.select()
      } else if (d.setSelectionRange){
        d.setSelectionRange(d.value.length,d.value.length)
      }
			da=true;
			hideCompleteDiv();
    } else { 
      if(_inputField.value!=V) {
        selectEntry(V)
      }
    }
  }
  _currentInputFieldValue=V;
  if(handleCursorUpDownEnter(_eventKeycode)&&_eventKeycode!=0) { 
    Pa(_completeDiv,valueOfCAutoComplete)
  }
}

function Fa(){
  return xb(w)
}

function xb(eb) {
  da=true;
  if(!_hasXMLHTTP){
    setCookie("qu","",0,_completeSearchString,null,null)
  }
  hideCompleteDiv();
	if(_lastKeyCode==13) {
		return false;
	}
  if(eb=="url"){
    var R="";
    if(_highlightedSuggestionIndex!=-1&&h) {
      R=valueOfCAutoComplete(_highlightedSuggestionDiv);
    }
    if(R=="") {
      R=_inputField.value;
    }
    if(q=="") { 
      document.title=R;
    } else {
      document.title=q;
    }
    var Tb="window.frames['"+mb+"'].location = \""+R+'";';
    setTimeout(Tb,10);
    return false
  }
}

// Go read about encodeURIComponent here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsmthencodeuricomponent.asp
// Basically converts a string to a valid uri... (spaces become %20, etc, etc..)
// this function was nb...
function escapeURI(La){
  var cirSymbols = new Array()
	var tempStr = "";
	cirSymbols.�="%A8";
	cirSymbols.�="%C9";
	cirSymbols.�="%D6";
	cirSymbols.�="%D3";
	cirSymbols.�="%CA";
	cirSymbols.�="%C5";
	cirSymbols.�="%CD";
	cirSymbols.�="%C3";
	cirSymbols.�="%D8";
	cirSymbols.�="%D9";
	cirSymbols.�="%C7";
	cirSymbols.�="%D5";
	cirSymbols.�="%DA";
	cirSymbols.�="%D4";
	cirSymbols.�="%DB";
	cirSymbols.�="%C2";
	cirSymbols.�="%C0";
	cirSymbols.�="%CF";
	cirSymbols.�="%D0";
	cirSymbols.�="%CE";
	cirSymbols.�="%CB";
	cirSymbols.�="%C4";
	cirSymbols.�="%C6";
	cirSymbols.�="%DD";
	cirSymbols.�="%DF";
	cirSymbols.�="%D7";
	cirSymbols.�="%D1";
	cirSymbols.�="%CC";
	cirSymbols.�="%C8";
	cirSymbols.�="%D2";
	cirSymbols.�="%DC";
	cirSymbols.�="%C1";
	cirSymbols.�="%DE";
	cirSymbols.�="%B8";
	cirSymbols.�="%E9";
	cirSymbols.�="%F6";
	cirSymbols.�="%F3";
	cirSymbols.�="%EA";
	cirSymbols.�="%E5";
	cirSymbols.�="%ED";
	cirSymbols.�="%E3";
	cirSymbols.�="%F8";
	cirSymbols.�="%F9";
	cirSymbols.�="%E7";
	cirSymbols.�="%F5";
	cirSymbols.�="%FA";
	cirSymbols.�="%F4";
	cirSymbols.�="%FB";
	cirSymbols.�="%E2";
	cirSymbols.�="%E0";
	cirSymbols.�="%EF";
	cirSymbols.�="%F0";
	cirSymbols.�="%EE";
	cirSymbols.�="%EB";
	cirSymbols.�="%E4";
	cirSymbols.�="%E6";
	cirSymbols.�="%FD";
	cirSymbols.�="%FF";
	cirSymbols.�="%F7";
	cirSymbols.�="%F1";
	cirSymbols.�="%EC";
	cirSymbols.�="%E8";
	cirSymbols.�="%F2";
	cirSymbols.�="%FC";
	cirSymbols.�="%E1";
	cirSymbols.�="%FE";
	//	alert(La.length);
	for (i=0; i<La.length; i++) {
//		alert(cirSymbols[La.charAt(i)]);
		if (cirSymbols[La.charAt(i)])
			tempStr+=cirSymbols[La.charAt(i)]
		else
			tempStr+=La.charAt(i)
	}
	return tempStr;
}


// Was yb
// If Mb is 0, will return 150...
// If Mb is 3, will return 250...
// If Mb is 4, will return 450...
// If Mb is X, will return 850...
function recalculateTimeout(Mb){
  var H=100;
  for(var o=1; o<=(Mb-2)/2; o++){
    H=H*2
  }
  H=H+50;
  return H
}

// This function sets itself up and gets called over and over (timeout driven)
// was idfn...
function mainLoop(){
/*
  if(_oldInputFieldValue!=_currentInputFieldValue){
    if(!da){
      var Za=escapeURI(_currentInputFieldValue);
      var ma=_resultCache[_currentInputFieldValue];
      if(ma){
        // Found in our cache...
        Va=-1;
        sendRPCDone(B,_currentInputFieldValue,ma[0],ma[1],B.completeDiv.prefixStrings, B.completeDiv.countryCodes, B.completeDiv.cityNames)
      }else{
        _timeoutAdjustment++;
        Va=(new Date()).getTime();
        if(_hasXMLHTTP){
          callGoogle(Za)
        }else{
          setCookie("qu",Za,null,_completeSearchString,null,null);
          frames["completionFrame"].document.location.reload(true)
        }
      }
      _inputField.focus()
    }
    da=false
  }
	_oldInputFieldValue=_currentInputFieldValue;
	setTimeout("mainLoop()",recalculateTimeout(_timeoutAdjustment));
	return true;
	*/
}
// Call mainLoop() after 10 milliseconds...
//setTimeout("mainLoop()",10);

// This is onMouseDown function...
function Cb(){
  selectEntry(valueOfCAutoComplete(this));
  setCountryCode(valueOfCodeAutoComplete(this));
  setCityNameEn(valueOfCityEnAutoComplete(this));
  q=valueOfDAutoComplete(this);
  da=true;
//  Fa()
}

// on mouseover...
function pb(){
  if(_highlightedSuggestionDiv) {
    setStyleForElement(_highlightedSuggestionDiv,"aAutoComplete");
  }
  setStyleForElement(this,"bAutoComplete")
}

// On Mouse out...
function ec(){
  setStyleForElement(this,"aAutoComplete")
}

// Called when cursor up/down pressed... selects new entry in completeDiv...
// was Na
function highlightNewValue(C){
  _currentInputFieldValue=G;
  selectEntry(G);
  q=G;
  if(!_completeDivDivList||_completeDivRows<=0) {
    return;
  }
  showCompleteDiv();
  if(C>=_completeDivRows){
    C=_completeDivRows-1
  }
  if(_highlightedSuggestionIndex!=-1&&C!=_highlightedSuggestionIndex){
    setStyleForElement(_highlightedSuggestionDiv,"aAutoComplete"); 
    _highlightedSuggestionIndex=-1
  }
  if(C<0){
    _highlightedSuggestionIndex=-1;
    _inputField.focus();
    return
  }
  _highlightedSuggestionIndex=C;
  _highlightedSuggestionDiv=_completeDivDivList.item(C);
  setStyleForElement(_highlightedSuggestionDiv,"bAutoComplete");
  _currentInputFieldValue=G;
  q=valueOfDAutoComplete(_highlightedSuggestionDiv);
  selectEntry(valueOfCAutoComplete(_highlightedSuggestionDiv));
  setCountryCode(valueOfCodeAutoComplete(_highlightedSuggestionDiv));
  setCityNameEn(valueOfCityEnAutoComplete(_highlightedSuggestionDiv));
}

// Was Eb
// returns false if cursor up / cursor down or enter pressed...
function handleCursorUpDownEnter(eventCode){
  if(eventCode==40){
    highlightNewValue(_highlightedSuggestionIndex+1);
    return false
  }else if(eventCode==38){
    highlightNewValue(_highlightedSuggestionIndex-1);
    return false
  }else if(eventCode==13||eventCode==3){
    return false
  }
  return true
}

// Pa(completeDiv,H)
// This function gets called for every keypress I make...
function Pa(localCompleteDiv,ib){
  var localInputField=_inputField;
  var T=false;
  _highlightedSuggestionIndex=-1;
  // This becomes the rows in our suggestion list...
  var J=localCompleteDiv.getElementsByTagName(_divTag);
  // # of rows in list...
  var O=J.length;
  _completeDivRows=O;
  _completeDivDivList=J;
  _completeDivRows2=O;
  G=_currentInputFieldValue;
  if(_currentInputFieldValue==""||O==0){
    hideCompleteDiv()
  }else{
    showCompleteDiv()
  }
  var Ab="";
  if(_currentInputFieldValue.length>0){
    var f;
    var o;
    // My prefixStrings was always an empty array...
    // So local variable T never would be set to true...
    // And the local variable Ab would remain empty...
    for(var f=0; f<O; f++){
      for(o=0; o<localCompleteDiv.prefixStrings.length; o++){
        var Ib=localCompleteDiv.prefixStrings[o]+_currentInputFieldValue;
        if(Y||ib(J.item(f)).toUpperCase().indexOf(Ib.toUpperCase())==0) {
          Ab=localCompleteDiv.prefixStrings[o]; 
          T=true; 
          break
        }
      }
      if(T){
        break
      }
    }
  }
  if(T) {
    _highlightedSuggestionIndex=f;
  }
  for(var f=0; f<O; f++) {
    setStyleForElement(J.item(f),"aAutoComplete");
  }
  if(T){
    _highlightedSuggestionDiv=J.item(_highlightedSuggestionIndex);
    q=valueOfDAutoComplete(_highlightedSuggestionDiv)
  }else{
    q=_currentInputFieldValue;
    _highlightedSuggestionIndex=-1;
    _highlightedSuggestionDiv=null
  }
  var ab=false;
  switch(_eventKeycode){
    // cursor left, cursor right, others??
    case 8:
    case 33:
    case 34:
    case 35:
    case 35:
    case 36:
    case 37:
    case 39:
    case 45:
    case 46:
      ab=true;
      break;
    default:
      // regular keypress ...
      break
  }
//  alert("ab: " + ab);
  if(!ab&&_highlightedSuggestionDiv){
    var Da=_currentInputFieldValue;
    setStyleForElement(_highlightedSuggestionDiv,"bAutoComplete");
    var z;
    if(T) {
      z=ib(_highlightedSuggestionDiv).substr(localCompleteDiv.prefixStrings[o].length);
    } else {
      z=Da;
    }
    if(z!=localInputField.value){
      if(localInputField.value!=_currentInputFieldValue) {
        return;
      }
      if(X){
        if(localInputField.createTextRange||localInputField.setSelectionRange) {
          selectEntry(z);
        }
        if(localInputField.createTextRange){
          var t=localInputField.createTextRange();
          t.moveStart("character",Da.length);
          t.select()
        }else if(localInputField.setSelectionRange){
          localInputField.setSelectionRange(Da.length,localInputField.value.length)
        }
      }
    }
  }else{
    _highlightedSuggestionIndex=-1;
    q=_currentInputFieldValue
  }
}

// Called as:
// calculateOffsetLeft(_inputField)
// was ob
function calculateOffsetLeft(r){
  return Ya(r,"offsetLeft")
}

// Called as:
// calculateOffsetTop(_inputField)
// Was Qb...
function calculateOffsetTop(r){
  return Ya(r,"offsetTop")
}

function Ya(r,attr){
  var kb=0;
  while(r){
    kb+=r[attr]; 
    r=r.offsetParent
  }
  return kb
}

// Sets cookie...
// (was called qa...)
function setCookie(name,value,Ra,hb,fb,Sb){
  var Nb=name+"="+value+(Ra?";expires="+Ra.toGMTString():"")+(hb?";path="+hb:"")+(fb?";domain="+fb:"")+(Sb?";secure":"");
  document.cookie=Nb
}

// Was Ha
function setInputFieldSize(){
  var xa=document.body.scrollWidth-220;
  xa=0.73*xa;
  _inputField.size=Math.floor(xa/6.18)
}
function lb(n){
  var N=-1;
  if(n.createTextRange){
    var fa=document.selection.createRange().duplicate();
    N=fa.text.length
  }else if(n.setSelectionRange){
    N=n.selectionEnd-n.selectionStart
  }
  return N
}

function bb(n){
  var v=0;
  if(n.createTextRange){
    var fa=document.selection.createRange().duplicate();
    fa.moveEnd("textedit",1);
    v=n.value.length-fa.text.length
  }else if(n.setSelectionRange){
    v=n.selectionStart
  }else{
    v=-1
  }
  return v
}
function cc(d){
  if(d.createTextRange){
    var t=d.createTextRange();
    t.moveStart("character",d.value.length);
    t.select() 
  } else if(d.setSelectionRange) {
    d.setSelectionRange(d.value.length,d.value.length)
  }
}

function jc(Zb,Ea){
  if(!Ea)Ea=1;
  if(pa&&pa<=Ea){
    var Ia=document.createElement("DIV");
    Ia.innerHTML=Zb;
    document.getElementById("console").appendChild(Ia)
  }
}

// Ex: setStyleForElement(document.createElement("DIV"), "aAutoComplete");
// was l
function setStyleForElement(c,name){
  db();
  c.className=name;
  if(Ka){
    return
  }
  switch(name.charAt(0)){
    case "m":
      c.style.fontSize="13px";
      c.style.fontFamily="arial,sans-serif";
      c.style.wordWrap="break-word";
      break;
    case "l":
      c.style.display="block";
      c.style.paddingLeft="3";
      c.style.paddingRight="3";
      c.style.height="16px";
      c.style.overflow="hidden";
      break;
    case "a":
      c.style.backgroundColor="white";
      c.style.color="black";
      if(c.displaySpan){
        c.displaySpan.style.color="green"
      }
      break;
    case "b":
      c.style.backgroundColor="#3366cc";
      c.style.color="white";
      if(c.displaySpan){
        c.displaySpan.style.color="white"
      }
      break;
    case "c":
      c.style.width=p+"%";
      c.style.cssFloat="left";
      break;
    case "d":
      c.style.cssFloat="right";
      c.style.width=100-p+"%";
      if(w=="query"){
        c.style.fontSize="10px";
        c.style.textAlign="right";
        c.style.color="green";
        c.style.paddingTop="3px"
      }else{
        c.style.color="#696969"
      }
      break
  }
}

function db(){
  p=65;
  if(w=="query"){
    var wb=110;
    var Sa=calculateWidth();
    var tb=(Sa-wb)/Sa*100;
    p=tb
  }else{
    p=65
  }
  if(ya){
    p=99.99
  }
}
function Gb(i){
  db();
  var Ub="font-size: 13px; font-family: arial,sans-serif; word-wrap:break-word; ";
  var Vb="display: block; padding-left: 3; padding-right: 3; height: 16px; overflow: hidden; ";
  var bc="background-color: white; ";
  var qb="background-color: #3366cc; color: white ! important; ";
  var ub="display: block; margin-left: 0%; width: "+p+"%; float: left; ";
  var Ga="display: block; margin-left: "+p+"%; ";
  if(w=="query"){
    Ga+="font-size: 10px; text-align: right; color: green; padding-top: 3px; "
  }else{
    Ga+="color: #696969; "
  }
  D(".mAutoComplete",Ub);
  D(".lAutoComplete",Vb);
  D(".aAutoComplete *",bc);
  D(".bAutoComplete *",qb);
  D(".cAutoComplete",ub);
  D(".dAutoComplete",Ga);
  setStyleForElement(i,"mAutoComplete")
}

// Called from sendRPCResponse...
// i = fr.completeDiv
// cs = list of comlete strings...
// Hb = list of results...
// was rb
function displaySuggestedList(i,cs,Hb,cc, cityEn){
  while(i.childNodes.length>0) {
    i.removeChild(i.childNodes[0]);
  }
  // For each element in our list, we create:
  // <DIV (u) - mousedown/mouseover/mouseout aAutoComplete>
  //   <SPAN (ka) lAutoComplete>
  //     <SPAN (ua) cAutoComplete>
  //        bug tracking
  //     </SPAN (ua)>
  //     <SPAN (ea) dAutoComplete>
  //        500,000 results
  //     </SPAN (ea)>
  //     <SPAN (ca) codeAutoComplete>
  //        countriesCode
  //     </SPAN (ca)>
  //     <SPAN (cen) cityEnAutoComplete>
  //        cityNameEn
  //     </SPAN (cen)>
  //   </SPAN (ka)>
  // </DIV (u)>
  for(var f=0; f<cs.length; ++f){
    var u=document.createElement("DIV");
    setStyleForElement(u,"aAutoComplete");
    u.onmousedown=Cb;
    u.onmouseover=pb;
    u.onmouseout=ec;
    var ka=document.createElement("SPAN");
    setStyleForElement(ka,"lAutoComplete");
    var ua=document.createElement("SPAN");
    ua.innerHTML=cs[f]; // the text for the suggested result...
    var ea=document.createElement("SPAN");
    setStyleForElement(ea,"dAutoComplete");
    setStyleForElement(ua,"cAutoComplete");
    u.displaySpan=ea;
    if(!ya) {
      ea.innerHTML=Hb[f]; // the text for # results for suggested result...
    }
    var ca=document.createElement("SPAN");
    setStyleForElement(ca,"codeAutoComplete");
    ca.innerHTML=cc[f]; 

    var cen = document.createElement("SPAN");
    setStyleForElement(cen,"cityEnAutoComplete");
    cen.innerHTML=cityEn[f]; 
    ka.appendChild(ua);
    ka.appendChild(ea);
    ka.appendChild(ca);
    ka.appendChild(cen);
    u.appendChild(ka);
    i.appendChild(u)
  }
}

function D(name,gb){
  if(Ka){
    var I=document.styleSheets[0];
    if(I.addRule){
      I.addRule(name,gb)
    }else if(I.insertRule){
      I.insertRule(name+" { "+gb+" }",I.cssRules.length)
    }
  }
}

// Was function jb...
// returns an XMLHttp object... gets it in an IE/Mozilla friendly way..
function getXMLHTTP(){
  var A=null;
  try{
    A=new ActiveXObject("Msxml2.XMLHTTP")
  }catch(e){
    try{
      A=new ActiveXObject("Microsoft.XMLHTTP")
    } catch(oc){
      A=null
    }
  }
  if(!A && typeof XMLHttpRequest != "undefined") {
    A=new XMLHttpRequest()
  }
  return A
}

// This function uses the xmlHttp object to send a message back to google...
// This is the primary function that dynamically communicates with google.
// was fc
// This is the call:
// http://www.google.com/complete/search?hl=en&js=true&qu=fast%20bug
// And we get back:
// sendRPCDone(frameElement, "fast bug", new Array("fast bug track", "fast bugs", "fast bug", "fast bugtrack"), new Array("793,000 results", "2,040,000 results", "6,000,000 results", "7,910 results"), new Array(""));
function callGoogle(Rb){
  if(_xmlHttp&&_xmlHttp.readyState!=0){
    _xmlHttp.abort()
  }
  _xmlHttp=getXMLHTTP();
  if(_xmlHttp){
    // We end up calling:
    // /complete/search?hl=en&js=true&qu=<my query string...> ... 
//	alert (_completeSearchEnString+"?q="+Rb);
  _xmlHttp.open("GET",_completeSearchEnString+"?j=true&q="+Rb,true);
//	_xmlHttp.open("GET","/test1.html",true);
    // Note that this function will ONLY be called when we get a complete
    // response back from google!!
    _xmlHttp.onreadystatechange=function() {
      if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
        var frameElement=B;
        if(_xmlHttp.responseText.charAt(0)=="<"){
          _timeoutAdjustment--
        }else{
          // The response text gets executed as javascript... 
//					alert(_xmlHttp.responseText);
          eval(_xmlHttp.responseText)
        }
      }
    }
    ;
    // DON'T TRY TO TALK WHEN WE'RE LOCAL...
    // Comment out when running from a local file...
    _xmlHttp.send(null)
  }
}

// Select suggested entry...
// wa is the value to set the inputfield to...
// was S
function selectEntry(Wa){
  _inputField.value=Wa;
  aa=Wa
}

function showMenu() {
	//document.getElementById("completeDiv").style.visibility="visible";
	
	if (_menuDiv.style.visibility!='visible') {
		setOpacity("menuDiv", 0);
		_menuDiv.style.display = "block";
		_menuDiv.style.visibility = 'visible';
		fadeInMyPopup("menuDiv");
	}
}

function hideMenu() {
	fadeOutMyPopup("menuDiv");
	setTimeout('closeMenu()', 800);
	return false;
}

function closeMenu() {
	_menuDiv.style.visibility = 'hidden';
	_menuDiv.style.display = 'none';
}

function getCal(date) {
	var monthArray = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var weekDayArray = new Array ("Mn", "Tu", "Am", "Th", "Fr", "St", "Su");
	var firstDayWeek = new Array (6,0,1,2,3,4,5)
	var j = 1;
	var stop = true;
	var today = new Date()
	var year = today.getFullYear()+1;
	var yearNum = date.getFullYear();
	
	monthNum = date.getMonth();
	firstDayWeekDay = date;
	firstDayWeekDay.setDate(1);
	firstDayWeekDay = firstDayWeek[firstDayWeekDay.getDay()];
	lastDay = date;
	lastDay.setDate(1);
	if (monthNum==11) {
		lastDay.setMonth(0);
		lastDay.setYear(lastDay.getYear()+1);
	}
	else
		lastDay.setMonth(lastDay.getMonth()+1);
	lastDay.setHours(0);
	lastDay.setMinutes(0);
	lastDay.setSeconds(0);
	lastDay.setTime(lastDay.getTime()-60*1000*60*24);
	lastDay = lastDay.getDate();

	tempCal="<table width='136' align='center' cellpadding='2' cellspacing='0' bgcolor='#315D9C'><tr align='center'><td height='22' colspan='7'><select style='width: 100%;' name='mn' id='arrivalMonth' onChange='changeCal();' >";
	for (i=0; i<=11; i++) {
		if (i==today.getMonth())
			year--
		if (monthNum == i)
			selected = "selected=selected"
		else
			selected = "";
		tempCal+="<option value='"+(i)+"'"+selected+" onchange='changeCal("+i+")'>"+monthArray[i]+" "+year+"</option>"
	}
	tempCal+="</td></tr><tr align='center'>";
	for (i=0; i<=6; i++) {
		tempCal+="<td width='22' height='22'><b class='wite'>"+weekDayArray[i]+"</b></td>"
	}
	tempCal+="</tr><tr align='center'>";
	i=0;
	while (stop) {
		if ((i<firstDayWeekDay) || (j>lastDay))
			tempCal+="<td class='day'>&nbsp;</td>";
		else {
			if (monthNum==today.getMonth())
				if (j==today.getDate())
					tempCal+="<td class='day_s'><a href='' onClick='setDate(\""+convertDate(j)+dateDelimiter+convertDate((monthNum+1))+dateDelimiter+yearNum+"\"); return false;' class='s_day'>"+j+"</a></td>";
				else
					if (j<today.getDate())
						tempCal+="<td class='day1'>"+j+"</td>";
					else
						tempCal+="<td class='day'><a href='' onClick='setDate(\""+convertDate(j)+dateDelimiter+convertDate((monthNum+1))+dateDelimiter+yearNum+"\"); return false;' class='today1'>"+j+"</a></td>";
			else
				tempCal+="<td class='day'><a href='' onClick='setDate(\""+convertDate(j)+dateDelimiter+convertDate((monthNum+1))+dateDelimiter+yearNum+"\"); return false;' class='today1'>"+j+"</a></td>";
			j++;
		}
		if ((i+1)%7 == 0)
			tempCal+="</tr><tr align='center'>";
		if ((j>lastDay) && ((i+1)%7 == 0))
			stop=false;
		i++;
	}
	
	tempCal+=";";
	tempCal=tempCal.replace("</tr><tr align='center'>;","</tr>");
	tempCal+="<tr align='left'><td height='22' colspan='7'><a href='' class='today' onClick='setDate(\""+convertDate(today.getDate())+dateDelimiter+convertDate((today.getMonth()+1))+dateDelimiter+today.getFullYear()+"\");return false;'>today</a></td></tr></table>";
	return tempCal;
}

function convertDate(dateStr)
{
	if (dateStr.toString().length == 1)
		dateStr = "0" + dateStr;
	return dateStr;
}

function getNights(nights) {
	var tempNights = "<table width='25' align='center' cellpadding='2' cellspacing='0' bgcolor='#315D9C'>";
	for (i=1; i<=30; i++) {
		if (i==parseInt(nights))
			tempNights+="<tr align='center'><td width='22' class='day_s'><a href='' class='s_day' onClick='setNights("+i+"); return false;'>"+i+"</a></td></td></tr>";
		else
			tempNights+="<tr align='center'><td width='22' class='day'><a href='' class='today1' onClick='setNights("+i+"); return false;'>"+i+"</a></td></tr>";
	}
	tempNights+="</table>";
	return tempNights;
}

function getAdults(adults) {
	var tempAdults = "<table width='25' align='center' cellpadding='2' cellspacing='0' bgcolor='#315D9C'>";
	for (i=1; i<=4; i++) {
		if (i==parseInt(adults))
			tempAdults+="<tr align='center'><td width='22' class='day_s'><a href='' class='s_day' onClick='setAdults("+i+"); return false;'>"+i+"</a></td></td></tr>";
		else
			tempAdults+="<tr align='center'><td width='22' class='day'><a href='' class='today1' onClick='setAdults("+i+"); return false;'>"+i+"</a></td></tr>";
	}
	tempAdults+="</table>";
	return tempAdults;
}

function changeCal() {
	var arrivalMonth = document.getElementById("arrivalMonth").value;
//	alert (document.getElementById("arrivalMonth").value);
	arrivalMonth = parseInt(arrivalMonth);
	if (arrivalMonth>=(new Date()).getMonth())
		arrivalYear = (new Date()).getFullYear()
	else
		arrivalYear = (new Date()).getFullYear()+1;
	arrivalDate = new Date(arrivalYear, arrivalMonth, 1);
	_dateDiv.innerHTML=getCal(arrivalDate);
}

function showCal() {
	_adultsDiv.style.visibility='hidden';
	_nightsDiv.style.visibility='hidden';
	var arrivalDate = document.getElementById("arrivalDate").value;
	if (arrivalDate == "Arrival date")
		arrivalDate = new Date()
	else {
		arrivalDate = arrivalDate.split(dateDelimiter);
		arrivalDate = new Date(arrivalDate[2], arrivalDate[1]-1, arrivalDate[0]);
	}
	_dateDiv.innerHTML=getCal(arrivalDate);
	_dateDiv.style.visibility='visible';
}

function setDate(dateStr) {
	_dateDiv.style.visibility='hidden';
	result = dateStr.split('.');
	document.getElementById("dtIn").value = result[0];
	document.getElementById("mnIn").value = result[1];
	document.getElementById("arrivalDate").value=dateStr;
}

function setNights(night) {
	_nightsDiv.style.visibility='hidden';
	document.getElementById("nights").value=night;
}

function setAdults(adults) {
	_adultsDiv.style.visibility='hidden';
	document.getElementById("adults").value=adults;
}

function showNights() {
	var nights = document.getElementById("nights").value;
	_nightsDiv.innerHTML=getNights(nights);
	_dateDiv.style.visibility='hidden';
	_adultsDiv.style.visibility='hidden';
	_nightsDiv.style.visibility='visible';
}

function showAdults() {
	var adults = document.getElementById("adults").value;
	_adultsDiv.innerHTML=getAdults(adults);
	_dateDiv.style.visibility='hidden';
	_nightsDiv.style.visibility='hidden';
	_adultsDiv.style.visibility='visible';
}

function setCountryCode(valueCC)
{
	_inputFieldCC.value = valueCC;
}

function setCityNameEn(valueCN)
{
	_inputFieldCityNameEn.value = valueCN;
}

function clearInput() 
{
	var city = document.getElementById("cityN").value;
	if (city == "Enter a city...")
		document.getElementById("cityN").value = "";
}

function checkFields()
{
	if (document.f.city.value == "" || document.f.city.value == "null")
	{
	  setCountryCode(valueOfCodeAutoComplete(_highlightedSuggestionDiv));
  	  setCityNameEn(valueOfCityEnAutoComplete(_highlightedSuggestionDiv));
	}
	if (document.f.city.value == "" || document.f.city.value == "null")
	{
		alert("The Incorrect town name!")
		return false;
	}
	if (document.f.date.value == "" || document.f.date.value == "null" ||  document.f.date.value == "Arrival date")
	{
		alert("Untrue date is specified!")
		return false;
	}
	document.f.submit();
	return true;
}
function checkFields_v2()
{
	if (document.f.cityId.value == "" || document.f.cityId.value == "null")
	{
		alert("The Incorrect town name!")
		return false;
	}
	if (document.f.date.value == "" || document.f.date.value == "null" ||  document.f.date.value == "Arrival date")
	{
		alert("Untrue date is specified!")
		return false;
	}
	if(CheckForm()){
		return document.f.submit();
	}
}

//Opacity

function setOpacity(element, value){
	document.getElementById(element).style.opacity = value / 10;
	document.getElementById(element).style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function fadeInMyPopup(element){
	for (var i = 0; i <= 100; i++) 
		setTimeout('setOpacity(\'' + element + '\', ' + (i / 10) + ')', 8 * i);
}

function fadeOutMyPopup(element){
	for (var i = 0; i <= 100; i++) {
		setTimeout('setOpacity(\'' + element + '\', ' + (10 - i / 10) + ')', 8 * i);
	}
}

function closeMyPopup(){
	document.getElementById("styled_popup").style.display = "none"
}

function fireMyPopup(){
	closeMyPopup();
	setOpacity(0);        
	document.getElementById("styled_popup").style.display = "block";
	fadeInMyPopup();
}

function CheckDate(){
	return true;
}
