//roda slider jquery------
$(document).ready(function(){
	$(".paging").show();
	$(".paging a:first").addClass("active");

	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;

	$(".image_reel").css({'width' : imageReelWidth});

	rotate = function(){
		var triggerID = $active.attr("rel") - 1;
		var image_reelPosition = triggerID * imageWidth;

		$(".paging a").removeClass('active');
		$active.addClass('active');

		$(".image_reel").animate({
			left: -image_reelPosition
		}, 500);
	};

	rotateSwitch = function(){
		play = setInterval(function(){
			$active = $('.paging a.active').next();
			if ( $active.length === 0){
				$active = $('.paging a:first');
			}
			rotate();
		}, 5000);
	};

	rotateSwitch();

	$(".image_reel a").hover(function(){
		clearInterval(play);
	}, function(){
		rotateSwitch();
	});

	$(".paging a").click(function(){
		$active = $(this);
		clearInterval(play);
		rotate();
		rotateSwitch();
		return false;
	});
});

//menu dropdown jquery------
$(document).ready(function(){
	$("#nav-one li").hover(
		function(){ $("ul", this).fadeIn("fast"); }, 
		function() { } 
	);
if(document.all){
		$("#nav-one li").hoverClass ("sfHover");
	}
});

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function(){ $(this).addClass(c);  },
			function(){ $(this).removeClass(c); }
		);
	});
};

//exclui registro depois de confirmar------
function Excluir(tipo,cod){
	if(confirm("Deseja realmente excluir este registro?")){
		window.location = "exc.php?tipo="+tipo+"&cod="+cod;
	}else{
		return false;
	}
}

//valida formulário obrigatório------
function valida(local){
	var onde = document.getElementById(local);
	var formulario = onde.getElementsByTagName("input");
	for(var i=0; i < formulario.length; i++){
		if(formulario[i].title === "*"){
			if(formulario[i].value == ""){
				var aux = formulario[i].name.toUpperCase();
				alert ("O campo " + aux + " deve ser preenchido");
				formulario[i].focus();
				return false;
			}
		}
	}
	return true;
}

//valida email
function ValidaEmail(local){
  var obj = document.getElementById(local).email;
  var txt = obj.value;
  if((txt.length != 0) && ((txt.indexOf("@") < 1) || (txt.indexOf('.') < 7))){
    alert('E-mail invalido.');
	obj.focus();
  }
}

//abre janela
function abre(url,x,y){
	window.open(url,'janela','width='+x+',height='+y+',top=150,left=300');
}

//faz requisição ajax
function GetXMLHttp(){
	if(navigator.appName == "Microsoft Internet Explorer"){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}

var xmlRequest = GetXMLHttp();

function abrirPag(valor){
	var url = "existe.php?email="+valor;

	xmlRequest.onreadystatechange = mudancaEstado;
	xmlRequest.open("GET",url,true);
	xmlRequest.send(null);

	if(xmlRequest.readyState == 1){
		document.getElementById('whois').innerHTML = "<img src='carregando.gif' border=0 />";
	}

	return url;
}

function mudancaEstado(){
	if(xmlRequest.readyState == 4)
		document.getElementById('whois').innerHTML = xmlRequest.responseText;
}
