<!-- hide from old browsers
sAlertMessage = '';
sCheckedElements = '';

function checkForm(form, sErrorImagePath, sGoodImagePath, bCustomCheck){

	sAlertMessage = '';
	bReturn = true;
	iFocusElement = -1;
	sCheckedElements = '';
	
	if (!document.images || sErrorImagePath == '' || sGoodImagePath == '' || !sErrorImagePath || !sGoodImagePath){
		bSwapImage = false;
	} else {
		bSwapImage = true;
	}
	
	for (i=0; i < form.elements.length; i++){
		var item = form.elements[i]
	
		if (item.name.indexOf("req_") >= 0 ) {
			bErr = false;
			switch (item.type) {
				case 'button':
					break;
				case 'checkbox':
					if (!checkCheckbox(item, form)) {
						addMessage(item, form);
						bReturn = false;
						bErr = true;
					}
					if (bSwapImage) {
						if (bErr) {
							swapImage(item, sGoodImagePath);
						} else {
							swapImage(item, sErrorImagePath);
						}
					}
						
					break;
				case 'file':
					break;
				case 'hidden':
					break;
				case 'password':
					if (!checkText(item, form)) {
						addMessage(item, form);
						if (iFocusElement == -1) {
							iFocusElement = i;
						}
						bReturn = false;
						bErr = true;
					}
					
					if (!checkLength(item, 8)){
						sAlertMessage = sAlertMessage + 'Password 8 - 12 Characters\n';
						if (iFocusElement == -1) {
							iFocusElement = i;
						}
						bReturn = false;
						bErr = true;
					}
					if (bSwapImage) {
						if (bErr) {
							swapImage(item, sGoodImagePath);
						} else {
							swapImage(item, sErrorImagePath);
						}
					}
					
					break;
				case 'radio':
					if (!checkCheckbox(item, form)) {
						addMessage(item, form);
						bReturn = false;
						bErr = true;
					}
					if (bSwapImage) {
						if (bErr) {
							swapImage(item, sGoodImagePath);
						} else {
							swapImage(item, sErrorImagePath);
						}
					}
					
					break;
				case 'reset':
					break;
				case 'select-one':
					if (!checkSelect(item, form)) {
						addMessage(item, form);
						if (iFocusElement == -1) {
							iFocusElement = i;
						}
						bReturn = false;
						bErr = true;
					}
					if (bSwapImage) {
						if (bErr) {
							swapImage(item, sGoodImagePath);
						} else {
							swapImage(item, sErrorImagePath);
						}
					}
					
					break;
				case 'select-multiple':
					if (!checkSelect(item, form)) {
						addMessage(item, form);
						if (iFocusElement == -1) {
							iFocusElement = i;
						}
						bReturn = false;
						bErr = true;
					}
					if (bSwapImage) {
						if (bErr) {
							swapImage(item, sGoodImagePath);
						} else {
							swapImage(item, sErrorImagePath);
						}
					}
					
					break;
				case 'submit':

					break;
				case 'text':
					if (!checkText(item, form)) {
						addMessage(item, form);
						if (iFocusElement == -1) {
							iFocusElement = i;
						}
						bReturn = false;
						bErr = true;
					} else {

						if (stripKeys(item.name).toLowerCase() == 'mail') {
							if (!checkEmail(item)) {
								addMessage(item, form);
								if (iFocusElement == -1) {
									iFocusElement = i;
								}
								bReturn = false;
								bErr = true;
							}
						}
					}
					
					if (bSwapImage) {
						if (bErr) {
							swapImage(item, sGoodImagePath);
						} else {
							swapImage(item, sErrorImagePath);
						}
					}
					
					break;
				case 'textarea':

					if (!checkText(item, form)) {
						addMessage(item, form);
						if (iFocusElement == -1) {
							iFocusElement = i;
						}
						bReturn = false;
						bErr = true;
					}
					if (bSwapImage) {
						if (bErr) {
							swapImage(item, sGoodImagePath);
						} else {
							swapImage(item, sErrorImagePath);
						}
					}
					
					break;
				default:

					break;
			}
		}
	}
	
	if (bCustomCheck) {

		if (customCheck) {
			var oCustomCheck = new customCheck(form, sGoodImagePath, sErrorImagePath);
			if (!oCustomCheck.pass){
				bReturn = false;
				sAlertMessage = sAlertMessage + oCustomCheck.message;
			}
		}
	}
	
	if (!bReturn) {
		alert(sAlertMessage);
	}
	
	if (iFocusElement >= 0) {
		form.elements[iFocusElement].focus();
	}
	
	return bReturn;
}

function checkCheckbox(item, form) {

	bLocValid = false;
		
	if (sCheckedElements.indexOf(item.name+',') < 0) {
	
		sCheckedElements = sCheckedElements + item.name + ',';
		
		if (eval('form.'+item.name+'.length')) {
			
			for (j=0; j < eval('form.'+item.name+'.length'); j++) {
				if (eval('form.'+item.name+'['+j+'].checked')){
					bLocValid = true;
					break;
				}
			}
		} else {
			
			if (item.checked) {
				bLocValid = true;
			}
		}
	} else {
		
		bLocValid = true;
	}

	return bLocValid;
	
}

function checkSelect(item) {

	bLocValid = true;
	
	if (item.selectedIndex < 0) {
		
		bLocValid = false;
	}
	if (item.selectedIndex == 0) {
		
		if (item.options[0].value == '') {
			bLocValid = false;
		}
	}
	return bLocValid;
}

function checkText(item, form) {
	
	bLocValid = true;
	
	if (item.value.length < 1) {
		
		bLocValid = false;
	} else {
		
		bLocValid = false;
		
		if (item.value.length < 100) {
			iLength = item.value.length;
		} else {
			iLength = 100;
		}
		
		for (j=0; j < iLength; j++) {
			sTemp = item.value.substring(j, j+1);
			if (sTemp != ' ' && sTemp != '\n' && sTemp != '\f' && sTemp != '\r' && sTemp != '\t') {
				bLocValid = true;
				break;
			}
		}
	}
		
	if (bLocValid) {
		
		if (!checkConfirm(item, form)) {
			bLocValid = false;
		}
	}
		
	return bLocValid;
}

function checkConfirm(item, form) {
	// set  the local varaibles
	bConfirm = true;
		
	if (eval('form.conf_'+stripKeys(item.name))) {
		if (eval('form.conf_'+stripKeys(item.name)+'.value') != item.value) {
			bConfirm = false;
		}
	}
	
	return bConfirm;
}

function checkEmail (item) {
	
	if (item.value.indexOf("@") < 0 || item.value.indexOf(".") < 0) {
		return false;
	} else {
		
		return true;
	}
}

function checkLength(item, iMin, iMax) {
		
	bLocValid = true;
	
	if (iMin && iMin != ''){
		if (item.value.length < iMin){
			bLocValid = false;
		}
	}
	if (iMax && iMax != ''){
		if (item.value.length > iMax){
			bLocValid = true;
		}
	}

	return bLocValid;
}

function stripKeys(sTemp) {
	
	sRet = sTemp.substring(sTemp.lastIndexOf("_")+1);
	return sRet;
}

function addMessage(item, form){
	
	sAlertMessage = sAlertMessage + eval('form.mes_'+stripKeys(item.name)+'.value') + '\n';
}

function swapImage(item, sSRC) {

	if (document[stripKeys(item.name)].src) {
		// swap the image
		document[stripKeys(item.name)].src = sSRC;
	}
}

// all done hiding -->