$(document).ready(function() {
     
    //if submit button is clicked
    $('#submit').click(function () {        
         
        //Get the data from all the fields
        var name = $('input[name=name]');
        var email = $('input[name=email]');
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				

				if(email.val() == '') {
    				alert("Please enter an email address.");
    				return false;
        }
			
				
				if(!emailReg.test(email.val() )) {
    				alert("Please enter a valid email address.");
    				return false;
        }

        //organize the data properly
        var data = 'name=' + name.val() + '&email=' + email.val();
                  
        //start the ajax
        $.ajax({
            //this is the php file that processes the data and send mail
            url: "/feedbacks", 
             
            //GET method is used
            type: "GET",
 
            //pass the data         
            data: data,     
             
            //Do not cache the page
            cache: false,
             
            //success
            success: function (html) {              
                //if process.php returned 1/true (send mail success)
                if (html==1) {                  
                    //hide the form
                    $('#forms').fadeOut('slow');                 
                     
                    //show the success message
                    $('#done').fadeIn('slow');
                     
                //if process.php returned 0/false (send mail failed)
                } else alert('Sorry, unexpected error. Please try again later.');               
            }       
        });
         
        //cancel the submit button default behaviours
        return false;
    }); 
		
    //if signup button is clicked
    $('#signup').click(function () {        
         
        //Get the data from all the fields
        var password = $('input[name=password]');
        var email = $('input[name=email]');
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				
				if(email.val() == '') {
    				alert("Please enter an email address.");
    				return false;
        }
				
				if(!emailReg.test(email.val() )) {
    				alert("Please enter a valid email address.");
    				return false;
        }
				if(password.val() == '') {
    				alert("Please enter password.");
    				return false;
        }

    });		
		
}); 
	 
	 
function generalRefresh(url,div){
    $('#'+div).html("<center><img src='/img/loading.gif' /></center>");
		
		//start the ajax
		$.ajax({
				//this is the php file that processes the data and send mail
				url: url, 
				 
				//GET method is used
				type: "GET",

				//pass the data         
				data: null,     
				 
				//Do not cache the page
				cache: false,
				 
				//success
				success: function (html) {              
						//if process.php returned 1/true (send mail success)
						if (html) {                  
								//$('#'+div).fadeOut('slow');
								$('#'+div).html(html);   
								//$('#'+div).fadeIn('slow'); 
						//if process.php returned 0/false (send mail failed)
						} //else alert('Sorry, unexpected error. Please try again later.');               
				}       
		});		
		
}	 
	 
$(document).ready(function(){
	setTimeout(function(){
	$("div.flashdiv").fadeOut("slow", function () {
	$("div.flashdiv").remove();
	});
	}, 2000);
});



$(document).ready(function(){
	$("input, textarea").addClass("idle");
			$("input, textarea").focus(function(){
					$(this).addClass("activeField").removeClass("idle");
	}).blur(function(){
					$(this).removeClass("activeField").addClass("idle");
	});
});	 
	 
	 
$(document).ready(function() {
 $('.topHeader').click(function(){
	 $('.div_top_section').show('slow');
	 $('.topSection').css("min-height","160px");
 });
 
 $('.mainHeader').click(function(){
	 $('.div_main_section').show('slow');
	 $('.mainSection').css("min-height","460px");
 });	 
 
 $('#showh1').click(function(){
	 $('div.showhide,h1').show();
 });
 $('#toggleh1').click(function(){
	 $('div.showhide,h1').toggle();
 });
});



function hideTopHeader(){
	$('.div_top_section').hide();
	$('.topSection').css("min-height","40px");
} 

function hideMainHeader(){
	$('.div_main_section').hide();
	$('.mainSection').css("min-height","40px");
} 	 
 

