//Literature request javascript
function checktickbox(field)
{
	if(Number(field.value) > 20)
	{
		alert("Maximum number of pre-printed copies is 20, if you require more than this please contact the adviser support team");
		field.focus();
	}
}

function sizeCheck(intNumberFields,strPrintedIDs)
{
	var objForm = document.litreq;
	var iSize = 0;
	var iPrintedLength = strPrintedIDs.length;
	
	for(i=0; i<intNumberFields; i++)
	{
		if(objForm.wantdoc[i].checked == true) 
		{
			iSize = Number(iSize) + Number(objForm.size[i].value);		
		}
	}
	if (iSize > 100) {
		return confirm("The file(s) you have chosen to be e-mailed total " + iSize + "k in size\n\nPlease confirm your wish to continue and receive the e-mail.");
	} else {
		if (iSize > 0) {
			return true;
		} else {
			istrStart = 0;
			while (istrStart > -1) {
				iStrEnd = strPrintedIDs.indexOf(',',istrStart)
				if (iStrEnd > -1) {
					strID = strPrintedIDs.substr(istrStart,iStrEnd-istrStart)
					if (objForm["NumForm" + strID].value != "") {
						return true;
					}
					istrStart = iStrEnd+1;
				} else {
					istrStart = -1;
				}
			}
			alert("Please select the documents you require to be e-mailed to you.");
			return false;
		}
	}
}

function validate(intNumberFields,strPrintedIDs) {
	var objForm = document.litreq;
	var iSize = 0;
	
	if (objForm.txtEmail.value == "") {
		for(i=0; i<intNumberFields; i++) {
			if(objForm.wantdoc[i].checked == true) {
				iSize = Number(iSize) + Number(objForm.size[i].value);		
			}
		}
		if (iSize > 0) {
			alert("Please enter your e-mail address.");
			objForm.txtEmail.focus();
			return false;
		}
	}
	//check valid email
	if (checkEmail(objForm.txtEmail) == false) {
		return false;
	}
	//check size of email to send
	if (sizeCheck(intNumberFields,strPrintedIDs) == false) {
		return false;
	}
	//all OK
	return true;
}