$(document).ready(function () {
	$(".latin").keypress(function (e) { 
		if((e.which<32 || e.which>126) && e.which != 0 && e.which != 8 && e.which != 13) {
			return false;
		}
	});
	
	$('.number').keypress(function (e) { 
		if(e.which > 31 && (e.which < 48 || e.which > 57) && e.which != 46 && e.which != 37 && e.which != 38 && e.which != 39 && e.which != 40 && e.which != 0 && e.which != 8) {
			return false;
		}	
	});
	
	$('#send_news_mail').click(function () {
		send_news_mail();
	});	
});

function send_news_mail() {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var mail=$('#news_mail').val();
	var return_val=true;
	if(mail=='') {
		return_val=false;
		$('#news_mail').css('color','#C00');	
	} else if(reg.test(mail)==false) {
		return_val=false;	
		$('#news_mail').css('color','#C00');
	} else {
		$('#news_mail').css('color','#999');
	}
	if(return_val) {
		$.ajax({
			type: "POST",
			url: "ajax/news_mail.php",
			data: "mail="+mail,
			cache: true,
			success: function(msg){
				$('#news_mail').val($('#news_mail').attr('title'));
				//$('#news_mail_result').css('display','block');
				show_mail_popup(mail);
			}
		});	
	}
}
var closeTimeout;
function show_mail_popup(mail){
	$('#mail_popup_mail').html('');
	var top1=$('#end').position().top;
	var top2=$('#body').height();
	var top=top2;        
	if(top1>top2) top=top1;
	$('#mail_popup_bg').css({height:top, opacity:0.8});
	$('#mail_popup').css({height:top});
	$('#mail_popup').fadeIn(200);
	$('#mail_popup_mail').html(mail);
	clearTimeout(closeTimeout);
	closeTimeout = setTimeout(mail_popup_close, 3000);
} 
function mail_popup_close() {
	$('#mail_popup').fadeOut(200);
}

function facebook(url) {
	url='http://www.facebook.com/sharer.php?u='+url
	var newwindow=window.open(url,"facebook","menubar=1,resizable=1,width=565,height=380");
	if (window.focus) {newwindow.focus()}
	return false;
}

function send_page(url) {
	var newwindow=window.open(url,"Send","menubar=1,resizable=1,width=450,height=350");
	if (window.focus) {newwindow.focus()}
	return false;
}
