function validateNumber(field, msg, min, max, optional) {
	if (!field.value && optional) {
		return true;
	}
	
	if (!min) { min = 0 }
	if (!max) { max = 255 }
	
	if ( (parseInt(field.value) != field.value) ||  field.value.length < min || field.value.length > max) {
		alert(msg);
		field.focus();
		field.select();
		return false;
	}
	
	return true;
}

function validateString(field, msg, min, max, optional) {
	if (!field.value && optional) {
		return true;
	}
	
	if (!min) { min = 1 }
	if (!max) { max = 65535 }
	
	if (!field.value || field.value.length < min ||  field.value.max > max) {
		alert(msg);
		field.focus();
		field.select();
		return false;
	}
	
	return true;
}

function validateEmail(email, msg, optional) {
	if (!email.value && optional) {
		return true;
	}
	
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if (!re_mail.test(email.value)) {
		alert(msg);
		email.focus();
		email.select();
		return false;
	}
	
	return true;
}

function validateCheckbox( box, msg, state ) {
	if( box.checked != state ) {
		alert( msg );
		box.focus();
		
		return false;
	}
	
	return true;
}

function askFor( msg, URL1, URL2 ) {
	var check = confirm( msg );
	if( check ) {
		location.href = URL1;
	} else {
		if( URL2 ) location.href = URL2;
	}
}

document.onLoad = function() { document.forms[0].elements[0].focus(); }
