function ID(id) { return document.getElementById(id); }
function gV(id) { return ID(id).value; }
function sV(id) { ID(id).value = Trim(gV(id)); }

function Trim(STRING) { return RTrim(LTrim(STRING)); }

function RTrim(STRING){
/*while(STRING.charAt((STRING.length -1))==" ") STRING = STRING.substring(0,STRING.length-1);
return STRING;*/
	var re = /((\s*\S+)*)\s*/;
	return STRING.replace(re, "$1");
}

function LTrim(STRING){
/*while(STRING.charAt(0)==" ") STRING = STRING.replace(STRING.charAt(0),"");
return STRING;*/
	var re = /\s*((\S+\s*)*)/;
	return STRING.replace(re, "$1");
}

function valBox(id,field) {
//alert(id);
//alert("id is:" + id + " field is :" + field);
sV(id);
if (!gV(id)) { showMsg(field,id); return false; }
else return true;
}

function valCombo(id,field) {
if (gV(id) == 0) { showMsg(field,id); return false; }
else return true;
}

function showMsg(msg,id) {
/*var ErrDiv = ID('ErrMsg');
ErrDiv.innerHTML = msg + ' is a required field';*/
alert(msg + ' is a required field');
ID(id).focus();
}

function emailChk(id) {
re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
if(re.test(gV(id))) return true;
else {alert('Invalid email, please try again'); return false; }
}

function ipChk(id) {
re = /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/;
if(re.test(gV(id))) return true;
else {alert('Invalid IP address, please try again'); return false; }
}