function SmileIcon(id, text) {
        var txtarea = document.getElementById(id);
        text = ' ' + text + ' ';
        if (txtarea.createTextRange && txtarea.caretPos) {
                var caretPos = txtarea.caretPos;
                caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
                txtarea.focus();
        } else {
                txtarea.value  += text;
                txtarea.focus();
        }
}

function CommentComplain(commentid) {
          window.open("/comment_complain.php?comment_id=" + commentid, "comment_complain", "width=370, height=240, left=200, top=150, directories=no, location=no, menubar=no, resizeble=no, status=yes, toolbar=no, scrollbars=no");
}

function CommentEdit(commentid) {
          window.open("/comment_edit_v2.php?comment_id=" + commentid, "comment_edit", "width=370, height=410, left=300, top=150, directories=no, location=no, menubar=no, resizeble=no, status=yes, toolbar=no, scrollbars=no");
}

function CheckReason() {
          var el = document.getElementById("reason");
          if (el.value.length == 0) { alert("Fill the reason!"); return false; } else return true;
}

function ShowDiv( id ) {
        var el = document.getElementById( id );
        el.style.display = 'inline';
}

function ShowDivBlock( id ) {
        var el = document.getElementById( id );
        el.style.display = 'block';
}

function HideDiv( id ) {
        var el = document.getElementById( id );
        el.style.display = 'none';
}

function addequipment(eqmode) {
        if (eqmode == 'camera') window.open('/equipment_dialog_camera.php', 'add_camera', 'width=500, height=400, left=200, top=200, directories=no, location=no, menubar=no, resizeble=no, status=yes, toolbar=no, scrollbars=yes');
        if (eqmode == 'lense') window.open('/equipment_dialog_lense.php', 'add_lense', 'width=500, height=400, left=200, top=200, directories=no, location=no, menubar=no, resizeble=no, status=yes, toolbar=no, scrollbars=yes');
}

function WeekauthorComment(n) {
        var el = document.getElementById("weekauthor" + n);
        el.style.display = "block";
}

function ConfirmGo(question, address) {
        if (confirm(question)) document.location.href = address;
        else return false;
}

function CheckEnglish(elid, message) {
          var el = document.getElementById(elid);
          text = el.value;
          sum = ''
          for (j = 0; j < text.length; j++) {
                  c = text.charAt(j);
                  if (!(
                    ((c >= 'a') && (c <= 'z')) ||
                    ((c >= 'A') && (c <= 'Z')) ||
                    ((c >= '0') && (c <= '9')) ||
                    ((c == '_') || (c == '-'))
                    )) break;
                  else sum+= c;
          }
          if (sum != text) flag = true; else flag = false;
          el.value = sum;
          if (flag) alert(message);
}

function is_object( mixed_var ){
    if (mixed_var === null) return false;
    else {
      if(mixed_var instanceof Array) {
        return false;
      } else {
        return (typeof( mixed_var ) == 'object');
      }
    }
}

function is_array( mixed_var ) {
    return ( mixed_var instanceof Array );
}

function format_float( tmp )  {
    x = tmp;
    a = Math.floor(x);

    x = Math.round((x - a) * 100);

    if (x < 10) return a + ".0" + x;
    else return a + "." + x;
}

function in_array(needle, haystack, strict) {
    var found = false, key, strict = !!strict;

    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }

    return found;
}

function function_exists( function_name ) {
    if (typeof function_name == 'string'){
        return (typeof window[function_name] == 'function');
    } else{
        return (function_name instanceof Function);
    }
}

function ForumPostInsert(text) {
        var txtarea = document.getElementById("post");
        txtarea.value  += text;
        txtarea.focus();
}

function SetInnerHTML(id, value) {
	var o = document.getElementById(id);
	if (!o) return false;

	o.innerHTML = value;
}

function AddInnerHTML(objid, objval) {
        var el = document.getElementById( objid );
        if (el) el.innerHTML = objval + el.innerHTML;
}

function AppendValue(id, value) {
	var o = document.getElementById(id);
	if (!o) return false;

	o.value = value + o.value;
}

function ForumTopicModerate(id, del) {
        var el = document.getElementById("topic_instrument_panel" + id);
        el.innerHTML+= " <a href='/forum/topic" + id + "/edit.html'><img src='/images/edit.gif' width='22px' height='10px' border='0px' alt='edit' /></a>";
        if (del) el.innerHTML+= " <a href='javascript:ForumTopicDelete(" + id + ")'><img src='/images/delete.gif' width='10px' height='10px' border='0px' alt='delete' /></a>";
}

