/**
 * Определяет тип используемого браузера
 *
 * @return String название браузера
 */
function GetBrowserType(){
    if(document.all)
        return 'IE';
    else
        return 'Mozilla';
}

/**
* Открывает окно с формой голосования за конкретный ресторан
*
* @return false
*/
function openRestVoteWin(i_ID, s_MainSite) {
    if ( i_ID ) {
        if (s_MainSite == '') {
            RestVoteWin = open("/voting/index.phtml?id=" + i_ID + "&job=vote_for_object", "displayWindow", "status=yes,toolbar=no,menubar=no,scrollbars=yes,height=510,width=525,resizable=yes,top=100,left=400");
        }
        else {
            RestVoteWin = open("http://" + s_MainSite + "/voting/index.phtml?id=" + i_ID + "&job=vote_for_object", "displayWindow", "status=yes,toolbar=no,menubar=no,scrollbars=yes,height=510,width=525,resizable=yes,top=100,left=400");
        }
    }
    return false;
}

/**
* Класс кэша для сохранения часто используемых элементов страницы (оптимизация функции getElementById)
*/
function ElementCache() {
    this.a_Cache = new Array();
    this.Put = function(s_Name) { this.a_Cache[s_Name] = document.getElementById(s_Name); };
    this.Get = function(s_Name) { 
            if (this.a_Cache[s_Name] == undefined)
                {
                    this.Put(s_Name);
                }
                return this.a_Cache[s_Name]; 
        };
}
/**
* динамическое обновление линков поиска
*/
function initLinks(divInput,urlParam) {
    divInput = document.getElementById(divInput);
    input = document.getElementById("search_string");
    links = divInput.getElementsByTagName("a");
    setInterval(function() {
        if (links != '') {
            var searchValue = input.value;
            for (var i = 0; i < links.length; i++) {
                if( urlParam[i] ){
                    a = links[i];
                    urlValue = urlParam[i];
    //                a.href = '/?' + (urlValue ? urlValue + '&' : '') + 'string=' + searchValue;
                    a.href = '/?' + (urlValue ? urlValue + '&' : '') + 'js=true&string=' + searchValue;//encodeURIComponent(searchValue);
    //                a.href = '/transformer/' + (urlValue ? urlValue + '/' : '') + 'string__' + escape_ru(searchValue) + '.html';
    //                a.href = '/?' + (urlValue ? urlValue + '&' : '') + 'string__' + Url.encode(searchValue);
                }
            }
        }
    }, 300);
}

// Инициализируем таблицу перевода
var trans = [];
for (var i = 0x410; i <= 0x44F; i++)
  trans[i] = i - 0x350; // А-Яа-я
trans[0x401] = 0xA8;    // Ё
trans[0x451] = 0xB8;    // ё

// Сохраняем стандартную функцию escape()
var escapeOrig = window.escape;

// Переопределяем функцию escape()
window.escape_ru = function(str)
{
  var ret = [];
  // Составляем массив кодов символов, попутно переводим кириллицу
  for (var i = 0; i < str.length; i++)
  {
    var n = str.charCodeAt(i);
    if (typeof trans[n] != 'undefined')
      n = trans[n];
    if (n <= 0xFF)
      ret.push(n);
  }
  return escapeOrig(String.fromCharCode.apply(null, ret));
}

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // 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;
    }

}




