/*** wizard_fan.js ****************************************************************
 *                                                                             *
 *	website: lp33.tv                                                           *
 *	author: matt antone                                                        *
 *	email: mattantone@lp33.tv                                                  *
 *  jQuery file and version: jquery-1.2.6.min.js                               *
 *  jQuery UI file and version: jquery-ui-personalized-1.6rc2.packed.js        *
 *                                                                             *
 *	This file should only be used to execute javascript functions for lp33.tv  *
 *	This file gets executed as if it were the "onload" in a body tag           *
 *                                                                             *
 *******************************************************************************/
 
$(document).ready(function(){
	//Setup the folder field automaticly
	$('input[name=lname], input[name=fname]').blur(function(){
		// if there is a first name and last name
		if($('input[name=fname]').val() && $('input[name=lname]').val()){
			$('input[name=folder]').val($('input[name=fname]').val().toLowerCase()+$('input[name=lname]').val().toLowerCase())
		}
	});
	
	$('input[name=folder]').blur(function(){
		var curInput = $(this);
		if($(curInput).val().length > 0){
			$.ajax({
				url: '/index.php?handler=wizard_fan&action=checkDirectory&directory='+$(this).val(),
				dataType: 'html',
				success: function(data){
					if(parseInt($('#status',data).text())){
						$('.response').remove();
						$(curInput).removeClass('invalid').after('<span class="response sucess">This URL can be yours.</span>');
					}else{
						$('.response').remove();
						$(curInput).addClass('invalid').after('<span class="response failure">This URL is unavailable. "'+$('#alternate',data).text()+'" is available.</span>');				
					}
				}
			});
		}
		return false;
	});
	
	//$('input[name="lname"]').trigger('blur');
	$('button.checkurl').click(function(){
		$('input[name=folder]').trigger('blur');
		return false;
	});
	
});
