
//------------------------------------------------------------------------------------
//function				(TV3)
//function				(TV6)
//function TV7			()
//function validator	(TV8,TV9,TVA)
//function				()
//function TVK			()
//function TVE			(TVk,TVl)
//function TVC			(TVn,TVW)
//function TVN			(TVq)
//Was
//'alphanum':/^\w+$/
//Now
//'alphanum':/^[\w\s]+$/
//------------------------------------------------------------------------------------

var TV0=/^(\d{1,2})\-(\d1,2})\-(\d{4})$/,
	TV1=/^(\d{1,2})\:(\d{1,2})\:(\d{1,2})$/,
	TV2={'joolz':/^[\w\s\-\.\,\/]+$/,
		 'alpha':/^[a-zA-Z\.\-\s]*$/,
	     'alphanum':/^[\w\s\-\.\,\/]+$/,
		 'unsigned':/^\d+$/,
		 'integer':/^[\+\-]?\d*$/,
		 'real':/^[\+\-]?\d*\.?\d*$/,
		 'email':/^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/,
		 'phone':/^[\d\.\s\-]+$/,
		 'date':
		 function(TV3)
		 {
    	 if(!TV0.test(TV3))return false;
    	 if(RegExp.$1>31||RegExp.$2>12)return false;
    	 var TV4=new Date(RegExp.$3,Number(RegExp.$2-1),RegExp.$1);
    	 if(TV4.getMonth()!=Number(RegExp.$2-1))return false;
   		 return true;
		 },
		 'time':
		 function(TV6)
		 {
    	 if(!TV1.test(TV6))return false;
    	 if(RegExp.$1>23||RegExp.$2>59||RegExp.$3>59)return false;
    	 return true;
		 }
};

//------------------------------------------------------------------------------------
//      Name : TV7()
//------------------------------------------------------------------------------------
//   Purpose : Sets the messagebox text
//------------------------------------------------------------------------------------
// Arguments : n/a
//------------------------------------------------------------------------------------
//   Returns : n/a
//------------------------------------------------------------------------------------
function TV7()
{
    this.alert=0;
    this.alert_class=[];
    this.to_disable=[];
    this.messages=
    {
        'setup':['No form name passed to validator construction routine',
			     'No array of "%form%" form fields passed to validator construction routine',
				 'Form "%form%" can not be found in this document',
				 'Can not find area for error message box (id="error_%form%")',
				 'Incomplete "%n%" form field descriptor entry. Attribute "%attr%" is missing',
				 'Can not find form field "%n%" in the form "%form%"',
				 'Can not find label tag (id="%t%")',
				 'Can not verify match. Field "%m%" was not found'],
				 'fill':['"%l%" is a required field',
				 '"%v%" is not valid value for "%l%"',
				 'Value for "%l%" must be %mn% characters or more',
				 'Value for "%l%" must be no longer than %mx% characters',
				 '"%l%" must match "%ml%"'],
				 'boxes':['<table cellpadding="0" cellspacing="0" border="0" width="100%">'
        +'<tr><td bgcolor="#CCCC33"><table cellpadding="15" cellspacing="1" border="0" width="100%">'
        +'<tr><td bgcolor="#FFFFCC" style="color: red;">%error%</td></tr>'
        +'</table></td></tr><tr><td height="10">&nbsp;</td></tr></table>','<table cellpadding="0" cellspacing="0" border="0" width="100%">'
        +'<tr><td bgcolor="#CCCC33"><table cellpadding="15" cellspacing="1" border="0" width="100%">'
        +'<tr><td bgcolor="#FFFFCC" style="color: green; font-weight: bold;">Submitting ...</td></tr>'
        +'</table></td></tr><tr><td height="10">&nbsp;</td></tr></table>'],'confirm':['The "%form%" form is to be submitted. Are you sure?']
    }
}


