function init_preview_info(){
  $('.recomend_bg, .recomend_wrap').unbind("mouseenter").unbind("mouseleave").bind("mouseenter",function(){
    $('div.href_slide', $(this)).slideDown(200);
  }).bind("mouseleave",function(){
    $('div.href_slide', $(this)).slideUp(200);
  });   
  $('#recomend_line a.recomend_title').each(function(){
    hepernate($(this));
  });
}
function init_context_menu(){
  $('.context_user .user_expand').click(function(e){
    pnt = $(this).parent();
    if (pnt.hasClass('context_user_on')){
      pnt.next('.context_name_show').removeClass('context_name_show').addClass('context_name');
      pnt.removeClass('context_user_on');
      $('.context_list_on', pnt).removeClass('context_list_on').addClass('context_list');
      $('body').unbind('click');
    }else{
      $('body').bind('click',function(){
        $('.context_user_on').removeClass('context_user_on');
        $('.context_list_on').removeClass('context_list_on').addClass('context_list');
        $('.context_name_show').removeClass('context_name_show').addClass('context_name');
      });
      func_hide_context();
      pnt.addClass('context_user_on');
      pnt.next('.context_name').removeClass('context_name').addClass('context_name_show');
      $('.context_list', pnt).removeClass('context_list').addClass('context_list_on');
    }
  });
} // init_context_menu

function msg_submit(){
  if ($('#input_msg').val()!=''){
    request('popup_submit_send_msg', 'msg_form');
    $('#DialogContainer').html('');
  }
} // msg_submit

function f_play_sample(){

} // f_play_sample

function cicle_img(d){
    var b1 = $('#btn_img_left');
    var b2 = $('#btn_img_right');
    var cc = parseInt($('#active_cover').val());
    var cn = cc+d;
    var zo = $('#btn_zoom');
    var zp = parseInt($('#cover_place img:eq('+(cn)+')').attr('zm'));
    
    if (d>0 && b1.hasClass('img_left_no')) b1.removeClass('img_left_no').addClass('img_left');    
    if (d<0 && b2.hasClass('img_right_no')) b2.removeClass('img_right_no').addClass('img_right');    
    if (d<0 && !$('#cover_place img:eq('+(cn+d)+')')[0]) b1.removeClass('img_left').addClass('img_left_no');    
    if (d>0 && !$('#cover_place img:eq('+(cn+d)+')')[0]) b2.removeClass('img_right').addClass('img_right_no');    
    
    if ($('#cover_place img:eq('+(cn)+')')[0]){
        if (zp==1 && zo.hasClass('zoom_off')){
            zo.removeClass('zoom_off').addClass('zoom_on');
        }else if(zp==0) zo.removeClass('zoom_on').addClass('zoom_off');
    }
    
    var t = 0;
    if ($('#cover_place img:eq('+(cn)+')')[0]){
        $('#active_index').val($('#cover_place img:eq('+(cn)+')').attr('ind'));
        np = d > 0  ? 280 : -280;
        $('#active_cover').val(cn);        
        if (d<0){
            $('#cover_place img:eq('+(cc)+')').css({'display':'none'});
            $('#cover_place img:eq('+(cn)+')').css({'left':0,'display':'none'});
            $('#cover_place img:eq('+(cn)+')').fadeIn(300);            
        }else {
            $('#cover_place img:eq('+(cc)+')').css({'left':0,'display':'none'});
            $('#cover_place img:eq('+(cn)+')').css({'left':0,'display':'none'}).fadeIn(300);
        }        
    }    
} // cicle_img
function hepernate(o){  
    var RusA = "[абвгдеёжзийклмнопрстуфхцчшщъыьэюя]";
    var RusV = "[аеёиоуыэю\я]";
    var RusN = "[бвгджзклмнпрстфхцчшщ]";
    var RusX = "[йъь]";
    var Hyphen = "\xAD";

    var re1 = new RegExp("("+RusX+")("+RusA+RusA+")","ig");
    var re2 = new RegExp("("+RusV+")("+RusV+RusA+")","ig");
    var re3 = new RegExp("("+RusV+RusN+")("+RusN+RusV+")","ig");
    var re4 = new RegExp("("+RusN+RusV+")("+RusN+RusV+")","ig");
    var re5 = new RegExp("("+RusV+RusN+")("+RusN+RusN+RusV+")","ig");
    var re6 = new RegExp("("+RusV+RusN+RusN+")("+RusN+RusN+RusV+")","ig");
    
    text = o.html();
    text = text.replace(re1, "$1"+Hyphen+"$2");
    text = text.replace(re2, "$1"+Hyphen+"$2");
    text = text.replace(re3, "$1"+Hyphen+"$2");
    text = text.replace(re4, "$1"+Hyphen+"$2");
    text = text.replace(re5, "$1"+Hyphen+"$2");
    text = text.replace(re6, "$1"+Hyphen+"$2");
    o.html(text);
}

