
/* 
Yahoo 
New Functions 

*/


var viewport = [
   YAHOO.util.Dom.getClientWidth(),
   YAHOO.util.Dom.getClientHeight()
];



var xmlHttp;
var dataDiv;
var dataTable;
var dataTableBody;
var dataExtra;
var dataExtra2;
var offsetEl;
var current_ID ="";
var timeout_ID = null;
var timeout_SECS = 5000;

var responseSuccess_TipView = function(o)
{
	
	//alert(YAHOO.util.Dom.getClientHeight());
	//transaction success case logic 
	//o.responseXML
	//o.responseText
	
	clearData();
	setOffsets();
	
	var header = o.responseXML.getElementsByTagName("header")[0].firstChild.data;
	var info ="";
	if(o.responseXML.getElementsByTagName("info").length != 0)
	{
		if(typeof(o.responseXML.getElementsByTagName("info")[0].firstChild) != 'undefined')
		{
			
			info = o.responseXML.getElementsByTagName("info")[0].firstChild.data;
			if(o.responseXML.getElementsByTagName("info")[0].childNodes.length >= 2)
			{
					 temp_info ="";
				    for(var i = 0; i < o.responseXML.getElementsByTagName("info")[0].childNodes.length; i++)
					{
							if(o.responseXML.getElementsByTagName("info")[0].childNodes[i].data == undefined)
							{
								//Special Characters
								if(o.responseXML.getElementsByTagName("info")[0].childNodes[i].childNodes != undefined)
								{
									if(o.responseXML.getElementsByTagName("info")[0].childNodes[i].childNodes[0] != undefined)
									{
										temp_info = temp_info + o.responseXML.getElementsByTagName("info")[0].childNodes[i].childNodes[0].data;
									}
									
								}
							}
							else
							{
								temp_info = temp_info + o.responseXML.getElementsByTagName("info")[0].childNodes[i].data;
							}
							//alert( + "x" + i);
							info = temp_info;
					}
					//
					//alert(o.responseXML.getElementsByTagName("info")[0].firstChild.data + o.responseXML.getElementsByTagName("info")[0].lastChild.childNodes[0].nodeValue);
					//alert(o.responseXML.getNamedItem("info").data);
					//o.responseXML.getElementsByTagName("info")[0].lastChild.data;
					
			}
			
		}
	}
	
	if(info != "")
	{
		var row, row2;
		var headerData = "" + header;
		var infoData = "" + info;
		row = createHeader(headerData);
		row2 = createInfo(infoData);
		dataTableBody.appendChild(row);
		dataTableBody.appendChild(row2);
		timeout_ID = setTimeout('clearData()',timeout_SECS);
	}
}



var responseFailure_TipView = function(o)
{
	//transaction failure case logic 
}

var callbackTipView =
{
	success:responseSuccess_TipView,
	failure:responseFailure_TipView
}

var current_ID ="";

function getToolTipData(element) {
	/*
	if(current_ID != element.id)
	{
		current_ID = element.id;
		actionData = "ARTICLEID_CHAR=" + escape(element.id);
		initVars();
		offsetEl = element;
		YAHOO.util.Connect.asyncRequest('POST','ax/js_tooltip.cfm',callbackTipView,actionData);
	}
	*/
}

function initVars() {
		dataTableBody = document.getElementById("tooltipDataBody");
		dataTable = document.getElementById("tooltipData");
		dataDiv = document.getElementById("popup");
		dataExtra = document.getElementById("tooltipExtra");
		dataExtra2 = document.getElementById("tooltipExtra2");
}


function removeAllChildNodes(node) {
    if (node && node.hasChildNodes && node.removeChild) {
        while (node.hasChildNodes()) {
            node.removeChild(node.firstChild);
        }
    }

} 


function createInfo(data) {
	
	var row, cell, txtNode;
	row = document.createElement("tr");
	cell = document.createElement("td");
	YAHOO.util.Dom.setStyle(cell, 'valign', "top");
	YAHOO.util.Dom.setStyle(cell, 'height', "110px");
	YAHOO.util.Dom.setStyle(cell, 'fontSize', "11px");
	YAHOO.util.Dom.setStyle(cell, 'padding', "0px");
	YAHOO.util.Dom.setStyle(cell, 'paddingTop', "10px");
	YAHOO.util.Dom.setStyle(cell, 'paddingLeft', "10px");
	YAHOO.util.Dom.setStyle(cell, 'backgroundColor', "#FFFFFF");
	YAHOO.util.Dom.setStyle(cell, 'border', "#888888 1px solid");
	YAHOO.util.Dom.setStyle(cell, 'borderLeft', "red 0px none");
	YAHOO.util.Dom.setStyle(cell, 'borderBottom', "red 0px none");
	YAHOO.util.Dom.setStyle(cell, 'borderRight', "red 0px none");
	YAHOO.util.Dom.setStyle(cell, 'color', "#000000");
	YAHOO.util.Dom.setStyle(cell, 'verticalAlign', "top");
	txtNode = document.createTextNode(data);
	cell.appendChild(txtNode);
	row.appendChild(cell);
	return row;
}


