function showDiv(_ID)
{
	obj = document.getElementById(_ID);
	obj.style.display = 'block';
}
function hideDiv(_ID)
{
	obj = document.getElementById(_ID);
	obj.style.display = 'none';	
}
function showDivIfChecked(_CheckboxObj, _ShowDivID)
{
	if (_CheckboxObj.checked)
		showDiv(_ShowDivID);
	else
		hideDiv(_ShowDivID);
}
///////////////////////////////////////////
function confirmDelete(_Text, _YesRedirect)
{
	if (confirm(_Text))
		window.location = _YesRedirect;
}

///////////////////////////////////////////
function clearSearch(_Obj) 
{
	if (_Obj.value!='Search Products')
		return;

	_Obj.value='';	
	removeClassName(_Obj, 'blur');
	addClassName(_Obj, 'focus');
}
///////////////////////////////////////////
function resetSearch(_Obj) 
{
	if (_Obj.value!="") 
		return;

	_Obj.value='Search Products';	
	removeClassName(_Obj, 'focus');
	addClassName(_Obj, 'blur');
}

///////////////////////////////////////////
function addClassName(_Obj, _ClassName)
{
	// skip if classname already there
	if (in_array(_ClassName, _Obj.className.split(" ")))
		return; 

	_Obj.className += (_Obj.className ? " " : "") + _ClassName;
}

///////////////////////////////////////////
function removeClassName(_Obj, _RemoveClassName)
{
	// rebuild className without _ClassName
	var NewClassNames = '';
	
	var CurClassNames = _Obj.className.split(" ");
	
	for (i=0; i<CurClassNames.length; i++)
	{
		NewClassNames += (NewClassNames == "") ? "" : " ";
		
		if (CurClassNames[i] != _RemoveClassName)
			NewClassNames += CurClassNames[i];
	}
//Debug('removeClassName');	
	_Obj.className = NewClassNames;
}
///////////////////////////////////////////
function in_array(_item, _array)
{
	for (i = 0; i < _array.length; i++)
	{
		if(_array[i] == _item)
			return true;
	}
	
	return false;
}



function OpenWindow(url, width, height)
{
	var PopupWidth = width;
	var PopupHeight = height;
  var PopupLeft = (screen.width - PopupWidth) / 2;
  var PopupTop = (screen.height - PopupHeight) / 3;
		 
	newwindow=window.open(url,'name','top='+PopupTop+',left='+PopupLeft+',width='+PopupWidth+',height='+PopupHeight+',resizable=yes,scrollbars=no');
	if (window.focus) {newwindow.focus()}
}



function otherMouseOver(_Id)
{
	Obj = document.getElementById(_Id);
	addClassName(Obj, 'hover');
}
function otherMouseOut(_Id)
{
	Obj = document.getElementById(_Id);
	removeClassName(Obj, 'hover');
}



// Debugging functions
///////////////////////////////////////////
function EoDebug(_Msg)
{
        var Debug = document.getElementById('debug_console');
        if (Debug == undefined)
		{
        	AddDebugConsole();
	        Debug = document.getElementById('debug_console');
		}
		
        Time = new Date();
        //_Msg = Time.getMinutes()+Time.getSeconds()+": "+ _Msg;
        _Msg = ": "+ _Msg;

        Debug.innerHTML = _Msg+"<br />"+Debug.innerHTML;
}
///////////////////////////////////////////
function AddDebugConsole()
{
        // add debug div
        var DebugConsole = document.createElement('div');
        DebugConsole.id = "debug_console";
        DebugConsole.style.position = "absolute";
        DebugConsole.style.top = 0;
        DebugConsole.style.left = 0;
        DebugConsole.style.width = "500px";
        DebugConsole.style.height = "600px";

        // add debug window to top left of browser
        document.body.insertBefore(DebugConsole, document.body.firstChild);
}










/* slightly modified scriptiny.com dropdown menu */
var eoMenu={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

eoMenu.dropdown=function(){
	
	var p={fade:1,slide:1,active:0,timeout:200}, init=function(n,o){
		for(s in o){p[s]=o[s]} p.n=n; this.build()
	};
	
	init.prototype.build=function(){
		this.h=[]; this.c=[]; this.z=1000;
		var s=T$$('ul',T$(p.id)), l=s.length, i=0; p.speed=p.speed?p.speed*.1:.5;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(p.n+'.show('+i+',1)');
			h.onmouseout=new Function(p.n+'.show('+i+')')
		}
	};

	
	init.prototype.show=function(x,d){
		var c=this.c[x], h=this.h[x];
		clearInterval(c.t); clearInterval(c.i); c.style.overflow='hidden';
		if(d){
			
			// add hover state to link
			atag = h.firstChild.firstChild; // div wrapped around our anchor, hence second firstChild
			if(p.active&&atag.className.indexOf(p.active)==-1){atag.className+=' '+p.active;}

			if(p.fade||p.slide){
				c.style.display='block';
				if (c.className == 'submenu')
				{
					c.style.left = c.parentNode.offsetWidth+'px';
//alert('1setting it to :'+c.parentNode.offsetWidth);					
//alert('2 height:'+c.style.height);
				}
				if(!c.m){
					if(p.slide){ // to fix slide bug, adjust below c.m=?
						c.style.visibility='hidden'; c.m=c.offsetHeight; c.style.height='0'; c.style.visibility=''
					}else{
						c.m=100; c.style.opacity=0; c.style.filter='alpha(opacity=0)'
					}
					c.v=0
				}
				if(p.slide){
					if(c.m==c.v){
						c.style.overflow='visible'
					}else{
						c.style.zIndex=this.z; this.z++; c.i=setInterval(function(){slide(c,c.m,1)},20)
					}
				}else{
					c.style.zIndex=this.z; this.z++; c.i=setInterval(function(){slide(c,c.m,1)},20)
				}
			}else{
				c.style.zIndex=this.z; 
				c.style.display='block';
				if (c.className == 'submenu')
				{
					c.style.left = c.parentNode.offsetWidth+'px';
//alert('2setting it to :'+c.parentNode.offsetWidth);		
//alert('2 height:'+c.style.height);
				}
			}
		}else{
			c.t=setTimeout(function(){hide(c,p.fade||p.slide?1:0,h,p.active)},p.timeout)
		}
	};
	
	
	function hide(c,t,h,s){
		
		// remove hover state from link
// RIGHT HERE		
		if(s){
		//	h.className=h.className.replace(s,'')
			atag = h.firstChild.firstChild;
			atag.className=atag.className.replace(s,'');
		}
		
		if(t){c.i=setInterval(function(){slide(c,0,-1)},20)}else{c.style.display='none'}
	}
	
	
	function slide(c,t,d){ // c = element, t = target height, d = direction
		// bug here in that if padding in ul, it won't include that in height of what slides
		if(c.v==t){ // slide completed
			clearInterval(c.i); c.i=0;
			if(d==1){ // expanding
				if(p.fade){c.style.filter=''; c.style.opacity=1}
				c.style.overflow='visible';
			}
			else // contracting
			{
				c.style.display='none'; 
			}
			
		}else{ 
			c.v=(t-Math.floor(Math.abs(t-c.v)*p.speed)*d);
			if(p.slide){c.style.height=c.v+'px'}
			if(p.fade){var o=c.v/c.m; c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')'}
		}
	}
	
	return{init:init}
}();
