var cookie_time = 1; /* en jours. */
var underit_urls = new Array();     
var underit_c_name_check = 'underit';                                                                  
var underit_c_name = 'underit_stats'; 
var underit_width = screen.width;  /* vous pouvez mettre une valeur en pixels. Ex: 800 */      
var underit_height = screen.height;  /* vous pouvez mettre une valeur en pixels. Ex: 500 */

function underit_win(url)
{
    var under = window.open(url,'','width=' +  underit_width + ',height=' + underit_height + ',scrollbars=1,resizable=1,toolbar=0,location=1,menubar=0,status=0,directories=0');
    if (under)
    {
	    under.blur();
	    focus();
    }
}
function underit_init()
{    
	var index = 0;
	var count = 1;
	init = false;
	var cookie = getCookie(underit_c_name);	
	if (cookie != null && cookie != '')
	{
		var tab = cookie.split('|')
		if (tab.length > 1)
		{
			total = parseInt(tab[0]);
			cookie = (total+1) + '|';
			var values = tab[1].split(',');
			var index = 0;
			for (var y = 0; y < values.length; y++)
			{ 
				if (values[y] != '')
				{             
					var tmp = values[y].split(':');
					value = parseInt((tmp[1]*100)/total);
					if (value < underit_urls[tmp[0]][1] && index == 0)
					{         
						index = tmp[0]; 
						count = parseInt(tmp[1])+1;
						cookie += y+':'+count+',';						
					} else { cookie += y+':'+tmp[1]+','; } 
				}
			}                                             
		} else { init = true; }
	} else { init = true; }
	if (init == true)
	{                               
		cookie = '1|'+index+':' + count +',';
		for (var y = 1; y < underit_urls.length; y++) cookie += y+':0,';
	}      
	if (underit_urls[index])
	{
		setCookie(underit_c_name_check, 'yes', cookie_time);
		setCookie(underit_c_name, cookie);
		return { url : underit_urls[index][0], index : index, count : count }
	}
	return;
}
function underit()
{
	var cookie = getCookie(underit_c_name_check);
	if (cookie != 'yes')
	{
		infos = underit_init();
		underit_win(infos.url);  
	}
}
function setCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

