/*---------------------------------------------
window.js
-----------------------------------------------*/
var Checked=new Array();
var Checkbox=new Array();

Checkbox[0]=new Image(13,13);
Checkbox[0].src='/imgs/uncheckedbox.gif';
Checkbox[1]=new Image(13,13);
Checkbox[1].src='/imgs/checkedbox.gif';

function CheckSearch()
  {
   if (document.SearchForm.SearchWord.value.length > 1)
      return true;
   else
     {
      alert ("Введите строку для поиска");
      return false;
     }
  }

function OpenC(theURL,winName,features)
  {
     var Win=window.open(theURL,winName,features);
     Win.focus();
     return false;
  }

function OpenCard(id, showcart)
  {
   var newURL="card.php?id="+id+"&showcart="+showcart;
   //Wid=window.open(newURL,id);
   Wid=window.open(newURL, id, 'toolbar=0,scrollbars=1,location=0,directories=0,status=0,menubar=0,width=771,height=505,border=thin,top=0,left=0,help=0');
   /*Wid.focus();*/
  }

function OpenReview(id, showcart)
  {
   var newURL="card.php?id="+id+"&showcart="+showcart+"&review=1#review";
   //Wid=window.open(newURL,id);
   Wid=window.open(newURL, id, 'toolbar=0,scrollbars=1,location=0,directories=0,status=0,menubar=0,width=590,height=505,border=thin,top=0,left=0,help=0');
   /*Wid.focus();*/
  }

function openphoto(URL,width,height)
  {
   var URL=URL;
   Widb=window.open(URL,'','toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,width='+width+',height='+height+',border=thin,top=0,left=0,help=0');
  }

function openphoto2(URL,width,height)
  {
   var URL=URL;
   Widb=window.open(URL,'','toolbar=0,scrollbars=1,location=0,directories=0,status=0,menubar=0,width='+width+',height='+height+',border=thin,top=0,left=0,help=0');
  }
function OpenImage(id)
  {
   var newURLb="/Pdb/text.phtml?id="+id+"&big=1";
   Widb=window.open(newURLb,id+'_i','toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,width=600,height=600,border=thin,top=0,left=0,help=0');
  }

function OpenGame2()
  {
   var newURLb="/game2/";
   Widb=window.open(newURLb,'game_2','toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,width=750,height=660,border=thin,top=0,left=0,help=0');
  }


function OpenSaleGame()
  {
   var newURLb="/salegame/";
   Widb=window.open(newURLb,'salegame','toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,width=655,height=600,border=thin,top=0,left=160,help=0');
  }

function Open3D(id,prefix,big)
  {
   if (big=='2') {
     var newURL="/Swf3/show.php?id=" + id + "&prefix=" + prefix;
     Widb=window.open(newURL,'main_big2','toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,width=603,height=697,border=thin,top=0,left=0,help=0');
   }
   else if (big=='1') {
     var newURL="/Swf2/show.php?id=" + id + "&prefix=" + prefix;
     Widb=window.open(newURL,'main_big','toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,width=600,height=600,border=thin,top=0,left=0,help=0');
   } else {
     var newURL="/Swf/show.php?id=" + id + "&prefix=" + prefix;
     Widb=window.open(newURL,'main','toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,width=400,height=400,border=thin,top=0,left=0,help=0');
   }
  }

function Order(id)
  {
   var newURL="/cart.php?ids["+id+"]=1";
   if (window.opener)
     window.opener.location = newURL;
   else
     window.open (newURL,"main");
   return false;
  }

function OpenShop (num)
  {
   var URL="/?p=shop"+num;
   if (window.opener && !window.opener.closed)
     window.opener.location = URL;
   else
     window.opener = window.open (URL, "main");
   window.opener.focus();
  }

function CheckboxClicked (id)
  {
   if (Checked[id])
     {
      Checked[id]=0;
      document['check'+id].src=Checkbox[0].src;
     }
   else
     {
      Checked[id]=1;
      document['check'+id].src=Checkbox[1].src;
     }
  }

