var myWidth;
var myHeight;

function soma(valor1,valor2,operador,objID,txt){
  
  var total = eval(valor1 + operador + valor2);
  
  var obj = document.getElementById(objID);
  obj.value = total;
  
  var totais = $('.total');
  var totalf = 0;
  
  for(i=0;i<totais.length;i++){
    totalf+=parseFloat(totais[i].value);
  }
  
  $('#total_final').html(totalf + " " + txt);
  $('#total_final2').attr("value",totalf);
}

function getSize() {

  
  if( typeof( window.innerWidth ) == 'number' ) { 
  
  //Non-IE 
  
  myWidth = window.document.body.scrollWidth;
  myHeight = window.document.body.scrollHeight; 
  
  } else if( document.documentElement && 
  
  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
  
  //IE 6+ in 'standards compliant mode' 
  
  myWidth = document.documentElement.scrollWidth; 
  myHeight = document.documentElement.scrollHeight 
  
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
  
  //IE 4 compatible 
  
  myWidth = document.body.scrollWidth; 
  myHeight = document.body.scrollHeight; 
  
  }
  var tamanho = new Array();
  tamanho[0] = myWidth;
  tamanho[1] = myHeight; 
  
  return  tamanho;
}
function montavideo(lg,id,flash,w,h) {
  
   //altera o tamanho do fundo opaco para as dimensões totais da página
  var tam = getSize();

    
      
  for(j=1;j<blc.length;j++){
      var obj1 = document.getElementById("flash3_Mov"+blc[j]);
      var obj2 = document.getElementById("btn_flash"+blc[j]);
      if(obj1!=null){
        obj1.style.display='none';
      }
      if(obj2!=null){
        obj2.style.display='none';
      }
    }
 
  
  var btn = document.getElementById("btn_flash"+id);
  var flsh = document.getElementById("flash3_Mov"+id);
  var div_flash = document.getElementById("div_flash");
  
  if(flsh!=null){
    flsh.style.display='';
   
  }
  if(btn!=null){
    btn.style.display='';
  }
  if(div_flash!=null){
  //alert("OK");
   div_flash.style.left = (tam[0] - w)/2 + "px";
   div_flash.style.top =   "300px";
  }
  
  var fundo_o = document.getElementById("fundo_opaco");
  if(fundo_o!=null){
    fundo_o.style.display='';
    fundo_o.style.width = tam[0]+"px";
    fundo_o.style.height =  tam[1]+"px";
  }
  
  //alert(flash);
   
  
  
	var fo2 = new FlashObject("flash/video2.swf", "movie"+id,533,300, "9", "000000");
	fo2.addParam("wmode", "transparent");
	fo2.addParam("allowFullScreen", "true");
	//fo2.addVariable("servidor", "http://www.livromilionario.com");
  fo2.addVariable("videoID",slocation + "/" + flash);
  fo2.addVariable("typePlay", true);
	fo2.write("flash3_Mov"+id);
	// ]]>
}

function montavideo2(lg,id,flash,w,h) {
  
   //altera o tamanho do fundo opaco para as dimensões totais da página
  var tam = getSize();

  
      
  for(j=1;j<blc.length;j++){
      var obj1 = document.getElementById("flash3_Mov"+blc[j]);
      var obj2 = document.getElementById("btn_flash"+blc[j]);
      if(obj1!=null){
        obj1.style.display='none';
      }
      if(obj2!=null){
        obj2.style.display='none';
      }
    }
 
  
  var btn = document.getElementById("btn_flash"+id);
  var flsh = document.getElementById("flash4_Mov"+id);
  var div_flash = document.getElementById("div_flash");
  
  if(flsh!=null){
    flsh.style.display='';
   
  }
  if(btn!=null){
    btn.style.display='';
  }
  if(div_flash!=null){
  //alert("OK");
   div_flash.style.left = (tam[0] - w)/2 + "px";
   div_flash.style.top =   "300px";
  }
  
  var fundo_o = document.getElementById("fundo_opaco");
  if(fundo_o!=null){
    fundo_o.style.display='';
    fundo_o.style.width = tam[0]+"px";
    fundo_o.style.height =  tam[1]+"px";
  }
  
  //alert(flash);
   
  
  
	var fo2 = new FlashObject("flash/video2.swf", "movie"+id,533,300, "9", "000000");
	fo2.addParam("wmode", "transparent");
	fo2.addParam("allowFullScreen", "true");
	//fo2.addVariable("servidor", "http://www.livromilionario.com");
  fo2.addVariable("videoID",slocation + "/flash/" + flash);
  fo2.addVariable("typePlay", true);
	fo2.write("flash4_Mov"+id);
	// ]]>
}

