var div_quest;
var xmlHTTP;
var div_thanks;
var sel_name;
var sel_email;
var sel_msg;
var page;

function quest_init() {
	div_quest = document.getElementById('quest');
	xmlHTTP = init_ajax();
	div_thanks= document.getElementById('thanks');
	sel_name = document.getElementById('qname');
	sel_email = document.getElementById('qemail');
	sel_msg = document.getElementById('qmsg');
	page = document.getElementById('page');
}

function doQuest() {
	var height = window.innerHeight || document.body.clientHeight;
	var width = window.innerWidth || document.body.clientWidth; 
	
//	div_shadow.style.display = 'block';
	div_quest.style.display = 'block';
	if(!(document.all && document.all.item)) {
	div_quest.style.top = ( height / 2 - 200) + 'px'; 
	div_quest.style.left = ( width / 2 - 250) + 'px';
	div_thanks.style.top = ( height / 2 - 200) + 'px'; 
	div_thanks.style.left = ( width / 2 - 250) + 'px';
	}
}

function doExit() {
	div_quest.style.display = 'none';
}

function doSend() {
	var url = "/ajax/quest.php?cmd=quest";
	var poststr = "name=" + encodeURI(sel_name.value) + "&e-mail=" + encodeURI(sel_email.value) + "&msg=" + encodeURI(sel_msg.value) + "&page=" + encodeURI(page.value); 
 
	xmlHTTP.onreadystatechange = ajax_response;
	xmlHTTP.open("POST",url,true);
	xmlHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHTTP.setRequestHeader("Content-length", poststr.length);
	xmlHTTP.setRequestHeader("Connection", "Close"); 
	xmlHTTP.send(poststr);
	
}

function ajax_response() {
	if(xmlHTTP.readyState == 4 && xmlHTTP.status == 200) {
		//alert(xmlHTTP.responseText); 
		div_thanks.style.display = 'block';
		setTimeout('div_thanks.style.display = "none";div_quest.style.display = "none";',1000);
	}
}


function init_ajax() {
	var ajax;
	if(window.XMLHttpRequest) ajax = new XMLHttpRequest();
	else {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e1) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e2) {
				xmlHttp = null;
			}
		}
	}
	if(ajax) return ajax;
	else alert("Ajax is not enabled");
}


