$(document).ready(function(){
	
	$("div.menu ul.menu li[id^=li_]").last().addClass("menu_last_item");
	
	$("div.menu ul.menu li[id^=li_]").hover(function () {
		$(this).children("div").fadeIn("100");
		if($(this).hasClass("menu_last_item")) {
			$("div.menu ul.menu li[id^=li_]").last().removeClass("menu_last_item");
		}
		$(this).addClass("hover");
	},
	function () {
		$(this).children("div").fadeOut("fast");
		$(this).removeClass("hover");
		$("div.menu ul.menu li[id^=li_]").last().addClass("menu_last_item");
	});
	
	//hirlevel
	$("input[name=hirlevel_nev]").focusin(function(){
		if($(this).val() == "neve"){
			$(this).val("");
		}
	});
	$("input[name=hirlevel_nev]").focusout(function(){
		if($(this).val() == ""){
			$(this).val("neve");
		}
	});

	$("input[name=hirlevel_email]").focusin(function(){
		if($(this).val() == "e-mail cime"){
			$(this).val("");
		}
	});
	$("input[name=hirlevel_email]").focusout(function(){
		if($(this).val() == ""){
			$(this).val("e-mail cime");
		}
	});

	//head_gombok
	$(".year_letters .letter").hover(function(e){
		$(this).addClass("h");
	},function(){
		if(!$(this).hasClass("a")){
			$(this).removeClass("h");
		}
	});
	
	check_input_fields();
	checkExtendedView();
});

function scrollBott(){
	$('.scroll_box_cont_fix').animate({
		scrollTop: "+=352px"
	}, 1000);
}

function scrollUp(){
	$('.scroll_box_cont_fix').animate({
		scrollTop: "-=352px"
	}, 1000);
}

function scroll_left(){
	$('.scroll_box_cont_fix').animate({
		scrollLeft: "-=472px"
	}, 500);
}

function scroll_right(){
		$('.scroll_box_cont_fix').animate({
			scrollLeft: "+=472px"
		}, 500);
}

function check_input_fields() {
	$("#id_user_login_username").focusout(function() {
		if($(this).val() == '' ) {
			$(this).val("[username]");
		}
	});
	$("#id_user_login_username").focusin(function() {
		if($(this).val() == '[username]' ) {
			$(this).val("");
		}
	});
	$("#id_user_login_password").focusout(function() {
		if($(this).val() == '' ) {
			$(this).val("[password]");
		}
	});
	$("#id_user_login_password").focusin(function() {
		if($(this).val() == '[password]' ) {
			$(this).val("");
		}
	});
}

