/* Standard HTML manipulation Javascripts. */

/* Clear input box text. */
function clearInputBox(fieldName)
{
	if (fieldName.defaultValue == fieldName.value)
	{
	  	fieldName.value = "";
	}
}

function clear()
{
}

/* Validate an HTML form. */
function validateForm(fieldname)
{
 	// Init.
	var valid;
	var fieldVal = document.getElementById(fieldname).value;
	// Output message if necessary.
	if(fieldVal == null || fieldVal == "")
	{
		alert("The field " + fieldname + " is empty.");
		valid = false;
	}
	else
	{
		valid = true;
	}
	// Return valid.
	return valid;
}

/* Send to requested location. */
function redirect(form,way)
{
	// If the user is adding via the Mailing List run a separate function.
	if(form == 'MLSubscribe')
	{
	 	// Run Mailing List validation.
		validateMailingListForm(way);
	}
	// Set location to form and submit.
	else if(form != '')
	{
		document.forms[form].action=way;
		document.forms[form].submit();
	}
	else
	{
		window.location = way;
	}
}
// Get a variable by language.
function getVarByLang(en,fr,lang)
{
	// Init.
 	langVar = '';
 	// EN.
	if(lang == "en")
	{
		langVar = en;
	}
	// FR.
	else if(lang == "fr")
	{
		langVar = fr;
	}
	// Add \n.
	langVar = langVar + "\n";
	// Return.
	return langVar;
}

// Validate Mailing List form.
function validateMailingListForm(way)
{
	// Initialise.
	problem = '';
	alertTxt = '';
	// Initialise variables.
	var lang = document.getElementById("MLLang").value;
	var MLforename = document.getElementById("MLforename").value;
	var MLsurname = document.getElementById("MLsurname").value;
	var MLemail = document.getElementById("MLemail").value;
	var MLConfirmEmail = document.getElementById("MLConfirmEmail").value;
	var MLprofession = document.getElementById("MLprofession").value;
	var MLorganisation = document.getElementById("MLorganisation").value;
	var MLcountry = document.getElementById("MLcountry").value;
	var MLlanguage = document.getElementById("MLlanguage").value;
	var MLinterests = document.getElementById("MLinterests").value;
	// Check if missing information 
	if (MLforename == null || MLforename == "")
	{
	 	problem = getVarByLang("- Forename","- Prénom",lang);
	}
	if (MLsurname == null || MLsurname == "")
	{
	 	problem = problem + getVarByLang("- Surname","- Nom de famille",lang);
	}
	if (MLemail == null || MLemail == "")
	{
	 	problem = problem + "- Email\n";
	}
	if (MLcountry == null || MLcountry == "")
	{
	 	problem = problem + getVarByLang("- Country","- Pays",lang);
	}
	if (MLlanguage == null || MLlanguage == "")
	{
	 	problem = problem + getVarByLang("- Language","- Langue",lang);
	}
	// Check if email and confirmation email are the same.
	if (MLemail != MLConfirmEmail)
	{
	 	problem = problem + getVarByLang("\n- The email address and confirmation email address you entered are different","L’adresse email de confirmation est différente de l’adresse email que vous avez préalablement insérée",lang);
	}
	// Output problem alert.
	if(problem != '')
	{
	 	alertTxt = getVarByLang("Please enter text in the following fields:","Merci d’entrer votre texte dans les champs suivants:",lang);
		alert(alertTxt + "\n\n" + problem + "");
		return false;
	}
	else
	{
		// Set location to form and submit. 
		document.forms['MLSubscribe'].action=way;
		document.forms['MLSubscribe'].submit();
		return true;
	}
}
