
function nuevoAjax(){ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo */
	var xmlhttp=false; 

	try
	{ 
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); // Creacion del objeto AJAX para navegadores no IE
	}
	catch(e)
	{ 
		try
		{ 

			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); // Creacion del objet AJAX para IE 
		}
		catch(E)
		{
			xmlhttp=false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		xmlhttp=new XMLHttpRequest();
	} 

	return xmlhttp; // retornar el objeto AJAX

}

function cargaContenido(valor1,valor2,valor3,respuesta,acc){ // funcion generica, utilizada principalmente para los productos de la cotizacion
	ajax=nuevoAjax();

	if(acc == 9 || acc == 10){
		var tabla = 'album';
		var cod_tabla = 'id_cat';
	}else
	if(acc == 14 || acc == 15){
		var tabla = 'cat_noticias';
		var cod_tabla = 'id_cat';
	}else
	if(acc == 19 || acc == 20){
		var tabla = 'cat_encuestas';
		var cod_tabla = 'id_cat';
	}else{
		var tabla = '';
		var cod_tabla = '';
	}
	ajax.open("GET", "include/ajax_resp.php?acc="+acc+"&valor1="+valor1+"&valor2="+valor2+"&valor3="+valor3+"&tabla="+tabla+"&cod_tabla="+cod_tabla, true);

	ajax.onreadystatechange=function(){ 

		if (ajax.readyState==4){
		    switch(acc){
                case 3:	case 4: case 9:	case 10:  case 14: case 15:  case 19: case 20:
					var datos = ajax.responseText.split('-');
					if(datos[0] == 1)
						actualizar_lista();
					
					if(acc == 4 || acc == 9 || acc == 14 || acc == 19){
						document.getElementById('btn_insertar').style.display  = '';
						document.getElementById('btn_modificar').style.display = 'none';
					}

					document.getElementById(respuesta).innerHTML=datos[1]; 
				break;
         	}
		} 

	}

	ajax.send(null);
}

function cargaContenido2(valor1,valor2,valor3,respuesta,acc){ 
	ajax=nuevoAjax();
	ajax.open("GET", "include/ajax_resp.php?acc="+acc+"&valor1="+valor1+"&valor2="+valor2+"&valor3="+valor3, true);

	ajax.onreadystatechange=function(){ 

		if (ajax.readyState==4){
		    switch(acc){
                case 22: case 23:
					var datos = ajax.responseText.split('-');
					if(datos[0] == 1)
						actualizar_lista();
					
					if(acc == 22){
						document.getElementById('btn_insertar').style.display  = '';
						document.getElementById('btn_modificar').style.display = 'none';
					}

					document.getElementById(respuesta).innerHTML=datos[1]; 
				break;
         	}
		} 

	}

	ajax.send(null);
}

function cargaCiudad(valor,respuesta,acc){ // funcion generica, utilizada principalmente para los productos de la cotizacion
	ajax=nuevoAjax();
	ajax.open("GET", "include/ajax_resp.php?acc="+acc+"&valor="+valor, true);

	ajax.onreadystatechange=function(){ 

		if (ajax.readyState==4)	{
			document.getElementById(respuesta).innerHTML=ajax.responseText;
		}else{
			document.getElementById(respuesta).innerHTML="<img src=../images/cargar.gif width=16 height=16> <b>Cargando.... </b>";
		}

	}

	ajax.send(null);
}

function reload_list(resp, id, tabla, opciones){
	ajax=nuevoAjax();

	ajax.open("GET", "include/ajax_resp.php?acc=8&tabla="+tabla+"&opciones="+opciones+"&id="+id, true);

	ajax.onreadystatechange=function()	{ 

		if (ajax.readyState==4)	{
			document.getElementById(resp).innerHTML=ajax.responseText;
		}else{
			document.getElementById(resp).innerHTML="<img src=../images/cargar.gif width=16 height=16> <b>Cargando.... </b>";
		}

	}

	ajax.send(null);
}

function winPopup(pag, ancho, alto, layer){
	fondo = document.createElement('div');
	fondo.id = 'id_fondo';
	fondo.style.top = '0px';
	fondo.style.left= '0px';
	fondo.style.minHeight = '100%';
	fondo.style.backgroundColor = '#000';
	fondo.style.filter = 'alpha(opacity=65)';
	fondo.style.opacity= '0.65';
	fondo.style.height = window.screen.height;
	fondo.style.width  = window.screen.width;
	fondo.style.zIndex ='1500';
	fondo.style.position ='absolute';
	cuerpo = document.getElementById(layer);// ID del body
	cuerpo.appendChild(fondo);

	ajax=nuevoAjax();

//	alert("includes/tree_m4/show_data.php?id="+id);
	ajax.open("GET", pag, true);
	ajax.onreadystatechange=function(){ 

		if (ajax.readyState==4){
			contenedor = document.createElement('div');
			contenedor.id    = 'id_data';
			contenedor.align = 'center';
			contenedor.style.height = alto;
			contenedor.style.width  = ancho;
			contenedor.style.zIndex = '1550';
			contenedor.style.position ='absolute';
			contenedor.style.overflow ='hidden';	
			contenedor.style.filter   = 'alpha(opacity=100)';
			contenedor.style.opacity  = '1';
			contenedor.style.top = (window.screen.height - alto)/2 - 70;
			contenedor.style.left= (window.screen.width  - ancho)/2;
			contenedor.style.backgroundColor = '#FFFFFF';
			contenedor.style.border = '1px'; 
			contenedor.style.borderColor = '#000000';
			contenedor.style.borderStyle = 'solid';
			cuerpo.appendChild(contenedor);
		
			document.getElementById('id_data').innerHTML=ajax.responseText;
			document.getElementById('id_fondo').innerHTML="";
		}else{
			document.getElementById('id_fondo').innerHTML="<img src='includes/loading.gif'>";
		}
		
	}

	ajax.send(null);

}

function count_clicks(id_imagen){
	ajax=nuevoAjax();

	ajax.open("GET", "include/ajax_resp.php?acc=16&id_imagen="+id_imagen, true);

	ajax.onreadystatechange=function()	{ 

		if (ajax.readyState==4)	{
			return;
		}

	}

	ajax.send(null);
}