/*
* ARQUIVO: gerais.js
* AUTOR: Nícolas
* VERSÃO: 1.0
*/

///////////////////////////////////////////////////////////////////////////////////////////
atual = 0;
numero = 0;
function destaque(pos,tot,view)
{
	para = document.getElementById('dest');
	if(pos == 'pro')
	{
		if(numero == tot)
		{
			atual = tot;
			numero = 1;
		}
		else
		{
			atual = numero;
			numero++;
		}
		document.getElementById('x_'+atual).className = "but";
		document.getElementById('x_'+numero).className = "but_over";
		para.innerHTML = document.getElementById('dest_' + numero).innerHTML;
		atual++;
		
	}
	else if(pos == 'atu')
	{
		para.innerHTML = document.getElementById('dest_1').innerHTML;
		img_pro = document.getElementById('x_1').className = "but_over";
		atual++;
		numero = 1;
	}
	else if(pos == 'view')
	{
		for( x = 1; x <= tot; x++ )
			document.getElementById('x_'+x).className = "but";
		
		document.getElementById('x_'+view).className = "but_over";
		para.innerHTML = document.getElementById('dest_' + view).innerHTML;
		atual = view;
		numero = view;
	}
	else
	{
		if(numero == 1)
		{
			atual = 1;
			numero = tot;
		}
		else
		{
			atual = numero;
			numero--;
		}
		document.getElementById('x_'+atual).className = "but";
		document.getElementById('x_'+numero).className = "but_over";
		para.innerHTML = document.getElementById('dest_' + numero).innerHTML;
		atual--;
	}
	//setTimeout("destaque('pro',"+tot+")",15000);
}
///////////////////////////////////////////////////////////////////////////////////////////
//destaques de flyers
atual1 = 0;
numero1 = 0;
function destaqueFly(pos1,tot1,view1)
{
	para = document.getElementById('fly');
	if(pos1 == 'pro')
	{
		if(numero1 == tot1)
		{
			atual1 = tot1;
			numero1 = 1;
		}
		else
		{
			atual1 = numero1;
			numero1++;
		}
		document.getElementById('y_'+atual1).className = "but";
		document.getElementById('y_'+numero1).className = "but_over";
		para.innerHTML = document.getElementById('fly_' + numero1).innerHTML;
		atual1++;
		
	}
	else if(pos1 == 'atu')
	{
		para.innerHTML = document.getElementById('fly_1').innerHTML;
		img_pro = document.getElementById('y_1').className = "but_over";
		atual1++;
		numero1 = 1;
	}
	else if(pos1 == 'view')
	{
		for( x = 1; x <= tot1; x++ )
			document.getElementById('y_'+x).className = "but";
		
		document.getElementById('y_'+view1).className = "but_over";
		para.innerHTML = document.getElementById('fly_' + view1).innerHTML;
		atual1 = view1;
		numero1 = view1;
	}
	else
	{
		if(numero1 == 1)
		{
			atual1 = 1;
			numero1 = tot1;
		}
		else
		{
			atual1 = numero1;
			numero1--;
		}
		document.getElementById('y_'+atual1).className = "but";
		document.getElementById('y_'+numero1).className = "but_over";
		para.innerHTML = document.getElementById('fly_' + numero1).innerHTML;
		atual1--;
	}
	//setTimeout("destaque('pro',"+tot+")",15000);
}
///////////////////////////////////////////////////////////////////////////////////////////

function relogio()
{
	
	dataNow = new Date;
	
	spanClock = document.getElementById('relogio');
	if(dataNow.getHours()<10) hora = "0"+dataNow.getHours();
	else hora = dataNow.getHours();
	
	if(dataNow.getMinutes()<10) minutos = "0"+dataNow.getMinutes();
	else minutos = dataNow.getMinutes();
	
	if(dataNow.getSeconds()<10) segundos = "0"+dataNow.getSeconds();
	else segundos = dataNow.getSeconds();
	
	spanClock.innerHTML = hora+":"+minutos+":"+segundos;
	setTimeout('relogio();',1000);
}


function formata_hora(formname,field)
{
	elemento = eval('document.' + formname + '.' + field);
	if (elemento.value.length == 2 || elemento.value.length == 5) 
	{ 
		elemento.value += ':';			
	}
}

function popup_relogio(u,n,p,w,h) {
	l = (screen.availWidth) - ((w)+12);
	t = (screen.availHeight) - ((h)+50);
	p = p + ",width=" + w + ",height=" + h + ",left=" + l + ",top=" + t;
	window.open(u,n,p);
}


//========= FUNÇÕES DOS BANNERS ==================================	



function setFlashWidth(divid, newW){
	document.getElementById(divid).style.width = newW+"px";
}
function setFlashHeight(divid, newH){
	document.getElementById(divid).style.height = newH+"px";
}
function setFlashLeft(divid, newL){
	document.getElementById(divid).style.left = newL+"px";
}

function setFlashTop(divid, newT){
	document.getElementById(divid).style.top = newT+"px";
}



