var myDelay=0;

function md1(selection) {
	target = selection.options[selection.selectedIndex].value;
		document.getElementById('cfa').style.display="none";
		document.getElementById('autclifin').value="";
		document.getElementById('clientsfinaux').selectedIndex=0;
	if (target=="rf") {
		document.getElementById('representationfiscale').style.display="block";
		document.getElementById('recuperationtva').style.display="none";	
	} else if (target=="rt") {
		document.getElementById('recuperationtva').style.display="block";	
		document.getElementById('representationfiscale').style.display="none";
	} else {
		document.getElementById('recuperationtva').style.display="none";
		document.getElementById('representationfiscale').style.display="none";
	}
}
function reinit(which) {
	if (which=="rf") {
		document.getElementById('representationfiscale').style.display="block";
		document.getElementById('recuperationtva').style.display="none";
	} else if (which=="rt") {
		document.getElementById('recuperationtva').style.display="block";	
		document.getElementById('representationfiscale').style.display="none";
	} else if (which=="at") {
	document.getElementById('cfa').style.display="block";
	}
}

function md2(selection) {
	target = selection.options[selection.selectedIndex].value;
	if (target=="at") {
		document.getElementById('cfa').style.display="block";
	} else {
		document.getElementById('cfa').style.display="none";
		document.getElementById('autclifin').value="";
	}
}

function FocusChamp(BoxName)
{
    if (BoxName.value == BoxName.defaultValue) { BoxName.value = ''; }
}

function BlurChamp(BoxName)
{
    if (BoxName.value == '') { BoxName.value = BoxName.defaultValue; }
}
function showMenu(id){
	document.getElementById('ssm1').style.visibility="hidden";
	document.getElementById('ssm2').style.visibility="hidden";
	document.getElementById('ssm3').style.visibility="hidden";
	if (id!="") {
		document.getElementById(id).style.visibility="visible";
	}
}
function sD(id,boolean) {
	document.getElementById(id).style.display=boolean;
}
function aD(id,boolean) {
	if (boolean) {
		window.clearTimeout(myDelay);
	} else {
		myDelay = setTimeout("sD('"+id+"','none')",100);	
	}
}
function isNumeric(sText){
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++){
	Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1){
			IsNumber = false;
		}
	}
	return IsNumber;
}

var digitsOnly = /[1234567890]/g;
var integerOnly = /[0-9\.+_\-()]/g;

function restrictCharacters(myfield, e, restrictionType) {
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);

	// if they pressed esc... remove focus from field...
	if (code==27) { this.blur(); return false; }
	
	// ignore if they are press other keys
	// strange because code: 39 is the down key AND ' key...
	// and DEL also equals .
	if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
		if (character.match(restrictionType)) {
			return true;
		} else {
			return false;
		}
		
	}
}

function checknewsl(language) {
	if (language=="fr") {
		err1 = 'Veuillez saisir une adresse E-MAIL';
		err2 = 'Veuillez saisir une adresse e-mail VALIDE';
	} else if (language=="uk") {
		err1 = 'Please insert an EMAIL address';
		err2 = 'Please insert a VALID email address';		
	}
	var emailRegEx = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/ ;
	var path=document.fnewsl;
	if (path.email.value=="" || path.email.value==path.email.defaultValue) {
		path.email.focus();
		alert(err1);
		return false;
	} else if (path.email.value.search(emailRegEx)==-1) {
		path.email.focus();
		alert();
		return false;
	} else {
	path.email.value = path.email.value.toLowerCase();
	return true;
}}

function checkstaf(language) {
	if (language=="fr") {
		err1 = 'Veuillez saisir une adresse E-MAIL';
		err2 = 'Veuillez saisir une adresse e-mail VALIDE';
	} else if (language=="uk") {
		err1 = 'Please insert an EMAIL address';
		err2 = 'Please insert a VALID email address';		
	}
	var emailRegEx = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/ ;
	var path=document.fstaf;
	if (path.email.value=="" || path.email.value==path.email.defaultValue) {
		path.email.focus();
		alert(err1);
		return false;
	} else if (path.email.value.search(emailRegEx)==-1) {
		path.email.focus();
		alert(err2);
		return false;
	} else {
	path.stafemail.value = path.stafemail.value.toLowerCase();
	return true;
}}

