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 );
        if (el) el.style.display = 'inline';
}

function ShowDivBlock( id ) {
        var el = document.getElementById( id );
        if (el) el.style.display = 'block';
}

function HideDiv( id ) {
        var el = document.getElementById( id );
        if (el) 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);
        if (el) 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 CheckEnglishEmail(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 == '-') || (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.png' width='16px' height='16px' border='0px' alt='edit' /></a>";
        if (del) el.innerHTML+= " <a href='javascript:ForumTopicDelete(" + id + ")'><img src='/images/delete.png' width='16px' height='16px' 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/lock_forum.png' width='16px' height='16px' border='0px' alt='close' /></a>";
          else el.innerHTML+= " <a href='javascript:ForumTopicOpen(" + id + ")'><img src='/images/unlock_forum.png' width='16px' height='16px' 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.png' width='16px' height='16px' 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.png' width='16px' height='16px' 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.png' width='16px' height='16px' 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.png' width='16px' height='16px' 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.png' width='16px' height='16px' 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.png' width='16px' height='16px' 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'><img src='/images/edit.png' width='16px' height='16px' border='0px' alt='" + 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.png' width='16px' height='16px' border='0px' alt='" + text + "'/></a>";
}

function ForumPostEditLinkAjax(id, text) {
        var el_head = document.getElementById("cp_buttons" + id);
        el_head.innerHTML+= "<a href='javascript:HideCurrentForm(); xajax_LoadForumPostEditForm(" + id + ", 0); void(0);'><img src='/images/edit.png' width='16px' height='16px' border='0px' alt='" + text + "' /></a>";
}

function ForumPostDeleteLinkAjax(id, text) {
        var el_head = document.getElementById("cp_buttons" + id);
        el_head.innerHTML+= "<a href='javascript:HideCurrentForm(); xajax_LoadForumPostEditForm(" + id + ", 1); void(0);'><img src='/images/delete.png' width='16px' height='16px' 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.png' alt='" + title_useful + "' title='" + title_useful + "'></a>&nbsp;<a href='javascript:xajax_VoteComment(" + id + ", " + aid + ", 0);void(0);'><img src='/images/no.png' 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; }

function SetCounter(id, n, k, lid) {
        if (lid == '') lid = id;
        SetHTML(id, n);
        if (n > k) document.getElementById(lid).style.color = "#C00000";
        else document.getElementById(lid).style.color = "";
}

function SetCommentButtons(id, comment_id, photo_id, comment_of_the_day, js_enable, no_moderate, author_name, quot_gif_alt, comment_complain, title_edit, title_delete, day_comment, lang) {
        var el = document.getElementById(id);

        var val = "";

        if (!lang) lang = 'he';

        if (day_comment) document.getElementById("num"+comment_id).style.background = "#F9B256";

        if (comment_of_the_day.length > 0) val += "<u onmouseover=\"this.style.cursor='pointer'\" onclick=\"checkValidComment('/show_photo.php?photo_id=" + photo_id + "&comment=useful&comment_num=" + comment_id + "','quot" + comment_id + "')\">" + comment_of_the_day + "</u> | ";
        if (js_enable) {
            val += "<a href=\"javascript:AddQuot('quot" + comment_id + "','" + author_name + "')\"><img src='/images/quot_" + lang + ".gif' width='28px' height='11px' border='0px' alt='" + quot_gif_alt + "' title='' /></a>";
        } else {
            val += "<a href='/show_photo/" + photo_id + "/quot" + comment_id + ".html#addcomment'><img src='/images/quot_" + lang + ".gif' width='28px' height='11px' border='0px' alt='" + quot_gif_alt + "' /></a>";
        }
        val += " | <a href=\"javascript:CommentComplain('" + comment_id + "')\">" + comment_complain + "</a>";
        if (!no_moderate) {
            val += " | <a href=\"javascript:CommentEdit('" + comment_id + "')\"><img src='/images/edit-key.gif' title=\"" + title_edit + "\" width='22px' height='10px' border='0px' alt='' /></a>";
            val += " | <a href=\"javascript:CommentEdit('" + comment_id + "&delete=true')\"><img src='/images/delete.gif' title=\"" + title_delete + "\" width='10px' height='10px' border='0px' alt='' /></a>";
        }

        if (el) el.innerHTML = val + el.innerHTML;
}

function SplashScreen(obj) {
  var el = document.getElementById(obj);
  el.innerHTML = "<div class='splash-screen'><img src='/images/wait.gif' width='40px' height='40px' border='0' /><br />Wait please...</div>";
}

function HideLayer(obj) {
  var el = document.getElementById(obj);
  el.style.display = 'none';
}

function HighLightBG(l) {
        for (i=0;i<11;i++){
                objname  ='bgcolor' + i;
                if (l==i) document.getElementById(objname).style['border'] = '1px solid #FF0000';
                else document.getElementById(objname).style['border'] = '1px solid #696969';
        }
}

function changeCategoryDesc(c) {
        var el = document.getElementById("cat_desc");
        var sc = document.getElementById("cat_desc_" + c);
        el.innerHTML = sc.innerHTML;
}

function BoxChecked(id) {
	var el = document.getElementById(id);
	if (el) if (el.checked) return 1;

	return 0;	
}

function SetSubjectTitle(id, val) {
        var el = document.getElementById(id);
        if (el) el.innerHTML = val + el.innerHTML;
}

function SetTrashMessageLink(id, folder, mes_id, val) {
        var el = document.getElementById(id);
        if (el) el.innerHTML = "<a href='/messages/" + folder + "/trash" + mes_id + ".html'>" + val + "</a>";
}

function checkValidComment(commRef, theObj) {
        var commObj = document.getElementById(theObj);
        if (false && commObj.innerHTML.length < 900) alert("comment too short");
        else
          if (confirm("Are you sure comment of day")) window.location.href=commRef;
}

function HideCurrentComplaintForm(t) {
	if (document.getElementById("complaint_form_id")) {
		var f = document.getElementById(t + document.getElementById("complaint_form_id").value);
		if (f) f.innerHTML = "&nbsp;";
	}
}

function checkComplaint(message) {
	var complaint = document.getElementById('complaint');
	if (complaint) {
		if (complaint.value.length == 0) { alert(message); return false; }
			else return true;
	}

	return false;
}

function enableMenu(id) {
        for (var j = 0; j < menu.length; j++) {
                if (is_object(document.getElementById("submenu" + menu[j]))) document.getElementById("submenu" + menu[j]).style.display = "none";
                if (is_object(document.getElementById("menu" + menu[j]))) document.getElementById("menu" + menu[j]).className = "";
                if (is_object(document.getElementById("spacer" + menu[j]))) document.getElementById("spacer" + menu[j]).className = "";
        }

        if (!isNaN(id) && id !== null) {
                if (is_object(document.getElementById("submenu" + id))) document.getElementById("submenu" + id).style.display = "block";
                if (is_object(document.getElementById("menu" + id))) document.getElementById("menu" + id).className = "over";
                if (is_object(document.getElementById("spacer" + id))) document.getElementById("spacer" + id).className = "nav_over_right";

        }
}




function RedirectToPage(page) {
	document.location.href = page;
}

function FixCatalogItemClick(item_id, page) {
	var id = 0;
	xajax_CatalogItemIncClicks(item_id);
	id = setTimeout("RedirectToPage('" + page + "');", 3000);
}



function getRadioGroupValue(radioGroupObj) {
  for (var i=0; i < radioGroupObj.length; i++)
    if (radioGroupObj[i].checked) return radioGroupObj[i].value;

  return null;
}