function add_node(n_id, n_tag){
  $('#' + n_id + ' div.e_color').remove();
  $('#' + n_id + ' input.mark').removeClass('mark');
  n = $('#' + n_id + ' ' + n_tag + ':eq(0)');  
  n = n.html();
  $('#' + n_id).append('<'+n_tag+'>' + n + '</'+n_tag+'>');
  n = $('#' + n_id + ' ' + n_tag ).length;
  $('#' + n_id + ' ' + n_tag + ':last span.mw25').html(n +'.');
  $('#' + n_id + ' ' + n_tag + ':last input:eq(0)').val('').removeClass('mark');
  $('#' + n_id + ' ' + n_tag + ':last textarea:eq(0)').val('').removeClass('mark');
} // add_node

function remove_node(n_id, p){
    if (!$(p).parent().hasClass('hold')) $(p).parent().remove();
    else{
        var li = $(p).parent();
        $('input',li).val('');
    }
    var x = 1;
    $('#' + n_id + ' li span.mw25').each(function(){
        $(this).html(x+'.');
        x+=1;
    });
} // remove_node
function float_v(obj, mx){
    v = parseFloat($(obj).val());
    if (mx > 0 && v > mx) v = mx;
    if (isNaN(v)) $(obj).val('0.00');
    else $(obj).val(v.toFixed(2));
    
} // tf
function explode( delimiter, string ) {    // Split a string by string
    // 
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: kenneth
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
 
    var emptyArray = { 0: '' };
 
    if ( arguments.length != 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
 
    return string.toString().split ( delimiter.toString() );
}

function int_v(o){
    k = parseInt($(o).val());
    if (isNaN(k)){
      $(o).val('');
      k = 0;
    }
    return k;
} // int_v

function get_current_page(hash, m) {
    if (m == 0) var reg=/page=(\d*)/;
    else var reg=/#page=(\d*)/;
    arr=reg.exec(hash);
    return arr ? arr[1] : 0;
}
function randomString(string_length){
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var randomstring = '';
    for (var i=0; i<string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum,rnum+1);
    }
    return randomstring;
} // randomString

function expand_div(d, o){    
    if ($(o).hasClass('btn_hide')){                        
        //  , path, domain, secure 
        Set_Cookie( 'display['+d+']', 1);
        $(o).removeClass('btn_hide').addClass('btn_show').attr('title', 'Развернуть');
        $('#'+d).slideUp(100);
        /*$("html,body").animate({scrollTop: $(o).offset().top-$('#'+d).height()}, 300);*/
    }else{        
        Set_Cookie( 'display['+d+']', 0);
        $(o).addClass('btn_hide').removeClass('btn_show').attr('title', 'Свернуть');        
        $('#'+d).slideDown(100);
        /*$("html,body").animate({scrollTop: $(o).offset().top}, 300);*/
    }    
} // expand_div

function expand_object(d, o){
  if ($(o).hasClass('open')){            
    $(o).removeClass('open').addClass('closed');
    $('#'+d).slideUp();
  }else{
    //  Set_Cookie( name, value, expires, path, domain, secure );
    $(o).addClass('open').removeClass('closed');
    $('#'+d).slideDown();
  }
} // expand_div

function ut(){
    var foo = new Date;
    var unixtime_ms = foo.getTime();
//    var unixtime = parseInt(unixtime_ms / 1000);
    var unixtime = parseInt(unixtime_ms);
    return unixtime;
}
function href(hr, hra){	
    if (hra != '') document.location.href = hra;
    else{
        a = gup('a');
        if (a != '') t = '?a='+a+'&m='+hr;
        else{
            hr = hr.replace('?m=', '');
            t = '?m='+hr;
        }        
        document.location.href = t;
    }
}

function gup( name ){
    /*
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    return( results == null ) ? "" : results[1];
    */
    return name == 'a' ? $('#core_action').val() : $('#core_mode').val();
}

function isArray(a){
    return a && typeof a == 'object' && a.constructor == Array;
} // isArray

