$(document).ready(function(){
	window.SearchCounter = 0;
	window.BackCounter = 0;
	$(".kereso_list_bg").hide();

	showNotifyMessage();

	if ($("input[name=login_user_field]").attr("type") == "text") {
		$("input[name=login_user_field]").focus();
	}

	$(document).keyup(function(e){
		if(e.keyCode == 27){
			$(".kereso_list_bg").slideUp("fast",function(){
				$(".kereso_content .kereso_box").css("background-image","url(images/kereso_box_bg.gif)");
				$(".kereso_box").css("height","24px");
			});
		}
	});

	$(".notify_message_field").click(function(){
		$(this).hide();
	});


	$("input[name=quick_search_field]").focusin(function(){
		if($(this).val() == "Gyorskereső"){
			$(this).val("");
		}
	});

	$("input[name=quick_search_field]").focusout(function(){
		if($(this).val() == ""){
			$(this).val("Gyorskereső");
		}
	});

	$("#list_table_search").focusin(function(){
		if($(this).val() == "Termék neve"){
			$(this).val("");
		}
	});

	$("#list_table_search").focusout(function(){
		if($(this).val() == ""){
			$(this).val("Termék neve");
		}
	});

	$(".return_reason_area").focusin(function(){
		if($(this).val() == "Reklamáció pontos leírása:"){
			$(this).val("");
		}
	});

	$(".return_reason_area").focusout(function(){
		if($(this).val() == ""){
			$(this).val("Reklamáció pontos leírása:");
		}
	});

	$(".return_portfolio_area").focusin(function(){
		if($(this).val() == "Megjegyzés:"){
			$(this).val("");
		}
	});

	$(".return_portfolio_area").focusout(function(){
		if($(this).val() == ""){
			$(this).val("Megjegyzés:");
		}
	});

	$(document).keyup(function(e){
		if(e.keyCode == 191){
			$("#input_kereses").focus();
		}
	});

	$("#input_kereses").focusin(function(){
		if($(this).val() == 'Gyorskereső'){
			$(this).val('');
		}
	});

	$("#input_kereses").focusout(function(){
		if($(this).val() == '' || $(this).val() == '?'){
			$(this).val('Gyorskereső');
		}
	});

	$(".kereso_box").click(function(){
			$(".kereso_list_bg").slideUp("fast",function(){
				$(".kereso_content .kereso_box").css("background-image","url(images/kereso_box_bg.gif)");
				$(".kereso_box").css("height","24px");
			});
	});

	$(".kereso_list_bot").mouseleave(function(){
		window.SearchCounter++;
		$(".kereso_list_bg").delay(400).slideUp("fast", function(){
			$(".kereso_content .kereso_box").css("background-image","url(images/kereso_box_bg.gif)");
			$(".kereso_box").css("height","24px");
		});
	});

	$(".visszaigazolas_box").click(function(){
		$(".visszaigazolas_box").hide();
		$(".visszaigazolas_layer").show();
	});

	$(".visszaigazolas_layer_in ul").mouseleave(function(event){
		$(".visszaigazolas_layer").hide();
		$(".visszaigazolas_box").show();
	});

	$(".kosar_layer").live('click',function() {
		if (!$(".kosar_box").hasClass("empty")) {
			window.location = window.base_url+"kosar";
		}
	})

	$(".kosar_box").live('mouseover', function(){
		if (!$(".kosar_box").hasClass("empty")) {
			if(window.BackCounter % 2 == 0){
				$(".kosar_list_bg").slideToggle("fast");
				$(".kosar_content .kosar_box").css("background-image","url(images/kosar_box_bg_nyit_.gif)");
				$(".kereso_box").css("height","25px");
			}else{
				$(".kosar_list_bg").slideToggle("fast",function(){
					$(".kosar_content .kosar_box").css("background-image","url(images/kosar_box_bg_.gif)");
				});
			}
			window.BackCounter++;
		}
	});

	$(".kosar_list_bg").live('mouseleave', function(){
		$(".kosar_list_bg").slideToggle("fast",function(){
			$(".kosar_content .kosar_box").css("background-image","url(images/kosar_box_bg_.gif)");
		});
		window.BackCounter++;
	});

	$("#input_kereses").keyup(function(){
		$.ajax({
			type: "POST",
			url: "ws_modul.php?s=wk_quick_search",
			data: "strData="+$(this).val(),
			success: function(msg) {
				if(msg) {
					$(".kereso_list_bot").html(msg);
					$(".kereso_list_bg").slideDown();
				} else {
					$(".kereso_list_bot").html('');
					$(".kereso_list_bg").slideUp();
				}
			}
		});
	});
});

