var LinkDivActive = 0;
var onDiv;
var timeOnDiv;
var layerRef;
var styleRef;
var showVar;
var hideVar;
var hideDivi;
var showDivi;
var currentCommentForm='0';
var mynews_tag_select = '';
if (navigator.appName == "Netscape") {
 layerRef="document.";
 styleRef="";
 showVar="'show'";
 hideVar="'hide'";
 showDivi="''";
 hideDivi="'none'";
} else {
 layerRef="document.all.";
 styleRef=".style";
 showVar="'visible'";
 hideVar="'hidden'";
 showDivi="''";
 hideDivi="'none'";
}
function banfileSubmit(form, reason) {
  if ($.trim(document.getElementById(reason).value).length==0) {
    alert('Укажите причину запрета!');
  } else if (confirm("Вы уверены?")) {
    document.getElementById(form).submit();
  }
  return false;
}
function flashComplete(data) {
  document.getElementById('publicfilesid').value = data;
  document.getElementById('publicfiles').submit();
}
function strip_tags(str, allowed_tags) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Marc Palau
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Eric Nagel
    // +      input by: Bobby Drake
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
    // *     example 4: strip_tags('1 < 5 5 > 1');
    // *     returns 4: '1 < 5 5 > 1'
    var key = '', allowed = false;
    var matches = [];
    var allowed_array = [];
    var allowed_tag = '';
    var i = 0;
    var k = '';
    var html = '';
    var replacer = function(search, replace, str) {
        return str.split(search).join(replace);
    };
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
    }
    str += '';
    // Match tags
    matches = str.match(/(<\/?[\S][^>]*>)/gi);
    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
         // Save HTML tag
        html = matches[key].toString();
         // Is tag not in allowed list? Remove from str!
        allowed = false;
         // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;
             if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
             // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
    return str;
}
function mynewsSubmit(noshowmess) {
  var bOk = true,
    errtext = "",
    newshead = $.trim($("#newshead").val()),
    newsannounce = $.trim(strip_tags($("#newsannounce").val())),
    newstext = $.trim(strip_tags(newstext_obj.getPageHtml(newstext_page))); // fix it
  if  (newshead.length == 0) {
    if (bOk) $("#newshead").focus();
    bOk = false;
    errtext += "<p>Заголовок не должен быть пустым</p>";
  }
  if  (newshead.length > 500) {
    if (bOk) $("#newshead").focus();
    bOk = false;
    errtext += "<p>Заголовок не должен превышать 500 символов</p>";
  }
  if  (newsannounce.length == 0) {
    if (bOk) $("#newsannounce").focus();
    bOk = false;
    errtext += "<p>Анонс не должен быть пустым</p>";
  }
  if  (newsannounce.length > 5000) {
    if (bOk) $("#newsannounce").focus();
    bOk = false;
    errtext += "<p>Анонс не должен превышать 5000 символов</p>";
  }
  if  (newstext.length == 0) {
    if (bOk) newstext_obj.focus();
    bOk = false;
    errtext += "<p>Текст не должен быть пустым</p>";
  }
//  if  (newstext.length > 10240) {
//    if (bOk) newstext_obj.focus();
//    bOk = false;
//    errtext += "<p>Текст не должен превышать 10240 символов</p>";
//  }
  if (!bOk) {
    showJsAlert("Ошибка", errtext);
    return false;
  } else {
    if (noshowmess) document.newssend.noshowmess.value = 'no';
    SpawPGcore.codeCleanupClick(newstext_obj.getTargetEditor(),newstext_obj.getToolbarItem('newstext_tools_0'));
    setTimeout('document.newssend.submit();', 500);
  }
}
function changeForumPartSubmit(el) {
  if (el.value!='')  {
    if (confirm("Вы уверены?")) {
      document.changeforumpartform.submit();
    } else el.selectedIndex = 0;
  }
}
function getMyNewsTagSelect(el) {
  document.getElementById('mynewstags-'+mynews_tag_select).style.display = 'none';
  document.getElementById('mynewstags-'+el.value).style.display = 'block';
  mynews_tag_select = el.value;
}
//Divisions Show | Hide
function switchDiv(divn) {
      eval('if ('+'document.getElementById(\''+divn+'\')'+styleRef+'.visibility == '+hideVar+') {showDiv(divn);} else {hideDiv(divn);}');
}
function hideDiv(divn) {
 eval('document.getElementById(\''+divn+'\')'+styleRef+'.visibility = '+hideVar);
 eval('document.getElementById(\''+divn+'\')'+styleRef+'.display = '+hideDivi);
}
function showDiv(divn) {
 eval('document.getElementById(\''+divn+'\')'+styleRef+'.visibility = '+showVar);
 eval('document.getElementById(\''+divn+'\')'+styleRef+'.display = '+showDivi);
}
//Link Divisions Stuff
function showLinkDiv(divn) {
 if (timeOnDiv != null) {
  clearTimeout(timeOnDiv);
  hideDiv(onDiv);
 }
 showDiv(divn);
 onDiv = divn;
}
function divTimer() {
 timeOnDiv = setTimeout("divOut()",500)
}
function divOut() {
 if (LinkDivActive == 0) {
  hideDiv(onDiv);
 }
}
function LinkDivOver() {
 LinkDivActive = 1;
 clearTimeout(timeOnDiv);
}
function LinkDivOut() {
 LinkDivActive = 0;
 timeOnDiv = setTimeout("divOut()",500)
}
function check_form (confirmMsg) {
      var is_confirmed = confirm(confirmMsg);
      return is_confirmed;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
 window.open(theURL,winName,features);
}
function open_winiid(url) {
 mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=550,height=414');
}
function clearSearch() {
      if (document.getElementById('textasrc').value=="  Поиск:") {
            document.getElementById('textasrc').value='';
      }
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function makeCalendarChoice(alias) {
      location.href='/'+alias+'/'+document.getElementById('archiveyear').value+'/'+document.getElementById('archivemonth').value+'/';
}
function hideAllHREF(sDivNameHREF) {
      if (! (document.getElementById))return;
      var i=0;
      while (true){
            if (document.getElementById) {
                  var obj = document.getElementById(sDivNameHREF+i);
                  if (obj) {
                        obj.className = "";
                        i++;
                  }
                  else return;
            } else break;
      }
}
function setDivNews(showingimage,sDivNameHREF,pict,num) {
      hideAllHREF(sDivNameHREF);
      var obj = document.getElementById(sDivNameHREF+num);
      if (obj) {
            obj.className = "newshrefclass";
      }
      var tempmap="";
      if (pict!="") {
            tempmap=tempmap+'<img src="'+pict+'" border=0 alt="">';
      }
      document.getElementById(showingimage).innerHTML=tempmap;
      return false;
}
/*
function cancelSetCommentForm() {
  if($oldparent = document.getElementById('clone-commentsend')) {
    $oldparent = $oldparent.parentNode;
    $('.actions a', $oldparent.parentNode).eq(0).html('Ответить');
    //$('form#clone-commentsend').remove();
    $($oldparent).html('').hide();
    $($oldparent).parent().height('auto');
  }
}
function setCommentForm($to, text) {
  var $box = $('#commentform'+$to);
  if ($box.css('display') == 'none') {
    $('.actions a', $box.parent()).eq(0).html('Отмена');
    oldtext = $box.context.getElementsByTagName('textarea')[0].value || '';
    cancelSetCommentForm();
    $box.html('<h2>Добавить комментарий:</h2>');
    if ($.browser.msie) {
      var clone = document.getElementById('commentsend').cloneNode(true);
      //clone.setAttribute('id', 'clone-commentsend';
      var a = clone.getElementsByTagName('a')[0];
      a.setAttribute('onclick', "");
      a.onclick = function() {
        sendCommentForm('clone-commentsend','clone-commenttextid');
      }
      var orig = $('form#commentsend').find("*").andSelf(), i = 0;
      $([clone]).find("*").andSelf().each(function(){
        if ( this.nodeName !== orig[i].nodeName )
          return;
        var events = jQuery.data( orig[i], "events" );
        for ( var type in events ) {
          for ( var handler in events[ type ] ) {
            jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
          }
        }
        i++;
      });
      document.getElementById('commentform'+$to).appendChild(clone);
      document.getElementById('commentform'+$to).getElementsByTagName('form')[0].id = 'clone-commentsend';
      document.getElementById('commentform'+$to).getElementsByTagName('textarea')[0].id = 'clone-commenttextid';
    } else {
      var clone = $('form#commentsend').clone(true);
      $('textarea', clone).attr('id', 'clone-commenttextid');
      $('.orange-button a', clone).removeAttr('onclick').click(function() {
        sendCommentForm('clone-commentsend','clone-commenttextid');
      });
      $(clone).attr('id', 'clone-commentsend');
      $box.append(clone);
    }
    $box.show();
    $box.context.getElementsByTagName('textarea')[0].value = oldtext + (text || '');
    $("input[name='pagetype']", 'commentform'+$to).val('curr');
  } else {
    if (text) {
      $textarea = $box.context.getElementsByTagName('textarea')[0];
      $textarea.value = $textarea.value + (text || '');
    } else {
      $('.actions a', $box.parent()).eq(0).html('Ответить');
      cancelSetCommentForm();
    }
  }
  return false;
}
*/
function cancelSetCommentForm() {
  return setCommentForm(0);
}
/*
function citoCommentForm($to) {
  text = '<cite>'+$("#commentbody"+$to).html()+'</cite>';
  return setCommentForm($to, text);
}*/
function setCommentForm(commentFormNumber, text) {
  if (commentFormNumber!=currentCommentForm) {
    var divCommentFormNew=document.getElementById('commentform'+commentFormNumber);
    var divCommentFormCurrent=document.getElementById('commentform'+currentCommentForm);
    if (divCommentFormCurrent && divCommentFormNew) {
      $(divCommentFormCurrent).parent().css('height', 'auto');
      document.getElementById("parentcommentid").value=commentFormNumber;
      $(divCommentFormNew).html('<h2>Добавить комментарий:</h2>');
      $('form#commentsend').appendTo(divCommentFormNew)
      $(divCommentFormNew).css("height", "auto");
      if (commentFormNumber*1!=0) {
        $(divCommentFormNew).css("height", $(divCommentFormNew).height()+'px');
        $('.actions a', divCommentFormCurrent.parentNode).eq(0).html('Ответить');
        $('.actions a', divCommentFormNew.parentNode).eq(0).html('Отмена');
        $box = $(divCommentFormNew);
        $f = $box.parent();
        $f.height($box.height()+ $f.height());
      }
      if (text) {
        $('#commenttextid').val($('#commenttextid').val()+text);
      }
      divCommentFormCurrent.innerHTML=' ';
      $("#commentform"+commentFormNumber).show();
      $("#commentform"+currentCommentForm).hide();
      currentCommentForm=commentFormNumber;
    }
  } else {
    if (text) {
      $('#commenttextid').val($('#commenttextid').val()+text);
    } else {
      $('.actions a', $('#commentform'+commentFormNumber).parent()).eq(0).html('Ответить');
      return cancelSetCommentForm();
    }
  }
  $("#pagetype").val((commentFormNumber*1!= 0) ? 'curr' :'last');
  //if (commentFormNumber!=0) document.getElementById('pagetype').value = 'curr';
  //else document.getElementById('pagetype').value = 'last';
  return false;
}
function citoCommentForm(commentFormNumber) {
  if (document.getElementById("commentbody"+commentFormNumber) && document.getElementById("commenttextid")) {
    //document.getElementById("commenttextid").value=document.getElementById("commenttextid").value+'<cite>'+document.getElementById("commentbody"+commentFormNumber).innerHTML+'</cite>';
    document.getElementById('pagetype').value = 'curr';
    return setCommentForm(commentFormNumber, '<cite>'+document.getElementById("commentbody"+commentFormNumber).innerHTML+'</cite>');
  }
  return false;
}
function sendCommentForm(formToCheck,sendedtext) {
  if(document.getElementById(formToCheck)) {
    if (document.getElementById(sendedtext)) {
      var textareatext=document.getElementById(sendedtext).value;
      if (textareatext.length>0) {
        document.getElementById(formToCheck).submit();
      }
    }
  }
  return false;
}
function getPosX(obj) {
  if (!obj) return 0;
  return (obj.offsetLeft + getPosX(obj.offsetParent));
}
function getPosY(obj) {
  if (!obj) return 0;
  return (obj.offsetTop + getPosY(obj.offsetParent));
}
function deleteSubmit(formToCheck) {
  if(document.getElementById(formToCheck)) {
    if (confirm('Вы уверены?')) {
      document.getElementById(formToCheck).submit();
    }
  }
  return false;
}
function deleteSubmit2(formToCheck,idInput,idValue,typeInput,typeValue) {
  if(document.getElementById(formToCheck)) {
    if (confirm('Вы уверены?')) {
      if (document.getElementById(idInput)) document.getElementById(idInput).value=idValue;
      if (document.getElementById(typeInput)) document.getElementById(typeInput).value=typeValue;
      document.getElementById(formToCheck).submit();
    }
  }
  return false;
}
function updateSubmit(formToCheck,updateInput) {
  if(document.getElementById(formToCheck)) {
    if (document.getElementById(updateInput)) {
      document.getElementById(updateInput).value='updatecomment';
      document.getElementById(formToCheck).submit();
    }
  }
  return false;
}
function sendNewsForm(formToCheck,newsHead,newsText) {
  if(document.getElementById(formToCheck)) {
    if(document.getElementById(newsHead)) {
      if (document.getElementById(newsText)) {
        var textareatext=document.getElementById(newsText).value;
        if (textareatext.length>0) {
          var textareatext=document.getElementById(newsHead).value;
          if (textareatext.length>0) {
            document.getElementById(formToCheck).submit();
          }
        }
      }
    }
  }
  return false;
}
function makeCalendarChoice1(alias) {
  var strhref='/'+alias+'/'+document.getElementById('archiveyear').value+'/'+document.getElementById('archivemonth').value+'/';
  if (document.getElementById('withphotosonly')) {
    if (document.getElementById('withphotosonly').checked) {
      strhref=strhref+'photos/';
    }
  }
  if (document.getElementById('withvideosonly')) {
    if (document.getElementById('withvideosonly').checked) {
      strhref=strhref+'video/';
    }
  }
  if (document.getElementById('withaudiosonly')) {
    if (document.getElementById('withaudiosonly').checked) {
      strhref=strhref+'audio/';
    }
  }
  location.href=strhref;
}
function addToFavorites() {
  window.external.AddFavorite (window.document.location, window.document.title);
  return false;
}
function ShowHideDiv(formid) {
  if (document.getElementById(formid)) {
    if (document.getElementById(formid).style.display!='none') {
      document.getElementById(formid).style.display='none';
    } else {
      document.getElementById(formid).style.display='block';
    }
  }
  return false;
}
function NewShowDiv(formid) {
  if (document.getElementById(formid)) {
    document.getElementById(formid).style.display='block';
  }
  return false;
}
function NewHideDiv(formid) {
  if (document.getElementById(formid)) {
    document.getElementById(formid).style.display='none';
  }
  return false;
}
function selectChange(el) {
  if (typeof(el)=='string') el = document.getElementById(el);
  if (el.value=='') return false;
  var count = document.messages_form.elements.length;
  var tf = false;
  for(var i=0; i<count; i++) {
    if (document.messages_form.elements[i].name.toLowerCase()=='message[]' && document.messages_form.elements[i].checked) {
      tf = true;
    }
  }
  if (!tf) {
    alert('Выберите хотя бы одно сообщение!');
    el.selectedIndex=0;
    return false;
  }
  if (!confirm('Вы уверены?')) {
    el.selectedIndex=0;
    return false;
  }
  var eldo = document.getElementById('do');
  eldo.value = 'actionmessages_'+el.value;
  document.messages_form.submit();
}
var to;
function ajaxcheckflag(o, e) {
  if (e=='up') {
    var id = '#'+$(o).attr("id");
    $(o).data("typing", false);
    to = setTimeout("ajaxcheckflag('"+id+"', 'check')", 1500);
  }
  if (e=='down') {
    $(o).data("typing", true);
    clearTimeout(to);
  }
  if (e=='check') {
    if (!$(o).data("typing")) ajaxcheckuser(o);
  }
}
function ajaxcheckuser(o) {
  $input = $(o), login = $input.val();
  if (login.length) {
  $.get(
    "/jqajax.php",
    { 'do': "checklogin", login: login },
    function(data){
      eval("data = "+data+";");
      if (data.stateResponse) {
        $input.css("border-color", "");
        $(o).parent().find("div.error-state").remove();
      } else {
        $input.css("border-color", "#e7b2b2");
        var errorText = '';
        $.each(data.dataResponse, function(key, o) {
          errorText += '<p class="'+key+'">'+
           (o.title ? '<b>'+o.title+'</b><br>' : '')+
          o.msg+'</p>';
        });
        if ($(o).parent().find("div.error-state").length) {
          $(o).parent().find("div.error-state").html(errorText);
        } else {
          $(o).parent().append('<div class="error-state"></div>').find("div.error-state").html(errorText);
        }
      }
    },
    "jsonObj"
  );
  } else {
    $(o).parent().find("div.error-state").remove();
  }
}
function showJsAlert(title, html, callback) {
  $('.js-alert-layout').remove();
  $('body').append('<div style="display:none;" class="draggable ui-draggable js-alert-layout" id="error-layout"><div class="bck"></div><div class="data"><h1></h1><a href="javascript:hideJsAlert()" class="cross"></a><div class="html-data"></div></div></div>');
  $errorLayout = $('.js-alert-layout').css({top: $(document).scrollTop()+192, left:'50%'});
  $('h1', $errorLayout).html(title);
  $('.cross', $errorLayout).click(function() {
    if (callback) callback();
    hideJsAlert();
  });
  $('.html-data', $errorLayout).html(html);
  $errorLayout.show().draggable({
    handle:'h1'
  });
}
function hideJsAlert() {
  $('.js-alert-layout').remove();
}
/* messages */
function checkLastMessages() {
  if (!($.browser.msie && $.browser.version<7)) {
    $.get(
      "/jqajax.php",
      { 'uid': uid, 'do':'checkmessages', 'r':Math.random() },
      function(data){
        eval("data = "+data+";");
        if (data.stateResponse) {
          showJsAlert('Новое сообщение', '<p>'+data.dataResponse.msg+'</p>');
        }
      },
      "jsonObj"
    );
    setTimeout("checkLastMessages()", 40000);
  }
};
function alertKickPrompt(id, url, name, o) {
  $box = $(o).parent().parent();
  if ($('.file-kickform', $box).length > 0) {
    $('.file-kickform', $box).remove();
  } else {
  $box.append('<form class="file-kickform" name="filebanform-'+id+'" id="filebanform-'+id+'" method="post" action="'+url+'"><input type="hidden" name="do" id="filebando-'+id+'" value="bannews"><input type="hidden" name="newsid" id="filebanid-'+id+'" value="'+id+'"><div class="input-box"><label>Укажите причину:<br><input class="gray-hovered" type="text" id="filebanreason-'+id+'" name="reason" class="reason"></label></div><div class="buttons" align="right"><a href="javascript:void(0)" onClick="return removeKickPrompt('+id+');">Отмена</a>   <a href="javascript:void(0)" onClick="return banfileSubmit(\'filebanform-'+id+'\', \'filebanreason-'+id+'\');">Запретить</a></div></form><b class="file-kickform clear"></b>');
  }
  return false;
}
function removeKickPrompt(id) {
  $("#filebanform-"+id).remove();
}
$(function() {
  checkLastMessages();
});
function miniChatShowSmiles(o) {
	if ($("#minichatSmiles").length > 0) {
		$("#minichatSmiles").remove();
		return false;
	}
	var docwidth = $('#layout').width(), docheight = $('#layout').height(), left = $(o).offset().left, top = $(o).offset().top, bubble = $('<div id="minichatSmiles"></div>').appendTo($("body"));
	var pathToSmiles = '/img/smiles/';
	var smiles = {':-)': 'smile-1.gif', ':-(': 'smile-2.gif',':)': 'smile-1.gif', ':(': 'smile-2.gif', ':-o': 'smile-3.gif', ':-D': 'smile-4.gif', ':-P': 'smile-5.gif', ':-I': 'smile-6.gif', ':-S': 'smile-7.gif', ';-)': 'smile-8.gif', ':-O': 'smile-9.gif', ':-*': 'smile-10.gif', '>:-0': 'smile-11.gif', '8-)': 'smile-12.gif', '$-D': 'smile-13.gif', ':-!': 'smile-14.gif', ':-<<': 'smile-15.gif', ':-\\': 'smile-16.gif', ':\'-(': 'smile-17.gif', ':-X': 'smile-18.gif', '(y)': 'smile-19.gif', '(n)': 'smile-20.gif', '(l)': 'smile-21.gif', '(u)': 'smile-22.gif', '(k)': 'smile-23.gif', '(g)': 'smile-24.gif', '(f)': 'smile-25.gif', '(b)': 'smile-26.gif', '(d)': 'smile-27.gif', '(t)': 'smile-28.gif', '(xx)': 'smile-29.gif', ':-/': 'smile-30.gif', ':-->': 'smile-31.gif', ':->': 'smile-32.gif', ':-))': 'smile-33.gif', ':x': 'smile-34.gif', 'X-(': 'smile-35.gif', ':-((': 'smile-36.gif', ':-B': 'smile-37.gif', 'I-)': 'smile-38.gif', ':-]': 'smile-39.gif', ':-[': 'smile-40.gif', ':-T': 'smile-41.gif', ':-J': 'smile-42.gif', ':-L': 'smile-43.gif', ':-C': 'smile-44.gif', ':-Z': 'smile-45.gif', ':-?': 'smile-46.gif', ';-P': 'smile-47.gif', ':-9': 'smile-48.gif', 'X-D': 'smile-49.gif', 'X-S': 'smile-50.gif', 'X-O': 'smile-51.gif', 'X-P': 'smile-52.gif', '8-O': 'smile-53.gif', ':-U': 'smile-54.gif', ':-,': 'smile-55.gif', ':-.': 'smile-56.gif', ':-\'': 'smile-57.gif', '(find)': 'smile-58.gif', ':\'-)': 'smile-59.gif', ':~)': 'smile-60.gif', ':~9': 'smile-61.gif', ':-Y': 'smile-62.gif', 'B:-)': 'smile-63.gif', 'I:-)': 'smile-64.gif', 'LMAO': 'smile-65.gif', ':\'S': 'smile-66.gif', ':\'C': 'smile-67.gif', 'X-)': 'smile-68.gif', 'X\'D': 'smile-69.gif', 'B-P': 'smile-70.gif', 'I-()': 'smile-71.gif', '>:-)': 'smile-72.gif', '>:-D': 'smile-73.gif', ':((': 'smile-74.gif', 'B-D': 'smile-75.gif', ':@)': 'smile-76.gif', ':(|)': 'smile-77.gif', '(~~)': 'smile-78.gif', '>-(': 'smile-79.gif', '%-)': 'smile-80.gif', ':-^': 'smile-81.gif', ';-^': 'smile-82.gif', 'X-^': 'smile-83.gif', ':\'D': 'smile-84.gif', 'O.O': 'smile-85.gif', 'O.o': 'smile-86.gif', '-.-': 'smile-87.gif', '-_-': 'smile-88.gif', '(victory)': 'smile-89.gif', '(ok)': 'smile-90.gif', '(five)': 'smile-91.gif'};
	jQuery.each(smiles, function(name, file) {
		$('<span class="smile"></span>').append('<img alt="'+name+'" style="cursor: pointer;" src="'+pathToSmiles+file+'" />').css('opacity', 0.7).click(function(){
			$("#messagetochat").val($("#messagetochat").val()+' '+$('img',this).attr("alt"));
		}).hover(
			function(){ $(this).css('opacity', 1); },
			function(){ $(this).css('opacity', 0.7); }
		).appendTo(bubble);
	});
	bubble.show().css({ top: (top+bubble.height()>=docheight-20) ? top-bubble.height()-25 : top+18, left:(left+bubble.width()>=docwidth-20) ? docwidth - bubble.width()-50 : left-100 });
	bubble.data("pos", { left:bubble.offset().left, top:bubble.offset().top, show:true });
}

function fileOp(sel) {
	if (sel.value!='') {
		var fileids = '';
		$('.file-check input:checkbox').each(function() {
			if (this.checked) {
				if (fileids) fileids += ',';
				fileids += this.value;
			}
		});
		if (fileids && confirm('Вы уверены?')) {
			$('#filesfuncid').val(fileids);
			$('#filesfuncdo').val(sel.value);
			$('#filesfunc').submit();
		} else {
			if (!fileids) alert('Выберите хотя бы один файл');
			sel.selectedIndex = 0;
		}
	};
}

function checkFormAndSubmit(form, fields) {
	if (!form) return false;
	
	//alert(1);
	
	if (typeof(form)=='string') {
		if (document.forms[form]) form = document.forms[form];
		else if (document.getElementById(form)) form = document.getElementById(form);
		else return false;
	}
	
	//alert(form);
	
	if (fields && fields.length) {
		if (typeof(fields)=="string") fields = new Array(fields);
		
		for(var i=0; i<fields.length; i++) {
			if (form.elements[fields[i]]) {
				switch(form.elements[fields[i]].type) {
					case 'radio':
					case 'select':
						if (!form.elements[fields[i]].value) {
							if (form.elements[fields[i]].title) alert('Выберите "'+form.elements[fields[i]].title+'"');
							form.elements[fields[i]].focus();
							return false;
						}
						break;
					case 'checkbox':
						if (!form.elements[fields[i]].checked) {
							if (form.elements[fields[i]].title) alert('Поставьте галочку "'+form.elements[fields[i]].title+'"');
							form.elements[fields[i]].focus();
							return false;
						}
						break;
					default:
						if (!form.elements[fields[i]].value) {
							if (form.elements[fields[i]].title) alert('Заполните поле "'+form.elements[fields[i]].title+'"');
							form.elements[fields[i]].focus();
							return false;
						}
						break;
				}
			} else return false;
		}
	}
	
	form.submit();
	return false;
}

function insertLink(link, linkid) {
	$('#link_'+linkid).val(link);
	$('#userfiles').hide();
	$("#outoverlay").hide();
	return false;
}

function albumDelSubmit(albumid) {
	if (confirm('Вы уверены?')) {
		document.albumdelform.albumid.value = albumid;
		document.albumdelform.submit();
	}
	return false;
}

function submitRegForm() {
	if (document.getElementById('form_login')) {
		var checkedVal=document.getElementById('form_login').value;
		if (checkedVal.length<2 || checkedVal.length>20) {
			alert('Неверный логин!');
			document.getElementById('form_login').focus();
			return false;
		}
	}
	if (document.getElementById('form_pass')) {
		var checkedVal=document.getElementById('form_pass').value;
		if (checkedVal.length<2) {
			alert('Пароль должен быть длиной не менее 2 символов!');
			document.getElementById('form_pass').focus();
			return false;
		}
	}
	
	if (document.getElementById('form_retry_pass')) {
		if (document.getElementById('form_pass').value!=document.getElementById('form_retry_pass').value) {
			alert('Пароль и повтор пароля должны совпадать!');
			document.getElementById('form_retry_pass').focus();
			return false;
		}
	}

	if (document.getElementById('form_mail')) {
		var checkedVal=document.getElementById('form_mail').value;
		if (checkedVal.length<6) {
			alert('Неверный e-mail!');
			document.getElementById('form_mail').focus();
			return false;
		}
	}
	if (document.getElementById('form_rulesagreement')) {
		if (!document.getElementById('form_rulesagreement').checked) {
			alert('Вы должны принять правила!');
			return false;
		}
	}

	document.getElementById('profile_form').submit();
	return false;
}

