function GetXmlHttpObject() {
    var xmlHttp=null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    } catch(e) {
        // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
  return xmlHttp;
}
//***************************************************************
function listaItem(valor)
{
    xmlHttp=GetXmlHttpObject();
    if(xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    
    xmlHttp.open("GET", "./listaitem.php?id=" + valor, true);
    xmlHttp.onreadystatechange = handleHttpResponse;
    xmlHttp.send(null);
}

function handleHttpResponse()
{
    if(xmlHttp.readyState==4 && xmlHttp.status == 200) {
        var resposta = xmlHttp.responseText.split(',');
        var pegaUndefined = resposta.pop();
        var campo;
        var campo2;
        var campo3;
        
        campo = window.document.formServicosMenu.itemMenu;
        campo2 = window.document.formServicosMenu.tipoMenu;
        campo3 = window.document.formServicosMenu.subtipoMenu;
        
        if(resposta.length == 0)
        {
            campo.options.length = 0;
            campo2.options.length = 0;
            campo3.options.length = 0;
            campo.options[0] = new Option( 'Item', '0' );
            campo2.options[0] = new Option( 'Tipo', '0' );
            campo3.options[0] = new Option( 'Subtipo', '0' );
            
            return false;
        }
        
        campo.options.length = 0;
        campo.options[0] = new Option( 'Item', '0' );
        for( j = 0; j < resposta.length; j++ )
		 {
		    string = resposta[j].split( "|" );
			campo.options[j + 1] = new Option( unescape(string[1]), string[0].replace(/[\n\r\t]/g, '') );
		 }
    }
}
//***************************************************************
function listaTipo(valor)
{
    xmlHttp=GetXmlHttpObject();
    if(xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    
    xmlHttp.open("GET", "./listatipo.php?id=" + valor, true);
    xmlHttp.onreadystatechange = handleHttpResponse2;
    xmlHttp.send(null);
}

function handleHttpResponse2()
{
    if(xmlHttp.readyState==4 && xmlHttp.status == 200) {
        var resposta = xmlHttp.responseText.split(',');
        var pegaUndefined = resposta.pop();
        var campo;
        var campo2;
        
        campo = window.document.formServicosMenu.tipoMenu;
        campo2 = window.document.formServicosMenu.subtipoMenu;
        
        if(resposta.length == 0)
        {
            campo.options.length = 0;
            campo2.options.length = 0;
            campo.options[0] = new Option( 'Tipo', '0' );
            campo2.options[0] = new Option( 'Subtipo', '0' );
            
            return false;
        }
        
        campo.options.length = 0;
        campo.options[0] = new Option( 'Tipo', '0' );
        for( j = 0; j < resposta.length; j++ )
		 {
		    string = resposta[j].split( "|" );
			campo.options[j + 1] = new Option( unescape(string[1]), string[0].replace(/[\n\r\t]/g, '') );
		 }
    }
}
//***************************************************************

function listaSubtipo(valor)
{
    xmlHttp=GetXmlHttpObject();
    if(xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    
    xmlHttp.open("GET", "./listasubtipo.php?id=" + valor, true);
    xmlHttp.onreadystatechange = handleHttpResponse3;
    xmlHttp.send(null);
}

function handleHttpResponse3()
{
    if(xmlHttp.readyState==4 && xmlHttp.status == 200) {
        var resposta = xmlHttp.responseText.split(',');
        var pegaUndefined = resposta.pop();
        var campo;
        
        campo = window.document.formServicosMenu.subtipoMenu;
        
        if(resposta.length == 0)
        {
            campo.options.length = 0;
            campo.options[0] = new Option( 'Subtipo', '0' );
            
            return false;
        }
        
        campo.options.length = 0;
        campo.options[0] = new Option( 'Subtipo', '0' );
        for( j = 0; j < resposta.length; j++ )
		 {
		    string = resposta[j].split( "|" );
			campo.options[j + 1] = new Option( unescape(string[1]), string[0].replace(/[\n\r\t]/g, '') );
		 }
    }
}
//***************************************************************