function domod () {
	$(".sms_request_field").modal({
		opacity:80,
		overlayCss: {backgroundColor:"#474747"},
		overlayClose:false,
		escClose:false
	});
}
/*
function AJAXHandler (url, todo, postContainer, desination, preFunction, postFunction, isSuspend) {
	var preFunctionAlertType = "openAlert";
	var functionAlertType = "openAlert";
	var preFunctionResult = true;

	url = trimData(url);
	todo = trimData(todo);
	postContainer = trimData(postContainer);
	desination = trimData(desination);
	preFunction = trimData(preFunction);
	postFunction = trimData(postFunction);

	if (url != "" || url != undefined) {
		if (isSuspend === true) {
			openDialog("", "Művelet folyamatban");
		}

		if (preFunction != "" && eval("typeof " + preFunction + " == 'function'")) {
			preFunctionResult = eval(preFunction + "();");
		}

		if (preFunction != "" && eval("typeof " + preFunction + " == 'function'") && preFunctionResult != true) {
			var rowAlertHeader = preFunctionResult.split("#SEP#");
			eval(preFunctionAlertType + "("+rowAlertHeader[0]+","+rowAlertHeader[1]+");");
		} else if (preFunctionResult === true) {
			$.ajax({
				type: "POST",
				url: url,
				async: false,
				data: $(postContainer).serialize(),
				complete: function () {
					if (isSuspend === true) {
						closeDialog();
					}
				},
				success: function (strMsg) {
					if (todo != "" || todo != undefined) {
					
						if ((postContainer != "" || postContainer != undefined) && (todo == "replace" || todo == "append") && todo != "function") {
							if (todo == "replace" && (desination != "" || desination != undefined)) {
								$(desination).html(strMsg);
							} else if (todo == "append" && (desination != "" || desination != undefined)) {
								$(desination).append(strMsg);
							}
						} else if (todo == "alert" && strMsg != "") {
							eval(functionAlertType + "("+strMsg+");");
						} else if (todo == "ack") {
							return true;
						} else if (todo == "function") {
							var rowFunctionHeader = strMsg.split("#SEP#");
							var strFunctionHeader = "";
							var numResultSize = rowFunctionHeader.length;
							var numCounter = 1;
							while (numCounter < numResultSize-1) {
								strFunctionHeader += "'"+rowFunctionHeader[numCounter] + "',";
								++numCounter;
							}

							strFunctionHeader += "'"+rowFunctionHeader[numResultSize-1]+"'";

							eval(rowFunctionHeader[0] + "(" + strFunctionHeader + ");");
						}
					}
				}
			});
			if (postFunction != "" && typeof postFunction == 'function') {
				eval(postFunction + "();");
			}
		}
	}
}
*/
function createPDF (numReturnID, strType) {
	var url = "ws_modul.php?s=wk_return_pdf&do=make_pdf";
	var strParamType = "";

	if (strType != undefined && strType != "") {
		strParamType = "&strType="+strType;
	}

	scs = false;
	fname = "";
	$.ajax({
		async: false,
		data: "numReturnID="+numReturnID+strParamType,
		type: "POST",
		url: url,
		success: function (data) {
			if (data == "") {
				scs = false;
			}else{
				fname = data;
				scs = true;
			}
		},
		complete: function() {
			if (scs == false) {
				openAlert("Hiba lépet fel a pdf elkészítése közben.");
			} else {
				dLoad = document.getElementById("frameDownload");
				dLoad.src = "ws_modul.php?s=wk_return_pdf&do=get_pdf&pdf="+fname;
			}
		}
	});
}

