self.onError=null;

currentX = currentY = 0;  
whichIt = null;           
lastScrollX = -10; lastScrollY = -50;
	
NS = ((document.getElementById && !document.all) || document.layers) ? 1 : 0;
IE = (document.all) ? 1: 0;

var x,y;

/*var startX = 10, startY = 0;
function JSFX_FloatTopLeft()
{
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	var px = document.layers ? "" : "px";
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
		el.x = startX; el.y = startY;
		return el;
	}
	window.stayTopLeft=function()
	{
		var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		var dY = (pY > startY) ? pY : startY;
		ftlObj.y += (dY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 20);
	}
	ftlObj = ml("popupContainer");
	stayTopLeft();
}
JSFX_FloatTopLeft();*/

// floating feeadback box
function floatFeedback() {
	if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }
    if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }
		
	if(diffY != lastScrollY) {
		percent = .1 * (diffY - lastScrollY);
		if(percent > 0) 
			percent = Math.ceil(percent);
		else 
			percent = Math.floor(percent);
		if(IE) 
			document.all.popupContainer.style.pixelTop += percent
		if(NS) 
			document.getElementById("popupContainer").style.top += percent + "px"; 
		lastScrollY = lastScrollY + percent;
    }
	if(diffX != lastScrollX) {
		percent = .1 * (diffX - lastScrollX);
		if(percent > 0) 
			percent = Math.ceil(percent);
		else 
			percent = Math.floor(percent);
		if(IE) 
			document.all.popupContainer.style.pixelLeft += percent;
		if(NS) 
			document.getElementById("popupContainer").style.left += percent + "px";
		lastScrollX = lastScrollX + percent;
	}	
}

function grabIt(e) {
	document.getElementById("popupTitleBar").style.cursor = "move";
	if(IE) {
		whichIt = event.srcElement;
		while (whichIt.id.indexOf("popupTitleBar") == -1) {
			whichIt = whichIt.parentElement;
			if (whichIt == null) { return true; }
	    }
   	    whichIt = document.getElementById("popupContainer");
		whichIt.style.pixelLeft = whichIt.offsetLeft;
	    whichIt.style.pixelTop = whichIt.offsetTop;
		currentX = (event.clientX + document.body.scrollLeft);
   		currentY = (event.clientY + document.body.scrollTop); 	
	} else {      
		whichIt = e.target;
		while (whichIt.id.indexOf("popupTitleBar") == -1) {
			whichIt = whichIt.parentNode;
			if (whichIt == null || whichIt.id == undefined) { return true; }
	    }
		whichIt = document.getElementById("popupContainer");
		currentX = parseInt(whichIt.style.left+0,10);
		currentY = parseInt(whichIt.style.top+0,10);
		x = e.clientX;
		y = e.clientY;
	}
    return true;
}
	
function moveIt(e) {
	if (whichIt == null || whichIt.style == undefined) { return false; }
	if(IE) {
	    newX = (event.clientX + document.body.scrollLeft);
	    newY = (event.clientY + document.body.scrollTop);
	    distanceX = (newX - currentX);    distanceY = (newY - currentY);
	    currentX = newX;    currentY = newY;
	    whichIt = document.getElementById("popupContainer");
	    whichIt.style.pixelLeft += distanceX;
	    whichIt.style.pixelTop += distanceY;
		if(whichIt.style.pixelTop < document.body.scrollTop) 
			whichIt.style.pixelTop = document.body.scrollTop;
		if(whichIt.style.pixelLeft < document.body.scrollLeft) 
			whichIt.style.pixelLeft = document.body.scrollLeft;
		if(whichIt.style.pixelLeft > document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20) 
			whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20;
		if(whichIt.style.pixelTop > document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5) 
			whichIt.style.pixelTop = document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5;
		event.returnValue = false;
	} else {        	
		whichIt.style.left = currentX + e.clientX - x + "px";  	
		whichIt.style.top  = currentY + e.clientY - y + "px";
        if(parseInt(whichIt.style.left) < 0+self.pageXOffset) 
        	whichIt.style.left = 0+self.pageXOffset + "px";
		else if((parseInt(whichIt.style.left) + parseInt(whichIt.style.width)) >= (window.innerWidth+self.pageXOffset-17))
        	whichIt.style.left = ((window.innerWidth+self.pageXOffset)-parseInt(whichIt.style.width))-17 + "px";

        if(parseInt(whichIt.style.top) < 0+self.pageYOffset) 
        	whichIt.style.top = 0+self.pageYOffset + "px";
		else if((parseInt(whichIt.style.top) + parseInt(whichIt.style.height)) >= (window.innerHeight+self.pageYOffset-17)) 
        	whichIt.style.top = ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17 + "px";
		
        	
        return false;
	}
    return false;
}
	
function dropIt() {
	whichIt = null;
    if(NS) window.releaseEvents (Event.MOUSEMOVE);
    return true;
}
	
if(NS) {
	window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);
	window.onmousedown = grabIt;
 	window.onmousemove = moveIt;
	window.onmouseup = dropIt;
}
if(IE) {
	document.onmousedown = grabIt;
 	document.onmousemove = moveIt;
	document.onmouseup = dropIt;
}

//if (!isSafari)
//	if(NS || IE) action = window.setInterval("floatFeedback()",1);

// swap images in the feedback box for their white sister image
function insertWhiteImage(content) {
	var tempString = content;
	
	while(tempString.indexOf("'") != -1 && tempString.indexOf(">") != -1) {	
		tempString = tempString.replace("'", "");
		tempString = tempString.replace(">", "");
	}
	var array = tempString.split("/");
					
	var imageName = "";
	for (var i = array.length - 1; i >= 0; i--) {
		if (array[i].indexOf(".gif") != -1) {
			imageName = (array[i].substring(0, array[i].indexOf(".gif") + 4));
			if (imageName != "" && content.indexOf(imageName) != -1 && content.indexOf("w" + imageName) == -1) {
				while (content.indexOf("/" + imageName) != -1) {
					content = content.replace("/" + imageName, "/w" + imageName);
				}
			}
		}
	}
		
	return content;
}
