function autoSelectInquiry()
{
	showDiv(0);
	var iType
	iType=document.location.search;
	iType=iType.substring(7,iType.length)
	if ((iType>0)&&(iType<(document.forms['EmailForm'].InquiryTypeDropDown.length)))
	{
		document.forms['EmailForm'].InquiryTypeDropDown.options[iType].selected=true;
		for (var i=0; i < document.forms['EmailForm'].InquiryTypeDropDown.length;i++)
		{
			if ((document.forms['EmailForm'].InquiryTypeDropDown.options[i].value)==iType)
			{
				document.forms['EmailForm'].InquiryTypeDropDown.options[iType].selected=true;
				showDiv(iType);
			}
		}
	}
	document.EmailForm.InquiryTypeDropDown.selectedIndex=0;
}

function resetStyle(fldName)
{
	fldName = "lbl" + fldName;
	//alert(fldName);
	document.getElementById(fldName).style.color="black";
	document.getElementById(fldName).style.fontWeight="normal";
}

function requireField(fldName)
{
	document.getElementById('lbl' + fldName).style.color="red";
	document.getElementById('lbl' + fldName).style.fontWeight="bold";
	flag = false;
}

function displayAttachmentInput()
{
	document.getElementById("dependent-upload-link").style.display = 'none';
	document.getElementById("dependent-upload").style.display = 'block';
}

