


function isValidVoicesForm(objForm)
{
	var strCultureCode = "nl-NL";
	var blnOneVoiceSelected = false;
	
	objAllElements = objForm.elements;
	
	for (i=0;i < objAllElements.length;i++)
	{
		objElement = objAllElements[i];
		if ((objElement.type == "checkbox") && (objElement.name == "voice")) {
			if (objElement.checked) {
				blnOneVoiceSelected = true;
			}
		}
	}
	
	if (blnOneVoiceSelected == false)  {
		alert("You have to select a language or voice.");			
		return false;
	} else  {
		return true;
	}	
}


function isValidProjectDetailsForm(objForm)
{
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";
	
	if ( (objForm.script_minutes.value == "") && (objForm.script_words.value == "") )
	{
		strError += "> The length of the text";
	}
	
	if (strError != "")  {
		strErrorIntro = "The following fields have not been completed: \n\n";
		alert(strErrorIntro + strError);			
		return false;
	} else  {
		return true;
	}	

}


function isValidContactDetailsForm(objForm)
{
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";
	
	strError += ensureInput(objForm, "Name_Full", strCultureCode);
	strError += ensureInput(objForm, "Company", strCultureCode);
	strError += ensureInput(objForm, "Email", strCultureCode);
	strError += ensureInput(objForm, "Phone", strCultureCode);
	strError += ensureInput(objForm, "Country", strCultureCode);
	
	if (strError != "")  {
		strErrorIntro = "The following fields have not been completed: \n\n";
		alert(strErrorIntro + strError);			
		return false;
	} else  {
		return true;
	}	
}


function isValidContactForm(objForm)
{
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";
	
	var subject = objForm.subject.value;
	
	strError += ensureInput(objForm, "Name_Full", strCultureCode);
	strError += ensureInput(objForm, "Email", strCultureCode);
		
	if (subject == "IAmAVoiceOver") {
		strError += ensureInput(objForm, "Phone", strCultureCode);
		strError += ensureInput(objForm, "audio_file", strCultureCode);
		strError += ensureInput(objForm, "languages_id", strCultureCode);
		strError += ensureInput(objForm, "references", strCultureCode);
	} else {
		strError += ensureInput(objForm, "Company", strCultureCode);
		strError += ensureInput(objForm, "question", strCultureCode);
		
	}
	
	if (strError != "")  {
		strErrorIntro = "The following fields have not been completed: \n\n";
		alert(strErrorIntro + strError);			
		return false;
	} else  {
		
		var mySubmitButton = document.getElementById("submitbutton")
		mySubmitButton.disabled = true;
		
		return true;
	}	
}



function isValidLanguageSelectForm(objForm, strErrorMessage)
{
	var oneChecked = false;
	
	for (i=0; i < objForm.elements.length; i++)
	{
		objElement = objForm.elements[i];
		
		if ((objElement.type == "checkbox") && (objElement.checked) ) {
			oneChecked = true;		
		}
		
	}
	
	if (oneChecked == false)  {
		alert(strErrorMessage);			
		return false;
	} else  {
		return true;
	}	

}



function ensureInput(objForm, strFieldName, strCultureCode) 
{
	strValue = getValueByFieldName(objForm, strFieldName);
	strLabel = getLabelByCultureCode(strFieldName, strCultureCode);
		
	if (strValue == "") {
		setBackgroundColorToElement(objForm, strFieldName);
		return "> " + strLabel + "\n";
	} else {
		return "";
	}
}




function ensureNumber(objForm, strFieldName, strCultureCode) 
{
	strValue = getValueByFieldName(objForm, strFieldName);
	strLabel = getLabelByCultureCode(strFieldName, strCultureCode);
		
	if ( (strValue == "") || (isNaN(strValue)) ) {
		setBackgroundColorToElement(objForm, strFieldName);
		return "> " + strLabel + "\n";
	} else {
		return "";
	}
}



function ensurePhone(objForm, strFieldName, strCultureCode) 
{
	strValue = getValueByFieldName(objForm, strFieldName);
	strLabel = getLabelByCultureCode(strFieldName, strCultureCode);
	
	isEmpty = false;
	if (strValue == "") {
		isEmpty = true;
	}
	
	var objRegExp = /^[a-zA-Z]+$/;
	objRegExp.IgnoreCase = true;
	containsAZ = objRegExp.test(strValue);
		
	if ((isEmpty) || (containsAZ)) {
		setBackgroundColorToElement(objForm, strFieldName);
		return "> " + strLabel + "\n";
	} else {
		return "";
	}
}


