var rand=Math.round(Math.random()*1000+1);
var j=0;
var mat = -1;

function windowMotion(dir) {
	(mat==1) ? mat=-1 : mat=1;
	if (dir==5) dir=mat;
	var i=0;
	var timer=window.setInterval(function() {
		i+=10*dir;
		if (Math.abs(i)<200) {
			document.getElementById('window1').style.top = document.getElementById('window1').offsetTop+10*dir+'px';
		} else {
			window.clearInterval(timer);
			if (dir==1) {
				j++;
				document.getElementById('buttonMini').className="buttonMini miniUp";
				document.getElementById('link').innerHTML='Закрыть панель';
				document.getElementById('buttonMini').onclick=document.getElementById('link').onclick=function anonymouse() { windowMotion(-1) }; 
			} else {
				j--;
				document.getElementById('buttonMini').className="buttonMini miniDown";
				document.getElementById('link').innerHTML='Задать вопрос';
				document.getElementById('buttonMini').onclick=document.getElementById('link').onclick=function anonymouse() { windowMotion(1) }; 
			}
		}
	}, 10);
	return false;
}  

function checkStepOne() {
	(document.getElementById('name').value==""||document.getElementById('quest').value=="") ? document.getElementById('send').className="send inactive" : document.getElementById('send').className="send active";
	return false;
}

function makeRequestObject() {
	var http_request = false;
	if (window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return http_request;
}

function makeRequest(reqObj, url, functionName) {
    reqObj.onreadystatechange = functionName;
    reqObj.open('GET', url, true);
	reqObj.send(null);
	return false;
}

function requestSend() {
	var req = makeRequestObject();
	var link = 'http://ictorg.ru/cgi-bin/bin/public/faq/send.cgi?question='+document.getElementById('quest').value+'&name='+document.getElementById('name').value+'&rand='+(Math.round(Math.random()*1000+1)+rand++); 
	makeRequest(req, link, function () { clear(req); });
	return false;
}

function clear(obj) {
	if (obj.readyState == 4) {
        if (obj.status == 200) {
			document.getElementById('quest').innerHTML="";
			document.getElementById('name').value="";
			document.getElementById('send').className="send inactive";
			windowMotion(5);
		} else alert('Ошибка соединения! Проверьте Ваше соединение и повторите попытку.');
	} else document.getElementById('send').className="send inactive";
	return false;
}