function showDiv(optionValue)
{
	//Reset Styles
	resetStyle("FirstName");
	resetStyle("LastName");
	resetStyle("JobTitle");
	resetStyle("EmailAddress");
	resetStyle("PhoneNumber");
	resetStyle("AccountNumber")
	resetStyle("OrgType")
	resetStyle("PostalCode")
	resetStyle("InquiryOther");
	resetStyle("InquiryDescription");
	resetStyle("InquiryOther2");
	resetStyle("DescriptionOfRequest");
	resetStyle("Attachment")

	// first hide all dependent divs
	document.getElementById("dependent-inquiry-other").style.display = 'none';
	document.getElementById("Inquiry-Details-Fieldset").style.display = 'none';
	document.getElementById("dependent-inquiry-description").style.display = 'none';
	document.getElementById("dependent-inquiry-other2").style.display = 'none';
	document.getElementById("dependent-upload-link").style.display = 'none';
	document.getElementById("dependent-upload").style.display = 'none';
	document.getElementById("Contact-Method-Fieldset").style.display = 'none';
	document.getElementById("Submit-Buttons").style.display = 'none';
	document.EmailForm.InquiryDescriptionDropDown.selectedIndex=0;

	var inqDesc = document.EmailForm.InquiryDescriptionDropDown;

	switch (optionValue)
	{
		//Customer Service
		case "1":
			window.document.EmailForm.FormType.value="1";

			inqDesc.length=1;
			inqDesc.options[inqDesc.options.length] = new Option('Compte','Compte');
			inqDesc.options[inqDesc.options.length] = new Option('Mot de passe Mon compte','Mot de passe Mon compte');
			inqDesc.options[inqDesc.options.length] = new Option('Abonnement','Abonnement');
			inqDesc.options[inqDesc.options.length] = new Option('Facturation','Facturation');
			inqDesc.options[inqDesc.options.length] = new Option('Expédition','Expédition');
			inqDesc.options[inqDesc.options.length] = new Option('Autre','Autre');
			break

		//Orders & Product Information
		case "2":
			window.document.EmailForm.FormType.value="2";

			inqDesc.length=1;
			inqDesc.options[inqDesc.options.length] = new Option('Commande','Commande');
			inqDesc.options[inqDesc.options.length] = new Option('Renseignements sur un produit','Renseignements sur un produit');
			inqDesc.options[inqDesc.options.length] = new Option('Autre','Autre');
			break

		//Claims
		case "4":
			window.document.EmailForm.FormType.value="4";

			inqDesc.length=1;
			inqDesc.options[inqDesc.options.length] = new Option('Suivi d\'une commande','Suivi d\'une commande');
			inqDesc.options[inqDesc.options.length] = new Option('Produit endommagé','Produit endommagé');
			inqDesc.options[inqDesc.options.length] = new Option('Produit manquant','Produit manquant');
			inqDesc.options[inqDesc.options.length] = new Option('Mauvais produit reçu','Mauvais produit reçu');
			inqDesc.options[inqDesc.options.length] = new Option('Autre','Autre');
			break

		//Address Changes
		case "5":
			window.document.EmailForm.FormType.value="5";

			inqDesc.length=1;
			inqDesc.options[inqDesc.options.length] = new Option('Déménagement - compagnie','Déménagement - compagnie');
			inqDesc.options[inqDesc.options.length] = new Option('Déménagement - personne','Déménagement - personne');
			inqDesc.options[inqDesc.options.length] = new Option('Correction d\'une adresse','Correction d\'une adresse');
			inqDesc.options[inqDesc.options.length] = new Option('Autre','Autre');
			break

		//Technical Support
		case "6":
			window.document.EmailForm.FormType.value="6";

			inqDesc.length=1;
			inqDesc.options[inqDesc.options.length] = new Option('Problèmes d\'accès','Problèmes d\'accès');
			inqDesc.options[inqDesc.options.length] = new Option('Problèmes d\'impression','Problèmes d\'impression');
			inqDesc.options[inqDesc.options.length] = new Option('Installation/téléchargement','Installation/téléchargement');
			inqDesc.options[inqDesc.options.length] = new Option('Dépannage','Dépannage');
			inqDesc.options[inqDesc.options.length] = new Option('Autre','Autre');
			break

		//Reference Support
		case "7":
			window.document.EmailForm.FormType.value="7";

			inqDesc.length=1;
			inqDesc.options[inqDesc.options.length] = new Option('Contenu d\'un cédérom','Contenu d\'un cédérom');
			inqDesc.options[inqDesc.options.length] = new Option('Contenu d\'un service en ligne','Contenu d\'un service en ligne');
			inqDesc.options[inqDesc.options.length] = new Option('Contenu d\'un ouvrage imprimé','Contenu d\'un ouvrage imprimé');
			inqDesc.options[inqDesc.options.length] = new Option('Autre','Autre');
			break

		//Cancellations
		case "8":
			window.document.EmailForm.FormType.value="8";

			inqDesc.length=1;
			inqDesc.options[inqDesc.options.length] = new Option('Politique d\'annulation','Politique d\'annulation');
			inqDesc.options[inqDesc.options.length] = new Option('Renouvellement d\'abonnement','Renouvellement d\'abonnement');
			inqDesc.options[inqDesc.options.length] = new Option('Autorisation de retour','Autorisation de retour');
			inqDesc.options[inqDesc.options.length] = new Option('Annulation d\'abonnement','Annulation d\'abonnement');
			inqDesc.options[inqDesc.options.length] = new Option('Autre','Autre');
			break

		//Westlaw eCARSWELL
		case "9":
			window.document.EmailForm.FormType.value="9";

			inqDesc.length=1;
			inqDesc.options[inqDesc.options.length] = new Option('S\'abonner à REJB ou DCL','S\'abonner à REJB ou DCL');
			inqDesc.options[inqDesc.options.length] = new Option('Mots de passe additionnels','Mots de passe additionnels');
			inqDesc.options[inqDesc.options.length] = new Option('Facturation','Facturation');
			inqDesc.options[inqDesc.options.length] = new Option('Résolution de problème','Résolution de problème');
			inqDesc.options[inqDesc.options.length] = new Option('Autre','Autre');
			break

		//TaxnetPRO
		case "10":
			window.document.EmailForm.FormType.value="10";

			inqDesc.length=1;
			inqDesc.options[inqDesc.options.length] = new Option('S\'abonner à La référence RH','S\'abonner à La référence RH');
			inqDesc.options[inqDesc.options.length] = new Option('Mots de passe additionnels','Mots de passe additionnels');
			inqDesc.options[inqDesc.options.length] = new Option('Facturation','Facturation');
			inqDesc.options[inqDesc.options.length] = new Option('Résolution de problème','Résolution de problème');
			inqDesc.options[inqDesc.options.length] = new Option('Autre','Autre');
			break

		//Other
		case "12":
			window.document.EmailForm.FormType.value="12";

			inqDesc.length=1;

			document.getElementById("dependent-inquiry-other").style.display = 'block';
			document.getElementById("Inquiry-Details-Fieldset").style.display = 'block';
			document.getElementById("dependent-upload-link").style.display = 'block';
			document.getElementById("Contact-Method-Fieldset").style.display = 'block';
			document.getElementById("Submit-Buttons").style.display = 'block';
			break

	} //switch

	if (optionValue != 0 && optionValue != 12)
	{
		document.getElementById("Inquiry-Details-Fieldset").style.display = 'block';
		document.getElementById("dependent-inquiry-description").style.display = 'block';
		document.getElementById("dependent-upload-link").style.display = 'block';
		document.getElementById("Contact-Method-Fieldset").style.display = 'block';
		document.getElementById("Submit-Buttons").style.display = 'block';
	}

} //showDiv

