function getSegmentacaoId(url){
	regiao_id = $('regiao_id').value;
	faturamento_id = $('faturamento_id').value;
	ramo_id = $('ramo_id').value;
	area_geral_id = $('area_geral_id').value;
	area_especifica_id = $('area_especifica_id').value;
	cargo_id = $('cargo_id').value;
	
	url = url+'?regiao_id='+regiao_id+'&faturamento_id='+faturamento_id+'&ramo_id='+ramo_id+'&area_geral_id='+area_geral_id+'&area_especifica_id='+area_especifica_id+'&cargo_id='+cargo_id;

	NewWindow(url,'segmentacao','800','600');
}


function carregar_calendario(entrada,botao) {
    Calendar.setup(
    {
	inputField : entrada, // ID of the input field
	ifFormat : "%d/%m/%Y", // the date format
	button : botao // ID of the button
	}
    );
}

function fnVolta(link){

	window.opener.location = link;
	window.close();
}

function fnVoltaNoClose(link){

	window.opener.location = link;
}

function validaSegmentacao(){
	if($('regiao_id').value == ""){
		alert("Por favor selecione uma REGIÃO");
		$('regiao_id').focus();
		return false;
	}
	if($('faturamento_id').value == ""){
		alert("Por favor selecione um FATURAMENTO");
		$('faturamento_id').focus();
		return false;
	}
	if($('ramo_id').value == ""){
		alert("Por favor selecione um RAMO");
		$('ramo_id').focus();
		return false;
	}
	if($('area_geral_id').value == ""){
		alert("Por favor selecione uma ÁREA GERAL");
		$('area_geral_id').focus();
		return false;
	}
	if($('area_especifica_id').value == ""){
		alert("Por favor selecione uma ÁREA ESPECÍFICA");
		$('area_especifica_id').focus();
		return false;
	}
	if($('cargo_id').value == ""){
		alert("Por favor selecione um CARGO");
		$('cargo_id').focus();
		return false;
	}
}

function fnOpenPop(url){
	msgErro = "";
	if ($('regiao_id').value == '') {
		msgErro += '<strong>Região</strong>'+", ";
	}
	if ($('faturamento_id').value == '') {
		msgErro += '<strong>Faturamento</strong>'+", ";
	}
	if ($('ramo_id').value == '') {
		msgErro += '<strong>Ramo</strong>'+", ";
	}
	if ($('area_geral_id').value == '') {
		msgErro += '<strong>Área Geral</strong>'+", ";
	}
	if ($('area_especifica_id').value == '') {
		msgErro += '<strong>Área Específica</strong>'+", ";
	}
	if ($('cargo_id').value == '') {
		msgErro += '<strong>Cargo</strong>'+", ";
	}
	
	if (msgErro != "") {
	  msgErro = 'Você deve selecionar o(s) campos(s) ' + msgErro;
	  msgErro = msgErro.substring(0, (substring.length -1))
		$('msgSegmentacao').innerHTML = msgErro;
		$('msgSegmentacao').show();
		return false;
	} else {
		$('msgSegmentacao').hide();
		getSegmentacaoId(url);
		return false;
	}
}


//função para obrigar preenchimento ou seleção de campo
function obrigatorio(ids,titulos) {
   var id,titulo,i,tipo
      
   id = ids.split("|");
   titulo = titulos.split("|");  
   
   for (i=0;i < id.length;i++) {
   		
   	   tipo = $(id[i]).type;
   	   
      if(!$(id[i]).value || $(id[i]).value.trim() == ""){
         tipo = $(id[i]).type;
         if (tipo == "select-one"){
            alert("O campo "+titulo[i]+" deve ser selecionado");
         }else{
            if((tipo == "text") || (tipo == "textarea") || (tipo == "password")){
              	 alert("O campo "+titulo[i]+" deve ser preenchido");
            }
            
         }
         $(id[i]).focus();
         return false;
      }
   }
   return true;
}


