/* auteur: DarK-MooS */

function rediriger (page)
{
	if (page != "")
		location.href=page;
	else
		location.href="index.php";
}

function retour()
{
	history.go (-1);
}

function refresh ()
{
	document.location.reload();
	return(false);
}

function test_formulaire (form, start_str, tab_champ, tab_msg, nb_val)
{	
	if (form != "" && nb_val > 0)
	{			
		j = 0;
		k = 0;
		str = start_str;	
		
		while (j < nb_val)
		{
			if (eval('document.'+form+'.'+tab_champ[j]+'.value') == "")
			{
				str += "- "+tab_msg[j]+"\n";
				k++;		
			}	
			j++;
		}		
		
		if (k > 0)
			alert (str);
		else
			valid_form(form);		
	}
}	

function valid_form(form)
{	
	if (form != "")
	{
		eval ('document.' + form + '.submit()');		
	}
}

function close_window()
{
	window.close();
}

function set_div_size (div_name, width, height)
{
	domok = document.getElementById;
	if (domok)
	{
		skn = document.getElementById(div_name);		
		skn.style.width = width;
		skn.style.height = height;
		
	}
}

function insertion(repdeb, repfin, formul, elem) 
{
	var input = eval ("document."+formul+"."+elem);
	input.focus();
  
  	// pour l'Explorer Internet 
	if(typeof document.selection != 'undefined') 
	{
		// Insertion du code de formatage 
		var range = document.selection.createRange();
		var insText = range.text;
		range.text = repdeb + insText + repfin;
		// Ajustement de la position du curseur
		range = document.selection.createRange();
		if (insText.length == 0) 
		{
			range.move('character', -repfin.length);
		} 
		else 
		{
			range.moveStart('character', repdeb.length + insText.length + repfin.length);
		}
		range.select();
	}
	// pour navigateurs plus récents basés sur Gecko
	else if(typeof input.selectionStart != 'undefined')
	{
		// Insertion du code de formatage 
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		input.value = input.value.substr(0, start) + repdeb + insText + repfin + input.value.substr(end);
		// Ajustement de la position du curseur 
		var pos;
		if (insText.length == 0) 
		{
			pos = start + repdeb.length;
		} 
		else 
		{
			pos = start + repdeb.length + insText.length + repfin.length;
    	}
		input.selectionStart = pos;
		input.selectionEnd = pos;
	}
	// pour les autres navigateurs 
	else
	{
		// requête de la position d'insertion 
		var pos;
		var re = new RegExp('^[0-9]{0,3}$');
		while(!re.test(pos)) 
		{
			pos = prompt("Insertion à la position (0.." + input.value.length + "):", "0");
		}
		if(pos > input.value.length) 
		{
			pos = input.value.length;
		}
		// Insertion du code de formatage 
		var insText = prompt("Veuillez entrer le texte à formater:");
		input.value = input.value.substr(0, pos) + repdeb + insText + repfin + input.value.substr(pos);
	}
}

function change_img (form, field, div_name, num, tab_img, tab_name)
{
	domok = document.getElementById;
	if (domok)
	{
		skn = document.getElementById(div_name);
		num_select = eval ('document.'+form+'.'+field+'.selectedIndex');
		
		if (tab_img[num][num_select] == "" && tab_name[num][num_select] != "")
		{
			skn.innerHTML = "No picture for : "+tab_name[num][num_select];
	  		skn.style.background = "";
		}
		else
		{
			if (tab_name[num][num_select] != "")
			{
				skn.innerHTML = tab_name[num][num_select];
	  			skn.style.background = "transparent url("+tab_img[num][num_select]+") no-repeat center top";
			}
			else
			{
				skn.innerHTML = "";
	  			skn.style.background = "";
			}
		}		
	}
}

function change_url_and_valid_form (form, url)
{
	if (url != "" && form != "")
	{
		eval('document.'+form+'.action=\"'+url+'\"');
		valid_form (form);		
	}
}

function close_window_pop() 
{
	if (ladate.getSeconds() > 0 || ladate.getMinutes() > 0 || ladate.getSeconds() > 0)
	{
		ladate.setSeconds(ladate.getSeconds() - 1);
	}
	
	var hours = ladate.getHours();
	var minutes = ladate.getMinutes();
	var seconds = ladate.getSeconds();

	if (signal_close == 1 && hours <= 0 && minutes <= 0 && seconds <= 0)
	{
		fenetre_pop.document.form_load.pourcent_load.value = "100%";
		fenetre_pop.close();
	}
	else
	{
		if (signal_close == 0 && hours <= 0 && minutes <= 0 && seconds <= 0)
		{
			fenetre_pop.document.form_load.pourcent_load.value = "99%";		
		}
		else
		{
			next_update--;
			count_time++;
			if (next_update <= 0)
			{
				pourcent = Math.round((count_time/total_time)*100);
				if (pourcent >= 100)
					pourcent = 99;
				fenetre_pop.document.form_load.pourcent_load.value = pourcent+"%";
				/* Réinitialiser */
				next_update = Math.round(Math.random(0)*2) + 1;
			}
		}
			
		setTimeout('close_window_pop()',1000);
	}
}