function changeInquiryDescription(FormType)
{
	switch (document.EmailForm.InquiryDescription.value)
	{
		case "Autre":
			document.getElementById("dependent-inquiry-other2").style.display = 'block';
			break;
		default:
			document.getElementById("dependent-inquiry-other2").style.display = 'none';
			break;
	}
}

function SubmitForm()
{
	strFormType = document.EmailForm.FormType.value;
	strInquiryType = document.EmailForm.InquiryDescription.value;

	strErr = ""; //clear error label
	flag = true; //unset flag

	//unset all style colors
	resetStyle("FirstName");
	resetStyle("LastName");
	resetStyle("JobTitle");
	resetStyle("EmailAddress");
	resetStyle("PhoneNumber");
	resetStyle("AccountNumber")
	resetStyle("OrgType")
	resetStyle("PostalCode")
	resetStyle("InquiryOther");
	resetStyle("InquiryDescription");
	resetStyle("InquiryOther2");
	resetStyle("DescriptionOfRequest");
	resetStyle("Attachment")

	validateForm();
	if (flag){
		document.EmailForm.action="SendEmail.asp";
		document.EmailForm.submit();
	}
	else
		alert(strErr);
}

function validateForm()
{
	validRequired("FirstName");
	validRequired("LastName");
	validRequired("JobTitle");
	validRequired("EmailAddress");
	validRequired("PhoneNumber");
	validRequired("AccountNumber");
	validRequired("OrgType");
	validRequired("PostalCode");
	validRequired("DescriptionOfRequest");

	switch(strFormType)
	{
		case "12": // Other
			validRequired("InquiryOther");
			break;

		default: // Every other one
			validRequired("InquiryOther2");
			validRequired("InquiryDescription");
			break;
	}
	if (!flag){strErr = strErr + "Veuillez compléter tous les champs obligatoires (identifiés en rouge).";}
}