function checkRegForm(){
	var user_name = trim($("input[name=user_full_name]").val());
	var login_name = trim($("input[name=user_login_name]").val());
	var email = trim($("input[name=user_email]").val());
	var pass_1 = trim($("input[name=user_password_1]").val());
	var pass_2 = trim($("input[name=user_password_2]").val());
	var phone = trim($("input[name=user_phone]").val());
	var ship_phone = trim($("input[name=ship_phone]").val());
	var numPartnerType = trim($("select[name=user_login_user_type]").val());
	var schoolCity = trim($("input[name=school_city]").val());
	var schoolAddr = trim($("input[name=school_address]").val());
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	var number = /^[0-9]+$/;
	
	if((numPartnerType == 78 || numPartnerType == 76 || numPartnerType == 77) && (schoolCity == '' || schoolAddr == '')){
		alert("[school_needed]!");
	}else if(numPartnerType == 0){
		alert("[chose_partner_type]!");
	}else if(!user_name){
		alert("[require_full_name]!");
	}else if(user_name.length > 60){
		alert("[too_long_name]!");
	}else if(user_name.length < 4){
		alert("[incorrect_name]!");
	}else if(!login_name){
		alert("[require_login]");
	}else if(login_name.length < 5){
		alert("[too_short_login]!");
	}else if(!email){
		alert("[require_email]!");
	}else if(!emailRegExp.test(email)) {
		alert("[incorrect_email]!");
	}else if(!phone) {
		alert("[require_phone]!");
	}else if(phone.length < 8) {
		alert("[phone_length]!");
	}else if(!checkPhoneNumber(phone)){
		alert("[phone_format]!");
	}else if ( ship_phone != '' && !checkPhoneNumber(ship_phone) ) {
		if(ship_phone.length < 8) {
			alert("[phone_length]!");
		}else if(!checkPhoneNumber(ship_phone)){
			alert("[phone_format]!");
		}
	} else if(!pass_1 || !pass_2){
		alert("[require_password]!");
	}else if( (pass_1.length != pass_2.length) || (pass_1 != pass_2) ){
		alert("[two_password_doesnt_exist]!");
	}else if(pass_1.length < 4) {
		alert("[too_short_password]!");
	}else if( !checkRegFormVarFields() ) {
		alert("[fill_out_all_marked_field]!");
	}else {
//		$("form[name=regisztracio]").submit();
		return true;
	}
	return false;
}
function getSchool(strType, isBlur) {
	var strCity = $("#school_city_select").val();
	if ( strType == "name" )  {
		var strOM = $("#school_name_select").val();
	} else {
		var strOM = $("#om_code_ac").val();
	}
	$.ajax({
		async: false,
		type: "POST",
		url: "ws_modul.php?s=get_school_data",
		data: ({
			type: strType,
			city: strCity,
			om_code: strOM
		}),
		success: function(strMsg) {
			if ((strType == 'om_code') && (!isBlur)) {
				var rowTomb = strMsg.split('CRLF');
				$("#school_name_select").html(rowTomb[1]);
				$("#school_city_hidden").val(rowTomb[2]);
				$("#school_city_select").val(rowTomb[2]);
				$("input[name=school_irsz]").val(rowTomb[3]);
				$("input[name=school_address]").val(rowTomb[4]);
				$("input[name=school_phone]").val(rowTomb[5]);
				$(".school_c").val(strCity);
				$("input[name=school_c]").val($("#school_city_select").val());
			} else if ( strType == 'city') {
				$("#school_name_select").html(strMsg);
				$("#om_code_ac").val("");
				$(".school_c").val(strCity);
				$("input[name=school_irsz]").val("");
				$("input[name=school_phone]").val("");
				$("input[name=school_address]").val("");
				$('#actdiv_om_code').find('input').val("");
				$("input[name=school_c]").val($("#school_city_select").val());
			} else {
				var rowTomb = strMsg.split('CRLF');
				$("#om_code_ac").val(rowTomb[0]);
				$('#actdiv_om_code').find('input').val(rowTomb[0]);
				$("#school_name_select").html(rowTomb[1]);
				$("#school_city_hidden").val(rowTomb[2]);
				$("#school_city_select").val(rowTomb[2]);
				$("input[name=school_irsz]").val(rowTomb[3]);
				$("input[name=school_address]").val(rowTomb[4]);
				$("input[name=school_phone]").val(rowTomb[5]);
				$(".school_c").val(strCity);
				$("input[name=school_c]").val($("#school_city_select").val());
			}
		}
	}); 
}
function checkRegFormVarFields(numPartnerType) {
	if ( numPartnerType == undefined ) {
		numPartnerType = $("select[name=user_login_user_type]").val();
	}
	var isFilled = true;
	switch (numPartnerType) {
		case'40':
			$(".check_pay").each(function(){
				if( $(this).val() == '' || trim($(this).val()) == '' )  {
					isFilled = false;
				}
			});
		break;
		case '77':
			$(".check_teacher").each(function(){
				if( $(this).val() == '' || trim($(this).val()) == '' )  {
					isFilled = false;
				}
			});
		break;
		case '78':
			$(".check_student, .check_pay").each(function(){
				if( $(this).val() == '' || trim($(this).val()) == '' )  {
					isFilled = false;
				}
			});
		break;
		case '232':
			$(".check_ship, .check_pay").each(function(){
				if( $(this).val() == '' || trim($(this).val()) == '' )  {
					isFilled = false;
				}
			});
		break;
	}
	return isFilled;
}

