var mnu = ""
var mnu_t;
var mnu_h;
var donothing;
var viewingmenu = false;

var news = new Array();
var newsindex = 0;
news[0] = '<a href="/q/webedi">Mac users: WebEDI runs great on Mac Safari.<br><br>Click here to find out more...</a>';
news[1] = '<a href="/q/webedi">DataTrans WebEDI is the affordable solution for small-to-midsized companies!<BR><BR>Click here to learn more</a>';
news[2] = '<a href="/q/news#webedi30">Introducing WEBEDI 3.0<br>The most intuitive web-based EDI solution just got a whole lot better!</a>';
news[3] = '<a href="/q/bridges">ERP Application Bridges help smooth the transition to ERP systems<BR><BR>Learn more about this exciting software enhancement!</a>';
news[4] = '<a href="/q/news#hybrid">Integrated EDI plus the convenience of a web-based interface.<br><br> Find out how a hybrid solution can benefit your company</a>';
news[5] = '<a href="/q/hipaa">DataTrans: Your HIPAA certified EDI solution provider!</a>';
news[6] = '<a href="/q/news#catalog">WebEDI Catalog and Auto Pack<br><br>Sending an ASN just got easier!</a>';
news[7] = '<a href="/q/webedi">Enhancements to WebEDI system now available! Find out more... </a>';
news[8] = '<a href="/q/software">Powerful, intuitive and affordable EDI software from DataTrans. Click here to find out more...</a>';
news[9] = '<a href="/q/large_corporation_solutions">DataTrans e-Community program provides a simple solution to enable companies to become EDI capable - regardless of size. More...</a>';
news[10] = '<a href="/q/news#energy">Solutions for the Energy Sector <br><br>Support for NAESB/GISB Communications Protocal</a>';
		
function hideMenu(){
	if(donothing) return;
	viewingmenu = false;
	var obj = document.getElementById(mnu);
	if(obj != null){
		obj.style.visibility = 'hidden';
		//obj.style.height = mnu_h - 2;
		obj.style.display = 'none';
	}
}

function _vm(){
	donothing = true;
	clearTimeout(mnu_t);
}

function _hm(){
	donothing = false;
	mnu_t = setTimeout("hideMenu()",300);
}

function viewMenu(caller, mnuid, direction){
	var obj = document.getElementById(mnuid);
	if(obj != null){
		//if(mnu == mnuid && viewingmenu) return;
		donothing = false;
		hideMenu();
		donothing = true;
		viewingmenu = true;
		mnu = mnuid;
		x = findPosX(caller);
		y = findPosY(caller);
		obj.style.display = 'block';
		mnu_h = obj.offsetHeight;
		obj.style.left = x;
		if(direction == null)
			obj.style.top = y + caller.offsetHeight + 2;
		else{
			obj.style.top = y - obj.offsetHeight - 2;
		}
		//slideMenu(mnuid,0,obj.offsetHeight);
		obj.style.visibility = 'visible';
		obj.onmouseout = _hm;
		obj.onmouseover = _vm;
		caller.onmouseout = _hm;
	}
}

function slideMenu(objId,cur,max){
	var obj = document.getElementById(objId);
	if(obj != null){
		obj.style.visibility = 'visible';
		if(cur < max){
			cur += 10;
			if(cur > max) cur = max;
			obj.style.height = cur;
			setTimeout("slideMenu('"+objId+"',"+cur+","+max+")");
		}
	}
}

function itemSelect(obj){
	if(obj.style.backgroundColor == '' || obj.style.backgroundColor == "transparent")
		obj.style.backgroundColor = "#da9090";
	else
		obj.style.backgroundColor = "transparent";
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;

	return curtop;
}

function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent){
		while(obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
		
	return curleft;
}

function initNews() {
	newsId = 'news';
	var n = document.getElementById(newsId);
	setOpacity(n, 0);
	n.innerHTML = news[newsindex];
	n.style.visibility = 'visible';
	newsFadeIn(newsId,0);
	setInterval("newsFadeOut('"+newsId+"',100);",7000);
}

function newsFadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 10;
			setTimeout("newsFadeIn('"+objId+"',"+opacity+")", 100);
		}
	}	
}

