$(function() {
  $(".first").css({color:"#226699"});
  $(".eml").css({color:"#226699"});
  $('input').css({backgroundColor:"#FFFFFF"});
  $('input').focus(function(){
    $(this).css({backgroundColor:"#FCFCF2"});
  });
  $('input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $(".first").css({color:"#226699"});
    $(".eml").css({color:"#226699"});
    
	var fname = $("input.fields_fname").val();	  
	var email = $("input.fields_email").val();
	//alert(email);
	if (email == "" || email == undefined) {
      $(".eml").css({color:"red"});
      $("input.fields_email").focus();
      return false;
    }	
    //alert(fname);
    if (fname == "" || fname == undefined) {
      $(".first").css({color:"red"});
      $("input.fields_fname").focus();
      return false;
    }			
		
	//var dataString = 'fields_fname='+ fname + '&fields_email=' + email + '&listid=108293&specialid:108293=C7HT&clientid=501279&formid=7003&reallistid=1&doubleopt=0';
		
	/*
	$.ajax({
      type: "POST",
      url: "https://app.icontact.com/icp/signup.php",
      data: dataString,
      success: successfulPOST,
      error: failedPOST      
     });
     */    
     
    return true;
	});
});

function successfulPOST() {    
    
    $('.SignUp').html("<div class='message'></div>");
    $('.message').html("<h2>Contact Form Submitted Successfully!</h2>")
    .append("<p>I will be in touch soon.</p>")
    .hide()
    .fadeIn(1500, function() {
      $('.message').append("<img height='50' width='50' src='images/checkmark.jpg' />");
      
    });
  }

function failedPOST() {    
    $('.SignUp').html("<div class='message'></div>");
    $('.message').html("<h2>Sorry, but there seems to be a problem</h2>")
    .append("<p>Please try again.</p>");        
      
  }

function clear_form_elements(ele) {
    $(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });
}

$("#newsletterPopup").click(function() {
    $("#homeForm").html('');
});

//runOnLoad(clear_form_elements(this.form));

runOnLoad(function(){
  $("input.fields_email").select().focus();
});