function isObject(o){
    return (o && "object" == typeof o) || isFunction(o);
} // isObject
                                               
function isFunction(o){
    return 'function' == typeof o;
} // isFunction

function getFormFields(fdata) {
    form = document.getElementById(fdata);
    var result = {};
    var form_elements = form.elements;
    var cnt = form_elements.length;
    var cc = new Array();
    var el_c = new Array();
    for (var i = 0; i < cnt; i++) {
        if (cc == undefined) cc[n] =0;
        var field = form_elements[i];
        
        var field_type = field.type;
        if (('button' == field_type) || ('submit' == field_type)) continue;
        var n = field.name.replace('[]','');
        //.replace(']','');
        //n = field.name;
        
        if (n == '') n = 'undefined';
        
        if ($(field).attr('alt') == $(field).val()){
            var v = '';
        }else{
            var v = field.value;            
        }
            
        if ('checkbox' == field_type && !field.checked) v = '';
        if ('radio' == field_type && !field.checked) continue;
        
        if (el_c[n] == undefined){
            a_input = $('#'+fdata+' input[name="'+n+'"]').length;
            a_text = $('#'+fdata+' textarea[name="'+n+'"]').length;
            a_select = $('#'+fdata+' select[name="'+n+'"]').length;
            el_c[n] = a_input + a_text + a_select;
            if (el_c[n] == 0) el_c[n] = $('#'+fdata+' textarea[name="'+n+'"]').length;
            if (el_c[n] == 0) el_c[n] = $('#'+fdata+' select[name="'+n+'"]').length;
            cc[n] = 0; 
        }        
        if (el_c[n] == 1) result[n] = v;
        else if ('radio' != field_type){
            result[n+'['+cc[n]+']'] = v;
            cc[n] += 1;
        }else result[n] = v;
    }
    return result;        
} // getFormFields


function request(mode, fdata, a){
    a = typeof(a) != 'undefined' ? a : gup('a');
    if ($('#btn_'+mode).hasClass('disabled')) return false;    
    dialogDisplayed = false;
    var popup = mode.indexOf('popup_');    
    var hidden = mode.indexOf('hidden_');
    var json = mode.indexOf('json_');

    if ($('#DialogContainer')[0]) dialogDisplayed =true;
    if (!dialogDisplayed && hidden<0) {
      $("body").prepend('<div id="jDialogProgressBar"><div class="loading_img"></div></div><div id="jDialogOverlay"></div><div id="jDialogContainer"></div>');
      overlayPos(1);
      dialogDisplayed=true;        
    }
    $("#jDialogProgressBar").show();
    
    url_get = '';
    if (document.getElementById(fdata)){
      send_data = jQuery.extend(getFormFields(fdata), {'m' : mode});
      if (a!='') url_get += '&form_name='+fdata;
      else url_get += '?form_name='+fdata;
    }else send_data = (isObject(fdata)) ? jQuery.extend(fdata, {'m' : mode}) : jQuery.extend({'id' : fdata}, {'m' : mode});
    
    
    var json = mode.indexOf('json_');
    
    dt = (popup >=0) ? 'text' : 'script';
    if (json >=0) dt = 'json';
    
    if (a!='') sr = '/index.php?a='+a+url_get;
    else sr = '/index.php'+a+url_get;
    $.ajax({
      type: 'POST',
      url: sr,
      data: send_data,
      dataType: dt,
      error: function(msg){               
      },
      success: function(msg){            
        if (popup>=0){
          var currentPos = true;
          $("#jDialogContainer").html('<div class="DialogContainer" id="DialogContainer">'+msg+'</div>');
          if (currentPos){
            reposition();
            $('#jDialogOverlay').bind('click', function(){$.closeDialog();});
          }
          $("#jDialogProgressBar").fadeOut(900);
          
          if($.browser.msie && parseInt($.browser.version) < 7) {
            $(window).scroll(function(){
              if(dialogDisplayed==1) {
                overlayPos();
                if (currentPos)
                    reposition();
              }
            });
          }
          $(window).resize(function(){
            if (dialogDisplayed==1) {
              overlayPos();
              if (currentPos)
                  reposition();
            }
          });
          
          $(window).unload( function () {
            if (dialogDisplayed==1)
                $.closeDialog();
          });
          
          $(window).keydown(function(event){
            if (event.keyCode == 27) 
                $.closeDialog();
          });
        }else if (hidden < 0){
            $.closeDialog();
        }else{
          $("#jDialogProgressBar").hide();
        }
      }
    });
} // request

