function forgot_pass(form_id)
{
	var poststr=getFormData(form_id);
	
	xmlHttpObject=getXmlHttpObject();
	xmlHttpObject.open("post", "/ForgotPassword", true ); 
	xmlHttpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
	xmlHttpObject.send(poststr);
	xmlHttpObject.onreadystatechange = function()
	{
		if (xmlHttpObject.readyState == 4)
		{
			var x=JSON.parse(xmlHttpObject.responseText);
			switch (x.answer)
			{
				case "email_with_password_sent":
					window.alert("Az új jelszót elküldtük az email címedre");
				break;
				case "account_not_active":
					window.alert("Nem aktiv a hozzáférésed. Lépj kapcsolatba velünk, ha valami hibás sejtesz emögött");
				break;
				case "user_email_not_found":
					window.alert("A felhasználónév és az email cím nem található az adatbázisban");
				break;
				default:
					window.alert("Ismeretlen hiba, próbáld újra");
					window.reload();
				break;
			}
		}
	}
}


function register(_user,_pass1,_pass2,_email,_chkbox,_bonus_code)
{
	if (document.getElementById(_pass1).value!=document.getElementById(_pass2).value)
	{
		window.alert("A jelszó és a jelszó újra nem egyezik. Kérem írja be újra!");
		document.getElementById(_pass1).focus();
		return false;
	}

	c=getCookie("reg_user");
	var data=	"user="+escape(encodeURI(document.getElementById(_user).value))+
				"&pass="+escape(encodeURI(document.getElementById(_pass1).value))+
				"&email="+escape(encodeURI( document.getElementById(_email).value))+
				"&chkbox="+escape(encodeURI( document.getElementById(_chkbox).checked))+
				"&bonus_code="+escape(encodeURI( document.getElementById(_bonus_code).value))+
				"&reg_user="+escape(encodeURI(c?c:''));

	xmlHttpObject = getXmlHttpObject();
	if (xmlHttpObject != null)
	{
		xmlHttpObject.open("post", "/Register_execute", true ); 
		xmlHttpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		xmlHttpObject.send(data);

		xmlHttpObject.onreadystatechange = function()
		{
			if(xmlHttpObject.readyState == 4)
			{
//				window.alert(xmlHttpObject.responseText);
				var answerObject=JSON.parse(xmlHttpObject.responseText);
				switch(answerObject.answer)
				{
					case 'bad_username':
						window.alert('Hibás felhasználónév. Kérlek ellenőrizd');
						document.getElementById(_user).focus();
					break;
					case 'short_password':
						window.alert('A jelszó túl rövid. Kérlek adj meg hosszabbat');
						document.getElementById(_pass1).focus();
					break;
					case 'email_not_valid':
						window.alert('Az emailcím nem megfelelő. Kérlek ellenőrizd');
						document.getElementById(_email).focus();
					break;
					case 'chkbox_must_be_filled':
						window.alert('El kell fogadnia a felhasználási feltételeket');
						document.getElementById(_chkbox).focus();
					break;
					case 'email_already_exists':
						window.alert('Az email cím már regisztrálva van. Kérem használjon másikat');
						document.getElementById(_email).focus();
					break;
					case 'username_already_exists':
						window.alert('A felhasználónév már létezik. Kérem használjon másikat');
						document.getElementById(_username).focus();
					break;
					case 'bonuscode_invalid':
						window.alert('Hibás bónuszkód');
						document.getElementById(_bonus_code).focus();
					break;
					case 'registration_successfull':
//						window.alert('Sikeres regisztráció');
//						setCookie('reg_user',document.getElementById(_user).value,5);
						window.location.href="/Regisztral/Koszonet";
					break;
					default:
						window.alert('Ismeretlen hiba :-(');
						window.location.href="/Regisztral";
					break;
				}
			}
		}
	}
}

function loadchat(div_id, model_name, room_type, status_type)
{
	xmlHttpObject = getXmlHttpObject();
	if (xmlHttpObject != null)
	{
		xmlHttpObject.open("GET", "/LoadChat/"+model_name+"/"+room_type+"/"+status_type, true);
		xmlHttpObject.send(null);
		xmlHttpObject.onreadystatechange = function()
		{
			if(xmlHttpObject.readyState == 4)
			{
				var myObject=JSON.parse(xmlHttpObject.responseText);
				switch (myObject.answer)
				{
					case 'ok':
						document.getElementById(div_id).innerHTML=myObject.text;
					break;
					case 'no_enough_funds_for_voyeur':
						window.alert("Nincs elég kredited, legalább egy percnyi kreditednek kell lennie, hogy kukkolhass");
					break;
					case 'no_enough_funds_for_private':
						window.alert("Nincs elég kredited a privát műsorhoz. Legalább fél percnyi kreditnek kell lennie, hogy privát műsorba léphess");
					break;
					case 'model_not_found':
						window.alert("Model nem található");
					break;
					default:
						window.alert("Ismeretlen hiba");
					break;
				}
			}
		}
	}
}