function checkformuz(language) {
	if (language=="fr") {
		err1 = 'Veuillez saisir une adresse E-MAIL';
		err2 = 'Veuillez saisir une adresse e-mail VALIDE';
		err3 = 'Veuillez cocher une CASE';
	} else if (language=="uk") {
		err1 = 'Please insert an EMAIL address';
		err2 = 'Please insert a VALID email address';		
		err3 = 'Please tick a BOX';
	}
	var emailRegEx = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/ ;
	var path=document.fforms;0
	if (path.choix[0].checked==false && path.choix[1].checked==false) {
		alert(err3);
		return false;
	} else if (path.email.value=="" || path.email.value==path.email.defaultValue) {
		path.email.focus();
		alert(err1);
		return false;
	} else if (path.email.value.search(emailRegEx)==-1) {
		path.email.focus();
		alert(err2);
		return false;
	} else {
	path.email.value = path.email.value.toLowerCase();
	return true;
}}

function tb(number) {
	var path=document.fforms;
	if (number==0) {
		path.choix[0].checked=true;
	} else {
		path.choix[1].checked=true;
	}
}

function checkcontact_fr(boolean) {
	var emailRegEx = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/ ;
	var path=document.formulaire;
	path.mel.value=path.mel.value.toLowerCase();
	 if (path.soc.value=="") {
		path.soc.focus();
		alert('Veuillez saisir une SOCIETÉ');
		return false;
	} else if (path.cp.value!="" && (!isNumeric(path.cp.value) || path.cp.value.length!=5)) {
		path.cp.focus();
		alert('Veuillez saisir un code postal VALIDE');
		return false;
	} else if (path.ctc.value=="") {
		path.ctc.focus();
		alert('Veuillez saisir le NOM DU CONTACT');
		return false;
	} else if (path.tel.value=="") {
		path.tel.focus();
		alert('Veuillez saisir un NUMÉRO DE TÉLÉPHONE');
		return false;
	} else if (path.mel.value=="") {
		path.mel.focus();
		alert('Veuillez saisir une adresse E-MAIL');
		return false;
	} else if (path.mel.value.search(emailRegEx)==-1) {
		path.mel.focus();
		alert('Veuillez saisir une adresse e-mail VALIDE');
		return false;
	} else if (path.demande.selectedIndex==0) {
		alert('Veuillez préciser votre DEMANDE');
		return false;
	} else if (path.security_code.value=="") {
		path.security_code.focus();
		alert('Veuiller saisir le CODE DE SECURITE');
		return false;
	} else {
		if (boolean) {
			return true;
		} else {
			path.submit();
		}
	}
}

function checkcontact_uk(boolean) {
	var emailRegEx = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/ ;
	var path=document.formulaire;
	path.mel.value=path.mel.value.toLowerCase();
	 if (path.soc.value=="") {
		path.soc.focus();
		alert('Please enter a COMPANY');
		return false;
	} else if (path.cp.value!="" && (!isNumeric(path.cp.value) || path.cp.value.length!=5)) {
		path.cp.focus();
		alert('Please enter a VALID postal code');
		return false;
	} else if (path.ctc.value=="") {
		path.ctc.focus();
		alert('Please enter a CONTACT name');
		return false;
	} else if (path.tel.value=="") {
		path.tel.focus();
		alert('Please enter a PHONE NUMBER');
		return false;
	} else if (path.mel.value=="") {
		path.mel.focus();
		alert('Please enter an E-MAIL ADDRESS');
		return false;
	} else if (path.mel.value.search(emailRegEx)==-1) {
		path.mel.focus();
		alert('Please enter a VALID e-mail address');
		return false;
	} else if (path.demande.selectedIndex==0) {
		alert('Please select your INQUIRY');
		return false;
	} else if (path.security_code.value=="") {
		path.security_code.focus();
		alert('Please enter the SECURITY CODE');
		return false;
	} else {
		if (boolean) {
			return true;
		} else {
			path.submit();
		}
	}
}


function actupopup(url,largeur,hauteur) {
	var haut=(screen.height-largeur)/2;
	var gauche=(screen.width-hauteur)/2;
	fencent=window.open(url,'ACTU','top='+haut+',left='+gauche+',width='+largeur+',height='+hauteur+',scrollbars=1,resizable=0,status=1');
	fencent.focus();	
}

function menuderoulant(selection) {
	window.location=selection.options[selection.selectedIndex].value;
}

function reloaded() {
	window.focus();
}
