window.onerror = null;
var newPopUpWindow = null;

function openPopUpWindow(popUpWindowPath, popUpWindowName, popUpWindowProperties, phoneNum) {   
	if (popUpWindowName=="AddImage") {
		if (!(isNull(newPopUpWindow))) 
		{
			if (newPopUpWindow) if (!newPopUpWindow.closed) newPopUpWindow.close();      
		}
	}
	doOpen(popUpWindowPath, popUpWindowName, popUpWindowProperties, phoneNum);	
	//newPopUpWindow = window.open(popUpWindowPath, popUpWindowName, popUpWindowProperties);
	//newPopUpWindow.focus();
}

function openPopup(URL)	{
	Link = URL;
	doOpen(Link,"Questions","toolbar=no,scrollbars=yes,resizable=yes,menubar=no,status=no,directories=no,location=no,top=200,left=100,width=275,height=300")	
	//newWindow=window.open(Link,"Questions","toolbar=no,scrollbars=yes,resizable=yes,menubar=no,status=no,directories=no,location=no,top=200,left=100,width=275,height=300")
	//newWindow.focus();
}

function doOpen(url, popUpWindowName, popUpWindowProperties, phoneNum)     {
// attempt to open the popup
	win = window.open(url, popUpWindowName, popUpWindowProperties);
    if (win)	{
    // popup successfully created
		win.focus();
	} else {
	// popup was not created.
		showPopupMessage(url, phoneNum);
	}
	return win;
}

function showPopupMessage(url, phoneNum)	{
	if (!document.createElement)	{
		return;
	}
    var elmDiv = document.createElement('div');
	if (typeof(elmDiv.innerHTML) != 'string')	{
		return;
	}
	elmDiv.id  = 'popupmessage';
	
	elmDiv.style.cssText = 
         'position: absolute; left: 300px; top: 200px;' +
         'width: 400px;' +
         'color: black; ' +
         'background-color: white; ' +
         'font-weight: bold; ' +
         'border: solid #cecfce 3px; ' +
         'padding: 1em;';
	 
		 //'<p style="font-family:arial;font-size:12px;"><font color="#800000">Your computer settings may be set to restrict pop-ups.</font><br>Pop-up restriction on www.selectcomfort.com will restrict access to a ' + 
         //'significant amount of important information including product details and special offers. To make your browsing experience more ' +
  	 	 //'enjoyable, we recommend enabling pop-ups for this site. <br>' + phoneNum + 
var html = '<p style="font-family:arial;font-size:12px;"><font color="#800000">Your computer settings may be set to restrict pop-ups.</font><br>' +
		 'Pop-up restriction on <a href="http://www.selectcomfort.com/">www.selectcomfort.com</a> will restrict access to a significant amount of important information including ' +
		 'product details and special offers. To make your browsing experience more enjoyable, we recommend enabling pop-ups for this site. ' +
		 'If you have questions please contact us at ' + phoneNum + '.' + 		 
		 //<a href="#" ' +
         //'onclick="win = doOpen(\'' + url + '\'); hidePopupMessage(); return false;">' +
         //'open the window' +
         //'<\/a>.' +
         '</p><p align="center" style="font-family:arial;font-size:12px;">' +
         '<a href="#" onclick="hidePopupMessage(); return false;">Close this message<\/a>' +
         '<\/div>';
       document.body.appendChild(elmDiv);
       elmDiv.innerHTML = html;
}

function hidePopupMessage()	{
	var elmDiv = document.getElementById('popupmessage');
	if (elmDiv)	
		{
          elmDiv.parentNode.removeChild(elmDiv);
        }
}