var countAll = 0;
var varsFlash = { }
var varsFlash2 = { }
var regionsStr = '';
var metrosStr = '';
var dataStrAll = '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111';
var dataStrNone = '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
var dataStr = '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
var varsFlashMap = { datastr: dataStr }
var dataStrMAll = '111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111';
var dataStrM = '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
var itemsAdd = false;
var is_ie = (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent));
function GID(id) { return (is_ie) ? document.all[id] : document.getElementById(id); }

$(document).ready(function() {
   $('.banRotate').find('.dn').removeClass('dn');
   $(".pngFix").pngFix();
   if ($("#textareaAdd").length) $("#textareaAdd").maxlength({ maxChars: 600 });
   checkFlash();
   if ($(".tooltip").length) $('.tooltip').tooltip({
  	   track: true,
     	delay: 100,
      bodyHandler: function() { return $("#"+$(this).attr('id')+"Div").html(); }
  });
  $(".mapCheck").click(function() {
     var sendStr = '';
     var thisCheck = $(this).attr('checked');
     var parId = $(this).parent().attr('id');
     $("#"+parId+" .mapCheck").attr('checked', thisCheck);
     $(".mapCheck").each(function() {
        if ($(this).attr('checked')) sendStr = sendStr + (sendStr.length ? '|' : '') + $(this).attr('name');
     });
     ajaxRedraw(sendStr);
     ajaxRedrawTable(sendStr);
  });
  $(".mapCheckMain").click(function() {
     var sendStr = '';
     var thisCheck = $(this).attr('checked');
     var parId = $(this).parent().attr('id');
     $("#"+parId+" .mapCheckMain").attr('checked', thisCheck);
  });
  $(".mapHrefs").click(function() {
     var sh = $(this).next().css('display');
     if (!sh || sh == 'none') $(this).next().css('display', 'block');
     else $(this).next().css('display', 'none');
  });
});

function checkAjaxB(ids) {
   $.ajax({
    type: "POST",
    async: false,
    url: "ban-show.php",
    data: 'ids='+ids,
    success: function(response) {  }
   });
}

function fnCheckSearchForm(f) {
   if (!f.search.value.match(/^.+$/)) {
      alert("Óêàæèòå ïîèñêîâûé çàïðîñ!");
      f.search.focus();
      return false;
   }
   return true;
}

function fnCheckSearchFormGoogle(f) {
   if (!f.q.value.match(/^.+$/)) {
      alert("Óêàæèòå ïîèñêîâûé çàïðîñ!");
      f.q.focus();
      return false;
   }
   return true;
}

function hashIsEmpty(hash) {
    for (var k in hash) return false;
    return true;
}

function hashLength(hash) {
    var ret = 0;
    for (var k in hash) ret = ret + 1;
    return ret;
}

function submitPager(obj, url) {
   obj.action = url+'_'+obj.pager.value+'.htm';
   return true;
}

function viewSubparts(id) {
   var disp = $("#divSC"+id).css('display');
   $(".divSC").css('display', 'none');
   $(".strSC").attr('src', 'image/list-str.gif');
   if (disp == 'none' || !disp) {
      $("#divSC"+id).css('display', 'block');
      $("#strSC"+id).attr('src', 'image/list-str-a.gif');
   }
   else {
      $("#divSC"+id).css('display', 'none');
      $("#strSC"+id).attr('src', 'image/list-str.gif');
   }
}

function showAreasList() {
   var disp = $(".areasDivS").css('display');
   if (disp == 'none' || !disp) $(".areasDivS").css('display', 'block');
   else $(".areasDivS").css('display', 'none');
}

function showContentItem(idC) {
   $(".menuItem TD").removeClass("tmLink3Sel").addClass("tmLink3");
   $("#menuItem"+idC).removeClass("tmLink3").addClass("tmLink3Sel");
   $("#contentItem").empty();
   $("#contentItem").html($("#contentItem"+idC).html());
   if (idC == 1) load();
}

function printPage(form) {
   $("#commentP").html(form.comment.value);
   $(".btnPrint").hide();
   window.print();
}

function fnGoToItem(idI) {
   document.goToItem.action = 'item_'+idI+'.htm';
   document.goToItem.submit();
   return false;
}

jQuery.extend({
   serialize: function ( mixed_value ) {
       var _getType = function( inp ) {
           var type = typeof inp, match;
           var key;
           if (type == 'object' && !inp) {
               return 'null';
           }
           if (type == "object") {
               if (!inp.constructor) {
                   return 'object';
               }
               var cons = inp.constructor.toString();
               match = cons.match(/(\w+)\(/);
               if (match) {
                   cons = match[1].toLowerCase();
               }
               var types = ["boolean", "number", "string", "array"];
               for (key in types) {
                   if (cons == types[key]) {
                       type = types[key];
                       break;
                   }
               }
           }
           return type;
       };
       var type = _getType(mixed_value);
       var val, ktype = '';

       switch (type) {
           case "function":
               val = "";
               break;
           case "boolean":
               val = "b:" + (mixed_value ? "1" : "0");
               break;
           case "number":
               val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
               break;
           case "string":
               val = "s:" + encodeURIComponent(mixed_value).replace(/%../g, 'x').length + ":\"" + mixed_value + "\"";
               break;
           case "array":
           case "object":
               val = "a";
               /*
               if (type == "object") {
                   var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
                   if (objname == undefined) {
                       return;
                   }
                   objname[1] = serialize(objname[1]);
                   val = "O" + objname[1].substring(1, objname[1].length - 1);
               }
               */
               var count = 0;
               var vals = "";
               var okey;
               var key;
               for (key in mixed_value) {
                   ktype = _getType(mixed_value[key]);
                   if (ktype == "function") {
                       continue;
                   }

                   okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
                   vals += $.serialize(okey) +
                           $.serialize(mixed_value[key]);
                   count++;
               }
               val += ":" + count + ":{" + vals + "}";
               break;
           case "undefined": // Fall-through
           default: // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP
               val = "N";
               break;
       }
       if (type != "object" && type != "array") {
           val += ";";
       }
       return val;
   }
});
