var Sar = new Array();
var user_choice='';

var Browser = {
  Version: function() {
    var version = 999;
    if (navigator.appVersion.indexOf("MSIE") != -1)
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}

function searchbox_load() {
	$("#sb_submit").css("background-image","url(/images/searchbox_load.gif)");
	$("form").submit(function(){return false;});
}

function set_footer() {
 var heightContent = 0;
 if (document.getElementById('content-inn').offsetHeight > document.getElementById('content').offsetHeight) {
  heightContent = document.getElementById('content-inn').offsetHeight; }
 else {
  heightContent = document.getElementById('content').offsetHeight; 
 } 
 if (document.getElementById('footer')) {
     heightContent = heightContent+143;
     if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0) {
         document.getElementById('footer').style.setAttribute('top', heightContent + 'px')
     } else {
         document.getElementById('footer').style.setProperty ('top', heightContent + 'px', null)
      }
     document.getElementById('blankimage').style.height = heightContent + 255;
     document.getElementById('blankimage').style.display = 'block';
     document.getElementById('footer').style.display = 'block';
 }
}

var map = null;
var geocoder = null;

    function maps_initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        geocoder = new GClientGeocoder();
        if (document.getElementById('f_address_curr')) {
         showAddressEx(document.getElementById('f_address_curr').value,10)
        } else {
         map.setCenter(new GLatLng(55.75005, 37.61695), 10);
        }
      }
    }

    function showAddress(address) {
      if (address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (point) {
             map.setCenter(point, 15);
             var marker = new GMarker(point);
             map.addOverlay(marker);
            }
          }
        );
      }
     } 
    }
    function showAddressEx(address,mst) {
      if (address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (point) {
             map.setCenter(point, mst);
             var marker = new GMarker(point);
             map.addOverlay(marker);
            }
          }
        );
      }
     } 
    }

function initpage() {
 set_footer();
 initRollovers();
 maps_initialize();
}

window.onload = initpage;

var ru2en = {
  ru_str : "ÀÁÂÃÄÅ¨ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäå¸æçèéêëìíîïðñòóôõö÷øùúûüýþÿ",
  en_str : ['A','B','V','G','D','E','Yo','Zh','Z','I','Y','K','L','M','N','O','P','R','S','T',
    'U','F','Kh','C','Ch','Sh','Shh',String.fromCharCode(35),'Y',String.fromCharCode(39),'Ye','Yu',
    'Ya','a','b','v','g','d','e','yo','zh','z','i','y','k','l','m','n','o','p','r','s','t','u','f',
    'kh','c','ch','sh','shh',String.fromCharCode(35),'y',String.fromCharCode(39),'ye','yu','ya'],
  translit : function(org_str) {
    var tmp_str = "";
    for(var i = 0, l = org_str.length; i < l; i++) {
      var s = org_str.charAt(i), n = this.ru_str.indexOf(s);
      if(n >= 0) { tmp_str += this.en_str[n]; }
      else { tmp_str += s; }
    }
    return tmp_str;
  }
}

function set_station(msid,trans) {
 var st=document.getElementById('ms'+msid);
 if (Sar[msid]) {
  st.src='/data/maps/dot_blank.gif';
  Sar[msid]='';
 } else {
  st.src='/data/maps/dot_blink.gif';
  Sar[msid]=1;
 }
 document.getElementById('hotels_metro_list').innerHTML='';
 for (var i = 0; i < Sar.length; i++) {
	if (Sar[i]) {
   if (i > 0) { user_choice=i+' '+user_choice; }
   if (metrohash[i]) {
    var line=lineshash[i];
    var col='';
    var cd;
    if (line) { col=linescolor[line]; }
    if (col) { cd='<div style="width:12px;height:12px;background-color:'+col+';position:relative;display:inline">   </div> '; } 
    if (trans == 1) {
     document.getElementById('hotels_metro_list').innerHTML=document.getElementById('hotels_metro_list').innerHTML+cd+" "+ru2en.translit(metrohash[i])+"<br>"
    } else {
     document.getElementById('hotels_metro_list').innerHTML=document.getElementById('hotels_metro_list').innerHTML+cd+" "+metrohash[i]+"<br>";
    }  
   } 
  }  
 }
}
function enum_station(p1,p2,p3,p4,p5,p6,p7) {
 var requestline='';
 for (var i = 0; i < Sar.length; i++) {
	if (Sar[i]) {
   if (i > 0) { user_choice=i+' '+user_choice; }
   if (metrohash[i]) { requestline=requestline+"-"+i; } 
  }  
 }
 location.href='/hotels/display_c'+p1+'_p1r'+p2+'_p2r'+p3+'_cr'+p4+'_s'+p5+'_e'+p6+'_m'+requestline+'_chsm'+p7+'_1.html';
}
function enum_dates(p3,pc) {
 var p1='';
 var p2='';
 if (document.getElementById('v_date1')) {
  p1=document.getElementById('v_date1').value;
 }
 if (document.getElementById('v_date2')) {
  p2=document.getElementById('v_date2').value;
 }
 if (p1 && p2) { location.href='/hotels/viewdate_'+p1+'_'+p2+'_'+p3+'_cr'+pc+'.html'; }
}

var timerID = null; 
var timerOn = false; 
var timecount = 1000;
function hideAll () {
 document.getElementById('hotels_metro_station').style.display='none';
}
function startTime() { 
 if (timerOn == false) { 
 timerID=setTimeout( "hideAll()" , timecount); 
 timerOn = true; 
 } 
}
function stopTime() { 
 if (timerOn) { 
 clearTimeout(timerID); 
 timerID = null; 
 timerOn = false; 
 } 
}

function showStation(sid) {
 if (document.getElementById(sid)) {
  var sh=parseInt(sid.replace('ms',''));
  if (datahash[sh]) {
   stopTime();
   var sl=document.getElementById(sid).style.left;
   var st=document.getElementById(sid).style.top;
   var sln=parseInt(sl.replace('px',''))+12;
   if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0) {
        document.getElementById('hotels_metro_station').style.setAttribute('top', st)
        document.getElementById('hotels_metro_station').style.setAttribute('left', sln+'px')
   } else {
        document.getElementById('hotels_metro_station').style.setProperty('top', st, null)
        document.getElementById('hotels_metro_station').style.setProperty('left', sln+'px', null)
   }
   document.getElementById('hotels_metro_station').innerHTML=datahash[sh];
   document.getElementById('hotels_metro_station').style.display='block';
  } 
 } 
}

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}

var Utf8 = {


    // public method for url encoding
    encode : function (string) {
        string = string.replace(/rn/g,"n");
        var utftext = "";


        for (var n = 0; n < string.length; n++) {


            var c = string.charCodeAt(n);


            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }


        }


        return utftext;
    },


    // public method for url decoding
    decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;


        while ( i < utftext.length ) {


            c = utftext.charCodeAt(i);


            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }


        }


        return string;
    }


}

function isIE() {
 return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

var gmap_save;

function UpdateGoogleMap(){
 if (document.getElementById('f_address_curr')) {
  if (!gmap_save) { gmap_save=document.getElementById('f_address_curr').value;}
  if (document.getElementById('f_address_curr').value != gmap_save) {
   showAddressEx(document.getElementById('f_address_curr').value,10);
  }
  setTimeout('UpdateGoogleMap()',1500);
 }
}

if (isIE()) {
 setTimeout('UpdateGoogleMap()',2000);
} 

