var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();

var is_opera = (agt.indexOf('opera') != -1);
var is_ie  = (appVer.indexOf('msie') != -1);
var is_gecko = ((navigator.product)&&(navigator.product.toLowerCase()=='gecko'))?true:false;

function resize()
{
        var x = this.document.getElementById('img').width + 56;
        var y = this.document.getElementById('img').height + 240;
        if (x < 400) 
		x = 400;

	if (is_ie && !is_opera && !is_gecko) {
		window.resizeTo(x, y);
	} else {
		window.sizeToContent();
	}

}


var e;
function p(name, x, y)
{
        if (!x || (x <= 0) ) {x = 600 }
        if (!y || (y <= 0) ) {y = 400 }
	e = window.open(name , 'pic', 'scrollbars=no,width=' + x + ',height=' + y);
	if (window.focus) { e.focus(); }

	return false;
}


function basket(id)
{

	var url = '/basket/?';

	if (id > 0) {
          var obj = document.getElementById('t' + id);
          var t = 1;

          if (obj) {
                t = obj.value;
          }
	  if (t < 1) 
	    t = 1;

          url = url + 'good=' + id + '&t=' + t;
	}

        return openbasket(url);
}


function order(id)
{

	var url = '/basket/?';

	if (id > 0) {
          url = url + 'order=' + id;
	}

        return openbasket(url);

}

function checkedbasket (off)
{
	var url = '/basket/?';

	var form = document.getElementById('content-form');

	if (form)
	{
                var c = form.elements;
		for (i=0; i< c.length; i++)
		{
			if (c[i].type == 'checkbox' && c[i].name == 'id' && (off || c[i].checked == true))
                        {
                            var id = c[i].value;
                            var obj = document.getElementById('t' + id); 
                            var t = 1;
                            if (obj) {
                                t = obj.value;
                            }
	  	  	    if (t < 1) 
	  	  	        t = 1;
                    
                            url += 'good=' + id + '&t' + id + '=' + t + '&';
                        }
                }
        }

        return openbasket(url);

}

function openbasket (url)
{

	e = window.open(url, 'basket', 'scrollbars=yes,width=600,height=400');
	if (window.focus) { e.focus(); }
	return false;
}

function check()
{
	var form = document.getElementById('content-form');

	if (form)
	{
                var c = form.elements;
		for (i=0; i< c.length; i++)
		{
			if (c[i].type == 'checkbox' && c[i].name == 'id')
                        	c[i].checked = true;
		}
	}
}


function uncheck()
{
	var form = document.getElementById('content-form');

	if (form)
	{
                var c = form.elements;
		for (i=0; i< c.length; i++)
		{
			if (c[i].type == 'checkbox' && c[i].name == 'id')
                        	c[i].checked = false;
		}
	}
}


function el_move(el, left, top) {
        if (!el) return false;
        el.style.left = left + "px";
        el.style.top = top + "px";
}

function el_get_dimensions(el) {
        if (el.style.display != 'none') {
              return {w:el.offsetWidth,h:el.offsetHeight};
        }
        return {w:el.clientWidth,h:el.clientHeight};
}

function el_get_position(el) {
	var x = 0, y = 0;
	do {
		y += el.offsetTop  || 0;
		x += el.offsetLeft || 0;
		el = el.offsetParent;
	} while (el);

	if (navigator.userAgent.indexOf ("Opera") != -1){
    	    y = window.event.y+document.body.scrollTop;
        }
                                                                
	return {x:x,y:y};
	
}

function el_info (el, id) {
    var block = document.createElement('div');
    block.setAttribute('id', id);
    document.body.appendChild(block);
    block.style.display = 'block';
    block.style.position = 'absolute';

    var blockWH = el_get_dimensions(block);
    var blockXY = el_get_position(el);

    blockXY.y = parseInt(blockXY.y) - blockWH.h - 10;
    el_move(block, parseInt(blockXY.x), parseInt(blockXY.y));

}
