$.fn.send = function(opts)
{
	opts = opts || {};
	var default_opts = {			
		dataType : 'json',			
		success : null,
		error: null			
	};

	var enabled_opts = $.extend(default_opts, opts);

	$.ajax({
		url: $(this).attr('action'),
		type: $(this).attr('method'),
		dataType: enabled_opts.dataType,
		data: $(this).serialize(),
		success: enabled_opts.success,
		error: enabled_opts.error
	});
}

$(document).ready(function(){
	$(".lavaLamp").lavaLamp({ fx: "backout", speed: 700 });
	
	$('#contatoForm').html5form({
		labels: 'hide',
		allBrowsers: true,
		method : 'POST',
		action : 'contato_acoes.php',
		responseDiv : '#contact'
	});

	var captions = ['<a href=\"http://radiodifusaoenegocios.com.br\" target=\"_blank\">radiodifusaoenegocios.com.br</a>','<a href=\"http://robertatum.com.br\" target=\"_blank\">robertatum.com.br</a>', '<a href=\"http://colinas.to.gov.br\" target=\"_blank\">colinas.to.gov.br</a>', '<a href=\"http://colegiosantacruz.g12.br\" target=\"_blank\">colegiosantacruz.g12.br</a>'];

	$('#imgprincipal').crossSlide({
	  speed: 40,
	  fade: 2
	}, [
	  { src: '/layout/img/img_principal4.jpg', dir: 'down' },
	  { src: '/layout/img/img_principal1.jpg', dir: 'up' },
  	  { src: '/layout/img/img_principal3.jpg', dir: 'down' },
  	  { src: '/layout/img/img_principal2.jpg', dir: 'up'}
	], function(idx, img, idxOut, imgOut) {
		  if (idxOut == undefined)
		  {
		    // starting single image phase, put up caption
		    $('#caption').html(captions[idx]).fadeIn()
		  }
		  else
		  {
		    // starting cross-fade phase, take out caption
		    $('#caption').fadeOut()
		  }
	});



	$("#opinar").click(function () {
		$("#formEnquete").send({
			dataType:"html",
			success:function(jason){
				$("#enquete").html("");
				$("#enquete").html($(jason));
			}
		});
	});

});

/* Config */
var tempoAlternar = 4000;
var tempoAddLetra = 50;
var cfgLimitChar = 75;

/* Fim Config */

var nitens = 0;
var atual = 0;

var totChar;
var limitChar;
var maxChar;
var minChar;
var TextoComp;

function addLetra(){
	maxChar++;
	cMax = maxChar;
	minChar = maxChar - limitChar;
	if (minChar < 0) minChar = 0;
	if (cMax > limitChar) cMax = limitChar;
	
	texto = TextoComp.substr(minChar, cMax);
	
	TextoLink = limpaStr(TextoComp);
	
	if (maxChar==totChar){
		document.getElementById('ultimas').innerHTML = '<a href="/noticia/' + TextoLink + '/' + IDNot + '" title="">' + texto + '</a>';
		window.setTimeout('mudaItem()', tempoAlternar);
	}else {
		document.getElementById('ultimas').innerHTML = '<a href="/noticia/' + TextoLink + '/' + IDNot + '" title="">' + texto + '_</a>';
		window.setTimeout('addLetra()', tempoAddLetra);
	}
}

function escreveItem(id){
	totChar = itens[id].length;
	limitChar = cfgLimitChar;
	maxChar = 0;
	minChar = -cfgLimitChar;
	TextoComp = itens[id];
	IDNot = idnot[id];
	addLetra();
}

function mudaItem(){
	if (document.getElementById('ultimas') != null){
		if (atual > nitens) atual=0;
		novoItem = atual++;
		escreveItem(novoItem);
	}
}


limpaStr = function(str){
	q = str
		.toLowerCase()
		.replace(/[áàâäã]/gi, 'a')
		.replace(/[éèëẽê]/gi, 'e')
		.replace(/[íìĩïî]/gi, 'i')
		.replace(/[óòõöô]/gi, 'o')
		.replace(/[úùũüû]/gi, 'u')
		.replace(/[ñ]/gi, 'n')
		.replace(/[ç]/gi, 'c')
		.replace(/[,.:;!@#$%^&*)(\"\']/gi, '')
		.replace(/[ \/]/gi, '-')
		.replace(/\-+/gi, '-');
	
	return q;
}


function excluiItem(msg, destino){
	if (confirm('Deseja excluir: ' + msg + ' ?')){
		window.location=destino;
	}
}

function pergunta(msg, destino){
	if (confirm(msg)){
		window.location=destino;
	}
}

function mudaStatusBar(){
    setTimeout("erase()",0);
}

function erase(){
   window.status="robertatum.com.br";
}

erase();

function abrir(pagina,nome,largura,altura,parametros) {
	w = screen.width;
	h = screen.height;
	meio_w = w/2;
	meio_h = h/2;
	altura2 = altura/2;
	largura2 = largura/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;
	window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+''+parametros); 
}

function combo_reload(targ,selObj,restore){ // onChange="combo_reload('seloTempo',this,2)"
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
}

function doEmail(pStr) // onBlur="doEmail(this.value); return false;"
{
	var reEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/; 
	if (reEmail.test(pStr)) {
		return true;
	} else if (pStr != null && pStr != "") {
		alert("'"+pStr + "'\nNÃO é um endereço de e-mail válido.");
		document.form1.email.value="";
		document.form1.email.focus();
		document.form1.email.focus();
		return false;
	}
} // doEmail

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
	countfield.value = maxlimit - field.value.length;
}

function textCount(field, countfield) {
	countfield.value = field.value.length;
}

function Campo(id){
	return document.getElementById(id);
}

function concordo(){
	if (document.form1.autorizo.checked == true){
		document.form1.cadastrar.disabled = false;
		document.form1.cadastrar.style.display = "block";
	}else{
		document.form1.cadastrar.disabled = true;
		document.form1.cadastrar.style.display = "none";
	}
}

function checaSenha(){
	if ( (document.form1.senha.value != "") && (document.form1.senha2.value != "") ){
		if (document.form1.senha.value != document.form1.senha2.value){
			alert('As senhas não conferem!');	
			document.form1.senha.value = "";
			document.form1.senha2.value = "";
			document.form1.senha.focus();
			
		}	
	}
}

