
/*
 * Asigna a combo provincias un ajax para la carga de municipios
 * Ambito de uso: Index Avanzadas, Index Blancas
 */
function chageProvDv(url_serv, text_todos, texto_cargando, lang)
{
    $("select[name=prov]").change(function () {
        var id = $("select[name=prov] option:selected").val();
        jsLoading('mun', texto_cargando);
        $.ajax({
                url: url_serv + "index.php?ajax=&lang="+lang+"&prov=" + id,
                cache: false,
                success: function (html) {
                    $('#mun_dv').empty();
                    $('#mun_dv').html(html);
                    changeMunDv(url_serv, texto_cargando, lang);
                    $('#loc_dv').empty();
                    $('#loc_dv').html(emptySelect('loc', text_todos));
                }
            });
    });
}

/*
 * Asigna a combo muncipios un ajax para la carga de localidades
 * Ambito de uso: Index Avanzadas, Index Blancas
 */
function changeMunDv(url_serv, texto_cargando, lang)
{
    $("select[name=mun]").change(function () {
        var id = $("select[name=mun] option:selected").val();
        jsLoading('loc', texto_cargando);
        $.ajax({
                url: url_serv + "index.php?ajax=&lang="+lang+"&mun=" + id,
                cache: false,
                success: function (html) {
                    $('#loc_dv').empty();
                    $('#loc_dv').html(html);
                }
            });
    });
}
function emptySelect(id, text_todos)
{
	if (text_todos == '') { text_todos = 'Todos'; }
    return "<select name='"+id+"' id='"+id+"'><option value='0'>" + text_todos + "</option></select>";
}

function jsLoading(id, texto_cargando)
{
	if (texto_cargando == '') { texto_cargando = 'Cargando'; }
	if (document.getElementById(id)) {
	    var combobox = document.getElementById(id);
	    for (var i = (combobox.options.length-1); i >= 0; i--) {
	        combobox.options[i]=null;
	    }
	    combobox.options.add(new Option(texto_cargando,1));
	}
}
function mailnobot(part1, part2) {
	correo = part1 + '@' + part2;
	document.location.href = 'mailto:' + correo;
}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
$(function()
{
	$(".mostrarNavCliente").click(function() {
	$(".navCliente").fadeToggle("fast", "linear");});
});

$(function()
{
	$(".mostrarIdioma").click(function() {
	$(".idioma").fadeToggle("fast", "linear");});
});

function cargarFotoIndex(INT, url_total){
	document.location.href = url_total + INT + '/';
}

function cargarDetalleNoticia(num){
	document.getElementById('num').value = num;
	document.forms['formulario_news'].submit()
}
function cargarQDQ(select_lang) {
	document.location.href = "http://" + select_lang + ".qdq.com/" + document.getElementById('search').value;
}
		
var div_expandido = false;
function cargar_debug() {
	div_expandido = !div_expandido;
	document.getElementById("div_debug2").style.overflow = 'hidden';
	if (document.getElementById("tx_xml")) document.getElementById("tx_xml").style.display = 'none';
	setTimeout(div_creciendo, 10);
}
function div_creciendo() {
	altura = document.getElementById("div_debug").style.height.replace("px","");
	anchura = document.getElementById("div_debug").style.width.replace("px","");
	if (div_expandido) { h_crece = 10; w_crece = 7; } else { h_crece = -10; ; w_crece = -7; }
	altura = parseInt(altura) + h_crece;
	anchura = parseInt(anchura) + w_crece;
	if (altura >= 17 && altura <= 300) {
		document.getElementById("div_debug").style.height = altura+"px";
		document.getElementById("div_debug").style.width = anchura+"px";
		setTimeout(div_creciendo, 10);
	} else {
		if (altura-30 < 0) { document.getElementById("div_debug2").style.height = "0px"; } else { document.getElementById("div_debug2").style.height = altura-30+"px"; }
		if (anchura-10 < 0) { document.getElementById("div_debug2").style.width = "0px"; } else { document.getElementById("div_debug2").style.width = anchura-10+"px"; }
		document.getElementById("div_debug2").style.overflow = 'scroll';
		if (document.getElementById("tx_xml")) document.getElementById("tx_xml").style.display = '';
	}
}
// Estadisticas plantillas nuevas
function setStadistic(url_serv, tipo, referencia, lang, cli, enlace) {
    $.ajax({
            url: url_serv + "/index.php?d='+(Math.random()*100000)+'&ajax=&tipo=" + tipo + "&referencia=" + referencia + "&lang=" + lang + "&cli=" + cli
        });
    if (enlace !='' && enlace != undefined) {
    	// Dejo un tiempo para que cargue la página, porque sino no funciona
    	setTimeout("cargarEnlace('"+enlace+"');",500);
    }
}
function cargarEnlace(enlace) {
	document.location.href = enlace;
}
function enviarFormulario(url_serv, tipo, referencia, lang, cli) {
	setStadistic(url_serv, tipo, referencia, lang, cli); 
	setTimeout("document.forms['formulario'].submit();",500);
}
function trazarRuta(url_serv, tipo, referencia, lang, cli) {
	setStadistic(url_serv, tipo, referencia, lang, cli); 
	setTimeout("traceRoute();",500);
}
function cargarDetalleNoticiaPrevio(num, url_serv, tipo, referencia, lang, cli) {
	setStadistic(url_serv, tipo, referencia, lang, cli); 
	setTimeout("cargarDetalleNoticia("+num+");",500);
}
$(function(){
	$.ajaxSetup({
		cache: false
	});
	$("a[data-stats]").click(function(event) {
		var dom = '';
		var stats = $(this).data('stats').split(';');
	 
		if (document.domain.indexOf('infoplus') != -1 || document.domain.indexOf('qdqdesa') != -1)
			dom = stats[0];
		else
			dom = 'http://'+document.domain;
		$.ajax({
			url: dom + "/index.php",
			data: { ajax: '', tipo: stats[1], referencia: stats[2], lang: stats[3], cli: stats[4] },
			async: false
		});
		return true;
	});
});


