	
/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var initClose = false;
function closeRoot() {
	initClose = true;	
	dirFade = -1;
	window.clearInterval(timerResize);
	timerFade = window.setInterval("fadeIn()", 30);		
}

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);
		
		ieAlpha = (this.root.filters)? true:false;
		mzAlpha = (this.root.style.MozOpacity)? true:false;
		this.root.startopacity = (ieAlpha)? ((this.root.filters["alpha"].opacity)/100) : (this.root.style.MozOpacity);
		if (ieAlpha) this.root.filters["alpha"].opacity = 65
		else this.root.style.MozOpacity =  0.65;	

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;
		
		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;	
		
		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		var o = Drag.obj.root;
		if ( initClose == false ) {
			if (ieAlpha) o.filters["alpha"].opacity = o.startopacity * 100
			else o.style.MozOpacity =  o.startopacity;	
		}
		
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};


	
	/*************************************************************************

	  dw_viewport.js
	  version date Nov 2003
	  
	  This code is from Dynamic Web Coding 
	  at http://www.dyn-web.com/
	  Copyright 2003 by Sharon Paine 
	  See Terms of Use at http://www.dyn-web.com/bus/terms.html
	  regarding conditions under which you may use this code.
	  This notice must be retained in the code as is!
	
	*************************************************************************/  
	  
	var viewport = {
	  getWinWidth: function () {
		this.width = 0;
		if (window.innerWidth) 
		this.width = window.innerWidth - 18;
		else if (document.documentElement && document.documentElement.clientWidth) 
			this.width = document.documentElement.clientWidth;
		else if (document.body && document.body.clientWidth) 
			this.width = document.body.clientWidth;
	  },
	  
	  getWinHeight: function () {
		this.height = 0;
		if (window.innerHeight) this.height = window.innerHeight - 18;
		else if (document.documentElement && document.documentElement.clientHeight) 
			this.height = document.documentElement.clientHeight;
		else if (document.body && document.body.clientHeight) 
			this.height = document.body.clientHeight;
	  },
	  
	  getScrollX: function () {
		this.scrollX = 0;
		if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
		else if (document.documentElement && document.documentElement.scrollLeft)
			this.scrollX = document.documentElement.scrollLeft;
		else if (document.body && document.body.scrollLeft) 
			this.scrollX = document.body.scrollLeft; 
		else if (window.scrollX) this.scrollX = window.scrollX;
	  },
	  
	  getScrollY: function () {
		this.scrollY = 0;    
		if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
		else if (document.documentElement && document.documentElement.scrollTop)
			this.scrollY = document.documentElement.scrollTop;
		else if (document.body && document.body.scrollTop) 
			this.scrollY = document.body.scrollTop; 
		else if (window.scrollY) this.scrollY = window.scrollY;
	  },
	  
	  getAll: function () {
		this.getWinWidth(); this.getWinHeight();
		this.getScrollX();  this.getScrollY();
	  }
  
}

/////////////////////////////////////////////////

