/**
 * $Id: impresjo.js 46 2006-10-03 15:05:35Z dream3r $
 */

var tipWidth = 350;

function showTooltip(div_id, img_id, dir) {
  var div = document.getElementById(div_id);
  var img = document.getElementById(img_id);

  if (div.style.display != 'inline') {
    div.style.display = 'inline';
    switch (dir.toLowerCase()) {
      case 'center':
        div.style.left = x - 125 + 'px';
        break;
      case 'left':
        div.style.left = findPosX(img) - tipWidth - 20 + 'px';
        break;
      default:
        div.style.left = x + 'px';
    }

    div.style.top = findPosY(img) + 'px';
  }
}

function hideTooltip(id) {
  var div = document.getElementById(id);
  div.style.display = 'none';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var lastObj;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			lastObj = obj;
			obj = obj.offsetParent;
		}
		if (lastObj != null) {
			curtop += lastObj.offsetParent.offsetTop;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function zoom(winUrl) {
	var img = document.getElementById('product');
	if (img != null) {
		var w = img.width;
		var h = img.height;
		var scale = 0;
		var max = 600;

		if (w >= h) {
			scale = max / w;
		} else {
			scale = max / h;
		}
		w = w * scale;
		h = h * scale;
		popupWnd(winUrl, '', w+50, h+30);
	}
}

function popupWnd(winUrl,winName,width,height,showScroll)  {

	if (isNaN(showScroll) || showScroll == null) {
		showScroll = 0;
	} else {
		showScroll = showScroll ? 1 : 0;
	}

  var left = (screen.width - width) / 2;
  var top = (screen.height - height) / 2;

  winFeatures='width='+width+',height='+height+',titlebar=0,resizable=0,scrollbars='+showScroll+',top='+top+',left='+left;

  window.open(winUrl,winName,winFeatures);
}
var level = 0;
function switchForm(chkbox, id, enable, div) {
	if (level > 10) return;
	if (chkbox != null) {
		var div = document.getElementById(id);
		enable = chkbox.checked;
	}
	obj = div.childNodes;
	for (var i = 0; i < obj.length; i++) {
		e = obj[i];
		if (e.tagName == 'DIV' || e.tagName == 'SPAN') {
			if ( e.childNodes.length > 0 ) {
				level++;
				obj = switchForm(null, '', enable, e);
				level--;
			}
		} else if (e.tagName == 'INPUT') {
			if (enable) {
				e.disabled = 'disabled';
			} else {
				e.disabled = '';
			}
		}
	}
	return div.parentNode.childNodes;
}

function setChecked(id, div_id, enabled) {
	var chkbox = document.getElementById(id);
	if (enabled) {
		chkbox.checked = 'checked';
	} else {
		chkbox.checked = '';
	}
	switchForm(chkbox, div_id, null, null);
}

function mailTo(email) {
	document.loaction='mailto:' + email;
}

function change(obj)
{
  obj.href = obj.href.replace('[at]', String.fromCharCode(64));
}

function basketAdd(url) {
	document.location = url;
	return false;
}