function validRequired(fldName)
{
	// First Name Validation
	if ((fldName=="FirstName") && (document.EmailForm.FirstNameTextBox.value==""))
		requireField(fldName);

	// Last Name Validation
	if ((fldName=="LastName") && (document.EmailForm.LastNameTextBox.value==""))
		requireField(fldName);

	// Job Title
	if ((fldName=="JobTitle") && (document.EmailForm.JobTitleTextBox.value==""))
		requireField(fldName);

	// Email Validation
	if ((fldName=="EmailAddress") && (document.EmailForm.EmailAddressTextBox.value==""))
		requireField(fldName);
	if ((fldName=="EmailAddress") && (document.EmailForm.EmailAddressTextBox.value!=""))
	{
		var eMailRegEx = new RegExp("^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$");
		if (!eMailRegEx.test(document.EmailForm.EmailAddressTextBox.value))
		{
			requireField(fldName);
			alert('Veuillez entrer une adresse de courriel valide.')
		}
	}

	// Phone Validation
	if (fldName=="PhoneNumber"){
		if (document.EmailForm.PhoneNumberTextBox.value=="")
			requireField(fldName);
		else
		{
			if (document.EmailForm.PhoneNumberTextBox.value!="")
			{
				if (document.EmailForm.PhoneNumberTextBox.value.length < 10)
				{
					requireField(fldName);
					alert('Le numéro de téléphone doit être composé d\'au moins 10 chiffres.')
				}
				else
				{
					x=0
					for (j=0; j<document.EmailForm.PhoneNumberTextBox.value.length; j++)
					{
						x=x+1
						if ((document.EmailForm.PhoneNumberTextBox.value.charAt(j) < "0") || (document.EmailForm.PhoneNumberTextBox.value.charAt(j) > "9"))
						{
							x=x-1
						}
					}
					if (x<10)
					{
						requireField(fldName);
						alert('Le numéro de téléphone doit être composé d\'au moins 10 chiffres.')
					}
			 	}
			}
		}
	}

	// Account Number Validation
	if ((fldName=="AccountNumber") && (document.EmailForm.AccountNumberTextBox.value!=""))
	{
		var acctNumRegEx = new RegExp("^[a-zA-Z0-9]{1,8}$");
		if (!acctNumRegEx.test(document.EmailForm.AccountNumberTextBox.value))
		{
			requireField(fldName);
			alert('Le numéro de compte doit être composé de 1 à 8 caractères alpha-numériques. Veuillez vérifier votre numéro de compte et soumettre à nouveau.')
		}
	}

	// Organization Type Validation
	if ((fldName=="OrgType") && (document.EmailForm.OrgTypeDropDown.selectedIndex==0))
		requireField(fldName);

	// Postal Code Validation
	if ((fldName=="PostalCode") && (document.EmailForm.PostalCodeTextBox.value==""))
		requireField(fldName);
	if ((fldName=="PostalCode") && (document.EmailForm.PostalCodeTextBox.value!=""))
	{
		var PostalCodeRegEx = new RegExp("^[a-zA-Z0-9]{6}$");
		if (!PostalCodeRegEx.test(document.EmailForm.PostalCodeTextBox.value))
		{
			requireField(fldName);
			alert('Le code postal doit être composé de 6 caractères. Veuillez vérifier votre code postal et soumettre à nouveau.')
		}
	}

	// Inquiry Other Validation
	if ((fldName=="InquiryOther") && (document.EmailForm.InquiryOtherTextBox.value==""))

		requireField(fldName);

	// Inquiry Description Validation
	if ((fldName=="InquiryDescription") && (document.EmailForm.InquiryDescriptionDropDown.selectedIndex==0))
		requireField(fldName);

	// Inquiry Other2 Validation
	if ((fldName=="InquiryOther2") && (document.EmailForm.InquiryOther2TextBox.value==""))
		if (document.EmailForm.InquiryDescriptionDropDown.value == "Other")
			requireField(fldName);

	// Requests/Comments Validation
	if ((fldName=="DescriptionOfRequest") && (document.EmailForm.DescrptionOfRequestTextArea.value==""))
		requireField(fldName);

	// Attachment Validation
	if ((fldName=="Attachment") && (document.EmailForm.FilAttach.value!=""))
	{
		var ext = document.EmailForm.FilAttach.value;
		ext = ext.substring(ext.length-3,ext.length);
		ext = ext.toLowerCase();
		if ((ext == 'exe')||(ext=='.js')||(ext=='.vb')||(ext=='asp')||(ext=='dll')||(ext=='scr')||(ext=='bat')||(ext=='reg')||(ext=='cab')||(ext=='mp3'))
		{
			alert('Vous avez sélectionné un fichier de type .'+ext+
			' Veuillez sélectionner un fichier de type texte.');
			flag = false;;
		}
	}
}
