// JavaScript Document

function updateFilterOptions()
{
	var authentication = randomString();
	var price = $("#SA_price").val();
	var category = $("#SA_category").val();
	var character = $("#SA_character").val();
	var brand = $("#SA_brand").val();

	$("#SA_price").load('lib/php/scripts/loadFilters.php?price='+price+'&category='+category+'&character='+character+'&brand='+brand+'&type=1&auth='+authentication);
	$("#SA_category").load('lib/php/scripts/loadFilters.php?price='+price+'&category='+category+'&character='+character+'&brand='+brand+'&type=2&auth='+authentication);
	$("#SA_character").load('lib/php/scripts/loadFilters.php?price='+price+'&category='+category+'&character='+character+'&brand='+brand+'&type=3&auth='+authentication);
	$("#SA_brand").load('lib/php/scripts/loadFilters.php?price='+price+'&category='+category+'&character='+character+'&brand='+brand+'&type=4&auth='+authentication);
}

function randomString(length) {
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
    
    if (! length) {
        length = Math.floor(Math.random() * chars.length);
    }
    
    var str = '';
    for (var i = 0; i < length; i++) {
        str += chars[Math.floor(Math.random() * chars.length)];
    }
    return str;
}

function sendAlert(){
	var email = $("#emailAddress").val();
	var authentication = randomString();
	if(email != ''){
		$.post('lib/php/scripts/toyalert.php',{email:email, auth:authentication});
		$("#formContent").fadeOut(function(){
			$("#thankyou").fadeIn();										  
		});
	}
}