function checkChangeForm(){
	var user_name = trim($("input[name=user_full_name]").val());
	var login_name = trim($("input[name=user_login_name]").val());
	var email = trim($("input[name=user_email]").val());
	var pass_1 = trim($("input[name=user_password_1]").val());
	var pass_2 = trim($("input[name=user_password_2]").val());
	var phone = trim($("input[name=user_phone]").val());
	var ship_phone = trim($("input[name=ship_phone]").val());
	var oldpass = $("input[name=old_password]").val();
	
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	
//	var phoneRegExp = /^[+]?[0-9 \\\/\-]{7,15}$/;
//	var mobilRegExp = /^[0-9\-]{9}$/;
	
	if(!user_name){
		alert("[did_not_enter_the_full_name]");
		return false;
	}else if(user_name.length > 60){
		alert("[too_long_a_name_for_it]");
		return false;
	}else if(!email){
		alert("[did_not_enter_an_e-mail_address]");
		return false;
	}else if(!emailRegExp.test(email)){
		alert("[wrong_e-mail_address_in]");
		return false;
	}else if(!phone){
		alert("[phone_number_is_required]");
	}else if(phone.length < 8) {
		alert("[phone_length]!");
	}else if(!checkPhoneNumber(phone)){
		alert("[gave_an_incorrect_phone_number]\n" +
		"[example]: +36 / 55 333-444");
	}else if(ship_phone.length > 0 && !checkPhoneNumber(ship_phone)){
		alert("[gave_an_incorrect_phone_number]\n" +
		"[example]: +36 / 55 333-444");
	}else if(pass_1 || pass_2) {
		if( (pass_1.length != pass_2.length) || (pass_1 != pass_2)){
			alert("[the_two_passwords_do_not_match]");
		}else if(pass_1.length < 4 && pass_1.length > 0){
			alert("[the_password_is_too_short]");
		}else if(!oldpass){
			alert("[you_did_not_enter_the_old_password]");
		}else{
			$("form[name=adatmodositas]").submit();
		}
	}else if(!checkRegFormVarFields($("#id_user_type").val())) {
		alert("[fill_out_all_marked_field]!");
	}else if(!oldpass){
		alert("[you_did_not_enter_the_old_password]");
	}else if( !checkRegFormVarFields($("#user_visibility_type").val()) ) {
		alert("[fill_out_all_marked_field]!");
	}else{
		$("form[name=adatmodositas]").submit();
	}
}

function checkFeedbackForm(){
	var title = trim($("select[name=feedback_title]").val());
	var body = trim($("textarea[name=feedback]").val());
	if(!title){
		alert("[require_feedback_title]!");
	}else if(!body){
		alert("[require_feedback_note]!");
	}else{
//		$("form[name=visszajelzes]").submit();
		return true;
	}
	return false;
}

function bookReqCheck(){
	var note = trim($("textarea[name=teacher_req_note]").val());
	
	if(!note){
		alert("[teach_req_field_note]");
	}else{
		$("form[name=teacher_req]").submit();
	}
}

function checkLoginForm() {
	var name = trim($("input[name=user_login_username]").val());
	var password = trim($("input[name=user_login_password]").val());
	
	
	if(name == "" || name == undefined || name == "[username]") {
		alert("[require_username]!");
		return false;
	} else if(password == "" || password == undefined || name == "[password]"){
		alert("[require_password]!");
		return false;
	} else {
		return true;
		$("form[name=login_form]").submit();
	}
}

function hirlevel_form() {
	var username = $("input[name=hirlevel_nev]").val();
	var email = $("input[name=hirlevel_email]").val();
	var level = $("input[name=hirlevel_feltetel]").val();
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	
	if(!username || username == 'neve') {
		alert("[require_username]!");
	} else if(!email || email == 'e-mail cime') {
		alert("[require_email]!");
	} else if(!emailRegExp.test(email)) {
		alert("[incorrect_email]!");
	} else {
		$("form[name=form_hirlevel]").submit();
	}
}

function addBasket(id){
	$(".head_box_head a").each(function(){
		$(this).removeClass("akt_box");
	});
	$(".head_box_search").css("display","none");
	$(".head_box_login").css("display","none");
	$(".head_box_basket").css("display","block");
	$(".head_basket").addClass("akt_box");
	if(id != 0) {
		$.ajax({
			type: "POST",
			url: "ws_modul.php?s=basket",
			data: "do=add&id="+id,
			success: function(msg){
				var tmp = msg.split("CRLF");
				$(".head_box_basket").html(tmp[1]);
				$("#basket_count_id").html(tmp[0]);
			}
		});		
	}
}

function addFavor(id, partnerid, action){
	if(id != 0 && partnerid != 0) {
		$.ajax({
			type: "POST",
			url: "ws_modul.php?s=favor",
			data: "do="+action+"&id="+id+"&partner="+partnerid,
			success: function(msg){
				msg = msg.replace('favor','');
				if(msg.length > 0){
					alert(msg);
				}
				window.location.reload();
			}
		});		
	}
}

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

