// Hypertools CMS
// global.js V1.1

// default functions
function setContent(obj,ded,output) {
	tmp = findObj(obj,'');
	tmp.innerHTML = output;
}

function doSubmit(cartAct) {
	obj = findObj('cartAct');
	obj.value = cartAct;
	//obj2 = findObj('frmCart');
	document.frmCart.submit();
}

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

// image functions
function doImgPop(imgSrc,imgAlt) {
	window.open("viewImage.asp?image="+ imgSrc,'viewImage','toolbar=no,location=no,status=no,resizable=yes,width=300,height=300');
}

function doImgMain(objID,imgSrc,imgAlt) {
	tmp = findObj(objID,'');
	tmp.src = "/media/"+ imgSrc;
	tmp.alt = imgAlt;
}

function doImgInline(imageName,theid) {
	document.getElementById('picpreviewimg').src='/media/'+ imageName;
	document.getElementById('picpreview').style.top  = getElementPosition(theid).top  - 50;
	document.getElementById('picpreview').style.left = getElementPosition(theid).left;
	document.globalstore.lastopenID.value = window.setTimeout('doImgInlineAction()',500);
	//document.globalstore.lastcloseID.value = window.setTimeout('closeImageObj()',10000)
	//alert(imageName);
	}

function doImgInlineAction() {
	document.getElementById('picpreview').style.visibility = 'visible';
	}

function closeImageObj() {
	window.clearTimeout(document.globalstore.lastopenID.value);
	window.clearTimeout(document.globalstore.lastcloseID.value);
	document.getElementById('picpreview').style.visibility = 'hidden';
	document.getElementById('picpreviewimg').src='/assets/gfx_site/loading_thumb.gif'
	}

function getElementPosition(elemID) {
	var offsetTrail = document.getElementById(elemID);
	var offsetLeft = 0;
	var offsetTop = -60;
	while (offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") {
		offsetLeft += document.body.leftMargin;offsetTop += document.body.topMargin;
	}
	return {left:offsetLeft, top:offsetTop};
}
