function zpopup_remove() {
    
    $("#zpopup_window").fadeOut("fast",function(){
        $('#zpopup_window,#zpopup_overlay').remove();
    });
    return false;
}

function zpopup_position() {
    var de = document.documentElement;
    var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
    var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;

    if (window.innerHeight && window.scrollMaxY) {
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){
        yScroll = document.body.scrollHeight;
    } else {
        yScroll = document.body.offsetHeight;
    }
    $("#zpopup_window").css({
        width:"430px",
        height:"600px",
        left: "50%",
        top: "140px",
        'margin-left': "-219px"
    });
    $("#zpopup_window_content").css({
        height:"245px"
    });
    $("#zpopup_overlay").css("height",yScroll +"px");
}

function zpopupb_click(url) {
    $("#zpopup_window,#zpopup_overlay").remove();
    $("body").append("<div id='zpopup_overlay'></div><div id='zpopup_window'></div>");
    $("#zpopup_overlay").css("opacity","0.6");
    $("#zpopup_overlay").css("filter","alpha(opacity=60)");
    $("#zpopup_overlay").css("-moz-opacity","0.6");
    $("#zpopup_overlay").click(zpopup_remove);
    $("#zpopup_overlay").show();
    $("#zpopup_window").append("<div id='zpopup_content'>\n\
    <table width='425' border='0' align='center' cellpadding='0' cellspacing='0'>\
   <tbody><tr>\
    <td colspan='3'><img src='/im/p_top.png' width='425' height='37'></td>\
  </tr>\
  <tr>\
    <td width='20' class='p_bgl'>&nbsp;</td>\
    <td width='385' class='p_bg' bgcolor='#e9eef4'>\
    <table width='100%' border='0' cellspacing='0' cellpadding='0'>\
      <tbody><tr>\
        <td align='center' class='pl13'><div align='right' style='position:absolute; z-index:+1; padding-left:335px;'><a href='#' title='Закрыть окно' id='zpopup_close'><img src='/im/ico_close.png' width='24' height='22' border='0' align='right'></a></div><h1 id='zpopup_window_title' style='padding-right:13px;'></h1></td>\
        </tr>\
      <tr>\
        <td class='p12b' id='zpopup_window_content'>\
        \
         </td>\
        </tr>\
    </tbody></table>\
    </td>\
    <td width='20' class='p_bgr'>&nbsp;</td>\
  </tr>\
  <tr>\
    <td colspan='3'><img src='/im/p_bott.png' width='425' height='37'></td>\
  </tr>\
</tbody></table></div>\n");
    $("#zpopup_close").click(zpopup_remove);

    $.ajaxSetup({
        beforeSend: function(req){
            req.setRequestHeader("X-Requested-With", 0);
        }
    });
    $.get(url, function(data) {
        $('#zpopup_window_content').html(data);
        $('#zpopup_window_title').html($('#zpopup_window_title_content').html());
        $('#zpopup_window_title_content').hide();
    })
    zpopup_position();
    $("#zpopup_window").fadeIn("normal");
    this.blur();
    setTimeout("enable_effects()", 500);
}

function get_content(url){
    $.post(url, function(data) {

        })
}

function zpopup_reopen(url){
    //$("#zpopup_window,#zpopup_overlay").remove();
    zpopupb_click(url);
}

function zpopup_alert(url){
    //$("#zpopup_window,#zpopup_overlay").remove();
    zpopupb_click(url);
    setTimeout("$('#zpopup_window, #zpopup_overlay').fadeOut('slow'); \
                ", 3000);
}

function enable_effects(){
    var default_values = new Array();
    $(".vanishing").focus(function() {
        if (!default_values[this.id]) {
            default_values[this.id] = this.value;
        }
        if (this.value == default_values[this.id]) {
            this.value = '';
        }
        $(this).blur(function() {
            if (this.value == '') {
                this.value = default_values[this.id];
            }
        });
    });
}

function send_contacts1(){
    data = {
      name: $('#name').val(),
      email: $('#email').val(),
      message: $('#message').val(),
      cv: $('#cv').val()
    }
    $.post('/contacts1/send', data);
}

function send_contacts2(){
    data = {
      name: $('#name').val(),
      email: $('#email').val(),
      message: $('#message').val()
    }
    $.post('/contacts2/send', data);
}

function send_contacts3(){
    data = {
      name: $('#name').val(),
      city: $('#city').val(),
      company: $('#company').val(),
      phone: $('#phone').val(),
      email: $('#email').val(),
      message: $('#message').val()
    }
    $.post('/contacts3/send', data);
}
