$(function() {
  $('.error').hide();
  //denne fliken endrer css style på focus og blur
  //$('input.text-input').css({backgroundColor:"#FFFFFF"});
  //$('input.text-input').focus(function(){
    //$(this).css({backgroundColor:"#FFDDAA"});
  //});
  //$('input.text-input').blur(function(){
    //$(this).css({backgroundColor:"#FFFFFF"});
  //});

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();


    /*if ($("input[name='how_many'][checked=false]")) {
       alert('Hvor mange Altibox-kunder har Notodden Energi?');
        return false;
    }

    if ($("input[name='how_much'][checked=false]")) {
       alert('Hvor mye sparer du hvert år på å være e-faktura kunde hos Notodden Energi?');
        return false;
    }
    
    if ($("input[name='how_year'][checked=false]")) {
       alert('Du må svare på alle spørsmål');
        return false;
    } */   


		
	  var fname = $("input#fname").val();
		if (fname == "") {
      $("div#fname_error").show();
      $("input#fname").focus();
      return false;
    }
    
	  var ename = $("input#ename").val();
		if (ename == "") {
      $("div#ename_error").show();
      $("input#ename").focus();
      return false;
    }

        
		var email = $("input#email").val();
		if (email == "") {
      $("div#email_error").show();
      $("input#email").focus();
      return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("div#phone_error").show();
      $("input#phone").focus();
      return false;
    } 

    var options = { 
				success: function() {
					$('#contact_form').html("<div id='message'></div>");
					$('#message').html("<h2>Du er nå med i trekningen om en iPod Touch 8Gb</h2>")
					.append("<p></p>")
					.hide()
					.fadeIn(1500, function() {
						$('#message').append("<img id='checkmark' src='http://static.websys.no/files/sites/www.notoddenenergi.no/design/images/check.png' />");
					});
				}        
    }; 
 
    // bind to the form's submit event 
    $('#myform').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    });
	});
});

