var url = window.location.host;
//var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//var pageTracker = _gat._getTracker("UA-5957829-1"); pageTracker._trackPageview();

function changePageBlog ( page )
{
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "blog",  
      func:    "bl_viewBlog",  
      page:   page
    },
    function ( data )
    {
      $('#blog').html(data);
    }
  );
}

function uploadMagazine(id)
{
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "journal",  
      func:    "fileUpload",  
      ident:   id
    },
    function ( data1 )
    {
    }
  );
}

function sendMail( idStatus, idComment, status )
{
  if( idStatus != '' && idComment != '' && status != '' )
  {
    $.post(
      "http://"+url+"/index.php",
      { 
        s:       "ajax",
        ajax:    "comments",  
        func:    "sendMail",  
        ident:   idStatus,
        comment: idComment,
        status:  status
      },
      function ( data )
      {
        alert( data );
        $("#send"+idComment).removeAttr('onclick');
      }
    );
  }
}

function deleteCatalogs()
{
  if(confirm('Вы действительно желаете удалить?')) 
  { 
    $("#myform").submit(); 
  }
}

function changeManual(id)
{
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "manual",  
      func:    "changeManual",  
      city_id:   id
    },
    function ( data1 )
    {
      $("#citi_box").html( data1 );
    }
  );
}

function OpenCloseComments()
{
  if($('#viewComments').css('display') == 'block' )
  { 
    $('#viewComments').css('display','none'); 
    $('#viewCommentsAddDown').css('display','none'); 
    $('#otkl_').html('Включить');
    $('#otkl').html('Включить');
  } 
  else 
  {
    $('#viewComments').css('display','block'); 
    $('#viewCommentsAddDown').css('display','block'); 
    $('#otkl_').html('Отключить');
    $('#otkl').html('Отключить');
  }
}

function changeNews(id)
{

  $('#title_news').html('Wait..');
    
    
  $('#inbox_news').empty();
  $('#inbox_news').html('Wait..');
  
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "news",  
      func:    "getNewsMenu",  
      ident:   id
    },
    function ( data1 )
    {
      $('#title_news').empty();
      $('#title_news').html(data1);
    }
  );
  
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "news",  
      func:    "getNews",  
      ident:   id
    },
    function ( data2 )
    {
      $('#inbox_news').empty();
      $('#inbox_news').html(data2);
    }
  );

}

function changeArticle(id)
{

  $('#title_article').html('Wait..');
    
    
  $('#inbox_article').empty();
  $('#inbox_article').html('Wait..');
  
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "article",  
      func:    "getArticleMenu",  
      ident:   id
    },
    function ( data1 )
    {
      $('#title_article').empty();
      $('#title_article').html(data1);
    }
  );
  
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "article",  
      func:    "getArticle",  
      ident:   id
    },
    function ( data2 )
    {
      $('#inbox_article').empty();
      $('#inbox_article').html(data2);
    }
  );

}

function changeNewsDet( id )
{
  $('#title_news').html('Wait..');
    
    
  $('#inbox_news').empty();
  $('#inbox_news').html('Wait..');
  
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "news",  
      func:    "getNewsMenuDet",  
      ident:   id
    },
    function ( data1 )
    {
      $('#title_news').empty();
      $('#title_news').html(data1);
    }
  );
  
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "news",  
      func:    "getNewsDet",  
      ident:   id
    },
    function ( data2 )
    {
      $('#inbox_news').empty();
      $('#inbox_news').html(data2);
    }
  );
}

function changeArticleDet( id )
{
  $('#title_article').html('Wait..');
    
    
  $('#inbox_article').empty();
  $('#inbox_article').html('Wait..');
  
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "article",  
      func:    "getArticleMenuDet",  
      ident:   id
    },
    function ( data1 )
    {
      $('#title_article').empty();
      $('#title_article').html(data1);
    }
  );
  
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "article",  
      func:    "getArticleDet",  
      ident:   id
    },
    function ( data2 )
    {
      $('#inbox_article').empty();
      $('#inbox_article').html(data2);
    }
  );
}

