/* Author: FBolaji
*/

  	$(function(){
		$('.remove').remove();
		
		if ($.browser.msie && $.browser.version == 6) {
			var thisAlert = $('#alertUpgrade');
			thisAlert.css({'display':'block'});
			thisAlert.find('.btn').click(function(){
				$('#alertUpgrade').css({'display':'none'});
			});
		}
		
	$("#body-background").ezBgResize(); // resize background iamges
	
	// top navigation
	  var currentPage = page;
	 // console.log(currentPage)
		var link = $('#topNav li a:contains("'+currentPage+'")');
		link.each(function(){
			 if($(this).children().length < 1){
				$(this).addClass("current");
			 }
		});
		
// form validation
	    $('.error').hide();
	    $(".btn").click(function() {
	      // validate and process form here

	      $('.error').hide();
	  	  var forename = $("input#forename").val();
	  		if (forename == "") {
	        $("label#forename_error").show();
	        $("input#forename").focus();
	        return false;
	      }
		  var surname = $("input#surname").val();
	  		if (surname == "") {
	        $("label#surname_error").show();
	        $("input#surname").focus();
	        return false;
	      }		      

	  	var phone = $("input#phone").val();
	  		if (phone == "") {
	        $("label#phone_error").show();
	        $("input#phone").focus();
	        return false;
	      }
	  	var email = $("input#email").val();
	  		if (email == "") {
	        $("label#email_error").show();
	        $("input#email").focus();
	        return false;
	      }   
		var txtArea = $("textarea#message");
	  	var message = txtArea.val();
	  		if (message == "") {
				$("label#message_error").show().css({'margin-top':'31px','marginLeft':'-3px'});
				txtArea.focus();
	        return false;
	      }         
	

	    var dataString = 'forename='+ forename + '&surname=' + surname + '&phone=' + phone + '&email=' + email + '&message='+ message;
	    //alert (dataString);return false;
	    $.ajax({
	      type: "POST",
	      url: "assets/mail/process.php",
	      data: dataString,
	      success: function() {
	        $('.copy').html("<div id='message'></div>");
	        $('#message').html("<h1>Thank you for your enquiry.</h1>")
	        .append("<p>Someone will contact you soon.</p>")
	        .hide()
	        .fadeIn(1500, function() {
	          $('#message');
			  //.append("<img id='checkmark' src='images/check.png' />");
	        });
	      }
	    });
	    return false;
	    });
	 

	  
});























