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 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 + '=' + 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;
  
  if(typeof(CheckFilterForm) == "function")
    CheckFilterForm(sform, 0, 0);
  else
    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 AddToCart(url, itemId, numPrice){
	if(document.forms["qty_"+itemId+'_'+numPrice] && document.forms["qty_"+itemId+'_'+numPrice].qty && itemId != 0)
        document.location = frontBaseHref + url+'&qty='+document.forms["qty_"+itemId+'_'+numPrice].qty.value;
    else
        document.location = frontBaseHref + url+'&qty=1';
}

function AddToCartProp(url, itemId, propId, numPrice){
	if(document.forms["qty_"+itemId+'_'+propId+'_'+numPrice] && document.forms["qty_"+itemId+'_'+propId+'_'+numPrice].qty && itemId != 0)
	    document.location = frontBaseHref + url+'&qty='+document.forms["qty_"+itemId+'_'+propId+'_'+numPrice].qty.value;
    else
        document.location = frontBaseHref + url+'&qty=1';
}

/* ADVERTISING BLOCK */

var advCurTmStamp = new Date();
document.usedAdvData = "";
var isInnerHtmlSupported = -1;
var shownAdvPlaces = '';
var shownAdvPlacesCnt = 0;
var advReferrer = ''
if(document.referrer)
    advReferrer = document.referrer;
function showAdvPlace(idPlace, viewURL){
    if(isInnerHtmlSupported == -1){
        if(document.body.innerHTML)
            isInnerHtmlSupported = 1;
        else
            isInnerHtmlSupported = 0;
    }
    // After the document is loaded (new scheme)
    if(isInnerHtmlSupported == 1){
        shownAdvPlacesCnt ++;
        document.write('<span id="advp_'+idPlace+'_'+shownAdvPlacesCnt+'"></span>');
        shownAdvPlaces += (shownAdvPlaces == '' ? ';' : '')+idPlace+';';
    // Old scheme - inline method
    }else{
        if (!document.usedAdvData)
            document.usedAdvData = '';
        rndseed = new String(Math.random()); rndseed = rndseed.substring(2,11);
        document.write ("<" + "script language='JavaScript' type='text/javascript' src='"+viewURL+"adv.php?action=view&rs="+advCurTmStamp.getTime()+rndseed+"&place="+idPlace+"&used="+document.usedAdvData+"&curl="+escape(viewURL)+"&referer="+escape(advReferrer)+"'><"+"/script>");
    }
}

function showAdvBanner(id, content){
    if(document.usedAdvData)
        document.usedAdvData += ','+id+',';
    else
        document.usedAdvData  = ','+id+',';
    document.writeln(content);
}

function advClick(clickURL){
    rndseed = new String(Math.random()); rndseed = rndseed.substring(2,11);
    clickURL+="&rs="+advCurTmStamp.getTime()+rndseed;
    img = new Image();
    img.src = clickURL;
}

/* MODULE ADVERTISEMENT PART */

var prevBodyOnLoad = false;
var modAdvertStr = "";
// Set advertisement onload callback and remember previous one ...
function setAdvEvtOnLoad(){
    if(window.onload != onLoadForAdv){
        if(window.onload){
            prevBodyOnLoad = window.onload;
        }
        window.onload=onLoadForAdv;
    }
}

// Execute advertise onload callback and previous one thereafter
function onLoadForAdv(){
    rndseed = new String(Math.random()); rndseed = rndseed.substring(2,11);
    modURL='/adv.php?action=modview&&rs='+advCurTmStamp.getTime()+rndseed+'&data='+modAdvertStr;
    if(frontBaseHref)
        modURL=frontBaseHref+'adv.php?action=modview&rs='+advCurTmStamp.getTime()+rndseed+"&referer="+escape(advReferrer)+'&data='+modAdvertStr;
    img = new Image();
    img.src = modURL;
    if(prevBodyOnLoad != false){
        prevBodyOnLoad();
    }
};

// Set item view
function setView(modName, bodyType, id){
    setAdvEvtOnLoad();
    modAdvertStr += ';'+modName+'|'+bodyType+'|'+id+';';
}

// Returns cookie value
function getCookie(name) {
    var search = name + "=";
    if (document.cookie.length > 0) {
        // if there are any cookies
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            // if cookie exists
            offset += search.length;
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset);
            // set index of end of cookie value
            if (end == -1) {
                end = document.cookie.length;
            }
            return unescape(document.cookie.substring(offset, end));
        }
    }
}

// {{{ window.onLoad events queue implementation

var onLoadEvents = new Array ();
var previousOnLoadEvent;

function addOnLoadEvent(event) {
	onLoadEvents[onLoadEvents.length] = event;
}

function savePreviousOnLoadEvent() {
	previousOnLoadEvent = window.onload;
	window.onload = runOnLoadEventsQueue;
}

function runOnLoadEventsQueue() {
	if (previousOnLoadEvent) {
		previousOnLoadEvent();
	}
	for (var i = 0 ; i < onLoadEvents.length; i++) {
		onLoadEvents[i]();
	}
}

// }}}