function fileDownload(id)
{
  return false;
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "journal",  
      func:    "fileDownload",  
      ident:   id
    },
    function ( data1 )
    {
      alert( data );
    }
  );
}
/*
function clearAddComment()
{
 // alert(  $("#nameComment").val());
  $("#nameComment").val('Ваше имя');
  $("#textComment").val('Текст комментария');
  $("#captcha").val('');
  refreshimg();
}

function clearAddCommentAnother()
{
 // alert(  $("#nameComment").val());
  $("#nameComment1").val('');
  $("#textComment1").val('');
  $("#captcha1").val('');
  refreshimg1();
}

function addComment( action, ident )
{
  var status;
  
  if( action == "news" )
  {
    status = "bl_viewComment";
  }
  else if( action == "article" )
  {
    status = "bl_viewCommentArticle";
  }
  else if( action == "blog" )
  {
    status = "bl_viewCommentBlog";
  }

  if(  ($("#nameComment").val() != '' || $("#nameComment").val() != 'Ваше имя') && ( $("#textComment").val() != '' || $("#textComment").val() != 'Текст комментария' ) )
  {
    $.post(
      "http://"+url+"/index.php",
      { 
        s:       "ajax",
        ajax:    "comments",  
        func:    "addComment",
        action:  action,
        ident:   ident,
        name:    $("#nameComment").val(),
        text:    $("#textComment").val() 
      },
      function ( data2 )
      {
        alert(data2);
        clearAddComment();
        $.post(
          "http://"+url+"/index.php",
          { 
            s:       "ajax",
            ajax:    "comments",  
            func:    status,
            id:      ident,
            action:  "addComment"
          },
          function ( data3 )
          {
            $("#viewComments").html(data3);
          }
        );
      }
    );
  }
}
 

function commentTo( author )
{
  viewAddComment();
  
  if( $('#textComment').val() == 'Текст комментария' )
  {
    $('#textComment').val(author+' ');
  }
  else
  {
    $('#textComment').val($('#textComment').val()+' '+author+' ');
  }
}
 */

/*
function addCommentAnother( action, ident )
{
  var status;
  
  if( action == "news" )
  {
    status = "bl_viewComment";
  }
  else if( action == "article" )
  {
    status = "bl_viewCommentArticle";
  }
  
  if(  $("#nameComment1").val() != '' && $("#textComment1").val() != '' )
  {
    $.post(
      "http://"+url+"/index.php",
      { 
        s:       "ajax",
        ajax:    "comments",  
        func:    "addComment",
        action:  action,
        ident:   ident,
        name:    $("#nameComment1").val(),
        text:    $("#textComment1").val() 
      },
      function ( data2 )
      {
        alert(data2);
        clearAddCommentAnother();
        $.post(
          "http://"+url+"/index.php",
          { 
            s:       "ajax",
            ajax:    "comments",  
            func:    status,
            id:      ident,
            action:  "addComment"
          },
          function ( data3 )
          {
            $("#viewComments").html(data3);
          }
        );
      }
    );
  }
}
*/
//function viewAddComment()
//{
//  
//  $('#addComm').css("display", "block");
//  $('#addCommAnother').css("display", "none");
  //refreshimg1();
//}
/*
function viewAddCommentAnother()
{
    $('#addCommAnother').css("display", "block");
   $('#addComm').css("display", "none");
   refreshimg();

}*/

function changePage( ident, page, status )
{
  var func;
  if( status == "article" )
  {
    func = "bl_viewCommentArticle";
  }
  else
  {
    func = "bl_viewComment";
  }
  $.post(
    "http://"+url+"/index.php",
    { 
      s:       "ajax",
      ajax:    "comments",  
      func:    func,
      id:      ident,
      action:  "addComment",
      page:    page
    },
    function ( data3 )
    {
      $("#viewComments").html(data3);
    }
  );
}

function viewContentSearchObj ( id )
{
  $("#searchRealEstate").empty();
  $("#searchRealEstate").html('Waiting..');
  $.post(
    "http://"+url+"/index.php",
    { 
      s:    "ajax",
      ajax: "objects",  
      func: "bl_viewCatObj",
      id:   id
    },
    function ( data )
    {
      $("#searchRealEstate").empty();
      $("#searchRealEstate").html(data);
    }
  );
}
function viewContentSearch( id )
{
  $("#searchRealEstate").empty();
  $("#searchRealEstate").html('Waiting..');
  $.post(
    "http://"+url+"/index.php",
    { 
      s:    "ajax",
      ajax: "catalog",  
      func: "viewContentSearch",
      id:   id
    },
    function ( data )
    {
      $("#searchRealEstate").empty();
      $("#searchRealEstate").html(data);
    }
  );
}

function viewContentSearchLeft( id )
{
  $("#searchRealEstateLeft").empty();
  $("#searchRealEstateLeft").html('Waiting..');
  $.post(
    "http://"+url+"/index.php",
    { 
      s:    "ajax",
      ajax: "objects",  
      func: "viewCatObjLeft",
      id:   id
    },
    function ( data )
    {
      $("#searchRealEstateLeft").empty();
      $("#searchRealEstateLeft").html(data);
    }
  );
}

//captcha
// CREATING THE REQUEST


function refreshimg()
{
  //var url = 'image_req.php';
  //dorefresh(url, displayimg);
  document.getElementById('captcha').style.border = '1px solid #ffffff';
  document.getElementById('captcha').style.background = '#fffffff';
  $.post("http://"+url+"/index.php",
    { 
      s:    "ajax",
      ajax: "comments",  
      func: "sessionComment"
    },
    function ( data )
    {
      $("#idCaptcha").html(data);
      $('#captcha').empty();
    }
  );
}
/*
function refreshimg1()
{
  //var url = 'image_req.php';
  //dorefresh(url, displayimg);
  document.getElementById('captcha1').style.border = '1px solid #ffffff';
  document.getElementById('captcha1').style.background = '#fffffff';
  $.post("http://"+url+"/index.php",
    { 
      s:    "ajax",
      ajax: "comments",  
      func: "sessionComment1"
    },
    function ( data )
    {
      $("#idCaptcha1").html(data);
      $('#captcha1').empty();
    }
  );
}*/