function checkLostPassForm(){
	var email = trim($("input[name=user_email]").val());
	
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	if(!email){
		alert("[did_not_enter_an_e-mail_address]");
	}else if(!emailRegExp.test(email)){
		alert("[wrong_e-mail_address_in]");
	}else{
//		$("form[name=jelszo_emlekezteteto]").submit();
		return true;
	}
	return false;
}

function checkOrderForm(){
	var identical = $("#shiping_checkbox").attr("checked");
	var ship_name = trim($("input[name=ship_name]").val());
	var ship_zip = trim($("input[name=ship_irsz]").val());
	var ship_city = trim($("input[name=ship_city]").val());
	var ship_address = trim($("input[name=ship_address]").val());
	var pay_name = trim($("input[name=pay_name]").val());
	var pay_zip = trim($("input[name=pay_irsz]").val());
	var pay_city = trim($("input[name=pay_city]").val());
	var pay_address = trim($("input[name=pay_address]").val());
	var ship_phone = trim($("input[name=ship_phone]").val());
	var user_id = trim($("#hiddenuserid").val());
	var school_om = trim($("#school_id").val());
	var ptype = trim($("#ptype").val());
	var strData = '';
	
	$.ajax({
		async: false,
		type: "POST",
		url: "ws_modul.php?s=get_user_school",
		data: ({
			id: user_id
		}),
		success: function (returnStr){
			if(returnStr == 'ERROR')
				strData = "ERROR";
			else
				strData = returnStr; 
		}
	});
	if(strData == "ERROR" && ( ptype != 40 && ptype != 232 )){
		openConfirmGotoEditProfile2();
		return false;
		
	} else {
		if( (identical && pay_name && pay_zip && pay_city && pay_address/* && ship_phone*/) || (!identical && pay_name && pay_zip && pay_city && pay_address &&
																				ship_name && ship_zip && ship_city && ship_address && ship_phone) ) {
			if(identical && (pay_name.length==0 || pay_zip.length==0 || pay_city.length==0 || pay_address.length==0/* || ship_phone.length==0*/)){
				alert("[all_fields_are_required]");
			}else if(!identical && (pay_name.length==0 || pay_zip.length==0 || pay_city.length==0 || pay_address.length==0 ||
									ship_name.length==0 || ship_zip.length==0 || ship_city.length==0 || ship_address.length==0 || ship_phone.length==0) ){
				alert("[all_fields_are_required]");
			}else{	
				return true;
				//alert("[unknown_error]");
				//return false;
			}
			
		}else{
			alert("[all_fields_are_required]");
		}
		return false;
	}
}

/*function checkSchoolFilled(user_id){
	$.ajax({
		async: false,
		type: "POST",
		url: "ws_modul.php?s=get_user_school",
		data: ({
			id: user_id
		}),
		success: function (strData)  {
			if(strData == 'ERROR')
				return 0;
			else
				return strData;
		}
	});
}*/

function checkPhoneNumber(nStr){
	var phoneRegExp = /^[+]?[0-9 \\\/\-]{7,15}$/;
	var mobilRegExp = /^[0-9\-]{9}$/;
	
	if (phoneRegExp.test(nStr) || mobilRegExp.test(nStr)) {
		return true;
	} else {
		return false;		
	}
}

$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
while(x<c.length){var m=r.exec(c.substr(x));
  if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
  }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
  o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});