function fechavideo(lg,id) {
  
  for(j=1;j<blc.length;j++){
    var obj1=document.getElementById("flash3_Mov"+blc[j]);
    var obj2=document.getElementById("btn_flash"+blc[j]);
    if(obj1!=null){
      obj1.style.display='none';
    }
    if(obj2!=null){
      obj2.style.display='none';
    }
  }
 
  
  var btn = document.getElementById("btn_flash"+id);
  var flsh = document.getElementById("flash3_Mov"+id);
  
  if(flsh!=null){
    flsh.style.display='none';
    flsh.innerHTML = "";
  }
  if(btn!=null){
    btn.style.display='none';
  }
  var fundo_o = document.getElementById("fundo_opaco");
  if(fundo_o!=null){
    fundo_o.style.display='none';
  }
   
}

function fechavideo2(lg,id) {
  
  for(j=1;j<blc.length;j++){
    var obj1=document.getElementById("flash4_Mov"+blc[j]);
    var obj2=document.getElementById("btn_flash"+blc[j]);
    if(obj1!=null){
      obj1.style.display='none';
    }
    if(obj2!=null){
      obj2.style.display='none';
    }
  }
 
  
  var btn = document.getElementById("btn_flash"+id);
  var flsh = document.getElementById("flash4_Mov"+id);
  
  if(flsh!=null){
    flsh.style.display='none';
    flsh.innerHTML = "";
  }
  if(btn!=null){
    btn.style.display='none';
  }
  var fundo_o = document.getElementById("fundo_opaco");
  if(fundo_o!=null){
    fundo_o.style.display='none';
  }
   
}

function mudaData(formID){
  var form = document.getElementById(formID);
  
  if(form!=null){
    var mes = document.getElementById('mes').value;
    var ano = document.getElementById('ano').value;
  }
  calendar.cal1.cfg.setProperty("PAGEDATE",mes + "/" + ano);
  calendar.cal1.render();
  //alert();

  $.ajax({
      url: 'get_eventos.php',
      type: 'POST',
      data:$('#' + formID).serializeArray(),
      success: function(data) {
        $('#eventsH').html(data);
        //$('#changedata').hide();
        //$('#dados_fact').show();
        
      }
  });
}

function verifica_pesq(form) {

var formulario = document.getElementById(form)
var txt=formulario.pesq;
var texto = txt.value;
var error;

  if((txt.value=="") || (txt.value==unescape(json[45]))){
      alert(unescape(json[43]));
      error=1;
  }else if(txt.value!="" &&  texto.length<3){
      alert(unescape(json[44]));
      error=2;
      
  }

  if((txt.value!=unescape(json[45])) && (texto.value!="") && (texto.length>=3)){
     error=0;
  }
  
  if(error>0){
    return false;
  }else {
    return document.getElementById(form).submit();
  }
  
  
}

function loadScript(){
  var script = document.createElement("script");
  script.setAttribute('id', 'gscript');
  script.type = "text/javascript";
  script.src = "http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAA19KocPjcm25GQItUREYSAhRRPb9aeCP_i3oHoGlT5cDoXV041RQgvQs_2G0MidPHL6c-HcoIl4ZPsg&async=2";
  if(document.getElementById("gscript")==null){
    document.body.appendChild(script);
  }
  
}

function mostraMapa(coord){
  
  
  var c = coord.split(",");
  //alert(c);
  if(c[0]!="" && c[1]!=""){
    loadScript();
	jQuery('.poplocation').height(jQuery(document).height());
    jQuery('.poplocation').show(500,function(){ loadMap('map',c[0],c[1]); } );
    
    
    
  }
  
}

