/**
 * Copyright © 2003 - 2006  Internet Shopping Enterprises, Inc. All Rights Reserved
 */

var uqtx = (new Date()).getTime();

function asimlOver(s){s.style.textDecoration = "none";}

function asimlOut(s){s.style.textDecoration = "underline";}

function msie_ISE_QuickView(s){
	var qvd = s.parentElement.parentElement.getElementsByTagName("DIV")[0];
	if ("none" == qvd.style.display) {
		qvd.firstChild.src = s.IseQvSrc;
		qvd.style.display = "inline";
		s.innerText = "Close Quick Look";
		s.parentElement.nextSibling.style.visibility = "visible";
	}
	else {
		qvd.style.display = "none";
		qvd.firstChild.src = "";
		s.innerText = "Quick Look";
		s.parentElement.nextSibling.style.visibility = "hidden";
	}
}

function ISE_QuickView(s){
	var qvd = s.parentNode.parentNode.getElementsByTagName("DIV")[0];
	if ("none" == qvd.style.display) {
		var ifsrc = getAttValue(s, "IseQvSrc");
		qvd.firstChild.src = ifsrc;
		qvd.style.display = "inline";
		s.innerHTML = "Close Quick Look";
		s.parentNode.nextSibling.style.visibility = "visible";
	}
	else {
		qvd.style.display = "none";
		qvd.firstChild.src = "";
		s.innerHTML = "Quick Look";
		s.parentNode.nextSibling.style.visibility = "hidden";
	}
}

function ISE_MaxView(s){
	var qvd = s.parentNode.nextSibling;
	if (250 == qvd.firstChild.height) {
		qvd.firstChild.height = 550;
		s.innerHTML = "Minimize";
	}
	else {
		qvd.firstChild.height = 250;
		s.innerHTML = "Maximize";
	}
}

function setBodyVis(b) {
	if (b) {
		document.body.topMargin="15";
		document.body.leftMargin="15";
		document.body.style.overflowY = "visible";
		document.body.scroll = "yes";
		document.getElementById("tblBody").style.display = "inline";
	}
	else {
		document.body.scroll = "no";
		document.body.topMargin="0";
		document.body.leftMargin="0";
		document.body.style.overflowY = "hidden";
		document.getElementById("tblBody").style.display = "none";
	}
}

function view(turl, durl) {

	// http?
	if ("http://" != turl.substr(0, 7)) {
		turl = "http://"+turl;
	}

	// re-encode?
	if ("http://redirect.alexa.com/redirect?" == turl.substr(0, 35)) {

		// encodeURIComponent
		// encodeURI

		// alert("@debug::[iseqv.008].view():re-encode....");

		turl = turl.substr(35);
		turl = "http://redirect.alexa.com/redirect?" + encodeURIComponent(turl);
	}
	// alert("@debug::[iseqv.008].view():\n\tturl:["+turl+"]");

	setBodyVis(false);

	var viewTbl = document.getElementById("res_view");
	viewTbl.resTargetUrl = turl;
	viewTbl.rows[0].cells[0].innerHTML = "<span>"+"http://"+durl+"</span>";
	viewTbl.style.display = "inline";

	winHeight = document.documentElement.clientHeight;
	winHeight = winHeight - 24;

	var pvwFme = document.getElementById("res_iframe");
	pvwFme.src = turl;
	pvwFme.style.height = winHeight+"px";
}

function res_viewClose_onclick() {
	document.getElementById("res_iframe").src = "about:blank";
	document.getElementById("res_view").style.display="none";

	setBodyVis(true);
}

function res_viewMaximize_onclick() {
	var viewTbl = document.getElementById("res_view");
	var turl = viewTbl.resTargetUrl;
	window.location=turl;
}

function aThumb(ti) {
	var host = getRsltHost(ti);
	if (7 < host.length && "http://" == host.substr(0, 7)) {
		host = host.substr(7);
	}
	var sdx = host.indexOf("/");
	if (0 < sdx) {
		host = host.substr(0, sdx);
	}
	host = encodeURIComponent(host);

	var domid = getDomId(ti);
	domid = domid.substr(21);
	domid = encodeURIComponent(domid);

	var shref = "/search/amg?query="+host+"&domid="+domid+"&ts=" + uqtx;
	var rs=document.createElement("script");
	rs.id = "rs"+uqtx;
	rs.defer = true;
	rs.setAttribute("type", "text/javascript");
	rs.setAttribute("src", shref);
	document.getElementsByTagName("head")[0].appendChild(rs);
}

function loadThumbs() {
	var imgs = document.getElementsByTagName("img");
	for (var i=0,l=imgs.length;i<l;i++) {
		var tmburl = getThumbUrl(imgs[i]);
		if (null != tmburl) {
			imgs[i].src = tmburl;
		}
	}
}

function hideThumb(ti) {

	// alert("@debug:[iseqv.009.js]::hideThumb("+ti+")");

	var ts = getThumbState(ti);

	// alert("@debug:[iseqv.009.js]::hideThumb("+ti+"): ts["+ts+"]");

	if (null == ts || "undefined" == typeof(ts))
		return;

	ts = ts-0;

	// alert("@debug:[iseqv.009.js]::hideThumb("+ti+"): ts<INT>["+ts+"]");

	switch(ts) {
		case 0:
			aThumb(ti);
			break;
		case 1:
			ti.src = "/images/alexa.comingsoon.gif";
			break;
		default:
			ti.src = "/images/alexa.comingsoon.gif";
			break;
	}
	ti.isthumb = ++ts;
}

function getThumbUrl(n) {
	if (null == n)
		return null;

	if (n.thumburl)
		return n.thumburl;

	var atts = n.attributes;
	if (null == atts || 0 == atts.length)
		return null;

	var u = atts.getNamedItem("thumburl");
	if (null == u || "undefined" == typeof(u))
		return null;

	if (null == u.value || 0 == u.value.length)
		return null;
	else
		return u.value;
}

function getThumbState(n) {
	if (null == n)
		return null;

	if (n.isthumb)
		return n.isthumb;
	else
		return getAttValue(n, "isthumb");
}

function getAlt(n) {
	if (null == n)
		return null;

	if (n.alt)
		return n.alt;
	else
		return getAttValue(n, "alt");
}

function getRsltHost(n) {
	if (null == n)
		return null;

	if (n.rslthost)
		return n.rslthost;
	else
		return getAttValue(n, "rslthost");
}

function getDomId(n) {
	if (null == n)
		return null;

	if (n.id)
		return n.id;
	else
		return getAttValue(n, "id");
}

function getAttValue(node, attName) {
	var atts = node.attributes;
	if (null == atts || 0 == atts.length)
		return null;

	var u = atts.getNamedItem(attName);
	if (null == u || "undefined" == typeof(u))
		return null;

	if (null == u.value || 0 == u.value.length)
		return null;
	else
		return u.value;
}

/*
Node
	.attributes
NamedNodeMap
	.length
	.item(idx)
*/
function alertNode(n) {
	var nstr=n.nodeName+" ATTRIBUTES:";
	var atts = n.attributes;

	if (null == n || null == atts || 0 == atts.length) {
		alert("!ATTS");
		return;
	}

	for (var i=0,l=atts.length;l>i;i++) {
		nstr += "\n\t["+atts.item(i).name+"]\t\t\t= ["+atts.item(i).value+"]";
	}
	alert(nstr);
}
