// JavaScript Document

/**
* scripts/pop-up.js
*
* SOS Cuisine
*   Scripts JavaScript de support
*
* Created  : 2005/02/16
* Modified : 2005/02/16
* Author(s): Jean-François Beauchamp <jfbeauchamp@videotron.ca>
* Version  :
* History  :
*   2005/02/16 Jean-François Beauchamp
*	  - Création de ce fichier
* 
* Features :
*       
* To do    :
*
* Question :
*
* @author  Jean-François Beauchamp <jfbeauchamp@videotron.ca>
* @version 1.0 2005/02/16
*/


var newWindow = '';

function popup(mylink, windowname, windowparam)
{
	//  tests for the existence of the window.focus method. window.focus is how we bring the popup 
	// to the front every time, even though it was already open. Some older browsers do not have 
	// window.focus -- those browsers degrade gracefully by failing out of the function 
	// and going to the popup's URL in the current window. Note that there are no parentheses 
	// after window.focus because we are testing for the existence of the function, not running it.
	if (! window.focus) return true;
	//  Figure out what that URL is. We test if mylink is a string. If it is a string, 
	// we assign to href the value of the string. If mylink is not a string then we assume 
	// it is an <A ...> or <AREA ...> object and we assign to href the value of the objects href property
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	// Exemple de windowparam : 'toolbar=yes,menubar=yes,resizable=yes,scrollbars=yes'
	if (windowparam == '') windowparam = 'width=500,height=350,toolbar=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=yes';
	// If the script is called, we first need to check if the popup is already opened.
	if (!newWindow.closed && newWindow.location)
	{
		newWindow.location.href = href;
	}
	else
	{
		newWindow = window.open(href, windowname, windowparam);
		if (!newWindow.opener) newWindow.opener = self;
	}
	// Put the focus on the popup if the browser supports the focus method 
	if (window.focus) {newWindow.focus()}
	// Return false for accessibility reasons.
	return false;
}

var imgWindow = null;
function imagePopup(url, windowName, width, height, header, urlText, link)
{
    if (! window.focus) return true;
    
    windowparam = "width=" + width + ",height= " + height + "toolbar=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=yes";
    
    doc = "<div>";
       doc += "<div>";
           doc += "<img src='media/images/logo_simple.png'>";
       doc += "</div>";
       doc += "<h1 style='text-align:center;color:#666666;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:20px;padding:0;margin:0'>" + header +  "</h1>";
       doc += "<div style='text-align:center;'><a onclick='window.opener.location = this.href; window.close(); return false;' style='color:#CC0000' href='" + link + "'>" + urlText + "</a></div>";
       doc += "<img src='" + url + "'>";
    doc += "</div>";
    
    if (!imgWindow || imgWindow.closed)
    {
       imgWindow = window.open('', windowName , windowparam);    
    }
    else
    {
       imgWindow.innerWidth = width;
       imgWindow.innerHeight = height;
    }
    imgWindow.document.write(doc);
    imgWindow.document.close();
    if (window.focus) {imgWindow.focus()}
}

