// JScript File

var DELAY_BEFORE_CLOSING = 5000;  // in miliseconds


var popUpWin = ['1', '2', '3'];

function popUpWindowWithSizes2(URLStr, width, height)
{
    return showModalDialog(URLStr, "", "dialogHeight: " + height + "px; dialogWidth: " + width + "px; edge: Raised; center: Yes; help: no; resizable: Yes; status: Yes;");
}

function popUpWindowWithSizes(URLStr, width, height)
{
	return popUpWindowWithSizesFull(URLStr, width, height, 'no', 'no', 'no', 'no', 'no', 'yes', 'yes', 'yes');
}


function popUpWindowWithSizesFull(URLStr, width, height, toolbar, location, directories, status, menubar, scrollbars, resizable, copyhistory)
{
	var new_index;
	var rk_availWidth;
	var rk_availHeight;
	var rk_width;
	var rk_height;
	var rk_top;
	var rk_left;
	var top_shift = 40;
	var rk_options;
	var new_win_name;
	
	// detect browser
	var explorer;
	
	// statusbar string according to the current browser
	var sbr;
	
	// start browser detection
	explorer = (navigator.userAgent.toLowerCase().indexOf('msie') != (-1));
	
	// is it explorer?
	if (explorer)
	{
		// yes, it is. but it's not the standard
		sbr = 'scrollbars';
	}
	else
	{
		// no. it isn't.
		sbr = 'scrollbar';
	}
	
	rk_availWidth = screen.availWidth;
	rk_availHeight = screen.availHeight;
	rk_width = width;
	rk_height = height;
	
	// set the top and the left so that the popped window
	// appears in the middle of the cleint's screen.
	
	// first, the top
	// get the delta
	rk_top = 0.5 * (rk_availHeight - rk_height);
	// floor it
	rk_top = Math.floor(rk_top);
	// shift a bit to the top
	rk_top = rk_top - top_shift;
	
	// now, the left
	// delta
	rk_left = 0.5 * (rk_availWidth - rk_width);
	// floor it
	rk_left = Math.floor(rk_left);
	
	// debugging
	// alert("rk_width = " + rk_width + " rk_height = " + rk_height + " rk_top = " + rk_top + " rk_left = " + rk_left + " rk_availWidth = " + rk_availWidth + " rk_availHeight = " + rk_availHeight + "");

	do
	{
		new_index = NewGuid();
	} while (popUpWin[new_index] != null);
	
	// prepare options string
	rk_options = 'toolbar=' + toolbar;
	rk_options += ',location=' + location;
	rk_options += ',directories=' + directories;
	rk_options += ',status=' + status;
	rk_options += ',menubar=' + menubar;
	rk_options += ',' + sbr + '=' + scrollbars;
	rk_options += ',resizable=' + resizable;
	rk_options += ',copyhistory=' + copyhistory;
	rk_options += ',width='+rk_width;
	rk_options += ',height='+rk_height;
	rk_options += ',left='+rk_left;
	rk_options += ',top='+rk_top;
	rk_options += ',screenX='+rk_left;
	rk_options += ',screenY='+rk_top+'';
	
	// and now, ladies and gents...
	new_win_name = 'popUpWin' + RandomInt(10000, 99999) + '';
	popUpWin[new_index] = window.open(URLStr, new_win_name, rk_options);
	
	// focus it!
	if(popUpWin[new_index])
		popUpWin[new_index].focus();
	
	// just for safety reasons
	return new_index;
}


function popUpWindowX(URLStr)
{
	var new_index;
	var rk_availWidth;
	var rk_availHeight;
	var wRatio = 0.9;
	var hRatio = 0.6;
	var rk_width;
	var rk_height;
	var rk_top;
	var rk_left;
	
	var explorer;
	
	var sbr;
	
	explorer = (navigator.userAgent.toLowerCase().indexOf('msie') != (-1));
	if (explorer)
		sbr = 'scrollbars';
	else
		sbr = 'scrollbar';
	
	rk_availWidth = screen.availWidth;
	rk_availHeight = screen.availHeight;
	rk_width = wRatio * rk_availWidth;
	rk_width = Math.floor(rk_width);
	rk_height = hRatio * rk_availHeight;
	rk_height = Math.floor(rk_height);
	rk_top = 0.5 * (rk_availHeight - rk_height);
	rk_top = Math.floor(rk_top);
	rk_top = rk_top - 40;
	rk_left = 0.5 * (rk_availWidth - rk_width);
	rk_left = Math.floor(rk_left);
	
	// alert("rk_width = " + rk_width + " rk_height = " + rk_height + " rk_top = " + rk_top + " rk_left = " + rk_left + " rk_availWidth = " + rk_availWidth + " rk_availHeight = " + rk_availHeight + "");
	
	new_index = popUpWin.length;
	popUpWin[new_index] = window.open(URLStr, 'popUpWin' + new_index + '', 'toolbar=yes,location=no,directories=no,status=no,menubar=yes,' + sbr + '=yes,resizable=yes,copyhistory=yes,width='+rk_width+',height='+rk_height+',left='+rk_left+',top='+rk_top+',screenX='+rk_left+',screenY='+rk_top+'');
	setTimeout("docHelper(" + new_index + ")", 100);
	return false;
}

function RandomInt(atLeast, atMost)
{
    var delta = atMost - atLeast;
    var r = Math.random() * delta;
    r = Math.floor(r);
    return atLeast + r;
}

//**************************************
//     
// Name: Generate Guid
// Description:Create a guid in javascript. 
//     Global Unique Identifier
// By: Lewis E. Moten III
//
//This code is copyrighted and has limited warranties.
//Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=4678&lngWId=2
//for details.
//**************************************
//     

// Ron's comment: it's random alright, 
// but it's not based on any algorithm that
// really avoids repeating values.
// however, it gives a "good" random value.

function NewGuid()
{
    var g = "{";
    for (var i = 0; i < 32; i++)
    	g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : "");
    return g + "}";
}

function goReload()
{            
    self.location.reload(false);
}