var popupWindow = '';
var refreshInterval;

function ShowPopup(url) 
{
	if (!popupWindow.closed && popupWindow.location) 
	{
		popupWindow.location.href = url;
	}
	else 
	{
		popupWindow = window.open(url, 'Popup', 'height=675,width=675,scrollbars=1,resizable=1');
		
		if (!popupWindow.opener) 
		{
		    popupWindow.opener = self;
		}
	}
  
    if (window.location && window.location.search.search(/preval=1/i) != -1 && 
        ( url.search(/edititem.aspx/i) != -1 || url.search(/editgiftmessage.aspx/i) != -1))
    {    
        if (window.setInterval)
        {
            refreshInterval = window.setInterval('FireRefreshEvent()', 750);
        }
    }
    
    if (window.focus) 
	{
	    popupWindow.focus();
	}
   	
	return false;
}

var newWindow = '';

function OpenWindow(url)
{
    if (!newWindow.closed && newWindow.location)
    {
        newWindow.location.href = url;        
    }
    else
    {
        newWindow = window.open(url, 'new_window');
        
        if (!newWindow.opener)
        {
            newWindow.opener = self;
        }
    }
    
    if (window.focus)
    {
        newWindow.focus();
    }
    
    return false;
}

function ClosePopup(thisIsIgnored)
{       
    window.close();    
}

function FireRefreshEvent()
{     
    if (popupWindow == null || popupWindow.closed)
    {                      
        if (refreshInterval && window.clearInterval)
        {          
            window.clearInterval(refreshInterval);
        }
        
        if (window.location)
        {   
            if (window.location.search.search(/preval=1/i) != -1)
            {
                window.location.reload();
            }
        }
    }
}

function ThrowPopup(popUrl, mainUrl) 
{
	if (!popupWindow.closed && popupWindow.location) 
	{
		popupWindow.location.href = popUrl;
	}
	else 
	{
		popupWindow = window.open(popUrl, 'Popup', 'height=675,width=675,scrollbars=1,resizable=1');
		
		if (!popupWindow.opener) 
		{
		    popupWindow.opener = self;
		}
	}
		
    if (window.self != popupWindow)		
    {
	    window.location.href = mainUrl;
      
        if (window.focus) 
	    {
	        popupWindow.focus();
	    }
    }
   	
	return false;
}


function clientSideInclude(id, url) {


	var req;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
 
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}
 