function EventsSearchTop(){
	jQuery('.searchtop input[type="text"], .subnews input[type="text"]').focusin(function(){
		if(jQuery(this).val() != ''){
			jQuery(this).val('');
		}
	});
	
	jQuery('.searchtop input[type="image"]').hover(function(){
		jQuery(this).attr('src', 'sysimages/btpesq_hover.png');
	}, function(){
		jQuery(this).attr('src', 'sysimages/btpesq.png');
	});
	
	jQuery('.innermembers button').css({
		marginLeft : ((jQuery('.memberarea').width() - jQuery('.innermembers button').width()) / 2) + 'px',
		marginTop : '10px'
	});
}

function CenterMenufooter(){
	jQuery('ul.menufooter').css({
		width : GetItemsWidth() + 'px',
		margin : '0px auto'
	});
}

function GetItemsWidth(){
	var widthCounter = 0;
	
	jQuery('ul.menufooter > li').each(function(){
		widthCounter += jQuery(this).outerWidth(true);
	});
	
	return widthCounter;
}

jQuery(document).ready(function(){
	if(jQuery.browser.safari && jQuery.browser.mac){
		jQuery('ul.useful > li').css('padding-left', '10px');
	}
	
	EventsSearchTop();
	CenterMenufooter();
	
	jQuery('.closepop').click(function(){
		jQuery('.poplocation').hide(500);
	});
	
	jQuery('.innerlogin input').focusin(function(){
		jQuery('label', jQuery(this).parents('.elementoform')).hide('fast');	
	}).focusout(function(){
		if($(this).val() == ''){
			jQuery('label', jQuery(this).parents('.elementoform')).show('fast');	
		}
	});
	
	if(jQuery.browser.ie && jQuery.browser.version == '7.0'){
		jQuery('.pagination').css('background', 'url(sysimages/bgwrapperdocs.png) repeat-x left 46px');
	}
	
	jQuery('.elementoform input:text, .elementoform textarea').focusin(function(){
		jQuery('label', jQuery(this).parents('.elementoform')).hide('fast');
	}).focusout(function(){
		if($(this).val() == ''){
			jQuery('label', jQuery(this).parents('.elementoform')).show('fast');
		}
	});
	
	jQuery('.elementoform label').click(function(){
		jQuery(this).hide();
	});
	
	jQuery('.innerlogin .ptop').click(function(){
		if(jQuery.browser.ie){
			jQuery('.login').css('display', 'none');
		}
		else{
			jQuery('.login').hide(300);
		}
	});
});

function OpenLogin(){
	if(jQuery.browser.ie){
		jQuery('.login').css('display', 'block');
	}
	else{
		jQuery('.login').show(300);
	}
}

function Comments(){
	jQuery('.insertcomment input:text, .insertcomment textarea').focusin(function(){
		jQuery('label', jQuery(this).parents('.elementoform')).hide();
	}).focusout(function(){
		if($(this).val() == ''){
			jQuery('label', jQuery(this).parents('.elementoform')).show();
		}
	});
	
	jQuery('label, div:first:has(label)', jQuery('.elementoform')).click(function(){
		jQuery('input:text', jQuery(this).parents('.elementoform')).focus();
		jQuery('input:password', jQuery(this).parents('.elementoform')).focus();
		jQuery('textarea', jQuery(this).parents('.elementoform')).focus();
	});
	
	jQuery('.topcomments ul > li.sel span.spansel').css('left', GetLeftValue(jQuery('.topcomments ul > li.sel')) + 'px');
	
	jQuery('.topcomments ul > li.unsel a').live('click', function(ev){
		ev.preventDefault();
		
		jQuery('.topcomments ul > li.sel span.spansel').hide(100);
		jQuery('.topcomments ul > li.sel').attr('class', 'unsel');
		
		var parent = jQuery(this).parent();
		
		jQuery('span.spansel', parent).css('left', GetLeftValue(parent) + 'px').show(100);
		
		parent.attr('class', 'sel');
		
		jQuery('.padcomments').children().hide(200);
		jQuery('.' + jQuery(this).attr('rel')).show(500);
	});
}

