//alert('nimbus.js syntax ok'); 
function PrognoseFenster ( gebiet, inhalt, date ) {
	var d = UnixToJSDate ( date );
	newWindow=window.open('http://streckenflug.ch/WordPress/wp-content/themes/Nimbus/classic/Meteo/RegThermArea.php?' +
		'a=' + gebiet + '&content=' + inhalt + '&hacker=Urs_Ribi&d=' + Math.floor ( d.getTime() / 1000 ),"_blank",
		'width=880,height=500,toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=1,resizable=1');
	newWindow.focus();
}
function OpenGraphicWin ( host, id, dte, hck )	{
	var url = host + 'wp-content/themes/Nimbus/classic/Meteo/RegThermArea.php?content=2&a=' + id + "&d=" + dte + hck;
	var newWindow = window.open( url,'_blank','width=880,height=505,toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=1,resizable=1');
	newWindow.focus();
}
function show_hide(element) {
	element = $(element);
	if (element.style.display == 'block')
		element.style.display = 'none';
	else
		element.style.display = 'block';
}

function reloadImage (element,addr,width) {
	var img = "<img src=\"" + addr + "\"  width=\"" + width + "\" />";
//	alert(img);
	element.innerHTML = img;
}

/*------------------------------------------------------------
**	collaps | uncollaps
*/

function collaps (element, target, job)	{
	element = $(element).up();
	var open = element.hasClassName('collapsed');
	if (job)
		open = job == 'on';
	if (open)	{
		element.className = 'uncollapsed';
		if (target)
			$(target).style.display = 'block';
	}
	else	{
		element.className = 'collapsed';
		if (target)
			$(target).style.display = 'none';
	}
}
function Wolke (path, typ)	{
alert('pfad :' + pfad);
	switch (typ)	{
		case "ch":	return "<img src=" + path + "images/Cirrus.jpg>";
		case "cm":	return "<img src=" + path + "images/Cirrostratus.jpg>";
		case "cl":	return "<img src=" + path + "images/Altocumulus.jpg>";
		case "cum":	return "<img src=" + path + "images/Cumulus.jpg>";
	}
}
function ToPilotTip ( id )	{
	var pic = "<img src='http://streckenflug.ch/images/Portrait/" + id + ".jpg' width='128' />";
	return pic;
}
function ImageTip ( url, width ) {
	var r = Math.random();
	var img = "<img src='" + url + "?rnd=" + r + "' width='" + width + "' />";
	Tip ( img );
}
function PDFTip ( url, width ) {
	var r = Math.random();
//	var img = "<img src='" + url + "?rnd=" + r + "' width='" + width + "' />";
	var pdf = "<iframe src='" + url + "' width='" + width + "' /></iframe>";
	Tip ( pdf );
}
//---------------------------------------------------------------------------------------
//	visitor statistics
//.......................................................................................
function online_statistic ( job, target, succeeding ) {
	switch ( job ) {
	case 'online':
	case 'hour':
	case 'today':
	case 'week':
	case 'month':
	case 'year':	target = job + '_visitors';
					document.getElementById(target).style.display = 'inline';
					VisitorCounter ( target, job, "<visitors>" ); break;
	case 'start':
		if ( succeeding ) document.getElementById( succeeding + '_text' ).style.display = 'inline';
		online_statistic ( target, target + '_visitors' );
		document.getElementById( target + '_text' ).className = "";
		switch ( target ) {
		case 'hour':	document.getElementById( target + '_text' ).innerHTML = "in der letzten Stunde, "; break;
		case 'today':	document.getElementById( target + '_text' ).innerHTML = "heute, "; break;
		case 'week':	document.getElementById( target + '_text' ).innerHTML = "diese Woche, "; break;
		case 'month':	document.getElementById( target + '_text' ).innerHTML = "diesen Monat, "; break;
		case 'year':	document.getElementById( target + '_text' ).innerHTML = "dieses Jahr"; break;
		}
	}
}
function VisitorCounter ( element, periode, template, date ) {
	var arg = { 'template': template, 'periode': periode };
	if ( date )
		arg.d = date;
	AjaxReload( 'counter', element, arg );
}

