function testURL(fieldid) {
	var o = document.getElementById(fieldid);
	if(!o.value||!isURL(o)) return _showError(o);
	var oWindow = window.open(o.value, 'preview');
	if(oWindow!=null) oWindow.focus();
	return true;
}
function isEmail(o) {
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	if(o.value&&!re.test(o.value)) return _showError(o);
	return _isOK(o);
}
function isURL(o) {
	var url = o.value, re;
	if(url.substr(0,4) == 'www.') { url = 'http://' + url; o.value=url; }
	re =  /^(((https?:|ftp:|gopher:)\/\/))[a-zA-Z0-9\-\?%,\.\/&##!@:=\+~_]+[A-Za-z0-9\/]$/
	if(url&&!re.test(url)) return _showError(o);
	return _isOK(o);
}
function parseTime(o) {
	var t=o.value, sep=':', re, a, h, m;
	if(!t) return true;
	re = new RegExp("[^0-9\.:]", "g");
	t = t.replace(re,"");
	t = t.replace(/\./, sep);
	if(t.length==4&&t.indexOf(sep)==-1)
		t = t.substr(0,2)+sep+t.substr(2,2);
	else if(t.length>=1&&t.length<=2)
		t += (sep+'00');
	a=t.split(sep);
	if(!a||a.length!=2) return _showError(o);
	h = parseInt(a[0],10); // assume decimal format (BASE 10)
	m = parseInt(a[1],10);
	if( h>24||m>59||(h==24&&m!=0))
		return _showError(o);
	o.value=(h<10?'0':'')+h.toString()+sep+(m<10?'0':'')+m.toString();
	return _isOK(o);
}
function parsePrice(o) {
	var p=o.value, re, a, sep;
	if(!p) return true;
	sep = p.indexOf(',')<p.lastIndexOf('.')?'.':',';
	p=(sep=='.')?p.replace(',',''):p.replace('.',''); 
	re = new RegExp("[^0-9\.,]", "g");
	p=p.replace(re,"");
	if(p.indexOf(sep)!=p.lastIndexOf(sep))
		return _showError(o);
	a=p.split(sep);
	a[0]=!a[0]?'0':a[0];
	a[1]=!a[1]?'00':a[1].length==1?a[1]+'0':a[1].substr(0,2);
	o.value=a.join(sep);
	return _isOK(o);
}
function parseNum(o)
{
	if(!o.value) return true;
	var re = /[^0-9]/g;
	o.value=o.value.replace(re,"");
	return _isOK(o);
}
function parseDate(o) {
	if(!o.value) return true;
	var re,a,sep,d,m,y,dim, yy = new Date().getFullYear();
	re = /^(\d{1,2})(\/|\.|-)(\d{1,2})(\/|\.|-)(\d{2,4})$/;
	a=o.value.match(/^(\d{1,2})(\/|\.|-)(\d{1,2})(\/|\.|-)?$/); // no year
	if(a!=null) 
		o.value+=(!a[4]?a[2]:'')+String(yy);
	a=o.value.match(re);
	if(a==null)	return _showError(o);
	sep = a[2];
	d = parseInt(a[1],10);
	m = parseInt(a[3],10);
	y = parseInt(a[5],10);
	if(y<100) y+=2000;
	dim=(m==4||m==6||m==9||m==11)?30:31;
	if(m==2)
		dim=((y%4==0)&&((!(y%100==0))||(y%400==0)))?29:28;
	if( y<1940||y>2079||m<1||m>12||d<1||d>dim )
		return _showError(o);
	o.value = (d<10?'0':'')+d.toString()+sep+(m<10?'0':'')+m.toString()+sep+String(y);
	return _isOK(o);
}
function parsePhone(o) {
	if(!o.value) return true;
	var re = /[^0-9 ]/g;
	o.value = o.value.replace(re, '');
	return _isOK(o);
}	
function hasLen(o) {
	if(o.required && !o.value) return _showError(o);
	if(o.onblur) return true;
	return _isOK(o);
}
function _showError(o) {
	o.className='rsreq';
	if(o.value) o.focus();
	return true;
}
function _isOK(o) {
	if(o.value) o.className='';
	return true;
}