/* Opens any .gif, .jpg or .png image thru /bin/phplib/popup_image.php script
** on a new window with no toolbar that is resized automatically based on the size of the 
** image
** Parameters :
**   urlImage = absolute or relative url of the image to open
**   do not refer absolute urls as http://... Relative paths should be refered to the actual php
**   script from where this function is called.
** Optional parameter :
**   Window title, default is NOAA/AOML/PhOD
*********************************************************************/
//$RCSID = '$$';
RCSID = '$$';

function openImage(urlImage) {
    
	var winTitle = arguments[1];
	var w; 	var h; var name; var pageUrl;
	
	name = "imagesautoresize";
	pageUrl = document.location.href;
	if (!winTitle){
		winTitle = "NOAA/AOML/PhOD";
	}
	w = 400;
	h = 200;
	if (pageUrl.indexOf("?") > -1){
		pageUrl = pageUrl.substring(0,pageUrl.indexOf("?"));
	}
	if (pageUrl.indexOf("#") > -1){
		pageUrl = pageUrl.substring(0,pageUrl.indexOf("#"));
	}
	url = "/phod/bin/phplib/popup_image.php?&pImgUrl="+urlImage+"&pPageUrl="+pageUrl+"&pSWidth="+screen.width+"&pSHeight="+screen.height+"&pTitle="+winTitle;
	
	var win = window.open(url, name, "resizable=yes,scrollbars=yes,toolbar=no,status=no,left=20,top=20,width=" + w + ",height=" + h);
	
    	if (win.opener == null) win.opener = this;
	
    	win.focus();
}

function openText(url) {

        // calculates the name of the page depending on the url
        var fin = url.indexOf(".htm");
        var name;
        if (fin != -1) {
                var deb = url.lastIndexOf("/");
                name = url.substring(deb + 1, fin);
        } else {
                // image (gif, jpg) : window 'images'
                fin = url.indexOf(".gif");
                if (fin == -1) fin = url.indexOf(".jpg");
                if (fin != -1) name = "images";
                // if not new window
                else name = "_blank";
        }
    // parameters
    var w = arguments[1];
    var h = arguments[2];
    if (!w) w = 650;
    if (!h) h = 500;
        // opens the window
        var win = window.open(url, name, "resizable=yes,scrollbars=yes,toolbar=no,width=" + w + ",height=" + h);
        if (win.opener == null) win.opener = this;
        // focus on the window if already opened
        win.focus();
}