window.setTimeout("online_statistic('online','online_visitors')",30000);
//---------------------------------------------------------------------------------------
//	Flightplan::NewDate ( date )
//.......................................................................................
function UnixToJSDate ( date ) {
	var now = new Date();
	var j = now.getYear();
	var mo = now.getMonth();
	var d = now.getDate();
	var h = 0, m = 0, s = 0;
	date = date.gsub(/([0-9]{4})-([0-9]{2})-([0-9]{2})/,function(p){
				j = p[1]; mo = p[2] - 1; d = p[3];
			  });
	date = date.gsub(/([0-9]{2}):([0-9]{2})/,function(p){
				h = p[1]; m = p[2]; 
			  });
	date = date.gsub(/([0-9]{2})/,function(p){
				s = p[3];
			  });
	return new Date ( j, mo, d, h, m, s );
}
CronJob();
function CronJob ()	{
	AjaxGet( 'cron', function (a) { if (a) alert(a); } );
	window.setTimeout("CronJob()",600000);
}
function Picture (pict){
alert('pfad :' + pfad);
	return "<img src=\"" + pfad + "images/" + pict + ".jpg\">";
}
function Portrait (pilid){
alert('pfad :' + pfad);
	return "<img src=\"" + pfad + "images/Portrait/" + pilid + ".jpg\" alt=\"Portrait\">";
}