function checkLoginForm () {
	var strUserName = trimData($("input[name=login_user_field]").val());
	var strPassword = trimData($("input[name=login_password_field]").val());

	if (strUserName == "" || strUserName == undefined) {
		$("input[name=login_user_field]").focus();
//		showNotifyMessage("Nem adott meg bejelentkezési azonosítót!", "red");
	} else if (strPassword == "" || strPassword == undefined) {
		$("input[name=login_password_field]").focus();
//		showNotifyMessage("Nem adott meg jelszót!", "red");
	} else {
		return true;
	}
	return false;
}

function trimData (strData) {
	if(strData != undefined){
		var	str = strData.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
		while (ws.test(str.charAt(--i)));
		return str.slice(0, i + 1);
	}
}

function showNotifyMessage (strData, strColor) {
	if ($("div.notify_message_field:hidden").html() != null) {
		if (strColor != undefined && strColor.length > 0) {
			$("div.notify_message_field").css("background", strColor);
		}

		if (strData != undefined && strData.length > 0) {
			$("div.notify_message_field").html(strData);
			var numDelay = strData.length * 100;
		} else {
			var numDelay = $("div.notify_message_field").html().length * 100;
		}

		var msg = $("div.notify_message_field").html();

		if (msg != "") {
			$("div.notify_message_field").fadeIn(400);
			$("div.notify_message_field").delay(numDelay).fadeOut(1000);
		}
	}
}

function checkChangePass() {
	var strNewPass = trimData($("input[name=form_new_pass]").val());
	var strNewPassAgain = trimData($("input[name=form_new_pass_again]").val());
	var strOldPass = trimData($("input[name=form_old_pass]").val());
	
	if(strNewPass == "" || strNewPass == undefined) {
		showNotifyMessage("Új jelszavának megadása kötelező!");
		return false;
	} else if(strNewPassAgain == "" || strNewPassAgain == undefined) {
		showNotifyMessage("Adja meg új jelszavát mégegyszer!");
		return false;
	} else if(strNewPass != strNewPassAgain) {
		showNotifyMessage("A két megadott jelszava nem egyezik meg!");
		return false;
	} else if(strNewPass.length < 6) {
		showNotifyMessage("Túl rövid jelszót adott meg! Minimum 6 karakter szükséges.");
		return false;
	} else if(strOldPass == "" || strOldPass == undefined) {
		showNotifyMessage("Régi jelszavának megadása kötelező!");
		return false;
	} else {
		return true;
	}
}

function checkChangeData() {
	var strEmail = $("input[name=form_email]").val();
	var strPhone = $("input[name=form_mobil]").val();
	var strPass = $("input[name=form_data_password]").val();

	var strValidEmail = /^[\w\d._%+-]+@[\w\d.-]+\.[\w]{2,4}$/;
	var strValidPhone = /^\+\d{2} \d{2} \d{3} \d{4}$/;

	if( (strEmail != "" || strEmail == undefined) && (!strValidEmail.test(strEmail)) ) {
		showNotifyMessage("Helytelen e-mail címet adott meg!");
		return false;
	} else if( (strPhone != "" || strPhone == undefined) && (!strValidPhone.test(strPhone)) ) {
		showNotifyMessage("Helytelen telefonszámot adott meg!");
		return false;
	} else if( strPass == "" || strPass == undefined ) {
		showNotifyMessage("Nem adta meg jelenlegi jelszavát!");
		return false;
	} else {
		return true;
	}
}

