Proto.go=function(url)
      {
    		document.location.href=url;
      }
Proto.chet=function(i)
{
    if(isNaN(i)){ throw('This is not a Number');return;}
    
    return( (Math.round(i/2))*2 == i );
}
Proto.toHash=function(obj,prefix){
       
       var cnt = 0;
       var ret = new Hash();
    for (var p in obj) 
    {
        
        if(typeof obj[p]=="object" || typeof obj[p]=="array")
            {
               // if(p!="elements"){
                    tmp = prefix+"-"+p;
                    //}else{tmp=prefix;}
                ret = ret.merge(Proto.toHash(obj[p],tmp));
                cnt++;
            }
            else
            {
                tmp = ((prefix!="")?prefix+"-"+p:p);
                ret.set( tmp , obj[p] );
            }
        
    }
      return ret;         

    };
    
Proto.print_r=function (theObj, include_functions){
        var str="";
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
     str+="<ul>";
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
        str+="<li>["+p+"] => "+typeof(theObj);
        str+="<ul>";
        str+=Proto.print_r(theObj[p]);
        str+="</ul> </li>";
      } else {
          if (!include_functions && typeof theObj[p] != "function") {
              str += "<li>[" + p + "] => " + theObj[p] + "</li>";
          }
      }
    }
    str+="</ul>";
  }
  return str;
}


Proto.replaceInputType=function(el,newType)
{
    var newEl = new Element("input",{type:newType,id:el.id,name:el.name,value:el.value,'class':el.className,style:el.style});
    el.parentNode.insertBefore(newEl,el);
    el.remove();
    return(newEl);
}



Element.addMethods({
  getNumStyle: function(element, style) {
    var value = parseFloat(_(element).getStyle(style));
    return isNaN(value) ? null : value;
  },
  getAttributeDimensions: function(element, attribut ) {
    var dim = $w('top bottom left right').inject({}, function(dims, key) {
      dims[key] = element.getNumStyle(attribut + "-" + key + (attribut == "border" ? "-width" : ""));
      return dims;
    });
    dim.width  = dim.left + dim.right;
    dim.height = dim.top + dim.bottom;
    return dim;
  },

  getBorderDimensions:  function(element) {return element.getAttributeDimensions("border")},
  getMarginDimensions:  function(element) {return element.getAttributeDimensions("margin")},
  getPaddingDimensions: function(element) {return element.getAttributeDimensions("padding")},
  
  getAllDimensions:function(element)
  {
  	var h = element.getHeight()+element.getBorderDimensions().height+element.getMarginDimensions().height+element.getPaddingDimensions().height;
  	var w = element.getWidth()+element.getBorderDimensions().width+element.getMarginDimensions().width+element.getPaddingDimensions().width;
  	return ({width:w, height:h});
  }
});

document.observe("dom:loaded", function() {
document.observe(((Prototype.Browser.WebKit)?'keydown':'keypress'),function(e){

if(e.keyCode==Event.KEY_ESC){
Event.stop(e);

Proto.UI.Dialogs.each(function(d){
	     	if(!d.container.hasClassName("ProtoDialogBlired")&&!d.minimize)
	     		{
	     			d.close();
	     		}
	     	});



}
});
});
Object.extend(Array.prototype, {
  empty: function() {
    return !this.length;
  },

  extractOptions: function() {
    return this.last().constructor === Object ? this.pop() : { };
  },

  removeAt: function(index) {
    var object = this[index];
    this.splice(index, 1);
    return object;
  },

  remove: function(object) {
    var index;
    while ((index = this.indexOf(object)) != -1)
      this.removeAt(index);
    return object;
  },

  insert: function(index) {
    var args = $A(arguments);
    args.shift();
    this.splice.apply(this, [ index, 0 ].concat(args));
    return this;
  }
});
Element.addMethods({
  getScrollDimensions: function(element) {
    return {
      width:  element.scrollWidth,
      height: element.scrollHeight
    }
  },

  getScrollOffset: function(element) {
    return Element._returnOffset(element.scrollLeft, element.scrollTop);
  },

  setScrollOffset: function(element, offset) {
    element = _(element);
    if (arguments.length == 3)
      offset = { left: offset, top: arguments[2] };
    element.scrollLeft = offset.left;
    element.scrollTop  = offset.top;
    return element;
  },

  // returns "clean" numerical style (without "px") or null if style can not be resolved
  // or is not numeric
  getNumStyle: function(element, style) {
    var value = parseFloat(_(element).getStyle(style));
    return isNaN(value) ? null : value;
  },

  // by Tobie Langel (http://tobielangel.com/2007/5/22/prototype-quick-tip)
  appendText: function(element, text) {
    element = _(element);
    text = String.interpret(text);
    element.appendChild(document.createTextNode(text));
    return element;
  }
});

function _proc(ish,pr)
{
return((pr*(ish/100)));
}


var currenthash="";//document.location.hash.replace("#","");


function getXMLDocument(url)
{
    var xml;
    if(window.XMLHttpRequest)
    {
        xml=new window.XMLHttpRequest();
        xml.open("GET", url, false);
        xml.send("");
        return xml.responseXML;
    }
    else
        if(window.ActiveXObject)
        {
            xml=new ActiveXObject("Microsoft.XMLDOM");
            xml.async=false;
            xml.load(url);
            return xml;
        }
        else
        {
            alert("Загрузка XML не поддерживается браузером");
            return null;
        }
}
  /*var parseDateString= function(i)
         {
				var rg = /:|-| |\./;
				var rg2 = /,0(\d)/;
				var str = i.gsub(rg,",").gsub(rg2,",#{1}");
				try { 
				    eval("var ar =["+str+"];"); 
				    ar[1]--;
				    //alert(ar.toJSON());
				    var d = new Date(ar[0],ar[1],ar[2],ar[3],ar[4])
				    
				    }
				catch (e){ return (this.date) }
				//d.setMonth(d.getMonth()-1);
				var rg3 = /\:/;
				if(!rg3.test(i)){ d.setDate(d.getDate()-1)}
				//document.title= str+" :: "+d;
				return(d);
         }
         
     */    
Proto.UI.counterEffect=Class.create({
       	initialize: function() 
        {
                      
        	this.options = Object.extend({
        	       element:false,
        	       duration:1
                }, arguments[0] || { });
                
                if(this.options.element.tagName=="INPUT")
                {
                    this.set=function(value)
                    {
                        this.options.element.value=value;
                    }.bind(this);
                    this.get=function()
                    {
                        return(this.options.element.value);
                    }.bind(this);
                    
                }
                else
                {
                    this.set=function(value)
                    {
                        this.options.element.update(value);
                    }.bind(this) ;
                    
                    this.get=function()
                    {
                        var v=Number(this.options.element.innerHTML);
                        return((!isNaN(v))?v:0);
                    }.bind(this);               
                }
                return(this)
        },
        upd:function(v)
        {
            if(this.process){ return; }
            this.process=true;
            new Effect.Tween(null, this.get(), v,{ 
                            duration:this.options.duration,
                            afterFinish:function()
                                { 
                                this.process=false;this.set(v);
                                }.bind(this)
                                }, function(p){ this.set(Math.round(p)) }.bind(this)); 
        
        }
                       
});