function Check(e)
{
  for (i=0;i<document.compare_form.elements.length;i++)
   {
     if (e==1 && document.compare_form.elements[i].type == 'hidden')
       {
        Checked[document.compare_form.elements[i].value]=1;
        document['check'+document.compare_form.elements[i].value].src=
          Checkbox[1].src;
       }
     if (e==2 && document.compare_form.elements[i].type == 'hidden')
       {
        Checked[document.compare_form.elements[i].value]=0;
        document['check'+document.compare_form.elements[i].value].src=
          Checkbox[0].src;
       }
     if (e==3 && document.compare_form.elements[i].type == 'hidden')
       {
        num=Checked[document.compare_form.elements[i].value];
        if (isNaN(num))
          num=0;
        Checked[document.compare_form.elements[i].value]=
          1-num;
        document['check'+document.compare_form.elements[i].value].src=
          Checkbox[1-num].src;
       }
   }
}


function Send_checked(form_name,opros)
  {
   var si = 0;
   var url = '?';
   var tmp = new Array();

   for (var i=0; i<document.form_name.elements.length; i++)
     if ( document.form_name.elements[i].type == 'hidden' &&
          Checked[document.form_name.elements[i].value] &&
          si<160
         )
       tmp[si++] = 'id_opros_browser[]='
               + document.form_name.elements[i].value;

   url = url + tmp.join('&') + '&opros_num=' +  opros;

   if (si >= 1)
     location.href=url;
   else
     window.alert("Выберите один из пунктов");
  }


function Compare()
  {
   var si = 0;
   var url = '/compare.php?';
   var tmp = new Array();

   for (var i=0; i<document.compare_form.elements.length; i++)
     if (document.compare_form.elements[i].type == 'hidden' &&
         Checked[document.compare_form.elements[i].value] && si<160)
       tmp[si++] = 'ids[]='
               + document.compare_form.elements[i].value;

   url = url + tmp.join('&');

   if (si > 1)
     window.open(url,'compare','resizable=yes,width=790,height=540,toolbar=no,scrollbars=yes,location=no,directories=no,status=no,menubar=no,top=no,left=no,help=no');
   else
     window.alert("Выберите товары для сравнения");
  }

function Compare_2()
  {
   var si = 0;
   var url = '/compare.php?';
   var tmp = new Array();

   for (var i=0; i<document.compare2_form.elements.length; i++)
     if (document.compare2_form.elements[i].type == 'hidden')
       tmp[si++] = 'ids[]='
               + document.compare2_form.elements[i].value;

   url = url + tmp.join('&');

     window.open(url,'compare','resizable=yes,width=790,height=540,toolbar=no,scrollbars=yes,location=no,directories=no,status=no,menubar=no,top=no,left=no,help=no');

  }

function LeaveSelected()
  {
   var si = 0;
   var url="/pricelist/?p=t&";
   var tmp = new Array();

   for (var i=0; i<document.compare_form.elements.length; i++)
     if (document.compare_form.elements[i].type == 'hidden' &&
         Checked[document.compare_form.elements[i].value] && si<160)
       tmp[si++] = 'ids[]='
                 + document.compare_form.elements[i].value;

   url = url + tmp.join('&');

   window.location=url;
  }

function OpenBrand ()
  {
   mark = document.brandform.mark.options[document.brandform.mark.options.selectedIndex].value;
   if (mark) window.location = "/classifier.php?mark=" + mark;
  }

function OpenCity ()
  {
   city = document.cityform.city.options[document.cityform.city.options.selectedIndex].value;
   if (city) window.location = city;
  }

function OpenAdvSearch ()
  {
   var newURL;
   newURL="http://www.mvideo.ru/pricelist/?p=search";
   Win=window.open(newURL, 'AdvSearch', 'toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,width=570,height=260,border=thin,top=0,left=0,help=0');
   Win.focus();
  }

