/* JS */

var ageFalse = 9999;
var MailOK = false;
var DontGo = true;

function Get(id) {
	return document.getElementById(id);
}

function ButtonVis() {
	pattern = /\d+/;
	if (document.xForm.Kandydat.value == 9999) {
		var KandydatError = true;
	} else {
		var KandydatError = false;
	}
	if (!pattern.test(document.xForm.Wiek.value) || document.xForm.Sex.value == 9999 || document.xForm.Education.value == 9999 || KandydatError || document.xForm.Partia.value == 9999) {
		Get("Dalej").style.visibility = "hidden";
	} else {
		Get("Dalej").style.visibility = "visible";
	}
} // ButtonVis


function ageTest() {
	var years = document.xForm.Wiek.value;
	pattern = /\d+/;
	if (pattern.test(years)) {
		document.getElementById("ageInf").style.display = "none";
		if (years<18) {
			document.getElementById("ageInf").innerHTML = 'W badaniu mog± brać udział jedynie osoby, które ukończyły 18 lat.';
			document.getElementById("ageInf").style.display = "block";
		}
	} else {
		document.getElementById("ageInf").innerHTML = 'Dopuszczalne warto¶ci: od 1 do 99.';
		document.getElementById("ageInf").style.display = "block";
	}
} // document

function OnSubmitForm() {
	pattern = /\d+/;
	if (document.xForm.Zdecydowanie.value == 1 && document.xForm.Kandydat.value == 9999) {
		var KandydatError = true;
	} else {
		var KandydatError = false;
	}
	if (!pattern.test(document.xForm.Wiek.value) || document.xForm.Sex.value == 9999 || document.xForm.Education.value == 9999 || document.xForm.Zdecydowanie.value == 9999 || KandydatError || document.xForm.Partia.value == 9999) {
		document.getElementById("ageInf").innerHTML = 'Prosimy o uzupełnienie danych.';
		document.getElementById("ageInf").style.display = "block";
		return false;
	} else {
		return true;
	}
}

function NextStage(id) {
	document.getElementById('Part_'+id).style.display = 'none';
	document.getElementById('Part_'+(id+1)).style.display = 'block';
}



function GetxmlHttpObject() {
	if (window.XMLHttpRequest) {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	  
	if (window.ActiveXObject) {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
} // GetxmlHttpObject


function EmailSave() {
	xmlHttp = GetxmlHttpObject();
	if (xmlHttp == null) { alert ("Browser does not support HTTP Request"); return; }
	
	var PostValue = 'Email='+Get('id_Email').value+'&LastID='+Get('id_LastID').value;
	
	var url = "_SaveEmail.php";
	
		xmlHttp.onreadystatechange = function () {
				if (xmlHttp.readyState == 4) {
					Ramka = Get('id_EmailField_Info');
					if (xmlHttp.responseText == 'Dziękujemy') {
						Get('id_EmailField').style.display = 'none';
						Ramka.className = 'MiniOK';
					} else {
						Ramka.className = 'MiniError';
					}
					Ramka.style.display = 'block';
					Ramka.innerHTML = xmlHttp.responseText;
				}
			}
	xmlHttp.open("POST",url,true);
//	xmlHttp.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", PostValue.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(PostValue);
} // UpdateSingleField