function apply_voucher(aa,bb,cc)
{
	a=document.getElementById(aa).value;
	b=document.getElementById(bb).value;
	c=document.getElementById(cc).value;
	xmlHttpObject = getXmlHttpObject();
	if (xmlHttpObject != null)
	{
		xmlHttpObject.open("POST", "/Kreditvasarlas/Voucher_execute", true ); 
		xmlHttpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		xmlHttpObject.send("code="+a+b+c);
	
		xmlHttpObject.onreadystatechange = function ()
		{
			if (xmlHttpObject.readyState == 4)
			{
//				window.alert(xmlHttpObject.responseText);
				var myObject=JSON.parse(xmlHttpObject.responseText);
				switch (myObject.answer)
				{
					case 'ok':
						window.alert(myObject.amount+' kreditet hozzáadtunk a számládhoz')
						window.location.href="/";
					break;
					case 'code_invalid':
						window.alert('A promo kód hibás! Kérlek ellenőrizd');
					break;
					case 'not_logged_in':
						window.alert('Nem vagy bejelentkezve');
						window.location.href="/Login";
					break;
				}
			}
		}
	}
}

var oldv=new Array(3);

function voucher_change(nr)
{
	var str=document.getElementById('voucher'+nr).value;
	
	if (is_alphanum(str))
	{
		oldv[nr]=str;
		if (nr!=3)
		{
			if (str.length==4)
			{
				nr++;
				document.getElementById('voucher'+nr).focus();
			}
		}
		else
		{
			if (str.length==4)
			{
				document.getElementById('voucher_request').focus();
			}
		}
		return true;
	}
	else
	{
		document.getElementById('voucher'+nr).value=oldv[nr];
		return false;
	}
}

function refreshIt(divID, MyPage) {
		xmlHttp = getXmlHttpObject();
		xmlHttp.onreadystatechange = function(){
				if(xmlHttp.readyState == 4) { setInnerText(divID, xmlHttp.responseText); }
		}
		xmlHttp.open("GET", MyPage, true);
		xmlHttp.send(null);
		return false;
}
function setInnerText(divID, response){
		var el = (document.getElementById) ? document.getElementById(divID) : document.all[divID];
		if(el) { el.innerHTML = response; }
}

function change_user_password(_old_pass,_new_pass1,_new_pass2)
{
	old=document.getElementById(_old_pass);
	new1=document.getElementById(_new_pass1);
	new2=document.getElementById(_new_pass2);
	if (new1.value!=new2.value)
	{
		window.alert('Az új jelszó és új jelszó újra mezők nem egyeznek!');
		new1.focus();
		return false;
	}
	
	xmlHttpObject = getXmlHttpObject();
	if (xmlHttpObject != null)
	{
		var data = "old_password="+old.value+"&new_password="+new1.value;
		xmlHttpObject.open("post", "/ChangePassword", true ); 
		xmlHttpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		xmlHttpObject.send(data);

		xmlHttpObject.onreadystatechange = function()
		{
			if(xmlHttpObject.readyState == 4)
			{
//				window.alert(xmlHttpObject.responseText);
				var aO=JSON.parse(xmlHttpObject.responseText);
				switch(aO.answer)
				{
					case 'ok':
						window.alert('A jelszó sikeresen lecserélve');
						old.value='';
						new1.value='';
						new2.value='';
						showhide("showDiv");
						return false;
					break;
					case 'old_password_wrong':
						window.alert('A régi jelszó nem megfelelő. Kérlek ellenőrizd');
						old.focus();
					break;
					
					case 'redirect_to_login':
						window.alert("Nem vagy bejelentkezve. Jelentkezz be");
						window.location.href="/Bejelentkezes";
					break;
					case 'available_for_standalone_models_only':
						window.alert('Hack attempt');
					break;
					case 'short_password':
						window.alert('A jelszó nem lehet hat karakternél rövidebb');
						new1.focus();
					break;
					default:
						window.alert('Ismeretlen hiba :(');
//						location.reload(true);
					break;
				}
			}
		}
	}
}

function refresh_model_data()
{
	xmlHttpObject = getXmlHttpObject();
	if (xmlHttpObject != null)
	{
		var url = "/StatusList";
		xmlHttpObject.open("GET", url, true);
		xmlHttpObject.send(null);

		xmlHttpObject.onreadystatechange=function()
		{
			if (xmlHttpObject.readyState==4)
			{
			var tomb = JSON.parse(xmlHttpObject.responseText);
				h=0;
				for(i in tomb.data) {
				h++;
				}
	//			window.alert(h);
				frissites=false;
					if (h!=k)
					{
					frissites=true;
					}
					else
					{
					ujlista=new Array();
						for (i=0;i<h;i++)
						{
						ujlista[tomb.data[i].id]=tomb.data[i].chat_status;
							if (tomb.data[i].chat_status != lista[tomb.data[i].id])
							{
							frissites=true;
							}
						}
						if (frissites)
						{
						document.getElementById("statusf").innerHTML = "<a href=\"#\" onclick=\"return refreshIt('status', '/OnlineModels')\">[ >Kattints ide a lista frissítéséhez< ]</a>";
						lista=ujlista;
						}
					}
				k=h;
			}
		}
	}
	setTimeout("refresh_model_data();", 3000);
}

function showhide(layer_ref)
{
	c=document.getElementById(layer_ref);
	if (c.style.display=="none")
	{
		c.style.display="block";
	}
	else
	{
		c.style.display="none";
	}
}

function layerSetup(id,visibility){
	if(document.getElementById){
	this.obj = document.getElementById(id).style;
	this.obj.visibility = visibility;
	return this.obj;
	}
		else if(document.all){
		this.obj = document.all[id].style;
		this.obj.visibility = visibility;
		return this.obj;
		}
		else if(document.layers){
		this.obj = document.layers[id];
		this.obj.visibility = visibility;
		return this.obj;
		}
}
function visVisible(param){
	new layerSetup(param,'visible');
}
function visHidden(param){
	new layerSetup(param,'hidden');
}