function newsFadeOut(objId,opacity){
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity >= 0) {
			setOpacity(obj, opacity);
			opacity -= 10;
			setTimeout("newsFadeOut('"+objId+"',"+opacity+")", 100);
		}
		else{
			newsindex++;
			if(newsindex >= news.length)
				newsindex = 0;
			obj.innerHTML = news[newsindex];
			newsFadeIn(objId,0);
		}
	}	
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;

	// IE/Win
	obj.style.filter = "Alpha(opacity="+opacity+")";
	
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;

	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;

	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
	
}

function expandLogin(elem){
	var obj=document.getElementById("logintab");
	if(obj != null){
		var top = findPosY(elem);
		var left = findPosX(elem);
		var width = elem.offsetWidth;
		var offset = (width - parseInt(obj.style.width));
		obj.style.top = top+1;
		obj.style.left = left + offset;
		obj.style.display = "inline";
		obj.style.visibility = "visible";
		document.frmlogin.username.focus();
	}
}

function loginHide(){
	var obj=document.getElementById("logintab");
	if(obj!=null){
		obj.style.display = "none";
		obj.style.visibility = "hidden";
	}
}

function checkLogin(){
	if(document.frmlogin.username.value=="" || document.frmlogin.password.value==""){
		alert("Please include a username and password.");
		return false;
	}
	else
		return true;
}

function browser(){
	
	var userAg = navigator.userAgent.toLowerCase();
	
	this.userAgent = userAg;
	this.isIE = (userAg.indexOf("msie") > -1);
	this.isSafari = (userAg.indexOf("safari") > -1);
	this.isFirefox = (userAg.indexOf("firefox") > -1);
	this.isOpera = (userAg.indexOf("opera") > -1);
	
	this.isWin = (userAg.indexOf("win") > -1);
	this.isMac = (userAg.indexOf("mac") > -1);
	this.isLinux = (userAg.indexOf("linux") > -1);
	this.isUnix = (userAg.indexOf("unix") > -1);
	
	this.version = -1;
	if(this.isIE)
		this.version = parseFloat(userAg.substring(userAg.indexOf("msie ") + 5));
	else if(this.isFirefox)
		this.version = parseFloat(userAg.substring(userAg.indexOf("firefox/") + 8));
	else if(this.isSafari)
		this.version = parseFloat(userAg.substring(userAg.indexOf("safari/") + 7));
	else if(this.isOpera)
		this.version = parseFloat(userAg.substring(userAg.indexOf("opera") + 5));

	
	this.getWindowHeight = function(){
		if(window.innerHeight)
			r = window.innerHeight;
		else if(document.body.clientHeight)
			r = document.body.clientHeight;
		else if(document.documentElement.clientHeight)
			r = document.documentElement.clientHeight;
		
		return r;
	}

	this.getWindowWidth = function(){
		if(window.innerWidth)
			r = window.innerWidth;
		else if(document.body.clientWidth)
			r = document.body.clientWidth;
		else if(document.documentElement.clientWidth)
			r = document.documentElement.clientWidth;
		
		return r;
	}
}
var browser = new browser();

var tip_n = "";
var tip_t = null;
var tip_donothing=false;

function _ht(){
	tip_donothing = false;
	tip_t = setTimeout("_hide()",300);
}

function _show(e,el,xpad,ypad){
	var obj = document.getElementById(e);
	if(obj != null){
		if(!xpad) xpad = 0;
		if(!ypad) ypad = 0;
		tip_donothing = false
		_hide();
		tip_donothing = true;
		obj.style.display='block';
		if(el){
			var x = findPosX(el);
			var y = findPosY(el);
			w = browser.getWindowWidth();
			if(x + 340 > w) x -= ((x+380) - w);
			
			obj.style.left = x + xpad;
			obj.style.top = y + 15 + ypad;
		}
		
		tip_n = e;
		obj.style.visibility = 'visible';
		el.onmouseout = _ht;
		document.onclick = function(){tip_donothing=false;_hide();};
	}
	
}
function _hide(){
	if(tip_donothing) return;
	var obj = document.getElementById(tip_n);
	if(obj != null){
		obj.style.visibility = 'hidden';
		obj.style.display='none';
		document.onclick = null;
	}
}