/*
function setFlashSize(divid, newW, newH, newL, newT){
	setFlashWidth(divid, newW);
	setFlashHeight(divid, newH);
	setFlashLeft(divid, newL);
	setFlashTop(divid, newT);
}
*/




 function setFlashSize(divid, newW, newH, newL, newT)
 {
	
	setFlashWidth(divid, newW);
	setFlashHeight(divid, newH);
	
	if (newW<468) 
	{
	
		janela = window.location;
		janela = janela.toString(); 
	
		
		if(janela.search('popup') == '-1')
		{
			document.getElementById(divid).style.left = newL + "px";
		}
		else
		{ 
			if(!document.all) 		  
		  	{ 
				document.getElementById(divid).style.left = newL + "px"; 
			} else { 
			
				if (newW == 350)
				{
					document.getElementById(divid).style.left = 158 + "px";
				} else {			   
					document.getElementById(divid).style.left = 388 + "px";
				}
			}
		}
	} else {		
		//setFlashLeft(divid, newL);
	}

	setFlashTop(divid, newT);

	//window.alert (newL);
}










function menuDrop()
{
	obj = document.getElementById('drop');
	base = document.getElementById('select');
	obj.style.left = findPosX(base) - 1 + "px";
	obj.style.top = findPosY(base) + 18 + "px";
	if( gl == 0 )
	{
		abreDiv('drop','display');
		gl = 1;
	}
	else
	{
		fechaDiv('drop','display');
		gl = 0;
	}
	
}

function delay(funcao, tempo)
{
	setTimeout(funcao, tempo);		
}

function abreDiv(id, metodo)
{
	obj = document.getElementById(id);
	if(metodo == 'display')
	{
		obj.style.display = 'block';
	}
	else
	{
		obj.style.visibility = 'visible';
	}
}

function fechaDiv(id, metodo)
{
	obj = document.getElementById(id);
	if(metodo == 'display')
	{
		obj.style.display = 'none';
	}
	else
	{
		obj.style.visibility = 'hidden';
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function menuOver()
{
	obj  = document.getElementById('menu_servicos');
	base = document.getElementById('servicos');
	obj.style.left = findPosX(base) - 30 + 'px';
	obj.style.top = findPosY(base) + 13 + 'px';
	abreDiv('menu_servicos','display');
}

function menuOut()
{
	obj  = document.getElementById('menu_servicos');
	base = document.getElementById('servicos');
	fechaDiv('menu_servicos','display');
}

/**********************************************************
* Função makeRequest(url). Faz um request com AJAX.
* Está sendo usado no calendário do site
* Busca feita no Wikipédia, retornou a página
* http://developer.mozilla.org/en/docs/AJAX:Getting_Started
* Resumindo, a função recebe uma url, e a executa por
* baixo dos panos, retorna pela função retornaValor
* Pesquisa por: Nícolas.
* Data: 16/02/2006.
* Data de alteração: n/d.
**********************************************************/

var http_request = false;

function makeRequest(url) {
	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = retornaValor;
	http_request.open('GET', url, true);
	http_request.send(null);

}

/*
0 (não inicializado) 
1 (carregando) 
2 (carregado) 
3 (interativo) 
4 (completo) 
*/
function retornaValor() {

	/*
	if (http_request.readyState == 1) {
		document.getElementById('index').innerHTML = "<div style='padding-top:5px;' align='center'>Carregando...</div>";
	}
	
	if (http_request.readyState == 4) {
		document.getElementById('retCalendario').innerHTML = http_request.responseText;
	}*/

}
function testaVazio(campo,comparacao,formulario,mensagem,erro) 
{
	if (erro == true)
		return true;
	obj1 = eval("document."+formulario+"."+campo);
	if (obj1.value == comparacao)
	{
		alert (mensagem);
		obj1.focus();
		return true;
	}
	else 
		return false;
}

function ativaCi(valor)
{
	if(valor == 'OTHER')
	{
		document.getElementById('ci').style.display = 'block';
		if(document.getElementById('ci').value == '')
			document.getElementById('ci').value = 'Digite aqui sua cidade';
			
		document.getElementById('ci').name = 'cidade';
	}
	else
	{
		document.getElementById('ci').style.display = 'none';
		document.getElementById('ci').name = 'ci';
	}
}
function limpaCi(valor)
{
	if(valor == 'Digite aqui sua cidade')
		document.getElementById('ci').value = '';
		
}

function testaVazio1(campo,comparacao,formulario,mensagem,erro) 
{
	if (erro == true)
		return true;
	obj1 = eval("document."+formulario+"."+campo);
	if (obj1.value == comparacao)
	{
		alert (mensagem);
		obj1.focus();
		return true;
	}
	else 
		return false;
}



function verDados(valor, option)
{
	if(valor == "")
	{
		alert("Você deve escolher um valor válido!");
	}
	else if(valor == 0)
	{
		alert("Você deve escolher um valor, não uma categoria!");
	}
	else
	{
		document.location = "principal.php?option=" + option + "&action=ver&valor=" + valor	;
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function setFlashTop(divid, newT){
	if(divid == 'flashResizer')
		document.getElementById(divid).style.top = newT+"px";
}

function setFlashLeft(divid, newL){
	if(divid == 'flashResizer')
	{
		if(!document.all)
		{
			document.getElementById(divid).style.left = newL + "px";
		}
		else
		{
			document.getElementById(divid).style.left = newL - 60 + "px";
		}
	}
}

function mouse(id,ti)
{
	obj = document.getElementById(id);
	
	str = obj.src;
	
	if(ti == 'over')
		obj.src = str.replace('/o/','/n/');
	else
		obj.src = str.replace('/n/','/o/');
}

function addFav()
{
    var url = "http://www.baladajovem.com.br";
    var title = "BaladaJovem";
    
	if (window.sidebar) 
		window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print)
	{
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all)
	{
		window.external.AddFavorite(url, title);
	}
}

