/*
* 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);
}
///////////////////////////////////////////////////////////////////////////////////////////

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";
	return true;
}


function setFlashSize(divid, newW, newH, newL, newT)
{
	setFlashWidth(divid, newW);
	if(setFlashHeight(divid, newH) == true)
	{
	
		if(divid != 'flashResizerDireita')
			base = document.getElementById('banner_topo');
		else
			base = document.getElementById('direita');
		
		
		if(!document.all)
		{
			document.getElementById(divid).style.left = newL + "px";
		}
		else
		{
			
			if(newW == 350)
				document.getElementById(divid).style.left = findPosX(base) - 229 + "px";
			else
				document.getElementById(divid).style.left = findPosX(base) + 1 + "px";
		}
		setFlashTop(divid, newT);
	}
}

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


function setFlashSizeDireita(flashResizerDireita, newW, newH, newL, newT)
{
	alert('d');
	setFlashWidth(flashResizerDireita, newW);
	setFlashHeight(flashResizerDireita, newH);
	setFlashLeft(flashResizerDireita, newL);
	setFlashTop(flashResizerDireita, newT);
}



gl = 0;
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_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";
		}
	}
}

////////////////////////////////////////////////////////////////////////////////////////
//FUNÇÕES RESTRITAS AO CARRODOVALE
var aux = 1;
var t = 1;
function abreEnquete(id)
{
	obj = document.getElementById(id);
	
	if(t == 1)
	{
		obj.style.visibility = 'visible';
	}
	if(aux == 1)
	{
		obj.style.visibility = 'visible';
		//new Effect.BlindDown(id);
		aux = 0;
	}
	else
	{
		obj.style.visibility = 'hidden';
		//new Effect.Fade(id);
		aux = 1;	
	}

}

function changeSelect(cadastro, value, alvo)
{
	document.getElementById('iframe_filtro').src = './paineldecontrole/frame.php?cadastro='+cadastro+'&value='+value+'&alvo='+alvo;
}

function logaSistema()
{
	if( document.login_user.user.value != "" && document.login_user.pass.value != "" )
	{
		document.login_user.submit();
	}
	else
	{
		alert("Os campos Usu&aacute;rio e Senha devem ser preenchidos!");
	}
}

function trocaFotoVeiculo(imagem)
{
	foto = imagem.replace('/80x60/','/350x263/');
	changeSrc('foto_gra',foto);
}
function changeSrc(id,img_src)
{
	obj = document.getElementById(id);
	obj.src = img_src;
}

function setPhoto(id, imagem)
{
	atual = document.getElementById('foto_gra').src;
	document.getElementById('foto_gra').src = imagem.replace('/80x60/','/350x263/');
	document.getElementById(id).src = atual.replace('/350x263/','/80x60/');
}

function buttomOver(id){
	obj = document.getElementById(id);
	src = obj.src;
	obj.src = obj.src.replace("ov/","no/");
}

function buttomOut(id, img_src){
	obj = document.getElementById(id);
	src = obj.src;
	obj.src = obj.src.replace("no/","ov/");
}
