
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,respuesta,acc){ // funcion generica, utilizada principalmente para los productos de la cotizacion
	ajax=nuevoAjax();

	if(acc == 9 || acc == 10){
		var tabla = 'cat_galeria';
		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
	if(acc == 30 || acc == 31){
		var tabla = 'destinos';
		var cod_tabla = 'id_destino';
	}else
	if(acc == 40 || acc == 41){
		var tabla = 'paises';
		var cod_tabla = 'id_pais';
	}else{
		var tabla = '';
		var cod_tabla = '';
	}

	ajax.open("GET", "include/ajax_resp.php?acc="+acc+"&valor1="+valor1+"&valor2="+valor2+"&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:  case 30: case 31: case 40: case 41:
					var datos = ajax.responseText.split('-');
					if(datos[0] == 1)
						actualizar_lista();
					
					if(acc == 4 || acc == 9 || acc == 14 || acc == 19 || acc == 30 || acc == 40){
						document.getElementById('btn_insertar').style.display  = '';
						document.getElementById('btn_modificar').style.display = 'none';
					}

					document.getElementById(respuesta).innerHTML=datos[1]; 
				break;
				case 29:
					document.getElementById(respuesta).innerHTML=ajax.responseText; 
					for(var i=0; i<=document.getElementById('num').value; i++){
						if(document.getElementById('detalles'+i+'_omit'))
							document.getElementById('detalles'+i+'_omit').value = document.getElementById('descripcion').value
					}
				break;
				default:
					document.getElementById(respuesta).innerHTML=ajax.responseText; 
				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 reload_list2(resp, id, tabla, opciones, acc){
	ajax=nuevoAjax();

	ajax.open("GET", "include/ajax_resp.php?acc="+acc+"&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 removeWin(frm_down){
	var fx = document.getElementById(frm_down);
	if(fx){
		for (i = 0; i < fx.elements.length; i++) {
			if(fx.elements[i].type == "select" || fx.elements[i].type == "select-one" || fx.elements[i].type == "select-multiple"){
				fx.elements[i].style.visibility = "visible";
			}
		}
	}
	var cuerpo = document.body;
	cuerpo.removeChild(document.getElementById('id_data'+frm_down));
	cuerpo.removeChild(document.getElementById('id_fondo'+frm_down));
}

function winPopup(pag, ancho, alto, frm_down){
	var h = 0; // height
	var w = 0; // width
	var top  = (window.screen.height - alto)/2 - 120;
	var left = (window.screen.width  - ancho)/2;

	if( typeof( window.innerHeight ) == 'number' ) {
		//no es IE
		pos = 'fixed';
	} else if( document.body && document.body.clientHeight ) {
		//IE 4 o superior
		pos = 'absolute';
	}

	h = document.body.scrollHeight;
	w = document.body.scrollWidth;
	
	var fondo = document.createElement('div');
	fondo.id = 'id_fondo'+frm_down;
	fondo.style.top = '0px';
	fondo.style.left= '0px';
	fondo.style.minHeight = '100%';
	fondo.style.backgroundColor = '#000000';
	fondo.style.filter = 'alpha(opacity=65)';
	fondo.style.opacity= '0.65';
	fondo.style.height = h+'px';
	fondo.style.width  = w+'px';
	fondo.style.zIndex = 1500;
	fondo.style.position = 'absolute';
	var cuerpo = document.body;
	cuerpo.appendChild(fondo);

	ajax_win=nuevoAjax();

	var c = pag.split('?');
	if(c.length <= 1){
		pag=pag+'?';
	}

	ajax_win.open("GET", pag+'&frm='+frm_down, true);
	ajax_win.onreadystatechange=function(){ 

		if (ajax_win.readyState==4){
			var contenedor= document.createElement('div');
			contenedor.id = 'id_data'+frm_down;
			contenedor.style.height = alto+'px';
			contenedor.style.width  = ancho+'px';
			contenedor.style.zIndex = 1500;
			contenedor.style.position = pos;
			contenedor.style.overflowY= 'auto';	
			contenedor.style.filter   = 'alpha(opacity=100)';
			contenedor.style.opacity  = '1';
			contenedor.style.top = top+'px';
			contenedor.style.left= left+'px';
			contenedor.style.backgroundColor = '#FFFFFF';
			contenedor.style.border = '1px'; 
			contenedor.style.borderColor = '#000000';
			contenedor.style.borderStyle = 'solid';
			cuerpo.appendChild(contenedor);
			contenedor.focus();

			document.getElementById('id_data'+frm_down).innerHTML =ajax_win.responseText;
			document.getElementById('id_fondo'+frm_down).innerHTML="";

			var fx = document.getElementById(frm_down);
			if(fx){
				for (i = 0; i < fx.elements.length; i++) {
					if(fx.elements[i].type == "select" || fx.elements[i].type == "select-one" || fx.elements[i].type == "select-multiple"){
						fx.elements[i].style.visibility = "hidden";
					}
				}
			}

		}else{
			document.getElementById('id_fondo'+frm_down).innerHTML="<img src='include/loadingAnimation.gif'>";
		}
		
	}

	ajax_win.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);
}
