function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}

function new_captcha(){
	if(document.getElementById){
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("captchaimg").src;
		// add ?(random) to prevent browser/isp caching
		document.getElementById("captchaimg").src = thesrc+"&"+Math.round(Math.random()*100000);
	}//fin if
}

function check_form(cual){
	if(document.getElementById('search').value.length < 3){
		alert("La longitud mínima para buscar es de 3 caracteres");
		return false;
	}else{
		action = document.frm_busqueda.action + 'b/' + document.frm_busqueda.search.value;
		document.frm_busqueda.action = action;
		document.frm_busqueda.search.value = '';
		return true;
	}
}

function liststates(state){
	if(document.getElementById("record[id_country]")){
		if(!state){
			state = '';
		}
		id_country=document.getElementById("record[id_country]").value;
			$.post("/reg/?id_country="+id_country+"&state="+state, function(data) {
				if( data != '' ) {
					document.getElementById("div_state").innerHTML = data;
				}
			});
	}
}

function add_favourites(auth, name, path, id){
	if (auth==0){
		alert("No estás autentificado para realizar esta acción");
	}else{
		if (confirm("¿Quieres agregar "+name+" a tus juegos favoritos?")){
			document.location.href = path + 'af/' + id + '/';
		}
		
	}
}

function delete_favourites(auth, name, path, id){
	if (auth==0){
		alert("No estás autentificado para realizar esta acción");
	}else{
		if (confirm("¿Quieres eliminar "+name+" de tus juegos favoritos?")){
			document.location.href = path + 'df/' + id + '/';
		}
		
	}
}