function reposition(){ //calculate the position
  var left = 0;
  var top = 0;
  var winWidth = $(window).width();
  var winHeight =  $(window).height();
  var dialogHeight = $("#jDialogContainer").children().height();
  var dialogWidth = $("#jDialogContainer").children().width();
  
  var x = parseInt($("#popup_holder img:eq(0)").attr('width'));  
  if (x > dialogWidth){
    dialogWidth = x + 44;    
    $('#DialogContainer').css('width', dialogWidth);
  }
  /*alert(dialogWidth+':'+$("#jDialogContainer").children().outerWidth());*/
  
  if ($.browser.msie) {
    left = document.body.scrollLeft || document.documentElement.scrollLeft;
    top = document.body.scrollTop || document.documentElement.scrollTop;
  }else{
    left = window.pageXOffset;
    top = window.pageYOffset;
  }

  var topOff = top + winHeight/2 - dialogHeight/2; //offset for IE6
  var leftOff = left + winWidth/2 - dialogWidth/2; //offset for IE6
  var topFixed = topOff - top;
  var leftFixed = leftOff - left;
  
  if ($.browser.msie && parseInt($.browser.version) < 7) { // IE6
    $("#jDialogContainer").children().css({
        top: topOff,
        left: leftOff,
        position: "absolute",
        zIndex: (2001)
    }).show(); 
  }
  else{    // firefox and IE7
    $("#jDialogContainer").children().css({
        top: topFixed, 
        left: leftFixed, 
        position: "fixed", 
        zIndex: (2001)
    }).show();
  }
}

function disableSelection(ind){
    target = (ind.innerHTML) ? ind : document.getElementById(ind);
    if (target){
        if (typeof target.onselectstart!="undefined") //IE route
	        target.onselectstart=function(){return false}
            else if (typeof target.style.MozUserSelect!="undefined"){
                //Firefox route
	            target.style.MozUserSelect="none"
            }else target.onmousedown=function(){return false}
        target.onmousedown=function(){return false}        
	}
} // disableSelection


function overlayPos(init){
    var left = 0;
    var top = 0;
    var overlayWidth = $(window).width();
    var overlayHeight = $(document).height();
    var winHeight =  $(window).height();
    if ($.browser.msie && parseInt($.browser.version) < 7) { //if IE6
      $("#jDialogOverlay").css({
          top: 0, 
          left: 0, 
          width: overlayWidth, 
          height: overlayHeight, 
          position: "absolute",
          display: "block",
          color: '#000',
          zIndex: 1000
      });
    }else { //other browsers
      $("#jDialogOverlay").css({
          top: 0, 
          left: 0, 
          width: overlayWidth, 
          height: winHeight, 
          position: "fixed",
          display: "block",
          zIndex: 1000
      }).show();
    }
    
    if (init==1) {
      /*$("#jDialogOverlay").css("opacity", 0);
      $("#jDialogOverlay").fadeTo(200, 1);*/
    }
}
function unmark_field(f){
    $('#'+f + ' .mark').removeClass('mark');
    $('#'+f + ' div.e_color').remove();
} // unmark_field

function mark_field(f, m, ind){
  if (ind>=0) f = f + '[]';
  var eq = ind <= 0 ? 0 : ind;
  var o = $('[name="'+f+'"]:eq('+eq+')');    
  if (m!=''){
    /*o.attr('title',m);    */
    o.parent().append('<div class="e_color">'+m+'</div>');
  }
  o.addClass('mark').bind('change', function(){o.removeClass('mark');});
} // mark_field

function focus_on(o){
    setTimeout(function(){
        $('#'+o)[0].focus();
    }, 500);
}

function ls_mark_all(o,m,e){
    if (!$(o).attr('checked')) $('[name='+m+']').removeAttr('checked');
        else $('[name='+m+']').attr('checked','checked');
} // mark_all

function estop(e){
  if(!e) var e = window.event;
  e.cancelBubble = true;
//  e.returnValue = false;
  if (e.stopPropagation) {
    e.stopPropagation();
//    e.preventDefault();
  }
  /*if (typeof e == 'object') e.stopPropagation();*/
  return false;
}

function set_message(n){
    var p = $('#holder_new_message b:eq(0)');
    if (p[0]){
        if (!p.attr('num')) p.attr('num', n);
    }else{
        $('#holder_new_message').prepend('<b></b> ');
        //
    }
    if (p.attr('num')!=n){
        p.html('' + n + '').fadeOut().attr('num', n).fadeIn();
    }
} // set_message