// SUBMISSION

function check(type, ident)
{
  var submission = $('#captcha').val();
//  var url = 'process.php?captcha=' + submission;
  //docheck(url, displaycheck);
  $.post("http://"+url+"/index.php",
    { 
      s:    "ajax",
      ajax: "comments",  
      func: "checkCaptchaComment",
      captcha: submission
    },
    function ( data )
    {
      if(data == '1')
      {
        document.getElementById('captcha').style.border = '1px solid #49c24f';
        document.getElementById('captcha').style.background = '#bcffbf';
        addComment(type, ident);
      }
      if(data == '0')
      {
        document.getElementById('captcha').style.border = '1px solid #c24949';
        document.getElementById('captcha').style.background = '#ffbcbc';
        alert('Wrong image code');
      }
    }
  );
}

function checkCaptcha()
{
  var submission = $('#captcha').val();
//  var url = 'process.php?captcha=' + submission;
  //docheck(url, displaycheck);
  $.post("http://"+url+"/index.php",
    { 
      s:    "ajax",
      ajax: "comments",  
      func: "checkCaptchaComment",
      captcha: submission
    },
    function ( data )
    {
      if(data == '1')
      {
        document.getElementById('captcha').style.border = '1px solid #49c24f';
        document.getElementById('captcha').style.background = '#bcffbf';
        $("#myform").submit();
      }
      if(data == '0')
      {
        document.getElementById('captcha').style.border = '1px solid #c24949';
        document.getElementById('captcha').style.background = '#ffbcbc';
        alert('Wrong image code');
      }
    }
  );
}

/*function check1(type, ident)
{
  var submission = $('#captcha1').val();
//  var url = 'process.php?captcha=' + submission;
  //docheck(url, displaycheck);
  $.post("http://"+url+"/index.php",
    { 
      s:    "ajax",
      ajax: "comments",  
      func: "checkCaptchaComment1",
      captcha1: submission
    },
    function ( data )
    {
      if(data == '1')
      {
        document.getElementById('captcha1').style.border = '1px solid #49c24f';
        document.getElementById('captcha1').style.background = '#bcffbf';
        addCommentAnother(type, ident);
      }
      if(data == '0')
      {
        document.getElementById('captcha1').style.border = '1px solid #c24949';
        document.getElementById('captcha1').style.background = '#ffbcbc';
        alert('Wrong image code');
      }
    }
  );
}*/

/*function docheck(url, callback)
{
  http.open('GET', url, true);
  http.onreadystatechange = displaycheck;
  http.send(null);
}

function displaycheck()
{
  if(http.readyState == 4)
  {
    var showcheck = http.responseText;
    if(showcheck == '1')
    {
      document.getElementById('captcha').style.border = '1px solid #49c24f';
      document.getElementById('captcha').style.background = '#bcffbf';
    }
    if(showcheck == '0')
    {
      document.getElementById('captcha').style.border = '1px solid #c24949';
      document.getElementById('captcha').style.background = '#ffbcbc';

    }
  }
}*/

function addAttantion( id, status )
{
  $.post("http://"+url+"/index.php",
    { 
      s:    "ajax",
      ajax: "attantion",  
      func: "addAttantion",
      ident: id,
      status: status
    },
    function ( data )
    {
      if( data != 'false' )
      {
        $("#attantion_quest").html(data);
      }
    }
  );
}

function minusAttantion( id, status )
{
  $.post("http://"+url+"/index.php",
    { 
      s:    "ajax",
      ajax: "attantion",  
      func: "minusAttantion",
      ident: id,
      status: status
    },
    function ( data )
    {
      if( data != 'false' )
      {
        $("#attantion_quest").html(data);
      }
    }
  );
}

function validateString(str)
{
    var reg = /[^\d\s\w]/i;
    var result = reg.test(str);
    if (!result)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function validateStringSigns(str)
{
    var reg = /[^\d\s\w\?\!,;-]/i;
    var result = reg.test(str);
    if (!result)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function validateEmail(email)
{
    var reg = /(\w|\.+)@([a-z]|-|\d|_)+(\.[a-z]+){1,10}$/i;
 
    var result = reg.test(email);
 
    if(!result)
    {
        return false;
    }
    else
    {
        return true;
    }
}

function confirmDelete()
{
    return confirm( translates['confirm_delete'] );
}


function updateCaptcha()
{
    //alert("==");
    //alert(document.getElementById("captcha_img").src);
    //document.getElementById("captcha_img").src ="http://"+url+"/globals/inc/captcha/CaptchaSecurityImages.php";
}

function validateForm(id)
{    
    if( $("#"+id).validate().form() )
    {
        $("#"+id).submit();
    }
    else
    {
        $("#errors").html(translates['fill_correctly']);
    }
}


