// JavaScript Document
$(document).ready(function(){
	
	//textfield checks
	$("#uemail").blur(function() {
		//alert("bluring");								
	});
	$("#e").focusout(function(){
		$("#emailcheck").css({"display":"visible"});
	});
	$("#n").focusout(function(){
		$("#namecheck").css({"display":"visible"});
	});
	$("#m").focusout(function(){
		$("#messagecheck").css({"display":"visible"});
	});
	
	//send message
	
	$("#emailus").click(function(){
		//alert('press');
		
		var e	 	= $('#e').val();
		var n 		= $('#n').val();
		var m		= $('#m').val();
		var mid		= $('#minid').val();
		var me		= $('#me').val();
		var mn		= $('#mname').val();
		var errors = new Array;
		
		if(e==""){
			errors.push("\rPlease enter your email");
		}
		if(n==""){
			errors.push("\rPlease enter your name");
		}
		if(m==""){
			errors.push("\rPlease enter a message");
		}
		
		if(errors.length==0){
			//proceed
		}else{
			//alert errors
			
			var aVal = "";
			$.each(errors, function(key, value) { 
				aVal += value;
			});
			/*$(".overlayerpop").fadeIn("fast");
			$("#alertpop").fadeIn("fast");
			$("#alertmessage").html(aVal); */
			alert(aVal);
			return false;
		}
		$("#emailus").css({"display":"none"});
		$("#loading").fadeIn("slow");
		
		var send = 
		'e=' + e
		+ '&n=' + n
		+ '&m=' + m 
		+ '&mid=' + mid
		+ '&min=' + mn
		+ '&me=' +me; 
		
		$.ajax({  
			url: "http://www.lifestream.tv/sendusanote/index.php",   
         	type: "GET",  
			data: send,       
        	cache: false,  
        	//success  
            success: function (data) {
				if(data == "success"){ 
				alert("Thank you, your message has been sent.");
				$("#loading").css({"display":"none"});
				$("#emailus").fadeIn("slow");
				$("#e").val("");
				$("#n").val("");
				$("#m").val("");
				}else{
				alert(data);
				}
			}
		});	
		
	});//end ajax
	
});//end script