//------------------------------------------------------------------------------------
//      Name : 
//------------------------------------------------------------------------------------
//   Purpose : 
//------------------------------------------------------------------------------------
// Arguments : n/a
//------------------------------------------------------------------------------------
//   Returns : n/a
//------------------------------------------------------------------------------------
function validator(TV8,TV9,TVA)
{
    this.TVB=TVC;
    var TVD=new TV7();
    TVE(TVA,TVD);
    this.TVA=TVD;
    this.TVF=TVD.alert;
    this.TVG=this.TVF&4?function(TVH)
    {
        alert(TVH);
        return false
}:
    
	
//------------------------------------------------------------------------------------
//      Name : 
//------------------------------------------------------------------------------------
//   Purpose : 
//------------------------------------------------------------------------------------
// Arguments : n/a
//------------------------------------------------------------------------------------
//   Returns : n/a
//------------------------------------------------------------------------------------    
function()
{
    return false
};

this.TVI=TVD.alert_class;
if(!TV8)return this.TVG(this.TVB('setup',0));
this.TV8=TV8;
if(!TV9||typeof(TV9)!='object')
return this.TVG(this.TVB('setup',1));
this.TV9=TV9;
this.TVJ=TVD.to_disable;
this.exec=TVK;

}


//------------------------------------------------------------------------------------
//      Name : TVK
//------------------------------------------------------------------------------------
//   Purpose : 
//------------------------------------------------------------------------------------
// Arguments : n/a
//------------------------------------------------------------------------------------
//   Returns : n/a
//------------------------------------------------------------------------------------
function TVK()
{
    var TVL=document.forms[this.TV8];
    if(!TVL)return this.TVG(this.TVB('setup',2));
    var TVM=TVN('error_'+this.TV8),TVO=document.body&&document.body.innerHTML;
    if((this.TVF&2)||(this.TVF&8))
    {
        if(TVO&&!TVM)return this.TVG(this.TVB('setup',3));
        if(TVO)
        {
            TVM.style.display='none';
            TVM.innerHTML='';
        }
    }
    var TVP=['l'];
    for(var TVQ in this.TV9)
    {
        this.TV9[TVQ]['n']=TVQ;
        for(TVR in TVP)
        if(!this.TV9[TVQ][TVP[TVR]])return this.TVG(this.TVB('setup',4,this.TV9[TVQ],
        {
            'attr':TVP[TVR]
        }
        ));
        TVS=TVL.elements[TVQ];
        if(!TVS)return this.TVG(this.TVB('setup',5,this.TV9[TVQ]));
        this.TV9[TVQ].TVS=TVS;
    }
    if(TVO)for(var TVQ in this.TV9)
    if(this.TV9[TVQ]['t'])
    {
        var TVT=this.TV9[TVQ]['t'],TVU=TVN(TVT);
        if(!TVU)return this.TVG(this.TVB('setup',6,this.TV9[TVQ]));
        this.TV9[TVQ].TVV=TVU;
        TVU.className=this.TVI[1];
    }
    for(var TVQ in this.TV9)
    {
        TVS=this.TV9[TVQ].TVS;
        this.TV9[TVQ]['v']=null;
        if(TVS.type=='checkbox')
        {
            if(TVS.checked&&TVS.value)this.TV9[TVQ]['v']=TVS.value;
        }
        else
        if(TVS.value)this.TV9[TVQ]['v']=TVS.value;
        else if(TVS.options&&TVS.selectedIndex>-1)this.TV9[TVQ]['v']=TVS.options[TVS.selectedIndex].value;
        else if(TVS.length>0)for(var TVW=0;
        TVW<TVS.length;
        TVW++)
        if(TVS[TVW].checked)
        {
            this.TV9[TVQ]['v']=TVS[TVW].value;
            break;
        }
    }
    var TVX=0,TVY,TVZ,TV_,TVa;
    for(var TVQ in this.TV9)
    {
        TVb=this.TV9[TVQ];
        TV_=TVb['f']?(TV2[TVb['f']]?TV2[TVb['f']]:TVb['f']):null;
        TVa=(TV_+'').indexOf('function')>-1;
        TVb.TVc=null;
        if(TVb['r']&&!TVb['v'])
        {
            TVb.TVc=1;
            TVX++;
        }
        else if(TVb['mn']&&String(TVb['v']).length<TVb['mn'])
        {
            TVb.TVc=3;
            TVX++;
        }
        else if(TVb['mx']&&String(TVb['v']).length>TVb['mx'])
        {
            TVb.TVc=4;
            TVX++;
        }
        else if(TV_&&((TVa&&(TVY=TV_(TVb['v'],TVL))!=true)||(!TVa&&TVb['v']&&!TV_.test(TVb['v']))))
        {
            TVb.TVc=typeof(TVY)!='string'?2:TVY;
            TVX++;
        }
        else
        if(TVb['m'])
        {
            for(var TVd in this.TV9)
            if(TVd==TVb['m'])
            {
                TVZ=TVd;
                break;
            }
            if(TVZ==null)return this.TVG(this.TVB('setup',7,TVb));
            if(this.TV9[TVZ]['v']!=TVb['v'])
            {
                TVb['ml']=this.TV9[TVZ]['l'];
                TVb.TVc=5;
                TVX++;
            }
        }
    }
    var TVe='',TVf='',TVg;
    if(TVX)
    {
        for(var TVQ in this.TV9)
        {
            var TVh=this.TV9[TVQ].TVc,TVi='';
            if(TVh)
            {
                TVi=this.TVB('fill',TVh-1,this.TV9[TVQ]);
                if(!TVi)TVi=TVh;
            }
            if(TVi)
            {
                if(!TVg)TVg=TVL.elements[TVQ];
                TVe+=TVi+'<br>';
                TVf+=TVi+"\n";
                if(TVO&&this.TVI&&this.TV9[TVQ].TVV)this.TV9[TVQ].TVV.className=this.TVI[0];
            }
        }
        TVe=this.TVB('boxes',0,
        {
            'error':TVe
        }
        );
        if(typeof(this.TVF)!='function')
        {
            if(this.TVF&1)alert(TVf);
            if(TVO&&(this.TVF&2))
            {
                TVM.innerHTML=TVe;
                TVM.style.display='block';
            }
            if(TVg.focus&&TVg.type!='hidden')TVg.focus();
            return false;
        }
    }
    if(typeof(this.TVF)=='function')return this.TVF(TVf,TVe,TVM);
    else
    {
        if((this.TVF&16)&&!confirm(this.TVB('confirm',0)))return false;
        if(TVO&&(this.TVF&8))
        {
            TVM.innerHTML=this.TVB('boxes',1);
            TVM.style.display='block';
        }
        for(TVQ in this.TVJ)
        {
            var TVj=TVN(this.TVJ[TVQ]);
            if(TVj&&TVj.disabled!=null)TVj.disabled=true;
        }
    }
    return true;
}


