// JavaScript Document
var sVersao	= navigator.appVersion;
var ua 		= navigator.userAgent.toLowerCase();
var bIsIE 	= ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));
var IE 		= navigator.appName == 'Microsoft Internet Explorer';

function in_array(valor,tal_da_array){
	var retorno = false;
	for(var i=0;i<tal_da_array.length;i++){
		if(tal_da_array[i] == valor){
			retorno = true;
		}
	}
	return retorno;
}

function get(elemento){
	return document.getElementById(elemento);
}

function LTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str){
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

function trim(str){
   return RTrim(LTrim(str));
}

function soh_numero(numero){
	var validos = "0123456789";
	var numero_ok = '';
	for(i=0;i<numero.length;i++){
		if(validos.indexOf(numero.substr(i,1)) != -1){
			numero_ok += numero.substr(i,1);
		}
	}
	return numero_ok;
}


function conf_logout(){
	if(confirm('Você deseja realmente deslogar do animakut?')){
		window.location = '/logout.php';
	}
}

function pergunta_div(icon_opacity){
	if(icon_opacity == 'undefined'){
		var icon_opacity = 67;
	}
	querCopiar = document.createElement('DIV');
	querCopiar.id = "pergunta_fundo";
	querCopiar.style.visibility = '';
	querCopiar.style.position = 'absolute';
	querCopiar.style.zIndex = 29;
	querCopiar.style.top = '0';
	querCopiar.style.left = '0';
	querCopiar.style.width = '100%';
	querCopiar.style.backgroundColor  = '#000';
	querCopiar.style.opacity 	= icon_opacity/100;
	querCopiar.style.MozOpacity = icon_opacity/100;
	querCopiar.style.filter 	= 'alpha(opacity='+icon_opacity+')';
	
	querCopiar2 = document.createElement('DIV');
	querCopiar2.id = "pergunta";
	querCopiar2.style.visibility = '';
	querCopiar2.style.position = 'absolute';
	querCopiar2.style.zIndex = 30;
	querCopiar2.style.top = '0';
	querCopiar2.style.left = '0';
	querCopiar2.style.width = '100%';

	querCopiar.style.height = "3000px";
	document.body.appendChild(querCopiar);
	document.body.appendChild(querCopiar2);
}

function remove_pergunta(){
	document.body.removeChild(get('pergunta'));
	document.body.removeChild(get('pergunta_fundo'));	
}


function adicionar_aos_favoritos(){
    var url        	= "http://www.animakut.com";
    var title    	= "Animakut - Gifs com Glitter e Recados Animados para orkut, hi5, fotolog, flog, blog, msn, msnspaces.";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    } else if(document.all){
		window.external.AddFavorite(url, title);
	}
}

/*
	Report Color 
*/
	corClick = '#ffcc99';
	corOver	 = '#feefe7';
	corOut	 = '#ffffff';
	ativoAtual = false;
function trC(obj, acao){
	switch(acao){
		case 'over':
			if(obj.bgColor!=corClick){
				obj.style.backgroundColor = corOver;
			}
		break;
		case 'out':
			if(obj.style.backgroundColor!=corClick){
				obj.style.backgroundColor = corOut;
			}
		break;
		
		case 'click':
			if(obj.style.backgroundColor != corClick){
				obj.style.backgroundColor = corClick;
//				obj.style.fontWeight = 'bolder';
				if(ativoAtual){ ativoAtual.style.backgroundColor=corOut; ativoAtual.style.fontWeight = ''; }
				ativoAtual = obj;
			} else {
				obj.style.backgroundColor = corOver;
				obj.style.fontWeight = '';
			}
		break;
	}	
}

function indicar_para_amigo(){
	pergunta_div(70);
	get('pergunta').innerHTML = "<br><br><br><br>"+
	"<form method='post' id='formIndique' action='/conector.php'> <input type='hidden' name='acao' value='indique'>"+
	"<center><img src='http://static.animakut.com/img/th_indique.png?1'><br><table width='450' cellspacing=0 cellpadding=4 bgcolor='#ffffff' style='border: 1px solid #A94AF7; margin-top: -2px;'>"+
	"<tr><th align=right> Seu nome:&nbsp;</th> <td align=left><input type='text' title='seu nome' name='from_nome' size='20' class='vr_obrigatorio'></td> </tr>"+
	"<tr><th align=right valign=top> E-mails amigos:&nbsp;</th> <td align=left><textarea name='emails_to' cols=30 rows=4></textarea><br><font color=#333 size=1>separados por , ou nova linha (&lt;enter&gt;)</font></td> </tr>"+
	"<tr><th align=right valign=top> Texto indicação:&nbsp;</th> <td align=left><textarea name='texto' cols=30 rows=4>eu achei esse site muito show, tem um monte de gifs animados, acessa aí, acho que você vai curtir!</textarea></td></tr>"+
	"<tr><th align=right valign=top> Indicar qual endereço?;</th> <td align=left><input type='radio' name='url' value='http://www.animakut.com/'> http://www.animakut.com/<br> <input type='radio' name='url' value='"+window.location.href+"' checked=checked> endereço atual</td></tr>"+
	"<tr><td align=center> <input type=button value='cancelar' onClick='remove_pergunta();'></td> <td align=center> <input type='submit' value='enviar'></td> </tr>"+
	"</table></center>";
	ttrValidacao.adicionarForm('formIndique', true);
}


/*****************/

function votar_imagem(codigo_imagem, avaliacao){
	ttrAdicionaLoading();
	get_url("/conector.php", 'ttr_retorno_ajax', "acao=votar&tipo=imagem&codigo_imagem="+codigo_imagem+"&avaliacao="+avaliacao);
}

function seleciona_box(codigo_imagem){
	obj_textarea = get('textarea_'+codigo_imagem);
	obj_text 	 = get('text_'+codigo_imagem);
	
	obj_textarea.select();
	obj_textarea.focus();
	obj_text.innerHTML = "Copie o c&oacute;digo usando <strong>Ctrl + C</strong> e cole no Orkut ou site usando <strong>Ctrl + V</strong>";
	
	obj_acesso = new Image();
	obj_acesso.src = "/conector.php?acao=acesso&tipo=imagem&codigo="+codigo_imagem;
}

function reload_who(){
	objLoad2 = new Image();
	objLoad2.src = 'http://whos.amung.us/widget/p4m6qg2g.png';
	setTimeout('reload_who()', 300000);
}

objLoad = new Image();
objLoad.src = 'http://static.animakut.com/img/menu_a_hover.png';
