function downloadCommPage(link)
{
     placePreloader("preloaderStartCommunication");
     $.get(link, function(data){
         $("#communication").html(data);
         if($("#message").length > 0)
         {
             $("#message").focus();
             //$("#commentForm").validate();
             $("#commentForm").validate({
                 submitHandler: function() {
                     saveNewMessage()
                 }
             }); 
         }
     });
     return false;
}

 function newMessageForm()
 {
     placePreloader("preloaderStartCommunication");
     downloadCommPage("/startpage/newMessageForm.php");
 }
 
 function saveNewMessage()
 {
     $("#btnSendMessage").replaceWith("Публикую...");
     $.ajax({
         url : "/startpage/newMessageForm.php",
         data : { message: $("#message").val() },
         cache : false,
         type: "POST",
         beforesend: function() {
             placePreloader("communication");
         },
         error : function(XMLHttpRequest, textStatus, errorThrown){
            //console.log or alert error
            alert(errorThrown);
         },
         success: function(data){
            getCommunicationFirstPage();
         }
     });

     return false;
 }
 
 function getCommunicationFirstPage()
 {
     downloadCommPage("startpage/communication.php");
     return false;
 }
 
 function getPhotoFirstPage(page)
 {
     downloadPartView("startpage/photo.php?p="+page, "startPhoto", null, "GET", true, "preloaderStartPhoto");
     return false;
 }
 
 function getStoryFirstPage(page)
 {
     downloadPartView("startpage/story.php?p="+page, "startStory", null, "GET", true, "preloaderStartStory");
     return false;
 }
 
 $(document).ready(function(){
    //getCommunicationFirstPage();
    //getPhotoFirstPage();
    //getStoryFirstPage();
 })