﻿/* Global Functions */

$(function() {
   
/*////////////////////////////////////*/
/* ---- =BANNER CYCLE --*/

   $('.banner') 
	.after('<div class="bannerNav">') 
	.cycle({ 
    fx:     'fade', 
    speed:  1000, 
    timeout: 5000, 
    pager:  '.bannerNav' 
});
	
	/*////////////////////////////////////*/
/* ---- =NEWS CYCLE --*/
	
	$('.newsTicker ul').cycle({ 
    fx:     'fade', 
    timeout: 6000, 
    delay:  -2000 
});
	
/*////////////////////////////////////*/
/* ---- =SLIDE TOGGLE --*/
	
	$("a.toggle").click(function () {
      $(".signUp").slideToggle(250);
	  $("#btnMidL").toggleClass("on");
	  return false;
    });

/*////////////////////////////////////*/
/* ---- =FORM SIGNUP --*/

//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 option = $('input[name=option]');
		var comment = $('textarea[name=comment]');

		//Simple validation to make sure user entered something
		//If error found, add error class to the text field
		if (name.val()=='') {
			name.addClass('error');
			return false;
		} else name.removeClass('error');
		
		if (email.val()=='') {
			email.addClass('error');
			return false;
		} else email.removeClass('error');
		
		if (option.val()=='0') {
			option.addClass('error');
			return false;
		} else option.removeClass('error');
		
		if (comment.val()=='') {
			comment.addClass('error');
			return false;
		} else comment.removeClass('error');
		
		//organize the data properly
		var data = 'name=' + name.val() + '&email=' + email.val() + '&option=' + 
		option.val() + '&comment='  + encodeURIComponent(comment.val());
		
		//disabled all the text fields
		$('.text').attr('disabled','true');
		
		//show the loading sign
		$('.loading').show();
		
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "signUp.php",	
			
			//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) {					
					//show the success message
					$('.sent').fadeIn('slow');
					$('.loading').hide();
					
				//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;
	});
	
/*////////////////////////////////////*/
/* ---- =FORM FEEDBACK --*/

//if submit button is clicked
	$('#feedback').click(function () {		
		
		//Get the data from all the fields
		var name2 = $('input[name=name2]');
		var email2 = $('input[name=email2]');
		var option2 = $('select[name=option2]');
		var comment = $('textarea[name=comment]');

		//Simple validation to make sure user entered something
		//If error found, add error class to the text field
		if (name2.val()=='') {
			name2.addClass('error');
			return false;
		} else name2.removeClass('error');
		
		if (email2.val()=='') {
			email2.addClass('error');
			return false;
		} else email2.removeClass('error');
		
		if (option2.val()=='0') {
			option2.addClass('error');
			return false;
		} else option2.removeClass('error');
		
		if (comment.val()=='') {
			comment.addClass('error');
			return false;
		} else comment.removeClass('error');
		
		//organize the data properly
		var data = 'name2=' + name2.val() + '&email2=' + email2.val() + '&option2=' + 
		option2.val() + '&comment='  + encodeURIComponent(comment.val());
		
		//disabled all the text fields
		$('.text').attr('disabled','true');
		
		//show the loading sign
		$('.loading').show();
		
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "feedback.php",	
			
			//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) {					
					//show the success message
					$('.sent').fadeIn('slow');
					$('.loading').hide();
					
				//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;
	});
	
});