function close_window_pop_refresh() 
{
	if (ladate.getSeconds() > 0 || ladate.getMinutes() > 0 || ladate.getSeconds() > 0)
	{
		ladate.setSeconds(ladate.getSeconds() - 1);
	}
	
	var hours = ladate.getHours();
	var minutes = ladate.getMinutes();
	var seconds = ladate.getSeconds();
	
	if (signal_close == 1 && hours <= 0 && minutes <= 0 && seconds <= 0)
	{
		fenetre_pop.document.form_load.pourcent_load.value = "100%";
		fenetre_pop.close();
		refresh ();
	}
	else
	{
		if (signal_close == 0 && hours <= 0 && minutes <= 0 && seconds <= 0)
		{
			fenetre_pop.document.form_load.pourcent_load.value = "99%";		
		}
		else
		{
			next_update--;
			count_time++;
			if (next_update <= 0)
			{
				pourcent = Math.round((count_time/total_time)*100);
				if (pourcent >= 100)
					pourcent = 99;
				fenetre_pop.document.form_load.pourcent_load.value = pourcent+"%";
				/* Réinitialiser */
				next_update = Math.round(Math.random(0)*2) + 1;
			}
		}
			
		setTimeout('close_window_pop_refresh()',1000);
	}
}

function close_window_pop_redirect() 
{
	if (ladate.getSeconds() > 0 || ladate.getMinutes() > 0 || ladate.getSeconds() > 0)
	{
		ladate.setSeconds(ladate.getSeconds() - 1);
	}
	
	var hours = ladate.getHours();
	var minutes = ladate.getMinutes();
	var seconds = ladate.getSeconds();
	
	if (signal_close == 1 && hours <= 0 && minutes <= 0 && seconds <= 0)
	{
		fenetre_pop.document.form_load.pourcent_load.value = "100%";
		fenetre_pop.close();
		rediriger (url_redirect);
	}
	else
	{
		if (signal_close == 0 && hours <= 0 && minutes <= 0 && seconds <= 0)
		{
			fenetre_pop.document.form_load.pourcent_load.value = "99%";		
		}
		else
		{
			next_update--;
			count_time++;
			if (next_update <= 0)
			{
				pourcent = Math.round((count_time/total_time)*100);
				if (pourcent >= 100)
					pourcent = 99;
				fenetre_pop.document.form_load.pourcent_load.value = pourcent+"%";
				/* Réinitialiser */
				next_update = Math.round(Math.random(0)*2) + 1;
			}
		}
			
		setTimeout('close_window_pop_redirect()',1000);
	}
}

function open_window_content (content, name, width, height, left, top, toolbar, location, directories, status, scrollbars, resizable, copyhistory)
{
	fenetre = window.open("", name, "toolbar="+toolbar+", location="+location+", directories="+directories+", status="+status+", scrollbars="+scrollbars+", resizable="+resizable+", copyhistory="+copyhistory+", width="+width+", height="+height+", left="+left+", top="+top+"");
	fenetre.document.write(content);
	fenetre.document.close();
	return fenetre;
}

function open_special_window_content (img, content, name, width, height, left, top, toolbar, location, directories, status, scrollbars, resizable, copyhistory)
{
	if (img != '')
		content_img = '<img src="'+img+'" alt="'+img+'" align="center">';
	else
		content_img = '';
	content_final = content + '<form name="form_load"><input size="3" name="pourcent_load" value="0%" DISABLED></form>' + content_img;
	return open_window_content (content_final, name, width, height, left, top, toolbar, location, directories, status, scrollbars, resizable, copyhistory);
}

function change_url_form(url, form, field)
{
	if (url != "" && form != "" && field != "")
	{
		val = eval ('document.'+form+'.'+field+'.value');	
		eval('document.'+form+'.action=\"'+url+val+'\"');
		valid_form(form);
	}
}

function change_url_form_simple(url, form, blank)
{
	if (url != "" && form != "")
	{
		if (blank == 1)
			eval('document.'+form+'.target=\"_blank\"');
		else
			eval('document.'+form+'.target=\"\"');
			
		eval('document.'+form+'.action=\"'+url+'\"');
	}
}

function refresh_parent_windows ()
{
	window.opener.document.location.reload();
}

function open_fenetre_msg(message, name, width, height, left, top, toolbar, location, directories, status, scrollbars, resizable, copyhistory)
{
	fenetre = window.open("", name, "toolbar="+toolbar+", location="+location+", directories="+directories+", status="+status+", scrollbars="+scrollbars+", resizable="+resizable+", copyhistory="+copyhistory+", width="+width+", height="+height+", left="+left+", top="+top+"");
	fenetre.document.write(message);
	fenetre.document.close();
}