function ur_FotoPopupBericht (bild, width, height)	{
	newWindow=window.open(bild,'Bild',
		'width=' + width + ',height=' + height + ',toolbar=0,' +
		'location=0,directories=0,status=0,menuBar=0,scrollBars=1,' +
		'resizable=1');
	newWindow.focus();
}
function ToggleHTML (id, checked)	{
	var html = document.getElementById(id);
	if ( html )
		html.style.display = checked ? 'block' : 'none';
	else
		alert ( 'ToggleHTML ' + id + ' failed' );
}
function Toggle (id, job, onshow, onhide)	{
	var button  = $(id + 'btn');
	var open = button.className == 'is_off';
	if (job)
		open = job == 'on';
	if ( open )	{
		$(id).style.display = 'block';
		button.className = 'is_on';
		if (onshow) eval("("+onshow+")");
	}
	else	{
		$(id).style.display = 'none';
		button.className = 'is_off';
		if (onhide) onhide();
	}
}
function ReloadAusland ( jahr, order )	{
	AjaxReload('OLC', 'SchweizerImAusland', {'jahr':jahr,'klasse':'ausland','id':'SchweizerImAusland','order':order});
}
function ReloadPilot ( id, jahr, order )	{
	var div = 'jahr' + jahr + id;
	AjaxReload('Pilot', div, { 'jahr': jahr,pilotid: id, job:'jahr', id: div, 'order':order});
}
function ReloadClub ( id, jahr, order )	{
	var div = 'jahr' + jahr + id;
	AjaxReload('Club', div, { 'jahr': jahr,clubid: id, job:'jahr', id: div, 'order':order});
}
function ReloadOLCTag(tag, element)	{
	if (tag == 0)
		return;
	var button = $(element + 'btn');
	$(element).style.display = 'block';
	button.className = 'is_on';
	AjaxReload('OLC',element,	{ tag: tag,klasse:'tag',id:element});
}
function LoadLiga(runde,element,jahr)	{
	$(element).innerHTML = 'Die OLC Liga Runde ' + runde + ' wird geladen';
	var button = $(element + 'btn');
	$(element).style.display = 'block';
	button.className = 'is_on';
	AjaxLoad('OLC',element,	{ 'jahr': jahr, klasse:'liga',id:element, 'runde': runde});
}
function LoadNSFWGruppen(runde,element,jahr)	{
	$(element).innerHTML = 'Die NSFW Liga Runde ' + runde + ' wird geladen';
	var button = $(element + 'btn');
	$(element).style.display = 'block';
	button.className = 'is_on';
	AjaxLoad('NSFW',element, { 'jahr': jahr, klasse:'gruppen',id:element, 'runde': runde});
}
var PilotLoaded = false;
function DoOpenPilot (pilotid)	{
	var element = $('champ' + pilotid + 'btn').up('li',1).down('h2');
	collaps(element,'pilot' + pilotid, 'on');
	element = element.up('li',1).down('h2');
	collaps(element,'Piloten', 'on');
}
function OpenPilot (pilotid)	{
	if (PilotLoaded)	{
		DoOpenPilot(pilotid);
		PilotLoaded = false;
	}
	else
		PilotLoaded = true;
}
function TimeToFloat ( t1 )	{
	var t = t1.strip().split(':');
	return Number(t[0]) + t[1] / 60;
}
function FloatToTime ( t )	{
	var h = Math.floor(t);
	var m =  Math.round((t - h) * 60);
	return h + ':' + (m < 10 ? '0' : '') + m;
}
var checkmark = '';
var lineclasses = [ '_even' , '_odd' ];
function IsChecked (cell)	{
	var content = $(cell).innerHTML;
	if (checkmark == '')	{
		$(cell).innerHTML = '&radic;';
		checkmark = $(cell).innerHTML;
		$(cell).innerHTML = content;
	}
	return content == checkmark;
}
function SetCheckMark (cell, check)	{
	if (check)
		$(cell).innerHTML = '&radic;';
	else
		$(cell).innerHTML = '&nbsp;&nbsp;&nbsp;';
	return  check;
}
function ToggleCheck (cell)	{
	return SetCheckMark( cell, ! IsChecked(cell) );
}
function ToggleOddEven(line,zeile)	{
	var newclass = lineclasses[zeile % 2];
	var oldclass = lineclasses[++zeile % 2];
	if (line.hasClassName(oldclass))	{
		line.removeClassName(oldclass);
		line.addClassName(newclass);
	}
}
function ParseList ( arg )	{
	this.klasse	= [ '_even' , '_odd' ];
	this.oddnr	= 0;
	this.arg	= arg;
	this.rang	= 1;
	this.doRang	= typeof(arg.rang) == 'object';
	this.doSum	= typeof(arg.sum) == 'object';
	this.doQuot	= typeof(arg.quot) == 'object';
	this.doTime	= typeof(arg.time) == 'object';
	this.cells	= null;
	this.line	= null;
	
	this.SetClass = function ( )	{
		var oldclass = this.klasse[ this.oddnr % 2 ];
		++this.oddnr;
		with (this.line)	{
			if (hasClassName ( oldclass ) )	{
				removeClassName ( oldclass );
				addClassName ( this.klasse[ this.oddnr % 2 ] );
			}
		}
	}
	this.Set = function ( line )	{
		this.line = line;
		this.cells = line.childElements()
	}
	this.IsChecked = function ()	{
		return IsChecked ( this.cells.last() );
	}
	this.RestoreRang = function ( )	{
		if ( this.doRang )
			this.cells[this.arg.rang.col].innerHTML = this.cells[this.arg.rang.back].innerHTML;
	}
	this.SetRang = function ( )	{
		if ( this.doRang )
			with (this.cells[ this.arg.rang.col ])
				if ( ! innerHTML.blank() )
					innerHTML = this.rang++;
	}
	this.CollectSum = function ()	{
		for ( var i = 0, len = this.arg.sum.length; i < len; ++i )
			with ( this.arg.sum[i] )
				if ( val = Number( this.cells[ col ].innerHTML ) )	{
					total += val;
					++count;
				}
	}
	this.CollectTime = function ()	{
		for ( var i = 0, len = this.arg.time.length; i < len; ++i )
			with ( this.arg.time[i] )
				if ( val = TimeToFloat( this.cells[ col ].innerHTML ) )	{
					total += val;
					++count;
				}
	}
	this.CollectQuot = function ()	{
		for ( var i = 0, len = this.arg.quot.length; i < len; ++i )
			with ( this.arg.quot[i] )
				if ( rechts = Number( this.cells[ col2 ].innerHTML ) )	{
					var links = Number( this.cells[ col1 ].innerHTML);
					left += links;
					right += links / rechts;
					++count;
				}
	}
	this.Collect = function ( )	{
		if ( this.doSum )	this.CollectSum ();
		if ( this.doTime )	this.CollectTime ();
		if ( this.doQuot )	this.CollectQuot ();
	}
	this.PrintSum = function ()	{
		for ( var i = 0, len = this.arg.sum.length; i < len; ++i )	{
			with ( this.arg.sum[i] )	{
				this.cells[ dst ].innerHTML = total.toFixed( prec );
				if ( typeof(templ) == 'string' )	{
					avg = Math.round( total / count );
					var t = new Template( templ );
					this.cells[ dest ].innerHTML = t.evaluate( this.arg.sum[i] );
				}
			}
		}
	}
	this.PrintTime = function ()	{
		for (var i = 0, len = this.arg.time.length; i < len; ++i)	{
			with ( this.arg.time[i] )
				this.cells[ dst ].innerHTML = FloatToTime( total );
		}
	}
	this.PrintQuot = function ()	{
		for (var i = 0, len = this.arg.quot.length; i < len; ++i)	{
			with ( this.arg.quot[i] )	{
				if ( dst1 )
					this.cells[ arg.quot[i].dst1 ].innerHTML = left.toFixed( prec1 );
				if ( dst2 )	{
					var result = left / right;
					this.cells[ dst2 ].innerHTML = result.toFixed( prec2 );
				}
				if ( typeof(templ) == 'string' )	{
					avg = Math.round( left / count );
					var t = new Template( templ );
					this.cells[ dest ].innerHTML = t.evaluate( this.arg.quot[i] );
				}
			}
		}
	}
	this.Print = function ()	{
		if ( this.doSum )	this.PrintSum ();
		if ( this.doTime )	this.PrintTime ();
		if ( this.doQuot )	this.PrintQuot ();
	}
}
function ShowHide ( cell, arg )	{
	var body = $(cell).up('table').down('tbody');
	var lines = body.childElements(this.cells);

		var parser = new ParseList (arg);
		if ( ToggleCheck ( cell ) )	{
			lines.invoke ( 'show' );
			lines.each ( function ( line ) {
				parser.Set ( line );
				parser.SetClass ();
				parser.RestoreRang ();
				parser.Collect ();
			} );
		}
		else	{
			lines.invoke('hide');
			lines.each ( function ( line ) {
				parser.Set ( line );
				if ( parser.IsChecked () )	{
					parser.SetClass ();
					parser.SetRang ();
					parser.Collect ();
					line.show ();
				}
			} );
		}
		parser.Set ( $(cell).up('table').down('tfoot').down() );
		parser.Print();
}
function MarkLines (lines,index,id)	{
	lines.each(function(line) {
		var cells = line.childElements();
		if ( cells[index].innerHTML.strip() == id )
			SetCheckMark ( cells.last(), true );
	} );
}
function SelectLines (cell, id, col)	{
	MarkLines($(cell).up('tbody').childElements(),col,id);
}
function MarkClub (cell,clubid)	{
	MarkLines($(cell).up('tbody').childElements(),0,clubid);
}
function MarkAirport (cell,apid)	{
	MarkLines($(cell).up('tbody').childElements(),1,apid);
}
function ClearMarks (cell)	{
	var lines = $(cell).up('table').down('tbody').childElements();
	lines.each(function(line) { 
		SetCheckMark ( line.childElements().last(), false );
	} );
}
function InstallPilot (pilotid)	{
	if (pilotid == 0)
		return;
	if ($('pilot' + pilotid + 'li'))	{
		DoOpenPilot (pilotid);
		return true;
	}
	AjaxGet( 'Pilot',
		function (html) {
			$('PilotSelect').up().insert( { after: html } );
			OpenPilot (pilotid);
		} ,
		 { job: 'menu', pilotid: pilotid } );
	AjaxGet( 'Pilot',
		function (html) {
			$('Piloten').insert( { top: html } );
			OpenPilot (pilotid);
		} ,
		 { job: 'container', pilotid: pilotid } );
}
var ClubLoaded = false;
function DoOpenClub (clubid)	{
	var element = $('club' + clubid + 'li').down('h2');
	collaps(element,'club' + clubid, 'on');
	element = element.up('li',1).down('h2');
	collaps(element,'Club', 'on');
}
function OpenClub (clubid)	{
	if (ClubLoaded)	{
		DoOpenClub(clubid);
		ClubLoaded = false;
	}
	else
		ClubLoaded = true;
}
function InstallClub (clubid)	{
	if (clubid == 0)
		return;
	if ($('club' + clubid + 'li'))	{
		OpenClub (clubid);
		return true;
	}
	AjaxGet( 'Club',
		function (html) {
//alert(html);
			$('ClubSelect').up().insert( { after: html } );
			OpenClub (clubid);
		} ,
		 { job: 'menu', 'clubid': clubid } );
	AjaxGet( 'Club',
		function (html) {
//alert(html);
			$('Club').insert( { top: html } );
			OpenClub (clubid);
		} ,
		 { job: 'container', 'clubid': clubid } );
}
function Explode (str)	{
	str = '[' + str.gsub(/([^ ]+)/,"'#{1}'") + ']';
	str = str.gsub(" ",",");
	return str.evalJSON();
}
function PilotenSeite (id)	{
	if (id == 0)
		return;
	InstallPilot(id);
}
function ClubSeite (cell,clubid)	{
	MarkClub (cell,clubid);
}
function AirportSeite (cell,apid)	{
	MarkAirport (cell,apid);
}
function OLCTagSeite (date)	{
	Go ('OLCTag', date);
}
function OLCSeite (flug, jahr)	{
	var url = '';
	switch (jahr)	{
		case 2003:	
		case 2004:	
		case 2005:	
		case 2006:	url = 'http://www2.onlinecontest.org/olcphp/' + jahr + '/ausw_fluginfo.php?spr=de&ref3=' + flug;
					break;
		case 2007:
		case 2008:	url = 'http://www.onlinecontest.org/olc-2.0/gliding/flightinfo.html?flightId=' + flug;
					break;
		default:	url = 'http://www.onlinecontest.org/olc-2.0/gliding/flightinfo.html?dsId=' + flug;
					break;
	}
	window.open(url);
}
function WetterSeite (date)	{
	if (date < '2007-02-25')	{
		alert("Für diesen Tag gibt es keine Wetteraufzeichnungen.\nDie Aufzeichnungen beginnen erst am 25.02.2007");
		return;
	}
	window.open( ABSPATH + '?section=wetter&d=' + date, '_blank' );
}
function OpenUp (element)	{
	var name;
	if (element = $(element).up('li',1))	{
		element = element.down('h2');
		if (name = String(element.onclick).match(/"(.*)"/))	{
			collaps(element, name[1], 'on');
		}
		else if (name = String(element.onclick).match(/'(.*)'/))	{
			collaps(element, name[1], 'on');
		}
		OpenUp (element);
	}
}
function EvalParam (p)	{
	for (var i = p.length - 1; i >= 0; --i)	{
		Go(p[i][0], p[i][1]);
	}
}
function Go (selector, value)	{
	var element = selector + value;
	switch (selector)	{
	case 'OLCTag':		element = 'OLCTag' + Saison ( value );
						ReloadOLCTag ( value, element );
						break;
	case 'OLCChampion':	AjaxLoad('OLC',element,	{ jahr: value, klasse:'champion', id:element});
						break;
	case 'OLCBeste':	AjaxLoad('OLC',element,	{ jahr: value, klasse:'best', id:element});
						break;
	case 'OLCAlle':		AjaxLoad('OLC',element,	{ jahr: value, klasse:'all', id:element});
						break;
	case 'OLCGruppen':	AjaxLoad('OLC',element,	{ jahr: value, klasse:'gruppen', id:element});
						break;
	case 'OLCLiga':		var p = Explode(value);
						var jahr = p[0];
						var runde = p[1];
						element = selector + jahr;
						LoadLiga(runde, element, jahr);
						break;
	case 'NSFWGruppe':	if ( value <= 2008 )
							AjaxLoad('NSFW',element, { jahr: value, klasse: 'gruppen', id: element });
						else {
							var p = Explode(value);
							var jahr = p[0];
							var runde = p[1];
							element = selector + jahr;
							AjaxLoad('NSFW',element, { jahr: jahr, klasse:'gruppen',id:element, 'runde': runde});
						}
						break;
	case 'NSFWOpen'	:	AjaxLoad('NSFW',element, { jahr: value, klasse: 'open', id: element });
						break;
	case 'NSFW18m'	:	AjaxLoad('NSFW',element, { jahr: value, klasse: '18m', id: element });
						break;
	case 'NSFW15m'	:	AjaxLoad('NSFW',element, { jahr: value, klasse: '15m', id: element });
						break;
	case 'NSFWStandard'	:AjaxLoad('NSFW',element, { jahr: value, klasse: 'standard', id: element });
						break;
	case 'NSFWClub'	:	AjaxLoad('NSFW',element, { jahr: value, klasse: 'club', id: element });
						break;
	case 'NSFWJunioren':AjaxLoad('NSFW',element, { jahr: value, klasse: 'junioren', id: element });
						break;
	case 'NSFWSenioren':AjaxLoad('NSFW',element, { jahr: value, klasse: 'senioren', id: element });
						break;
	case 'NSFWahv':		AjaxLoad('NSFW',element, { jahr: value, klasse: 'ahv', id: element });
						break;
	case 'history':		element = value;
						AjaxLoad('History',value, { klasse: value, id: value });
						break;
	case 'Pilot':		InstallPilot(value);
						return;
	case 'ausland':		ReloadAusland( value, '`date` DESC' );
						element = "SchweizerImAusland";
						break;
	default:			return;
	}
	Toggle ( element, 'on' );
	OpenUp ( element + 'btn' );
}

