$(function(){

// получаем рефереры
$('#referers').val( window.name );
// alert( $('#ls').html() );

$('#popup_form').submit(function(){
   var errors = '';
   $('input[type=text]', this).each(function(){
      if( $(this).val() == '' ) {
         errors = 'Все поля обязательны для заполнения';
      }
   });
   var email = $('input[name=email]', this).val();
   if( !( /^[a-zA-Z0-9_\.\-]+\@[a-zA-Z0-9\-]+\.+[a-zA-Z0-9\.\-]+$/.test(email) ) ) {
      errors += '\nПоле email заполнено неверно';
   }
   
   if( errors ) {
      alert( errors );
   } else {
      var data = $(this).serialize();
      $('body').append( 
         '<script type="text/javascript" \
            src="http://www.plastic-okna.ru/cgi-bin/cert/main.pl?' + data + '"></script>' 
      );
   }//if
   return false;
});
});
function isInt(x) {
var y=parseInt(x);
if (isNaN(y)) return false;
return x==y && x.toString()==y.toString();
}

function showCert(resp){
   if( isInt( resp ) ) {
      location.replace('http://www.plastic-okna.ru/cgi-bin/cert/main.pl?session=' + new Date().getTime() + resp );
   } else {
      alert(resp);
   }
}
