﻿$(document).ready(function () {
							$(".getaccess").click(function () {
								if ($("#ftpreg").css('display') == 'none' ) {
									$("#ftpreg").css({display:"block"})
									$("#ftpreg").animate({ opacity: "1.0", top: "-=175", left: "+=210" }, 500)
									return false;
								} else {return false;}
							});
							$(".ftpregclose").click(function () {					
								$("#ftpreg").animate({ opacity: "0"}, 250)
								window.setTimeout(
									function () { $("#ftpreg").css({display:"none", top: "410px", left: "90px", opacity: "0"}) }, 251 )
								return false;
							});
							$(".ftpregsend").click(function () {
								if ($("input[name='regtxt_comp']").val() == '' || $("input[name='regtxt_name']").val() == '' || $("input[name='regtxt_phone']").val() == '' || $("input[name='regtxt_mail']").val() == '') {
									alert('Заполните все поля!');
								} else {
									var req = new XMLHttpRequest();
									if (req == undefined) {
									  req = function() {
										try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
										  catch(e) {}
										try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
										  catch(e) {}
										try { return new ActiveXObject("Msxml2.XMLHTTP"); }
										  catch(e) {}
										try { return new ActiveXObject("Microsoft.XMLHTTP"); }
										  catch(e) {}
										throw new Error("This browser does not support XMLHttpRequest.");
									  }
									}
									var params = 'comp=' + encodeURIComponent($("input[name='regtxt_comp']").val()) + '&name=' + encodeURIComponent($("input[name='regtxt_name']").val());
									params += '&phone=' + encodeURIComponent($("input[name='regtxt_phone']").val()) + '&mail=' + encodeURIComponent($("input[name='regtxt_mail']").val());
									req.open("POST", "templates/artpohod/send_access.php", true);
									req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
									req.send(params);
									$(".ftpregsps").css({display: "block"});
									req.onreadystatechange = function () {
									try {
									    if (req.readyState == 4) {
											//alert(req.status);
											if (req.status == 200) {
												//alert(req.responseText);
												//if (req.responseText != 'isok') {alert(req.responseText);} else  { alert('ok'); }
												window.setTimeout(
													function () { $("#ftpreg").animate({ opacity: "0"}, 1000) }, 1000 );
												window.setTimeout(
													function () { 
														$("#ftpreg").css({display:"none", top: "410px", left: "90px", opacity: "0"}) 
														$(".ftpregsps").css({display: "none"});
														$("input[name='regtxt_comp']").val('');
														$("input[name='regtxt_name']").val('');
														$("input[name='regtxt_phone']").val('');
														$("input[name='regtxt_mail']").val('');
													}, 2001 );
												return false;
											}
										}
									} catch(e) { alert(e); }
									}
								}
							})
});