/*------------------------------------------------------------
** The Movie object plays a sequence of pictures
** Each picture fades into the nextPage
** Parameters:
**		parent		HTML Container of this movies
**		movie_name	this identifies the movie when requested from the server
**		duration	time between pictures in seconds (optional, default 5)
**		url			url which provides the movie sequence (optional, default Get.php)
** Controls while playing:
**		SetSpeed (duration)		duration = time between pictures
**		Start()		start playing
**		Stop()		stop plaiyng
**		Toggle()	toggle start <--> stop
** Remote call to the server:
**		include file is "movie".php
**		function name is movie_name
** Server reply JSON structure:
**		{ "width" : width,
**		  "height":	height,
**		  "img":	[ array of picture urls ]}
*/

function Movie (parent, arg)	{
	this.ratio		= 0.8;		// transition time part of duration
	this.next_id	= 0;		// next picture index
	this.bot_img	= document.createElement("img");
	this.top_img	= document.createElement("img");
	this.bot_img.style.position = "absolute";
	this.top_img.style.position = "absolute";
	this.running	= false;
	this.parent		= parent;
	parent.appendChild(this.bot_img);
	parent.appendChild(this.top_img);

	this.SetSpeed = function (duration)	{
		this.duration	= duration == null ? 5 : duration;
		this.transition	= this.duration * this.ratio;
		this.fps		= 20 / this.transition;
	}
	this.Change = function (param)	{
		AjaxGet( param.name, this.GetMovieArray.bind(this), param );
		this.SetSpeed( param.duration );
	}
	this.Start = function ()	{
		this.running = true;
	}
	this.Stop = function ()	{
		this.running = false;
	}
	this.Toggle = function ()	{
		this.running = !this.running;
	}
	this.Goto = function (index)	{
		this.Start();
		this.next_id = index % npictures;
		this.Next();
		this.Stop();
	}
	this.GetMovieArray = function (obj)	{
		this.Images = obj.evalJSON();		
		if (this.Images.comment)
			alert(this.Images.comment);
		this.parent.setStyle (eval("({width:'" + this.Images.width + "px'," +
									"height:'" + this.Images.height+ "px'})"));
		if ( ! this.running)
			this.top_img.src = this.Images.img[0];
	}
	this.MovieCallback = function ()	{
		window.setTimeout(this.MovieCallback.bind(this), (this.duration) * 1000);
		if (this.running)
			this.Next();
	}
	this.Next = function ()	{
		var npictures = this.Images.img.length;
		if ( npictures > 0 )	{
			this.top_img.src = this.bot_img.src;
			this.top_img.show();
			this.bot_img.src = this.Images.img[this.next_id];
			this.next_id = ++this.next_id % npictures;
			new Effect.Fade(this.top_img,{duration:this.transition, fps:this.fps});
		}
	}
	this.Change(arg);
	this.MovieCallback();
}

