/**
 * Esse arquivo eh pra colocar funcoes JS do ICOX
 */

function checar(id, bool) {
    document.getElementById(id).checked = bool;
}


function checarLista(nome) {
    var ar = document.getElementsByName(nome);
    var t = ar.length;
    var chk = false;
    
    for(i = 0; i < t; i ++) { if(ar[i].checked == false) { chk = true; } }
    
    for(i = 0; i < t; i ++) { ar[i].checked = chk; }
}


function checarListaBool(nome, bool) {
    var ar = document.getElementsByName(nome);
    var t = ar.length;
    
    for(i = 0; i < t; i ++) { ar[i].checked = bool; }
}

function checarListaLida(nome, ler) {
    var ar = document.getElementsByName(nome);
    var t = ar.length;
    
    for(i = 0; i < t; i ++) { ar[i].checked = false; }
    
    for(i = 0; i < t; i ++) { 
    	if(ar[i].title == ler) {
    		ar[i].checked = true; 
    	}
    }
}

function deletarSelecionados(nome, us, pg) {
    var ar = document.getElementsByName(nome);
    var t = ar.length;
    var ax = '';
    var ir = '';
    var ct = 0;
    
    for(i = 0; i < t; i ++) { 
        if (ar[i].checked == true) {
            ax += '&item['+i+']='+ar[i].value;
            ct ++; 
        }
    }    
    ir = 'icox.php?mdl=pagina&op=apagarrecado&lista=deletar&usuario='+us+'&pagina='+pg+ax;
    if (ct > 0) { window.location = ir; }
}




function trocaClass(c1, c2, id) {
    var ob = document.getElementById(id);
    
    if(ob.className == c1) {
        ob.className = c2;
    } else {
        ob.className = c1;
    }
}


function nomeClass(classe, id) {
   document.getElementById(id).className = classe;
}


function setaValue(ob, id) {
    if (ob.value == "") { document.getElementById(id).value = ""; }
    else { document.getElementById(id).value = ob.value+" \n\n"; }
}


function trocaValue(v1, v2, id) {    
    var ob = document.getElementById(id);
    
    if(ob.value == v1) {
        ob.value = v2;
    } else {
        ob.value = v1;
    }
}


function idValue(id, v) {    
    document.getElementById(id).value = v;
}

function idDisable(id, bool) {    
    document.getElementById(id).disabled = bool;
}

function popup(url, h, w) {
	window.open(url, 'Convidar', config='height='+ h +',width='+ w +',toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');
	return false;
}

function sf() {	
	contador_caracteres('texto_conteudo', 'contador', 255);
      document.getElementById('texto_conteudo').focus();  
}

function contador_caracteres(opt_texto_conteudo, opt_contador, opt_maxSize) {
  var texto_conteudo = opt_texto_conteudo ?
    opt_texto_conteudo : "texto_conteudo";
  var contador = opt_contador ? opt_contador : "contador";
  var maxSize = opt_maxSize ? opt_maxSize : 255;
    
  var field = document.getElementById(texto_conteudo);
  if (field && field.value.length >= maxSize) {
    field.value = field.value.substring(0, maxSize);
  }
  var txtField = document.getElementById(contador);
  if (txtField) {  
    txtField.innerHTML = field.value.length;
  }
}

function carrega_img(id, img) {
    if (document.getElementById(id) == undefined) {
        document.getElementById(id + '_span').innerHTML = '<br /><img src="upload/galeria/'+img+'" class="polaroid" width="96" id="foto_usuario" />';
    } else {
    	document.getElementById(id).src = 'upload/galeria/'+img;
    }
}


function mudaFoto(im, sele) {
    var idOp = document.getElementById(sele).value;
    document.getElementById(im).src = 'upload/fotos/'+document.getElementById('hi_'+idOp).value;
}

function trocaStyle(id_item, cor) {
    ob = document.getElementById(id_item);
    ob.style.background = cor;
}

function formIdioma (c) {
    v = document.getElementById(c);
    if (v.value == '' || v.value == 'portugues.php') {
        alert ("O nome do arquivo não está dentro do padrão.");
        v.focus();
        return false;
    } else {
        return true;
    }
}