function createHeader(data,border) {
	
	var row, cell, txtNode;
	
	row = document.createElement("tr");
	cell = document.createElement("td");
	
	YAHOO.util.Dom.setStyle(cell, 'color', "#FFFFFF");
	YAHOO.util.Dom.setStyle(cell, 'width', "267px");
	YAHOO.util.Dom.setStyle(cell, 'height', "13px");
	YAHOO.util.Dom.setStyle(cell, 'fontSize', "11px");
	YAHOO.util.Dom.setStyle(cell, 'padding', "5px");
	YAHOO.util.Dom.setStyle(cell, 'paddingBottom', "0px");
	YAHOO.util.Dom.setStyle(cell, 'paddingLeft ', "10px");
	YAHOO.util.Dom.setStyle(cell, 'backgroundColor', "#888888");
	
	txtNode = document.createTextNode(data);
	cell.appendChild(txtNode);
	row.appendChild(cell);
	return row;
}


function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}


function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}


function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function setOffsets() {
	 var y = YAHOO.util.Dom.getY(offsetEl.id);
	 var x = YAHOO.util.Dom.getX(offsetEl.id);
	 var end = offsetEl.offsetWidth + 25;
	 var top = y - offsetEl.offsetHeight;
	
	 //var units = Math.round(document.height/YAHOO.util.Dom.getClientHeight());
	 //var units_size = YAHOO.util.Dom.getClientHeight();
	 //var document_percentage = (top/document.height); 
	 
	 var padd_bottom = 152;
	 var t=f_scrollTop();
	 var r=YAHOO.util.Dom.getClientWidth();	 
	 var b= t + YAHOO.util.Dom.getClientHeight() - padd_bottom;
	 var l=0;
	 
	 var targetRegion = new YAHOO.util.Region(t, r, b, l);
	 var cursorPoint = new YAHOO.util.Point(end,top);
	 var inRegion = targetRegion.contains(cursorPoint);
	 
	 var dataExtra_src_down = "arrow_temp.gif";
	 var dataExtra_src_up = "arrow_temp_alt.gif";
	 var dataExtra_src_current = "arrow_temp.gif"; 
	  
	 if(dataExtra.src != null)
	 {
		temp_split = dataExtra.src.split("images/");
		if(temp_split.length != 0)
		{
			dataExtra_src_current = temp_split[1];
		}
	 }
	 
	 if(inRegion)
	 {
		// Flip Down 
		dataExtra.src="images/" + dataExtra_src_down;
	 }
	 else
	 {
		 //Flip Up
		 dataExtra.src="images/" +  dataExtra_src_up;
		 top = top - 110;
	 }
	 
	
	YAHOO.util.Dom.setY(dataDiv.id, top);
	YAHOO.util.Dom.setX(dataDiv.id, end);
	YAHOO.util.Dom.setStyle(dataExtra, 'display',"block");
	YAHOO.util.Dom.setStyle(dataExtra2, 'display',"block");
	YAHOO.util.Dom.setStyle(dataTable, 'height', "152px");
	YAHOO.util.Dom.setStyle(dataTable, 'border', "#888888 1px solid");
	YAHOO.util.Dom.setStyle(dataTable, 'borderLeft',"#888888 0px solid");
	YAHOO.util.Dom.setStyle(dataTable, 'borderRight', "#888888 1px solid");
	YAHOO.util.Dom.setStyle(dataTable, 'fontFamily', "Arial, Helvetica, sans-serif");
}

function calculateOffsetTop(field) {
	return calculateOffset(field, "offsetTop");
}

function calculateOffset(field, attr) {
	var offset = 0;
	while(field) {
	offset += field[attr];
	field = field.offsetParent;
	}
	return offset;
}

function clearData(element,e) {
	
	removeAllChildNodes(dataTableBody);
	YAHOO.util.Dom.setStyle(dataDiv, "none");
	
	//YAHOO.util.Dom.setStyle(dataExtra, 'fontFamily', "Arial, Helvetica, sans-serif");
	//YAHOO.util.Dom.setStyle(dataExtra2, 'fontFamily', "Arial, Helvetica, sans-serif");
	
	YAHOO.util.Dom.setStyle(dataTable, 'border', "none");
	YAHOO.util.Dom.setStyle(dataDiv, 'left', "-200px");
	YAHOO.util.Dom.setStyle(dataDiv, 'top', "-200px");
	current_ID ="";
	if(timeout_ID != null)
	{
		clearTimeout(timeout_ID);
	}
	
}