<!--
// funções de Javascript




//AJAX_________________________________________

function cria_ajax()
	{
	var xmlhttp;
	try
		{
		xmlhttp = new XMLHttpRequest();
		}
	catch(ee)
		{
		try
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch(e)
			{
			try
				{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(E)
				{
				xmlhttp = false;
				}
			}
		}
	return xmlhttp;
	}



function exclui_video_hd(id_video)
	{
	var quadro=document.getElementById('video_hd_atual');
		quadro.innerHTML="Aguarde...";

	var xmlhttp=cria_ajax();
	xmlhttp.open("GET", "../ferramentas/ajax_exclui_video_hd.php?id_video=" + id_video, true);
	xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4)
			{
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			
			quadro.innerHTML=texto;
			lista_video_uploads();
			}
		}
	xmlhttp.send(null);
	delete xmlhttp;
	}


function exclui_imagem_repertorio(id_texto)
	{
	var quadro=document.getElementById('box_texto_atual');
		quadro.innerHTML="Aguarde...";

	var xmlhttp=cria_ajax();
	xmlhttp.open("GET", "../ferramentas/ajax_exclui_imagem_repertorio.php?id_texto=" + id_texto, true);
	xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4)
			{
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			
			quadro.innerHTML=texto;
			}
		}
	xmlhttp.send(null);
	delete xmlhttp;
	}


function lista_uploads()
	{
	var quadro=parent.document.getElementById('box_lista_arquivos');
		quadro.style.display='none';

	var quadro_loading=parent.document.getElementById('load_arquivos');
		quadro_loading.style.display='block';

	var xmlhttp=cria_ajax();
	xmlhttp.open("GET", "../ferramentas/ajax_lista_uploads.php", true);
	xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4)
			{
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			//alert(texto);
			
			quadro.innerHTML=texto;
			quadro.style.display='block';
			quadro_loading.style.display='none';
			}
		}
	xmlhttp.send(null);
	delete xmlhttp;
	}


function seleciona_arquivo(nome_arquivo_selecionado)
	{
	var campo=parent.document.getElementById('nome_arquivo');
		campo.value=nome_arquivo_selecionado;

	var quadro=parent.document.getElementById('arquivo_selecionado');
		quadro.innerHTML='<strong>Arquivo selecionado:</strong> ' + nome_arquivo_selecionado;
	}


function seleciona_arquivo_hd(nome_arquivo_selecionado)
	{
	var campo=parent.document.getElementById('nome_arquivo_hd');
		campo.value=nome_arquivo_selecionado;

	var quadro=parent.document.getElementById('arquivo_selecionado_hd');
		quadro.innerHTML='<strong>Arquivo selecionado:</strong> ' + nome_arquivo_selecionado;
	}




function lista_video_uploads()
	{
	lista_video_hd_uploads();
	
	var quadro1=parent.document.getElementById('box_lista_arquivos');
		quadro1.style.display='none';

	var quadro_loading1=parent.document.getElementById('load_arquivos');
		quadro_loading1.style.display='block';

	var xmlhttp=cria_ajax();
	xmlhttp.open("GET", "../ferramentas/ajax_lista_video_uploads.php", true);
	xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4)
			{
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			//alert(texto);
			
			quadro1.innerHTML=texto;
			quadro1.style.display='block';
			quadro_loading1.style.display='none';
			}
		}
	xmlhttp.send(null);
	delete xmlhttp;
	}



function lista_video_hd_uploads()
	{
	var quadro2=parent.document.getElementById('box_lista_arquivos_hd');
		quadro2.style.display='none';

	var quadro_loading2=parent.document.getElementById('load_arquivos_hd');
		quadro_loading2.style.display='block';

	var xmlhttp=cria_ajax();
	xmlhttp.open("GET", "../ferramentas/ajax_lista_video_hd_uploads.php", true);
	xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4)
			{
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			//alert(texto);
			
			quadro2.innerHTML=texto;
			quadro2.style.display='block';
			quadro_loading2.style.display='none';
			}
		}
	xmlhttp.send(null);
	delete xmlhttp;
	}

