
function launchPopUp(linkObject) {
	// This closes a pop-up window by the same name if it is already open.
	var winName = linkObject.href;
	if (linkObject.name) {
		winName = linkObject.name;
		if (eval("window." + winName) != null) {
			eval("window." + winName + ".close()");
		}
	}
	
	var h = 400;
	if (linkObject.getAttribute("h")) {h = linkObject.getAttribute("h")}
	
	var w = 400;
	if (linkObject.getAttribute("w")) {w = linkObject.getAttribute("w")}
	
	var r = "yes";
	if (linkObject.getAttribute("r")) {r = linkObject.getAttribute("r")}
	
	var s = "yes";
	if (linkObject.getAttribute("s")) {s = linkObject.getAttribute("s")}
	
	var newWin = window.open(linkObject.href,"","width=" + w + ",height=" + h + ",resizable=" + r + ",scrollbars=" + s);

	newWin.focus();
	
	return newWin;

}

function openFeatureImage(image,title,caption,price,retail) {
	var newWin = "newWin";
	if(title) {var newWin = title.replace(/\s/g, "");
			   var winTitle = title;}
	
	var winCap = "";
	if(caption) {var winCap = caption;}
	
	var code = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'><html><head><title>" + winTitle + "</title><script language='JavaScript' src='js/interiors.js'></script><link rel='stylesheet' media='all' type='text/css' href='css/interiors.css' /></head><body onLoad='popResize(); window.focus();' class='popup'><img src='" + image + "' id='popimage'><p><span class='sale'>" + price + "</span> " + retail + "</p><p id='caption'><strong>" + title + "</strong> " + winCap + "</p></div></body></html>"
	
	var featureWindow = window.open("","popWin","width=200,height=200,resizable=yes,scrollbars=yes");

	featureWindow.document.open();
	featureWindow.document.write(code);
	featureWindow.document.close();
}

function popResize() {
	var hpad = 220;
	var wpad = 52;
	var featureImg = document.getElementById("popimage");
	var height = featureImg.height + hpad;
	var width = featureImg.width + wpad;
	if (height > 700) {height=700;}
	if (width >700) {width=700;}
	window.resizeTo(width, height);
}

function launchPop(el) {
	var image = el.href;
	var title = "";
	var caption = "";
	var price = "";
	var retail = "";
	if (getElementsByClass("title",el.parentNode).length > 0) {
		title = getElementsByClass("title",el.parentNode)[0].innerHTML;
	}
	if (getElementsByClass("desc",el.parentNode).length > 0) {
		caption = getElementsByClass("desc",el.parentNode)[0].innerHTML;
	}
	if (getElementsByClass("sale",el.parentNode).length > 0) {
		price = getElementsByClass("sale",el.parentNode)[0].innerHTML;
	}
	if (getElementsByClass("retail",el.parentNode).length > 0) {
		retail = getElementsByClass("retail",el.parentNode)[0].innerHTML;
	}
	openFeatureImage(image,title,caption,price,retail);
}

function intializePop() {
	var tbls = getElementsByClass("products");
	for (var y=0; y<tbls.length; y++) {
		var els = tbls[y].getElementsByTagName("img");
		for (var i=0; i<els.length; i++) {
			if(els[i].parentNode.tagName == "A") {
				els[i].parentNode.onclick=function() {launchPop(this); return false;};
			}
		}
	}
}

function getElementsByClass(cname,tel) {
	var elementsByClass = new Array();	
	if(tel) {
		var target = tel;
	}
	else {
		var target = document;
	}
	
	if(target.className == cname) {
		elementsByClass[0] = target;
	}
	var children = target.childNodes;
	for(var i=0;i<children.length;i++) {
		elementsByClass = elementsByClass.concat(getElementsByClass(cname,children[i]));
	}
	return elementsByClass;
}

function checker(e) {
	var x = e.split(",");
	var pass = true;
	checkerInvalid = new Array;
	for(i=0; i<x.length; i++) {
		if(!eval(x[i])) {
			pass = false; 
			checkerInvalid[checkerInvalid.length] = x[i];
		}
	}
	return pass;
}
