//Checa o campo E-Mail
function verifica_mail(email){
	var campo = email;
	//se a "@" nÃ£o existe e Ã© o primeiro caractere 
	if (campo.indexOf("@") < 1) return false
	//se o caracter antes da "@" Ã© "." 
	if(campo.charAt(campo.indexOf("@")-1) == ".") return false;
	//se a Ãºltima incidÃªncia de "." estÃ¡ antes da @ 
	if (campo.lastIndexOf(".") <= campo.indexOf("@")) return false;
	//se o Ãºltimo caracter Ã© ponto,
	if (campo.lastIndexOf(".")  == (campo.length-1)) return false; 
	
	return true;
}
// FUNÃ‡ÃƒO QUE FORMATA CAMPO DE ACORDO COM A ESPECIFICAÃ‡ÃƒO '/'
// COMO UTILIZAR:    onKeyPress="return txtBoxFormat(document.form1, 'telefone', '(99) 9999-9999', event);"
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode; }
else if(document.layers) { // Nestcape
nTecla = evtKeyPress.which;
}

sValue = objForm[strField].value;

// Limpa todos os caracteres de formataÃ§Ã£o que
// jÃ¡ estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( ":", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
bolMask = bolMask || (sMask.charAt(i) == ":")

if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}

i++;
}

objForm[strField].value = sCod;

if (nTecla != 8) { // backspace
if (sMask.charAt(i-1) == "9") { // apenas nÃºmeros...
return ((nTecla > 47) && (nTecla < 58)); } // nÃºmeros de 0 a 9
else { // qualquer caracter...
return true;
} }
else {
return true;
}
}
// COMO UTILIZAR: onkeypress="evita_letra2(event)"
// NÃ£o permite digitar letras em um input type=text
function evita_letra2(tecla) {
	if (tecla.keyCode < 48 || tecla.keyCode > 57) 
		tecla.returnValue = false;
}

var JGCookie = {
  date: new Date(),
  set: function(name, content, days) {
    var expires = "";
    if(days) {
	  this.date.setTime(this.date.getTime()+(days*24*60*60*1000));
      expires = this.date.toGMTString() + "; ";
	}
	document.cookie = name + "=" + content + "; " + expires + "path=/";
	return true;
  },
  get: function( name ) {
  	var nameE = name + "=";
	var cookies = document.cookie.split(";");
	for(var i = 0, Cookie; Cookie = cookies[i]; i++) {
	  while(Cookie.charAt(0) == " ") {
	  	Cookie = Cookie.substring(1,Cookie.length);
	  }
	  if(Cookie.indexOf(nameE) == 0) {
	  	return Cookie.substring(nameE.length,Cookie.length);
	  }
	}
	return false;
  },
  unset: function( name ) {
  	this.set(name, "", -1);
  	return true;
  }
  
}
//JGCookie.set("Key", "Value", 1); // Setamos (nome, valor, duracao)
//JGCookie.get("Key"); // Lemos (nome)
//JGCookie.unset("Key"); // Apagamos (nome)


	function estrela(v, c){
		//v = numero do id
		//c = class a ser mudada - se for 1 Ã© para selecionar
		var nota = document.getElementById("estrelaV").value;
		var i = 1;
		if(c=="1"){
			while(i<=v){
				document.getElementById("estrela"+i).className="seleciona";
				i++;
			}
		}else{
			i=1;
			while(i<=5){
				if(nota!=parseInt(nota) && parseInt(nota)==i-1){
					document.getElementById("estrela"+i).className="meia";
				}else if(i<=nota){
					document.getElementById("estrela"+i).className="cheia";
				}else if(i>nota && i<=5){
					document.getElementById("estrela"+i).className="vazia";
				}
				i++;
			}
		}
	}
String.prototype.trim = function(){
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
	function verifica_host(){
		var url = window.location.href;
		if(url.search(".com.br") != -1){
			return "http://www.habbid.com.br/";
		}else if(url.search(".org") != -1){
			return "http://www.habbid.org/";
		}
	}
//JANELAS POP UP
	function pop_tir(id){
		window.open(verifica_host()+"modulos/tirinhas/tirinhas_popup.php?id="+id, "TIRINHA", "height=600, width=600, scrollbars=yes, status=yes, menubar=yes, toolbar = no, location = no");
	}
	function pop_valores(id_rare){
		window.open(verifica_host()+"modulos/valores/pop_mobi.php?id="+id_rare, "TIRINHA", "height=600, width=600, scrollbars=yes, status=yes, menubar=yes, toolbar = no, location = no");
	}

	function pop_pix(id){
		window.open(verifica_host()+"modulos/pixelclub/pixelclub_popup.php?id="+id, "PixelClub", "height=600, width=600, scrollbars=yes, status=yes, menubar=yes, toolbar = no, location = no");
	}
	
//CORES DO SITE
	function hexFromRGB (r, g, b) {
		var hex = [
			r.toString(16),
			g.toString(16),
			b.toString(16)
		];
		$.each(hex, function (nr, val) {
			if (val.length == 1) {
				hex[nr] = '0' + val;
			}
		});
		return hex.join('').toUpperCase();
	}

	function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
	function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
	function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
	function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}

	function refreshSwatch() {
		var select_color = $("#color_select").val();
		var red = $("#red").slider("value")
			,green = $("#green").slider("value")
			,blue = $("#blue").slider("value")
			,hex = hexFromRGB(red, green, blue);
		$(select_color).css("background-color", "#" + hex);
		$.cookie(select_color, hex, {expires: 7});
	}
	function seleciona_cores_site(value){
		$(function() {
			$("#red, #green, #blue").slider({
				orientation: 'horizontal',
				range: "min",
				max: 255,
				value: 127,
				slide: refreshSwatch,
				change: refreshSwatch
			});
			
			var_cookie = "#"+$.cookie(value);
			
			red = HexToR(var_cookie);
			green = HexToG(var_cookie);
			blue = HexToB(var_cookie);
	
			if(red && green && blue){
				$("#red").slider("value", red);
				$("#green").slider("value", green);
				$("#blue").slider("value", blue);
			}
		});
	}
	function carrega_cores_site(){
        $("#color_select option").each(function() {
            val = $(this).val();
			if(val){
            	$(val).css("background-color", "#" + $.cookie(val));
			}
        });
	}
	function apaga_cookies(){
		$("#color_select option").each(function() {
            val = $(this).val();
			if(val){
				$.cookie(val, null);
			}
        });
		carrega_cores_site();
	}
