var carregando_segmento = 'not';
var url_site = 'http://www.revistaestilofashion.com.br/';

function openAnuncio(img,w,h)
{
	var img_h = 0, img_w = 0, pop_h = 0, pop_w = 0;
	img_h = h;
	img_w = w;
	pop_h = h+40;
	pop_w = w+40;
	var janela = null
janela=window.open(url_site + 'publicidade/ver_anuncio/' + img + '/' + img_w + '/' + img_h,'Anuncio','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=' + pop_w + ',height=' + pop_h + ', left=, top=');
}

function remove_space(valor) 
	{
		if (valor == null || valor == "")
			{
				return "";
			}
		else
			{
				return valor.replace(/ /g, "");
				//return valor.replace(/^\s+|\s+$/g, "");
		}
}

function url_encode(str) {  
    var hex_chars = "0123456789ABCDEF";  
    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;  
    var n, strCode, hex1, hex2, strEncode = "";  

    for(n = 0; n < str.length; n++) {  
        if (noEncode.test(str.charAt(n))) {  
            strEncode += str.charAt(n);  
        } else {  
            strCode = str.charCodeAt(n);  
            hex1 = hex_chars.charAt(Math.floor(strCode / 16));  
            hex2 = hex_chars.charAt(strCode % 16);  
            strEncode += "%" + (hex1 + hex2);  
        }  
    }  
    return strEncode;  
}  

  // url_decode version 1.0 
    function url_decode(str) { 
        var n, strCode, strDecode = ""; 

        for (n = 0; n < str.length; n++) { 
            if (str.charAt(n) == "%") { 
                strCode = str.charAt(n + 1) + str.charAt(n + 2); 
                strDecode += String.fromCharCode(parseInt(strCode, 16)); 
                n += 2; 
            } else { 
                strDecode += str.charAt(n); 
            } 
        } 

        return strDecode; 
	}

function lists_segs(seg) 
{
	if (carregando_segmento == "sim") 
	{
		if (remove_space(window['var' + seg]) == "")  {
			$('#combo-'+seg).find('option').remove().end().append("<option disabled>Aguarde um momento</option>");
			window['proximo'] = seg;
			return false;
		}
		else { 
			return false;
		}
	}
					 
	if (remove_space(window['var' + seg]) == "") 
	{
		carregando_segmento = "sim";
		window['var' + seg] = '1';
		$("#loading").fadeIn("normal");
		$('#combo-'+seg).find('option').remove().end().append("<option disabled>Um momento por favor...</option>");
				
		$.post(url_site + "publicidade/ajax_listar_segmentos/",{search:seg},function(html) 
		{
			$("#loading").fadeOut("normal");
			$('#combo-'+seg).find('option').remove().end().prepend(url_decode(html));
			carregando_segmento = "nao";
			if (remove_space(window['proximo']) != "") { 
				lists_segs(window['proximo']); 
			}
		});
	}
}// JavaScript Document

$(function() {
	$('#container-1 > ul').tabs();
	$('#combo-a').find('option').remove().end().append("<option value='' disabled>Clique em uma letra</option>");
	$('#combo-a').find('option').end().append("<option value='' disabled>para ver os anunciantes</option>");
	$('#combo-a').find('option').end().append("<option value='' disabled>dos segmentos</option>");
	$('select[@id^=combo-]').click(function()
	{
		var id = $(this).val();
		if (remove_space(id) == "") { 
			return false; 
		}
		
		window.location = url_site + "publicidade/ver_segmento/" + id + ".html";
	});/*FIM*/
	  
	if (screen.width >= 1024)
	{
		$.post(url_site + "publicidade/ajaxlistarclientes/",function(html) 
		{
			$("#box_1024").html(html);
		});
	}
	
});
