// JavaScript Document

function checkMail(email) {
	var filtro = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@+([_a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]{2,200}\.[a-zA-Z]{2,6}$/;
	return filtro.test(email);
}

function clickEmailThis() {
	//evento.preventDefault();
	testMail = checkMail($('#etTo').val());
	if ((testMail) && ($('#etFrom').val()!="") && ($('#etComments').val()!="")) {
		//$('#frm-feedback').attr('method', 'post').submit();
		$.post("ah_emailthis.php", { To: $('#etTo').val(), From: $('#etFrom').val(), Address: $('#etAddress').val(), Comments: $('#etComments').val() }, function (datos) {
			tb_remove();					
		});
	} else {
		alert("Please provide all the information required and a valid email address.");	
	}
};

function calendarbtnstart() {
		$('#datepicker').unbind();		
		$('table.ui-datepicker-calendar a').click(function (evento) { 
				evento.preventDefault();
				$.get('ah_events.php', { date: $(this).attr('rel') }, function (losdatos) { 
					$('#futurecalendarevents').html(losdatos);
				});
		});
		$('#datepicker #dp-elheader a').click(function (evento) {
				evento.preventDefault();
				$.get('ah_calendar.php', { month: $(this).attr('rel'), gathe: $('#mark-home').html() }, function (devoluciondatos3) { 
					$('#datepicker').html(devoluciondatos3); 
					calendarbtnstart();
					correctPNG();
				});	
		});
}

function bpeoplestart() {
		//$(document).pngFix(); 
		$('#submit-comment').click(function (evento) { 
				evento.preventDefault();
				testMail = checkMail($('#Email').val());
				if ((testMail) && ($('#Name').val()!="") && ($('#Comment').val()!="")) {
						$('#tapa').fadeIn();
						$.post("ah_comments.php", { Id_Post: $('#Id_Post').val(), Email: $('#Email').val(), Name: $('#Name').val(), Comment: $('#Comment').val() }, function (datos) {
							$('#tapa').html(datos).animate({opacity: 1}, 2000, function () { 
								$('#comment_form_input').remove();
								$('#tapa').fadeOut('normal', function() { $('#comment_form').remove(); $.scrollTo('0px', 800); $('#comment_title2').remove(); });
							});
						});
				} else {
					alert("Please provide all the information needed and a valid email address.");	
				}
		});
		$('#submit-comment-sps').click(function (evento) { 
				evento.preventDefault();
				testMail = checkMail($('#Email').val());
				if ((testMail) && ($('#Name').val()!="") && ($('#Comment').val()!="")) {
						$('#tapa').fadeIn();
						$.post("ah_comments_sps.php", { Id_Post: $('#Id_Post').val(), Email: $('#Email').val(), Name: $('#Name').val(), Comment: $('#Comment').val() }, function (datos) {
							$('#tapa').html(datos).animate({opacity: 1}, 5000, function () { 
								$('#comment_form_input').remove();
								$('#tapa').fadeOut('normal', function() { $('#comment_form').remove(); $.scrollTo('0px', 800); $('#comment_title2').remove(); });
							});
						});
				} else {
					alert("Please provide all the information needed and a valid email address.");	
				}
		});
		
		
		
		$('#submit-sps-login').click(function (evento) { 
				evento.preventDefault();
				$('#frm-sps-login').submit();
		});
		$('#pass,#user').bind('keypress', function(e) {
			if(e.keyCode==13){
				// Enter pressed... do anything here...
				$('#frm-sps-login').submit();
			}
		});
		$('#btn_search').click(function (evento) { 
				evento.preventDefault();
				$('#form-search').submit();
		});
		$('#btn_feedback').click(function (evento) { 
				evento.preventDefault();
				testMail = checkMail($('#Email').val());
				if ((testMail) && ($('#Name').val()!="") && ($('#LastName').val()!="") && ($('#Summary').val()!="") && ($('#Remarks').val()!="")) {
					$('#frm-feedback').attr('method', 'post').submit();
				} else {
					alert("Please provide all the information required and a valid email address.");	
				}
		});
		calendarbtnstart();
}

$(document).ready(function(){
		bpeoplestart();
});