function isDigit(strNum)
{
	return /^\-?\d+(\.\d+)?$/.test(strNum);
}

function checkEmail(strEmail)
{
	return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})$/.test(strEmail);
}
	
var type_1 = 'Null';
var type_2 = 'Mail';
var type_3 = 'Digit';
var type_4 = 'NotZero';

//======= Check the Admin Form ====================

function validateForm( theForm ) {

strErrorList = 'יש להזין/לתקן את השדות הבאים:\n' + '-------------------------------------------\n';
strFocusField = '';

for ( f = 0; f < formElements.length; f++ )
{
	switch(formElements[f][2]) {
		case 'Null':
		if (eval('theForm.'+formElements[f][0]+'.value')==''){
			strErrorList += '* '+ formElements[f][1] +' - יש להזין שדה זה!\n';
			strFocusField = ( strFocusField == '' )? formElements[f][0] : strFocusField;
		}
		break;
		case 'Mail':
		if (!checkEmail(eval('theForm.'+formElements[f][0]+'.value'))){
			strErrorList += '* '+ formElements[f][1] +' - לא הוזנה כתובת אינטרנט חוקית!\n';
			strFocusField = ( strFocusField == '' )? formElements[f][0] : strFocusField;
		}
		break;
		case 'Digit':
		if (!isDigit(eval('theForm.'+formElements[f][0]+'.value'))){
			strErrorList += '* '+ formElements[f][1] +' - יש להזין מספרים בלבד!\n';
			strFocusField = ( strFocusField == '' )? formElements[f][0] : strFocusField;
		}
		break;
		case 'NotZero':
		if (eval('theForm.'+formElements[f][0]+'.value')=='0'){
			strErrorList += '* '+ formElements[f][1] +' - בחר מהרשימה!\n';
			strFocusField = ( strFocusField == '' )? formElements[f][0] : strFocusField;
		}
		break;
		default:
		var strTypeArray = formElements[f][2].split(",");
		var strOperatorType = strTypeArray[0];
		var strOperatorValue = strTypeArray[1];
		var fieldValue = eval('theForm.'+formElements[f][0]+'.value');
		if (eval('\''+fieldValue+'\''+strOperatorType+'\''+strOperatorValue+'\'')){
			strErrorList += '* '+ formElements[f][1] +'\n';
			strFocusField = ( strFocusField == '' )? formElements[f][0] : strFocusField;
		}
		break;
	}
}

if (strErrorList != 'יש להזין/לתקן את השדות הבאים:\n' + '-------------------------------------------\n' )
{
	alert( strErrorList );
	eval( 'theForm.' + strFocusField + '.focus( );' );
	return false;
}

return true;
}
