function is_empty(obj) {
    for(var prop in obj) {
        if(obj.hasOwnProperty(prop))
            return false;
    }

    return true;
}

Array.prototype.unique = function(){
    var vals = this;
    var uniques = [];
    for(var i=vals.length;i--;){
        var val = vals[i];  
        if($.inArray( val, uniques )===-1){
            uniques.unshift(val);
        }
    }
    return uniques;
}

function new_solution() {

	numbers = new Array();
	
	// generate random string of numbers	
	while (numbers.length < max_numbers) {
	
		// generate random int
		number = Math.floor(Math.random()*10);
		//console.log(number);
		
		if (!in_array(number, numbers)) {
			// add it to array (if unique)
			numbers.push(number);
		}
		
	}

	//$('#solution').html(numbers.toString());
	//console.log(numbers);
	
	return numbers;
}

function load_my_scores() {
	
	num_scores = 0;
	
	if (!is_empty(previous_scores)) {
	
		// remove all the list items
		$('#previous_scores li').remove();
		
		// populate previous_scores list with scores
		
		for (var id in previous_scores) {
		
			num_scores++;
			
			time_stamp = previous_scores[id].date;
			date = new Date(time_stamp);
			date_str = date.format('mmmm d, yyyy HH:MM');
			
			
			num_attempts = previous_scores[id].num_attempts;
			
			if (num_attempts == 1) {
				attempts_str = 'attempt';
			} else {
				attempts_str = 'attempts';
			}
		
			$('#previous_scores').prepend($(
				'<li id="' + id + '" class="touch"><span class="time_stamp">' + date_str + '</span><small class="counter">' + num_attempts + ' ' + attempts_str + '</small></li>'
			));
		}
	}
	
	// update counter on my_scores with number of recorded scores
	$('#num_previous_scores').html(num_scores);
	
}

function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 1004.1212
    // discuss at: http://phpjs.org/functions/in_array    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict; 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {                return true;
            }
        }
    }
     return false;
}

