function show_picture(script, src, alt, width, height) {

// alt must be escaped or empty because encodeURIComponent(str) doesn't work with russian symbols
  if (  (script.substring(0,7).toLowerCase()) != "http://"  &&  (script.substring(0,8).toLowerCase() != "https://" ) ){
    script = frontBaseHref + script;
  }

  var w_width = 40 + parseInt(width);
  var w_height = 100 + parseInt(height);

  if (w_height > window.screen.availHeight)
    w_height = window.screen.availHeight;
  if (w_width > window.screen.availWidth)
    w_width = window.screen.availWidth;

  window.open(script+"?src=" + encodeURIComponent(src) + "&alt=" + alt + "&width="+width + "&height="+height, "pic",
              "resizable=yes, status=yes, scrollbars=yes, width=" + w_width + ", height=" + w_height);
}

function show_details(script) {
  if (  (script.substring(0,7).toLowerCase()) != "http://"  &&  (script.substring(0,8).toLowerCase() != "https://" ) ){
    script = frontBaseHref + script;
  }

  var w_width = 200;
  var w_height = 250;

  if (w_height > window.screen.availHeight)
    w_height = window.screen.availHeight;
  if (w_width > window.screen.availWidth)
    w_width = window.screen.availWidth;

  window.open(script, "pic", "resizable=yes, status=yes, scrollbars=yes, width=" + w_width + ", height=" + w_height);
}


function none(){
  return false;
}


function isEmail_old(string) {
   if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
      return true;
   else
      return false;
}


function isEmail(string) {
    if
(string.search(/^(\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+(;|,|$))+$/)
!= -1)
        return true;
    else
        return false;
}
//
// following functions will be deleted later
//

function collect_link(cform){
  var vlink = '';
  var first = 1;

  for(var i=0; i<cform.length; i++){
    el = cform.elements[i];
    if(el.type == 'hidden'){
      delim = (first)?'':'&';
      vlink = vlink + delim + el.name + '=' + encodeURIComponent(el.value);
      first = 0;
    }
  }
 return vlink;
}

function view_item(id){
  var sform = document.forms[_cms_document_form];
  var link = _cms_script_link;

  sform.elements['sort'].value = '';
  sform.elements['sdim'].value = '';

  return user_click('view', id);
}

function user_click(action, id){
  var sform = document.forms[_cms_document_form];
  var link = _cms_script_link;
  var anchor = '#anchor';

  if(action!='edit') anchor='';
  sform.elements['action'].value = action;
  sform.elements['id'].value = id;
  document.location = link + collect_link(sform) + anchor;

  return false;
}

function _go_page(sform, start, varname) {
  if(typeof(sform.elements[varname]) == 'object') {
    sform.elements[varname].value = start;
  } else {
    sform.elements['offset'].value = start;
  }
}

function go_page(start, varname){
  var sform = document.forms[_cms_document_form];
  var link = _cms_script_link;
  _go_page(sform, start, varname);
  sform.elements['action'].value = 'resort';
  document.location = link + collect_link(sform);
  return false;
}

function go_pageSubmit(start, varname, action){
  var sform = document.forms[_cms_document_form];
  var link = _cms_script_link;
  _go_page(sform, start, varname);
  sform.elements['action'].value = action;
  sform.submit();
  return false;
}

function go_pagesize(size){
  var sform = document.forms[_cms_document_form];
  var link = _cms_script_link;

  sform.elements['action'].value = 'resort';
  sform.elements['limit'].value = size;
  if(typeof(sform.elements['enc_limit']) == 'object') {
    sform.elements['enc_limit'].value = size;
  }
  document.location = link + collect_link(sform);

  return false;
}

function resort(ccol,cdim){
  var sform = document.forms[_cms_document_form];
  var link = _cms_script_link;

  sform.elements['action'].value = 'resort';
  sform.elements['sort'].value = ccol;
  sform.elements['sdim'].value = cdim;

  document.location = link + collect_link(sform);
  return false;
}

function resortSubmit(ccol,cdim){
  return advResortSubmit(ccol,cdim,"sort","sdim");
}

function advResortSubmit(ccol,cdim,ccolname,cdimname){
  var sform = document.forms[_cms_document_form];
  //var link = _cms_script_link;
  //sform.elements['action'].value = 'resort';
  sform.elements[ccolname].value = ccol;
  sform.elements[cdimname].value = cdim;
  sform.submit();
  return false;
}

function publish(id, act){
  var sform = document.forms[_cms_document_form];
  var link = _cms_script_link;

  sform.action.value = 'publish';
  sform.publish.value = act;
  sform.id.value = id;
  document.location = link + collect_link(sform);

  return false;
}

function setCookie(sName, sValue, path, days, hours){

  var oDate = new Date();
  if (typeof(days) == "undefined" && typeof(hours) == "undefined"){
    days = 30;
  }

  if (typeof(days) != "undefined") oDate.setDate(oDate.getDate() + days);
  if (typeof(hours) != "undefined") oDate.setHours(oDate.getHours() + hours);

  var pathStr = "";

  if( typeof(path) !="undefined" && path != "") {
      pathStr = "; path="+path;
  }
  delCookie(sName);
  document.cookie = sName + "=" + encodeURIComponent(sValue) + pathStr + "; expires="+oDate.toGMTString();
}

function delCookie(sName, path)
{
  var pathStr = "";
  if(path != "") {
      pathStr = "; path="+path;
  }
  sValue = getCookie(sName);
  if (sValue != null)
    document.cookie = sName + "=" + encodeURIComponent(sValue) + pathStr + "; expires=Fri, 31-Dec-1999 23:59:59 GMT;";
}

function getCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  var value = "";
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) {
      if(aCrumb[1] === undefined) {
        value = null;
      } else {
        value = decodeURIComponent(aCrumb[1]);
      }
      return value;
    }
  }

  // a cookie with the requested name does not exist
  return null;
}