function OpenParamSearch (lvl,class_,group,mark)
  {
   var newURL;
   if (window.location.href.indexOf("/homeshop/")==-1)
     newURL="/pricelist/paramsearch.phtml?lvl="+lvl+"&class="+class_+"&group="+group+"&mark="+mark;
   else
     newURL="/homeshop/paramsearch.phtml?lvl="+lvl+"&class="+class_+"&group="+group+"&mark="+mark;
   Win=window.open(newURL, 'ParamSearch', 'toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,width=450,height=400,border=thin,top=0,left=0,help=0');
   Win.focus();
  }

function OpenAdvAction(num)
  {
   var newURL="/adv-txt/?p="+num;
   if (window.opener)
     window.opener.location = newURL;
   else
     window.open (newURL,"main");
   return false;
  }

function OpenInOpener(newURL)
  {
   if (window.opener)
     window.opener.location = newURL;
   else
     window.open (newURL,"main");
   return false;
  }

function set_cookie(name, value, expires)
{
 if (!expires)
  {
   expires = new Date();
  }
 document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

/*---------------------------------------------
flash_detect.js
-----------------------------------------------*/

<!-- // Detect Client Browser type
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 6;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Revision of Flash required
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;


var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
        // NS/Opera version >= 3 check for Flash plugin in plugin array
        if (navigator.plugins != null && navigator.plugins.length > 0) {
                if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
                        var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
                      var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
                        descArray = flashDescription.split(" ");
                        tempArrayMajor = descArray[2].split(".");
                        versionMajor = tempArrayMajor[0];
                        versionMinor = tempArrayMajor[1];
                        if ( descArray[3] != "" ) {
                                tempArrayMinor = descArray[3].split("r");
                        } else {
                                tempArrayMinor = descArray[4].split("r");
                        }
                      versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
              } else {
                        flashVer = -1;
                }
        }
        // MSN/WebTV 2.6 supports Flash 4
        else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
        // WebTV 2.5 supports Flash 3
        else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
        // older WebTV supports Flash 2
        else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
        // Can't detect in all other cases
        else {

                flashVer = -1;
        }
        return flashVer;
}
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
         reqVer = parseFloat(reqMajorVer + "." + reqRevision);
           // loop backwards through the versions until we find the newest version
        for (i=25;i>0;i--) {
                if (isIE && isWin && !isOpera) {
                        versionStr = VBGetSwfVer(i);
                } else {
                        versionStr = JSGetSwfVer(i);
                }
                if (versionStr == -1 ) {
                        return false;
                } else if (versionStr != 0) {
                        if(isIE && isWin && !isOpera) {
                                tempArray         = versionStr.split(" ");
                                tempString        = tempArray[1];
                                versionArray      = tempString .split(",");
                        } else {
                                versionArray      = versionStr.split(".");
                        }
                        versionMajor      = versionArray[0];
                        versionMinor      = versionArray[1];
                        versionRevision   = versionArray[2];

                        versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
                        versionNum        = parseFloat(versionString);
                // is the major.revision >= requested major.revision AND the minor version >= requested minor
                        if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
                                return true;
                        } else {
                                return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
                        }
                }
        }
        return (reqVer ? false : 0.0);
}

function display_flash(f_src,f_width,f_height,f_zagl,f_url,bgcolor)
{  
var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if(hasRightVersion) {  // if we've detected an acceptable version
    var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    + 'width="'+f_width+'" height="'+f_height+'"'
    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
    + '<param name="movie" value="'+f_src+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="salign" value="lt" /><param name="wmode" value="transparent" /><param name="bgcolor" value="'+bgcolor+'" />'
    + '<embed src="'+f_src+'" loop="false" menu="false" quality="high" salign="lt" wmode="transparent" bgcolor="'+bgcolor+'" '
    + 'width="'+f_width+'" height="'+f_height+'" align="middle"'
    + 'play="true"'
    + 'salign="lt"'
    + 'wmode="transparent"'
    + 'loop="false"'
    + 'quality="high"'
    + 'allowScriptAccess="sameDomain"'
    + 'type="application/x-shockwave-flash"'
    + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
    + '<\/embed>'
    + '<\/object>';
    document.write(oeTags);   // embed the flash movie
  } else {  // flash is too old or we can't detect the plugin
    var alternateContent = '<a href="'+f_url+'"><img src="'+f_zagl+'" height="'+f_height+'" width="'+f_width+'"  border="0" alt="-" /></a>';
    document.write(alternateContent);  // insert non-flash content
  }
}
// -->