//_____________________________________________


function validaCPF(formulario) {
                 var cpf = document.forms[formulario].cnpj.value;
                 erro = new String;
                 if (cpf.length < 11) erro = "CPF inválido!"; 
                 var nonNumbers = /\D/;
                 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! "; 
                 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
                         erro = "CPF inválido!"; 
               }
               var a = [];
               var b = new Number;
               var c = 11;
               for (i=0; i<11; i++){
                       a[i] = cpf.charAt(i);
                       if (i < 9) b += (a[i] * --c);
               }
               if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
               b = 0;
               c = 11;
               for (y=0; y<10; y++) b += (a[y] * c--); 
               if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
               if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
                       erro = "CPF inválido!"; 
               }
               if (erro.length > 0)
		       {
                       alert(erro);
                       document.forms[formulario].cnpj.focus();
                       return false;
               	       }
		else 
		       {
        	       return true;
		       }
	}



function validaCNPJ(formulario) 
		{
		CNPJ = document.forms[formulario].cnpj.value;
		erro = new String;
		if (CNPJ.length < 14) erro = "CNPJ inválido! O número deve conter 14 carateres. \n\nVerifique se há um zero à esquerda deste CNPJ.";

		if (erro.length == 0)
			{
			var a = [];
			var b = new Number;
			var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
			for (i=0; i<12; i++)
			     {
			     a[i] = CNPJ.charAt(i);
				 b += a[i] * c[i+1];
				 }
		    if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
			b = 0;
			for (y=0; y<13; y++) 
			    {
				b += (a[y] * c[y]); 
				}
		    if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
			if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]))
			    {
				erro = "CNPJ inválido!";
				}
		    }

		if (erro.length > 0)
			{
			alert(erro);
            document.forms[formulario].cnpj.focus();
			return false;
			}
		else 
		    {
        	return true;
		    }
	}



function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function






function checar(formulario)
{
for(var i=0;i<formulario.elements.length;i++)
     {
	 
	 var campo=formulario.elements[i];
	 
	 if(campo.type=="text" || campo.type=="hidden" || campo.type=="select" || campo.type=="select-one" || campo.type=="password" || campo.type=="file" || campo.type=="textarea" || campo.type=="radio")
	      {
	 	  var obriga=campo.getAttribute('obrigatorio');
	 	  var nomecampoatual=campo.getAttribute('nomecampo');
		  
		  if(campo.type=="radio" && obriga==1)
		       {
			   var meuradio=document.getElementsByName(campo.getAttribute('name'));
			   var preencheu = false;
			   for (var k=0; k<meuradio.length; k++) 
			             {
						 //alert(k + "- teste: " + meuradio[k].value + " está " + meuradio[k].checked);
						 
						 if (meuradio[k].checked)
						           {
								   preencheu = true;
								   }
  						 }
			  if (preencheu==false)
			            {
						alert("Ao menos uma das opções do campo '" + nomecampoatual + "' deve ser selecionada.");
			   			return false;
						break;
						}
			   }
		  else if(obriga==1 && trim(campo.value)=="")
		       {
			   alert("O campo '" + nomecampoatual + "' não pode ficar vazio.");
			   campo.focus();
			   return false;
			   break;
			   }
		  }
	 }
return true;
}



function limita_texto(field, countfield, maxlimit) 
     {
	 if (field.value.length > maxlimit) // if too long...trim it!
	      {
		  field.value = field.value.substring(0, maxlimit);
		  }
     else 
	      {
		  countfield.innerHTML = maxlimit - field.value.length;
		  }
     }



