jQuery(function(){
jQuery('ul.superfish').superfish();
});

jQuery(function(){

    // Autoselect form input fields on focus
    $('#contact-form input').focus(
        function( ) {
	    if(this.value == this.defaultValue) {
	        this.select();
	    }
        }
    );

    // Submit form on button click
    $('#contact-form .button').click(
        function( ) {
            js_validate_form();
        }
    );

    // Hide contact-header on close click
    $('#contact-close').click(
        function( ) {
	    $('#contact-header').slideUp();
        }
    );

    // Submit form trigger
    $('.contact-form-trigger').click(
        function( ) {
	    contact_show();
        }
    );

});

function contact_hide() {
    $('#contact-header').slideUp();
}

function contact_show() {
    $('#contact-header').slideDown();
}

function js_validate_form() {
var n=$('#contact-name');
var c=$('#contact-company');
var p=$('#contact-phone');
var e=$('#contact-liame');
var i=$('#contact-inquiry');

if(n.val()==''||n.val()=='Your Name'){ $('#contact-status').html('name required!'); return false;}
if (c.val()==''||c.val()=='Company'){ $('#contact-status').html('company required');return false;}
if (e.val()==''||e.val()=='Email'){ $('#contact-status').html('email required');return false;}
if (p.val()==''||p.val()=='Phone'){ $('#contact-status').html('phone required');return false;}
//if (i.val()==''||i.val()=='Interested in...'){ $('#contact-status').html('what interest?');return false;}

$('#contact-action').val('__process_form');

js_do_submission();
}

function js_do_submission() {
	//$('#contact-status').html('sending...');
	$.post( 
		$('#contact-form').attr( 'action' ) , 
		'__action=' + $('#contact-action').val()
		+ '&__n=' + $('#contact-name').val()
		+ '&__c=' + $('#contact-company').val()
		+ '&__e=' + $('#contact-email').val()
		+ '&__l=' + $('#contact-liame').val()
                + '&__p=' + $('#contact-phone').val()
                + '&__i=' + $('#contact-inquiry').val()
	);
	$('#contact-form').slideUp();
	$('#contact-result').html( '<h3>Your request has been sent</h3><h3>We look forward to working with you.</h3><p>Mon-Fri 9AM-4PM we usually respond within the hour, all others times within 24 hours.</p><p>If you need immediate assistance please pickup the phone and call us. (325) 939-0288</p>' );
}