//HABBID SEARCH
function setInput(obj,t,c){
	if(obj.value == c){ obj.value = t; }
}
function habbidsearch_opcao(v){
	$("#search_value").val(v);
	if($("#search_value").val() == 1){
		$("#habbidsearch_input").val('Buscar mobi');
		setInput(this,'Buscar mobi', '');
	}else if($("#search_value").val() == 2){
		$("#habbidsearch_input").val('Buscar ouvinte');
		setInput(this,'Buscar ouvinte','');
	}else if($("#search_value").val() == 3){
		$("#habbidsearch_input").val('Buscar not\u00edcias');
		setInput(this,'Buscar notícias','');
	}
	$('#habbidsearch_filter').hide('explode',{},500);
	$('#habbidsearch_input').focus();
}
$(document).ready(function() {
		$('#habbidsearch_input').click(function() {
			if($("#search_value").val() == ""){
				$('#habbidsearch_filter').show('explode',{},500);
			}
     	});  
		$('#habbidsearch_input').dblclick(function() {
				$('#habbidsearch_filter').show('explode',{},500);								   
		});
		$('#habbidsearch_input').focus(function() {  
			 if(!$("#search_value").val()){
				 setInput(this,'','Buscar mobi');
			 }else if($("#search_value").val() == 2){
				 setInput(this,'','Buscar ouvinte');
			 }else if($("#search_value").val() == 3){
				 setInput(this,'','Buscar not\u00edcias');
			 }
     	});
		 $('#habbidsearch_input').blur(function() {  
			 if($("#search_value").val() == 1){
				 setInput(this,'Buscar mobi', '');
			 }else if($("#search_value").val() == 2){
				 setInput(this,'Buscar ouvinte','');
			 }else if($("#search_value").val() == 3){
				 setInput(this,'Buscar not\u00edcias','');
			 }
     	});  
		 $('#habbidsearch_input').keyup(function() {  
			 if($('#habbidsearch_input').val().length >= 3){
				$("#valoresarea").html("Carregando...");
				$("#valoresarea").load("modulos/search.php?opcao="+$("#search_value").val()+"&q="+$('#habbidsearch_input').val());
			 }
     	}); 
});

//HABBID SEARCH 2
function setInput(obj,t,c){
	if(obj.value == c){ obj.value = t; }
}
function habbidsearch2_opcao(v){
	$("#search_value").val(v);
	if($("#search_value").val() == 1){
		$("#habbidsearch2_input").val('Buscar mobi');
		setInput(this,'Buscar mobi', '');
	}else if($("#search_value").val() == 2){
		$("#habbidsearch2_input").val('Buscar ouvinte');
		setInput(this,'Buscar ouvinte','');
	}else if($("#search_value").val() == 3){
		$("#habbidsearch2_input").val('Buscar not\u00edcias');
		setInput(this,'Buscar notÃ­cias','');
	}
	$('#habbidsearch2_filter').hide('explode',{},500);
	$('#habbidsearch2_input').focus();
}
$(document).ready(function() {
		$('#habbidsearch2_input').click(function() {
			if($("#search_value").val() == ""){
				$('#habbidsearch2_filter').show('explode',{},500);
			}
     	});  
		$('#habbidsearch2_input').dblclick(function() {
				$('#habbidsearch2_filter').show('explode',{},500);								   
		});
		$('#habbidsearch2_input').focus(function() {  
			 if(!$("#search_value").val()){
				 setInput(this,'','Buscar mobi');
			 }else if($("#search_value").val() == 2){
				 setInput(this,'','Buscar ouvinte');
			 }else if($("#search_value").val() == 3){
				 setInput(this,'','Buscar not\u00edcias');
			 }
     	});
		 $('#habbidsearch2_input').blur(function() {  
			 if($("#search_value").val() == 1){
				 setInput(this,'Buscar mobi', '');
			 }else if($("#search_value").val() == 2){
				 setInput(this,'Buscar ouvinte','');
			 }else if($("#search_value").val() == 3){
				 setInput(this,'Buscar not\u00edcias','');
			 }
     	});  
		 $('#habbidsearch2_input').keyup(function() {  
			 if($('#habbidsearch2_input').val().length >= 3){
				$("#valoresarea").html("Carregando...");
				$("#valoresarea").load("modulos/valoresiframe.php?opcao="+$("#search_value").val()+"&q="+$('#habbidsearch2_input').val());
			 }
     	}); 
});