// JavaScript Document

function confirma(msg,url)
{
  if(true == confirm(msg))
    window.location = url;
}

function podPlayer(arquivo)
{
	arquivo = "../arquivospod/" + arquivo;
	document.write('<object type="application/x-shockwave-flash" data="player/podPlayer.swf" id="podPlayer" height="24" width="290">');
	document.write('  <param name="movie" value="player/podPlayer.swf" />');
	document.write('  <param name="FlashVars" value="playerID=1&bg=0xFFFFFF&leftbg=0xB6D587&rightbg=0xB6D587&rightbghover=0x999999&lefticon=0xffffff&righticon=0xffffff&righticonhover=0xFFFFFF&text=0x666666&slider=0x666666&track=0xFFFFFF&loader=0xB6D587&border=0x666666&autostart=false&soundFile='+arquivo+'" />');
	document.write('  <param name="quality" value="high" />');
	document.write('  <param name="wmode" value="transparent" />');
	document.write('  <param name="menu" value="false" />');
	document.write('</object>');
}

//exibe flash no site
function insere_flash(arq,w,h,modo)
{
    document.write('<object class="z-index: '+arq+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+w+'" height="'+h+'">');
	document.write('  <param name="movie" value="'+arq+'" />');
	document.write('  <param name="quality" value="high" />');
	document.write('  <param name="wmode" value="'+modo+'" />');
	document.write('  <param name="menu" value="false" />');
	document.write('  <embed menu="false" wmode="'+modo+'" src="'+arq+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed>');
	document.write('</object>');
}

function insere_mp(arq)
{
    document.write(' <object height="320" width="256" id="video1" border="1" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 CODEBASE=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Carregando Trailer..." type="application/x-oleobject">');
	document.write('	<param name="FileName" value="'+arq+'">');
	document.write('	<param name="ShowDisplay" value="False">');
	document.write('	<param name="ShowStatusBar" value="True">');
	document.write('	<param name="StatusBar" value="True">');
	document.write('	<param name="AnimationAtStart" value="True">');
	document.write('	<param name="ShowAudioControls" value="True">');
	document.write('	<param name="ShowPositionControls" value="True">');
	document.write('	<param name="ShowControls" value="True">');
	document.write('	<param name="AutoSize" value="False">');
	document.write('	<param name="AutoStart" value="True">');
	document.write('	<param name="AutoRewind" value="True">');
	document.write('	<param name="scale" value="tofit">');
	document.write('	<!--Plugin para o Netscape-->');
	document.write('	<EMBED SRC="'+arq+'" ShowStatusBar="1" type="application/x-mplayer2" width=320 height=256 AutoStart=1 pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="MP1" border="0">');
	document.write('	</EMBED>');
	document.write('</object>');
}

function insere_qt(arq)
{
    document.write('<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" border="0" align="left" WIDTH="320" height="186" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" id="video">');
	document.write('    <PARAM name="SRC" VALUE="'+arq+'">');
	document.write('	<PARAM name="AUTOPLAY" VALUE="true">');
	document.write('	<PARAM name="CONTROLLER" VALUE="true">');
	document.write('	<param name="ShowStatusBar" value="True">');
	document.write('	<param name="AutoSize" value="true">');
	document.write('	<param name="Kioskmode" value="true">');
	document.write('	<param name="scale" value="tofit">');
	document.write('<EMBED SRC="'+arq+'" WIDTH="320" HEIGHT="186" AUTOPLAY="true" CONTROLLER="true" PLUGINSPAGE="http://www.apple.com/quicktime/download/" type="video/quicktime"></EMBED>');
	document.write('</OBJECT>');
}

function handleClick(id) {
	var obj = "";	

		// Check browser compatibility
		if(document.getElementById)
			obj = document.getElementById(id);
		else if(document.all)
			obj = document.all[id];
		else if(document.layers)
			obj = document.layers[id];
		else
			return 1;

		if (!obj) {
			return 1;
		}
		else if (obj.style) 
		{			
			obj.style.display = ( obj.style.display != "none" ) ? "none" : "";
		}
		else 
		{ 
			obj.visibility = "show"; 
		}
}
//-------------------------------------------------------
function CorOver(celula,txtStatus)
 {
  if(!celula.contains(event.fromElement))
  	{
		celula.style.cursor='hand';
		celula.bgColor='#99CCFF';
	}
 }
//------------------------------------------------------- 
function CorOut(celula)
	{
		if(!celula.contains(event.toElement))
			{
				celula.bgColor='#FFFFFF';
				celula.style.cursor='default';
			}
	}
//-------------------------------------------------------
function valida_contato()
{
 if(document.contato.nome.value == "")
  {
   alert("Informe seu nome completo.");
   document.contato.nome.focus();
  }else if(document.contato.email.value == "")
         {
           alert("Informe seu e-mail.");
           document.contato.email.focus();
         }else if(document.contato.msg.value == "")
		        {
				 alert("Digite sua mensagem.");
                 document.contato.msg.focus();
				}else
				     document.contato.submit();
}
//----------------------------------------------------------------------
function pop_up_rol(url,x,y,rol)
 {
    //y -> Altura (px)
    //x -> Largura (px)
	//url -> página à abrir (parâmetro entre aspas -> "parametro")
	//rol -> Barra de rolagem ("yes" ou "no")
   
   pos_y = (screen.availHeight/2)-(y/2);
   pos_x = (screen.availWidth/2)-(x/2);
   x = window.open(url,'janela','width='+x+',directories=no,location=no,menubar=no,resizable=no,scrollbars='+rol+',status=no,toolbar=no,height='+y+',left='+pos_x+',top='+pos_y+'');
   if(!x)
     alert("Atenção.\n\nFoi detectado um bloquador de pop-up ativado.\nPara visualizar, é necessário desativar o bloqueador de pop-up para este site.");
}

function pop_up_rol_semAviso(url,x,y,rol)
 {
    //y -> Altura (px)
    //x -> Largura (px)
	//url -> página à abrir (parâmetro entre aspas -> "parametro")
	//rol -> Barra de rolagem ("yes" ou "no")
   
   pos_y = (screen.availHeight/2)-(y/2);
   pos_x = (screen.availWidth/2)-(x/2);
   x = window.open(url,'janela','width='+x+',directories=no,location=no,menubar=no,resizable=no,scrollbars='+rol+',status=no,toolbar=no,height='+y+',left='+pos_x+',top='+pos_y+'');
}

//----------------------------------------------------------------------
function pop_up(url,x,y,nome)
 {
   /* 
    y -> Altura
    x -> Largura
	url -> página à abrir
   */
   pos_y = (screen.availHeight/2)-(y/2);
   pos_x = (screen.availWidth/2)-(x/2);
   x = window.open(url,nome,'width='+x+',directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,height='+y+',left='+pos_x+',top='+pos_y+'');
   if(!x)
     alert("Atenção.\n\nFoi detectado um bloquador de pop-up ativado.\nPara visualizar é necessário desativar o bloqueador de pop-up para este site.");
}
//-------------------------------------------------------
function pop_up2(url,x,y)
 {
   /* 
    y -> Altura
    x -> Largura
	url -> página à abrir
   */
   pos_y = (screen.availHeight/2)-(y/2);
   pos_x = (screen.availWidth/2)-(x/2);
   window.open(url,'login','width='+x+',directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,height='+y+',left='+pos_x+',top='+pos_y+''); 
}
//-------------------------------------------------------  

function formata_cpf(campo)
{
	var tecla = event.keyCode;
	vr = "";
	if(campo.value.length < 14)
	{
		  for(i=0;i<campo.value.length;i++)
		  	  if (campo.value.charAt(i)!="." && campo.value.charAt(i)!="." && campo.value.charAt(i)!="-")
			     vr = vr + campo.value.charAt(i);
		  tam = vr.length ;
		  campo.maxLength = 14;
		  if (tam < 11 && tecla != 8)
		  {
			tam = vr.length + 1;
		  }
		  
		  if (tecla == 8)
		  { 
			tam = tam - 1 ;
		  }
		 
		  if(tam <= 3)
		  {
			campo.value = vr ;
		  } 
		  else if((tam > 3) && (tam <= 6) )
			   { 
				 campo.value = vr.substr( 0, tam - 2 ) + '.' + vr.substr( tam - 2, tam ) ;
			   } 
				  else if((tam > 6) && (tam <= 9) )
					   { 
						 campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ; 
					   } 
						  else if((tam > 9) && (tam <= 11) )
							   {
								 campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;
							   }
	}
}	

//--------------------------------------------------------

// Permite somente a digitacao de numeros
function aceita_numero() {

	if (event.keyCode==34 || event.keyCode==38 || event.keyCode==39) {
		event.keyCode=0;
	}
   	if ((event.keyCode < 48)||(event.keyCode > 57)) {
      	event.keyCode=0;
    }
}

//--------------------------------------------------------

// Valida o CPF informado
function ValidaCPF(numCPF) {
	var campo="";
	// retira carateres não numericos do identificador( CPF )
	for (i=0; i<numCPF.length;i++){
		if ((numCPF.charAt(i)!=".") && (numCPF.charAt(i)!="-") && (numCPF.charAt(i)!="/")){campo = campo + numCPF.charAt(i)}}

	if (campo.length>0)
	{
		// exclui números inválidos
		if ((campo=="00000000000") || (campo == "11111111111") || (campo == "22222222222") || (campo == "33333333333") || (campo == "44444444444") || (campo == "55555555555") || (campo == "66666666666") || (campo == "77777777777") || (campo == "88888888888") || (campo == "99999999999") || (campo == "12345678901")){return false;}
		tam = campo.length;
		// calcula primeiro digito
		val1 = tam-1;
		soma = 0
		for (i=0;i<=tam-3;i++)
		{
			val2 = campo.substring(i,i+1);
			soma = soma + ( val2 * val1);
			val1 = val1 - 1;
		}
		dig1 = 11 - (soma % 11);
		if (dig1 == 10) dig1=0 ;
		if (dig1 == 11) dig1=0 ;
		//calcula segundo digito
		val1 = 11;
		soma = 0;
		for (i=0;i<=tam-2;i++)
		{
			soma = soma + (campo.substring(i,i+1) * val1);
			val1 = val1 - 1;
		}
		dig2 = 11 - (soma % 11);
		if (dig2 == 10) dig2=0;
		if (dig2 == 11) dig2=0;
		// valida digitos verificadores
		if ((dig1 + "" + dig2) == campo.substring(tam,tam-2))
		{
			return true;
		}
		else {	return false;	}
	}
}

//-----------------------------------------------------------
 function verifica(dest)
{
  x = false;
  x = confirm("Deseja realmente remover os seus dados de nosso banco de currículos?");
  if(x)
   window.location = dest;
}
//------------------------------------------------------------
function valida()
{
  if((document.cad.nome.value == "")||(document.cad.email.value == "")||(document.cad.telefone.value == "")
     ||(document.cad.endereco.value == "")||(document.cad.numero.value == "")||(document.cad.bairro.value == "")||(document.cad.senha.value == "")
	 ||(document.cad.cep.value == "")||(document.cad.cidade.value == "")||(document.cad.estado.value == 0)||(document.cad.dia_nasc.value == '0')
	 ||(document.cad.mes_nasc.value == '0')||(document.cad.ano_nasc.value == '0'))
	 alert("Os campos marcados são campos obrigatórios");
  else  if(!ValidaCPF(document.cad.cpf.value))
	     alert("CPF Inválido.\nInforme um número correto para o CPF");
		else
		  document.cad.submit();
}
	
//------------------------------------------------------------
function monique(op)
	{
	 window.location=op;
	} 
//------------------------------------------------------------

function valida_curriculo()
{
  if((document.cad.nome.value == "")||(document.cad.email.value == "")||(document.cad.telefone.value == "")
     ||(document.cad.endereco.value == "")||(document.cad.numero.value == "")||(document.cad.bairro.value == "")
	 ||(document.cad.cep.value == "")||(document.cad.cidade.value == "")||(document.cad.estado.value == 0)||(document.cad.dia_nasc.value == '0')
	 ||(document.cad.mes_nasc.value == '0')||(document.cad.ano_nasc.value == '0'))
	 alert("Os campos marcados são campos obrigatórios");
  else  if(!ValidaCPF(document.cad.cpf.value))
	     alert("CPF Inválido.\nInforme um número correto para o CPF");
		else
		  document.cad.submit();
}
//---------------------------------------------------------------
function abre(url,x,y,rol)
 {
   /* 
    y -> Altura
    x -> Largura
	url -> página à abrir
	rol -> Rolagem (yes/no)
   */
   pos_y = (screen.availHeight/2)-(y/2);
   pos_x = (screen.availWidth/2)-(x/2);
   window.open(url,'login','width='+x+',directories=no,location=no,menubar=no,resizable=no,scrollbars='+rol+',status=no,toolbar=no,height='+y+',left='+pos_x+',top='+pos_y+''); 
}
//---------------------------------------------------------------
function formataMascara(format, field)
{
	var result = "";
	var maskIdx = format.length - 1;
	var error = false;
	var valor = field.value;
	var posFinal = false;
	if( field.setSelectionRange ) 
	{
    	if(field.selectionStart == valor.length)
    		posFinal = true;
    }
	valor = valor.replace(/[^0123456789Xx]/g,'')
	for (var valIdx = valor.length - 1; valIdx >= 0 && maskIdx >= 0; --maskIdx)
	{
		var chr = valor.charAt(valIdx);
		var chrMask = format.charAt(maskIdx);
		switch (chrMask)
		{
		case '#':
			if(!(/\d/.test(chr)))
				error = true;
			result = chr + result;
			--valIdx;
			break;
		case '@':
			result = chr + result;
			--valIdx;
			break;
		default:
			result = chrMask + result;
		}
	}

	field.value = result;
	field.style.color = error ? 'red' : '';
	if(posFinal)
	{
		field.selectionStart = result.length;
		field.selectionEnd = result.length;
	}
	return result;
}

function getTeclaPressionada(evt)
{
	if(typeof(evt)=='undefined')
		evt = window.event;
	return(evt.keyCode ? evt.keyCode : (evt.which ? evt.which : evt.charCode));
}

// teclas 63230 a 63240 = safari
function isTeclaEspecial(key)
{
	return key<32||(key>=35&&key<=36)||(key>=37&&key<=40)||key==46||(key>=63230&&key<=63240);
}

function isTeclaRelevante(key)
{
	return (key == 8)||(key == 46)||(key>=48&&key<=57)||(key>=96&&key<=105);
}

function isCaracterRelevante(key)
{
	return (key == 120)||(key>=48&&key<=57);
}

function StopEvent(evt)
{
	if(document.all)evt.returnValue=false;
	else if(evt.preventDefault)evt.preventDefault();
}

function filtraTeclas(evt)
{
	var key = getTeclaPressionada(evt);
	if(isTeclaEspecial(key) || isTeclaRelevante(key))
		return true;
	StopEvent(evt);
	return false;
}

function filtraCaracteres(evt)
{
	var key = getTeclaPressionada(evt);
	if(isTeclaEspecial(key) || isCaracterRelevante(key))
		return true;
	StopEvent(evt);
	return false;
}

function saltaCampo(campo,proxCampo,tamanhoMaximo){
	var vr = campo.value;
	var tam = vr.length;
	if (tam >= tamanhoMaximo)
	{
		proxCampo.focus();
	}
}