// JavaScript Document
function winOpen(url,nome,w,h){
	var width		= screen.width;
	var height		= screen.height;
	var left		= (width-w)/2;
	var top			= (height-h)/2;

	var config = 'scrollbars=yes,status=yes,location=no,resizable=yes,left='+left+',top='+top+',width='+w+',height='+h;
	window.open(url,nome,config);
}
function getObj(name){
	if (document.getElementById){
		var obj	= document.getElementById(name);
	}else if (document.all){
		var obj	= document.all[name];
	}else if (document.layers){
		var obj	= document.layers[name];
	}
	return obj;
}
function setStar(STAR,ACAO){
	var imgOn	= "/imagens/bullets/star_yellow.png";
	var imgOff	= "/imagens/bullets/star_grey.png";
	if(ACAO=='on'){
		for(i=1;i<=5;i++){
			var obj = new getObj('STAR'+i);
			if(i<=STAR){
				obj.src = imgOn;
			}else{
				obj.src = imgOff;	
			}
		}
	}else{
		for(i=1;i<=5;i++){
			var obj = new getObj('STAR'+i);
			if(i<=STAR){
				obj.src = imgOn;
			}else{
				obj.src = imgOff;	
			}
		}
	}
	var legend = new getObj('starLegend');
	if(STAR==1){
		legend.innerHTML = "pessímo";
	}
	if(STAR==2){
		legend.innerHTML = "ruim";
	}
	if(STAR==3){
		legend.innerHTML = "bom";
	}
	if(STAR==4){
		legend.innerHTML = "ótimo";
	}
	if(STAR==5){
		legend.innerHTML = "excelente";
	}
}
var ID_		= "";
var VOTO_	= "";
function setVoto(ID,VOTO,SAVE){
	if(SAVE=='exc'){
		if(confirm('Tem certeza que deseja excluir esse comentário?')){
			lyM("alert");
			ajaxHTML('divExibe','scripts/media.php&exc=true&'+ID,'exibe');	
		}
		return true;
	}
	if(SAVE=='false'){
		ID_ = ID;
		VOTO_ = VOTO;
		return true;
	}
	if(ID_!=''){
		var obj = new getObj('B_COM');
		var	obs	= obj.value;
		lyM("alert");
		ajaxHTML('divExibe','scripts/media.php&exc=false&'+ID_+'&voto='+VOTO_+'&obs='+obs,'exibe');
		obj.value = '';
	}
}
function views(table,chave,id){
	ajaxHTML('resp','scripts/views.php&table='+table+'&chave='+chave+'&id='+id,'');	
}
function real_dec(valor){
	return valor.replace(',','.');
}
function arredonda( valor , casas ){
   return Math.round( valor * Math.pow( 10 , casas ) ) / Math.pow( 10 , casas );
}
function setAval(ID,SAVE){
	var grafico	= new getObj('grafico');
	var grafico_= real_dec(grafico.value)*1
		if((grafico_<1) || (grafico_>5)){
			alert('Gráfico -> A nota deve ser entre 1 e 5');
			grafico.focus();
			return false;
		}
	var som		= new getObj('som');
	var som_	= real_dec(som.value)*1
		if((som_<1) || (som_>5)){
			alert('Som -> A nota deve ser entre 1 e 5');
			som.focus();
			return false;
		}
	var jogabil = new getObj('jogabilidade');
	var jogabil_= real_dec(som.value)*1	
		if((jogabil_<1) || (jogabil_>5)){
			alert('Jogabilidade -> A nota deve ser entre 1 e 5');
			//jogabili.focus();
			return false;
		}
	var obj 	= new getObj('B_COM');
	var	obs		= obj.value;
	var media	= arredonda((grafico_+som_+jogabil_)/3,2);
	if(SAVE=='false'){
		lyE('alert');
		lyM('comentario');
		var obj		= new getObj('divNota');
			obj.innerHTML = 'Gráficos: '+ grafico.value + ' Som: '+ som.value + ' Jogabilidade: '+ jogabil.value + ' Média: '+ media ;		
	}else{
		lyE('comentario');
		lyM('alert');
		ajaxHTML('retorno','scripts/avaliacao.php&'+ID+'&grafico='+grafico_+'&som='+som_+'&jogabilidade='+jogabil_+'&media='+media+'&obs='+obs,'exibe');
		//if(obs!=''){
			//ajaxHTML('comment','scripts/comentarios.php&'+ID+'&votou=true','exibe');
		//}
		setTimeout('lyE("alert")',5000);		
	}
}
function lyM(layer){
	var lyObj	= new getObj(layer);	
		lyObj.style.visibility = "visible"
}
function lyE(layer){
	var lyObj	= new getObj(layer);
		lyObj.style.visibility = "hidden"
}
function pesquisar(){
	var obj = new getObj('q');
	var q	= escape(obj.value);
	window.top.location.href = "/pesquisar/"+q;
}
function nota(e){
	var strCheck	= "12345";
//	var whichCode	= (window.Event) ? e.which : e.keyCode;
	if (!e) var e = window.event;   
	if (e.keyCode) whichCode = e.keyCode;   
	else if (e.which) whichCode = e.which;	
	key = String.fromCharCode(whichCode);
	if ((whichCode <= 13)) return true;
	if (strCheck.indexOf(key) == -1) return false;
}
function formatar(src,mask){
	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);
	}
}
function IsDate(myDate) {
	var myDate	= myDate.split("/");
	var day		= myDate[0];
	var month	= myDate[1];
	var year	= myDate[2]
	var date	= new Date();
	var blnRet	= false;
	var blnDay;
	var blnMonth;
	var blnYear;

	date.setFullYear(year, month -1, day);
	blnDay   = (date.getDate()      == day);
	blnMonth = (date.getMonth()     == month -1);
	blnYear  = (date.getFullYear()  == year);

	if (blnDay && blnMonth && blnYear)
	blnRet = true;

	return blnRet;
}
function enter(funcao,e){
	if (!e) var e = window.event;   
	if (e.keyCode) whichCode = e.keyCode;   
	else if (e.which) whichCode = e.which;	
	key = String.fromCharCode(whichCode);
	if ((whichCode == 13))

	if(whichCode == 13){
		eval(funcao)
	}
}
var reEmail1 = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail2 = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

var reEmail3 = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail = reEmail3;

function doEmail(pStr, pFmt){
	eval("reEmail = reEmail" + pFmt);
	if (reEmail.test(pStr)) {
		return true;
	} else if (pStr != null && pStr != "") {
		return false;
	}
}
function getFrm(formulario){
		var obj = eval("document."+formulario);
	return obj;
}
function loadJogos(q,local,div){
	if((q.length>3 && q.length<6)||(q.length>6 && q.length<9)||(q.length>9 && q.length<11)||(q.length>11)){
		lyM(div)
		var script = 'jogos';
		if(div=='loadPla'){
			script = 'plataforma';
		}
		if(div=='loadCid'){
			script = 'cidades';
		}		
		ajaxHTML(div,'scripts/'+script+'.php&q='+q+'&local='+local,'exibe');
	}
}
function participe(tipo,pla,jog){
	ajaxHTML('H_desc','scripts/participe.php&plataforma='+pla+'&jogo='+jog+'&tipo='+tipo,'exibe');
}