/*---------------------------------------------
scripts.js
-----------------------------------------------*/

function show_marks(type)
{
   var mark_first = document.getElementById('mark_first').value;
   var mark_cnt = document.getElementById('mark_cnt').value;
   var path = "/imgs/lowprice/brands/big/";
   if (type=='n')
   {
      mark_first = parseInt(mark_first)+1;
   }
   else if (type=='p')
   {
      mark_first = parseInt(mark_first) - 1;
   }
  // alert(mark_first);
   var i = 1;
   for(i=1; i<=9; i++)
   {
      var num = (parseInt(mark_first)+i);	   
	  var i1_src = document.getElementById('mark_'+num).value;
      var i1_url = document.getElementById('mark_link_'+num).value;

      if (document.getElementById('mark_url_'+i))
      {
         document.getElementById('mark_src_'+i).src = path+i1_src+'.gif';         
         document.getElementById('mark_url_'+i).href = i1_url;
         document.getElementById('mark_name_url_'+i).href = i1_url;
         document.getElementById('mark_name_url_'+i).innerHTML = image_name[num-1];
      }
   }

   if (parseInt(mark_first)+9>=mark_cnt)
   {
      document.getElementById('mark_next').innerHTML = '<b class="block" id="arr_right_grey"></b>';
      document.getElementById('mark_next').onclick = function(){};
   }
   else
   {
      document.getElementById('mark_next').innerHTML = '<b class="block cpointer" id="arr_right_red"></b>';
      document.getElementById('mark_next').onclick = function(){show_marks('n')};
   }
   if (mark_first==0)
   {
      document.getElementById('mark_prev').innerHTML = '<b class="block" id="arr_left_grey"></b>';
      document.getElementById('mark_prev').onclick = function(){};
   }
   else
   {
      document.getElementById('mark_prev').innerHTML = '<b class="block cpointer" id="arr_left_red"></b>';
      document.getElementById('mark_prev').onclick = function(){show_marks('p')};
   }
   document.getElementById('mark_first').value = mark_first;
}



function resizeGroupBlock()
{
   var screen_w = document.body.offsetWidth;
   var w1 = 1024;
   var w2 = 1244;
   var w3 = 1440;
   allOfDivs = document.getElementsByTagName("DIV");
   //alert(document.body.offsetWidth);
   for (var i = 0; i < allOfDivs.length; i++)
   {
      var oObj = allOfDivs.item(i);
      if (oObj.className=="group_block dottedRight" || oObj.className=="group_block")
      {
         if (screen_w<w2)
         {
            if (oObj.id=="group_block4") oObj.style.display='none';
            if (oObj.id=="group_block4") oObj.style.display='none';
            if (oObj.id=="group_block3") oObj.className='group_block';
         }
         else if (screen_w>=w2)
         {
            if (oObj.id=="group_block4") oObj.style.display='block';
            if (oObj.id=="group_block5") oObj.style.display='none';
            if (oObj.id=="group_block3") oObj.className='group_block dottedRight';
            if (oObj.id=="group_block4") oObj.className='group_block';
         }
         else if (screen_w>w3)
         {
            if (oObj.id=="group_block4") oObj.style.display='block';
            if (oObj.id=="group_block5") oObj.style.display='block';
            if (oObj.id=="group_block3") oObj.className='group_block dottedRight';
            if (oObj.id=="group_block4") oObj.className='group_block dottedRight';
            if (oObj.id=="group_block5") oObj.className='group_block';
         }


      }

   }
}



/* листалка подарочных карт **/


