
/* VALIDAR O CAMPO DATA DA SITUAÇÃO DA RODOVIA */
function ValidaData(frm) {
	with(frm) {
		// txtData value="dd/mm/aaaa"
		if ((txtData.value == '') || ((txtData.value == 'dd/mm/aaaa'))) {
			alert('Por favor, informe uma data válida.');
			return false;
		}
		if (!Date.parse(txtData.value)) {
			alert('Por favor, informe uma data válida.');
			txtData.focus();
			return false;}
	}
}

/* SCRIPT SUBSTITUIR _AT_ POR @ */
/* EVITA QUE BOTS DE SPAMMERS COPIEM O E-MAIL */
var Convert = {
  initialize: function() {
	var spans = document.getElementsByTagName("span");
	for (var i = 0; i < spans.length; i++) {
	  if(spans[i].className == "email") {
		string = spans[i].childNodes[0].nodeValue;
		email = string.split("_")[0] + "@" + string.split("_")[2];
		spans[i].innerHTML = '<a href="mailto:' + email + '" class="LinkPadrao" rel="nofollow">' + email + '<\/a>';
	  }
   }
 }
}
//window.onload = Convert.initialize;

/*  */
function limparForms(qualform) {
	for (var i = 0; i < qualform.elements.length; i++) {
		var element = qualform.elements[i];
		if (element.type == "submit") continue;
		if (element.type == "button") continue;
    if (!element.defaultValue) continue; 
    element.onfocus = function() {
    	if (this.value == this.defaultValue) {
				this.value = "";
			}
		}
		element.onblur = function() {
      if (this.value == "") {
        this.value = this.defaultValue;
      }
    }
  }
}

function iniciarForms() {
  for (var i = 0; i < document.forms.length; i++) {
		var thisform = document.forms[i];
		var formClass = thisform.getAttribute("className");
		formClass = formClass ? formClass : thisform.getAttribute("class");
		if (formClass == "LimpaCampos") {
				limparForms(thisform);
		}
  }
}

/* SCRIPT PARA RODAR OS PODCASTS */
var uniqueID = 300;

function playAudio(audio, title) {
  var width = 300;
  var height = 45;
  var winWidth = 320;
  var winHeight = 220;
  //cria a posicao aonde ficara a janela com o player
  var x = (window.screen.width - winWidth) / 2;
  var y = (window.screen.height - winHeight) / 2;
  //cria a janela
  var win = null;
  var params = "width=" + winWidth + ", height=" + winHeight + ", top=" + y + ",left=" + x + ", ,left=0,resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0,personalbar=0";
  //abre a janela
  win = window.open("", uniqueID, params);
  
  win.moveTo(x, y);
  win.focus();
  //cria o content desse player, setando o arqivo
  var content = '<html>';
  content += '	<head><title>' + title + '</title></head>'
  content += ' <body>';
  content += '	<center>';  
  content += '		<img src="http://www.concepa.com.br/site/images/radiovia-popup-af.jpg" />';
  content += '		<object width="' + width + '" height="' + height + '">';
  content += '			<param name="autoplay" value="true">';
  content += '			<param name="controller" value="true">';
  content += '			<param name="bgcolor" value="#FFFFFF">';
  content += '			<embed src="'+ audio + '" autostart="true" loop="false" width="' + width + '" height="' + height + '" controller="true" bgcolor="#FFFFFF"></embed>';
  content += '		</object>';
  content += '	<center>';
  content += ' </body></html>';
  
  win.document.write(content);
  win.document.close();	
  uniqueID += 1;
}

/* SCRIPT PARA ABRIR POPUP DO FREE WAY AO VIVO */
var win = null;

function NewWindow(mypage, myname, w, h, scroll, pos) {
	if (pos == "random") {
		LeftPosition = (screen.width) ? Math.floor(Math.random() * (screen.width - w)) : 100;
		TopPosition = (screen.height) ? Math.floor(Math.random() * ((screen.height - h) - 75)) : 100;
	}
	if (pos == "center") {
		LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
		TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;
	}
	else if ((pos != "center" && pos != "random") || pos == null) {
		LeftPosition = 0;
		TopPosition = 20;
	}
	settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win = window.open(mypage,myname,settings);
}

// FORÇA OS LINKS A ABRIREM EM UMA NOVA JANELA
function createExternalLinks() {
    if (document.getElementsByTagName) {
        var anchors = document.getElementsByTagName('a');
        for (var i = 0; i < anchors.length; i++) {
            var anchor = anchors[i];
            if (anchor.getAttribute("href") && anchor.getAttribute('rel') == 'externo') { // <-- É necessário inserir rel="externo" no link
                anchor.target = '_blank';
                var title = anchor.title + ' (Este link abre uma nova janela)'; // <-- Insere este texto no final do Title do link
                anchor.title = title;
            }
        }
    }
}

// ESTA FUNÇÃO INICIA TODAS AS OUTRAS EM UM DOCUMENTO
function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent('on' + evType, fn);
        return r;
    } else {
        return false;
    }
}

addEvent(window, "load", createExternalLinks);
addEvent(window, "load", iniciarForms);
addEvent(window, "load", Convert.initialize);