function ChangeHelp ( page )	{
	var url = '<?php echo HELP ?>' + page;
	return AjaxChangeHTML ( 'content', url );
}
function AjaxChangeHTML( selector, url )	{
	return ajax_call( url, false, '', {}, function (mysack) { mysack.onCompletion = function (a) { $(selector ).innerHTML = a }; mysack.element = null; } );
}
function AjaxReload( selector, element, parameter )	{
	return ajax_call( AJAX_URL, false, selector, parameter, function (mysack) { mysack.element = element; } );
}
function AjaxLoad( selector, element, parameter )	{
	if ($(element).innerHTML.length > 1000) return true;
	return ajax_call( AJAX_URL, false, selector, parameter, function (mysack) { mysack.element = element; } );
}
function AjaxGet( selector, callback, parameter )	{
	return ajax_call( AJAX_URL, false, selector, parameter, function (mysack) { mysack.onCompletion = callback; mysack.element = null; } );
}
function AjaxPush( selector, parameter )	{
	return AjaxGet( selector, function (p){ if (p) alert(p); }, parameter );
}
function AjaxRefresh( selector, parameter )	{
	return AjaxLoad( selector, selector, parameter );
}
function AjaxRun( selector, parameter )	{
	return ajax_call( AJAX_URL, true, selector, parameter );
}
function ajax_call( url, execute, selector, parameter, onPrepartion ){
	var mysack = new sack( url );    
	if (execute)
		mysack.execute = 1;
	mysack.setVar( 'selector', selector );
	if ( parameter ) {
		if (hack)
			parameter.hacker = hackarg;
		var key = Object.keys(parameter);
		var val = Object.values(parameter);
		for (var i = 0; i < key.length; ++i)	{
			mysack.setVar( key[i], val[i] );
		}
	}
	mysack.method = 'POST';
	mysack.onError = function() { // alert('AJAX error' ) 
								 };
	if (onPrepartion)	{
		onPrepartion(mysack);
	}
	mysack.runAJAX();
	return true;
}
// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

