/**
 * Mutes firebug console code and errors on browsers where firebug is not installed
 */
if (!window.console || !console.firebug) {
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", 
	"groupCollapsed", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
    window.console = {};
    for (var i = 0; i < names.length; ++i) {
        window.console[names[i]] = function() {};
	}
}

///**
// * Mutes google analytics event tracking. GA won't be present on the admin side, so pageTracker._trackEvent will throw errors.
// */
//if (!window.pageTracker) {
//	var trackers = ["_trackEvent"];
//	window.pageTracker = {};
//	for (var pti = 0; pti < trackers.length; ++pti) {
//		window.pageTracker[trackers[pti]] = function() {};
//	}
//}

// CONTACT FORM VALIDATION
function submitContact() {

	// Cache some shyte
	var contactErrorList = $('.contactValidationMessages');

	// Valid by default
	var validContact = true;
	$('#contactForm .invalid').removeClass('invalid');
	contactErrorList.hide().children().remove();

	// First Name Blank?
	if ($('.firstName').val() === '') {
		contactErrorList.append('<li>Doh! We need your <strong>first name</strong> please.</li>');
		//pageTracker._trackEvent('Jan2010Funnel', 'Error', 'CCFormStateInvalid');
		$('.firstName').addClass('invalid');
		validContact = false;
		LogValidationError('[contact] First name was blank');
	}
	
	// Last Name Blank?
	if ($('.lastName').val() === '') {
		contactErrorList.append('<li>Please enter your <strong>last name</strong>.</li>');
		//pageTracker._trackEvent('Jan2010Funnel', 'Error', 'CCFormStateInvalid');
		$('.lastName').addClass('invalid');
		validContact = false;
		LogValidationError('[contact] Last name was blank');
	}
	
	// Email Blank?
	if ($('.contactEmail').val() === '') {
		contactErrorList.append('<li>Kindly enter your <strong>email</strong> address.</li>');
		//pageTracker._trackEvent('Jan2010Funnel', 'Error', 'CCFormStateInvalid');
		$('.contactEmail').addClass('invalid');
		validContact = false;
		LogValidationError('[contact] Email address was blank');
	}
	
	// Email Format?
	var regexEmail = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if ( !regexEmail.test($('.contactEmail').val())) {
		contactErrorList.append('<li>Looks like there\'s something wrong with your <strong>email address</strong>. hmm.</li>');
		//pageTracker._trackEvent('Jan2010Funnel', 'Error', 'CCFormStateInvalid');
		$('.contactEmail').addClass('invalid');
		validContact = false;
		LogValidationError('[contact] Email address wasnt valid according to regex (' + $('.contactEmail').val() + ')');
	}
	
	// Phone Number Blank?
	if ($('.contactTopic').val() === '') {
		contactErrorList.append('<li>Please choose a <strong>topic</strong> for your message. This helps us know how to route your message to the correct person here at HireAHelper.com Feel to free to choose \"Other\" if you need to.</li>');
		//pageTracker._trackEvent('Jan2010Funnel', 'Error', 'CCFormStateInvalid');
		$('.contactTopic').addClass('invalid');
		validContact = false;
		LogValidationError('[contact] Topic was blank');
	}
	// Topic Blank?
	if ($('.contactPhoneNumber').val() === '') {
		contactErrorList.append('<li>Please enter your <strong>phone number</strong> so we can contact you if needed.</li>');
		//pageTracker._trackEvent('Jan2010Funnel', 'Error', 'CCFormStateInvalid');
		$('.contactPhoneNumber').addClass('invalid');
		validContact = false;
		LogValidationError('[contact] Phone number was blank');
	}
	
	// Subject Blank?
	if ($('.contactSubject').val() === '') {
		contactErrorList.append('<li>Doh! You forgot to enter a <strong>subject</strong> for your message.</li>');
		//pageTracker._trackEvent('Jan2010Funnel', 'Error', 'CCFormStateInvalid');
		$('.contactSubject').addClass('invalid');
		validContact = false;
		LogValidationError('[contact] Subject was blank');
	}
	
	// Message Blank?
	if ($('.contactMessage').val() === '') {
		contactErrorList.append('<li>Hang on! What\'s your <strong>message</strong>?</li>');
		//pageTracker._trackEvent('Jan2010Funnel', 'Error', 'CCFormStateInvalid');
		$('.contactMessage').addClass('invalid');
		validContact = false;
		LogValidationError('[contact] Message was blank');
	}

	if ( validContact === false ) {
		contactErrorList.show();
	} else {
	    //__doPostBack('ContactForm', 'SubmitContactForm');
	    $('form:first').submit();
	}
	return false;
}

/*	DOM-READY FUNCTION
-------------------------------------------------------------- */
$(function() {
	// Reset the sp@m preventi0n value
	$('.sspm10sec').val('');
	// Prevent sp@m with a ten second timer on the form
	sspm10sec = setTimeout(sspm10secGo, 10000);
	// Afvter the ten seconds, set the value
	function sspm10secGo() {
		$('.sspm10sec').val('10sec');
		// And reset the timer
		clearTimeout(sspm10sec);
	}
	
	// Contact form submit
	$('.contactFormSubmit').click( function() {
		submitContact();
	});
	// Remove invalid class when focusing on inputs
	$('#contactForm input, #contactForm textarea').focus( function() {
		$(this).removeClass('invalid');
	});

});

// 
// 
// /*	WINDOW LOADED FUNCTION
// -------------------------------------------------------------- */
// $(window).load(function () {
// 	
// 
// 	
// 
// 
// });






















