/*
	Title:	Javascript Debug Output Screen
	Author:	Andrew M King
	Email:	andrewtek@excite.com
	Date:	08/23/01
	
	Usage:	Use at own risk. Free to use, Free to copy. If you use this in 
		your applications, please give credit to me somewhere in the 
		comments of your code.
		
	Note:	This program REQUIRES the use of detector.js for div tag 
		acquisition and certain types of divtag manipulation. Please be sure to
		include detector.js before including divtag.js
	
*/

divtag_TOP = 1;
divtag_BOTTOM = 2;
divtag_LEFT = 4;
divtag_RIGHT = 8;

function divtag_divObj(divtag){
	this.divtag = divtag;
	this.contentHandle = divtag;

	/*WHAT IS THE SIZE AND POSITION?*/
	this.xPos = 0;
	this.yPos = 0;
	this.xWid = 0;
	this.yHei = 0;

	/*WHAT ARE THE SCROLLING CONSTRAINTS?*/
	this.minX = 0;
	this.maxX = 0;
	this.minY = 0;
	this.maxY = 0;

	/*DOES THIS OBEY CONSTRAINTS?*/
	this.lConst = false;
	this.rConst = false;
	this.tConst = false;
	this.bConst = false;

	/*SHOULD THE SCROLLING CONSTRAINTS BE INVERTED
		an example of inverting the scrolling constraint would be having a div tag whose xPos must always be LESS than minX (like a scrolling text)
	*/
	this.lConstInv = false;
	this.rConstInv = false;
	this.tConstInv = false;
	this.bConstInv = false;
	
	/*DOES THIS HAVE HTML CONTENT*/
	this.content = '';
}

function divtag_acquireDivtag(divName){
	var currentDivTag, returnDivObj;
	if(detector_browserUsed == "ie" || detector_browserUsed == "n6"){
		var temp
		if(detector_browserUsed == "ie"){
			temp = eval("document.all." + divName);
		}else{
			temp = document.getElementById(divName);
		}
		if(temp != null){
			currentDivTag = temp.style;
		}
		returnDivObj = new divtag_divObj(currentDivTag);
		returnDivObj.contentHandle = temp;
	}else if(detector_browserUsed == "n4"){
		currentDivTag = eval("document." + divName);
		returnDivObj = new divtag_divObj(currentDivTag);
	}
	

	return returnDivObj;
}

function divtag_changeDivContent(divObj, newContent){
	divObj.content = newContent;
	divtag_updateContent(divObj);
}

function divtag_updateContent(divObj){
	if(detector_browserUsed == "n4"){
		divObj.divtag.document.open();
		divObj.divtag.document.writeln(divObj.content);
		divObj.divtag.document.close();
	}else{
		divObj.contentHandle.innerHTML = divObj.content;
	}
}


function divtag_moveDiv(divObj, xMov, yMov){
	/*move the object's location*/
	divObj.xPos += xMov;
	divObj.yPos += yMov;
	
	/*check this object's constraints*/
	divtag_checkConstraints(divObj)
	
	/*this moves the actual screen element to match the div tag's position*/
	divObj.divtag.left = Math.round(divObj.xPos);
	divObj.divtag.top = Math.round(divObj.yPos);
}

function divtag_addConstraint(divObj, side, value){
	if(side == divtag_TOP){
		divObj.minY = value;
		divObj.tConst = true;
	}else if(side == divtag_BOTTOM){
		divObj.maxY = value;
		divObj.bConst = true;
	}else if(side == divtag_RIGHT){
		divObj.maxX = value;
		divObj.rConst = true;
	}else if(side == divtag_LEFT){
		divObj.minX = value;
		divObj.lConst = true;
	}
}

function divtag_removeConstraint(divObj, side){
	if(side == divtag_TOP){
		divObj.tConst = false;
	}else if(side == divtag_BOTTOM){
		divObj.bConst = false;
	}else if(side == divtag_RIGHT){
		divObj.rConst = false;
	}else if(side == divtag_LEFT){
		divObj.lConst = false;
	}
}

function divtag_invertConstraint(divObj, side){
	if(side == divtag_TOP){
		divObj.tConstInv = !divObj.tConstInv;
	}else if(side == divtag_BOTTOM){
		divObj.bConstInv = !divObj.bConstInv;
	}else if(side == divtag_RIGHT){
		divObj.rConstInv = !divObj.rConstInv;
	}else if(side == divtag_LEFT){
		divObj.lConstInv = !divObj.lConstInv;
	}
}

function divtag_checkConstraints(divObj){
	/*if constraints have been applied to this object, this code is sure to honor them*/
	if(divObj.lConst && (divObj.xPos < divObj.minX) != divObj.lConstInv){
		divObj.xPos = divObj.minX;
	}else if(divObj.rConst && ((divObj.xPos + divObj.xWid) > divObj.maxX) != divObj.rConstInv){
		divObj.xPos = divObj.maxX - divObj.xWid;
	}
	if(divObj.tConst && (divObj.yPos < divObj.minY) != divObj.tConstInv){
		divObj.yPos = divObj.minY;
	}else if(divObj.bConst && ((divObj.yPos + divObj.yHei) > divObj.maxY) != divObj.bConstInv){
		divObj.yPos = divObj.maxY - divObj.yHei;
	}
	//debug_println(divObj.bConst + ":" + (divObj.yPos + divObj.yHei) + ":" + divObj.maxY + ":" + divObj.bConstInv);
}
