
function isEmpty(x) {
	var filter=/[^\s]+/;
	return !filter.test(x);
}

function trim(v) {
	var l,s,d;
	l=v.length;
	while(l>0&&(v.charAt(l-1)==' '||v.charAt(l-1)=='\n'||v.charAt(l-1)=='\t'))l--;
	s=0;
	while(s<l&&(v.charAt(l-1)==' '||v.charAt(l-1)=='\n'||v.charAt(l-1)=='\t'))s++;
	d='';
	for(i=s;i<l;i++) d+=v.charAt(i);
	return d;
}

function emailOk(e) {
	var email;
	email=trim(e);
	if(email.length<6||email.indexOf("@")<0||email.indexOf(".")<0||email.indexOf(" ")>0)
		return false;
	return true;
}

function reloadCap(l,c) {
	if(l) l.blur();
	if(!c) c='captcha';
	var i=document.getElementById(c);
	if(i) i.src=i.src+'1';
	return false;
}

function setSelByVal(o,v) {
	if(!o.type&&o[0].type.toLowerCase()=='radio') { // radio / collection
		for(i=0;i<o.length;i++) if(o[i].value==v){o[i].checked=true;return true;}
	} else if(o.type.substr(0,4).toLowerCase()=='sele') { // select
		for(i=0;i<o.options.length;i++) if(o.options[i].value==v){o.selectedIndex=i;return true;}
	} else return false;
}

function getRadioSelected(o) {
	var ret=false;
	if(!o.type&&o[0].type.toLowerCase()=='radio') { // radio / collection
		for(i=0;i<o.length;i++) if(o[i].checked) return o[i].value;
	}
	return ret;
}

function fmtPhone(o) {
	var s, orig=o.value;
	s=orig.replace(/[^0-9+()]*/g,'');
	if(s!=orig) {
		o.value=s;
		alert('Please use only "+", "(", ")" and numbers');
	}
}

