function show_picture(script, src, alt, width, height) {

// alt must be escaped or empty because escape(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=" + escape(src) + "&alt=" + alt + "&width="+width + "&height="+height, "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 + '=' + escape(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 + "=" + escape(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 + "=" + escape(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 = unescape(aCrumb[1]);
	  }
      return value;
	}
  }

  // a cookie with the requested name does not exist
  return null;
}

function motoCookie(sName){
  var newL = document.getElementById(sName).offsetLeft + 5;
  document.getElementById(sName).style.left = newL;
  if (newL < 330) setTimeout('motoCookie("win_subscrible")', 10);
}

function viewCookie(sName){
 var val = getCookie(sName);
 if (val != 'Subscribe to news') {
  var mc = setTimeout('motoCookie("win_subscrible")', 10);
//  document.getElementById('win_subscrible').style.left = '330px';
 }
}

function closeCookie(sName, sValue, path, days, hours){
 setCookie(sName, sValue, path, days, hours);
 document.getElementById('win_subscrible').style.display = 'none';
}

function checkWinForm() {
  flag = 1;

  if (document.SR_form.field_email.value == '') {
    alert('Не заполнено поле "Ваш E-mail"');
    document.SR_form.field_email.focus();
    flag = 0;
    return false;
  } else {
    if (!isEmail(document.SR_form.field_email.value)) {
      alert('Не корректное значение E-mail');
      document.SR_form.field_email.focus();
      flag = 0;
      return false;
    }
  }
  
  if (document.SR_form.field_name_first.value == '') {
    alert('Не заполнено поле "Ваше имя"');
    document.SR_form.field_name_first.focus();
    flag = 0;
    return false;
  }
  
  if (flag == 1) {
    setCookie('mail_cookie', 'Subscribe to news', '', 365, 0);
    document.getElementById('win_subscrible').style.display = 'none';
    document.SR_form.submit();
    return true;
  }
}

