//
// Inicializa a classe VHTML
//
function Vhtml() {    
	Vhtml.init  = function() {
		var req;
		
		try {
			req     = new ActiveXObject( "Microsoft.XMLHTTP" );
		
		} catch( e ) {
			try {
				req   = new ActiveXObject( "Msxml2.XMLHTTP" );
			
			} catch( ex ) {
				try {
					req = new XMLHttpRequest();
				
				} catch( exc ) {
					req = null;
				}
			}
		}
		
		return req;
	}
	
	//
	// Executa a URL informada e trata o retorno de acordo com o tipo especificado
	//
	Vhtml.open = function( str_url, str_function ) {
		var vhtml      = Vhtml.init();
		
		if ( vhtml ) {
			var boo_post = Vhtml.open.arguments[2] ? Vhtml.open.arguments[2] : null;
			
			if ( boo_post ) {
				vhtml.open( "POST", str_url, true );
				vhtml.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
			
			} else
				vhtml.open( "GET", str_url, true );
			
			vhtml.onreadystatechange = function() {
				if ( vhtml.readyState == 4 ) {
					if ( vhtml.status == 200 ) {
						// Obtêm a resposta do PHP / DHTML
						var str_result = vhtml.responseText;
						
						// Não obteve resposta do PHP
						if ( !str_result )
							return false;
						
						// Executa a função de retorno
						eval( str_function + '( "' + str_result + '" );' );
						
					} else {
						// Exibe a mensagem de erro
						alert( 'Error ' + vhtml.status + ': ' + vhtml.statusText );
						return false;
					}
				}
			}
			
			vhtml.send( boo_post );
		}
	}
}

new Vhtml();