function ForumTopicCloseOpen(id, p) {
        var el = document.getElementById("topic_instrument_panel" + id);
        if (p == "close")
         el.innerHTML+= " <a href='javascript:ForumTopicClose(" + id + ")'><img src='/images/forum_lock.GIF' width='10px' height='10px' border='0px' alt='close' /></a>";
          else el.innerHTML+= " <a href='javascript:ForumTopicOpen(" + id + ")'><img src='/images/forum_unlock.GIF' width='10px' height='10px' border='0px' alt='open' /></a>";
}

function ForumTopicNAUp(id) {
        var el = document.getElementById("topic_instrument_panel" + id);
        el.innerHTML+= " <a href='javascript:ForumTopicNewsActivityUp(" + id + ")'><img src='/images/arrow-up_na.gif' width='11px' height='11px' border='0px' alt='news activity up' /></a>";
}

function ForumTopicNewsActivityUp(id) {
        if (confirm("Up this topic in news activity?")) document.location.href = "/forum/topic" + id + "/na_up.html";
}

function ForumTopicGetThemeList(id) {
        var place = "topic_instrument_panel" + id;
        var el = document.getElementById(place);
        el.innerHTML+= " <a href='javascript:xajax_ForumGetThemeList(" + id + ", \"" + place + "\");void(0);'><img src='/images/arrow-right_move.gif' width='11px' height='11px' border='0px' alt='move' /></a>";
}

function ForumTopicModerateUp(id) {
        var el = document.getElementById("topic_instrument_panel" + id);
        el.innerHTML+= " <a href='javascript:ForumTopicUp(" + id + ")'><img src='/images/arrow-up.gif' width='11px' height='11px' border='0px' alt='up' /></a>";
}

function ForumTopicModerateDown(id) {
        var el = document.getElementById("topic_instrument_panel" + id);
        el.innerHTML+= " <a href='javascript:ForumTopicDown(" + id + ")'><img src='/images/arrow-down.gif' width='11px' height='11px' border='0px' alt='down' /></a>";
}

function ForumTopicModerateUpMain(id) {
        var el = document.getElementById("topic_instrument_panel" + id);
        el.innerHTML+= " <a href='javascript:ForumTopicUpMain(" + id + ")'><img src='/images/arrow-up_superstick.gif' width='11px' height='11px' border='0px' alt='up on main' /></a>";
}

function ForumTopicModerateDownMain(id) {
        var el = document.getElementById("topic_instrument_panel" + id);
        el.innerHTML+= " <a href='javascript:ForumTopicDownMain(" + id + ")'><img src='/images/arrow-down_superstick.gif' width='11px' height='11px' border='0px' alt='down on main' /></a>";
}

function ForumPostDelete(id) {
        if (confirm("Delete this post?")) document.location.href = "/forum/post" + id + "/delete.html";
}

function ForumTopicDelete(id) {
        if (confirm("Delete this topic?")) document.location.href = "/forum/topic" + id + "/delete.html";
}

function ForumTopicUp(id) {
        if (confirm("Up this topic?")) document.location.href = "/forum/topic" + id + "/up.html";
}

function ForumTopicDown(id) {
        if (confirm("Down this topic?")) document.location.href = "/forum/topic" + id + "/down.html";
}

function ForumTopicUpMain(id) {
        if (confirm("Up this topic(on main page)?")) document.location.href = "/forum/topic" + id + "/upmain.html";
}

function ForumTopicDownMain(id) {
        if (confirm("Down this topic(on main page)?")) document.location.href = "/forum/topic" + id + "/downmain.html";
}

function ForumTopicOpen(id) {
        if (confirm("Open this topic?")) document.location.href = "/forum/topic" + id + "/open.html";
}

function ForumTopicClose(id) {
        if (confirm("Close this topic?")) document.location.href = "/forum/topic" + id + "/close.html";
}

function ForumThemeSubscr(id) {
        if (confirm("Are you sure?")) document.location.href = "/forum/theme" + id + "/subscr.html";
}

function ForumThemeUnsubscr(id, sid) {
        if (confirm("Are you sure?")) document.location.href = "/forum/theme" + id + "/unsubscr/" + sid + ".html";
}

