﻿function showlev(lev) {
    var elem = document.getElementById(lev);
    if (elem != null) elem.style.display = 'block';
}


function hidelev(lev) {
    var elem = document.getElementById(lev);
    if (elem != null) elem.style.display = 'none';
}


  function ShowErrorLoginForm()
  {
    showLoginForm();
    replace_blocks('registration-openid','login-simple');
  }
  
  function replace_blocks (showingid,hidingid) {
	 if(document.getElementById(showingid)&&document.getElementById(hidingid)) {
	  document.getElementById(showingid).style.display="block";
	  document.getElementById(hidingid).style.display="none";
	 }
	}

   var defaultButton=null;
   document.onkeypress=document_keypress;
    function document_keypress(evt)
    { 
      e = evt || window.event;
      if (defaultButton==null || e.keyCode!=13)
      {
        return;
      }
      defaultButton.click();
      e.returnValue = false;
      return false;
    }
    function set_default_button(button_id) {
     if(button_id!=null) if(document.getElementById(button_id)) {
      defaultButton=document.getElementById(button_id);
     }
     else defaultButton=null;
    }
    function cancel_bubble(evt) {
     evt = evt || window.event;
     evt.cancelBubble = true;
    }
    var current_shown_popup="";
    function show_popup(id)
    {
      hide_popups();
      var popup=document.getElementById(id);
      if(popup)
      {
        popup.style.display="block";
        popup.onclick=function(evt) { cancel_bubble(evt); };
        current_shown_popup=id;
        center_popup(id);
        var obj = findFirstInputRecursive(popup);
        safeFocus(obj);
      }
    }
    function safeFocus(obj)
    {
        if ( !obj )
            return;
        if (typeof(obj) == 'string')
            obj = document.getElementById(id);
        if (obj)
            try { obj.focus(); } catch(e) {}
    }
    function findFirstInputRecursive(obj)
    {
        if (obj.tagName == 'INPUT' || obj.tagName == 'TEXTAREA' || obj.tagName == 'SELECT')
            return obj;
        for (var i = 0; i < obj.childNodes.length; i++)
        {
            var child = findFirstInputRecursive(obj.childNodes[i]);
            if (child != null)
                return child;
        }
        return null;
    }
    function hide_popups()
    {
      var popup_container=document.getElementById("popup-content-cell");
      if(document.getElementById("please-authorize")) document.getElementById("please-authorize").style.display="none";
      if(popup_container)
      {
        for(var i=0; i<popup_container.childNodes.length;i++)
        {
          if(popup_container.childNodes[i].nodeType == 1)
          {
            popup_container.childNodes[i].style.display="none";
          }
        }
      }
      if(document.getElementById("reviews-info")) document.getElementById("reviews-info").style.display="none";
      if(document.getElementById("review-tooshort")) document.getElementById("review-tooshort").style.display="none";
      if(document.getElementById("confirm-removing")) document.getElementById("confirm-removing").style.display="none";
      if(document.getElementById("change-userpic")) document.getElementById("change-userpic").style.display="none";
      if(document.getElementById("fill-theme")) document.getElementById("fill-theme").style.display="none";
      if(document.getElementById("b-rmv-friend-form")) document.getElementById("b-rmv-friend-form").style.display="none";
      current_shown_popup="";
      document.getElementById("popup-layer").style.top="0px";
    }
    var current_shown="";
    function show_hide(id) {
      if((current_shown!="")&&(current_shown!=id)) if(document.getElementById(current_shown)) document.getElementById(current_shown).style.display="none";
      var popup=document.getElementById(id);
      if(popup.style.display=='block') {
       popup.style.display='none';
       current_shown="";
      }
      else {
       hide_popups();
       popup.style.display='block';
       current_shown=id;
      }
    }
    function please_authorize(){
     if(document.getElementById("please-authorize")) document.getElementById("please-authorize").style.display="block";
     center_curr_popup();
    }
    function hide_all_popups(evt){
     if (evt.button && evt.button == 2) return false;
     hide_popups();
     if(document.getElementById(current_shown)){ document.getElementById(current_shown).style.display="none"; current_shown=""; }
    }
    function tadam(evt){
     if (evt.button && evt.button == 2) return false;
    }
    
  function showGetSityForm()
  {
    show_popup('choosecity-block');
  }
    function showLoginForm()
    {
        setCookie('SpecialFlag',0, null); show_popup('auth-block');
    }
    
    function setCookie(c_name,value,expiredays)
    {
        var domain = document.getElementById("ctl00_inpCookieDomain").value;
        var exdate = new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        var sCook = '';
        if (domain == 'localhost' || domain == '')
            sCook = c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ";path=/";
        else
            sCook = c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ";path=/" + ";domain=" + domain + ";";
        document.cookie = sCook;
    }    
    //document.write(document.cookie)
        
    function center_popup(id){
      var popup=document.getElementById(id);
      if(popup)
      {
       if(current_shown_popup!=""){
        var abscontainer=document.getElementById("popup-layer");
        if(current_shown_popup=="reviews-info") abscontainer=document.getElementById("reviews-info"); else if(current_shown_popup=="review-tooshort") abscontainer=document.getElementById("review-tooshort"); else if(current_shown_popup=="confirm-removing") abscontainer=document.getElementById("confirm-removing"); else if(current_shown_popup=="change-userpic") abscontainer=document.getElementById("change-userpic"); else if(current_shown_popup=="fill-theme") abscontainer=document.getElementById("fill-theme");
        needtop=Math.round((getClientHeight()-popup.offsetHeight)/2);
        abscontainer.style.top=needtop-190+Math.max(document.getElementsByTagName('body')[0].scrollTop,document.documentElement.scrollTop)+"px";
       }
      }
    }
    
    function center_curr_popup(){
     if(current_shown_popup!=""){
       center_popup(current_shown_popup);
     }
    }
    
    function getClientHeight(){
     return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
    }
    
    function getAddress(addressId)
    {
        var addressTextBox = document.getElementById(addressId);
        if(addressTextBox)
        {
            addressTextBox.value = document.location.href;
        }
    }
    
        //  Search    
    var searchProviderUrl = 'http://www.afisha.ru/Search/AfishaSearchPluginUtf8.xml';

    function IsAddSearchProviderEnabled()
    {
        if (window.external)
        {
            try
            {
                if ('AddSearchProvider' in window.external)
                {
                    if ('IsSearchProviderInstalled' in window.external)
                    {
                        try
                        {
                            return !window.external.IsSearchProviderInstalled(searchProviderUrl);
                        }
                        catch(exception)
                        {}
                    }
                    return true;
                }
            }
            catch(exception)
            {}
        }
        return false;                                
    }

    function SetupSearchProvider()
    {            
        window.external.AddSearchProvider(searchProviderUrl);
    }
// End of Search
        
    var onscrollloaded=false;
        
    window.onscroll=function w_onscroll(){ if(onscrollloaded)documentscroll(); center_curr_popup(); };
    window.onresize=function w_onresize() { center_curr_popup(); };
    
// -->


Array.prototype.inArray = function (value) {
        var i;
        for (i=0; i < this.length; i++) {
                if (this[i] === value) {
                        return true;
                }
        }
        return false;
};
