
window.defaultAlertFuntion = window.alert;

window.defaultAlert = function(message, fn){
	defaultAlertFuntion(message);
	if(fn != undefined){
		eval(fn);
	}
}
window.alert = function(message, fn){
	$.modal(str_replace(message, "\n", '<br/>'), {'onClose':fn});
	$('#simplemodal-container').css('height', ($('#simplemodal-data').height()) + 'px').css('width', ($('#simplemodal-data').width()) + 'px');
}

function str_replace(miben, mit, mire){
	return miben.toString().split(mit).join(mire);
}


var isNN = (navigator.appName.indexOf("Netscape") != -1);

function OnEnter(e, functionName){	
	var keyCode = (isNN) ? e.which : e.keyCode;
	if(keyCode == 13){
		if(e.keyCode == 13){
			if(functionName != ''){
				eval(functionName);
			}
		}
	}
}

function Register(){
	var emailCim = $('#email').val();
	$.post(
		'/!/regisztracio.php',
		{email:emailCim},
		function(html){
			var res = html.split(';');
			if(res[0] == 'error'){
				alert(res[1]);
			}else{
				alert('Köszönjük!', "document.location.href='/';");
			}
		}
	);
}

function FinishRegister(type){
	$.post(
		'/!/finishregisztracio.php',
		{pw1:$('#pw1').val(), pw2:$('#pw2').val(), accept:$('#accept').attr('checked')},
		function(html){
			var res = html.split(';');
			if(res[0] == 'error'){
				alert(res[1]);
			}else{
				if(type==0){
					alert('Köszönjük!', "document.location.href='" + res[1] + "';");
				}else{
					alert('Köszönjük!', "document.location.href='/adatok_modositasa/'");
				}
			}
		}
	);
}

function Login(){
	$.post(
		'/!/login.php',
		{email:$('#name').val(), pw:$('#pw').val()},
		function(html){
			var res = html.split(';');
			if(res[0] == 'error'){
				alert(res[1]);
			}else{				
				document.location.href='/';
			}
		}
	);
}

function Logout(){
	$.post(
		'/!/logout.php',
		{1:1},
		function(html){
			document.location.href='/';			
		}
	);
}

function LostPass(){
	var emailCim = $('#email').val();
	$.post(
			'/!/lostPass.php',
			{email:emailCim},
			function(html){
				var res = html.split(';');
				if(res[0] == 'error'){
					alert(res[1]);
				}else{
					alert('Köszönjük!', "document.location.href='/';");
				}
			}
		);
}

function FinishNewPass(){	
	$.post(
			'/!/newPass.php',
			{oldpw:$('#oldpw').val(), pw1:$('#pw1').val(), pw2:$('#pw2').val()},
			function(html){
				var res = html.split(';');
				if(res[0] == 'error'){
					alert(res[1]);
				}else{
					alert('Köszönjük!', "document.location.href='/';");
				}
			}
		);
}

function FinishNewEmail(){
	$.post(
			'/!/newEmail.php',
			{newemail:$('#newemail').val(), pw:$('#pw').val()},
			function(html){
				var res = html.split(';');
				if(res[0] == 'error'){
					alert(res[1]);
				}else{
					alert('Köszönjük!', "document.location.href='/';");
				}
			}
		);
}

function finishEditDatas(){
	$.post(
			'/!/editDatas.php',
			{
				name:$('#name').val(),
				birth_year:$('#birth_year').val(),
				birth_month:$('#birth_month').val(),
				birth_day:$('#birth_day').val(),
				zipid:$('#zipid').val(),
				gender:$("input[@name='gender']:checked").val(),
				phone:$('#phone').val(),
				'post_address[country]':$('#post_address_country').val(),
				'post_address[zip]':$('#post_address_zip').val(),
				'post_address[city]':$('#post_address_city').val(),
				'post_address[address]':$('#post_address_address').val(),
				'billing_address[name]':$('#billing_address_name').val(),
				'billing_address[country]':$('#billing_address_country').val(),
				'billing_address[zip]':$('#billing_address_zip').val(),
				'billing_address[city]':$('#billing_address_city').val(),
				'billing_address[address]':$('#billing_address_address').val()
			},
			function(html){
				var res = html.split(';');
				if(res[0] == 'error'){
					alert(res[1]);
				}else{
					alert('Sikeresen módosítottad az adataidat!', "document.location.href='/';");
				}
			}
		);
}

function zipPress(zip){
	$.post('/@/zipCheck.php', {zip:zip}, function(html){$('#zipcode').html(html)});
}
function keyfilter_Digit(event) {
	keyfilter(function(c) {return (c >= 48 && c <= 57) || c==13},event);
}
function keyfilter(filter, event) {
	if (!event) event=window.event;
	var c=getCharCode(event);
	if (c && !filter(c)) cancelEvent(event);
}

function getCharCode(event) {
	return typeof(event.charCode)=="undefined" ? (event.keyCode || event.which) : event.charCode;
}
	
function cancelEvent(event) {
	if (!event) event=window.event;
	if (event.preventDefault) event.preventDefault();
	else event.returnValue=false;
}
