
/* *******************************************
*	Copyright © 2002-2008 ExpoCharger International, Inc. All rights reserved
* ****************************************** */


//no dependencies

var ECI = {

	getElement: function(itemId){
		var item;
		if(document.getElementById)
			return document.getElementById(itemId);
		else if(document.all)
			return document.all[itemId];
			
		return null;
	},
	
	getOffsetLeft: function(elem){
		var n = elem.offsetLeft;
		while(elem.offsetParent){
			n += elem.offsetParent.offsetLeft;
			elem = elem.offsetParent;
		}
		return n;
	},
	getOffsetTop: function(elem){
		var n = elem.offsetTop;
		while(elem.offsetParent){
			n += elem.offsetParent.offsetTop;
			elem = elem.offsetParent;
		}
		return n;
	},
	
	ECgetFirstChild: function(elem){
		if(!elem.childNodes)
			return null;
		var count = elem.childNodes.length;
		for(var i=0;i<count;++i){
			if(elem.childNodes[i].nodeType==1){
				return elem.childNodes[i];
			}
		}
		return null;
	},
	
	ECgetNextSibling: function(elem){
		do{
			elem = elem.nextSibling;
		} while (elem && elem.nodeType != 1);
		return elem;
	},
	
	ECgetVdir: function(absolutePath){
		var pos = window.location.pathname.toLowerCase().indexOf("/forms/");
		pos = pos - 2;
		var relPath = window.location.pathname.substring(0,pos);
		if(absolutePath==true){
			return window.location.protocol + "//" + window.location.host + relPath;
		}
		else {
			return relPath;
		}
		
	},
	
	
	ECmoveSpecial: function(moveItem,targetLeft,targetTop,animate,callback,callbackParm){
		var animateCount = (navigator.appName=="Microsoft Internet Explorer")?5:5;// 5 is good for ff, 10 good for ie7
		var animateMs = (animateCount==10)?1:1;
		if(!moveItem.style.left){
			moveItem.style.left = ECI.getOffsetLeft(moveItem) + "px";
			moveItem.style.top = ECI.getOffsetTop(moveItem) + "px";
		}
		if(animate != true){
			moveItem.style.left = targetLeft + "px";
			moveItem.style.top = targetTop + "px";			
			if(callback) callback(callbackParm);
			return;
		}
		try{
			var iterations = 0;
			var intId = setInterval(function(){
					++iterations;
					var curLeft = parseInt(moveItem.style.left);
					var curTop = parseInt(moveItem.style.top);
					var distance = Math.sqrt( Math.pow(targetLeft - curLeft,2) + Math.pow(targetTop - curTop,2) );
					if( (iterations > animateCount*2) || (distance <= 20) ) {
						clearInterval(intId);
						moveItem.style.left = targetLeft + "px";
						moveItem.style.top = targetTop + "px";
						if(callback) callback(callbackParm);
					} 
					else {						
						var stepsRemaining=(animateCount==iterations)?2:animateCount-iterations;//avoid division by 0
						moveItem.style.left = curLeft + (targetLeft - curLeft)/(stepsRemaining) + "px";
						moveItem.style.top = curTop + (targetTop - curTop)/(stepsRemaining) + "px";
					}								
				},animateMs);
		} 
		catch (e){
			moveItem.style.left = targetLeft + "px";
			moveItem.style.top = targetTop + "px";
			if(callback) callback(callbackParm);
			return;
		}
	},
	

	setItemEnabled: function(item,enabled){
		if(!item)
			return;
		item.disabled = !enabled;
		/*
		if(item.type=="checkbox" || item.type=="radio"){
			var aspnetSpan=item.parentNode;
			if(aspnetSpan){
				aspnetSpan.disabled = !enabled;
			}	
		}
		*/
	},

	setItemVisible: function(item,visible,displayMode){
		if(!item)
			return;
		if(!item.style)
			return;
		var itemStyle = item.style;
		if(visible==true){
			if(typeof displayMode != "undefined")
				itemStyle.display=displayMode;
			else
				itemStyle.display='block';
		}
		else {
			itemStyle.display='none';
		}
		/* vstudio2003 before servicepack would wrap span around checkboxes, after sp it uses <label for=chkId...
		if(item.type=="checkbox" || item.type=="radio"){
			var aspnetSpan=item.parentNode;
			if(aspnetSpan){
				aspnetSpan.style.display = itemStyle.display;
			}
		}	
		*/
	},

	isItemVisible: function(item){
		if(!item)
			return false;
		if(!item.style)
			return false;
		return (item.style.display=='block')?true:false;
	},	
	
	removeArrayElement: function(arr,arrElement){
		for(var i=0;i<arr.length;i++){
			if(arr[i]==arrElement){
				if(arr.splice){
					arr.splice(i,1);
					return arr;
				} else {
					var a2=new Array();
					for(var i2=0;i2<arr.length;i2++){
						if(i2 != i)
							a2.push(arr[i2]);
					}
					return a2;
				}
			}
		}
	},
	
	dumpObj: function(obj){
		if(!obj)
			return "";
		var s="";
		for(var p in obj){
			s=s+p+"="+obj[p]+"\n";
		}
		return s;
	}

}; //ECI.

