function send_xmlhttprequest(obsluha, method, url, content, headers) {
	var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));

	if (!xmlhttp)
		return false;

	xmlhttp.open(method, url);

	if (obsluha != null)
		xmlhttp.onreadystatechange = function() {
			obsluha(xmlhttp);
		};

	if (headers) {
		for (var key in headers)
			xmlhttp.setRequestHeader(key, headers[key]);
	}

	xmlhttp.send(content);
	return true;
}

function open_popup(dokument, sirka, vyska, scrollbars) {
	so = screen.width;
	vo = screen.height;
	zleva = ((so - sirka) / 2) - 13;
	shora = 120;
	popup_win = window.open(dokument,"popup_okno","width="+sirka+",height="+vyska+",left="+zleva+",top="+shora+",location=0,resizable=1,scrollbars="+scrollbars+",status=0,toolbar=0");
	popup_win.focus();
}

function Show(id, show) {
  if (show)
    document.getElementById(id).style.visibility='visible';
  else
    document.getElementById(id).style.visibility='hidden';
}

function virtual_prod_r(xmlhttp) {
	if (xmlhttp.readyState == 4) {
		document.getElementById('dark_bg').style.display = 'block';
		document.getElementById('matwindow').style.display = 'block';
		document.getElementById('matwindow_in').style.display = 'block';
		document.getElementById('matwindow_in').innerHTML = xmlhttp.responseText;

        reg = /^.*MSIE 6.*$/;
        if (reg.test(navigator.appVersion)) {
            var sel = document.body.getElementsByTagName("SELECT");
            for (var i = 0; i < sel.length; i++)
                sel[i].style.visibility = "hidden";
        }
	}
}

function virtual_prod() {
	if (!send_xmlhttprequest(virtual_prod_r, 'GET', '/virt_prod.php')) {
		return true;
	}

	return false;
}

function close_matwindow() {
	var obj = document.getElementById('matwindow');
    var obj2 = document.getElementById('matwindow_in');
    var obj3 = document.getElementById('dark_bg');

	if (obj) {
		obj2.innerHTML = '';
		obj.style.display = 'none';
		obj2.style.display = 'none';
	}

	if (obj3)
		obj3.style.display = 'none';

    reg = /^.*MSIE 6.*$/;
    if (reg.test(navigator.appVersion)) {
        var sel = document.body.getElementsByTagName("SELECT");
        for (var i = 0; i < sel.length; i++)
            sel[i].style.visibility = "visible";
    }
}


function sendForm( form ) {
	myform = form;
	var max = form.elements.length;
	var buffer = new Array();
	var headers = new Array();

	headers['Content-type'] = 'application/x-www-form-urlencoded';

	for (var i = 0; i < max; i++) {
			buffer.push(form.elements[i].name + '=' + encodeURIComponent(form.elements[i].value));
	}

	if (!send_xmlhttprequest(sendForm_r, 'POST', '/send_order_form.php', buffer.join('&'), headers)) {
		return true;
	}

	return false;
}

function sendForm_r(xmlhttp) {
	if (xmlhttp.readyState == 4) {
		var obj = document.getElementById('id_message');
		
		if(obj) {
			obj.innerHTML = xmlhttp.responseXML.getElementsByTagName('message')[0].firstChild.data;
			var result = parseInt(xmlhttp.responseXML.getElementsByTagName('result')[0].firstChild.data);
			if (result) {
				obj.className = "good_message";
				var obj2 = document.getElementById('id_order_form_content');
				if (obj2) {
					obj2.style.display = "none";
				}
			} else {
				obj.className = "bad_message";
			}
		}  
	}
}


