function openPopup(url, name, width, height){
	var params = "width=" + width;
	params += ",height=" + height;
	params += ",status=0";
	params += ",toolbar=0";
	params += ",location=0";
	params += ",menubar=0";
	params += ",directories=0";
	params += ",resizable=1";
	params += ",scrollbars=1";

	window.open(url, name, params);
}

function openPopupResizable(url, name, width, height){
	var params = "width=" + width;
	params += ",height=" + height;
	params += ",status=0";
	params += ",toolbar=0";
	params += ",location=0";
	params += ",menubar=0";
	params += ",directories=0";
	params += ",resizable=1";
	params += ",scrollbars=1";

	window.open(url, name, params);
}

function hideErrorMessage(e){
	if(e.which != 0){		
		$("#fielderror_"+$(this).attr("name").replace(/\./, "_")).hide();
	}
}

function scrollRanking(i){
    $("#gameName").html($("#gameLink"+i).html());
    $("#gameLink"+i).click();
}

function scrollAutomatic() {
   	if(index == max){
       	scrollPrevious();
                    
    }else if (index == 2 && control == 1){
    	scrollNext();
    	
    }else if (index == 2 && control == 2){
        scrollPrevious();
        
    }else{
    	scrollNext();
    }
   
}

function scrollPrevious(){
	index--;
    if(index == 1){
    	$("#previousLink").css('visibility','hidden');
    	$("#gameNext").html("Tranca");
    }
    $("#nextLink").css('visibility','visible');
    $("#gamePrevious").html("Poker");
    control = 2;
    scrollRanking(index);
    
    clearInterval(interval);
    interval = setInterval(function(){ scrollAutomatic(); }, 5000);
	
}


function scrollNext(){
	index++;
    if(index == max){
    	$("#nextLink").css('visibility','hidden');
    	$("#gamePrevious").html("Tranca");
    }
    if(index == 2){
    	$("#gamePrevious").html("Poker");
    	control = 1;
    }
    $("#previousLink").css('visibility','visible');
    $("#gameNext").html("Buraco");
    scrollRanking(index);
    
    clearInterval(interval);
    interval = setInterval(function(){ scrollAutomatic(); }, 5000);
}

function lowerCase(obj){
	  obj.value=obj.value.toLowerCase();  
}
  
function isEnterKey(){
    if(event){
        key = event.keyCode;
   } else {
        key = e.which;
   }

   if(key == 13){  	 
        return true;
   } else {
	    return false;
   }
}
