﻿function openWindow(url, width, height, menuBars, reloadOnClose)
{
	var win = window.open(
		url, 
		'poma-popup', 
		'width=' + width + ', height=' + height + ', menubar=' + (menuBars ? 'yes' : 'no')
	);
	/*
	if(reloadOnClose) {
		Event.observe(win, 'unload', function(){ 
			if (!this.loaded) {
				this.loaded = true;
			} else {
				this.opener.location.reload();
			}
		});
	}
	*/
}


function doMassAction()
{
	var submit = true;
	var select = $('selectMassAction');
	var option = select.options[select.selectedIndex];
	
	if(!$F('selectMassAction')) {
		alert('Séléctionnez une action');
		return false;
	}
	
	if(option.hasClassName('confirm')) {
		if(!confirm('Êtes-vous sur ?')) {
			submit = false;
		}
	}
	
	if(submit) {
		$('dataGridForm').submit();
	}
}


function getMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

Diaporama = Class.create({
	
	initialize: function(el)
	{
		this.el = $(el);
		this.current = 0;
		this.init();
	},
	
	init: function()
	{
		this.items = [];
		this.el.getElementsBySelector('li').each(function(li) {
			this.items.push(li);
		}, this);
		
		if(this.items.length) {
			new PeriodicalExecuter(this.next.bind(this), 4);
		}
	},
	
	next: function()
	{
		if(this.current == this.items.length) {
			this.current = 0;
		}
		
		$A(this.items).each(function(item, i) {
			if(i == this.current) {
				item.show();
			} else {
				item.hide();
			}
		}, this)
		this.current++;
	}
	
});

Event.observe(window, 'load', function() {
	$$('a[href$=.jpg]').each(function(el) {
		el.observe('click', window.openPopup.bindAsEventListener(window, el.href));
		
	});
	$$('a[href$=.gif]').each(function(el) {
		el.observe('click', window.openPopup.bindAsEventListener(window, el.href));
		
	});
	/*
	$$('a[rel="popup"]').each(function(el) {
		el.observe('click', window.openPopup.bindAsEventListener(window, el.href));
		
	});
	*/
});

function openPopup(e,url)
{
	e.stop();
	window.open(__baseUrl__  + 'popup.php?url=' + url, '', "width=750, height=550, toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no");
}