/* CATALOGO DE FUNCIONES 
 *  -   createXMLHttpRequest()--> Creo el objeto XMLHttpRequest
 *  -   makeRequestAJAX(url,accion)--> Hace la llamada ajax que corresponda
 */   
<!--
/**
 * Función que realiza una llamada AJAX a la url especificada y trata el evento con la función definida en acción
 * http://www.baluart.net/articulo.php?id_art=225. Ejemplo básico de AJAX
 */
var http;
var layerProv='';
var layerCodProv=''
function createXMLHttpRequest() {
    var httpReq;
    if (httpReq != null && httpReq.readyState != 0 && httpReq.readyState != 4) { 
    	httpReq.abort(); 
    } 
    try { 
      	httpReq = new XMLHttpRequest(); 
    } 
    catch (error) { 
    	try { 
            httpReq = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	catch (error) { 
            httpReq = null; 
	} 
    }
    return httpReq;
}
/* url del servlet que genera el xml, acción el javalscril al que se llama cuando se recibe la respuesta*/
function makeRequestAJAXNew(url,accion,method) {
    http=createXMLHttpRequest();
    http.onreadystatechange = accion; 
    http.open(method,url,true); 
    //http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded charset=UTF-8');
    http.send(null); 
    return true; 
}
/*Cargo las provincias en la capa correspondiente de un determinado pais*/
function cargarProvinciasNew(codPais,lProv,lCProv) {
    var codGruEnv=document.getElementById("cod_grupo_envios").value;
    var al=Math.random();
    if(codPais!='')    {
        layerProv=lProv;//variable global para capas de provincias
        layerCodProv=lCProv;
        //alert(layerCodProv+", lProv: "+lProv+", lCProv: "+lCProv+",codGruEnv: "+codGruEnv);
        //act='/GestionAccionesAjaxServlet?accion=field_info_provincias_bd&cod_pais='+codPais+"&nocache="+al;
        act='/GestionAccionesAjaxServlet?accion=field_info_pge_bd&cod_pais='+codPais+"&cod_grupo_envios="+codGruEnv+"&nocache="+al;
        var func = handleCargarProvincias;
        makeRequestAJAXNew(act,func,'GET');
    }
    else {//reinicio el elemento
        var tdProvincia= document.getElementById(lProv);
        document.getElementById(lProv).innerHTML="";
    }
}
/*Función que a partir del XML paises escribo un select con los provincias asociados a un pais y a un grupo de envio*/
function handleCargarProvincias(){
    var codProvSel='';
    lP=layerProv;
    lCP=layerCodProv;
    if((http.readyState == 4)&&(http.status == 200)){
    //alert("http: "+http.readyState+",status: "+http.status+"-"+lP+", arg2: "+arguments[0]+", arg1: "+arguments[1])
    if(document.getElementById(lCP)) codProvSel=document.getElementById(lCP).value;
    var tdProvincia= document.getElementById(lP);
    document.getElementById(lP).innerHTML="";
    if (http.responseText.charAt(0) == "<") { 
        if(http.responseXML.getElementsByTagName("provincias_grupo_envios")[0]){//si hay item
            //alert("codProvSel: "+codProvSel+", layerCodProv: "+layerCodProv+", lCP: "+lCP)
            var root_node = http.responseXML.getElementsByTagName('provincias_grupo_envios').item(0);//
            lenghtElements=root_node.childNodes.length;//número de items a tratar
            //alert("lenghtElements: "+lenghtElements)
            //creando tr provincia
            textNodeProv = document.createTextNode(txtNode2+"*");
            strongNodeProv=document.createElement("strong");
            strongNodeProv.appendChild(textNodeProv);            
            tdProvincia.appendChild(strongNodeProv);  
            //tdProvincia.appendChild(textNodeProv);
            selectNodeProv= document.createElement("select");
            selectNodeProv.setAttribute("name",lP+"_sel");
            selectNodeProv.setAttribute("id",lP+"_sel");
            //alert("CPROV: "+http.responseXML.getElementsByTagName("cod_provincia")[0].childNodes[0].nodeValue);
            for(i=0;i<(lenghtElements);i++){
                if(http.responseXML.getElementsByTagName("provincia")[i]){
                    provincia=http.responseXML.getElementsByTagName("provincia")[i].childNodes[0].nodeValue;
                    codProv=http.responseXML.getElementsByTagName("cod_provincia")[i].childNodes[0].nodeValue;
                    mascaraCP=http.responseXML.getElementsByTagName("mascara_cp")[i].childNodes[0].nodeValue;
                    //if(i<5)alert("provincia: "+provincia+", codProv: "+codProv+", mascaraCP: "+mascaraCP)
                    optionNodeProv= document.createElement("option");
                    optionNodeProv.setAttribute("value",codProv);
                    if(codProvSel==codProv)optionNodeProv.setAttribute("selected","true");
                    optionNodeProv.appendChild(document.createTextNode(provincia)); 
                    selectNodeProv.appendChild(optionNodeProv);
                    codPostales[codProv]=mascaraCP;//cargo las máscaras en una tabla para validar los códigos postales
                }//fin if existen los objetos en cuestión
            }
            //tdNodeProv.appendChild(selectNodeProv);  
            tdProvincia.appendChild(selectNodeProv); 
        }
        else {//si no existe reinicio campos
            //document.getElementById(lP).setAttribute('value','');
           codPostales[codProv]=new Array();
        }
    } 
    else alert("NO HAY DOCUMENTO XML PROVINCIAS_PAIS")
    //layerProv='';
    return true; 
    }
}
/*Cargo las tarifas de un producto asociado a un proveedor y a su grupo de tarifas*/
var cgt='';
function loadPriceSupplier(codProd,codProv,codGrupoTarifas) {
    var al=Math.random();
    if(codProv!='')    {
        //alert("codProd: "+codProd+", codProv: "+codProv+",codGrupoTarifas:"+codGrupoTarifas);
        act='/GestionAccionesAjaxServlet?accion=field_info_proveedores_bd&cod_producto='+codProd+'&cod_proveedor='+codProv+"&nocache="+al;
        var func = handlePriceSupplier;
        cgt=codGrupoTarifas;
        makeRequestAJAXNew(act,func,'GET');
    }
    else {//reinicio el preico de coste y el precio Recomendado
        document.getElementById("pc_"+codGrupoTarifas).value='';
        document.getElementById("pr_"+codGrupoTarifas).value='';
    }
}
function handlePriceSupplier(){
    if((http.readyState == 4)&&(http.status == 200)){
        //alert("http: "+http.readyState+",status: "+http.status+"-, arg2: "+arguments[0]+", arg1: "+arguments[1])
        if (http.responseText.charAt(0) == "<") { 
            if(http.responseXML.getElementsByTagName("productos_proveedores")[0]){//si hay item
                var root_node = http.responseXML.getElementsByTagName('productos_proveedores').item(0);//
                lenghtElements=root_node.childNodes.length;//número de items a tratar
                for(i=0;i<(lenghtElements);i++){
                    if(http.responseXML.getElementsByTagName("producto_proveedor")[i]){
                        pCoste=http.responseXML.getElementsByTagName("precio_coste")[i].childNodes[0].nodeValue;
                        pvpRecomendado=http.responseXML.getElementsByTagName("pvp_recomendado")[i].childNodes[0].nodeValue;
                        //alert("pvp_recomendado: "+pvp_recomendado+",precio_coste:"+precio_coste)
                        document.getElementById("pc_"+cgt).value=pCoste;
                        document.getElementById("pr_"+cgt).value=pvpRecomendado;
                        cgt='';
                    }
                }
            }
        } 
        //else alert("NO HAY DOCUMENTO XML PRODUCTOS_PROVEEDOR")
        return true; 
    }
}
/*Obtiene el pvp_recomendado y el factor_impuesto de un producto determinado asociado a una tarifa concreta*/
function loadPriceProduct(codProd,codGrupoTarifas) {
    var al=Math.random();
    if(codProd!='')    {
        //alert("codProd: "+codProd+", cgt: "+codGrupoTarifas);
        act='/GestionAccionesAjaxServlet?accion=field_info_productos_tarifas_bd&cod_producto='+codProd+"&cod_grupo_tarifas="+codGrupoTarifas+"&nocache="+al;
        var func = handlePriceProduct;
        cgt=codGrupoTarifas;
        makeRequestAJAXNew(act,func,'GET');
    }
    //else alert("Producto vacio no hago nada");

}
function handlePriceProduct(){
    if((http.readyState == 4)&&(http.status == 200)){
       //alert("http: "+http.readyState+",status: "+http.status+"-, arg2: "+arguments[0]+", arg1: "+arguments[1])
        if (http.responseText.charAt(0) == "<") { 
            if(http.responseXML.getElementsByTagName("productos_tarifas")[0]){//si hay item
                var root_node = http.responseXML.getElementsByTagName('productos_tarifas').item(0);//
                lenghtElements=root_node.childNodes.length;//número de items a tratar
                for(i=0;i<(lenghtElements);i++){
                    if(http.responseXML.getElementsByTagName("producto_tarifa")[i]){
                        facImp=http.responseXML.getElementsByTagName("factor_impuesto")[i].childNodes[0].nodeValue;
                        pvpRecom=http.responseXML.getElementsByTagName("pvp_recomendado")[i].childNodes[0].nodeValue;
                        pvpFinal=http.responseXML.getElementsByTagName("precio_final")[i].childNodes[0].nodeValue;
                        //alert("pvp_facImp: "+facImp+",pvpRecom:"+pvpRecom)
                        document.getElementById('pf_ins').value=pvpFinal;
                        document.getElementById('fi_ins').value=facImp;
                        document.getElementById('cant_ins').value=1;
                        cgt='';
                    }
                }
            }
        } 
        //else alert("NO HAY DOCUMENTO XML PRODUCTOS_TARIFAS")
        return true; 
    }
}
/*Obtiene el pvp_coste de un producto asociado a un proveedor*/
function loadPriceSupplier2(codProd,codProv) {
    var al=Math.random();
    if(codProd!='')    {
        //alert("codProd: "+codProd+", codProv: "+codProv);
        act='/GestionAccionesAjaxServlet?accion=field_info_proveedores_bd&cod_producto='+codProd+'&cod_proveedor='+codProv+"&nocache="+al;
        var func = handlePriceSupplier2;
        makeRequestAJAXNew(act,func,'GET');
    }
    //else alert("Producto vacio no hago nada");
}
function handlePriceSupplier2(){
    if((http.readyState == 4)&&(http.status == 200)){
       //alert("http: "+http.readyState+",status: "+http.status+"-, arg2: "+arguments[0]+", arg1: "+arguments[1])
        if (http.responseText.charAt(0) == "<") { 
            if(http.responseXML.getElementsByTagName("productos_proveedores")[0]){//si hay item
                var root_node = http.responseXML.getElementsByTagName('productos_proveedores').item(0);//
                lenghtElements=root_node.childNodes.length;//número de items a tratar
                for(i=0;i<(lenghtElements);i++){
                    if(http.responseXML.getElementsByTagName("producto_proveedor")[i]){
                        //facImp=http.responseXML.getElementsByTagName("factor_impuesto")[i].childNodes[0].nodeValue;
                        preCoste=http.responseXML.getElementsByTagName("precio_coste")[i].childNodes[0].nodeValue;
                        //alert("pvp_facImp: "+facImp+",pvpRecom:"+pvpRecom)
                        document.getElementById('pf_ins').value=preCoste;
                        //document.getElementById('fi_ins').value=facImp;
                        document.getElementById('cant_ins').value=1;
                    }
                }
            }
        } 
        //else alert("NO HAY DOCUMENTO XML PRODUCTOS_TARIFAS")
        return true; 
    }
}

-->