// ---------------------------------------- Verificação de formulário
String.prototype.trim = function(){
 return this.replace(/^\s*/, "").replace(/\s*$/, "")
}

function mailCheck(m){
 return (m.search(/^[a-zA-Z][\.\w-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)==-1||m.search(/\.{2,}|\.-|-\.|-{2,}|\._|_\./)>-1)?false:true
}

function alerta(nC,el){
  window.alert('Por favor, preencha o campo ' +nC.toUpperCase()+ ' corretamente!')
	try{
		el.focus()
	  el.select()
	}
	catch(e){}
}

passou=0
function validarCampos(f){
  var i,el,nC,vC,al='alerta(nC,el)'
  for(var i=0; i<f.elements.length; i++){
	   el=f.elements[i]
     nC=el.name
     vC=el.value.trim()
     el.value=vC
       if((vC.length==0 || vC=='') && el.className!='no'){
			   eval(al)
				 return false
       }
		   if(el.className.toLowerCase()=='email' && !mailCheck(vC)){
		     eval(al)
				 return false
		   }
			 if(passou==1){
				 window.alert('Por favor, aguarde. Sua inscrição está sendo processada!')
				 return false
			 }
  }
	passou=1
	return true
}
// ---------------------------------------- Verificação de formulário - tratar campo select

function tratarValor(de,para){
	para.value=''
	var extra=document.getElementById('extra')
	var selec=document.getElementById('selec')
	if(de=='Jornal Qual?' || de=='Revista Qual?' || de=='Outra forma Qual?'){
		selec.style.display='none'
		extra.style.display='block'
		para.focus()
	}
	else{
		extra.style.display='none'
		para.value=de
	}
}

// ---------------------------------------- popup
function CNWin(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
