// VALIDATOR
//  form requires id=Vf and onsubmit='return validate()'
//  add' title attribute to fields.
//  'Requires value' will check if value.
//  'Requires email' will check emails.
//  'Requires password' & 'Requires confirmation' will check passwords.
//  if 'Requires password' & 'Requires confirmation' will compare.
//  'Requires check' will check checkbox on.
//  ... add numbers after above for field value length check: ' and >33 characters'  (only 2 numbers allowed)

var vO,vD,vc

function validate(f)
{
if(!vO)
{
if(document.getElementById('Vf'))
{
vO=document.getElementById('Vf').getElementsByTagName('*')
vc=(window.valcol?valcol:'lightyellow')
}
}
if(vO)
{
n=0
er=''
var ps1,ps2
for(i=0;i<vO.length;i++)
{
e=0
if(vO[i].title)
{
if(!vD)
{
if(vO[i].tagName.toLowerCase()=='select')
vO[i].onchange=function(){validate(1)}
else
vO[i].onkeyup=function(){validate(1)}
}
v=vO[i].value
c=vO[i].title
if(c.indexOf('>')>-1)
{
c=c.substr(0,c.indexOf('>')-5)
l=(c=='Requires email'?5:parseInt(vO[i].title.substr(vO[i].title.indexOf('>')+1,2)))
}
else
l=-1
if(c=='Requires value'&&(!v||v==0||v.length<l))
{
if(!f)
er=1
e=1
n++
}
else if(c=='Requires check'&&vO[i].checked==false)
{
if(!f)
er=1
e=1
n++
}
else if(c=='Requires email'&&(!v||v.indexOf('@')<1||v.indexOf('.')<1||v.length<l))
{
if(!f)
er=1
e=1
if(!vD)
vO[i].onblur=function(){validate(1)}
n++
}
else if(c=='Requires password'||c=='Requires confirmation')
{
c=='Requires password'?ps1=vO[i]:ps2=vO[i]
if(!v||v.length<l)
{
if(!f)
er=1
e=1
n++
}
}
vO[i].style.background=(e?vc:'')
}
}
vD=1
if(ps1&&ps2)
{
if(ps1.value!=ps2.value)
{
ps1.style.background=vc
ps2.style.background=vc
if(!f)
er+=' '+(n+1)+'. Pasword & Confirm: do not match.'
n++
}
else if(!n)
{
ps1.style.background=''
ps2.style.background=''
}
}
if(!f&&n)
{
alert('Form requires attention!\nPlease fill in all highlighted fields')
return false
}
}
}