function checkField(required,type,name){

	var value = name.value;
	var reqOK = true;
	var typeOK = false;
	
	if(required&&(value=="")){
		reqOK = false;
	}
	if(type=="text"){
		typeOK = isText(value);
	}else if(type=="alphanum"){
		typeOK = isAlfaNum(value);
	}else if(type=="int"){
		typeOK = isInt(value);
	}else if(type=="double"){
		typeOK = isDouble(value);
	}else if (type == "email"){
		typeOK = isEmail(value);
	}else if(type=="ignore"){
		typeOK = true;
	}
	if(!(typeOK&&reqOK)){
		name.style.backgroundColor="#FFA07A";
	}
	return(typeOK&&reqOK);
}

function isText(value){
var checkOK = ' !"#$%&' + "'" + '()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz|~\n';
var result = runLoop(checkOK,value);
return(result);
}

function isAlfaNum(value){
var checkOK = "-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789., ";
var result = runLoop(checkOK,value);
return(result);
}

function isInt(value){
var checkOK = "-0123456789";
var result = runLoop(checkOK,value);
return(result);
}

function isDouble(value){
var checkOK = "-0123456789.";
var result = runLoop(checkOK,value);
return(result);
}

function isEmail(value){
	return (value.indexOf(".") > 0) && (value.indexOf("@") > 0);
}

function runLoop(checkOK,value){
var checkStr = value;
var allValid = true;

for (i = 0;  i < checkStr.length;  i++){
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
return (allValid);
}