function ForumTopicSubscr(id) {
        if (confirm("Are you sure?")) document.location.href = "/forum/topic" + id + "/subscr.html";
}

function ForumTopicUnsubscr(id, sid) {
        if (confirm("Are you sure?")) document.location.href = "/forum/topic" + id + "/unsubscr/" + sid + ".html";
}

function ForumTopicBold(id) {
        var el = document.getElementById("title" + id);
        el.innerHTML = "<b>" + el.innerHTML + "</b>";
}

function ForumPostNum(id, n) {
        var el = document.getElementById("num" + id);
        el.innerHTML = n;
}

function ForumShowPath(id) {
        var el = document.getElementById("path" + id);
        el.style.display = "block";
}

function ForumFocusPost() {
        var el = document.getElementById('post');
        el.focus();
}

function ForumThemeSubscribe(id, s, sid, text) {
        var el_top = document.getElementById("theme_instruments_top");
        if (s == "unsubscribe") {
          el_top.innerHTML+= " [<a href='javascript:ForumThemeUnsubscr(" + id + ", " + sid + ")'>" + text + "</a>]";
        } else {
          el_top.innerHTML+= " [<a href='javascript:ForumThemeSubscr(" + id + ")'>" + text + "</a>]";
        }
}


function ForumTopicSubscribeInInstrument(id, s, sid, text) {
        var el_top = document.getElementById("topic_instruments_top");
        var el_bottom = document.getElementById("topic_instruments_bottom");
        if (s == "unsubscribe") {
          el_top.innerHTML+= " [<a href='javascript:ForumTopicUnsubscr(" + id + ", " + sid + ")'>" + text + "</a>]";
          el_bottom.innerHTML+= " [<a href='javascript:ForumTopicUnsubscr(" + id + ", " + sid + ")'>" + text + "</a>]";
        } else {
          el_top.innerHTML+= " [<a href='javascript:ForumTopicSubscr(" + id + ")'>" + text + "</a>]";
          el_bottom.innerHTML+= " [<a href='javascript:ForumTopicSubscr(" + id + ")'>" + text + "</a>]";
        }
}

function ForumGotoForm() {
        var el = document.getElementById('post');
        if (el) el.focus();


}

function ForumTopicQuote(id, name, text) {
        var el = document.getElementById("cp_buttons" + id);
        if (el) el.innerHTML = "&nbsp;<a href=\"javascript:ForumAddQuot('post" + id + "', '" + name + "')\">[" + text + "]</a>&nbsp;";
}

function ForumPostEditLink(id, text) {
        var el_head = document.getElementById("cp_buttons" + id);
        el_head.innerHTML+= "<a href='/forum/post" + id + ".html' style='font-weight: bold;'>" + text + "</a>";
}

function ForumPostDeleteLink(id, text) {
        var el_head = document.getElementById("cp_buttons" + id);
        el_head.innerHTML+= "&nbsp;<a href='javascript:ForumPostDelete(" + id + ");'><img src='/images/delete.gif' width='10px' height='10px' border='0px' alt='" + text + "'/></a>";
}

function SetContent(id, content, add) {
        var el = document.getElementById(id);
        if (el) {
           if (add) el.innerHTML += content; else el.innerHTML = content;
        }
}


function ResponseDelete(response_id) {
	if (!response_id) return false;
        
	document.responseform["form_id"].value = 'response_delete';
     	document.responseform["response_id"].value = response_id;
        document.responseform.submit();
}

function CommentVoteButtons(id, aid, title_useful, title_useless) {
        var el = document.getElementById('cp_buttons' + id);
        if (el) el.innerHTML = el.innerHTML + "&nbsp;<a href='javascript:xajax_VoteComment(" + id + ", " + aid + ", 1);void(0);'><img src='/images/yes.gif' alt='" + title_useful + "' title='" + title_useful + "'></a>&nbsp;<a href='javascript:xajax_VoteComment(" + id + ", " + aid + ", 0);void(0);'><img src='/images/no.gif' alt='" + title_useless + "' title='" + title_useless + "'></a>&nbsp;";
}

function ShowReplace() {
        el = document.getElementById('replace_photo');
        el.style.display = 'inline';
}

function AddCit(stradd) {
        var el = document.getElementById('comment');
        el.value=el.value+stradd;
        el.focus();
}

function SetHTML(id, n) { document.getElementById(id).innerHTML = n; }
function AddHTML(id, n) { document.getElementById(id).innerHTML+= n; }
