function evalNLData(iUpdate) {
	var thisForm = getDoc().forms["newsletterform"];
	var iResult = 1;

	if (iResult) {
		for (var i = 0; i < arrMandatoryFields.length; i++) {
			editField = thisForm.elements[arrMandatoryFields[i][0]];

			if (editField.type == "select-one") {
				if (editField.options[editField.selectedIndex].value == -1) {
					alert(strReplace(strMandatoryCountry, '%s', removeTags(arrMandatoryFields[i][1])));
					iResult = 0;
					break;
				}
			} else if (!thisForm.elements[arrMandatoryFields[i][0]].value.length) {
				alert(strReplace(strEmptyField, '%s', arrMandatoryFields[i][1]));
				thisForm.elements[arrMandatoryFields[i][0]].focus();
				iResult = 0;
				break;
			}
			if (thisForm.elements[arrMandatoryFields[i][0]].name == 'Email1' ||
				thisForm.elements[arrMandatoryFields[i][0]].name == 'Email2') {
				if (!ValIsEmail(thisForm.elements[arrMandatoryFields[i][0]].value)) {
					alert(strNotVaildEmail);
					thisForm.elements[arrMandatoryFields[i][0]].focus();
					iResult = 0;
					break;
				}
			}
		}
	}

	if (iResult && iUseCaptcha) {
		if (thisForm.VcCaptchaInput.value == '' || thisForm.VcCaptchaInput.value.length < 5) {
			alert(strNoCaptchaInput);
			thisForm.VcCaptchaInput.focus();
			iResult = 0;
		}
	}

	if (iResult) {
		thisForm.submit();
	}
}

/**************************************************************************************
*     evalNLLoginForm() -     verifies that the user has filled in the 
*									Email and password fields to log in
***************************************************************************************/
function evalNLLoginForm() {
	var thisForm = getDoc().forms["nlloginform"];
	var iResult = 1;

	if (!thisForm.email.value.length) {
		thisForm.email.focus();
		iResult = 0;
	}
	
	if (iResult) {
		if (!thisForm.password.value.length) {
			thisForm.password.focus();
			iResult = 0;
		}
	}
	
	if (iResult)
		thisForm.submit();
}

/**************************************************************************************
*     evalNLLostPasswordInfo() -     verifies that the user has specified a mail 
*									address to which the lost password must be sent
***************************************************************************************/

function evalNLLostPasswordInfo() {
	var thisForm = getDoc().forms["nlloginform"];
	
	if (!thisForm.email.value.length) {
		alert(strNoMail);
		thisForm.email.focus();
	} else {
		document.location = "/scripts/newsletter.php?Mode=lostpassword&email=" +
							escape(thisForm.email.value) + "&iLangID=" + iLangID;
	}	
}

function evalNLSendProfileInfo()
{
	var thisForm = getDoc().forms["nlloginform"];

	if (!thisForm.email.value.length) {
		alert(strNoMail);
		thisForm.email.focus();
	} else {
		document.location = "/scripts/newsletter.php?Mode=sendProfileInfo&email=" +
							escape(thisForm.email.value) + "&iLangID=" + iLangID + '&strRef=' + thisForm.strRef.value;
	}
}

function NLDeleteProfile(strEmail) {
	if (confirm(strConfirmDelete))
		document.location = "/scripts/newsletter.php?Mode=deleteprofile&email=" +
							escape(strEmail) + "&lang=" + iLangID;

}

function evalNLSignoff() {
	var thisForm = getDoc().forms["nlsignoffform"];
	
	if (!thisForm.email.value.length)
		thisForm.email.focus();
	else
		thisForm.submit();	
}

/**************************************************************************************
*     strReplace() -     replaces the string strPattern with strReplacement
*                        in strHaystack
***************************************************************************************/

function strReplace(strHaystack, strPattern, strReplacement) {
    var strTemp = "";
    if (strHaystack.indexOf(strPattern) != -1) {
        for (var i = 0; i < strHaystack.length; i++) {
            if (strHaystack.substring(i, i + strPattern.length) == strPattern) {
                strTemp += strReplacement;
                i += (strPattern.length - 1);
            } else {
                strTemp += strHaystack.charAt(i);
            }
        }
    } else {
        strTemp = strHaystack;
    }
    return strTemp;
}

function userListEvalFields() {
	var thisForm = getDoc().forms['nlform'];

	thisForm.strTxtMessage.value = tinyMCE.activeEditor.getContent();

	var iResult = 1;
	for (var i = 0; i < arrMandatoryFields.length; i++) {
		if (!thisForm.elements[arrMandatoryFields[i][1]].value.length) {
			alert(strReplace(strEmptyField, '%s', arrMandatoryFields[i][0]));
			thisForm.elements[arrMandatoryFields[i][1]].focus();
			iResult = 0;
			return iResult;
		}
	}
	return 1;
}

function userListMailJobAttach() {
	if (getDoc().forms['nlform'].attachedFile.value == '') {
		alert(noFileSelected);
	} else {
		getDoc().forms['nlform'].Mode.value = "attachedfiles_save";
		getDoc().forms['nlform'].submit();
	}
}

function userListMailJobSendTest() {
	if (!userListEvalFields())
		return;
	getDoc().forms['nlform'].Mode.value = "userlist_sendtest";
	getDoc().forms['nlform'].submit();
}

function userListMailJobAdjustUsers() {
	getDoc().forms['nlform'].Mode.value = "userlist_adjustusers";
	getDoc().forms['nlform'].submit();
}


function userListMailJobSendFinal() {
	if (!userListEvalFields())
		return;
	if (confirm(strConfirmFinalSend)) {
		getDoc().forms['nlform'].Mode.value = "userlist_sendfinal";
		getDoc().forms['nlform'].submit();
	}
}

function userListMailJobSelectAll() {
	var thisForm = getDoc().forms['nlform'];

	var arrElms = thisForm.elements;
	for (var i = 0; i < arrElms.length; i++) {
		if (arrElms[i].name.substring(0, 4) == "user")
			arrElms[i].checked = true;
	}
	
}

function userListMailJobUnselectAll() {
	var thisForm = getDoc().forms['nlform'];

	var arrElms = thisForm.elements;
	for (var i = 0; i <  arrElms.length; i++) {
		if (arrElms[i].name.substring(0, 4) == "user")
			arrElms[i].checked = false;
	}
}

function saveNLUserlistUsers() {
	var thisForm = getDoc().forms['nlform'];
	var iNumUsers = 0;

	var arrElms = thisForm.elements;
	for (var i = 0; i <  arrElms.length; i++) {
		if (arrElms[i].name.substring(0, 4) == "user"
			&& arrElms[i].checked)
			iNumUsers++;
	}
	if (iNumUsers == 0)
		alert(strUserSelect);
	else
		thisForm.submit();
}
