 $(document).ready(function(){
	$("#sendmail").click(function(){
		var valid = '';
		var isr = ' is required.';
		var name = $("#name").val();
		var mail = $("#mail").val();
		var subject = $("#subject").val();
		var text = $("#text").val();
		if (name.length<1) {
			valid += '<br />Name'+isr;
		}
		if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid += '<br />A valid Email'+isr;
		}
		if (subject.length<1) {
			valid += '<br />Subject'+isr;
		}
		if (text.length<1) {
			valid += '<br />Text'+isr;
		}
		if (valid!='') {
			$("#response").fadeIn("slow");
			$("#response").html("Error:"+valid);
		}
		else {
			
			
			var datastr ='name=' + name + '&mail=' + mail + '&subject=' + subject + '&text=' + encodeURIComponent(text);
			$("#response").css("display", "block");
			$("#response").html("Sending Message... ");
			$("#response").fadeIn("slow");
			setTimeout("send('"+datastr+"')",2000);
		}
		return false;
	});
});
function send(datastr){
	$.ajax({	
		type: "POST",
		url: "index.php?a=mail",
		dataType: "text",
		data: datastr,
		cache: false,
		success: function(html){
		$("#response").fadeIn("slow");
		$("#response").html(html);
		setTimeout('$("#response").fadeOut("slow")',2000);
	}
	});
}



function imageloader(url,folder) {
	
	var image="./pages/gallery.php?t=loadimage&imgid="+url+"&folder="+folder;
	
	
	$('#image').html('<p><center><img src="./template/images/loader.gif" width="220" height="19" id="preload" /></div></p>');
    $('#image').load(image, "",
        function(responseText, textStatus, XMLHttpRequest) {
            if(textStatus == 'error') {
                $('#example-placeholder').html('<p>There was an error making the AJAX request</p>');
            }
        }
    );
   
}
