function retira_acentos(palavra) {
com_acento = 'áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ ';
sem_acento = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC_';
nova='';
for(i=0;i<palavra.length;i++) {
if (com_acento.search(palavra.substr(i,1))>=0) {
nova+=sem_acento.substr(com_acento.search(palavra.substr(i,1)),1);
}
else {
nova+=palavra.substr(i,1);
}
}
return nova.toLowerCase();
}


function welcome()
{
    texto = ''
    
    mdata      = new Date()
    mhora      = mdata.getHours()
    mdia       = mdata.getDate()
    mdiasemana = mdata.getDay()
    mmes       = mdata.getMonth()
    mano       = mdata.getYear()
    if (mhora < 12)
	texto += 'Bom dia - ';
    else if(mhora >=12 && mhora < 18)
	texto += 'Boa Tarde - ';
    else if(mhora >= 18 && mhora < 24)
	texto += 'Boa Noite - ';

    var months=new Array(13);
    months[1]=" de Janeiro de";
    months[2]=" de Fevereiro de";
    months[3]=" de Março de";
    months[4]=" de Abril de";
    months[5]=" de Maio de";
    months[6]=" de Junho de";
    months[7]=" de Julho de";
    months[8]=" de Agosto de";
    months[9]=" de Setembro de";
    months[10]=" de Outubro de";
    months[11]=" de Novembro de";
    months[12]=" de Dezembro de";
    var time=new Date();
    var lmonth=months[time.getMonth() + 1];
    var date=time.getDate();
    var year=time.getYear();

    if (year < 2000)
    {
	year = year + 1900;
    }

    texto += date + lmonth + " " + year
    $("#welcomer").html(texto);
}


$(document).ready(function() {
    $('.link-noticia').bind('click',function(){
	if($('#franquia-nome').val() == $('#franquia-matriz').val())
	{
	    //url = $('#home-link').val() + $('#franquia-matriz').val() +'/noticia/'
	    url = $('#home-link').val() +'noticia/'
	}
	else
	{
	    url = $('#home-link').val() + 'noticia/'
	}
	url += retira_acentos($(this).attr('id').split(" ").join('-')) + '/'
	window.location = url.toLowerCase()
    })

    $('.link-noticia-n').bind('click',function(){
	url = $('#home-link').val().split("/")
	url.pop()
	url.pop()
	url = url.join('/').replace(/\,/gi,'/') + '/' + $('#franquia-matriz').val() + '/noticia/'
	url += retira_acentos($(this).attr('id').split(" ").join('-')) + '/'
	window.location =  url.toLowerCase()
    })

    $('.link-noticia-img').bind('click',function(){
	if($('#franquia-nome').val() == $('#franquia-matriz').val())
	{
	    url = $('#home-link').val() + $('#franquia-matriz').val() +'/noticia/'
	}
	else
	{
	    url = $('#home-link').val() + 'noticia/'
	}
	url += retira_acentos($(this).attr('id').split(" ").join('-')) + '/'
	window.location = url.toLowerCase()
    })

    $('.link-noticia-img-n').bind('click',function(){
	url = $('#home-link').val().split("/")
	url.pop()
	url.pop()
	url = url.join('/').replace(/\,/gi,'/') + '/' + $('#franquia-matriz').val() + '/noticia/'
	url += retira_acentos($(this).attr('id').split(" ").join('-')) + '/'
	window.location =  url.toLowerCase()
    })

    $('#tbl_banner_pub tr:last').remove()
    $('.tbl_banner_pub img:last').remove()
    $('#tbl_banner_pub img:last').remove()

    $('.flash_1').each(function(){
	mv = $(this).attr('url')
	link = $(this).attr('link')
	bann = ''
	//bann = '<a href="'+link+'" class="flash_ad">'
	bann += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="145">'
	bann += '<param name="movie" value="banners/'+mv+'">'
	bann += '<param name="quality" value="high">'
	bann += '<embed src="banners/'+mv+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="145">'
	bann += '</embed>'
	bann += '</object>'
	//bann += '</a>'
	$(this).html(bann)
    })

    $('.flash_1').each(function(){
	link = $(this).attr('link')
	if($.trim(link) == '')
	{
	    $(this).removeAttr('href')
	}
    })

    $('.flash_0').each(function(){
	link = $(this).attr('link')
	if($.trim(link) == '')
	{
	    $(this).removeAttr('href')
	}
    })
    
    $('.flash_ad').each(function(){
	link = $(this).attr('link')
	if($.trim(link) == '')
	{
	    $(this).removeAttr('href')
	}
    })
})



window.onload = function()
{
    $('.slideshow img:last').remove()
    $('.slideshow').show()
    $('.slideshow').cycle({
	fx: 'fade',
	speed:  7000
    })
    $('.ui-tabs-nav li:first').addClass('ui-tabs-selected')

    $("#featured").tabs({
	fx:{
	    opacity: "toggle"
	}
    }).tabs("rotate", 5000, true);
    
    $("#featured").hover(
	function() {
	    $("#featured").tabs("rotate",0,true);
	},
	function() {
	    $("#featured").tabs("rotate",5000,true);
	})
    welcome()
    $('.ui-tabs-nav li:last').remove()
    $('#all-fragments div:last').remove()
    $('#all-fragments').show()
    $('#all-noticias div:last').remove()
    $('#all-noticias-n div:last').remove()
}
swfobject.registerObject("myId", "9.0.0", "expressInstall.swf");
swfobject.registerObject("banner_franquia", "9.0.0", "expressInstall.swf");

function loadMap(franquia,ll)
{
    //javascript:void(prompt('',gApplication.getMap().getCenter()))
    arr = ll.split(',')
    lat = $.trim(arr[0])
    lon = $.trim(arr[1])
    if(lat != '' && lon != '')
    {
	$('body').append('<div id="dialog" title="Mapa"></div>')
	$('body').append('<div id="removecss"><link href="jscripts/jquery/ui/map/jquery-ui.css" type="text/css" rel="stylesheet" /></div>')
	$( "#dialog" ).dialog({
	    width:800,
	    height:600,
	    modal: true,
	    buttons: {
		"Fechar": function() {
		    $("#removecss").remove()
		    $(this).dialog("close")
		    $(this).remove()
		    $("#removecss").remove()
		}
	    },
	    open: function(ev,ui){
		$(this).gMap({
		    markers: [{
			latitude: lat,
			longitude: lon,
			html: franquia,
			popup: true
		    }],
		    zoom: 16
		})
	    },
	    close: function(ev, ui) {
		window.location = window.location
		$("#removecss").remove()
		$(this).remove()
		$("#removecss").remove()
	    }
	})
    }
}

