 
var hwndPopup;

/**********************************************************************
* function:		openpopup()
* description:	opens a new browser window
* variables:	url		- target URL
* 					popupW	- popup window width
* 					popupH	- popup window height
* 					posX		- window left screen position
* 					posY		- window top screen position
**********************************************************************/
function openpopup(url, popupW, popupH, posX, posY){
	if (popupW === undefined) popupW = 1010;
	if (popupH === undefined) popupH = 754;
	if (posX === undefined) posX = 300;
	if (posU === undefined) posU = 300;
	
	var isFullScreen = false;
	var isAutoCenter = false;
	var popupTarget = "popupwin";
	var popupParams = "toolbar=1, scrollbars=1, menubar=1, status=1, resizable=1";
 
	if (isFullScreen) {
		popupParams += ", fullscreen=1";
	} else if (isAutoCenter) {
		posU	= parseInt((window.screen.height - popupH)/2);
		posX	= parseInt((window.screen.width - popupW)/2);
	}

	var ua = window.navigator.userAgent;
	var isMac = (ua.indexOf("Mac") > -1);
	 
	//IE 5.1 PR on OSX 10.0.x does not support relative URLs in pop-ups the way they're handled below w/ document.writeln
	if (isMac && url.indexOf("http") != 0) {
	  url = location.href.substring(0,location.href.lastIndexOf('\/')) + "/" + url;
	}
 
	var isOpera = (ua.indexOf("Opera") > -1);
	var operaVersion;
	if (isOpera) {
		var i = ua.indexOf("Opera");
		operaVersion = parseFloat(ua.substring(i + 6, ua.indexOf(" ", i + 8)));
		if (operaVersion > 7.00) {
			var isAccessible = false;
			eval("try { isAccessible = ( (hwndPopup != null) && !hwndPopup.closed ); } catch(exc) { } ");
			if (!isAccessible) {
				hwndPopup = null;
			}
		}
	}
	
	if ( (hwndPopup == null) || hwndPopup.closed ) {
		
		if (isOpera && (operaVersion < 7)) {
			if (url.indexOf("http") != 0) {
				hwndPopup = window.open(url,popupTarget,popupParams + ((!isFullScreen) ? ", width=" + popupW +", height=" + popupH : ""));
				if (!isFullScreen) {
					hwndPopup.moveTo(posX, posU);
				}
				hwndPopup.focus();
				return;
			}
		}
		if (!(window.navigator.appName == "Netscape" && !document.getElementById)) {
			//not ns4
			popupParams += ", width=" + popupW +", height=" + popupH + ", left=" + posX + ", top=" + posU;
		} else {
			popupParams += ", left=" + posX + ", top=" + posU;
		}
		//alert(popupParams);
		hwndPopup = window.open("",popupTarget,popupParams);
		if (!isFullScreen) {
			hwndPopup.resizeTo(popupW, popupH);
			hwndPopup.moveTo(posX, posU);
		}
		hwndPopup.focus();
		with (hwndPopup.document) {
			open();
	    		write("<ht"+"ml><he"+"ad><\/he"+"ad><bo"+"dy onLoad=\"window.location.href='" + url + "'\"><\/bo"+"dy><\/ht"+"ml>");
			close();
		}
	} else {
		if (isOpera && (operaVersion > 7.00)) {
			eval("try { hwndPopup.focus();	hwndPopup.location.href = url; } catch(exc) { hwndPopup = window.open(\""+ url +"\",\"" + popupTarget +"\",\""+ popupParams + ", width=" + popupW +", height=" + popupH +"\"); } ");
		} else {
			hwndPopup.focus();
			hwndPopup.location.href = url;
		}
	}
}


/**********************************************************************
* function:		imgPopup()
* description:	shows an image in a window-like floating div
* variables:	photo		- image's URL
* 					title		- image title
* 					desc		- image description
* 					price		- item price
* 					chk		- window top screen position
**********************************************************************/
function imgPopup(photo, title, desc, price, chk) 
{
	if (self.innerWidth) {
		  w = self.innerWidth;
		  h = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		  w = document.documentElement.clientWidth;
		  h = document.documentElement.clientHeight;
	}


	//Create Div
	var imgDiv = document.createElement("div");
	imgDiv.id = "imgPopup";
	
	imgDiv.style.left = (w - 640) / 2 + 'px';
	imgDiv.style.top = (h - 480) / 2 + 'px';
	
	//document.getElementById('container').insertBefore(imgDiv, document.getElementById('main_content'));
	document.getElementById('container').appendChild(imgDiv);
	
	//Add closing buttons
	var closeLink = document.createElement("span");
	closeLink.id = "popupClose";
	closeLink.innerHTML = "<a href='#' onClick='removeImgPopup();return false;'>close window [x]</a>";
	imgDiv.appendChild(closeLink);
	

	
	//Add Image
	var img = document.createElement("img");
	img.className = "poppedImg";

	img.src = photo;
	imgDiv.appendChild(img);
	
	//Add Title
	var titleLbl = document.createElement("div");
	titleLbl.className = "poppedTitle";
	titleLbl.innerHTML = title;
	imgDiv.appendChild(titleLbl);
	
	
	//Add Desc
	var descLbl = document.createElement("div");
	descLbl.className = "poppedDesc";
	descLbl.innerHTML = desc;
	imgDiv.appendChild(descLbl);
	
	
	//Add Price
	var priceLbl = document.createElement("div");
	priceLbl.className = "poppedPrice";
	priceLbl.innerHTML = price;
	imgDiv.appendChild(priceLbl);
}


/**********************************************************************
* function:		removeImgPopup()
* description:	closes the image popup created by imgPopup()
* variables:	none
**********************************************************************/
function removeImgPopup() {
	document.getElementById('container').removeChild(document.getElementById('imgPopup'));
	//document.getElementById('imgPopup').style.visibility = hidden;
}