function checkValidInput(numInputValue, strInputName, numAlredyUsed, isPageKosar) {
	var numberRegexp = /^\d*$/;
	if ( numAlredyUsed == undefined ) {
		numAlredyUsed = 0;
	}

	if(numInputValue != 0 || numInputValue != undefined) {
		var strInputValue = $("#"+strInputName).val();
		if(!numberRegexp.test(strInputValue) && strInputValue != "") {
			var strReturnNumberRegexp = /[1-9][0-9]*/;
			$("#"+strInputName).val(Number(strReturnNumberRegexp.exec(strInputValue)));
		} else {
//			if( Number(strInputValue) > ( Number(numInputValue) - Number(numAlredyUsed))) {
//				alert("A maximálisan felhasználható mennyiség "+( Number(numInputValue) - Number(numAlredyUsed))+" db!");
//				$("#"+strInputName).val(( Number(numInputValue) - Number(numAlredyUsed)));
//			}
			if( Number(strInputValue) >  Number(numInputValue) ) {
				alert("A maximálisan felhasználható mennyiség "+( Number(numInputValue) )+" db!");
				$("#"+strInputName).val( Number(numInputValue) );
			}
		}
	}
	
	if ( isPageKosar == undefined || isPageKosar == false ) {
		var strNumRegexp = /^\d*$/;
		if ( strNumRegexp.test(strInputValue) ) {
			if( Number(strInputValue) > ( Number(numInputValue) - Number(numAlredyUsed))) { 
				var numRes = Number(numInputValue) - Number(numAlredyUsed);
			} else {
				var numRes = Number(strInputValue);
			}
			if ( $("#"+strInputName+"_felhasznalas").val() == undefined ) {
				$("div[name=felhasznalas]").append('<input type="hidden" id="'+strInputName+'_felhasznalas" class="felhasznalas_piece" value="'+strInputValue+'" />');
			} else  {
				$("#"+strInputName+"_felhasznalas").val(strInputValue);
			}
		}
		getNeedSum();
	} else {
		count_kosar_change();
		saveBasket();
	}
}

function checkValidReturnInput(numInputValue, strInputArukod, strInputSarzs) {
	var numberRegexp = /^(0|[1-9][0-9]*)$/;

	if(numInputValue != 0 || numInputValue != undefined) {
		var strinputValue = $("#"+strInputArukod+"_"+strInputSarzs).val();
		if(!numberRegexp.test(strinputValue) && strinputValue != "") {
			var strReturnNumberRegexp = /[1-9][0-9]*/;
			$("#"+strInputArukod+"_"+strInputSarzs).val(Number(strReturnNumberRegexp.exec(strinputValue)));
		} else {
			if(strinputValue > numInputValue) {
				alert("A maximális mennyiség "+numInputValue+" db!");
				$("#"+strInputArukod+"_"+strInputSarzs).val(numInputValue);
			}
			newRequestInput('save', $("#"+strInputArukod+"_"+strInputSarzs).val(), strInputSarzs, strInputArukod, $("#"+strInputArukod+"_"+strInputSarzs+"_date").val(),$("#"+strInputArukod+"_"+strInputSarzs+"_log_id").val());
		}
	}
}

function checkValidInputNumber (strInputValue, strInputName, isPageKosar) {
	var numberRegexp = /^(0|[1-9][0-9]*)$/;
	var strReturnNumberRegexp = /[1-9][0-9]*/;
	if(!numberRegexp.test(strInputValue) && strInputValue != "") {
		$("#igeny_"+strInputName).val(Number(strReturnNumberRegexp.exec(strInputValue)));
	}

	if ( ( Number($("#igeny_"+strInputName).attr("db_value")) != Number($("#igeny_"+strInputName).val()) ) ) {
		$("#igeny_"+strInputName).addClass("yellow_bg");
	} else if ($("#igeny_"+strInputName).hasClass("yellow_bg")) {
		$("#igeny_"+strInputName).removeClass("yellow_bg");
	}

	if ( isPageKosar == undefined || isPageKosar == false ) {
		if ( $("#"+strInputName+"_keszlet").val() == undefined && numberRegexp.test(Number(strInputValue)) ) {
			$("div[name=keszlet]").append('<input type="hidden" id="'+strInputName+'_keszlet" class="keszlet_piece" value="'+Number(strInputValue)+'" />');
		} else if ( numberRegexp.test(Number(strInputValue)) ) {
			$("#"+strInputName+"_keszlet").val(Number(strInputValue));
		}
		getNeedSum();
	} else {
		count_kosar_change();
		saveBasket();
	}
}

function getBillPDF(numBillLogHeadID, strType) {
	myRef = window.open('ws_modul.php?s=wk_get_bill_pdf&id=' + numBillLogHeadID +'&type='+strType,'mywin','left=20,top=20,width=800,height=600,menubar=0,toolbar=0,scrollbars=1,location=0,directories=0,status=0');
}

