function actionForValidator(cid, vid)
{
   cid = $(cid); if (!cid) return;
   cid.className = 'red_light';
   cid.addEvent('click', function(){this.className = 'green_light'; if (vid) $(vid).setHTML('');});
}

function showMenu(menuid, divid)
{
   var menu = $(menuid);
   var div = $(divid);
   if (menu == undefined || div == undefined) return;
   var size = menu.getSize()['size'];
   var coor = menu.getCoordinates();
   div.style.top = coor.top + size['y'];
   div.style.left = coor.left;
   div.style.visibility = 'visible';
}

function shBlock(menuid, divid)
{
   var menu = $(menuid);
   var el = $(divid);
   if (menu == undefined || el == undefined) return;
   var size = menu.getSize()['size'];
   var coor = menu.getCoordinates();
   el.style.zIndex = '999999999';
   el.style.position = 'absolute';
   el.style.top = coor.top + size['y'] + 'px';
   el.style.left = coor.left + 'px';
   el.display();
}

function addTag(tag, type)
{
  if (tag != '')
  {
    ajax.cdcall('ServiceTags::addTag', tag, type);
  }
}

function navLink(pagenumber)
{
  pagenumber++;
  path = pre + '/' + pagenumber;
  window.location.assign(path);
}

function ucfirst(str)
{
  str += '';
  var f = str.charAt(0).toUpperCase();
  return f + str.substr(1, str.length-1);
}

function createCrop(id, w, h)
{
  if (!$(id)) return;
  var crop = new MooCrop(id, {imgwidth: w, imgheight: h});
  var indicator = new Element('span', {'styles': {'position': 'absolute', 'display': 'none', 'padding': '4px', 'opacity': '.7', 'background': '#ffffff', 'border': '1px solid #525252', 'font-size': '11px'}}).injectInside(crop.wrapper);
  indicator.setStyles({'top': crop.getCropInfo().bottom + 10, 'left': crop.getCropInfo().left}).set('text', 'w: ' + crop.getCropInfo().width + ' h: ' + crop.getCropInfo().height);
  crop.addEvent('onBegin', function(imgsrc,crop,bound,handle){indicator.setStyle('display', 'block');});

  var extWidth = 'imgwidth';
  var extHeight = 'imgheight';

  if ( id == 'imgsourcelogo' )
  {
    extWidth = 'imgwidthlogo';
    extHeight = 'imgheightlogo';
  }

  crop.addEvent('onCrop', function(imgsrc,crop,bound,handle){indicator.setStyles({'top': crop.bottom + 10, 'left': crop.left}).set('text', 'w: ' + crop.width + ' h: ' + crop.height); $(extWidth).value = crop.width; $(extHeight).value = crop.height;});
  crop.addEvent('onComplete' , function(){indicator.setStyle('display', 'none');});

  return crop;
}

function serialize( mixed_val ) {    // Generates a storable representation of a value
    //
    // +   original by: Ates Goral (http://magnetiq.com)
    // +   adapted for IE: Ilia Kantor (http://javascript.ru)

    switch (typeof(mixed_val)){
        case "number":
            if (isNaN(mixed_val) || !isFinite(mixed_val)){
                return false;
            } else{
                return (Math.floor(mixed_val) == mixed_val ? "i" : "d") + ":" + mixed_val + ";";
            }
        case "string":
            return "s:" + mixed_val.length + ":\"" + mixed_val + "\";";
        case "boolean":
            return "b:" + (mixed_val ? "1" : "0") + ";";
        case "object":
            if (mixed_val == null) {
                return "N;";
            } else if (mixed_val instanceof Array) {
                var idxobj = { idx: -1 };
        var map = []
        for(var i=0; i<mixed_val.length;i++) {
            idxobj.idx++;
                        var ser = serialize(mixed_val[i]);

            if (ser) {
                            map.push(serialize(idxobj.idx) + ser)
            }
        }

                return "a:" + mixed_val.length + ":{" + map.join("") + "}"

            }
            else {
                var class_name = get_class(mixed_val);

                if (class_name == undefined){
                    return false;
                }

                var props = new Array();
                for (var prop in mixed_val) {
                    var ser = serialize(mixed_val[prop]);

                    if (ser) {
                        props.push(serialize(prop) + ser);
                    }
                }
                return "O:" + class_name.length + ":\"" + class_name + "\":" + props.length + ":{" + props.join("") + "}";
            }
        case "undefined":
            return "N;";
    }

    return false;
}

function substr( f_string, f_start, f_length ) {    // Return part of a string
    //
    // +     original by: Martijn Wieringa

    if(f_start < 0) {
        f_start += f_string.length;
    }

    if(f_length == undefined) {
        f_length = f_string.length;
    } else if(f_length < 0){
        f_length += f_string.length;
    } else {
        f_length += f_start;
    }

    if(f_length < f_start) {
        f_length = f_start;
    }

    return f_string.substring(f_start, f_length);
}

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
    return [curleft,curtop];
  }
}

function str_replace (search, replace, subject)
{
  if(!(replace instanceof Array))
  {
    replace = new Array(replace);
    if(search instanceof Array)
      while(search.length > replace.length)
        replace[replace.length]=replace[0];
  }

  if(!(search instanceof Array))
    search = new Array(search);
  while(search.length > replace.length)
    replace[replace.length] = '';

  if(subject instanceof Array)
  {
    for(k in subject)
      subject[k]=str_replace(search,replace,subject[k]);
    return subject;
  }

  for(var k=0; k<search.length; k++)
  {
    var i = subject.indexOf(search[k]);
    while(i>-1)
    {
      subject = subject.replace(search[k], replace[k]);
      i = subject.indexOf(search[k],i);
    }
  }

  return subject;
}

function setCookie (name, value, path, expires, domain, secure)
{
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookie(name)
{
  var cookie = " " + document.cookie;
  var search = " " + name + "=";
  var setStr = null;
  var offset = 0;
  var end = 0;
  if (cookie.length > 0)
  {
    offset = cookie.indexOf(search);
    if (offset != -1)
    {
      offset += search.length;
      end = cookie.indexOf(";", offset)
      if (end == -1)
        end = cookie.length;
      setStr = unescape(cookie.substring(offset, end));
    }
  }
  return(setStr);
}

function setFeedback()
{
  backajax = new Ajax();
  backajax.call('setFeedbackCookies');
  return false;
}
