/*
	File: js/caldwnld.js
	$Id: caldwnld.js,v 1.2 2008-12-04 20:40:17 laurie Exp $

	Used to download or copy one or more calendar entries to a desktop
	or online calendar.
*/

function calDownload( calType, items, url )
{

	$anot = "calDownload:"
			+ "\r\n  name: " + items.name
			+ "\r\n  typeof(name): " + typeof(items.name)
			+ "\r\n  typeof: " + typeof(items)
			+ "\r\n  constructor: " + items.constructor
			+ "\r\n  length: " + items.length
		;
	if ( ("undefined" != typeof( items.name )) && (null != typeof( items.name )) )
	{
		items = new Array( items );
	}
	$anot += "\r\n  length: " + items.length;

	gotone = false;
	url += '&option=' + calType + '&IDs=';
	sep = '';
	for ( ii = items.length; ii--; )
	{
		if ( items[ii].checked )
		{
			gotone = true;
			url += sep + items[ii].value;
			sep = ',';
		}
	}

	if ( gotone )
	{
		switch ( calType )
		{
			case 'g':
				port = window.location.port;
				if ( (null == port) || ('' == port) )
				{
					port = '';
				} else
				{
					port = ':' + port;
				}
				url = encodeURIComponent(
						  window.location.protocol
						+ "//" + window.location.host
						+ port
						+ window.location.pathname.replace( /\/[^\/]*$/, "/" )
						+ url
					);
				url = 'https://www.google.com/accounts/AuthSubRequest?scope=http%3A%2F%2Fwww.google.com%2fcalendar%2Ffeeds%2F&session=1&secure=0&next=' + url;
			break;

			default:
			break;
		}
		window.open( url );
	}

	//alert( $anot );

	return;
}
