
/**
 @fileoverview
 This javascript dispalys the preview link of merchant item in a pop-up window.
 Tom Negrino & Dori Smith : Previewing Links with Ajax : http://www.javascriptworld.com/chap15-4.html  
 */ 		
 		 		
window.onload = initAll;
var xhr = false;
var xPos, yPos;
var url = "";

function initAll() {
	//var allLinks = document.getElementsByTagName("a");
	var allLinks = document.getElementsByName("preview");
			
	for ( var i=0; i < allLinks.length; i++ ) {
		allLinks[i].onmouseover = showPreview;
	}
}

function showPreview(evt) {
	if (evt) { 
		//var url = evt.target;		
	}
	else {
		evt = window.event;
	}
	
	xPos = evt.clientX;
	yPos = evt.clientY;
	
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	}
	else {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");	
			}
			catch (e) { }
		}
	}
	
	if (xhr) {
		xhr.onreadystatechange = showContents;
		xhr.open("GET", url, true);
		xhr.send(null);
		
		url = "";
	} 
	else {
		alert("There was a problem creating an XMLHttpRequest");
	}
	
	return false;
}

function hidePreview() {
	document.getElementById("previewWin").style.visibility = "hidden";
}


function showContents() {
	var prevWin = document.getElementById("previewWin");
	
	if ( xhr.readyState == 4 ) {
		prevWin.innerHTML = (xhr.status == 200) ? xhr.responseText : "There was a problem with the request " + xhr.status;
		prevWin.style.top = parseInt(yPos) + 2 + "px";
		prevWin.style.left = parseInt(xPos) + 2 + "px";
		prevWin.style.visibility = "visible";
		prevWin.onmouseout = hidePreview;
	}
}	

function setURLPath(idnum) {
	url = "preview.htm?id=" + idnum;	
}			
