//<![CDATA[
	var fade_mail = { // Namespace
	ids	: {},
	step	: 0.08,
	delay	: 1, // ms
	timer	: null,
	setOpacity : function(elem, nOpacity) {
		if (typeof elem == 'string') elem = document.getElementById(elem);
		var props = ['MozOpacity', 'KhtmlOpacity', 'opacity'];
		for (var i in props) {
			if (typeof elem.style[props[i]] == 'string') {
				elem.style[props[i]] = nOpacity;
				return;
			}
		}
		// IE 6+
		try {
			nOpacity = 100 * parseFloat(nOpacity);
			if ((oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha)) oAlpha.opacity = nOpacity;
			else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+");";
		} catch (e) {
			// IE <= 5.5 OR Opera < 9 OR another browser. Do nothing
		}
	},
	_out : function(id, from, to, callback) {
		from -= this.step;
		from = from <= to ? to : from;
		if (this.doit(id, from, to, callback)) 
			this.timer = setTimeout("fade_mail._out('"+id+"', "+from+", "+to+", '"+(callback ? callback : '')+"')", this.delay);
	},
	_in : function(id, from, to, callback) {
		from += this.step;
		from = from >= to ? to : from;
		if (this.doit(id, from, to, callback)) 
			this.timer = setTimeout("fade_mail._in('"+id+"', "+from+", "+to+", '"+(callback ? callback : '')+"')", this.delay);
	},
	doit : function(id, from, to, callback) {
		this.setOpacity(id, from);
		clearTimeout(this.timer);
		if (from == to) {
			if (callback) eval(callback+'()');
		} else return true;
	}
}
//]]>

var mailValid = "true";

function mail_in(topScroll){
	if(mail_bg.style.width == '1px'){
		mail_bg.style.width = '100%';
		mail_bg.style.height = '1480px';
		mail_bg.style.display = '';

		mail.style.top = topScroll+'px';
		mail.style.left = '50%';

		fade_mail._in('mail', 0, 1.0);
	}
}




function mail_close(){
	fade_mail._out('mail', 1.0, 0, 'mail_close_2');
}
function mail_close_2(){
	mail_bg.style.width = '1px';
	mail_bg.style.height = '1px';
	mail_bg.style.display = 'none';

	mail.style.top = '0px';
}



var request;
var dest;

function processStateChange(){
	if (request.readyState == 4){
		contentDiv = document.getElementById(dest);
		if (request.status == 200){
			response = request.responseText;
			contentDiv.innerHTML = response;
		}
	}
}

function send_mail(){
if(message.send_result.value != "Ваше письмо отправлено") {
send_valid();

var NAME = message.user_name.value;
var TEL = message.user_tel.value;
var MAIL = message.user_mail.value;
var TEXT = message.user_text.value;

var URL = "/html/message.php";
var destination = "send_result";
  dest = destination;
  if(window.XMLHttpRequest){
    request = new XMLHttpRequest();
    request.onreadystatechange = processStateChange;
    request.open("POST", URL, true);
    request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
    request.send("user_name="+NAME+"&user_tel="+TEL+"&user_mail="+MAIL+"&user_text="+TEXT);
  }
}
}

function mail_clear(){

}

function send_valid(){
	if(message.send_result.value == "Ваше письмо отправлено") {
		mailValid = "false";
		clearTimeout(TTV);
		setTimeout("mail_close();",2000);
		setTimeout("mail_clear();",60000);
	}else{
		var TTV = setTimeout("send_valid()",2000);
	}
}

function mail_clear(){
	message.user_name.value = "";
	message.user_tel.value = "";
	message.user_mail.value = "";
	message.user_text.value = "";
	message.send_result.value = "";
}
