function S_SortBy(sort, lang)
{

	var ilang;
	ilang = '';
	if ( lang != '' )
		ilang = '&lang='+lang;
	if ( sort == 'n' )
		window.parent.document.location = 'index.php?ml=2'+ilang;
	if ( sort == 'm' )
		window.parent.document.location = 'index.php?ml=2'+ilang+'&cat=-2';
	if ( sort == 'c' )
		window.parent.document.location = 'index.php?ml=2'+ilang+'&cat=-3';

}

function H_SortBy(sort, lang)
{

	var ilang;
	ilang = '';
	if ( lang != '' )
		ilang = '&lang='+lang;
	if ( sort == 'n' )
		window.parent.document.location = 'index.php?ml=3'+ilang;
	if ( sort == 'm' )
		window.parent.document.location = 'index.php?ml=3'+ilang+'&cat=-2';
	if ( sort == 'c' )
		window.parent.document.location = 'index.php?ml=3'+ilang+'&cat=-3';

}


function P_SortBy(sort, lang, type)
{
	var ilang;
	var inews = 0;
	
	ilang = '';
	if (document.tri.afficher[1].checked == true)
		inews = 1;
	if ( lang != '' )
		ilang = '&lang='+lang;
	if ( sort == 'n' )
		window.parent.document.location = 'index.php?ml='+type+ilang+'&news='+inews;
	if ( sort == 'm' )
		window.parent.document.location = 'index.php?ml='+type+ilang+'&cat=-2'+'&news='+inews;
	if ( sort == 'c' )
		window.parent.document.location = 'index.php?ml='+type+ilang+'&cat=-3'+'&news='+inews;
}

function D_SortBy(sort, lang, type)
{

	var ilang;
	ilang = '';
	if ( lang != '' )
		ilang = '&lang='+lang;
	if ( sort == 'n' )
		window.parent.document.location = 'index.php?ml='+type+ilang+'&cat=1';
	if ( sort == 'm' )
		window.parent.document.location = 'index.php?ml='+type+ilang+'&cat=2';
}

function R_SortBy(sort, lang, type)
{
	// Revendeurs
	var ilang;
	ilang = '';
	if ( lang != '' )
		ilang = '&lang='+lang;
	window.parent.document.location = 'index.php?ml='+type+ilang+'&cat=1&sort='+sort;
}

function Choose_Product(liste, lang)
{
	// utilisée dans support.inc
	var ilang = '&lang=12';
	if ( lang != '' )
		ilang = '&lang='+lang;
	var pid;
	pid ='';
	if ( liste.value != -1 )
		pid = '&pid='+liste.value;
	// Modif 07/2004 : SIGNET
	//window.parent.document.location = 'index.php?ml=5'+ilang+pid;
	window.parent.document.location = 'index.php?ml=5'+ilang+pid+'&signet=topline';
}

function Choose_Product_Support(liste, ml, lang)
{
	// utilisée dans besoindaide_us.php
	var ilang = '&lang=12';
	if ( lang != '' )
		ilang = '&lang='+lang;
	var pid;
	pid ='';
	if ( liste.value != -1 )
		pid = '&pid='+liste.value;
	window.parent.document.location = 'index.php?ml='+ml+ilang+pid+'&signet=topform';
}

/*
function Choose_Product_Support(liste, lang)
{
	// utilisée dans support.inc depuis le 20/10/2004
	var ilang = '&lang=12';
	if ( lang != '' )
		ilang = '&lang='+lang;
	var ml_pid;
	ml_pid ='';
	if ( liste.value != -1 )
	{
		if ( liste.value == -2 )
		{
			// On fait comme avant
			var pid;
			pid = '&pid='+liste.value;
			window.parent.document.location = 'index.php?ml=5'+ilang+pid+'&signet=topline';
		}
		else
		{
			// La value de la liste ne contient plus l'id du produt mais le tag POST ml+pid
			ml_pid = liste.value;
			window.parent.document.location = 'index.php?' + ml_pid + '&rub=5' + ilang +'&signet=topline';
		}
	}
}
*/