function formatNumber(numVal, strSeparator) {
	if ( strSeparator == undefined ) {
		strSeparator = " ";
	}

	var strNum = numVal +"";
	var rowVal = strNum.split(".");
	var strRgx = /(\d+)(\d{3})/;
	var strNumFull = rowVal[0];

	while (strRgx.test(strNumFull)) {
		strNumFull = strNumFull.replace(strRgx, "$1" + strSeparator + "$2");
	}
	//strNumFull += ".";
	if ( rowVal[1] != "" && rowVal[1] != undefined ) {
		strNumFull += rowVal[1];
	} else {
		//strNumFull += "00";
	}

	return strNumFull;
}

function initLoadingLayer() {
	var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	var numWindowHeight = window.innerHeight;
	if (numWindowHeight==undefined) numWindowHeight=document.body.offsetHeight;
	if (numWindowHeight==undefined) numWindowHeight=document.documentElement.offsetHeight;
	var numWindowWidth = window.innerWidth;
	if (numWindowWidth==undefined) numWindowWidth=document.body.offsetWidth;
	if (numWindowWidth==undefined) numWindowWidth=document.documentElement.offsetWidth;

	if(isChrome) {
		$("#id_progress").height(getDocHeight() + 100);
	} else {
		$("#id_progress").height(getDocHeight());
	}

	$(".in_progress").css("margin-left", (numWindowWidth / 2) - 150);
	$(".in_progress").css("margin-top", (numWindowHeight / 2) - 75);
}

function getDocHeight() {
	var D = document;
	return Math.max(
		Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
		Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
		Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	);
}

function showLoadingLayer() {
	$("#id_progress").show();
	$(".in_progress").show();
}

function hideLoadingLayer() {
	$("#id_progress").hide();
	$(".in_progress").hide();
}

function number_format(number, decimals, dec_point, thousands_sep) {
	var n = !isFinite(+number) ? 0 : +number, 
		prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
		sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
		dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
		s = '',
		toFixedFix = function (n, prec) {
			var k = Math.pow(10, prec);
			return '' + Math.round(n * k) / k;
		};

	s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
	if (s[0].length > 3) {
		s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
	}
	if ((s[1] || '').length < prec) {
		s[1] = s[1] || '';
		s[1] += new Array(prec - s[1].length + 1).join('0');
	}
	return s.join(dec);
}

function openSuspend(){
	var strTitle = 'Művelet folyamatban';

	var objSuspend = $("#id_progress");
	objSuspend.html($('<div/>',{
		id: 'suspend_dialog',
		css: {
			'font-size': '1em'
		}
	}).html('<img src="images/loading.gif" alt="" style="margin-left: 80px; margin-top: 30px;"/>'));

	objSuspend.dialog({
		autoOpen: false,
		modal: true,
		title: strTitle,
		position: 'center',
		draggable: false,
		width: '350px',
		closeOnEscape: false,
		resizable: false,
		open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
	});

	objSuspend.find('.ui-button-text').css('padding', '0.1em');

	objSuspend.dialog('open');
}

function closeSuspend () {
	var objSuspend = $("#id_progress");

	objSuspend.dialog('destroy');
}

function openDialog (strTitle, strMessage) {
	if (!strTitle) {
		strTitle = '';
	}
	if (!strMessage) {
		strMessage = '';
	}

	var objDialog = $("#id_progress");
	objDialog.html(strMessage);

	objDialog.dialog({
		autoOpen: false,
		modal: true,
		title: strTitle,
		position: 'center',
		draggable: false,
		closeOnEscape: false,
		resizable: false
	});

	objDialog.dialog('open');

	$('.ui-widget-overlay').css({
		top: '0px',
		left: '0px',
		width: '100%',
		height: '100%'
	});
}

function closeDialog () {
	var objDialog = $("#id_progress");

	objDialog.dialog('destroy');
}

function openMsg(strMessage,strTitle){
	if(!strTitle) strTitle = 'Rendszerüzenet';
	if(!strMessage) strMessage = '';

	alert_dialog = $('<div/>',{
		id: 'alert_dialog',
		css: {
			'font-size': '1em'
		}
	}).html(strMessage);

	alert_dialog.dialog({
		autoOpen: false,
		modal: true,
		buttons: {Ok:function(){
			$(this).dialog('destroy');
			alert_dialog.remove();
		}},
		title: strTitle,
		position: 'center',
		draggable: false,
		width: '350px',
		closeOnEscape: false,
		resizable: false,
		open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
	});

	alert_dialog.find('.ui-button-text').css('padding', '0.1em');

	alert_dialog.dialog('open');
}

