/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}
var http = createObject();

/* -------------------------- */
/* SAVE */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
var errmsg="";
var hiba=0;
var ures=false;
var mehet=true;
function jatek() {
//Ellenörzések
errmsg="";
hiba=0;
mehet=true;
//kepek
if(document.getElementById('q1').value.length < 2){
	hiba=1;
	document.getElementById('q1').style.border='1px solid red';
	ures=true;
	}

	if(document.getElementById('q2').value.length < 2){
	hiba=1;
	document.getElementById('q2').style.border='1px solid red';
	ures=true;
	}
	
	if(document.getElementById('q3').value.length < 2){
	hiba=1;
	document.getElementById('q3').style.border='1px solid red';
	ures=true;
	}
	if(document.getElementById('q4').value.length < 2){
	hiba=1;
	document.getElementById('q4').style.border='1px solid red';
	ures=true;
	}
	if(document.getElementById('q5').value.length < 2){
	hiba=1;
	document.getElementById('q5').style.border='1px solid red';
	ures=true;
	}
	if(document.getElementById('q6').value.length < 2){
	hiba=1;
	document.getElementById('q6').style.border='1px solid red';
	ures=true;
	}
	if(document.getElementById('q7').value.length < 2){
	hiba=1;
	document.getElementById('q7').style.border='1px solid red';
	ures=true;
	}
	if(document.getElementById('q8').value.length < 2){
	hiba=1;
	document.getElementById('q8').style.border='1px solid red';
	ures=true;
	}
	if(document.getElementById('q9').value.length < 2){
	hiba=1;
	document.getElementById('q9').style.border='1px solid red';
	ures=true;
	}
	if(document.getElementById('q10').value.length < 2){
	hiba=1;
	document.getElementById('q10').style.border='1px solid red';
	ures=true;
	}
	if(document.getElementById('q11').value.length < 2){
	hiba=1;
	document.getElementById('q11').style.border='1px solid red';
	ures=true;
	}
	if(document.getElementById('q12').value.length < 2){
	hiba=1;
	document.getElementById('q12').style.border='1px solid red';
	ures=true;
	}
	
	if (ures==true){
		$.gritter.add({
				// (string | mandatory) the heading of the notification
				title: '<font style="color:red;">HIBA! Hiányzó vagy rossz adat!</font>',
				// (string | mandatory) the text inside the notification
				text: 'Valamelyik képre nem adott választ: pirossal jelölt mező. (min. 2 kar.)',
				// (string | optional) the image to display on the left
				image: 'http://www.vilagszam.hu/images/error_game.png',
				// (bool | optional) if you want it to fade out on its own or just sit there
				sticky: true, 
				// (int | optional) the time you want it to be alive for before fading out
				time: ''
				
			});
	}

	//plus
if(document.getElementById('plone').value.length < 1){
	hiba=1;
	document.getElementById('plone').style.border='1px solid red';
		$.gritter.add({
				// (string | mandatory) the heading of the notification
				title: '<font style="color:red;">HIBA! Hiányzó vagy rossz adat!</font>',
				// (string | mandatory) the text inside the notification
				text: 'A plusz kérdést nem válaszolta meg (min. 1 kar)',
				// (string | optional) the image to display on the left
				image: 'http://www.vilagszam.hu/images/error_game.png',
				// (bool | optional) if you want it to fade out on its own or just sit there
				sticky: true, 
				// (int | optional) the time you want it to be alive for before fading out
				time: ''
				
			});
	}
	
//nev
if(document.getElementById('jtkname').value.length < 3){
	hiba=1;
	document.getElementById('jtkname').style.border='1px solid red';
		$.gritter.add({
				// (string | mandatory) the heading of the notification
				title: '<font style="color:red;">HIBA! Hiányzó vagy rossz adat!</font>',
				// (string | mandatory) the text inside the notification
				text: 'A név túl rövid/üres! Min. 3 kar.',
				// (string | optional) the image to display on the left
				image: 'http://www.vilagszam.hu/images/error_game.png',
				// (bool | optional) if you want it to fade out on its own or just sit there
				sticky: true, 
				// (int | optional) the time you want it to be alive for before fading out
				time: ''
				
			});

	}
	
//cim
if(document.getElementById('jtkcim').value.length < 3){
	hiba=1;
	document.getElementById('jtkcim').style.border='1px solid red';
		$.gritter.add({
				// (string | mandatory) the heading of the notification
				title: '<font style="color:red;">HIBA! Hiányzó vagy rossz adat!</font>',
				// (string | mandatory) the text inside the notification
				text: 'A cím túl rövid/üres! Min. 3 kar.! ',
				// (string | optional) the image to display on the left
				image: 'http://www.vilagszam.hu/images/error_game.png',
				// (bool | optional) if you want it to fade out on its own or just sit there
				sticky: true, 
				// (int | optional) the time you want it to be alive for before fading out
				time: ''
				
			});
	}

	//telefonszám
if(document.getElementById('jtktel').value.length < 6){
	hiba=1;
	document.getElementById('jtktel').style.border='1px solid red';
	$.gritter.add({
				// (string | mandatory) the heading of the notification
				title: '<font style="color:red;">HIBA! Hiányzó vagy rossz adat!</font>',
				// (string | mandatory) the text inside the notification
				text: 'A telefonszám túl rövid/üres! Min. 6 kar.! ',
				// (string | optional) the image to display on the left
				image: 'http://www.vilagszam.hu/images/error_game.png',
				// (bool | optional) if you want it to fade out on its own or just sit there
				sticky: true, 
				// (int | optional) the time you want it to be alive for before fading out
				time: ''
				
			});
	
	}
	
		
//htext
if(document.getElementById('check').checked == false){
	hiba=1;
	document.getElementById('check').style.border='1px solid red';
		$.gritter.add({
				// (string | mandatory) the heading of the notification
				title: '<font style="color:red;">HIBA! Hiányzó vagy rossz adat!</font>',
				// (string | mandatory) the text inside the notification
				text: 'El kell fogadni a játékszabáylokat és részvételi feltételeket a játékban való részvételhez! ',
				// (string | optional) the image to display on the left
				image: 'http://www.vilagszam.hu/images/error_game.png',
				// (bool | optional) if you want it to fade out on its own or just sit there
				sticky: true, 
				// (int | optional) the time you want it to be alive for before fading out
				time: ''
			});

	}
	
//mail
	function check() {
		var mail=document.getElementById('jtkemail').value;
		var i=0;
		if(mail.indexOf("@") == -1 || mail.indexOf(".") == -1){ 
		return false;
		} 
		else {
			var first = mail.split("@");
			var user = first[0];
			var second = first[1].split(".");
			var domain = second[0];
			var ending = second[1];
			if(user.length < 2 || domain.length < 2 || ending.length < 2) {
			return false;
			} else {
				return true;
			}
		}
		}
		if (check()==false){
		hiba=1;
		  document.getElementById('jtkemail').style.border='1px solid red';
		  $.gritter.add({
				// (string | mandatory) the heading of the notification
				title: '<font style="color:red;">HIBA! Hiányzó vagy rossz adat!</font>',
				// (string | mandatory) the text inside the notification
				text: 'Az e-mail túl rövid/hibás!',
				// (string | optional) the image to display on the left
				image: 'http://www.vilagszam.hu/images/error_game.png',
				// (bool | optional) if you want it to fade out on its own or just sit there
				sticky: true, 
				// (int | optional) the time you want it to be alive for before fading out
				time: ''
			});
		 }


//Ell vége
//hibák kiirása+konkluzio
if (hiba == 1){
//alert(errmsg);
}
	if(hiba == 0){
// Optional: Show a waiting message in the layer with ID ajax_response
//document.getElementById('errmsg').innerHTML = "<img class='loadimage' src='images/ajaxload.gif' /> Mentés folyamatban...";
 //értékadások 
var q1 = encodeURI(document.getElementById('q1').value);	
var q2 = encodeURI(document.getElementById('q2').value);	
var q3 = encodeURI(document.getElementById('q3').value);	
var q4 = encodeURI(document.getElementById('q4').value);	
var q5 = encodeURI(document.getElementById('q5').value);	
var q6 = encodeURI(document.getElementById('q6').value);	
var q7 = encodeURI(document.getElementById('q7').value);	
var q8 = encodeURI(document.getElementById('q8').value);	
var q9 = encodeURI(document.getElementById('q9').value);	
var q10 = encodeURI(document.getElementById('q10').value);	
var q11 = encodeURI(document.getElementById('q11').value);	
var q12 = encodeURI(document.getElementById('q12').value);	
var plone = encodeURI(document.getElementById('plone').value);
var nev = encodeURI(document.getElementById('jtkname').value);
var cim = encodeURI(document.getElementById('jtkcim').value);
var email = encodeURI(document.getElementById('jtkemail').value);
var tel = encodeURI(document.getElementById('jtktel').value);
nocache = Math.random();
// Pass the login variables like URL variable
http.open("POST", "server_game.php", true);
var params ='q1='+q1+'&q2='+q2+'&q3='+q3+'&q4='+ q4+ '&q5='+q5+'&q6='+q6+'&q7='+q7+ '&q8='+q8+'&q9='+q9+'&q10='+q10+'&q11='+q11+'&q12='+q12+'&plone='+plone+'&nev='+nev+'&cim='+cim+'&tel='+tel+'&email='+email+'&nocache='+nocache;
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(params);
http.onreadystatechange = gameReply;
	}
}
function gameReply() {
if(http.readyState == 4){
var response = http.responseText;
if(response == "failed"){
// if login fails
  $.gritter.add({
				// (string | mandatory) the heading of the notification
				title: '<font style="color:red;">Szerver oldali hiba lépett fel!</font>',
				// (string | mandatory) the text inside the notification
				text: 'Kérjük próbálja újra!',
				// (string | optional) the image to display on the left
				image: 'http://www.vilagszam.hu/images/error_game.png',
				// (bool | optional) if you want it to fade out on its own or just sit there
				sticky: true, 
				// (int | optional) the time you want it to be alive for before fading out
				time: ''
			});
// else if login is ok show a message: "Welcome + the user name".
} else if (response == "fogl") {
  $.gritter.add({
				// (string | mandatory) the heading of the notification
				title: '<font style="color:red;">Regisztrációs hiba lépett fel!</font>',
				// (string | mandatory) the text inside the notification
				text: 'Ezzel az e-mail címmel már regisztrált valaki!',
				// (string | optional) the image to display on the left
				image: 'http://www.vilagszam.hu/images/error_game.png',
				// (bool | optional) if you want it to fade out on its own or just sit there
				sticky: true, 
				// (int | optional) the time you want it to be alive for before fading out
				time: ''
			});
}
else {
  $.gritter.add({
				// (string | mandatory) the heading of the notification
				title: '<font style="color:green;">SIKERES BEKÜLDÉS!</font>',
				// (string | mandatory) the text inside the notification
				text: 'Gratulálunk, Ön sikeresen beküldte a válaszokat. Nyeremény esetén értesítjük! Köszönjük a részvételét!',
				// (string | optional) the image to display on the left
				image: 'http://www.vilagszam.hu/images/success_game.png',
				// (bool | optional) if you want it to fade out on its own or just sit there
				sticky: true, 
				// (int | optional) the time you want it to be alive for before fading out
				time: ''
			});
//document.getElementById('adminform').style.display = "none";
var t=setTimeout('location.href="index.php";',8000);
}

}
}

