$(document).ready(function () {
  
  $('.link_book').click(function () {
    $("#bookWindow").html(makeBookForm());
		$('#bookWindow').modal();
	});


});


function sendBook(){

       $("#book_msg").html('');

          $.ajax({
		          type: "POST",
		          data: {
                      action: 'sendBooking',
                      arrival: $("#book_arrival").val(),
                      rooms: $("#book_rooms").val(),
                      nights: $("#book_nights").val(),
                      departure: $("#book_departure").val(),
                      obekt: $("#book_obekt").val(),
                      name: $("#book_name").val(),
                      to: $("#book_to").val(),
                      email: $("#book_email").val(),
                      phone: $("#book_phone").val(),
                      captcha: $("#book_captcha").val(),
                      more: $("#book_more").val()
                 }, 
              url: 'data.php',
		          dataType: 'json',
		          timeout: 6000,
		          global: 'false',
		          success: function(json) {
                
                 if (json.Result==true){
                     alert(json.Text);
                     $.modal.close();
                 }else{$("#book_msg").html(json.Text);}
             }    
          });  
}

function makeBookForm(){

     var text='';
    
       text+='<b class="b1f default"></b><b class="b2f default"></b><b class="b3f default"></b><b class="b4f default"></b>';
            text+='<div class="ldefault  pb5">';
                text+='<div class="default pl5 pt3 pb5 bb_news bold">';
                  text+=tr_online_booking;
                text+='</div>';
                
                text+='<div class="abstand pt2"></div>';
                text+='<div class="invisib mt5 mb5 c_red bold" id="book_msg"></div>';
        
                text+='<div class="inline w580 mauto center">';
                  text+='<h2 class="c_blue">'+req_title+'</h2>'; 
                text+='</div>';
                text+='<div class="abstand pt5"></div>';
                
            
                text+='<div class="inline w300 wauto" >';
                  text+='<b>'+tr_date_arrival+'</b><br />';
                  text+='<input type="text" name="book_arrival" id="book_arrival" value="" class="w260  intxt" />';   
                  text+='<input id="book_to" type="hidden" name="book_to" value="'+mailto+'" />';
                  text+='<input id="book_obekt" type="hidden" name="object" value="'+req_title+'" />';
                text+='</div>';
  
                text+='<div class="inline w300 wauto" >';
                  text+='<b>'+tr_date_departure+'</b><br />';
                  text+='<input type="text" name="book_departure" id="book_departure" value="" class="w260  intxt" />';
                text+='</div>';
                text+='<div class="abstand pt10 pb5"></div>';

                text+='<div class="inline w300 wauto" >';
                  text+='<b>'+tr_nr_nights+'</b><br /> ';
                  text+='<input type="text" name="book_nights" id="book_nights" value="" class="w260  intxt" />'; 
                text+='</div>';
  
                text+='<div class="inline w300 wauto" > ';
                  text+='<b>'+tr_nr_rooms+'</b> '+tr_room_arts+'<br /> ';
                  text+='<input type="text" name="book_rooms" id="book_rooms" value="" class="w260  intxt" />';
                text+='</div> ';
                text+='<div class="abstand pt10 pb5"></div> ';


                text+='<div class="inline w200 wauto" > ';
                  text+='<b>'+tr_your_name+'</b><br /> ';
                  text+='<input type="text" name="book_name" id="book_name"  value="" class="w160  intxt" />';
                text+='</div> ';
   
                text+='<div class="inline w200 wauto" >';
                  text+='<b>'+tr_your_email+'</b><br />';
                  text+='<input type="text" name="book_email" id="book_email" value="" class="w170  intxt" />';
                text+='</div>';
              
                text+='<div class="inline w200 wauto" >';
                  text+='<b>'+tr_your_phone+'</b><br />';
                  text+='<input type="text" name="book_phone" id="book_phone" value="" class="w150  intxt" />';
                text+='</div>';
              
                text+='<div class="abstand pt10 pb5"></div> ';
 
                text+='<div class="inline w580 ml10 mr10 mt5">';
                  text+='<div class="right inline w180 mt3 fs13"><b>'+tr_additionally+'</b><br />';
                  text+='</div>'; 
                  text+='<textarea name="book_more"  id="book_more" class="w350  intxt" cols="" rows="5"></textarea>';
                text+='</div>';
     
     
                 text+='<div class="abstand pt3 pb3"></div>';

                   text+='<div class="no_dist inline w350 ml10 mr5 mt2 right">';
                      text+='<b>'+tr_captcha_text+':</b> <br />'; 
                   text+='</div>';    

                    text+='<div class="no_dist inline w180 ml10 mr5">';
                         text+='<input type="text" value="" name="book_captcha" id="book_captcha" class="w80  intxt" />';
                    text+='</div>';    

                    text+='<div class="abstand"></div>';
  
                    text+='<div class="no_dist inline w100 ml10 mr5">';
                        text+='<img class="ml10" src="'+captcha+'"  />';
                    text+='</div>';         
               
            
                text+='<div class="abstand pt5"></div>';
            
                text+='<div class="inline w270 inline mr10">';
                     text+='<input type="button" onClick="sendBook();" class="w150 inbtn fright" value="'+tr_send+'" />';
                text+='</div>';
               
                 text+='<div class="inline w270 left inline">';
                     text+='<input type="button" onClick="$.modal.close();"; class="w150 inbtn" value="'+tr_close+'" />';
                text+='</div>';
               
                text+='<div class="abstand pt5"></div>';
            
           text+='</div>';
     text+='<b class="b4f ldefault"></b><b class="b3f ldefault"></b><b class="b2f ldefault"></b><b class="b1f ldefault"></b>';
 
 return text;
}

