//Utilizada para validar itens da area do cliente
var obj;

// TRIM COMPLETO
String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g,"");
}
 
// TRIM A ESQUERDA
String.prototype.ltrim = function () {
    return this.replace(/^\s+/,"");
}
 
// TRIM A DIREITA
String.prototype.rtrim = function () {
    return this.replace(/\s+$/,"");
}

// ABRIR PÁGINA EM DIV (JQUERY.JS)
function displayOnDivId(pagina, div) {
	$("#"+div).load(pagina); 
};

// SCROLL TOP
function toTop() {
	self.scrollTo(0, 0)
}

// VERIFICA SE HÁ CAMPO
function verificarCampo(targetForm) {
	form = document.getElementById(targetForm);
	for (i=0; i<form.elements.length; i++) {
		if (form.elements.item(i).nodeName == 'INPUT') {
			if (form.elements.item(i).name == 'iERR') {
				return true;
			}
		}
	}
}
//Oculta Div Login/Senha Blackout
function ocultaDiv(pobj1, pobj2){
	var obj1 = document.getElementById(pobj1);
	var obj2 = document.getElementById(pobj2);
	obj1.style.display = 'none'
	obj2.style.display = 'none'
}
//POPUP
function PopupCenter(pageURL, title,w,h) {
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

//Carrega Area do Cliente ao Logar com modal
function preenchediv(){
    if (ajax.readyState == 4) {
        if (ajax.status == 200 ) {
            document.getElementById("content").innerHTML = ajax.responseText;
        }
    }
}

function carregaDiv(caminho){
    enviarpost('POST', caminho,'',preenchediv);
}

//Capturar Nome do Item e caminho selecionado na Área do Cliente
function capturaItem(pobj){
	obj = pobj
	return obj;
}
//Carrega Item selecionado na Area do cliente
function carregaItem(){
	switch (obj){
    case 'chat':
		displayOnDivId('_areaDoCliente/chat.php', 'areaDoCliente');
      break;
    case 'treinamento':
		displayOnDivId('_areaDoCliente/treinamento.php', 'content');
      break;
    case 'enquete':
		displayOnDivId('_areaDoCliente/enquete.php', 'content');
      break;
    case 'noticias':
		displayOnDivId('_areaDoCliente/noticias.php', 'areaDoCliente');
      break;
    case 'downloads':
		displayOnDivId('_areaDoCliente/downloads.php', 'content');
      break;
    case 'sac':
		displayOnDivId('_areaDoCliente/sac.php', 'areaDoCliente');
      break;
    case 'atendimento':
	  displayOnDivId('_areaDoCliente/atendimento.php', 'areaDoCliente')
      break;
    case 'usuarios':
	  displayOnDivId('_areaDoCliente/usuarios.php', 'areaDoCliente')
      break;
 }
}
// RETORNA O VALOR DO RADIO BUTTON SELECIONADO
function valorRadioButtom(form, campo){
	var opcao;
	
	for(var i = 0; i < eval('document.'+form+'.'+campo+'.length'); i++) {
		var opcao = eval('document.'+form+'.'+campo+'[i]');
		if (opcao.checked) 	{
			opcao = opcao.value;
			break;
		}
	}
	if(opcao == '[object HTMLInputElement]') return 0; else return opcao;
}

//MASCARAS
function redireciona(caminho) {
	document.location = caminho;
}

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function dta(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    return v
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function FormataMascara(e,src,mask) {
	if(window.event) { _TXT = e.keyCode; }
	else if(e.which) { _TXT = e.which; }
	if(_TXT > 47 && _TXT < 58) {
		var i = src.value.length; var saida = mask.substring(0,1); var texto = mask.substring(i)
		if (texto.substring(0,1) != saida) { src.value += texto.substring(0,1); }
		return true; } else { if (_TXT != 8) { return false; }
	else { return true; }
	}
}

function leech(v){
	v=v.replace(/o/gi,"0")
	v=v.replace(/i/gi,"1")
	v=v.replace(/z/gi,"2")
	v=v.replace(/e/gi,"3")
	v=v.replace(/a/gi,"4")
	v=v.replace(/s/gi,"5")
	v=v.replace(/t/gi,"7")
	return v
}

function Formatadata(Campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;
	if (tecla != 8 && tecla != 8){
		if (tam > 0 && tam < 2)
		Campo.value = vr.substr(0, 2) ;
		if (tam > 2 && tam < 4)
		Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2);
		if (tam > 4 && tam < 7)
		Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, 7);
	}
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function Cpf(v){
	v=v.replace(/\D/g,"")                    
	v=v.replace(/(\d{3})(\d)/,"$1.$2")       
	v=v.replace(/(\d{3})(\d)/,"$1.$2")       
											 
	v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") 
	return v
}


function Cep(v){
	v=v.replace(/D/g,"")                
	v=v.replace(/^(\d{5})(\d)/,"$1-$2") 
	return v
}


function Cnpj(v){
	v=v.replace(/\D/g,"")                   
	v=v.replace(/^(\d{2})(\d)/,"$1.$2")     
	v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") 
	v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           
	v=v.replace(/(\d{4})(\d)/,"$1-$2")              
	return v
}

function Valor(v){
	v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
	v=v.replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/,"$1.$2");
	//v=v.replace(/(\d{3})(\d)/g,"$1,$2")
	v=v.replace(/(\d)(\d{2})$/,"$1.$2") //Coloca ponto antes dos 2 últimos digitos
	return v
}



///////////////////////