var ua = navigator.userAgent.toLowerCase();
// Internet Explorer
isIE = (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1);
if (isIE)
{
  var inline_d = 'inline';
}
else
{
  var inline_d = 'table-cell';
}

function show_list(type)
{
   var first = document.getElementById('list_first').value;
   var cnt = document.getElementById('list_cnt').value;

   //alert(first);
   if (type=='n')
   {
      document.getElementById('item_'+first).style.display='none';
      first = parseInt(first)+1;
      document.getElementById('item_'+(parseInt(first)+2)).style.display=inline_d;
   }
   else if (type=='p')
   {
      first = parseInt(first)-1;
      document.getElementById('item_'+first).style.display=inline_d;
      document.getElementById('item_'+(parseInt(first)+3)).style.display='none';
   }

   if (parseInt(first)+3>=cnt)
   {
      document.getElementById('list_next').style.visibility = 'hidden';
   }
   else
   {
      document.getElementById('list_next').style.visibility = 'visible';
   }
   if (first==0)
   {
      document.getElementById('list_prev').style.visibility = 'hidden';
   }
   else
   {
      document.getElementById('list_prev').style.visibility = 'visible';
   }
   document.getElementById('list_first').value = first;


   document.getElementById('item_2').className = 'right-b';
   document.getElementById('item_'+(parseInt(first)+1)).className = 'right-b';
   document.getElementById('item_'+(parseInt(first)+2)).className = 'no-b';

   //alert(first+'--item_'+(parseInt(first)+1)+'--item_'+(parseInt(first)+2));
}


/*---------------------------------------------
new_fix.js
-----------------------------------------------*/

var full_w = screen.width - 230;
var spec_width = 350; // 370
var novs_width = 250; // 270
var spec_offs = 0;


function show_spec_fishki(num)
{
   if (document.getElementById('spec_cnt'))
   {
   var spec_cnt = document.getElementById('spec_cnt').value;
   var firstspec = num;
   //var spec_per_page = document.getElementById('spec_per_page').value;
   var spec_per_page = 2;

   // стираем все кнопки нафиг. потом выставим.
   for (var i=1; i<=spec_cnt; i++)
   {
      if (document.getElementById('spec_'+i+'but')) document.getElementById('spec_'+i+'but').src = "/new_d/pager/"+i+".gif";
      if (document.getElementById('spec_div_'+i)) {document.getElementById('spec_div_'+i).style.display = 'none';}
   }

   // первый-последний
   if (firstspec==spec_cnt) // последний
   {
     firstspec = parseInt(firstspec)-1;
   }
   if (firstspec==1 && spec_per_page>2) // первый
   {
     firstspec = 2;
   }

   if (firstspec)
   {
      // кнопки
      if (document.getElementById('spec_'+firstspec+'but')) document.getElementById('spec_'+firstspec+'but').src = "/new_d/pager/"+firstspec+"a.gif";
      if (document.getElementById('spec_'+(parseInt(firstspec)+1)+'but')) document.getElementById('spec_'+(parseInt(firstspec)+1)+'but').src = "/new_d/pager/"+(parseInt(firstspec)+1)+"a.gif";
      if (document.getElementById('spec_'+(parseInt(firstspec)-1)+'but') && spec_per_page>2) document.getElementById('spec_'+(parseInt(firstspec)-1)+'but').src = "/new_d/pager/"+(parseInt(firstspec)-1)+"a.gif";

      // дивы
      if (document.getElementById('spec_div_'+firstspec)) document.getElementById('spec_div_'+firstspec).style.display = 'block';
      if (document.getElementById('spec_div_'+(parseInt(firstspec)+1))) document.getElementById('spec_div_'+(parseInt(firstspec)+1)).style.display = 'block';
      if (document.getElementById('spec_div_'+(parseInt(firstspec)-1)) && spec_per_page>2) document.getElementById('spec_div_'+(parseInt(firstspec)-1)).style.display = 'block';
   }
   document.getElementById('firstspec').value=firstspec;
   }
}