function update_rate_panel(pn, x, cn){
    v = Math.floor(x);
    d = Math.round((x-v)*100)/100;
    //wid = Math.ceil(d*25);
    wid = d*25;
    s = $('#rate_panel_' + pn + ' a span.half_star');
    if (s[0]){
        s.css('width',wid);
        sdom = s.parent().html();
        s.parent().html('');
        $('#rate_panel_' + pn + ' a:eq('+v+')').html(sdom);
    }else{
        $('#rate_panel_' + pn + ' a:eq('+v+')').html('<span style="width:'+wid+'px;" class="half_star">&nbsp;</span>');
    }    
    $('#rate_panel_' + pn).attr('title', 'Оценка: '+x+' (голосов: '+cn+')');    
    $('#rate_panel_' + pn + ' a:lt('+v+1+')').removeClass('star_off').addClass('star_on');
    $('#rate_panel_' + pn + ' a:gt('+(v-1)+')').addClass('star_off');
    
    $('#rate_panel_' + pn + ' a').unbind();
    init_rate_panel('rate_panel_' + pn, x, 0);
} // update_rate_panel
function disable_rate_panel(pn, x, cn){
    update_rate_panel(pn, x, cn);    
    $('#rate_panel_' + pn + ' a').unbind().removeClass('star_over').attr('title','').addClass('cursor_def');
} // disable_rate_panel

function init_rate_panel(pn, mw, ds){    
  $('#' + pn + ' a').each(function(){$(this).attr('title', $(this).attr('row_id') + ' из 10');});
  $('#' + pn + ' a').bind('mouseover', function(o){
      v = parseInt($(this).attr('row_id'));
      $('#' + pn + ' a:lt('+v+')').removeClass('star_off').removeClass('star_on').addClass('star_over')
      $('#' + pn + ' a:lt('+v+') span.half_star').hide();        
  }).bind('mouseout', function(o){
      var mint = parseInt(mw);
      var mintx = mint > 1 ? mint - 1 : mint;
      $('#' + pn + ' a.star_over').removeClass('star_over');
      $('#' + pn + ' a:lt('+mint+')').addClass('star_on');
      $('#' + pn + ' a:gt('+(mintx)+')').addClass('star_off');
      if (mint == 0) $('#' + pn + ' a:eq(0)').addClass('star_off');
      $('#' + pn + ' a span.half_star').show();
  }).bind('click', function(){
      v = parseInt($(this).attr('row_id'));
      if (typeof ds == 'undefined') ds = 0;
      if (ds == 0) request(pn, {'id':parseInt($('#'+pn).attr('row_id')), 'val':v, 'object':$('#'+pn).attr('row_name')});
      else if (ds == 1) popup_reg();      
  });
} // init_rate_panel

function remove_album(n){
  request('remove_album', parseInt(n));
}
function refresh_img(){
    $('#capthca')[0].src = '/random_image.php?i='+ut();
}
function parseUri(sourceUri){
    var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];
    var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);
    var uri = {};
    
    for(var i = 0; i < 10; i++){
        uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
    }
    
    // Always end directoryPath with a trailing backslash if a path was present in the source URI
    // Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key
    if(uri.directoryPath.length > 0){
        uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
    }
    
    return uri;
}

function basename (path, suffix) {
    // Returns the filename component of the path 
    //
    // version: 910.820
    // discuss at: http://phpjs.org/functions/basename
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
    // *     example 2: basename('ecra.php?p=1');
    // *     returns 2: 'ecra.php?p=1'
    var b = path.replace(/^.*[\/\\]/g, '');
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    return b;
}
function popup_static(txt){    
    $("body").append('<div id="jDialogProgressBar"><div class="loading_img"></div></div><div id="jDialogOverlay"></div><div id="jDialogContainer"></div>');    
    overlayPos(1);
    $("#jDialogContainer").html('<div class="DialogContainer" id="DialogContainer"><div class="cb"><div class="bt"><div/></div><div class="i1"><div class="i2"><div class="i3" id="popup_holder"><a id="img_close_btn" class="jDialogClose"></a>'+txt+'</div></div></div><div class="bb"><div/></div></div></div>');
    $('#jDialogOverlay').bind('click', function(){$.closeDialog();});    
    $('#img_close_btn').bind('click', function(){$.closeDialog();});    
    setTimeout(function(){
      reposition();
      $('#input_msg').focus();
    }, 100);
} // popup_static



