function openNewWindowForImage(imgPath, title)
{
    var img = document.createElement('img')
    var w = window.open("", "", "height=100,width=100,toolbar=no,location=no,statusbar=no,menubar=no,scrollbars=no,resizable=yes")
    w.document.write("<html><head><title>" + title + "</title></head><body style='margin:0;padding:0'><h1>Загружается</h1></body></html>")
    img.onload = function() {
        w.document.body.innerHTML = "<img src='"+ imgPath +"' />"
        w.document.close()
        w.resizeTo(this.offsetWidth, this.offsetHeight + 50)
        setTimeout("this.onload()", 1000);
        //alert([this.offsetHeight, this.offsetWidth])
        this.onload = null 
        this.onerror = null
        document.body.removeChild(this)
    }

    img.src = imgPath
    document.body.appendChild(img)
}

createFunction = function(fun, obj)
{
    return function(){
	   fun.apply(obj, $A(arguments))
	}
}

var addMyListener = function(element,name,func,capture) {
    if (element.addEventListener) { // not IE
        element.addEventListener(name,func,capture);
    } else {
        if (element.attachEvent) { // IE
            element.attachEvent("on"+name,func);
        }
    }
}

var removeMyListener = function(element,name,func,capture) {
    if (element.removeEventListener) { // not IE
        element.removeEventListener(name,func,capture);
    } else {
        if (element.detachEvent) { // IE
            element.detachEvent("on"+name,func);
        }
    }
}

/**
* для работы с куками
*/
var Cookie = function(){};
Cookie.prototype = {
	GetCookie : function(name){
		var arg = name + "=";
		var i = 0;
			while (i<document.cookie.length){
				var j = i + arg.length;
				if (document.cookie.substring(i,j) == arg) return this._G(j);
				i = document.cookie.indexOf(" ",i) + 1;
				if (i == 0) break;
			};
			return null;
	},
	/**
	* expires - время жизни куки с текущего момента, в миллисекундах, integer
	*/
	SetCookie : function(name, value, expires, path, domain, secure){
		document.cookie = name + '=' + escape(value) +
		((expires)? '; expires='  + (new Date((new Date()).getTime() + expires)).toGMTString() : '') +
		((path)?    '; path='     + path   : '; path=/') +
		((domain)?  '; domain='   + domain : '') +
		((secure)?  '; secure':''); 
	},
	DeleteCookie : function(name, path, domain){
		if (this.GetCookie(name)){
			document.cookie = name + '=' +
			((path)? '; path=' + path:'; path=/') +
			((domain)? '; domain=' + domain :'')+
			'; expires=Thu, 01-jan-70 00:00:01 GMT';
		}
	},
	_G : function(offset){
		var endstr = document.cookie.indexOf(";",offset);
		if (endstr == -1) endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
};
