// JavaScript Document
addEvent(window, "load", function() {
								  		if( document.getElementById("wpLinkDiv") )
										{
											addEvent(document.getElementById("wpLinkDiv"), "mouseover", wpLinkDelay);
											addEvent(document.getElementById("wpLinkDiv"), "mouseout", clearWpLinkDelay);
										}
										//addEvent(document.getElementById("wpLink"), "mouseover", wpLinkMouseover);
										if( document.getElementById("savedWpQkMenu") )
										{
											addEvent(document.getElementById("savedWpQkMenu"), "mouseover", wpLinkMouseover);
											addEvent(document.getElementById("savedWpQkMenu"), "mouseout", wpLinkMouseout);
										}
									}
		);
var glDelay = 0, glDelay2 = 0;
	
function wpLinkDelay()
{
	glDelay = window.setTimeout( 'wpLinkMouseover()', 200);
}
function clearWpLinkDelay()
{
	window.clearTimeout( glDelay );
	wpLinkMouseout();
}
function wpLinkMouseover()
{
	var menuX = document.getElementById('savedWpQkMenu'),
		lnkTd = document.getElementById('wpLinktd'),
		x=0,y=0,t=0;
	
	lnkTd.style.backgroundColor ='#999999';
	t = resizeSavedWpQkMenu(document.getElementById('savedWpQkMenuTbl').firstChild);
	//alert('t= ' + t);
	menuX.setAttribute('className', menuX.getAttribute('show'));
	
	for( var i=document.getElementById('wpLinktd'); i != null; i = i.parentElement)
	{
		x += parseInt(i.offsetLeft);
		y +=  parseInt(i.offsetTop);
		//alert( i.offsetTop + ' ' + i.offsetLeft + ' ' + i.innerHTML);		
	}
	//alert(document.body.scrollTop);
	//alert( x + ' ' + parseInt(lnkTd.offsetHeight) + ' ' + y + ' ' + parseInt(lnkTd.offsetHeight));
	menuX.style.top = y-64;// + parseInt(lnkTd.offsetHeight);
	menuX.style.left = x-7;
}
function wpLinkMouseout()
{
	//alert(document.getElementById("wpLinktd").className);
	document.getElementById('wpLinktd').style.backgroundColor = '#cccc99';
	document.getElementById('savedWpQkMenu').setAttribute('className', document.getElementById('savedWpQkMenu').getAttribute('hide'));
}

function createsavedWpQkMenuLink( rptid )
{
	var output = delete_qs_var('&rpt_id=');
	if( output )
		document.location = '/cfs/outreach/survey/load_cust_report.cfm' + output + '&rpt_id=' + rptid;
	else
		document.location = '/cfs/outreach/survey/load_cust_report.cfm?' + 'rpt_id=' + rptid;
}

function delete_qs_var( str )
{
	var tmp = output = document.location.search;
	var index1 = tmp.indexOf(str);
	if( index1 != -1 )
	{
		var index2 = tmp.indexOf("&", index1+1); 
		if( index2 > index1 )
			{ tmp = tmp.substr( index1, index2-index1 );  }
		else
			{ tmp = tmp.substr(index1, tmp.length-index1); }
		output = output.replace(tmp,"");
	}
	return output;
}

function resizeSavedWpQkMenu()
{
	var div = document.getElementById('savedWpQkMenu'),
	tbl = document.getElementById('savedWpQkMenuTbl'), w=0;
	//quick and dirty way to do it
	for( var i=0; i <= tbl.firstChild.children.length; i++)
	{
		var c = null;
		
		if(c = tbl.firstChild.children[i])
			if( c = c.children[1] )
				if( c = c.firstChild )
				{
					c = c.innerText;
					if( parseInt(c.length) > w )
						w = parseInt(c.length);
				}
	}
	div.style.width = w*7;
	return w*7;
	//--- Recursive approach ------
	/*
	var elm = arguments[0], maxi=0;
					
	if( elm == null )
	{ 
		//alert('Hit a null returning 0'); 
		return maxi;
	}
	for( var i=0,tmp=0; i<=elm.children.length; i++)
	{ //alert('entered for loop i= ' + i );
		tmp = resizeSavedWpQkMenu( elm.children[i] );
		//alert( 'After func call i= ' + i + ' returning = ' + elm.innerText.length + ' maxi= ' + maxi + ' elm.innerText: ' + elm.innerText + '\n\n\n' + elm.innerHTML);
		if( elm.innerText && elm.tagName == 'A')
		{
			maxi = tmp > elm.innerText.length?maxi:elm.innerText.length;
			alert( elm.tagName + ' ' + elm.innerText.length );
		}
	}
	return maxi;
	*/
}