function openwin(w, h, url) {
  w+=40;
  h+=30;
  window.open(url,'','width='+w+', height='+h+', status=true, toolbar=false, resizable=true, scrollbars=false');
}

function swtch(id) {
  var o = document.getElementById(id);
  if (o) {
    if (o.style.display == "none" || o.style.display == "") {
      o.style.display = "block";
      //saveCookie(id, o.style.display);
      return true;
    } else {
      o.style.display = "none";
      //saveCookie(id, o.style.display);
      return false;
    }
  }
}

function openTitledWin(img, width, height, title, text) 
{
	width+=50;
	height+=50;
  var left = screen.availWidth/2 - width/2;
  var top = screen.availHeight/2 - height/2;
  NewWin=window.open("", "NewWindow", 
    "width="+width+",height="+height+", top="+top+",left="+left+",status=yes,toolbar=no,menubar=yes"); 
  NewWin.document.open();
  NewWin.document.write("<html><head><title>"+title+"</title>");
  NewWin.document.write("<link href=\"/css/default.css\" rel=\"stylesheet\" type=\"text/css\" media=\"all\"></head>");
  NewWin.document.write("<body style='padding-top:20px;background-image:none;min-height:0px;'><center><img style='border:1px solid #ccc;padding:1px;' src='/"+img+"'></center></body></html>");
  NewWin.document.close();  
}

function openNewWin(width, height, title, text) 
{
	width+=50;
	height+=50;
  var left = screen.availWidth/2 - width/2;
  var top = screen.availHeight/2 - height/2;
  NewWin=window.open("", "NewWindow", 
    "width="+width+",height="+height+", top="+top+",left="+left+",status=yes,toolbar=no,menubar=yes"); 
  NewWin.document.open();
  NewWin.document.write("<html><head><title>"+title+"</title>");
  NewWin.document.write("<link href=\"/css/default.css\" rel=\"stylesheet\" type=\"text/css\" media=\"all\"></head>");
  NewWin.document.write("<body style='padding-top:20px;background-image:none;min-height:0px;'><center>"+text+"</center></body></html>");
  NewWin.document.close();  
}


function d(t) {
  console.debug(t);
}

function confirmation(q, link) {
  if (window.confirm(q)) {
    window.location = link;
  }
}

function id2id(idStr) {
  var parts = idStr.split('_');
  return parts[1] ? parts[1] : false;
}

// Ф-я присоединяет слово к другим словам, перечисленным через запятую
// Если слово уже присутствует в списке, оно не присоединяется
var compareWrods = function(initalTags, addTag) {
  if (!initalTags) return addTag;
  var tags = initalTags.split(',');
  if (tags) {
    var tagExists = false;
    for (var i=0; i<tags.length; i++) {
      tags[i] = tags[i].trim();
      if (tags[i] == addTag) {
        tagExists = true;
        break;
      }
    }
    if (!tagExists) return initalTags + ', ' + addTag;
    return initalTags;
  }
  return initalTags;
}

// Альяс для compareWrods()
var compareTags = compareWrods;
