function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)){
        if(charCode == 32 || charCode == 40 || charCode ==41 || (charCode >= 44 && charCode <= 46)){
            return true;
        }
        else{
            return false;
        }
    }
    return true;
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function validEmail(email){
    var tValid = true;
    if((email.length < 8) ||
        ((email.length>0) && (! email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)))){
        tValid = false;
    }
    return tValid;
}

function submitForm(){
	var fields = new Array();
	fields[0] = new Array("fname", "First Name");
	fields[1] = new Array("lname", "Last Name");
	fields[2] = new Array("email", "Email Address");
	var tmp = new String();
	var msg = "missing Required Information";
	var valid = true;
	for(var i=0;i<fields.length;i++){ 
		tmp = document.getElementById(fields[i][0]+"_id").value;
		tmp = tmp.trim();
		if(fields[i][0] == "email"){
				if(validEmail(tmp)){
					document.getElementById(fields[i][0]+"_lbl").style.color = "black";
					continue;
				}
				else{
					document.getElementById(fields[i][0]+"_lbl").style.color = "red";
					valid = false;
					msg += "\n"+fields[i][1];
				}
		}
		else{
			if(tmp.length < 1){
				valid = false;
				document.getElementById(fields[i][0]+"_lbl").style.color = "red";
				msg += "\n"+fields[i][1];
			}
			else{
				document.getElementById(fields[i][0]+"_lbl").style.color = "black";
			}
		}
	}
	if(valid){
		xajax_submitForm(xajax.getFormValues('requestDownload'));
		document.getElementById('error').style.display = 'none';
	}
	else{
		alert(msg);
		document.getElementById('error').style.display = 'inline';
	}
	return false;	
}