function sub_menu(id,hide)
{
   if(hide)
   {
      document.getElementById('subm'+id).style.display='none';
   }
   else
   {
      document.getElementById('subm'+id).style.display='block';
      var itemX = document.getElementById('topm'+id).offsetParent.offsetLeft;
      if (document.getElementById('topm'+(id+1)))
      {
         var itemXn = document.getElementById('topm'+(id+1)).offsetParent.offsetLeft;
      }
      var totalX = document.getElementById('topm').offsetWidth;
      var tablX = document.getElementById('subm'+id).offsetWidth;

      if (itemX == 0) // первый
      {
         Xp = 15;
      }
      else if (itemX <= (totalX - tablX))  // до половины
      {
         Xp = itemX;
      }
      else if(itemXn && itemXn - tablX > 15) // половина
      {
         Xp = itemXn - tablX;
      }
      else  // после половины
      {
         Xp = totalX - tablX - 15;
      }
      document.getElementById('subm'+id).style.left = Xp + 'px';
      document.getElementById('subm'+id).style.display='block';
   }
}


///////// счетчик

CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%H%% : %%M%% : %%S%% ";

CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0) CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;


function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero && s.length < 2)
    s = "0" + s;
  return s;
}

function CountBack(secs, div_id, deal) {

  var type_deal = (deal ? deal : 0);
  var seconds = secs;
	
  if (secs < 0) {
    if (document.location.search)
    {
       var add_chr = '&';
    }
    else
    {
       var add_chr = '?';
    }
    document.location.href= document.location.href + add_chr + 'rnd=1';
    return;
  }
 
  
  // days
  var days  = Math.ceil(secs / 86400) - 1;
  secs -= days * 86400;
  
  
  // hours
  var hours = Math.ceil(secs / 3600) - 1;
  secs -= hours * 3600;
  
  // minutes
  var mins  = Math.ceil(secs / 60) - 1;
  secs -= mins * 60;
  
  
  var d_name = 'дней';
  if (days == 1) {
  	d_name = 'день';
  }
  if (days > 1 && days < 5) {
  	d_name = 'дня';
  }
  
  
  if (days > 0) {
  	secs  = '';
  	//days = '<span>'+days+'</span>&nbsp;'+d_name;
  } else {
  	days = '';
  	//secs = '<span>'+secs+'</span>&nbsp;сек.';
  }
  
  if (hours > 0) {
  	//hours = '<span>'+hours+'</span>&nbsp;час.';
  } else {
  	hours = '';
  }
  
  if (mins > 0) {
  	//mins = '<span>'+mins+'</span>&nbsp;мин.';
  } else {
  	mins = '';
  }
  
  
  //document.getElementById(div_id).innerHTML = days+hours+mins+secs;
    
  
  if (days < 10) {
	  days = '0'+days;
	  }
  if (hours < 10) {
	  	hours = '0'+hours;
	  }
	  
  if (mins < 10) {
	  	mins = '0'+mins;
	  } 
  
  if (secs < 10) {
	  	secs = '0'+secs;
	  } 
  
  
  if (deal) {
	  document.getElementById(div_id).innerHTML = '<b>'+hours+'</b> час. <b>'+mins+'</b> мин. <b>'+secs+'</b> сек. ';
  } else {
	  document.getElementById(div_id).innerHTML = '<table width="100%" cellpadding="0" cellspacing="0"><tr>'+
		  									(days>0 ?  '<td>'+days +'</td><td class="time_line">|</td>' : '')+
		  									(hours>0 ? '<td>'+hours+'</td><td class="time_line">|</td>' : '')+
		  									(mins>0 ?  '<td>'+mins +'</td>' : '')+
		  									(secs>0 ?  '<td class="time_line">|</td><td>'+secs +'</td>' : '')+
		  									'</tr><tr class="s_text">'+
		  									(days>0 ?  '<td>'+human_plural_form(0, days,  new Array('день', 'дня', 'дней')) +'</td><td class="time_line"></td>' : '')+
		  									(hours>0 ? '<td>'+human_plural_form(0, hours, new Array('час', 'часа', 'часов')) +'</td><td class="time_line"></td>' : '')+
		  									(mins>0 ?  '<td>'+human_plural_form(0, mins,  new Array('минута', 'минуты', 'минут')) +'</td>' : '')+
		  									(secs>0 ?  '<td class="time_line"></td><td>секунд</td>' : '')+	  									
		  									'</tr></table>';
  }
	  
  
  
  
  if (CountActive) setTimeout("CountBack("+(seconds+CountStepper)+", '"+ div_id+"', "+type_deal+")", SetTimeOutPeriod);
}




