/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function validateEmail(email) { 
 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 
 return email.match(re) 
}
$(document).ready(function(){

 var components = {
  messageBox: function(){
   return "<div id='printMessageBox' style='\
          position:fixed;\
          top:50%; left:50%;\
          text-align:center;\
          margin: -60px 0 0 -155px;\
          width:310px; height:120px; font-size:16px; padding:10px; color:#222;\
          opacity:0;\
          background:#fff;\
          border: 6px solid #555;\
          border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px;\
          box-shadow:0px 0px 10px #888; -webkit-box-shadow:0px 0px 10px #888; -moz-box-shadow:0px 0px 10px #888'>\
          Спасибо за интерес к новостям!</div>";
  }
 }
 $("body").append(components.messageBox());
 $("#printMessageBox").css("opacity", 0);
 var el = $("#subscribe");
 
 $("<a />")
 .attr({
  "href":"#",
  "id":"gotF"
 })
 .html("Подписаться на новости")
 .appendTo(el)
 .click(function(){
  el.empty().html("Введите ваш email");
  $("<input />").attr({
   "type":"text",
   "name":"email",
   "id":"getMail"
  }).appendTo(el);
  $("<input />").attr({
   "type":"submit",
   "name":"submit",
   "value":"OK"
  }).appendTo(el).click(function(){
   a = $("#getMail").val();
   if(validateEmail(a)) {
    $("#printMessageBox").animate({
     opacity:1
    }, 1500,function(){
     $.get("/netcat/modules/default/subscribe.php",
     {
      'a':a
     },function(){
      el.remove().delay(2000).fadeOut(400,function(){
       $("#printMessageBox").hide("1500");
      });
     });
    });
    return false;
   }else {
    alert("Неккоректный адрес");
    return false;
   }
   return false;
  });
  return false;
 });
});