function get_course_filter(strCoursePage) {
	window.location = strCoursePage;
}
function toggleDownloadableContent (strType, numRowID) {
	$("#downloadable_content_"+strType+"_"+numRowID).toggle()	
}
function checkExtendedView () {
	setTimeout( function() {
		var strHash = window.location.hash;
		if ( strHash != '' ) {
			strHash = strHash.substr(1);
			var rowHash = strHash.split('#');
			var strOperation = rowHash[0];
			var rowAllowedOperations = ['comments','table_of_content','related_books','video','sample_page','item_demonstration'];
			
			if ( $.inArray(strOperation, rowAllowedOperations) >= 0 ) {
				var strGetView = /\/view\/\d*\//;
				var strView = strGetView.exec(window.location.pathname)+'';
				var rowTmp = strView.split('/');
				var numItemID = rowTmp[2];
				if ( strOperation == 'comments' ) {
					$("div.extended_description").hide();
					$("div.extended_linkage").hide();
				} else {
					$("div.extended_description").show();
					$("div.extended_linkage").show();
				} 
				$.ajax({
					async: false,
					type: "POST",
					url: "ws_modul.php?s=get_extended_view_content",
					data: ({
						item_id: numItemID,
						operation: strOperation
					}),
					success: function (strData)  {
						$("div.extended_view_dynamic_content").html(strData);
						var objPosition = $('#extended_view_dynamic_content_div').offset();
					    window.scrollTo(objPosition.left,objPosition.top+800);
					}
				});
			}
		}
	}, 100); 
}
function changeVideo(numVideoID) {
	setTimeout( function() {
		var strHash = window.location.hash;
		if ( strHash != '' ) {
			strHash = strHash.substr(1);
			var rowHash = strHash.split('#');
			var strOperation = rowHash[0];
			var rowAllowedOperations = ['comments','table_of_content','related_books','video','sample_page','item_demonstration'];
			
			if ( $.inArray(strOperation, rowAllowedOperations) >= 0 ) {
				var strGetView = /\/view\/\d*\//;
				var strView = strGetView.exec(window.location.pathname)+'';
				var rowTmp = strView.split('/');
				var numItemID = rowTmp[2];
				if ( strOperation == 'comments' ) {
					$("div.extended_description").hide();
					$("div.extended_linkage").hide();
				} else {
					$("div.extended_description").show();
					$("div.extended_linkage").show();
				} 
				$.ajax({
					async: false,
					type: "POST",
					url: "ws_modul.php?s=get_extended_view_content",
					data: ({
						item_id: numItemID
						,operation: strOperation
						,video_id: numVideoID
					}),
					success: function (strData)  {
						$("div.extended_view_dynamic_content").html(strData);
					}
				});
			}
		}
	}, 100); 
}
function changeItemDemo(numDemoID) {
	setTimeout( function() {
		var strHash = window.location.hash;
		if ( strHash != '' ) {
			strHash = strHash.substr(1);
			var rowHash = strHash.split('#');
			var strOperation = rowHash[0];
			var rowAllowedOperations = ['comments','table_of_content','related_books','video','sample_page','item_demonstration'];
			
			if ( $.inArray(strOperation, rowAllowedOperations) >= 0 ) {
				var strGetView = /\/view\/\d*\//;
				var strView = strGetView.exec(window.location.pathname)+'';
				var rowTmp = strView.split('/');
				var numItemID = rowTmp[2];
				if ( strOperation == 'comments' ) {
					$("div.extended_description").hide();
					$("div.extended_linkage").hide();
				} else {
					$("div.extended_description").show();
					$("div.extended_linkage").show();
				} 
				$.ajax({
					async: false,
					type: "POST",
					url: "ws_modul.php?s=get_extended_view_content",
					data: ({
						item_id: numItemID
						,operation: strOperation
						,demo_id: numDemoID
					}),
					success: function (strData)  {
						$("div.extended_view_dynamic_content").html(strData);
					}
				});
			}
		}
	}, 100); 
}
function addItemComment(numItemID) {
	var strComment = $("#new_comment").val();
	strComment = strComment.replace(/\s/,"") + '';
	if ( strComment.length > 0 ) {
		$.ajax({
			async: false,
			type: "POST",
			url: "ws_modul.php?s=get_extended_view_content",
			data: ({
				item_id: numItemID,
				operation: 'new_comment',
				comment: strComment
			}),
			success: function (strData)  {
				$("div.extended_view_dynamic_content").html(strData);
			}
		});
	}
}
function getCommentPage(numItemID, numPage) {
	var strComment = $("#new_comment").val();
	$.ajax({
		async: false,
		type: "POST",
		url: "ws_modul.php?s=get_extended_view_content",
		data: ({
			item_id: numItemID,
			operation: 'show_comment_page',
			page: numPage
		}),
		success: function (strData)  {
			$("div.extended_view_dynamic_content").html(strData);
			$("#new_comment").val(strComment);
		}
	});
}
function getTableOfContents(numItemID) {
	
	openDialog("[preparing_printing_please_wait]");
	
	var isScs = true;
	$.ajax({
		async: false,
		type: "GET",
		url: "ws_modul.php?s=table_of_contents&todo=make&item_id="+numItemID,
		success: function (data) {
			if (data != "OK") {
				isScs = false;
			}
		},
		complete: function() {
			if (isScs == false) {
				alert("[error_in_the_spleen_during_the_preparation_pdf]");
			} else {
				dLoad = document.getElementById("frameDownload");
				dLoad.src = "ws_modul.php?s=table_of_contents&todo=get";
			}
			closeDialog();
		}
	});
}
function openDialog(strMessage){
	if(!strMessage) strMessage = '';

	id = 'print_pdf_dialog';
	
	web_dialog = $('<div/>',{
		id: id,
		css: {
			'font-size': '1em'
		}
	}).html(strMessage);
	
	web_dialog.dialog({
		autoOpen: false,
		dialogClass: id,
		modal: true,
		title: '',
		position: 'center',
		draggable: false,
		closeOnEscape: false,
		resizable: false
	});
	
	$('.'+id).css('background-image','none');

	$('.'+id).find('.ui-dialog-titlebar').hide();
	
	web_dialog.dialog('open');

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

}
function closeDialog(id){
	id = 'print_pdf_dialog';
	$('#'+id).dialog('destroy');
	$('#'+id).remove();
}
function checkNumber(obj,numMax) {
	var strVal = obj.val();
	var strNumberRegexp = /^(0|[1-9]\d*)$/;
	if ( !strNumberRegexp.test(strVal) ) {
		strVal = strVal.replace(/\D/g,'');
		var strExecRegexp = /[1-9]\d*/;
		var strNumber = strExecRegexp.exec(strVal);
		if ( numMax != undefined && Number(numMax) < Number(strNumber) ) {
			obj.val(Number(numMax)); 
		} else {
			obj.val(Number(strNumber));			
		}
	} else if ( numMax != undefined && Number(numMax) < Number(strVal) ) {
		obj.val(Number(numMax)); 
	}
}
function checkPhoneNumberTeacherReq(obj) {
	var strVal = obj.val();
	var phoneRegExp = /^[+]?[0-9 \\\/\-]{7,15}$/;
	var mobilRegExp = /^[0-9\-]{9}$/;
	
	if (!(phoneRegExp.test(strVal)) && !(mobilRegExp.test(strVal))) {

		alert("[gave_an_incorrect_phone_number]\n" +
		"[example]: \n" +
		"+36/62 333-444\n"+
		"+36/20 333-4444\n");
	}
}
function initAllAvailableBooks() {
	var numRowID = 1;
	$("div.request_book_list div.request_book_list_row").each(function(){
		checkMaxAvailableBooks(numRowID++);
	});
	$("div.request_book_list input.number").each(function(){
		$(this).keyup(function(){
			if ( $(this).hasClass("request_piece") ) {
				var strID = $(this).attr("id");
				var rowTmp = strID.split("_");
				var numRowID = rowTmp[rowTmp.length-1];
				checkNumber($(this),getMaxAvailableBooks(numRowID));
				setTimeout(setTeacherToRequest(numRowID,$("#"+$(this).attr("id")).val()),100);
			} else {
				checkNumber($(this));
			}
		});
	});
	$("textarea.teacher_request").each(function(){
//		$(this).keyup(function(){
//			saveTeacherRequestData();
//		});
		$(this).blur(function(){
			saveTeacherRequestData();
		});
	});
	$("input.teacher_request").each(function(){
//		$(this).keyup(function(){
//			saveTeacherRequestData();
//		});
		$(this).blur(function(){
			saveTeacherRequestData();
		});
	});
	$("select.teacher_request").each(function(){
		$(this).change(function(){
			saveTeacherRequestData();
			checkTeacherRequestBooks();
		});
	});
}
function checkMaxAvailableBooks(numRowID) {
	var strReplace = "[required_number_of_free_copies]:";
	var numMax = getMaxAvailableBooks(numRowID);
	$("#maximum_orderable_"+numRowID).html(strReplace.replace("#number#",numMax));
}
function getMaxAvailableBooks(numRowID) {
	var strNumMax = /max#\d*/.exec($("#request_book_select_"+numRowID).find("option[value="+$("#request_book_select_"+numRowID).val()+"]").attr("class"))+'';
	var rowTmp = strNumMax.split('#'); 
	var numMax = Number(rowTmp[1]);
	return numMax;
}
function setTeacherToRequest(numRowID,numTeachers) {
	var rowTeachers = new Array();
	var numCount = 1;
	$("#teacher_name_list_"+numRowID+" input.teacher_name").each(function(){
		rowTeachers[numCount++] = $(this).val();
	});
	var strToSet = '';
	for ( i = 1; i <= numTeachers; i++ ) {
		strToSet += '	<div class="left_field">';
		strToSet += '		'+i+'. [teacher_name]:';
		strToSet += '	</div>';
		strToSet += '	<div class="right_field">';
		strToSet += '		<div class="input_bg">';
		strToSet += '			<input class="teacher_name teacher_request" name="pgs_request_field[items]['+numRowID+'][teachers]['+i+']" type="text" value="'+( ( rowTeachers[i] != undefined ) ? rowTeachers[i] : '' )+'" />';
		strToSet += '		</div>';
		strToSet += '	</div>';
		strToSet += '	<div class="clear"></div>';
	}
	$("#teacher_name_list_"+numRowID).html(strToSet);
	$("#teacher_name_list_"+numRowID+" input.teacher_name").each(function(){
		$(this).keyup(function(){
			saveTeacherRequestData();
		});
		$(this).blur(function(){
			saveTeacherRequestData();
		});
	});
}
function saveTeacherRequestData() {
	$.ajax({
		async: false
		,type: "POST"
		,url: "ws_modul.php?s=teacherBookRequest"
		,data: $(".teacher_request").serialize()+"&pgs_do=save_session"
	});
}
function checkTeacherRequestBooks() {
	openDialog("[operation_in_progress]");
	$.ajax({
		async: false
		,type: "POST"
		,url: "ws_modul.php?s=teacherBookRequest"
		,data: $(".teacher_request").serialize()+"&pgs_do=book_check"
		,success: function (strData) {
			if ( strData != '' ) {
				$("div.request_book_list").html(strData);
			}
		}
		,complete: function () {
			closeDialog();
		}
	});
	initAllAvailableBooks();
}
function checkTeacherBookRequestForm() {
	var strPhoneNumber = $("#teacher_request_phone_number").val();
	var strNumberRegexp = /^(00|\+\d{2}|\d{2})(\s[\/\-\\])?\d{1,2}(\d{2}(\s[\/\-\\])?\d{2}(\s[\/\-\\])?\d{2,3}|\d{3}(\s[\/\-\\])?\d{3,4})$/;
	var strTextbookResponsible = $("#teacher_request_textbook_responsible").val();
	var strDistributor = $("#teacher_request_distributor").val();
	var strNameCheckRegexp = /^[A-ZÍÁÉŐÚŰÓÜÖa-zíöüűóúőéá\ \.\-\,]*$/;	
	if ( !strNumberRegexp.test(strPhoneNumber) ) {
		alert("[gave_an_incorrect_phone_number]");
	} else if ( strDistributor.replace(/\s/g,'') + '' == '' ) {
		alert("[fill_out_distributor]");
	} else if ( strTextbookResponsible.replace(/\s/g,'') + '' == '' ) {
		alert("[fill_out_textbook_responsible]");
	} else if ( !strNameCheckRegexp.test(strDistributor) || !strNameCheckRegexp.test(strTextbookResponsible) ) {
		alert("[name_can_only_contain]");
	} else  {
		var strAllItemValid = '';
		$("div.request_book_list div.request_book_list_row").each(function(){
			var strID = $(this).attr("id");
			var rowTmp = strID.split("_");
			var numID = rowTmp[rowTmp.length-1];
			var strTmp = checkTeacherBookRequestItem(numID);
			if ( strTmp != '' && ( strAllItemValid == 'OK' || strAllItemValid == '' ) ) {
				strAllItemValid = strTmp;
			}
		});
		if ( strAllItemValid != 'OK' && strAllItemValid != '' ) {
			alert(strAllItemValid);
		} else if ( strAllItemValid == '' ) {
			alert('[fill_out_at_least_one_item]');
		} else if ( strAllItemValid == 'OK' ) {
			openDialog("[operation_in_progress]");
			$.ajax({
				async: false
				,type: "POST"
				,url: "ws_modul.php?s=teacherBookRequest"
				,data: $(".teacher_request").serialize()+"&pgs_do=save_form"
				,success: function (strData) {
					var rowTmp = strData.split("#");
					if ( rowTmp[0] == 'ERROR' ) {
						$("#order_result").html("<h4>[unsuccesful_teacher_req_please_try_again]</h4>");
					} else {
						window.location.reload();
					}
				}
				,complete: function () {
					closeDialog();
				}
			});
		}
	}
}
function checkTeacherBookRequestItem(numRowID) {
	var strValidText = '';
	if ( $("#request_book_select_"+numRowID).val() != 0 ) {
		var numRequestPiece = $("#request_book_piece_"+numRowID).val();
		var numFieldNames = 0;
		var strNameCheckRegexp = /^[A-ZÍÁÉŐÚŰÓÜÖa-zíöüűóúőéá\ \.\-\,]*$/;
		if ( Number(numRequestPiece) > 0 ) {
			$("#teacher_name_list_"+numRowID).find("input.teacher_name").each(function(){
				if ( strNameCheckRegexp.test($(this).val()) && strValidText == '' && $(this).val().replace(/\s/g,'') != '' ) {					
					numFieldNames++;
				} else if ( $(this).val().replace(/\s/g,'') != '' ) {
					strValidText = '[name_can_only_contain]';
				}
			});
			if ( numFieldNames != numRequestPiece && strValidText == '' ) {
				strValidText = '[not_all_names_are_given]';
			} else if ( strValidText == '' ) {
				strValidText = 'OK';
			}
		} else {
			strValidText = '[requested_piece_is_null]';
		}
	}
	return strValidText;
}
function slideTeacherRequest(numID) {
	$("#slide"+numID).slideToggle("slow");
}
function getTeacherBookRequestPDF (numRequestID) {
	openDialog("[preparing_printing_please_wait]");
	var isScs = true;
	$.ajax({
		async: false,
		type: "POST",
		url: "ws_modul.php?s=generate_teacher_request_pdf&do=generate&id="+numRequestID,
		success: function (strData) {
			console.log(strData);
			if ( strData == "DB ERROR" ) {
				isScs = false;
			}
		},
		complete: function() {
			if (isScs == false) {
				alert("[error_in_the_spleen_during_the_preparation_pdf]");
			} else {
				dLoad = document.getElementById("frameDownload");
				dLoad.src = "ws_modul.php?s=generate_teacher_request_pdf&do=dl";
			}
		}
	});
	closeDialog();
}