function openAlert(strMessage,strTitle,afterTrigger){
	if(!strTitle) strTitle = 'Hiba';
	if(!strMessage) strMessage = '';

	alert_dialog = $('<div/>',{
		id: 'alert_dialog',
		css: {
			'font-size': '1em'
		}
	}).html(strMessage);

	alert_dialog.dialog({
		autoOpen: false,
		modal: true,
		buttons: {Ok:function(){
			$(this).dialog('destroy');
			alert_dialog.remove();
			if(afterTrigger) afterTrigger();
		}},
		title: strTitle,
		position: 'center',
		draggable: false,
		width: '350px',
		closeOnEscape: false,
		resizable: false
	});

	alert_dialog.find('.ui-button-text').css('padding', '0.1em');

	alert_dialog.dialog('open');
}

function openConfirm (strMessage, okTrigger, cancelTrigger) {
	if(strMessage && (strMessage != '')){
		confirm_dialog = $('<div/>',{
			id: 'confirm_dialog',
			css: {
				'font-size': '1em'
			}
		}).html(strMessage);

		confirm_dialog.dialog({
			autoOpen: false,
			modal: true,
			buttons: {
				'Mégse':function(){
					$(this).dialog('destroy');
					confirm_dialog.remove();
					if(cancelTrigger != undefined && cancelTrigger) cancelTrigger();
				},
				'Ok':function(){
					$(this).dialog('destroy');
					confirm_dialog.remove();
					if(okTrigger != undefined && okTrigger) okTrigger();
				}
			},
			title: document.title,
			position: 'center',
			draggable: false,
			width: '350px',
			closeOnEscape: false,
			resizable: false
		});

		confirm_dialog.find('.ui-button-text').css('padding', '0.1em');

		confirm_dialog.dialog('open');
	}
}

function openPopup (strFunction, strTitle, isSuspend, isSecondPupup) {
	if (isSecondPupup == true) {
		var numModal = 2;
	} else {
		var numModal = 1;
	}
	if(isSuspend) openSuspend();
	resetPopup(numModal);

	if (typeof(strFunction) == "string") {
		eval(strFunction + "()");
	} else {
		strFunction();
	}

	showPopup(isSuspend, strTitle, numModal);
}

function showPopup (isSuspend, strTitle, numModal) {
	//disablePageScroll();
	$("ui-dialog.ui-widget.ui-widget-content.ui-corner-all").css("z-index", "4000");
	if ($("#modal_content_"+numModal).html() != "") {
		showPopupBg();
		$("#modal_title_"+numModal).html(strTitle);
		$("#dialog_"+numModal).jqmShow();
		setTimeout(function () {
			resizePopup(numModal);
		}, 150)
		$("#modal_content_"+numModal).show();
		if(isSuspend) closeSuspend();
	} else {
		$("#modal_content_"+numModal).hide();
		setTimeout("showPopup(" + isSuspend + ",'" + strTitle + "', " + numModal + ")", 300);
	}
}

function resetPopup (numModal) {
	$("#modal_title_"+numModal).html('');
	$("#modal_content_"+numModal).html('');
	if ($.browser.msie) {
		$("#dialog_"+numModal).css("width", "700px");
	}
	$("#dialog_"+numModal).css('margin-left', 0);
}

function resizePopup (numModal) {
	var numWidth = 0;
	numWidth = $("#modal_content_"+numModal).width();
	var numMargin = Number("-" + numWidth/2);

	$("#dialog_"+numModal).css("margin-left", numMargin+"px");
	if ($.browser.msie) {
		numDialogNewWidth = $("#modal_content_"+numModal).width();
		$.each($("#modal_content_"+numModal+" table"), function(i, e) {
			  if($(e).width() > numDialogNewWidth)
				  numDialogNewWidth = $(e).width();
		})
		$("#dialog_"+numModal).css("width", numDialogNewWidth);
	}
}

function showPopupBg () {
	$(".popup_background").css("height", $(document).height());
	$(".popup_background").show();
}