function Choose_Product_Register(liste, ml, lang)
{
	// utilisée dans register.inc
	var ilang = '&lang=12';
	if ( lang != '' )
		ilang = '&lang='+lang;
	var pid;
	pid ='';
	if ( liste.value != -1 )
		pid = '&pid='+liste.value;
	window.parent.document.location = 'index.php?ml='+ml+ilang+pid;
}

function Choose_Product_Press(liste, ml, cat, lang)
{
	// utilisée dans press_*.inc
	var ilang = '&lang=12';
	if ( lang != '' )
		ilang = '&lang='+lang;
	var pid;
	pid ='';
	if ( liste.value != -1 )
		pid = '&pidpress='+liste.value;
	window.parent.document.location = 'index.php?ml='+ml+'&cat='+cat+ilang+pid;
}

function emailCheck (emailStr)
{
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	
	// Modif MV 11-07-2008 : pas de vérif de domaine
	//var checkTLD=1;
	var checkTLD=0;
	
	/* The following is the list of known TLDs that an e-mail address must end with. */
	
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	
	var emailPat=/^(.+)@(.+)$/;
	
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	
	var validChars="\[^\\s" + specialChars + "\]";
	
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	
	var quotedUser="(\"[^\"]*\")";
	
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	/* The following string represents an atom (basically a series of non-special characters.) */
	
	var atom=validChars + '+';
	
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	
	var word="(" + atom + "|" + quotedUser + ")";
	
	// The following pattern describes the structure of the user
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null)
	{
	
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		
		//alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];
	
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	
	for (i=0; i<user.length; i++)
	{
		if (user.charCodeAt(i)>127)
		{
			//alert("The username contains invalid characters.");
			return false;
		}
	}
	
	for (i=0; i<domain.length; i++)
	{
		if (domain.charCodeAt(i)>127)
		{
			//alert("The domain name contains invalid characters.");
			return false;
		}
	}

	// See if "user" is valid 
	
	if (user.match(userPat)==null)
	{
		// user is not valid
		//alert("The username doesn't seem to be valid.");
		return false;
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		// this is an IP address
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
				//alert("Destination IP address is invalid!");
				return false;
		   	}
		}
		return true;
	}

	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1)
		{
			//alert("The domain name does not seem to be valid.");
			return false;
		}
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
	{
		//alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	
	// Make sure there's a host name preceding the domain.
	
	if (len<2)
	{
		//alert("This address is missing a hostname!");
		return false;
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}

function check_form_support()
{
	// Utilisée dans form_support.inc
	var todisable = false;
	if ( document.mail.nom.value == "" ||
 		 !emailCheck (document.mail.email.value) ||
		 document.mail.msg.value.length==0 )
		todisable = true;
	if ( todisable && document.mail.btn_send.disabled == false)
	{
		document.mail.btn_send.style.cursor = "default";
		document.mail.btn_send.disabled = true;
	}
	if ( !todisable && document.mail.btn_send.disabled == true)
	{
		document.mail.btn_send.style.cursor = "hand";
		document.mail.btn_send.disabled = false;
	}
	// Touches clavier
	if ( window.event.keyCode == 13 )
	{
		if ( window.event.srcElement.name == "nom" )
			document.mail.prenom.focus();
		if ( window.event.srcElement.name == "prenom" )
			document.mail.adresse.focus();
		if ( window.event.srcElement.name == "adresse" )
			document.mail.cp.focus();
		if ( window.event.srcElement.name == "cp" )
			document.mail.ville.focus();
		if ( window.event.srcElement.name == "ville" )
			document.mail.pays.focus();
		if ( window.event.srcElement.name == "pays" )
			document.mail.email.focus();
		if ( window.event.srcElement.name == "email" )
			document.mail.msg.focus();
	}
}

function check_form_contact()
{
	// Utilisée dans form_contacts.inc
	var todisable = false;
	if ( document.mail.nom.value == "" ||
		 document.mail.prod_list.value == -1 ||
		 !emailCheck (document.mail.email.value) ||
		 document.mail.msg.value.length==0 )
		todisable = true;
	if ( todisable && document.mail.btn_send.disabled == false)
	{
		document.mail.btn_send.style.cursor = "default";
		document.mail.btn_send.disabled = true;
	}
	if ( !todisable && document.mail.btn_send.disabled == true)
	{
		document.mail.btn_send.style.cursor = "hand";
		document.mail.btn_send.disabled = false;
	}
	// Liste
	if ( window.event.srcElement.name == "prod_list" )
		document.mail.nom.focus();
	// Touches clavier
	if ( window.event.keyCode == 13 )
	{
		if ( window.event.srcElement.name == "nom" )
			document.mail.prenom.focus();
		if ( window.event.srcElement.name == "prenom" )
			document.mail.adresse.focus();
		if ( window.event.srcElement.name == "adresse" )
			document.mail.cp.focus();
		if ( window.event.srcElement.name == "cp" )
			document.mail.ville.focus();
		if ( window.event.srcElement.name == "ville" )
			document.mail.pays.focus();
		if ( window.event.srcElement.name == "pays" )
			document.mail.email.focus();
		if ( window.event.srcElement.name == "email" )
			document.mail.msg.focus();
	}

}

function check_form_send_fiche(formulaire)
{
	// Utilisée dans send_prod_email.php
	
	var todisable = false;
	if (!emailCheck (formulaire.email.value))
		todisable = true;
	
	if ( todisable && formulaire.btn_send.disabled == false)
	{
		formulaire.btn_send.style.cursor = "default";
		formulaire.btn_send.disabled = true;
	}
	if ( !todisable && formulaire.btn_send.disabled == true)
	{
		formulaire.btn_send.style.cursor = "hand";
		formulaire.btn_send.disabled = false;
	}
}

function check_pid_cat(form)
{
	alert(form.name);
	alert(form.value);
}

function check_form_formation()
{
	// Utilisée dans form_formation.inc
	var todisable = false;
	if ( document.mail.nom.value == "" ||
		 !emailCheck (document.mail.email.value) ||
		 document.mail.msg.value.length==0 )
		todisable = true;
	if ( todisable && document.mail.btn_send.disabled == false)
	{
		document.mail.btn_send.style.cursor = "default";
		document.mail.btn_send.disabled = true;
	}
	if ( !todisable && document.mail.btn_send.disabled == true)
	{
		document.mail.btn_send.style.cursor = "hand";
		document.mail.btn_send.disabled = false;
	}
	
	// Touches clavier
	if ( window.event.keyCode == 13 )
	{
		if ( window.event.srcElement.name == "nom" )
			document.mail.prenom.focus();
		if ( window.event.srcElement.name == "prenom" )
			document.mail.adresse.focus();
		if ( window.event.srcElement.name == "adresse" )
			document.mail.cp.focus();
		if ( window.event.srcElement.name == "cp" )
			document.mail.ville.focus();
		if ( window.event.srcElement.name == "ville" )
			document.mail.pays.focus();
		if ( window.event.srcElement.name == "pays" )
			document.mail.email.focus();
		if ( window.event.srcElement.name == "email" )
			document.mail.msg.focus();
	}
}

function check_form_register(bSerialRequired, bSerialPresent)
{
	// Utilisée dans form_register.inc
	var todisable = false;
	if ( bSerialRequired )
	{
		if ( document.mail.nom.value == "" ||
			document.mail.prenom.value == "" || 
			document.mail.adresse.value == "" || 
			document.mail.cp.value == "" || 
			document.mail.ville.value == "" || 
			document.mail.pays.value == "" || 
		 	!emailCheck (document.mail.email.value) || 
			document.mail.buy_date.value == "" || 
			document.mail.shop.value == "" || 
			document.mail.serial.value == "")
			todisable = true;
	}
	else
	{
		if ( document.mail.nom.value == "" || 
			document.mail.prenom.value == "" || 
			document.mail.adresse.value == "" || 
			document.mail.cp.value == "" || 
			document.mail.ville.value == "" || 
			document.mail.pays.value == "" || 
			document.mail.buy_date.value == "" || 
			document.mail.shop.value == "" || 
   			!emailCheck (document.mail.email.value) )
			todisable = true;
	}
	if ( todisable && document.mail.btn_send.disabled == false)
	{
		document.mail.btn_send.style.cursor = "default";
		document.mail.btn_send.disabled = true;
	}
	if ( !todisable && document.mail.btn_send.disabled == true)
	{
		document.mail.btn_send.style.cursor = "hand";
		document.mail.btn_send.disabled = false;
	}
/*
	if ( window.event.keyCode == 13 )
	{
		if ( window.event.srcElement.name == "nom" )
			document.mail.prenom.focus();
		if ( window.event.srcElement.name == "prenom" )
			document.mail.adresse.focus();
		if ( window.event.srcElement.name == "adresse" )
			document.mail.cp.focus();
		if ( window.event.srcElement.name == "cp" )
			document.mail.ville.focus();
		if ( window.event.srcElement.name == "ville" )
			document.mail.pays.focus();
		if ( window.event.srcElement.name == "pays" )
			document.mail.email.focus();
		if ( bSerialPresent )
		{
			if ( window.event.srcElement.name == "email" )
				document.mail.serial.focus();
			if ( window.event.srcElement.name == "serial" )
				document.mail.buy_date.focus();
		}
		else
		{
			if ( window.event.srcElement.name == "email" )
				document.mail.buy_date.focus();
		}
		if ( window.event.srcElement.name == "buy_date" )
			document.mail.shop.focus();

	}
*/
}

function checkmailok()
{

	// Utilisée dans form_downloads.php
	var todisable = false;
	if ( document.mail.nom.value == "" || !emailCheck (document.mail.email.value) )
		todisable = true;
	if ( todisable && document.mail.btn_send.disabled == false)
	{
		document.mail.btn_send.style.cursor = "default";
		document.mail.btn_send.disabled = true;
	}
	if ( !todisable && document.mail.btn_send.disabled == true)
	{
		document.mail.btn_send.style.cursor = "hand";
		document.mail.btn_send.disabled = false;
	}
	// Touches clavier
	if ( window.event.keyCode == 27 )
		window.close();
	if ( window.event.keyCode == 13 )
	{
		if ( window.event.srcElement.name == "nom" )
			document.mail.prenom.focus();
		if ( window.event.srcElement.name == "prenom" )
			document.mail.adresse.focus();
		if ( window.event.srcElement.name == "adresse" )
			document.mail.cp.focus();
		if ( window.event.srcElement.name == "cp" )
			document.mail.ville.focus();
		if ( window.event.srcElement.name == "ville" )
			document.mail.pays.focus();
		if ( window.event.srcElement.name == "pays" )
			document.mail.email.focus();
	}
}	

function checksend(textinput)
{
	// utilisée dans search.inc
	if ( textinput.value == "" )
	{
		if ( !document.f_search.b_send.disabled )
		{
			document.f_search.b_send.disabled = true;
			document.f_search.b_send.style.cursor = "default";
		}
	}
	else
	{
		if ( document.f_search.b_send.disabled )
		{
			document.f_search.b_send.disabled = false;
			document.f_search.b_send.style.cursor = "hand";
		}
	}
	return true;
}

function submit_quick_search(form, lang)
{
	var hlang ='';
	var txt;
	var txt_search = form.search.value;
	if ( txt_search == '' )
		return false;
	var re1;
	var re2;
	var re3;
	if ( lang == '' )
		hlang = '&lang=12';
	else
		hlang = '&lang='+lang;
	txt = form.search.value;
	re1 = new RegExp("&","gi");
	txt_search  = txt.replace(re1, "%26");
	re2 = new RegExp("'","gi");
	txt_search  = txt_search.replace(re2, "%27");
	re3 = new RegExp("\"","gi");
	txt_search  = txt_search.replace(re3, "%22");
	// Ajout mode ( AND / OR )
	var s_mode = '&mode=and';
	/*
	var i;
	for (i=0; i<2; i++)
	{
		if ( form.s_mode[i].value == "or" && form.s_mode[i].checked )
			s_mode = '&mode=or';
	}
	*/
	window.parent.document.location = 'index.php?ml=8'+hlang+'&search='+txt_search+s_mode;
}

function submit_search(form, lang)
{
	var hlang ='';
	var txt;
	var txt_search = form.search.value;
	if ( txt_search == '' )
		return false;
	var re1;
	var re2;
	var re3;
	if ( lang == '' )
		hlang = '&lang=12';
	else
		hlang = '&lang='+lang;
	txt = form.search.value;
	re1 = new RegExp("&","gi");
	txt_search  = txt.replace(re1, "%26");
	re2 = new RegExp("'","gi");
	txt_search  = txt_search.replace(re2, "%27");
	re3 = new RegExp("\"","gi");
	txt_search  = txt_search.replace(re3, "%22");
	// Ajout mode ( AND / OR )
	var s_mode = '&mode=and';
	var i;
	for (i=0; i<2; i++)
	{
		if ( form.s_mode[i].value == "or" && form.s_mode[i].checked )
			s_mode = '&mode=or';
	}

	window.parent.document.location = 'index.php?ml=8'+hlang+'&search='+txt_search+s_mode;
}

function Choose_Search(mode)
{
	var i;
	var form = document.f_search;
	form.all.item("sp_and").style.textDecorationUnderline = false;
	form.all.item("sp_or").style.textDecorationUnderline = false;
	form.all.item("in_and").checked = false;
	form.all.item("in_or").checked = false;

	if ( mode == 'and' )
	{
		form.all.item("in_and").checked = true;
		form.all.item("sp_and").style.textDecorationUnderline = true;
	}
	else
	{
		form.all.item("in_or").checked = true;
		form.all.item("sp_or").style.textDecorationUnderline = true;
	}
/*
	for (i=0; i<2; i++)
	{
		if ( form.s_mode[i].value == mode  )
		{
			form.s_mode[i].checked = true;
			form.all.item("sp_and").style.textDecorationUnderline = true;
		}
	}
*/
}

function ShowDownload(item, type, lang)
{
	// MODIF 04/2004 pour enlever le formulaire d'enregistrement pour les téléchargements
/*	
	var taillex;
	var tailley;
	var ntop;
	var nleft;

	var w = 600;
	var h = 320;

	if (navigator.appName=="Microsoft Internet Explorer")
	{
		tailley = screen.height;
		taillex = screen.width;
	}
	else
	{
		tailley = window.screen.height;
		taillex = window.screen.width;
	}

	ntop = (tailley -h)/2;
	nleft = (taillex -w)/2;
	if ( ntop <0 )
		ntop=0;
	if ( nleft <0 )
		nleft=0;
	window.open('form_downloads.php?item='+item+'&type='+type+'&lang='+lang,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+(w+30)+',height='+(h+30)+',top='+ntop+',left='+nleft);
*/
	var taillex;
	var tailley;
	var ntop;
	var nleft;

	var w = 600;
	//var h = 170;
	var h = 190;

	if (navigator.appName=="Microsoft Internet Explorer")
	{
		tailley = screen.height;
		taillex = screen.width;
	}
	else
	{
		tailley = window.screen.height;
		taillex = window.screen.width;
	}

	ntop = (tailley -h)/2;
	nleft = (taillex -w)/2;
	if ( ntop <0 )
		ntop=0;
	if ( nleft <0 )
		nleft=0;
	
	//window.parent.document.location = 'scripts/force_download_file.php?item='+item+'&type='+type+'&lang='+lang;
	window.open('do_downloads.php?item='+item+'&type='+type+'&lang='+lang,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+(w+30)+',height='+(h+30)+',top='+ntop+',left='+nleft);
}

//function ShowBrand(brand,lang,heightlogo)
function ShowBrand(brand,lang)
{
	//alert ('type = ' + type + '\n' + 'item = ' + item);
	var taillex;
	var tailley;
	var ntop;
	var nleft;

	var w = 400;
	var h = 150;
	//var h = heightlogo;

	if (navigator.appName=="Microsoft Internet Explorer")
	{
		tailley = screen.height;
		taillex = screen.width;
	}
	else
	{
		tailley = window.screen.height;
		taillex = window.screen.width;
	}

	ntop = (tailley -h)/2;
	nleft = (taillex -w)/2;
	if ( ntop <0 )
		ntop=0;
	if ( nleft <0 )
		nleft=0;

	window.open('ShowBrand.php?brand='+brand+'&lang='+lang,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+(w+30)+',height='+(h+30)+',top='+ntop+',left='+nleft);

}

function DoDownloadAuto(filetodownload)
{
	//window.open('do_download_real.php?fic='+ filetodownload,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+(w+30)+',height='+(h+30)+',top='+ntop+',left='+nleft);	
	window.open('do_downloads_real.php?fic='+ filetodownload,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=10,height=10,top=10,left=10');	
}