
var ThisRegionOkay = 0;
var ThisRegionURL = "";

function GetTip(region) {
	OpenAJAXRequest('/magic/champsmap2007service.asp?region=' + region, Tooltip)
}

function Tooltip () { 
	if (AJAXRequestComplete()) {
		var xmldoc = GetAJAXRequestXML();

		
		var sTip = "";
		var sHref = "#";
		var sRegion = xmldoc.getElementsByTagName("region").item(0).firstChild.nodeValue;
		sTip += "<b><font size='+1'>" + sRegion + "</font></b><br/>";
		
		//alert(xmldoc.getElementsByTagName("name1").item(0).firstChild);
		
		if (!xmldoc.getElementsByTagName("name1").item(0).hasChildNodes()) {
			sTip += "<p><i>No information for this region yet!</i></p>";
			ThisRegionOkay = 0;
			
		} else {

			ThisRegionOkay = 1;
			var sName1 = xmldoc.getElementsByTagName("name1").item(0).firstChild.nodeValue;
			var sName2 = xmldoc.getElementsByTagName("name2").item(0).firstChild.nodeValue;
			
			var sPhoto = "";
			
			if (!xmldoc.getElementsByTagName("imageurl").item(0).hasChildNodes()) {
				sPhoto = "";
			} else {
				sPhoto = xmldoc.getElementsByTagName("imageurl").item(0).firstChild.nodeValue;
			}
			sTip += "<b>Winners:</b> " + sName1 + " &amp; " + sName2 + "<br/><br/><img src=\"" + sPhoto + "\" alt=\"\" border=\"0\"/>";
			sTip += "<br/><br/><i>Click on this state or province to see Top 4 decklists</i>";

			if (!xmldoc.getElementsByTagName("deckurl").item(0).hasChildNodes()) {
				sHref = "";
			} else {
				sHref = xmldoc.getElementsByTagName("deckurl").item(0).firstChild.nodeValue;
			}
			ThisRegionURL = sHref;
		}
		
	    if(!document.getElementById('tooltip')) newelement('tooltip');
   		var lixlpixel_tooltip = document.getElementById('tooltip');
    	lixlpixel_tooltip.innerHTML = sTip;
    	lixlpixel_tooltip.style.display = 'block';
    	document.onmousemove = getmouseposition;
	
//		document.getElementById('region_' + sRegion).href = sHref;
	
		// document.getElementById('myrulestext').innerHTML = tip;
	
	}
}



// position of the tooltip relative to the mouse in pixel //
var offsetx = -300;
var offsety = 8;

function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
function getmouseposition(e)
{
    if(document.getElementById)
    {
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;
        var lixlpixel_tooltip = document.getElementById('tooltip');
		
		if (mousex > 450) {
			offsetx = -300;
		} else {
			offsetx = 20;
		}
		
        lixlpixel_tooltip.style.left = (mousex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+offsety) + 'px';
    }
}

function exit()
{
    document.getElementById('tooltip').style.display = 'none';
	ThisRegionOkay = 0;
}

function launchdeck(sRegion)
{
    if (ThisRegionOkay) {
		window.open(ThisRegionURL, "", 'scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,status=yes,location=yes');
	}
}

