function y2k(number) {
	return (number < 1000) ? number + 1900 : number;
}

function Annee() {
	today=new Date();
	document.write(y2k(today.getYear()));
}

function BoutonUpDown(DivId, Pos) {
	if (Pos == 'down') {
		document.getElementById(DivId).className = 'bouton_down';
		document.getElementById(DivId).src = 'images/subscribe_down.jpg';
	}
	else {
		document.getElementById(DivId).className = 'bouton_up';
		document.getElementById(DivId).className = 'images/subscribe_up.jpg';
	}
}

function Transmit_Email() {
	var email=document.newsform.textfield.value;
	window.top.location.href ="newsletter.php?email=" + email;
}	

var variables=new Array()

function clear(text) {
	while (text.search(/%20/) != -1) text = text.replace(/%20/," ");
	return text;
}

function cutUrl() {
	var str1 = document.location.search;
	var str2 = str1;
	var pos1 = 1;
	var pos2 = pos1;
	var pos3 = pos1;
	var count = 0;

	while ( (pos2 = str1.indexOf("&", pos1)) != -1 ) {
		str2 = str1.substring(pos1,pos2);
		pos3 = str2.indexOf("=");
		variables[count] = new Array();
		variables[count]["name"] = str2.substring(0,pos3);
		variables[count]["value"] = clear(str2.substring(pos3+1,str2.length));
		pos1 = pos2+1;
		count++;
	}
	pos2 = str1.length;
	str2 = str1.substring(pos1,pos2);
	pos3 = str2.indexOf("=");
	variables[count] = new Array();
	variables[count]["name"] = str2.substring(0,pos3);
	variables[count]["value"] = clear(str2.substring(pos3+1,str2.length));
}

function getHiddens() {
	cutUrl();
	var hiddens = new Array();
	for (var i=0; i < variables.length; i++)
		hiddens[i] = "<input type=\"hidden\" name=\"" + variables[i]["name"] + "\" value=\"" + variables[i]["value"] + "\">";
	return hiddens;
}
	
var hiddens = getHiddens();
for (var i=0; i < hiddens.length; i++) document.write(hiddens[i]);

function Initial() {
	document.mail_form.zone_email.value = variables[0]["value"];
}

function Initial2() {
	param1=variables[0]["value"];
	if (param1 == "") document.mail_form.destinataire.value = "sales";
		else document.mail_form.destinataire.value = param1;
}

function MajSelect(value) {
	document.mail_form.destinataire.value = value;
}

function Go_Homepage() {
	location.href ="http://www.alligone.com/index.html";
}	

function verifSelection() {
	if (document.mail_form.zone_email.value == "") {
		alert('Le champ "Email" n\'a pas été correctement rempli dans le formulaire. Cliquez sur le bouton "OK" pour essayer de nouveau.')
		return false
	}
	invalidChars = " /:,;'"
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (document.mail_form.zone_email.value.indexOf(badChar,0) > -1) {
			alert('Le champ "Email" n\'a pas été correctement rempli dans le formulaire. Cliquez sur le bouton "OK" pour essayer de nouveau.')
			document.mail_form.zone_email.focus()
			return false
		}
	}
	atPos = document.mail_form.zone_email.value.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1) {
		alert('Le champ "Email" n\'a pas été correctement rempli dans le formulaire. Cliquez sur le bouton "OK" pour essayer de nouveau.')
		document.mail_form.zone_email.focus()
		return false
	}

	if (document.mail_form.zone_email.value.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
		alert('Le champ "Email" n\'a pas été correctement rempli dans le formulaire. Cliquez sur le bouton "OK" pour essayer de nouveau.')
		document.mail_form.zone_email.focus()
		return false
	}

	periodPos = document.mail_form.zone_email.value.indexOf(".",atPos)

	if (periodPos == -1) {					// and at least one "." after the "@"
		alert('Le champ "Email" n\'a pas été correctement rempli dans le formulaire. Cliquez sur le bouton "OK" pour essayer de nouveau.')
		document.mail_form.zone_email.focus()
		return false
	}

	if (periodPos+3 > document.mail_form.zone_email.value.length)	{		// must be at least 2 characters after the 
		alert('Le champ "Email" n\'a pas été correctement rempli dans le formulaire. Cliquez sur le bouton "OK" pour essayer de nouveau.')
		document.mail_form.zone_email.focus()
		return false
	}
}