function CountBack_All(secs, id) {

  var seconds = secs;
	
   
  // days
  var days  = Math.ceil(secs / 86400) - 1;
  secs -= days * 86400;
  
  
  // hours
  var hours = Math.ceil(secs / 3600) - 1;
  secs -= hours * 3600;
  
  // minutes
  var mins  = Math.ceil(secs / 60) - 1;
  secs -= mins * 60;
     
  if (days < 10) {
	  days = '0'+days;
	  }
  if (hours < 10) {
	  	hours = '0'+hours;
	  }
	  
  if (mins < 10) {
	  	mins = '0'+mins;
	  } 
  
  if (secs < 10) {
	  	secs = '0'+secs;
	  } 
  
  if (document.getElementById(id+'days'))	 document.getElementById(id+'days').innerHTML  = days; 
  if (document.getElementById(id+'hrs'))	 document.getElementById(id+'hrs').innerHTML = hours;
  if (document.getElementById(id+'min'))	 document.getElementById(id+'min').innerHTML  = mins;
  if (document.getElementById(id+'sec'))	 document.getElementById(id+'sec').innerHTML  = secs;
  
  
  
  if (CountActive) setTimeout("CountBack_All("+(seconds+CountStepper)+", '"+ id+"')", SetTimeOutPeriod);
}




/*----------------------------------------------------
opacity.js
------------------------------------------------------*/
/*
wwww.tigir.com - 06.07.2006

Source: http://www.tigir.com/js/opacity.js

Библиотека opacity.js к статье "CSS прозрачность (css opacity, javascript opacity)" - http://www.tigir.com/opacity.htm

setElementOpacity - установка прозрачности
getOpacityProperty - проверка, есть ли возможность менять прозрачность
fadeOpacity - плавное изменение прозрачности
*/

