// <![CDATA[
var showwindow3=false;

function initshow3()
{
  showwindow3=false;
}


Position.GetWindowSize = function(w) {
        w = w ? w : window;
        this.width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
        this.height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
        return this;

}

	
Position.Center = function(element, parent) {
        var w, h, pw, ph;
        var d = Element.getDimensions(element);
        w = d.width;
        h = d.height;

        Position.prepare();
        if (!parent) {
                var ws = Position.GetWindowSize();
                this.pw = ws.width;
                this.ph = ws.height;
        } else {
                this.pw = parent.offsetWidth;
                this.ph = parent.offsetHeight;
        }
        
        element.style.top =  (this.ph/2) - (h/2) + Position.deltaY + "px";
        element.style.left = (this.pw/2) - (w/2) +  Position.deltaX + "px";
        return this;
}

function hideContForm()
{
new Effect.Parallel([
   Effect.Shrink('fastform',{ queue: 'end', sync: true}),
   Effect.Fade('fastform',{ queue: 'end', sync: true})
], { 
  duration: 1.4,
  delay: 0.3
});
      setTimeout(initshow3, 1700);
}

/*Event.observe(window, 'load', function() {*/
document.observe("dom:loaded", function() {
$$(".clickFastForm").invoke('observe','click',function(e){
  if (showwindow3==false)
  {
    Position.Center($('fastform'));
    Effect.Grow('fastform',{ queue: 'end', duration: 1});

    /*$("minwidth").observe('click',function(e){
      if (showwindow3==true)
      {
        hideContForm();
      }
    });*/
    showwindow3=true;
  }
       Event.stop(e);
});

/*$$(".close").invoke('observe','click',function(e){*/
$$(".close").invoke('observe','click',function(e){
 if (showwindow3==true)
 {
      hideContForm();
 }

});



var er=false;
$("submitf").observe('click',function(e){
     check();
});

$("img_captcha").observe('click',function(){
  dorefresh();
  
  		  
});


function check_error(inp,er) {
$('lb_'+inp,inp).invoke('removeClassName', 'error');
if ($(inp).getValue().length < 3)
{
   $('lb_'+inp,inp).invoke('addClassName', 'error');
   return false;
}
return er;
}

function dorefresh()
{
	new Ajax.Request('/assets/snippets/nospam/image_req.php', { method: 'POST', 
  onSuccess: function(transport) {  
  displayimg(transport.responseText);}
  });  

}

function displayimg(otvet)
{
	$('img_captcha').writeAttribute('src', otvet);
}


function check()
{
	var submission = $('vericode').getValue();
	var url = '/assets/snippets/nospam/process.php?captcha=' + submission;
	new Ajax.Request(url, { method: 'GET', 
  onComplete: function(transport) {  
  displaycheck(transport.responseText);}
  }); 
}

function displaycheck(showcheck)
{
		 er=check_error("name",true);
		 er=check_error("family",er);
		 er=check_error("themetem",er);     		 
     er=check_error("email",er);
     er=check_error("message",er);
	
		if(showcheck === "0")
		{
      $('lb_vericode','vericode').invoke('addClassName', 'error');
      dorefresh();
      er=false;
		}
		else if(showcheck === "1")
		{
		  $('lb_vericode','vericode').invoke('removeClassName', 'error');
		  if (er!=false) {
      //er=true; 
      //читаем значения введенные в поля
//var f1 = $(“field1”).value;
//var f2 = $(“field2”).value;
//формируем строку с параметрами запроса
//var pars = $H({field1:f1, field2:f2}).toQueryString();


		 	var params = $('contactform').serialize(true); 
		  var url = '/response/sendRequestContact';
		 	//alert(params);
		  new Ajax.Request(url, { method: 'POST', parameters: params,
            onSuccess: function(trans) {
            otvet=trans.responseText;
            if (otvet==1)
            {       
             Position.Center($('fastformsucces'));
             hideContForm();
             Effect.Grow('fastformsucces',{duration: 1, delay:1.7});
              new Effect.Parallel([
                 Effect.Shrink('fastformsucces',{ sync: true}),
                 Effect.Fade('fastformsucces',{ sync: true})
              ], { 
                 duration: 1.4,
                 delay: 5.5
              });
              $('img_captcha').click();

            }
            else
            {
              //$('img_captcha').click();
            }
          }
      }); 


      
      }
		}

}


});

// ]]>