function addComment(){
  $('#msg_c').hide();
  $('#frm_c').show();
}

function GetLeftValue(obj){
	var objhelfw = obj.outerWidth() / 2;
	
	return (objhelfw - (jQuery('span.spansel').width() / 2))
}

function EventsFaqs(){
	jQuery('ul.ulfaqs > li.unsel a').live('click', function(e){
		e.preventDefault();
		
		jQuery('ul.ulfaqs > li.sel div').hide(300);
		jQuery('ul.ulfaqs > li.sel').attr('class', 'unsel');
		
		jQuery('div', jQuery(this).parent()).show(500);
		jQuery(this).parent().attr('class', 'sel');
	});
	
	jQuery('ul.ulfaqs > li.sel a').live('click', function(e){
		e.preventDefault();
		
		jQuery('div', jQuery(this).parent()).hide(300);
		jQuery(this).parent().attr('class', 'unsel');
	});
}

function EventNew(){
	jQuery('.new').hover(function(){
		var h = jQuery(this).height(),
			w = jQuery(this).width();
			
		jQuery('.hovernew', this).css({
			height : h - 1 + 'px',
			width : w + 'px'
		}).show(200);
		
		jQuery('.hovernew > div', this).css({
			height : h - 13 + 'px',
			width : w - 13 + 'px'
		});
	}, function(){
		jQuery('.hovernew', this).hide(100);
	});
}


function FisuelEvents(){
	jQuery('.event').live('click', function(ev){
		if(ev.currentTarget.className != 'closeevent'){
			jQuery('p.detailevent, .closeevent').hide(500);
			jQuery('.eventsel').attr('class','event');
			
			jQuery('p.detailevent, .closeevent', jQuery(this)).show(500);
			jQuery(this).attr('class', 'eventsel');
		}
	});
	
	jQuery('.closeevent').click(function(ev){
		if(ev.currentTarget.className == 'closeevent'){
			jQuery('p.detailevent', jQuery(this).parents('.eventsel')).hide(500, function(){
				jQuery('.closeevent').parents('.eventsel').attr('class','event');
			});
			jQuery(this).hide(200);
		}
	});
}
//var autoslide = true;
function FunctionsHome(){
	jQuery('.seemore').live('click', function(){
		var that = jQuery(this);
		
		jQuery('.lefthome').animate({
			width : '494px'
		}, 500, function(){
			jQuery('.righthome').animate({
				'width' : '452px'
			}, 500, function(){
			
				jQuery('.eventshome').css({
					'width' : '211px',
					'margin-left' : '12px'
				});
				
				jQuery('.eventhome').css('width', '211px');
				
				jQuery('.calendar').show(500, function(){
					jQuery('.linkall', jQuery(this).parents('.righthome')).css('background', 'url(sysimages/bgwrapperdocs.png) repeat-x left top');
					that.attr('class', 'seemoreclose');
				});
			});
		});
	});
	
	jQuery('.seemoreclose').live('click', function(){
		var that = jQuery(this);
		
		jQuery('.calendar').hide(500, function(){
			jQuery('.righthome').animate({
				width : '283px'
			}, 500, function(){
				var thiselm = jQuery(this);
				
				jQuery('.lefthome').animate({
					width : '664px'
				}, 500, function(){
					jQuery('.eventshome').css({
						'width' : '267px',
						'margin-left' : '0px'
					});
					
					jQuery('.eventhome').css('width', '283px');
					
					jQuery('.linkall', thiselm).css('background', 'none');
					that.attr('class', 'seemore');
				});
			});
		});
	});
	
	jQuery('.smallslider').jqContentSlider({
		autoSlide : autoslide,
		autoSlideInterval : 10000,
		slideNavigation : true,
		slideNavigationElement : '.ulpagination',
		msiedetection : false
	});
	
	jQuery('.bigslider').jqContentSlider({
		autoSlide : autoslide2,
		autoSlideInterval : 10000,
		slideNavigation : true,
		slideNavigationElement : '.ulpaginationbig',
		msiedetection : false
	});
}

