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

function checkEmail(strEmail)
{
	return /^\w+([\.]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})$/.test(strEmail);
}

//======= Validate Form Inputs ====================

var type_1 = "Null";
var type_2 = "Mail";
var type_3 = "Digit";
var type_4 = "NotZero";

function validateForm( theForm ) {

strErrorList = "Please, fill the next fields:\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] +" - must be filed in!\n";
			strFocusField = ( strFocusField == '' )? formElements[f][0] : strFocusField;
		}
		break;
		case "Mail":
		if (checkEmail(eval('theForm.'+formElements[f][0]+'.value'))==false){
			strErrorList += "* "+ formElements[f][1] +" - must be a valid e-mail address!\n";
			strFocusField = ( strFocusField == '' )? formElements[f][0] : strFocusField;
		}
		break;
		case "Digit":
		if (isDigit(eval('theForm.'+formElements[f][0]+'.value'))==false){
			strErrorList += "* "+ formElements[f][1] +" - must contain only numbers!\n";
			strFocusField = ( strFocusField == '' )? formElements[f][0] : strFocusField;
		}
		break;
		case "NotZero":
		if (eval('theForm.'+formElements[f][0]+'.value')=='0'){
			strErrorList += "* "+ formElements[f][1] +" - choose from list!\n";
			strFocusField = ( strFocusField == '' )? formElements[f][0] : strFocusField;
		}
		break;
	}
}

	if (strErrorList != "Please, fill the next fields:\n" + "-------------------------------\n" )
	{
		alert( strErrorList );
		eval( "theForm." + strFocusField + ".focus( );" );
		return false;
	}
	if(!checkExtra( theForm )) {
		return false;
	}
}

function checkExtra( theForm ) {
	if ((theForm.Country_Form.value=='United States') && (theForm.State_Form.value=='0')) {
		alert('Please, select your state');
		theForm.State_Form.focus();
		return false;
	}
	else {
		return true;
	}

	if (theForm.FileName_Form==undefined) {
		return true;
	}
	else {
		if (theForm.FileName_Form.value!='C:\\HTBsupport.txt') {
			alert('Please, upload the HTBsupport.txt file from drive C:');
			theForm.FileName_Form.focus();
			return false;
		}		
	}
}
