
$(document).ready(function() {

//for toggling the divs (show and hide, binds the event to the click)
$('#firstdiv').hide();//hide it first
$('#seconddiv').hide();//hide it first
$('#thirddiv').hide();//hide it first
$('#fourthdiv').hide();//hide it first

$('#date').datepicker({ dateFormat: 'dd-mm-yy' });//datepicker


$('#target1').toggle(function() {
  $('#firstdiv').fadeIn(500);
}, function() {
 $('#firstdiv').fadeOut(500);
});

$('#target2').toggle(function() {
  $('#seconddiv').fadeIn(500);
}, function() {
 $('#seconddiv').fadeOut(500);
});

$('#target3').toggle(function() {
  $('#thirddiv').fadeIn(500);
}, function() {
 $('#thirddiv').fadeOut(500);
});

$('#target4').toggle(function() {
  $('#fourthdiv').fadeIn(500);
}, function() {
 $('#fourthdiv').fadeOut(500);
});

//end toggling

//for fading images on hover
$('.hoverfade').each(function() {
            $(this).hover(function() {
                $(this).stop().animate({ opacity: 0.5 }, 300);
            },
           function() {
               $(this).stop().animate({ opacity: 1.0 }, 300);
           });
        });
//end fading images on hover





//clickable divs
$("div.clickable").click( //this makes divs clickable (including any images in them), specify the url in the page , in the <div> tag. (in gallery.php for example)
function()
{
    window.location = $(this).attr("url");
});
//end clickable divs





$('.box').mouseover(function() { //when mouse over the box div change the border
 $(this).removeClass("box").addClass("boxhighlight");
});

$('.box').mouseleave(function() { //when mouse leaves set it back again
 $(this).removeClass("boxhighlight").addClass("box");
 });


$('#end').hide();// for hiding ajami desc then showing the rest of it.

 $('#more').click(function() { 
 $('#end').fadeIn(2000);
 });

$('#less').click(function() { 
 $('#end').fadeOut(1000);
 });


//for contact form
 $('.error').hide(); //hide error messages in contact form and mailing list form
 $('#successmessage').hide(); //hide success message


$('.text-input').focus(function() {//when focus on a field change the class to focus
$(this).removeClass('text-input').addClass('focus');
});

$('.text-input').blur(function() {//when moving away change the class back
 $(this).removeClass('focus').addClass('text-input');
});


$("#message").val("Your message"); //set text area prompt
//  $("#message").val(""); //clear field//clear comment prompt on focus, have done this in the html with //onFocus="this.value=''; this.onfocus=null;"
$('#message').focus(function() {//clear comment prompt on focus- this is the same as //onFocus="this.value=''; this.onfocus=null;"
  $("#message").val(""); //clear field
});

$("#name").val("Your name"); //set input area prompt
$('#name').focus(function() {//clear comment prompt on focus- this is the same as //onFocus="this.value=''; this.onfocus=null;"
  $("#name").val(""); //clear field
});

$("#email").val("Your email"); //set input area prompt
$('#email').focus(function() {//clear comment prompt on focus- this is the same as //onFocus="this.value=''; this.onfocus=null;"
  $("#email").val(""); //clear field
});

$('#submit').click(function() {
var name = $("#name").val();  //variables from the contact form
	var email = $("#email").val();  
	var message = $("#message").val();  
	var spam = $("#spam").val();  
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

	
            if ((name == "") || (name == "Your name")) {  
			$("#name_error").fadeIn(500);  
			$("#name").focus();  
			 return false;  
			}  
/*
			 if ((email == "") || (email == "Your email")) {  
			$("#email_error").fadeIn(500);  
			$("#email").focus();  
			 return false;  
			}
	*/

			if (!email.match(emailExp)){		//if email is not valid
			$("#email_error").fadeIn(500);  
			$("#email").focus();  
			 return false;  
			}  	

			 if ((message == "") || (message == "Your message")) {  
			$("#message_error").fadeIn(500);  
			$("#message").focus();  
			 return false;  
			} 
			if (spam !="FODIP"){
			$("#spam_error").fadeIn(500);  
			$("#spam").focus();  
			 return false;  
			}


		
	/*		if ((spam !="fodip") && (spam !="FODIP")){  // AND needed here if you want 2 negative conditions		
			$("#spam_error").fadeIn(500);  
			$("#spam").focus();  
			 return false;  
			}*/  
					

document.getElementById('submit').disabled=true; //disable the button
var t=setTimeout("document.getElementById('submit').disabled=false", 5000);// re-enable the button after 5 seconds			


var dataString = 'name='+ name +'&email='+ email + '&message='+ message;
$.ajax({
		type: "POST",
		url: "processmail.php", 
		data: dataString,
		cache: false,
		success: function(html){

//$('#seeall').replaceWith(html);

$('#successmessage').fadeIn(1000);

$('.text-input').focus(function() { //if you focus on a field again the success message goes as do the errors
$("#successmessage").fadeOut(1000);
$('.error').hide();
});

//$("#placement").append(html);// is the placement
//$("#fromphp").fadeIn("slow");// comes from the php //have to hide it first for fade to work!!
//$('#newcomment').fadeOut(2000);
//$('#newcomment').empty(); //empty the div other wise any new comments are seen again

		}//html function
});//ajax
return false;

});//click function

//*************************start submit notice *********************************

 $('#noticemessage').hide(); //hide success message for notices/events

/* this sets the values and clears them onclick, not really needed?
$("#title")
//	.val("Title") //set text area prompt
//  $("#message").val(""); //clear field//clear comment prompt on focus, have done this in the html with //onFocus="this.value=''; this.onfocus=null;"
	.focus(function() {//clear comment prompt on focus- this is the same as //onFocus="this.value=''; this.onfocus=null;"
	$(this).val(""); //clear field
});


$("#details")
	.val("Enter the details here") //set text area prompt
	.focus(function() {
	$(this).val(""); //clear field
});

$("#noticeemail")
	.val("Your email") //set text area prompt
	.focus(function() {
	$(this).val(""); //clear field
});
*/


$('.loading').hide(); //hide the ajax loading gif
$('.upload_loading').hide(); //hide the ajax loading gif

$('#submitnotice').click(function() {

var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	var title = $("#title").val();  //variables from the form
var date = $("#date").val();
	var details = $("#details").val();  
var spam = $("#spamnotice").val();  
var email = $("#noticeemail").val();  

//var file= $("#file").val();  

			if (!email.match(emailExp)){		//if email is not valid
			$("#noticeemail_error").fadeIn(500);  
			$("#noticeemail").focus();  
			 return false;  
			}  	

			if ((title == "") || (title == "Title")) {  
			$("#title_error").fadeIn(500);  
			$("#title").focus();  
			 return false;  
			}
			
			if ((details == "") || (details == "Enter the details here")) {  
			$("#details_error").fadeIn(500);  
			$("#details").focus();  
			 return false;  
			}

			if (spam !="FODIP"){
			$("#spamnotice_error").fadeIn(500);  
			$("#spamnotice").focus();  
			 return false;  
			}


//var dataString = 'email='+ email +'&title='+ title +'&details='+ details;
//var dataString = '&email='+ email +'&title='+ title + '&date='+ date+ '&details='+ details;
var dataString = '&email='+ email +'&title='+ title + '&date='+ date+ '&details='+ details;



$('.loading').show(); 
$(this).attr('disabled', 'disabled');
//setTimeout(function(){$(this).removeAttr("disabled");}, 5000);
//$('input:submit').removeAttr("disabled");
//$(this).attr('disabled', 'disabled').delay(5000).attr('disabled', '');no
//$(this).attr('disabled', 'disabled');

//var t = setTimeout ($(this).attr('disabled', false), 5000 ); 
//$('#notice').submit(function(){
 //   $('input[type=submit]', this).attr('disabled', 'disabled');
//});

		$.ajax({
		type: "POST",
		url: "processnotice.php", 
		data: dataString,
		cache: false,
			success: function(html){
			//alert(email);
			$('#noticemessage').fadeIn(1000);
			$('.loading').hide(); 
		//	$('#noticemessage').append(html); //adds any output from php


				$('.text-input').focus(function() { //if you focus on a field again the success message goes as do the errors
				$("#noticemessage").fadeOut(1000);
			$('#uploadmessage').fadeOut(1000);

			//	$("#uploadmessage").fadeOut(1000);
				$('.error').hide();
				$('#submitnotice').attr('disabled', '');//reenable the submit button

				});

		}//success
	});//ajax
return false;

});//click function

//**************************end submit notice *********************************

//**************************start image *********************************
/*
$('#image').click(function() {

		$.ajax({
		type: "POST",
		url: "getimage.php", 
	//	data: dataString,
		cache: false,
		success: function(data){

	//	$('#imageplacement').append(data);
	$('<img></img>')
				.attr('src', 'images/' + data)//yes
				.hide()
				.load(function(){
					$(this).fadeIn();
				})  //load
				.appendTo('#imageplacement');//yes

		}//success
		});//ajax
		return false;
});//click function
*/
//**************************end image *********************************

//startajax upload
//	function ajaxFileUpload()
//	{
//		$("#loading") //when ajax starts the loader shows
	//	.ajaxStart(function(){
		//	$(this).show();
//		})
//		.ajaxComplete(function(){
//			$(this).hide();
//		});

$('#buttonUpload').click(function() {


var file= $("#file").val();  
if (file == ""){
	alert("Please browse and choose an image");
	return false;
	}
$('.upload_loading').show(); 

		$.ajaxFileUpload({
		//	$.ajax({
				url:'doajaxfileupload.php',
				secureuri:false,
				//fileElementId:'fileToUpload',
					fileElementId:'file',
				//dataType: 'json',
					dataType: 'html',
				//success: function (data, status) //yes
					success: function(html) 
				{
					
					/*
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{
							alert(data.msg);
						}
					}
				},//success

				error: function (data, status, e)
				{
					alert(e);
				}

			*/
				}
			});//ajax
		
		return false;
	});//click
	
//end ajax upload


 });//doc ready