function obrigatorioV2(ids, titulos, elementId, mensagem) {
  var id,titulo,i,tipo
  var exp_valida_email = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/
  
  id = ids.split("|");
  titulo = titulos.split("|");
  msg = '';
  var  apenasEmail = true;
  for (i=0;i < id.length;i++) {
    tipo = $(id[i]).type;
    if(!$(id[i]).value || $(id[i]).value.trim() == ""){
      apenasEmail = false;
      tipo = $(id[i]).type;
      if (tipo == "select-one"){
        msg += "O campo "+titulo[i]+" deve ser selecionado"+"<br />";
      }else{
        if((tipo == "text") || (tipo == "textarea") || (tipo == "password")){
          msg += "O campo "+titulo[i]+" deve ser preenchido"+"<br />";
        }
      }
    }else if($(id[i]).name.search(/email/i) >= 0){
      if(exp_valida_email.test($(id[i]).value) == false){
        msg += "Por favor, digite um "+titulo[i]+" valido."+"<br />";
      }
    }
  }
  if (msg != "") {
    if (titulos == '') {
      if (!apenasEmail) {
        if ((mensagem == null)) {
          msg = "Os campos marcados com <strong>*</strong> são de preenchimento obrigatórios.";
        } else {
          msg = mensagem;
        }
      }
      else {
        msg = "O campo <strong>email</strong> está preenchido incorretamente.";
      }
    }
    elementId = (elementId == null) ? 'msgRetorno' : elementId;
    document.getElementById(elementId).className = 'clean-error';
    document.getElementById(elementId).innerHTML = msg;
    document.getElementById(elementId).style.display = '';
    return false;
  } else {
    return true;
  }
}


function somente_numero(campo){
    var digits="0123456789";
    var campo_temp ;
    for (var i=0;i< campo.value.length;i++){
        campo_temp=campo.value.substring(i,i+1) 
        if (digits.indexOf(campo_temp)==-1){
            campo.value = campo.value.substring(0,i);
            break;
        }
    }
}


function f_verifica(xobj)
{
    if (xobj.nome.value == "") {
        alert("O nome deve ser preenchido");
        xobj.nome.focus();
        return false;
    }

    if (xobj.email.value == "") {
        alert("O email deve ser preenchido");
        xobj.nome.focus();
        return false;
    }

    if (xobj.ddd_com.value == "") {
        alert("O ddd deve ser preenchido");
        xobj.nome.focus();
        return false;
    }

    if (xobj.fone_com.value == "") {
        alert("O telefone deve ser preenchido");
        xobj.nome.focus();
        return false;
    }

	    // Qual o seu grau de satisfação com os serviços oferecidos pela Pesquisa Salarial e de Benefícios?
	if (xobj.grau_satisfacao.value == ""){
		alert("Por favor, especifique o grau de satisfação com os serviços oferecidos pela Pesquisa Salarial e de Benefícios");
		xobj.grau_satisfacao.focus();
		return false;
	}
	
	// Motivo de cancelamento
	checado = 0;
	for (x = 0; x < xobj.motivo_cancelamento.length; x++){
	    if (xobj.motivo_cancelamento[x].checked){
	        checado = 1;
	    }
	}
	
	if (checado == 0 && xobj.motivo_outros.value == ""){
		alert("Por favor, especifique o motivo de cancelamento");
		return false;
	}
	
	// Quais recomendações faria para melhorarmos?
	if (xobj.recomendacoes.value == ""){
		alert("Por favor, especifique quais recomendações faria para melhorarmos");
		xobj.recomendacoes.focus();
		return false;
	}
	
	
	// Você recomendaria a Pesquisa Salarial e de Benefícios à alguém que estivesse em busca deste tipo de serviço?
	if (!xobj.recomendaria[0].checked && !xobj.recomendaria[1].checked){
		alert("Por favor, informe se você recomendaria a Pesquisa Salarial e de Benefícios à alguém que estivesse em busca deste tipo de serviço");
		return false;
	}
	
	// Dê seu depoimento a respeito do site da Pesquisa Salarial e de Benefícios.
	if (xobj.depoimento.value == ""){
		alert("Por favor, dê seu depoimento a respeito do site da Pesquisa Salarial e de Benefícios");
		xobj.depoimento.focus();
		return false;
	}
	
	// Você autoriza a divulgação de suas respostas nestas questões?
	if (!xobj.autoriza[0].checked && !xobj.autoriza[1].checked){
		alert("Por favor, informe se você autoriza a divulgação de suas respostas nestas questões");
		return false;
	}
	
	//return false;
}

function verificaCarrinho(){
	

}