function pular(el)
	{
	if (el.value.length < el.getAttribute('maxlength')) return;
	
	var f = el.form;
	var els = f.elements;
	var x, nextEl;
	for (var i=0, len=els.length; i<len; i++)
		{
		x = els[i];
		if (el == x && (nextEl = els[i+1]))
			{
			if (nextEl.focus) nextEl.focus();
			}
		}
	}






function toca_video(arquivo, arquivo_original)
	{
	var destino = "videoplayer.php?arquivo_video=" + arquivo + "&arquivo_original=" + arquivo_original;
	
	var largura=600;
	var altura=400;
	var esquerda=(screen.availWidth-largura)/2;
	var topo=(screen.availHeight-altura)/2;
	
	window.open(destino, '','toolbar=no, scrollbars=no, left=' + esquerda + ', top=' + topo + ', width=' + largura + ', height= ' + altura + ''); 
	}


function confirma(destino, mensagem)
{

var quero;

quero=window.confirm(mensagem);

if(quero)
     {
	 window.location.href=destino;
	 }
}



function checkAll(theForm, cName) {
for (i=0,n=theForm.elements.length;i<n;i++)
if (theForm.elements[i].className.indexOf(cName) !=-1)
if (theForm.elements[i].checked == true) {
theForm.elements[i].checked = false;
} else {
theForm.elements[i].checked = true;
}
}



//______________________________________________



function switch_box(numero)
	{
	if(numero==1)
		{
		document.getElementById('box_funcionario').style.display='block';
		document.getElementById('box_cliente').style.display='none';
		}
	else
		{
		document.getElementById('box_funcionario').style.display='none';
		document.getElementById('box_cliente').style.display='block';
		}
	}


//______________________________________________


function lista_jobs(id_cliente, id_job_selecionado)
	{
	//alert(id_cidade + "-" + id_categoria_selecionada);
	toggle_job_selecionado(id_job_selecionado); // --> zera o input hidden para não permitir postar sem escolher um job (caso o combo não apareça porque o cliente não tem job ainda)
	
	var quadro=document.getElementById('campo_jobs');
	quadro.innerHTML="Pesquisando jobs...";
	quadro.style.display='block';
	
	var Ajax = cria_ajax(); // Inicia o Ajax. 
	Ajax.open("GET", "../ferramentas/ajax_lista_jobs.php?id_cliente=" + id_cliente + "&id_job_selecionado=" + id_job_selecionado, true); // fazendo a requisição 
	Ajax.onreadystatechange = function() 
		{ 
		if(Ajax.readyState == 4) 
			{ // Quando estiver tudo pronto. 
			if(Ajax.status == 200) 
				{
				var texto = Ajax.responseText; // Coloca o retornado pelo Ajax nessa variável 
				texto = texto.replace(/\+/g," "); // Resolve o problema dos acentos (saiba mais aqui: http://www.plugsites.net/leandro/?p=4) 
				texto = unescape(texto); // Resolve o problema dos acentos 
				//alert(texto);
				
				dados=eval(texto);
				
				var erro=dados[0];
				var mensagem=dados[1];
				
				if(erro==1)
					{
					quadro.innerHTML="erro! " + mensagem;
					}
				else
					{
					quadro.innerHTML=mensagem;
					}
				
				quadro.style.display='block';
				}
			}
		}
	Ajax.send(null); // submete 
	}


//______________________________________________



function init()
	{
		
	//___inicia o menu superior_________________________
	DynarchMenu.setup('menusup', {electric: true});
	//__________________________________________________
	
	
	
	//___cria o listener para o acordion do menu esquerdo_____
	vetor_caixas=$$('h3.boxmenu');
	for(i=0; i<vetor_caixas.length; i++)
		{
		Event.observe(vetor_caixas[i], 'click', toggle_box);
		}
	//_________________________________________________
	}