function Set_Cookie( name, value, expires, path, domain, secure ){
    // set time, it's in milliseconds    
    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ){
        expires = 1000 * expires * 60 * 60 * 24;
    } else expires = 1000*86400*365;
    
    if (Get_Cookie(name)) delete_cookie(name);
    
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}
    
    
function Get_Cookie( check_name ) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for ( i = 0; i < a_all_cookies.length; i++ )
    {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split( '=' );


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if ( cookie_name == check_name )
        {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if ( a_temp_cookie.length > 1 )
            {
                cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if ( !b_cookie_found )
    {
        return null;
    }
}

function delete_cookie( name, path, domain ) {
    if ( Get_Cookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
function func_config_reset(){
  delete_cookie('client_bg','',false);  
  $('body').css('background', 'url(/img/template/bg.png)');      
  Set_Cookie('client_bg', '/img/template/bg.png');
  $.closeDialog();
}
function func_topping(o, k){    
  $('a.active', $(o).parent()).removeClass('active');
  $(o).addClass('active');
  request('refresh_top_box', k);
} // func_topping
function func_slide_search(o, d){    
  if ($(o).hasClass('open')){    
    $('#'+d).slideUp(300, function(){
      $(o).removeClass('noborder open').addClass('closed');
    });
  }else{
    $('#'+d).slideDown(300, function(){
      $(o).addClass('noborder open').removeClass('closed');
    });
  }
}

function func_hide_context(){  
  $('.context_user_on').removeClass('context_user_on');
  $('.context_list_on').removeClass('context_list_on').addClass('context_list');
  $('.context_name_show').removeClass('context_name_show').addClass('context_name');
} // func_hide_context

function func_message_send(p_author){
  popup_static(p_message.html());  
  func_hide_context();
  $('#input_to').val(p_author);
  setTimeout(function(){
    reposition();
    $('#input_msg').focus();
  }, 100);
} // func_message_send
    
function func_bookmark_note(i, o){
  v = $(o).val();
  $.ajax({
    type: 'POST',
    url: '/index.php?m=subscribe_note',
    data: {'id':i, 'val' : v},
    dataType: 'script'
  });
} // func_bookmark_note
function func_bookmark_list_more(a, o){
  p = parseInt($(o).attr('rel'));
  m = parseInt($(o).attr('rev'));
  if (p > 0 && p * 5 < m){
    request('subscribe_more', {'page':p,'type':a});
    $(o).attr('rel', p+1);
  }else if(p < 0){
    request('subscribe_more', {'page':p,'type':a});
  }
} // func_bookmark_list_more
function func_article_tag(o){
  p = parseInt($(o).attr('rel'));
  m = parseInt($(o).attr('rev'));
  if (p > 0 && p * 4 < m){
    request('tag_article', {'page':p,'tag':$('#tag_article').val()});
    $(o).attr('rel', p+1);
  }else if(p < 0){
    request('tag_article', {'page':p,'tag':$('#tag_article').val()});
  }
} // func_article_tag
function f_genre(o, i){
  if (!$(o).hasClass('c_black')){
    $('a[rel="genre_toolbar"][row_id="'+i+'"]').addClass('bbox');
    $('a[genre_val="'+i+'"]').addClass('c_black');
  }else{
    $('a[genre_val="'+i+'"]').removeClass('c_black');    
    $('a[rel="genre_toolbar"][row_id="'+i+'"]').removeClass('bbox');
  }
  request('music_genre', {'id':i,'search':$('#paging_search').val()});
  
  $("html,body").animate({scrollTop: ($("#recomend_list").offset().top-48)}, 300);  
}
function cpanel_page(pk, p){
  $('#paging_page').val(p);
  request(pk, 'form_find');
}
function show_page(pk, p, d){
  request(pk,{'id':p,'d':d});
}
function reg_submit(){
  if ($('#agree')[0].checked == true){
    $('#e_submit').addClass('dn');
    $('#e_agree').addClass('dn');
    request('hidden_reg_submit', 'reg_form', '');
  }else if($('#agree')[0].checked == false) $('#e_agree').removeClass('dn');
} // local_submit

function valid_field(o){
  if (o=='pass'){
    v = $('#pass').val();
    if (v.length < 4 && v.length!=0){
      $('#v_pass').removeClass('dn');
    }else{
      $('#v_pass').addClass('dn');
    }
  }else if (o=='login'){
    v = $('#login').val();
    if (v.length !=0) request('hidden_valid_name', {'name':v}, '');
    else $('#e_login').addClass('dn');
  }else if (o=='email'){
    v = $('#email').val();
    if (v.length !=0) request('hidden_valid_email', {'email':v}, '');
    else{
      $('#e_email').addClass('dn');
      $('#e_email2').addClass('dn');
    }
  }
}


function init_week_draw(day_selected){
  var weekday=new Array("Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота");
  var monthlist=new Array("Января", "Февраля", "Марта", "Апреля", "Мая", "Июня", "Июля", "Августа", "Сентября", "Октября", "Ноября", "Декабря");
  var hm = $('#core_mode').val();
  w = parseInt($('#week_inc').val());
  var crDate = new Date($('#init_week_date').val());
  var tmpDate = new Date($('#init_week_date').val());
  var startDate = new Date($('#init_week_date').val());
  tmpDate.setDate(crDate.getDate()+(7 +w));
  startDate.setDate(crDate.getDate()+w);
  weekend = tmpDate.getDate();
  weekstart = startDate.getDate();
  var sameMonth = weekend<weekstart ? 0 : 1;
  var txt_weekstart = weekstart < 10 ? '0'+weekstart : weekstart;
  var txt_weekend = weekend < 10 ? '0'+weekend : weekend;        
  $('#span_week_start').html(txt_weekstart);
  $('#span_week_end').html(txt_weekend + ' ' + monthlist[tmpDate.getMonth()] + ' ' + tmpDate.getFullYear());
  $('.week_line a.poster_calendar_item').each(function(i){            
    n = i+w;
    var myDate = new Date($('#init_week_date').val());
    myDate.setDate(crDate.getDate()+n);            
    if (day_selected && n==0) $(this).addClass('active');            
    m = myDate.getMonth();
    b_text = sameMonth==1 ? myDate.getDate() : myDate.getDate();
    $('b', $(this)).html(b_text);
    $('font', $(this)).html(weekday[myDate.getDay()]);
    dd = myDate.getDate();
    if (dd<10) dd = '0'+dd;
    m += 1;
    if (m<10) m = '0'+m;
    hr =  myDate.getFullYear() + '-' + m + '-' + dd;
    $(this).unbind('click').click(function(){               
      if ($(this).hasClass('active') && !day_selected){
        //  $('#poster_list div.recomend[poster_date]').animate({'opacity':1}, 300);
        $('#poster_list div.recomend[poster_date]').show();
        $('#poster_day_empty').hide();
        $(this).removeClass('active');
      }else{
        /*$('#poster_list div.recomend[poster_date!="'+$(this).attr('row_id')+'"]').animate({'opacity':0.01}, 300);
        $('#poster_list div.recomend[poster_date="'+$(this).attr('row_id')+'"]').animate({'opacity':1}, 300);*/
        
        $('#poster_list div.recomend[poster_date!="'+$(this).attr('row_id')+'"]').hide();
        
        sh = $('#poster_list div.recomend[poster_date="'+$(this).attr('row_id')+'"]');
        sh.show();
        
        if (sh.length == 0) $('#poster_day_empty').show();
        else $('#poster_day_empty').hide();
        
        $('#poster_calendar_line a.poster_calendar_item.active').removeClass('active');
        $(this).addClass('active');
      }            
    }).attr('row_id', hr);                        
  });
} // init_week_draw

function poster_week_show(){
  $('#poster_list div.recomend[poster_date]').show();
  $('#poster_day_empty').hide();
  $('.week_line a.poster_calendar_item').removeClass('active');
}
function week_select(d){
  $('#poster_calendar_line a.poster_calendar_item.active').removeClass('active');    
  $.ajax({
    type: 'POST',
    url: '/index.php?a=poster&m=get_week',
    data: {'d':d, 'c' :$('#core_mode').val(),'w':$('#init_week_date').val()},
    dataType: 'script',
    error: function(msg){
      $('#poster_list, .week_line a.poster_calendar_item').animate({'opacity':1}, 100);            
    },
    success: function (msg){
      $('#poster_list').css('background', 'none');
      $('#poster_list, .week_line a.poster_calendar_item').animate({'opacity':1}, 100);            
    }
  });
  $('#poster_list, .week_line a.poster_calendar_item').animate({'opacity':0.5}, 100);
}
function f_tab_up(c,i,o){
  $(c).hide();
  $(i).show();
  $('#dlg_toolbar a.dgl_href_active').removeClass('dgl_href_active').addClass('dgl_href');
  $(o).addClass('dgl_href_active_b').removeClass('dgl_href');
  reposition();    
}
function init_gift_info(){
  $('#gift_list a.wallet_present_item').click(function(){                    
    popup_static(p_gift);
    $('#gift_info_img').attr('src','/resource/gift/'+$(this).attr('rev')+'.png');                    
    $('#gift_info_title').html($(this).attr('title'));
    $('#gift_info_note').html($(this).attr('rel'));
    
    u = $(this).attr('from');
    $('#gift_info_from').html(u).attr('href', '/user/'+u);                  
    $('#gift_info_date').html($(this).attr('date'));
  });
}
function w_request(m, x){
  $('#DialogContainer').css('zIndex', 500);
  $('#'+m+' input.input_error').removeClass('input_error');
  $('#'+m+' .e_on').html('').removeClass('e_on');
  
  $.ajax({
      type: 'POST',
      url: '/index.php?m='+m,
      data: typeof x == 'undefined' ? jQuery.extend(getFormFields(m), {'core_action' : $('#core_action').val()}) : {'id':x},
      dataType: 'json',
      error: function(msg){               
      },
      success: function(msg){
        if (typeof msg == 'object')
        {
          if (msg.gift)
          {
            $('#gift_list').html(msg.gift);
            $('#profile_gift_total').html(msg.gift_total);
            $('#head_deposit').html(msg.deposit);
            dialogDisplayed = false;
            $("#jDialogContainer, #jDialogProgressBar, #jDialogOverlay").remove();
            if (parseInt(msg.gift_total)>10) $('#profile_gift_all').show();            
            init_gift_info();
          } else if (msg.error) {            
            $('#DialogContainer').css('zIndex', 2001);
            if (msg.error.dom) $('#' + msg.error.dom).html(msg.error.msg).addClass('e_on');
            $('#' + msg.error.input).addClass('input_error');
          } else if (msg.history){
            $('#DialogContainer').css('zIndex', 2001);
            $('#dlg_window0').html(msg.history);
          } else {
            p_wallet = msg.content;
            $('#head_deposit').html(msg.deposit);
            if (msg.rate) $('#head_rating').html(msg.rate);
            dialogDisplayed = false;
            $("#jDialogContainer, #jDialogProgressBar, #jDialogOverlay").remove();
            popup_static(p_wallet);
          }
        } else $('#DialogContainer').css('zIndex', 2001);
      }
  });
}
function f_tab(c,i,o){
  $(c).hide();
  $(i).show();
  $('a.dgl_href_active_b').removeClass('dgl_href_active_b').addClass('dgl_href');
  $('a', $(o).parent()).removeClass('dgl_href_active').addClass('dgl_href');
  $(o).addClass('dgl_href_active').removeClass('dgl_href');
  reposition();
}
function p_wallet_send(n){  
    popup_static(p_wallet);
  $('#popup_holder div.dlg_window').hide();
  $('#dlg_toolbar a.dgl_href_active').removeClass('dgl_href_active').addClass('dgl_href');
  $('#dlg_window2').show();
  $('#dlg_toolbar a:eq(1)').removeClass('dgl_href').addClass('dgl_href_active');
  $('#wallet_send_name_input').val(n);
}
function p_wallet_present(n){  
  popup_static(p_wallet);
  $('#popup_holder div.dlg_window').hide();
  $('#dlg_toolbar a.dgl_href_active').removeClass('dgl_href_active').addClass('dgl_href');
  $('#dlg_window4').show();
  $('#dlg_toolbar_gift').removeClass('dgl_href').addClass('dgl_href_active');
  $('#wallet_gift_name_input').val(n);
}
function f_wallet_present(o){
  $('#input_gift_id').val($(o).attr('rel'));
  $('#wallet_present_window a.wallet_present_on').removeClass('wallet_present_on').addClass('wallet_present');
  $(o).addClass('wallet_present_on').removeClass('wallet_present');
}
function f_wallet_rate(o){
  b = parseInt($('#banana_nominal').html());
  w = parseFloat($('#f_wallet_rate_init').html().replace(',','.').replace(' ',''));
  v = int_v($(o));
  if (v > b)
  {
    v = b;
    $(o).val(b);
  } else if (v < 0) {
    v = 0;
    $(o).val(0);
  }
  p = roundNumber(w + v*0.1, 2);
  $('#f_wallet_rate_upd').html(p.toString().replace('.',','));
}
function roundNumber(num, dec) {
  var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
  return result;
}

