// JavaScript Document
function toggleCanadaTax(){
	if (window.document.page1.tax_quebec.checked){
		window.document.page1.tax_canada.checked = true;
	}
}

function setPulldown1(theSelect){
	if (theSelect.value != 'choose'){
		if (theSelect.value == 'internet'){
			document.getElementById('selList2_box').style.display='inline';
			document.getElementById('specify_box').style.display='none';
		} else {
			document.getElementById('specify_box').style.display='inline';
			document.getElementById('selList2_box').style.display='none';
		}
	} else {
		document.getElementById('specify_box').style.display='none';
		document.getElementById('selList2_box').style.display='none';
	}
}

function setPulldown2(theSelect)
{
	if (theSelect.value != 'choose'){
		if (theSelect.value == 'autre'){
			document.getElementById('specify_box').style.display='inline';
		} else {
			document.getElementById('specify_box').style.display='none';
		}
	} else {
		document.getElementById('specify_box').style.display='none';
	}
}

function checkPage1(theForm){
	var firstError = null;
	var count 	= 0;
	var why 	= "";
	if (theForm.programme.value != ""){
		count++;
	}
	if (theForm.module.value != "") {
		count++;
	}
	if (theForm.theme.value != ""){
		count++;
	}
	if (theForm.cours.value != ""){
		count++;
	}
	if (theForm.equivalence.value != ""){
		count++;
	}
	
	if (count == 0) {
		why += "- Vous n'avez pas spécifié la formation que vous désirez suivre.\n";
		if (firstError == null) firstError = theForm.programme;
	}
	
	else if (count > 1) {
		why += "- Vous devez choisir une seule formation à la fois.\n";
		if (firstError == null) firstError = theForm.programme;
	}
	
	if (theForm.currency.value != 'can' && theForm.tax_canada.checked ){
		why += "- Les résidants du Canada doivent payer en Dollars Canadiens.\n";
		if (firstError == null) firstError = theForm.currency;
	}
	if (theForm.currency.value == 'can' && theForm.tax_canada.checked == false ){
		why += "- Vous devez demeurer au Canada et payer la GST pour payer en Dollars Canadiens.\n";
		if (firstError == null) firstError = theForm.tax_canada;
	}
	if (theForm.currency.value == ''){
		why += "- Vous devez choisir une devise.\n";
		if (firstError == null) firstError = theForm.currency;
	}
	if (theForm.studyhours.value == ''){
		why += "- Vous n'avez pas spécifié un nombre d'heures d'étude par semaine.\n";
		if (firstError == null) firstError = theForm.studyhours;
	}
	else if (!isValidNumber(theForm.studyhours.value,1,100)){
		why += "- Vous n'avez pas spécifié un nombre d'heures d'étude par semaine valide; veuillez rentrer une valeur entre 1 et 100.\n";
		if (firstError == null) firstError = theForm.studyhours;		
	}
	if (theForm.prenom.value == ''){
		why += "- Vous n'avez pas spécifié votre prénom.\n";
		if (firstError == null) firstError = theForm.prenom;
	}
	if (theForm.nom.value == ''){
		why += "- Vous n'avez pas spécifié votre nom.\n";
		if (firstError == null) firstError = theForm.nom;
	}
	if (!theForm.sexe[0].checked && !theForm.sexe[1].checked){
		why += "- Vous n'avez pas spécifié votre sexe.\n";
		if (firstError == null) firstError = theForm.sexe[0];
	}
	if (theForm.adresse1.value == ''){
		why += "- Vous n'avez pas spécifié votre addresse.\n";
		if (firstError == null) firstError = theForm.addresse1;
	}
	if (theForm.ville.value == ''){
		why += "- Vous n'avez pas spécifié votre ville.\n";
		if (firstError == null) firstError = theForm.ville;
	}
	if (theForm.province.value == ''){
		why += "- Vous n'avez pas spécifié votre province.\n";
		if (firstError == null) firstError = theForm.province;
	}
	if (theForm.pays.value == ''){
		why += "- Vous n'avez pas spécifié votre pays.\n";
		if (firstError == null) firstError = theForm.pays;
	}
	if (theForm.code_postal.value == ''){
		why += "- Vous n'avez pas spécifié votre code postal.\n";
		if (firstError == null) firstError = theForm.code_postal;
	}
	if (theForm.tel_maison.value == ''){
		why += "- Vous n'avez pas spécifié votre telephone maison.\n";
		if (firstError == null) firstError = theForm.tel_maison;
	}
	if (theForm.lieu_naissance.value == ''){
		why += "- Vous n'avez pas spécifié votre lieu de naissance.\n";
		if (firstError == null) firstError = theForm.lieu_naissance;
	}
	if (theForm.profession.value == ''){
		why += "- Vous n'avez pas spécifié votre profession.\n";
		if (firstError == null) firstError = theForm.profession;
	}
	if (theForm.selList1.value == 'choose'){
		why += "- Vous n'avez pas spécifié ou vous avez vu l'annonce du collège .\n";
		if (firstError == null) firstError = theForm.selList1;
	}
	if (theForm.selList1.value == 'internet' && theForm.selList2.value == 'choose'){
		why += "- Vous n'avez pas spécifié la référence Internet.\n";
		if (firstError == null) firstError = theForm.selList2;
	}
	if (document.getElementById('specify_box').style.display=='inline' && document.getElementById('specify_box').value == ''){
		why += "- Vous n'avez pas spécifié la référence.\n";
		if (firstError == null) firstError = document.getElementById('specify_box');
	}
	if (!checkEmail(theForm.courriel.value)){
		why += "- Vous n'avez pas spécifié un courriel valide.\n";
		if (firstError == null) firstError = theForm.courriel;
   	}
	if (theForm.courriel.value != theForm.courriel2.value){
		why += "- Vous n'avez pas rentré la même adresse email deux fois.\n";
		if (firstError == null) firstError = theForm.courriel;
   	}
	if (why != ""){
		errorMsg = "Les erreurs suivantes on été détectées:\n\n" + why;
		alert(errorMsg);
		if (firstError != null) firstError.focus();
		return false;
	}
	return true;
}

function updateCurrencies(locale){
	if (locale.value == 'canada'){
		document.getElementById('locale-canada').style.display='block';
		//document.getElementById('currency').disabled = true;
		document.getElementById('currency').value = 'can';
		document.getElementById('locale-usa').style.display='none';
	} else if (locale.value == 'europe'){
		document.getElementById('locale-canada').style.display='none';
		//document.getElementById('currency').disabled = true;
		document.getElementById('currency').value = 'euro';
		document.getElementById('locale-usa').style.display='none';
	} else if (locale.value == 'usa'){
		document.getElementById('currency').disabled = false;
		document.getElementById('locale-canada').style.display='none';
		document.getElementById('locale-usa').style.display='block';
	}
}