function toggle_box(e)
	{
	var item_clicado=Event.element(e);
	item_clicado.toggleClassName('on');
	var id_item=item_clicado.readAttribute('id_item');
	var box='box_' + id_item;
	//alert(box);
	//$(box).toggle();

	if(item_clicado.hasClassName('on'))
		{
		//alert('abre');
		Effect.SlideDown(box, {duration: 0.2});
		//$(box).show();
		}
	else
		{
		//alert('fecha');
		Effect.SlideUp(box, {duration: 0.5});
		//$(box).hide();
		}
	}



function box_peca()
	{
	var caixa=$('div_peca');
	caixa.toggleClassName('on');
	if(caixa.hasClassName('on'))
		{
		Effect.Appear(caixa, {duration: 0.5});
		//Effect.SlideDown(caixa, {duration: 0.2});
		}
	else
		{
		Effect.Fade(caixa, {duration: 0.5});
		//Effect.SlideUp(caixa, {duration: 0.5});
		}
	}


function toggle_job_selecionado(id_job)
	{
	alvo=document.getElementById('id_job_selecionado');
	//alert('selecionou: ' + id_job);
	alvo.value= id_job==0 ? "" : 1;
	}




//___funções para o upload_____________________________________

iframe_progresso=	parent.document.getElementById("progresso");
box_progresso=		parent.document.getElementById("box_progresso");
box_upload=			parent.document.getElementById("box_upload");

function startupload(id_progresso) {
	iframe_progresso.src='_progress.asp?progressid=' + id_progresso;
	box_progresso.style.display='block';
	box_upload.style.display='none';

	document.theForm.action="_formresp.asp?progressid=" + id_progresso;
	document.theForm.submit();
}

function enviar_outro() {
	iframe_progresso.src='_blank.htm';
	
	box_progresso.style.display='none';
	box_upload.style.display='block';
}


//______________________________________________________

function __cliente_startupload(id_progresso) {
	nome_arquivo= document.getElementById('myFile').value.replaceAll(" ", "_");
	//alert('nome_arquivo: ' + nome_arquivo);
	
	iframe_progresso.src='__cliente_progress.asp?nome_arquivo=' + nome_arquivo + '&progressid=' + id_progresso;
	box_progresso.style.display='block';
	box_upload.style.display='none';

	document.theForm.action="__cliente_formresp.asp?progressid=" + id_progresso;
	document.theForm.submit();
}

function salvar_upload_enviado(nome_arquivo)
	{
	var xmlhttp=cria_ajax();
	xmlhttp.open("GET", "ferramentas/ajax_salvar_upload_enviado.php?nome_arquivo=" + nome_arquivo, true);
	xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4)
			{
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			
			parent.document.location.href='meus_arquivos.php';
			}
		}
	xmlhttp.send(null);
	delete xmlhttp;
	}


//______________________________________________________

function video_startupload(id_progresso) {
	nome_arquivo= document.getElementById('myFile').value.replaceAll(" ", "_");
	extensao=nome_arquivo.substring(nome_arquivo.length-3, nome_arquivo.length).toLowerCase();
	if(extensao!='flv')
		{
		//alert('nome_arquivo: ' + nome_arquivo + ', extensão: ' + extensao);
		alert('Extensão inválida. São permitidos somente arquivos FLV.');
		return false;
		}
	else
		{
		iframe_progresso.src='_progress.asp?nome_arquivo=' + nome_arquivo + '&progressid=' + id_progresso;
		box_progresso.style.display='block';
		box_upload.style.display='none';
	
		document.theForm.action="_formresp.asp?progressid=" + id_progresso;
		document.theForm.submit();
		return true;
		}
}

//______________________________________________________


String.prototype.replaceAll=function(strTarget, strSubString) {
	var strText = this;
	var intIndexOfMatch = strText.indexOf(strTarget);
	 
	while (intIndexOfMatch != -1) {
		strText = strText.replace(strTarget, strSubString)
		intIndexOfMatch = strText.indexOf(strTarget);
	}
	 
	return(strText);
}



-->