function ensureEmailAddress(objForm, strFieldName, strCultureCode) 
{
	strValue = getValueByFieldName(objForm, strFieldName);
	strLabel = getLabelByCultureCode(strFieldName, strCultureCode);
		
	if (isValidEmailAddress(strValue)==false) {
		setBackgroundColorToElement(objForm, strFieldName);
		return "> " + strLabel + "\n";
	} else {
		return "";
	}
}

function ensureRadio(objForm, strFieldName, strCultureCode, objRadio) 
{
	var oneChecked = false;
	
	for (i=0; i < objRadio.length; i++)
	{
		if (objRadio[i].checked) {
			oneChecked = true;
		}
	}
	
	strLabel = getLabelByCultureCode(strFieldName, strCultureCode);
		
	if (!oneChecked) {
		return "> " + strLabel + "\n";
	} else {
		return "";
	}
}


function setBackgroundColorToElement(objForm, strFieldName)
{
	//get object
	objElement = getElementByFieldName(objForm, strFieldName);

	if (objElement.type == "text") {
		objElement.className = objElement.className + " errorfield";
	}
}


function getElementByFieldName(objForm, strFieldName)
{
	for (i=0; i < objForm.elements.length; i++) 
	{
		objElement = objForm.elements[i];
		if (objElement.name == strFieldName) {
			return objElement;
		}
	}
}


function getValueByFieldName(objForm, strFieldName)
{
	strValue = "";
	
	for (i=0; i < objForm.elements.length; i++) 
	{
		objElement = objForm.elements[i];
		if (objElement.name == strFieldName) {
			strValue = objElement.value;
		}
	}
	
	return strValue;
}



function isValidEmailAddress(strValue)
{
	var objRegExp  = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	return objRegExp.test(strValue);
}

function getLabelByCultureCode(strLabelName, strCultureCode)
{
	var labelValue = "unknown labelValue";
	
	labelElement = document.getElementById(strLabelName);
	labelValue = labelElement.innerHTML;
	
	return labelValue;
}



function getLabelByCultureCodeOLD(strFieldName, strCultureCode)
{
	strLabel = "";

	if (strFieldName == "Name_First") {
		if (strCultureCode == "nl-NL") { strLabel = "Voornaam"; }
		if (strCultureCode == "en-US") { strLabel = "First name"; }
	}
	else if (strFieldName == "Name_Last") {
		if (strCultureCode == "nl-NL") { strLabel = "Achternaam"; }
		if (strCultureCode == "en-US") { strLabel = "Last name"; }
	}
	else if (strFieldName == "Name_Full") {
		if (strCultureCode == "nl-NL") { strLabel = "Naam"; }
		if (strCultureCode == "en-US") { strLabel = "Name"; }
	}
	else if (strFieldName == "Name_Prefix") {
		if (strCultureCode == "nl-NL") { strLabel = "Aanhef"; }
		if (strCultureCode == "en-US") { strLabel = "Prefix"; }
	}
	else if (strFieldName == "Company") {
		if (strCultureCode == "nl-NL") { strLabel = "Bedrijfsnaam"; }
		if (strCultureCode == "en-US") { strLabel = "Company"; }
	}
	else if (strFieldName == "Country") {
		if (strCultureCode == "nl-NL") { strLabel = "Land"; }
		if (strCultureCode == "en-US") { strLabel = "Country"; }
	}
	else if (strFieldName == "Phone") {
		if (strCultureCode == "nl-NL") { strLabel = "Telefoon"; }
		if (strCultureCode == "en-US") { strLabel = "Phone"; }
	}
	else if (strFieldName == "City") {
		if (strCultureCode == "nl-NL") { strLabel = "Plaats"; }
		if (strCultureCode == "en-US") { strLabel = "City"; }
	}
	else if (strFieldName == "Email") {
		if (strCultureCode == "nl-NL") { strLabel = "E-mail adres"; }
		if (strCultureCode == "en-US") { strLabel = "Emailaddress"; }
	}
	else if (strFieldName == "PostalCode") {
		if (strCultureCode == "nl-NL") { strLabel = "Postcode"; }
		if (strCultureCode == "en-US") { strLabel = "Zipcode"; }
	}
	else if (strFieldName == "Street_Line1") {
		if (strCultureCode == "nl-NL") { strLabel = "Straat"; }
		if (strCultureCode == "en-US") { strLabel = "Street"; }
	}
	else if (strFieldName == "strHuisNummer") {
		if (strCultureCode == "nl-NL") { strLabel = "Huisnummer"; }
		if (strCultureCode == "en-US") { strLabel = "Number"; }
	}
	else 
	{
		strLabel = "Veldnaam";
	}
	
 	return strLabel;
}



