function CValidator()
{
	this.ClassName = "";
	this.debug = false;
	this.names = null;
	this.values = null;
	this.m_FormID = "";
	
	this._validate = _validate;
	this._init = _init;
	this.log = _log;
	
	function _log( sMethod, sBuf, bAlways)
	{
		if( this.debug ||
			bAlways )
		{
			alert( this.ClassName + "::" + sMethod + " " + sBuf );
		}
	}
	function _validate()
	{
		var isValid = true; 
		var message = ""; 
		for(x=0; x < this.names.length; x++) 
		{
			var form = document.forms[this.m_FormID];
			
			// we have a confirmation field.
			// The next element in the array is the one we must match
			// For instance "passwd_confirm", "passwd"
			if( this.names[x].indexOf( "_confirm" ) > 0 )
			{
				var txt0 = eval( "form.id_" + this.names[x] );
				var txt1 = eval( "form.id_" + this.names[x+1] );
				
				if( txt0.value.length == 0 ||
					txt1.value.length == 0 ||
					(txt0.value != txt1.value) ) 
				{
					isValid = false; 
			        message += this.names[x] + " and " + this.names[x+1] + " do not match";
				}
				
				// skip the next one
				x++;
			}
			else
			{
				var txtObj = eval( "form.id_" + this.names[x] );
			    //alert( "form name = " + form.name + "\ninput = " + txtObj.value);
			    
			    //document.getElementById( "id_" + this.names[x] );
			    
			    if( !txtObj )
			    {
			    	//message += "id_" + requiredFields[x] + " doesn't exist ";
			    	continue;
			    }
			    	
			    if( 0 == txtObj.value.length ) 
			    { 
					isValid = false; 
			        message += this.names[x] + " is required\n"; 
			    }
			}
		}
		
		if( message.length > 0 )
			alert( message );
			
		return( isValid );
	}
	
	function _init(names, values)
	{
		this.names = names;
		this.values = values;
		
		loadURLNVP();
		
		if( getURLV( "debug" ) != "1" )
			return;
			
		if( !this.names )
			return;//alert( "aRequiredFields is null" );
		if( !this.values )
			return;//alert( "aTestFields is null" );
		
		var sMsg = "";
		var elem = null;
		
		for(x=0; x < this.names.length; x++) 
		{ 
			elem = document.getElementById( "id_" + this.names[x] );
			
			sMsg += "Setting id_" + this.names[x] + "\t=>\t" + this.values[x] + "\n";
			
			if( elem )
				elem.value = this.values[x];
			else
			{
				sMsg += "elem is null\n";
				continue;
			}
			
		}
		
		//var check = document.getElementById( "id_windowq1_4" );
		//check.checked = true;
		
		
		// do it again for unique radio ids
		for(x=0; x < this.names.length; x++) 
		{ 
			for( y=0; y<5; y++ )
			{
				elem = document.getElementById( "id_" + this.names[x] + "_" + y );
				if( elem )
				{
					if( this.values[x] == y+1 )
						elem.checked = true;
				}
				else
					sMsg += "elem is null\n";
			}
		}
		
		
		if( g_DEBUG )
			alert( sMsg );
			
	}

}