function hidePopupBg () {
	$(".popup_background").hide();
}

function closePopoup (strContainer) {
	if (strContainer == undefined || strContainer == '') {
		strContainer = "#dialog_1";
	}

	//enablePageScroll();
	$(strContainer).jqmHide();
	hidePopupBg();
}

function disablePageScroll () {
	$("body").css("overflow", "hidden");
}
function enablePageScroll () {
	$("body").css("overflow", "visible");
}

// SMS START
function openPopupSMS (strCallback, objCallbackParam) {
	if ($("#id_progress").css("display") == "none") {
		openSuspend();
	}

	$.ajax({
		  cache: false
		, type: "POST"
		, url: window.base_url+"webservice/sms"
		, data: "do=init_sms_confirm"
		, async: true
		, success: function (strResult) {
			$("#modal_content_1").html(strResult);
			showPopupBg();
			$("#modal_title_1").html("SMS hitelesítés");
			showPopupSMS();

			window.sms_callback = strCallback;
			window.sms_callback_param = objCallbackParam;
		}
	});
}

function showPopupSMS () {
	if ($("#modal_content_1").html() != "") {
		closeSuspend();

		$("#dialog_1").jqmShow();
		setTimeout( function () {
			resizePopup ("1")
		}, 150)
	} else {
		$("#dialog_1").hide();
	}
}

function checkSMSCode () {
	if ($("#id_progress").css("display") == "none") {
		openSuspend();
	}

	var SMSCodeValue = trimData($("input[name=sms_code_field]").val());

	if (SMSCodeValue != undefined && SMSCodeValue.length != 0) {
		$.ajax({
			  cache: false
			, type: "POST"
			, url: window.base_url+"webservice/sms"
			, data: "do=check_sms_code&sms_code=" + SMSCodeValue
			, async: true
			, success: function (strResult) {
				closeSuspend();

				if (strResult == "OK") {
					try {
						eval(window.sms_callback+"("+window.sms_callback_param+");");
					} catch(strError) {
						openAlert('Nem sikerült létrehozni a Callback objektumot: <br /><small>' + strError + '</small>');
					}

					window.sms_callback = null;
					window.sms_callback_param = null;

					closePopoup();
				} else {
					showNotifyMessage('Helytelen kódot adott meg.', 'red');
				}
			}
		});
	} else {
		closeSuspend();
		showNotifyMessage("Nem adott meg kódot!", "red");
	}
}
// SMS END

// DOWNLOAD START
function downloadDocument (strURL, strParam, strDownloadURL, strDownloadParam) {
	var objDownload = $("#download_document");

	if (objDownload.length == 0) {
		$("body").append("<iframe id='download_document' style='width: 0px; height: 0px; display: none;' />");
	}

	openSuspend();

	$.ajax({
		  cache: false
		, type: "POST"
		, url: window.base_url+strURL
		, async: true
		, data: strParam
		, success: function (strResult) {
			closeSuspend();
			$("#download_document").attr("src", window.base_url+strDownloadURL+strDownloadParam);
		}
	});
}

function downloadDocumentDirect (strDownloadURL, strDownloadParam) {
	var objDownload = $("#download_document");

	if (objDownload.length == 0) {
		$("body").append("<iframe id='download_document' style='width: 0px; height: 0px; display: none;' />");
	}

	$("#download_document").attr("src", window.base_url+strDownloadURL+strDownloadParam);
}
// DOWNLOAD END

// LOADING START
function openLoading (strContainer) {
	if ($(strContainer).length == 1) {
		var strHTML = "";
		$(strContainer).css('float','none');
		strHTML += "<div style='width: 100%; text-align: center; font-weight: bold; padding: 5px;'>Adatok lekérése folyamatban...</div>";
		strHTML += "<div style='width: 100%; text-align: center;'><img src='"+window.base_url+"images/loading.gif' alt='betöltés' /></div>";

		$(strContainer).html(strHTML);
	}
}
// LOADING END

function quickSearch (event) {
	if (typeof(event) == "undefined" || event.keyCode == 13) {
		window.location = window.base_url+"kereso/news/"+$("#box_search_input").val();
	}
}