function openConfirmGotoEditProfile(){
	confirm_dialog = $('<div>',{
		id : 'confirm_dialog',
		css: {
			'font-size': '1em',
			'background-color': '#FFFFFF',
		}
	}).html("[unable_to_order_without_school]<br/>[want_to_edit_now]?");

	confirm_dialog.dialog({
		autoOpen: false,
		modal: true,
		buttons: {
			'[cancel]':function(){
				$(this).dialog('destroy');
				confirm_dialog.remove();
				return false;
			},
			'OK':function(){
				$(this).dialog('destroy');
				confirm_dialog.remove();
				window.location = "change_account";
			}
		},
		title: document.title,
		position: 'center',
		draggable: false,
		width: '400px',
		closeOnEscape: false,
		resizable: false
	});
	
	confirm_dialog.find('.ui-button-text').css('padding', '0.1em');
	
	confirm_dialog.dialog('open');
	
}

function openConfirmGotoEditProfile2(){
	confirm_dialog = $('<div>',{
		id : 'confirm_dialog',
		css: {
			'font-size': '1em',
			'background-color': '#FFFFFF',
		}
	}).html("[school_needed]<br/>[want_to_edit_now]?");

	confirm_dialog.dialog({
		autoOpen: false,
		modal: true,
		buttons: {
			'[cancel]':function(){
				$(this).dialog('destroy');
				confirm_dialog.remove();
				//return false;
			},
			'OK':function(){
				$(this).dialog('destroy');
				confirm_dialog.remove();
				window.location = "change_account";
			}
		},
		title: document.title,
		position: 'center',
		draggable: false,
		width: '400px',
		closeOnEscape: false,
		resizable: false
	});
	
	confirm_dialog.find('.ui-button-text').css('padding', '0.1em');
	
	confirm_dialog.dialog('open');
	
}