// getStyleByClass: given an element type, a class selector and a property,
// return the value of the property for that element type.
// args:
//  t - element type
//  c - class identifier
//  p - CSS property
function getStyleByClass(t, c, p) {
	// first loop over elements, because if they've been modified they
	// will contain style data more recent than that in the stylesheet
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					var theStyle = eval('node.style.' + p);
					if((theStyle != "") && (theStyle != null)) {
						return theStyle;
					}
				}
			}
		}		
	}
	// if we got here it's because we didn't find anything
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if((allStyleRules[y] == c) ||
						   (allStyleRules[y] == (t + "." + c))) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) &&
						   ((rules[y].selectorText == c) ||
						    (rules[y].selectorText == (t + "." + c)))) {
							return z[p];
						}
					}
				}
			}
		}
	}
	return null;
}
function Saison (date)	{
	var begin = [[2003,'2002-10-08'],
				 [2004,'2003-10-14'],
				 [2005,'2004-10-12'],
				 [2006,'2005-10-11'],
				 [2007,'2006-10-10'],
				 [2008,'2007-10-09']];
	for (var i = begin.length - 1; i >= 0; --i)	{
		if (date >= begin[i][1])
			return begin[i][0];
	}
	return false;
}
function LatLonInPolygon ( point, polygon )	{
	var j=0;
	var oddNodes = false;
	var x = point.lng();
	var y = point.lat();
	for (var i=0; i < polygon.getVertexCount(); i++) {
		j++;
		if (j == polygon.getVertexCount())	{
			j = 0;
		}
		if (((polygon.getVertex(i).lat() < y)
			 && (polygon.getVertex(j).lat() >= y))
			 || ((polygon.getVertex(j).lat() < y) 
			 && (polygon.getVertex(i).lat() >= y))) {
			if (   polygon.getVertex(i).lng() + (y - polygon.getVertex(i).lat() )
				/ (polygon.getVertex(j).lat() - polygon.getVertex(i).lat())
				* (polygon.getVertex(j).lng() - polygon.getVertex(i).lng()) > x )	{
				oddNodes = !oddNodes;
			}
		}
	}
	return oddNodes;
}
function min ( a, b ) { return ( ( a < b ) ? a : b ); }
function max ( a, b ) { return ( ( a > b ) ? a : b ); }

//alert ('nimbus');