var iDiv = null;
var iImg = null;

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 ConvertStringTag(st) {
	    var new_st = '';
	    var b = 0;
	    var p = st.indexOf('&lt;');
        while (p > -1) {
        	new_st += st.substring(b, p) + '<';

			b = p + 4;
        	p = st.indexOf('&lt;', p + 4);
        }

		new_st += st.substring(b);

        return new_st;
}

function SendMessage(author_id) {
    window.open('/messages.php?author_id=' + author_id,'Messages','width=500, height=400, left=200, top=200, directories=no, location=no, menubar=no, resizeble=no, status=yes, toolbar=no, scrollbars=yes');
  }

  function ForumAddQuot(strcomm, qNameString) {
            var qName = "";
                if (qNameString != undefined)
                        qName = qNameString + ":\n";
        var el = document.getElementById('post');
        var el2 = document.getElementById(strcomm);
        var quote = el2.textContent == undefined ? el2.innerText : el2.textContent;
        el.value = el.value+'[q]'+qName+quote+'[/q]\n';
        el.focus();
  }

function ForumAddCit(stradd) {
var el = document.getElementById('post');
el.value=el.value+stradd+'\n';
el.focus();
}

function ForumGotoForm() {
        var el = document.getElementById('post');
        el.focus();
}

  function WeekauthorComment(n) {
          var el = document.getElementById("weekauthor" + n);
          el.style.display = "block";
  }

  function WindowGrade(photo) {
          window.open("/evaluate.php?photo_id=" + photo, "rating","width=800, height=700, left=200, top=10, directories=no, location=no, menubar=no, resizeble=no, status=yes, toolbar=no, scrollbars=yes");
  }


  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 CheckEnglishWithSpace(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 == ' '))
                    )) break;
                  else sum+= c;
          }
          if (sum != text) flag = true; else flag = false;
          el.value = sum;
          if (flag) alert(message);
  }

  function CheckCorrectEquipment(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 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 checkEmail(_id) {
     var reg = new RegExp('^[^@]+@.*\\.[0-9A-Za-z^\\.]{2,5}$');
     if (!reg.test(_id.value)){
          //_id.focus();
          return false;
     } else return true;
  }

  function checkMail(value) {
           var reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
           if (!value.match(reg)) {
               alert("Incorrect e-mail, try again");
               return false;
           } else return true;
  }

  function SetLogin(vl) {
          var el = document.getElementById('login');
          if (el) el.value = vl;
          var user_name = document.getElementById('yourusername');
          if (user_name) user_name.value = 'http://'+vl+'.photolight.co.il';
  }

  function RegFormSubmit() {

          var el = document.getElementById('login');
          if (el.value.length == 0) {
                  el.focus();
                  alert("Login is too short");
                  return false;
          }

          var el = document.getElementById('password');
          if (el.value.length == 0) {
                  el.focus();
                  alert("Password is too short");
                  return false;
          }

          var el = document.getElementById('protectcode');
          if (el.value.length == 0) {
                  el.focus();
                  alert("Incorrect protectcode");
                  return false;
          }

          var el = document.getElementById('email');
          if (el.value.length == 0) {
                  el.focus();
                  alert("Email is too short");
                  return false;
          }

          var el = document.getElementById('name');
          if (el.value.length == 0) {
                  el.focus();
                  alert("Name is too short");
                  return false;
          }

          return true;
  }


function AddCit(stradd) {
        var el = document.getElementById('comment');
        el.value=el.value+stradd;
        el.focus();
}

function AddQuot(strcomm, qNameString) {
        var qName = "";
        if (qNameString != undefined) qName = qNameString + ":\n";
        var el = document.getElementById('comment');
        var el2 = document.getElementById(strcomm);
        var quote = el2.textContent == undefined ? el2.innerText : el2.textContent;
        el.value = el.value+'[q]'+qName+quote+'[/q]\n';
        el.focus();
}

function checkValidComment(commRef, theObj) {
        var commObj = document.getElementById(theObj);
        if(commObj.innerHTML.length < 50) alert("comment too short");
        else
          if (confirm("are you sure comment of day")) window.location.href=commRef;
}

function CommentEdit(commentid) {
          window.open("/comment_edit.php?comment_id=" + commentid, "comment_edit", "width=370, height=410, left=200, top=150, directories=no, location=no, menubar=no, resizeble=no, status=yes, toolbar=no, scrollbars=yes");
}

function CheckReason() {
          var el = document.getElementById("reason");
          if (el.value.length == 0) alert("Fill the reason.");
}

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 CheckPostTitle() {
          var el = document.getElementById("topic");
          if (el.value.length == 0 || (el.value.length == 1 && el.value == " ")) el.value = "[NO SUBJECT]";
}

function colorCommentByAuthor_show_photo(photoAuthor, viewerAuthor) {
        if (photoAuthor != "undefined" || viewerAuthor != "undefined") {
                var verType = "ver1";
                var comm_table = document.getElementById('comments_div').nextSibling.nextSibling.lastChild;
                if (comm_table == null || comm_table == undefined) {
                        comm_table = document.getElementById('comments_div').nextSibling.lastChild;
                        verType = "ver2";
                        }
                if (comm_table != undefined) {
                        if (comm_table.rows.length > 1) {
                                tRows=0;
                                var boldElement;
                                var dayCommentElement;
                                var commentAuthor = "";
                                while(tRows < comm_table.rows.length) {
                                        if (verType=="ver1") {//firefox
                                                if (comm_table.rows[tRows].childNodes[3].childNodes.length > 0)
                                                                                                        commentAuthor = comm_table.rows[tRows].childNodes[3].childNodes[3].childNodes[0].href;
                                                boldElement = comm_table.rows[tRows].childNodes[1];
                                                dayCommentElement = comm_table.rows[tRows+1].childNodes[0].childNodes[0];
                                                }
                                        else {//ie
                                                if (comm_table.rows[tRows].childNodes[1].childNodes.length > 0)
                                                        commentAuthor = comm_table.rows[tRows].childNodes[1].childNodes[1].childNodes[0].href;
                                                boldElement = comm_table.rows[tRows].childNodes[0];
                                                dayCommentElement = comm_table.rows[tRows+1].childNodes[0].childNodes[0];
                                                }
                                                if (commentAuthor != null && commentAuthor != undefined) {
                                                        commentAuthor = commentAuthor.substring(commentAuthor.lastIndexOf("/")+1, commentAuthor.length-5);
                                                        if (commentAuthor == photoAuthor)  boldElement.style.backgroundColor  ="#7FA2F2";
                                                        if (commentAuthor == viewerAuthor) {
                                                                boldElement.style.backgroundColor  ="#A2FC96";
                                                                dayCommentElement.onmouseover=null;
                                                                dayCommentElement.onclick=null;
                                                                dayCommentElement.childNodes[0].nodeValue = "-";
                                                        }
                                                }
                                        tRows+=2
                                }
                        }
                }
        }
}

function colorCommentByAuthor_comments(viewerAuthor) {
        var photoAuthor = null;
        if (photoAuthor != "undefined" || viewerAuthor != "undefined") {
                var verType = "ver1";
                var comm_table = document.getElementById('comments_div').nextSibling.nextSibling;
                if(comm_table.className == "navigation")
                        comm_table = comm_table.nextSibling.nextSibling;
                if (comm_table != undefined) {
                        if (comm_table.rows.length > 1) {
                                tRows=0;
                                var boldElement;
                                var dayCommentElement;
                                var commentAuthor = "";
                                if (comm_table.rows[tRows].childNodes[5] == undefined)
                                        verType = "ver2";
                                while(tRows < comm_table.rows.length) {
                                        if (verType=="ver1") {//firefox
                                                commentAuthor = comm_table.rows[tRows].childNodes[5].childNodes[2].childNodes[3].href;
                                                boldElement = comm_table.rows[tRows].childNodes[1];
                                                dayCommentElement = comm_table.rows[tRows+1].childNodes[0].childNodes[0];
                                                photoAuthor = comm_table.rows[tRows].childNodes[3].childNodes[6].href;
                                                photoAuthor = photoAuthor.substring(photoAuthor.lastIndexOf("=")+1, photoAuthor.length);
                                                }
                                        else {//ie
                                                commentAuthor = comm_table.rows[tRows].childNodes[2].childNodes[1].childNodes[1].href;
                                                boldElement = comm_table.rows[tRows].childNodes[0];
                                                dayCommentElement = comm_table.rows[tRows+1].childNodes[0].childNodes[0];
                                                photoAuthor = comm_table.rows[tRows].childNodes[1].childNodes[6].href;
                                                photoAuthor = photoAuthor.substring(photoAuthor.lastIndexOf("=")+1, photoAuthor.length);
                                                }
                                                if (commentAuthor != null && commentAuthor != undefined) {
                                                        commentAuthor = commentAuthor.substring(commentAuthor.lastIndexOf("=")+1, commentAuthor.length);
                                                        if (commentAuthor == photoAuthor)  boldElement.style.backgroundColor  ="#7FA2F2";
                                                        if (commentAuthor == viewerAuthor) {
                                                                boldElement.style.backgroundColor  ="#A2FC96";
                                                                dayCommentElement.onmouseover=null;
                                                                dayCommentElement.onclick=null;
                                                                dayCommentElement.childNodes[0].nodeValue = "-";
                                                        }
                                                }
                                        tRows+=2
                                }
                        }
                }
        }
}

function setImgPrvObjects(dName, iName) {
        iDiv = document.getElementById(dName);
        iImg = document.getElementById(iName);
}

function showImgPrv(imgRef, ev) {
        if (iDiv == null || iImg == null)
                return;
        if(ev == null || ev == undefined)
        return;
        var winX = window.screenLeft == undefined ? window.pageXOffset : window.screenLeft;
        var winY = window.screenTop == undefined ? window.pageYOffset : window.document.body.scrollTop;
        if(typeof(ev.clientX)=='number' && typeof(ev.clientY)=='number') {
                iDiv.style.left = ev.screenX + winX + 5 + 'px';
                iDiv.style.top = ev.screenY + winY - 100 + 'px';
        } else {
                iDiv.style.left = ev.x + winX + 5 + 'px';
                iDiv.style.top = ev.y + winY - 100 + 'px';
        }

        iImg.src = imgRef;
        iDiv.style.display="block";
}
function hideImgPrv() {
        if (iDiv == null || iImg == null)
                return;
        iDiv.style.display="none";
}

function CommentVoteButtons(id, aid, title_useful, title_useless) {
        var el = document.getElementById('comment_buttons_' + id);
        if (el) el.innerHTML = "<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;" + el.innerHTML;
}

function ForumTopicModerate(id, del) {
        var el = document.getElementById("title" + 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("title" + 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 ForumThemeSubscribe(id, s, sid, text) {
        var el_top = document.getElementById("theme_instruments_top");
        var el_bottom = document.getElementById("theme_instruments_bottom");
        if (s == "unsubscribe") {
          el_top.innerHTML+= " [<a href='javascript:ForumThemeUnsubscr(" + id + ", " + sid + ")'>" + text + "</a>]";
          el_bottom.innerHTML+= " [<a href='javascript:ForumThemeUnsubscr(" + id + ", " + sid + ")'>" + text + "</a>]";
        } else {
          el_top.innerHTML+= " [<a href='javascript:ForumThemeSubscr(" + id + ")'>" + text + "</a>]";
          el_bottom.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 ForumTopicSubscribe(id, s, sid, text) {
        var el = document.getElementById("title" + id);
        if (s == "unsubscribe")
         el.innerHTML+= " <a href='javascript:ForumTopicUnsubscr(" + id + ", " + sid + ")'>[" + text + "]</a>";
          else el.innerHTML+= " <a href='javascript:ForumTopicSubscr(" + id + ")'>[" + text + "]</a>";
}

function ForumTopicQuote(id, name, text) {
        var el = document.getElementById("post_head_" + id);
        if (el) el.innerHTML = "&nbsp;<a href=\"javascript:ForumAddQuot('post" + id + "', '" + name + "')\">[" + text + "]</a>&nbsp;";
}

function ForumTopicAuthorInfo(id, content) {
        var el = document.getElementById("authorinfo_" + id);
        if (el) el.innerHTML = content;
}

function ForumTopicAuthorInfoConvert(id, content) {
        var el = document.getElementById("authorinfo_" + id);
        if (el) el.innerHTML = ConvertStringTag(content);
}

function ForumTopicGetThemeList(id) {
        var place = "title" + 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("title" + 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("title" + 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("title" + 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("title" + 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 ForumPostEditLink(id, text) {
        var el_head = document.getElementById("post_head_" + id);
        el_head.innerHTML+= "<a href='/forum/post" + id + ".html' style='font-weight: bold; color: #BA0404;'>" + text + "</a><br/>";
}

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 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 ForumPostInsert(text) {
        var txtarea = document.getElementById("post");
        txtarea.value  += text;
        txtarea.focus();
}

function ConfirmGo(question, address) {
        if (confirm(question)) document.location.href = address;
        else return false;
}

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 AddCategory() {
  var el_from = document.getElementById("category_from");
  var el_to = document.getElementById("category_to");

  for (j = 0; j < el_from.length; j++) {
          if (el_from.options[j].selected && el_from.options[j].value != 0) {
                  if (el_from.options[j].value == -1) { alert("You can not select a main category."); return; }
                  if (CategorySearch(el_from.options[j].value) == false) el_to.options[el_to.length] = new Option(el_from.options[j].text,el_from.options[j].value);
          }
  }

  SetCategory();
}

function CategorySearch(id) {
  var el = document.getElementById("category_to");
  for (i = 0; i < el.length; i++) if (el.options[i].value == id) return true;
  return false;
}

function RemoveCategory() {
  var el = document.getElementById("category_to");
  for (i = 0; i < el.length; i++) if (el.options[i].selected) {
    el.options[i].selected = null;
    el.options[i] = null;
  }
  SetCategory();
}

function SetCategory() {
  out = "=";
  var el = document.getElementById("category_to");
  for (i = 0; i < el.length; i++) out+= el.options[i].value + "=";

  var el_out = document.getElementById("category");
  el_out.value = out;
}

function AddCategoryById(id) {
  var el_from = document.getElementById("category_from");
  var el_to = document.getElementById("category_to");

  for (j = 0; j < el_from.length; j++) {
          if (el_from.options[j].value == id) {
                  if (CategorySearch(el_from.options[j].value) == false) el_to.options[el_to.length] = new Option(el_from.options[j].text,el_from.options[j].value);
          }
  }

  SetCategory();
}


function isGraphics(filename) {
 var i=filename.length; // get file length
 i=filename.lastIndexOf('.')+1; // find extension
 var ext=filename.substr(i); // pull out extension

 switch(ext.toLowerCase()) {
       case "gif": // GIF
       case "jpg": // JPG
       case "jpeg": // JPG
       return true;
       break;
       default: return false;
 }
}

function setImage(file) {
 var image=document.getElementById("preview");
 if(file.value.length) if(isGraphics(file.value))
 if(image.src!=file.value) image.src=file.value;
}


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 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 changeCategoryDesc(c) {
                          var el = document.getElementById("cat_desc");
                          var sc = document.getElementById("cat_desc_" + c);
                          el.innerHTML = sc.innerHTML;
                  }

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 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 activateLink(obj, href) {
        if (is_object(document.getElementById(obj)))
            document.getElementById(obj).innerHTML = '<a href="' + href + '" class="link">' + document.getElementById(obj).innerHTML + '</a>';
}

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 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 SetCommentCount(id, author_id, count_comments, text) {
        var el = document.getElementById(id);
        if (el) el.innerHTML = "<a href='/comments/author" + author_id + ".html'>" + text + " " + count_comments + "</a>";
}

function SetContent(id, content, add) {
        var el = document.getElementById(id);
        if (el) {
           if (add) el.innerHTML += content; else el.innerHTML = content;
        }
}

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);
    }
}