/* Функция кроссбраузерной установки прозрачности

Пример: setElementOpacity(document.body, 0.5); //сделать документ прозрачным на половину
*/
function setElementOpacity(oElem, nOpacity)
{
        var p = getOpacityProperty();
        (setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;        var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;        if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
}

// Функция getOpacityProperty() возвращает свойство которое используется для смены прозрачности или undefined, и может использоваться для проверки возможности изменения прозрачности
function getOpacityProperty()
{
        var p;
        if (typeof document.body.style.opacity == 'string') p = 'opacity';
        else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
        else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
        else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';

        return (getOpacityProperty = new Function("return '"+p+"';"))();
}

/* Функции для плавного изменения прозрачности:

1) fadeOpacity.addRule('opacityRule1', 1, 0.5, 30); //вначале создаем правило, задаем имя правила, начальную прозрачность и конечную, необязательный параметр задержки, влийяющий на скорость смены прозрачности
2) fadeOpacity('elemID', 'opacityRule1'); // выполнить плавную смену прозрачности элемента с id равным elemID, по правилу opacityRule1
3) fadeOpacity.back('elemID'); //вернуться в исходное сотояние прозрачности
*/
function fadeOpacity(sElemId, sRuleName, bBackward)
{
        var elem = document.getElementById(sElemId);
        if (!elem || !getOpacityProperty() || !fadeOpacity.aRules[sRuleName]) return;

        var rule = fadeOpacity.aRules[sRuleName];
        var nOpacity = rule.nStartOpacity;

        if (fadeOpacity.aProc[sElemId]) {clearInterval(fadeOpacity.aProc[sElemId].tId); nOpacity = fadeOpacity.aProc[sElemId].nOpacity;}
        if ((nOpacity==rule.nStartOpacity && bBackward) || (nOpacity==rule.nFinishOpacity && !bBackward)) return;

        fadeOpacity.aProc[sElemId] = {'nOpacity':nOpacity, 'tId':setInterval('fadeOpacity.run("'+sElemId+'")', fadeOpacity.aRules[sRuleName].nDalay), 'sRuleName':sRuleName, 'bBackward':Boolean(bBackward)};
}

fadeOpacity.addRule = function(sRuleName, nStartOpacity, nFinishOpacity, nDalay){fadeOpacity.aRules[sRuleName]={'nStartOpacity':nStartOpacity, 'nFinishOpacity':nFinishOpacity, 'nDalay':(nDalay || 30),'nDSign':(nFinishOpacity-nStartOpacity > 0?1:-1)};};

fadeOpacity.back = function(sElemId){fadeOpacity(sElemId,fadeOpacity.aProc[sElemId].sRuleName,true);};

fadeOpacity.run = function(sElemId)
{
        var proc = fadeOpacity.aProc[sElemId];
        var rule = fadeOpacity.aRules[proc.sRuleName];

        proc.nOpacity = Math.round(( proc.nOpacity + .1*rule.nDSign*(proc.bBackward?-1:1) )*10)/10;
        setElementOpacity(document.getElementById(sElemId), proc.nOpacity);

        if (proc.nOpacity==rule.nStartOpacity || proc.nOpacity==rule.nFinishOpacity) clearInterval(fadeOpacity.aProc[sElemId].tId);
}
fadeOpacity.aProc = {};
fadeOpacity.aRules = {};



/*
* Функция для всплывающего дива с затемненным бг. параметры: id - id дива, width - ширина дива 
*/


function show_pickup(id, width, height)
{
	var block_width  = width  || 690;
	var block_height = height || 480;
	
	$.blockUI({
        message: $('#pickup_'+id),
        css: { 
        		top:  ($(window).height() - block_height) /2 + 'px', 
                left: ($(window).width() - block_width) /2 + 'px', 
                background: '#ffffff', 
                width: block_width+'px',
                'max-height':'480px',
        		border: 'none',
        		'-webkit-border-radius': '10px', 
            	'-moz-border-radius': '10px',
            	cursor:'auto'
            },
        overlayCSS:  { 
        cursor: 'auto'
    	} 
    });
    $('.blockOverlay').attr('title','').click($.unblockUI); 
}

function close_pickup()
{
	$.unblockUI();	
}

function rate_photo(rate, photo_id)
{
	var note = ''
	$.post('/photofest/rate_photo.php', 
			{ 
				'rate': rate,
				'photo_id': photo_id
			}, 
			function(data)
			{   
				if (data>0)
				{
					note = 'Рейтинг фото: <b class="red">'+data+'</b>';
					if (document.getElementById('rate_parent_photo_div'+photo_id))
					{
						document.getElementById('rate_parent_photo_div'+photo_id).innerHTML = note;
					}		
					note += '<br><br><b>Спасибо. Ваш голос учтен.</b>';					
				}
				else
				{
					note = '<b>Не удалось сохранить данные. Попробуйте позже.</b>';
				}
				document.getElementById('rate_photo_div'+photo_id).innerHTML = note;				
			});
			
} 

function refreshimg_f()
{
   document.getElementById('code_send').src='/cap/Captcha.php?rnd='+Math.round(Math.random(0)*1000);
}

/**
* @param $number int число чего-либо
* @param $titles array варинаты написания для количества 1, 2 и 5 
* @return string
*/
function human_plural_form(id, number, titles){
    
	var cases = new Array (2, 0, 1, 1, 1, 2);
	var value = titles[(number%100>4 && number%100<20) ? 2 : cases[Math.min(number%10, 5)]];
	if (id) {		
		document.getElementById(id).innerHTML = value;
	} else {
		return value;
	}
		
    
}