function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}
function evalPrice() {
	var add;
	var addpc;
	var pages = $('#Pages').val();
	if (isNaN(pages) || pages == '0' || pages <= '0') {
		$('#Pages').val('1');
	}
	pages=parseInt(pages)-1;
  var	plus=$("#wp:checked").length;
	var	pc=$("#pc:checked").length;
	initial= 77;
	if (plus == '1') {add=115;}	else {add=0;}
	if (pc == '1') {addpc=39;} else {addpc=0;}
	
	total = (pages * 38) + initial + add + addpc;
	
	$('#price').html('$'+total);
	$('#inputprice').val(total);
}

$(function() {
  $('.error').hide();
	$('#loader').hide();
	
	$("input#File").filestyle({ 
			image: "img/browse.gif",
			imageheight : 24,
			imagewidth : 82,
			width : 118
	});

	
  $('input.text').css({backgroundColor:"#fff"});
	$('input.file').css({backgroundColor:"#fff"});
	$('textarea').css({backgroundColor:"#fff"});
  $('input.text').focus(function(){
    $(this).css({backgroundColor:"#eee"});
  });
	$('input.file').focus(function(){
    $(this).css({backgroundColor:"#eee"});
  });
	$('textarea').focus(function(){
    $(this).css({backgroundColor:"#eee"});
  });
  $('input.text').blur(function(){
    $(this).css({backgroundColor:"#fff"});
  });
	$('input.file').blur(function(){
    $(this).css({backgroundColor:"#fff"});
  });
	$('textarea').blur(function(){
    $(this).css({backgroundColor:"#fff"});
  });

  $("button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#Name").val();
		if (name == "") {
      $("#error").html('Please enter your name.');
      $("input#Name").focus();
      return false;
    }
		var email = $("input#Email").val();
		if (!isValidEmailAddress(email)) {
      $("#error").html('Please enter a corect email address.');
      $("input#Email").focus();
      return false;
    }
		var project = $("input#Project").val();
		if (project == "") {
			$("#error").html('Please enter the project name.');
      $("#error").show();
      $("input#Project").focus();
      return false;
    }
		var filepath = $("input#File").val();
		var filelink = $("input#Link").val();
		if (filepath == "" && filelink == "http://") {
			$("#error").html('Please upload your design sources or specify a link to your file(s).');
      $("#error").show();
      $("input#Link").focus();	
      return false;
    }
		
		var dataString = 'Name='+ name + '&Email=' + email + '&Project=' + project + '$Pages=' + $("input#Pages").val();
		//alert (dataString);return false;
		$("#button").hide();
		$("#loader").show();
		$("#orderForm").submit();
		
		/*$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#orderForm').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
		*/
    return false;
	});
});
runOnLoad(function(){
  $("input#Name").select().focus();
});