function captureEvt(obj) {
		targetObj = obj;
	}
	
	// TPPlus for OrderPopup
	var generalx = 0;
	var generaly = 0;
	// End
	function getPosition(e)
	{
		viewport.getAll();
		var posx = 0;
		var posy = 0;
		if (!e) var e = window.event;
		/*if (e.pageX || e.pageY)
		{
			// TPPlus
			generalx = posx = e.pageX;
			generaly = posy = e.pageY;	
			// End	
			alert(generalx + "   " + generaly);		
		}
		else*/if (/*e.clientX || e.clientY*/true)
		{
			// TPPlus
			//alert(viewport.scrollX);
			//alert(viewport.scrollY);
			//alert(viewport.width);
			//alert(viewport.height);
			//418
			generalx = posx = viewport.width + viewport.scrollX - 420; //e.clientX + viewport.scrollX;
			generaly = posy = viewport.scrollY; //e.clientY + viewport.scrollY;				
			//alert(viewport.scrollY);
		}
		
		if ( targetObj ) {
			emptyBufferContainer();
			theInfo.className = "infoLoad";
			theInfo.innerHTML = theInfoLoading;
			// if (ieAlpha) theRoot.filters["alpha"].opacity = 20
			if (ieAlpha) theRoot.filter = "alpha(opacity=20)";
			else theRoot.style.MozOpacity = 0.2;
			
			window.clearInterval(timerFade);
			window.clearInterval(timerResize);
			resizeRoot( false );
			repositionRoot(posx, posy);
		}		
	}
	var objClickX=0;
	var objClickY=0;
	function repositionRoot (posx, posy) {
			/*if (!objClickX) */objClickX = posx;
			/*if (!objClickY)*/ objClickY = posy;
			
			var rootH = 0;//theRoot.offsetHeight;
			var rootW = 0;//theRoot.offsetWidth;
			
			if (( objClickX + rootW + posOffsetX ) > viewport.width) {
				if (( objClickX - rootW - posOffsetX ) > 0) {
					theRoot.style.left = ( objClickX - rootW - posOffsetX ) + "px";
				} else {
					theRoot.style.left = ( viewport.scrollX + viewport.width - posOffsetX - rootW ) + "px";
				}
			} else {
				theRoot.style.left = (objClickX + posOffsetX) + "px";
			}
						
			if (( objClickY - rootH + posOffsetY ) < 0 ) {
				if (( objClickY + rootW - posOffsetY ) < viewport.height ) {
					theRoot.style.top = ( objClickY - posOffsetY ) + "px";
				} else {
					theRoot.style.top = posOffsetY + "px";
				}
			} else {
				theRoot.style.top = (objClickY + posOffsetY - rootH) + "px";
			}
			
			theRoot.style.visibility = 'visible';
			dirFade = 1;
			timerFade = window.setInterval("fadeIn()", 30);
			targetObj = null;
	}
	
	function getBufferContainer() {
		var bufferDiv = null;
		bufferDiv = document.getElementById("bufferATLAS");
		if (!bufferDiv) return null;
		var spanColl = bufferDiv.getElementsByTagName("span");
		if (!spanColl) return bufferDiv;
		if (!spanColl.length) return bufferDiv;
		return spanColl[0];
	}
	function emptyBufferContainer() {
		var bufferDiv = document.getElementById("bufferATLAS");
		if (!bufferDiv) return null;
		var spanColl = bufferDiv.getElementsByTagName("span");
		if (!spanColl) return null;
		if (!spanColl.length) return null;
		spanColl[0].innerHTML = "";
	}
	
	var timerFade = null;
	var timerResize = null;
	
	function serviceOnComplete() {
		theInfo.className = "infoData";
		theInfo.innerHTML = theBuffer.innerHTML;
		resizeRoot( true );
		objClickX = 0; objClickY = 0;	
	}
	
	function serviceOnTimeout() {
		theInfo.innerHTML = "Error getting content";
		theInfo.className = "infoLoad";
	}
		
	function resizeRoot( incremental) {
		resizeEndH = theInfo.offsetHeight + theHandle.offsetHeight+4;
		resizeEndW = theInfo.offsetWidth+8;		
		if ( incremental ) {			
			timerResize = window.setInterval( "slideSize()" , 3 );
		} else {
			theRoot.style.height = resizeEndH + "px" ;
			theRoot.style.width = resizeEndW + "px";
			resizeIncH = resizeEndH;
			resizeIncW = resizeEndW;
		}
		
	}
	
	var resizeEndH = 300;
	var resizeEndW = 300;
	var resizeIncW = 150;
	var resizeIncH = 150;
	var resizeSteps = 10;
	
	function slideSize() {
		var refHeight = ((resizeEndH-resizeIncH) > (resizeEndW - resizeIncW));
		
		var currH = parseInt(theRoot.style.height);
		var currW = parseInt(theRoot.style.width);
		
		var refDim = refHeight? resizeEndH : resizeEndW;
		var dif = refHeight? (resizeEndH-currH) : (resizeEndW-currW);
		
		if ( (dif - resizeSteps) > 0 ) {
			if ( (currH  + resizeSteps) < resizeEndH ) theRoot.style.height= (currH + resizeSteps) + "px";
			else theRoot.style.height = resizeEndH + "px";
			
			if ( ( currW  + resizeSteps) < resizeEndW ) theRoot.style.width= (currW + resizeSteps) +  "px";
			else theRoot.style.width = resizeEndW + "px";
		} else {
			window.clearInterval( timerResize);
			theRoot.style.height = resizeEndH + "px";
			theRoot.style.width = resizeEndW + "px";
		}
		
	}
	
	var dirFade=1;	
	var ieAlpha = false;
	var mzAlpha = false;
	var alphaStep = 0.075;
	
	function fadeIn(  ) {	
			ieAlpha = (theRoot.filters)? true:false;
			mzAlpha = (theRoot.style.MozOpacity)? true:false;
			var currentAlpha = (ieAlpha) ? ((theRoot.filters["alpha"].opacity)/100):(theRoot.style.MozOpacity);

			if(!currentAlpha) {
				window.clearInterval(timerFade);
				return;
			}
			
			var finalAlpha;
			var tmpAlpha = 0.1;
			
			if (dirFade == 1) {
			    
				if ( (currentAlpha + alphaStep) >= 1  ) {
					//if (ieAlpha) theRoot.filters["alpha"].opacity = 100
					if (ieAlpha) theRoot.filter = "alpha(opacity=100)";
					else theRoot.style.MozOpacity =  1
					clearInterval(timerFade);
					timerFade = null;
					dirFade = -1;
				} else {
					if (ieAlpha) { 
						theRoot.filters["alpha"].opacity = (parseFloat(currentAlpha) + alphaStep)*100;
						/*var tmp = (parseFloat(currentAlpha) + alphaStep)*100;
						theRoot.filter = "alpha(opacity=" + tmp + ")";*/
					}
					else {
						theRoot.style.MozOpacity = parseFloat(currentAlpha) + alphaStep;
					}
						
				}
			} else {
				if ( (currentAlpha - alphaStep) < 0.05  ) {
					// if (ieAlpha) theRoot.filters["alpha"].opacity = 5
					if (ieAlpha) theRoot.filter = "alpha(opacity=5)";
					else theRoot.style.MozOpacity =  0.05;	
					theRoot.style.visibility = "hidden";
					window.clearInterval(timerFade);
					
					initClose = false;
					dirFade = 1;
				} else {
					if (ieAlpha) theRoot.filters["alpha"].opacity = (currentAlpha - alphaStep)*100
					else theRoot.style.MozOpacity =  parseFloat(currentAlpha) - alphaStep;				
				}
			}
	}
	
	
	function trimAll(sString)
	{
		while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
		sString = sString.substring(0,sString.length-1);
		}
		return sString;
	}
	
	function Height(boxesvisible)
	{
	    viewport.getAll();
	    var headerheight = 0;
	    var footerheight = 0;
	    var totalheight = 0;
	    var header = document.getElementById('TP_Master_HeaderBlock');
	    var footer = document.getElementById('tableFooter');
	    var itemlist = document.getElementById('Tehava_Catalog');
	    var homeitemframe = document.getElementById('homeitemframe');
	    var tdCatalog = document.getElementById('tdCatalog');
	    var tdItemList = document.getElementById('tdItemList');
        var itemListBlock = document.getElementById('itemlistblock');
        var shoppingcartblock = document.getElementById('shoppingcartblock');
        var Tehava_ItemBoxes_Visible = document.getElementById('hidden_itemboxes_visible');
        var categoryFrame = document.getElementById('categoryFrame'); 
        
        if (header == null || footer == null || itemlist == null || homeitemframe == null || tdItemList == null || itemListBlock == null || shoppingcartblock == null || Tehava_ItemBoxes_Visible == null || categoryFrame == null || tdCatalog == null)
        {
            return;
        }
        
        headerheight = header.offsetHeight;
        
        //alert(footer.offsetHeight);
        footerheight = footer.offsetHeight;
        //alert(viewport.height);
        totalheight = viewport.height;
        
        // headerheight = header.offsetHeight;
        var rest = totalheight - headerheight - footerheight;
        rest = rest - 25; // Small correction
        
        var heightitemlist;
        var heightcart;
        
        // If show the normal catalog catalog split the screen in half
        // Tehava_ItemBoxes_Visible.value
        if (/*boxesvisible == */false)
        {
            heightitemlist = Math.round(rest / 2);
            heightcart = Math.round(rest / 2);
        }
        // If we show the promotions,out of stock, new products or soon available items devide the screen 75 / 25
        else
        {
            heightitemlist = Math.round(rest * 0.75);
            heightcart = Math.round(rest * 0.25);
        }
        
        // ItemListscroller is always 20 pixels than the itemlistblock
        // Shoppingcart scroller is 45 pixels less than the soppingblock
        if (rest - 160 < 0)
            return;
        homeitemframe.style.height = 160 + 'px'; // 170 is the height of one itembox in the upper left corner
        categoryFrame.style.height = rest - 160 + 'px'; // 170 is the height of one itembox in the upper left corner
        tdCatalog.style.height = rest + 'px';
        tdItemList.style.height = rest + 'px';
        
        itemListBlock.style.height = (heightitemlist - 20) + 'px';
        //Tehava_ItemList_Scroller.style.overflow = 'scroll';
        //Tehava_ItemList_Scroller.style.height = heightitemlist - 25 + 'px'; // 25 is the size of the red header
        shoppingcartblock.style.height = heightcart - 15 + 'px'; // 15 is the padding between the item list and shopping basket    
	}
	
	function ExplodeShoppingBasket()
	{
	    var itemListBlock = document.getElementById('itemlistblock');
        var shoppingcartBlock = document.getElementById('shoppingcartblock');
        var tditemlist = document.getElementById('tdItemList');
        
        itemListBlock.style.height = 0 + 'px';
        shoppingcartBlock.style.height = (parseInt(tditemlist.style.height) - 27) + 'px';
	}
	
	