if (typeof BASE_URL == 'undefined')
{
	//BASE_URL = '/americancreditgroup';
	BASE_URL = '';
}

var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

// JavaScript Document
$(document).ready(function() {																							
																											
	$("#free-consultation-tab a").click(function(event){
		$(".selected").removeClass("selected");
		$(".open").removeClass("open");			
		$("#free-consultation-tab a").addClass("selected");
		$("#free-consultation").addClass("open");			
	});  
		
	$("#customer-support-tab a").click(function(event){
		$(".selected").removeClass("selected");
		$(".open").removeClass("open");			
		$("#customer-support-tab a").addClass("selected");
		$("#customer-support").addClass("open");			
	});  
	
	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});

	// homepage free consultation
	$('#freeConsultation').submit(function(){
		
		var errors = [];
		
	
		$('#freeConsultation .required').each(function() {
		
			if ($.trim($(this).val()) == '')	
			{
				errors.push($(this).attr('title') + ' is required.');
			}
			
			
			if ( $(this).attr('name') == 'email' ) 
			{
				if ( !filter.test( $(this).val() ) )
				{
					errors.push('Valid email address is required.');
				}
			}
		});
	
	
		if ($('select[name="reasonForCall"] option:selected').length == 0)
		{
			errors.push('Reason for call is required.');
		}

	
		if (errors.length == 0)
		{
			$.post(BASE_URL + '/ajax/freeConsultation.php', $(this).serialize(), function(data) {
				if (data == 'success')
				{
					//alert('Form submitted.');
					window.location = BASE_URL + '/thanks.html';
					$('input').val('');
					$('select').val('');
				}
				else 
				{
					alert(data);
				}
			});
		}
		else
		{
			alert(errors.join('\n'));
		}
	
	
		return false;
	});
	
	
	//signUpForm
	$('#signUpForm').submit(function(){
		var errors = [];
		
		
		$('#signUpForm .required').each(function() {
		
			if ($.trim($(this).val()) == '')	
			{
				errors.push($(this).attr('title') + ' is required.');
			}
			
			
			if ( $(this).attr('name') == 'email' ) 
			{
				if ( !filter.test( $(this).val() ) )
				{
					errors.push('Valid email address is required.');
				}
			}
		});
	
	
		if ($('select[name="cctype"] option:selected').length == 0)
		{
			errors.push('Credit Card Type is required.');
		}

	
		if (errors.length == 0)
		{
			$.post(BASE_URL + '/ajax/signupForm.php', $(this).serialize(), function(data) {
				if (data == 'success')
				{
					//alert('Form submitted.');
					window.location = BASE_URL + '/thanks.html';
					$('input').val('');
					$('select').val('');
				}
				else 
				{
					alert(data);
				}
			});
		}
		else
		{
			alert(errors.join('\n'));
		}
	
	
		return false;		
		 
	});
						
}); 