//------------------------------------------------------------------------------------
//      Name : TVE
//------------------------------------------------------------------------------------
//   Purpose : 
//------------------------------------------------------------------------------------
// Arguments : n/a
//------------------------------------------------------------------------------------
//   Returns : n/a
//------------------------------------------------------------------------------------
function TVE(TVk,TVl)
{
    for(var TVm in TVk)if(TVk[TVm]!=null)
    {
        if(typeof(TVk[TVm])=='object')
        {
            if(typeof(TVl[TVm])!='object')alert("Type mismatch ("+TVm+"). Array in place of scalar.");
            TVE(TVk[TVm],TVl[TVm]);
        }
        else
        {
            if(typeof(TVl[TVm])=='object')alert("Type mismatch ("+TVm+"). Scalar in place of array.");
            TVl[TVm]=TVk[TVm];
        }
    }
}


//------------------------------------------------------------------------------------
//      Name : TVC
//------------------------------------------------------------------------------------
//   Purpose : 
//------------------------------------------------------------------------------------
// Arguments : n/a
//------------------------------------------------------------------------------------
//   Returns : n/a
//------------------------------------------------------------------------------------
function TVC(TVn,TVW)
{
    var TVm=this.TVA.messages[TVn][TVW],TVo=2,TVp;
    if(!TVm)return false;
    if(typeof(TVm)=='function')TVm=TVm(this.TV8);
    for(;
    TVo<arguments.length;
    TVo++)
    for(TVp in arguments[TVo])TVm=TVm.replace('%'+TVp+'%',arguments[TVo][TVp]);
    TVm=TVm.replace('%form%',this.TV8);
    return TVm
}


//------------------------------------------------------------------------------------
//      Name : TVN
//------------------------------------------------------------------------------------
//   Purpose : 
//------------------------------------------------------------------------------------
// Arguments : n/a
//------------------------------------------------------------------------------------
//   Returns : n/a
//------------------------------------------------------------------------------------
function TVN(TVq)
{
    return(document.all?document.all[TVq]:(document.getElementById?document.getElementById(TVq):null));
}
