function validateForm(lngID) {
	if (lngID == 1) {
		return validateOrderForm();
	} else 	if (lngID == 2) {
		return validateContactForm();
	} else 	if (lngID == 3) {
		return validateDownload();
	} else 	if (lngID == 4) {
		return validateRegister();
	}
	return false;
}

function validateRegister() {
	var frm = document.frmRegister;
	
	if (blankString(frm.txtFirstName.value)) return showErrorMessage('Firstname is missing!', frm.txtFirstName);
	if (blankString(frm.txtLastName.value)) return showErrorMessage('Last Name is missing!', frm.txtLastName);
	if (blankString(frm.txtEMail.value)) return showErrorMessage('E-Mail is missing!', frm.txtEMail);
	if (!validEMail(frm.txtEMail.value)) return showErrorMessage('E-Mail is invalid!', frm.txtEMail);
	if (frm.cboCountry.selectedIndex <= 0) return showErrorMessage('No Country selected!', frm.cboCountry);
	
	return true;
}

function validateDownload() {
	var frm = document.frmDownload;
	
	if (blankString(frm.txtName.value)) return showErrorMessage('Name is missing!', frm.txtName);
	if (blankString(frm.txtEMail.value)) return showErrorMessage('EMail is missing!', frm.txtEMail);
	if (!validEMail(frm.txtEMail.value)) return showErrorMessage('EMail is invalid!', frm.txtEMail);
	
	return true;
}

function validateOrderForm() {
	var frm = document.frmOrder;
	
	if (blankString(frm.txtFirstName.value)) return showErrorMessage('Firstname is missing!', frm.txtFirstName);
	if (blankString(frm.txtLastName.value)) return showErrorMessage('Last Name is missing!', frm.txtLastName);
	if (blankString(frm.txtAddLine1.value)) return showErrorMessage('Address Line1 is missing!', frm.txtAddLine1);
	if (blankString(frm.txtZip.value)) return showErrorMessage('Zip Code is missing!', frm.txtZip);
	if (blankString(frm.txtLoction.value)) return showErrorMessage('Location is missing!', frm.txtLoction);
	if (blankString(frm.txtCountry.value)) return showErrorMessage('Country is missing!', frm.txtCountry);
	if (blankString(frm.txtPhone.value)) return showErrorMessage('Telephone is missing!', frm.txtPhone);
	if (blankString(frm.txtEMail.value)) return showErrorMessage('EMail is missing!', frm.txtEMail);
	if (!validEMail(frm.txtEMail.value)) return showErrorMessage('EMail is invalid!', frm.txtEMail);
	if (blankString(frm.txtComment.value)) return showErrorMessage('Comment is missing!', frm.txtComment);
	
	return true;
}

function validateContactForm() {
	var frm = document.frmContact;
	
	if (blankString(frm.txtFirstName.value)) return showErrorMessage('Firstname is missing!', frm.txtFirstName);
	if (blankString(frm.txtLastName.value)) return showErrorMessage('Last Name is missing!', frm.txtLastName);
	if (blankString(frm.txtEMail.value)) return showErrorMessage('EMail is missing!', frm.txtEMail);
	if (!validEMail(frm.txtEMail.value)) return showErrorMessage('EMail is invalid!', frm.txtEMail);
	if (blankString(frm.txtComment.value)) return showErrorMessage('Comment is missing!', frm.txtComment);
	
	return true;
}


function blankString(strString) {
	strString = String(strString);
	
	if (strString == '') { return true; }
	
	for (var i=0; i<strString.length; i++) {
		if (strString.charCodeAt(i) != 10 && strString.charCodeAt(i) != 13 && strString.charCodeAt(i) != 32) { 
			return false;
		}
	}
	
	return true;
}

function validEMail(strEMail) {
	if (strEMail == '') return true;
	if (strEMail.match('^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$')) return true;
	
	return false;
}

function validEMail2(strEMail) {
	var fFoundAt = false;
	var fFoundDot = false;
	
	strEMail = String(strEMail);
	
	if (strEMail == '') { return true; }
	if (strEMail.length < 8) { return false; }
	
	for (var i=0; i<strEMail.length; i++) {
		//  . = 46 and @ = 64
		if (strEMail.charCodeAt(i) == 64) {
			if (fFoundAt) { return false; }
			fFoundAt = true;
		} else if (strEMail.charCodeAt(i) == 46) {
			if (fFoundAt) {
				fFoundDot = true;
				break;
			}
		}
	}
	
	if (!fFoundAt || !fFoundDot) { return false; }
	
	return true;
}

function showErrorMessage(strMessage, objControl) {
	objControl.focus();
	if (objControl.select) { objControl.select(); }
	alert(strMessage);
	return false;
}
