$(document).ready(function(){
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
	

	// MENU POS START
	var numMenuWidth = 0;
	$(".main_menu ul li").each(function(){
		var numTmpWidht = 0;
		$("ul.sub_menu_" + $(this).attr('id')).each(function() {
			numTmpWidht += $(this).width();
		});

		if( (numTmpWidht + numMenuWidth) > 950 )
			$("ul.sub_menu_" + $(this).attr('id')).css("margin-left", 950 - numTmpWidht);
		else
			$("ul.sub_menu_" + $(this).attr('id')).css("margin-left", numMenuWidth - 10);

		if($(this).hasClass('active')) {
			showActiveMenu($(this).attr('id'));
		}
		numMenuWidth += $(this).outerWidth();
	});
	// MENU POS END
	
	//INPUT FIELD START
	$(".login_box input[name=eusername]").focusin(function(){
		if($(this).val() == 'Felhasználónév')
			$(this).val('');
	});
	$(".login_box input[name=eusername]").focusout(function(){
		if($(this).val() == '')
			$(this).val('Felhasználónév');
	});
	$(".login_box input[name=epassword]").focusin(function(){
		if($(this).val() == 'Jelszó')
			$(this).val('');
	});
	$(".login_box input[name=epassword]").focusout(function(){
		if($(this).val() == '')
			$(this).val('Jelszó');
	});
	//INPUT FIELD STOP

	$(".top_menu_content").mouseleave(function(){
		showActiveMenuCallback();
	});

	manageMSQFormHeader();
});


function manageMSQFormHeader(strSide) {
	setTimeout("manageMSQFormHeaderLoader()", 100);
	if(strSide != undefined) {
		$(".msq_head_ul li").hide();
	}
}

function manageMSQFormHeaderLoader () {
	var numCounter = 0;
	var tmpCounter = 0;
	$(".msq_head_ul li").removeClass("med_active");

	$(".msq_head_ul li").each(function () {
		if($(this).hasClass("active")) {
			tmpCounter = numCounter - 1;
			$(".msq_head_ul li#msq_head_" + tmpCounter).addClass("med_active");
			tmpCounter = numCounter + 1;
			$(".msq_head_ul li#msq_head_" + tmpCounter).addClass("med_active");
			tmpCounter = 0;
		}
		++numCounter;
	});
	$(".msq_head_ul li.active").fadeIn();
	$(".msq_head_ul li.med_active").fadeIn();
}

function showActiveMenu( numMenuID ) {
	$(".top_menu_content .sub_menu ul").each(function() {
		$(this).hide();
	});

	$(".top_menu_content .main_menu ul li").each(function(){
		if($(this).hasClass("active")) {
			$(this).addClass("evitca");
			$(this).removeClass("active");
		}
	});
	$(".top_menu_content .main_menu ul li").removeClass("hover");
	$(".top_menu_content .main_menu ul li.main_menu_" + numMenuID).addClass("hover");
	$(".top_menu_content .sub_menu ul.sub_menu_" + numMenuID).fadeIn();
}

function hideActiveMenu() {
	$(".top_menu_content .sub_menu ul").each(function() {
		$(this).hide();
	});
}

function showActiveMenuCallback() {
	$(".top_menu_content .sub_menu ul").each(function() {
		$(this).hide();
	});

	$(".top_menu_content .main_menu ul li").removeClass("hover");

	$(".top_menu_content .main_menu ul li").each(function(){
		var numMenuID = $(this).attr('id');
		if($(this).hasClass("evitca")) {
			$(this).addClass("active");
			$(this).removeClass("evitca");
			$(".top_menu_content .sub_menu ul.sub_menu_" + numMenuID).fadeIn();
		} else if($(this).hasClass("active")) {
			$(".top_menu_content .sub_menu ul.sub_menu_" + numMenuID).fadeIn();
		}
	});
}

function showNotifyMessage (strData, isRed) {
	if ( $("div.notify_message_field:hidden").html() != null ) {
		if ( isRed != undefined && isRed == true )
			$("div.notify_message_field").addClass("red_bg_notify");

		if (strData != undefined)
			$("div.notify_message_field").html(strData);

		if( strData != undefined )
			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);
			if ( isRed != undefined && isRed == true ) {
				setTimeout('$("div.notify_message_field").removeClass("red_bg_notify");',(numDelay+2000));
			}
		}
	}
}

function checkItem() {
	if ($("#non_teva_usage_t").attr("checked")) {
		$("#non_teva_item_list").show();
		$(".non_teva_item_add_button").show();
	} else {
		$("#non_teva_item_list").hide();
		$(".non_teva_item_add_button").hide();
	}

	checkPage6();
}

function checkEmailStr (strEmail) {
	var strEmailRegexp = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/;
	strEmailRegexp.lastIndex = 0;

	return strEmailRegexp.test(strEmail);
}

function checkNameStr (strName) {
	var strNameRegexp = /^(\w|[óÓűŰüÜöÖéÉáÁíÍúÚőŐ]|\s|[.,-])*$/;
	//var strNameRegexp = new RegExp("^(\w|[óÓűŰüÜöÖéÉáÁíÍúÚőŐ]|\s|[.,-])*$");
	strNameRegexp.lastIndex = 0;

	return strNameRegexp.test(strName);
}

function checkMegnevNameStr (strName) {
	var strNameRegexp = /^(\w|[óÓűŰüÜöÖéÉáÁíÍúÚőŐ]|\s|[.,\/+-])*$/;
	strNameRegexp.lastIndex = 0;

	return strNameRegexp.test(strName);
}

function checkPage1 () {
	if (!$("#want_to_fill").attr("checked") && !$("#want_to_fill_cont").hasClass("not_valid")) {
		$("#want_to_fill_cont").addClass("not_valid");
	} else if ($("#want_to_fill").attr("checked") && $("#want_to_fill_cont").hasClass("not_valid")) {
		$("#want_to_fill_cont").removeClass("not_valid");
	}

	if (!$("#asker_email_address_cont").hasClass("not_valid") && !checkEmailStr($("#asker_email_address").val())) {
		$("#asker_email_address_cont").addClass("not_valid");
	} else if ($("#asker_email_address_cont").hasClass("not_valid") && checkEmailStr($("#asker_email_address").val())) {
		$("#asker_email_address_cont").removeClass("not_valid");
	}
	
	if (!$("#asker_phone_number_cont").hasClass("not_valid") && !checkPhoneNumber($("#asker_phone_number").val()) && $("#asker_phone_number").val() != '') {
		$("#asker_phone_number_cont").addClass("not_valid");
	} else if ($("#asker_phone_number_cont").hasClass("not_valid") && (checkPhoneNumber($("#asker_phone_number").val()) || $("#asker_phone_number").val() == '')) {
		$("#asker_phone_number_cont").removeClass("not_valid");
	}

	if ($("#want_to_fill").attr("checked") && checkEmailStr($("#asker_email_address").val()) && (checkPhoneNumber($("#asker_phone_number").val()) || $("#asker_phone_number").val() == '')) {
		$("#wizard_nav_button_next").show();
		return true;
	} else {
		$("#wizard_nav_button_next").hide();
		return false;
	}
}

function checkPage2 () {
	var isValid = true;
	$(".page_2_fill").each(function () {
		var strID = $(this).attr("id");
			if (!$("#"+strID+"cont").hasClass("not_valid")) {
			$("#"+strID+"_cont").addClass("not_valid");
		}
		
		if ($(this).val().replace(/\s*/g, "") == "") {
			isValid = false;
		} else if ($(this).hasClass("name") && (!checkNameStr($(this).val()) || $(this).val().length < 2)) {
			isValid = false;
		} else if ($("#"+strID+"_cont").hasClass("not_valid")) {
			$("#"+strID+"_cont").removeClass("not_valid");
		}
	});
	$(".page_2_fill_hcw").each(function () {
		var strID = $(this).attr("id");
		if (!$("#"+strID+"_cont").hasClass("not_valid")) {
			$("#"+strID+"_cont").addClass("not_valid");
		}
		if ($(this).val() !='' && $(this).hasClass("name") && ($(this).val().length < 2 || !checkNameStr($(this).val()))) {
			isValid = false;
		} else if ($(this).hasClass("email")) {
			if($(this).val()!=''){
				var isValidEmail = checkEmailStr($(this).val());
					if (isValid) {
					isValid = isValidEmail;
				}
			}
			if ((isValidEmail || $(this).val()=='') && $("#"+strID+"_cont").hasClass("not_valid")) {
				$("#"+strID+"_cont").removeClass("not_valid");
			}
		} else if ($(this).hasClass("phone")) {
			if($(this).val()!=''){
				var isValidPhone = checkPhoneNumber($(this).val());
					if (isValid) {
					isValid = isValidPhone;
				}
			}		
			if ((isValidPhone || $(this).val()=='') && $("#"+strID+"_cont").hasClass("not_valid")) {
				$("#"+strID+"_cont").removeClass("not_valid");
			}
		} else if ($("#"+strID+"_cont").hasClass("not_valid")) {
			$("#"+strID+"_cont").removeClass("not_valid");
		}
	});
	if (isValid) {
		$("#wizard_nav_button_next").show();
		return true;
	} else {
		$("#wizard_nav_button_next").hide();
		return false;
	}
}

function checkPage3 () {
	var isValid = true;

	$(".side_effect_table").each(function () {
		var strTableID = $(this).attr("id");
		var rowTmp = strTableID.split("_"); 
		var numTableID = rowTmp[2];

		$(this).find(".page_3_fill").each(function () {
			var strID = $(this).attr("id");

			if (!$("#"+strID+"_cont").hasClass("not_valid")) {
				$("#"+strID+"_cont").addClass("not_valid");
			}

			if ($(this).val().replace(/\s/g,"") == "") {
				isValid = false;
			} else if ($(this).hasClass("name") && !checkMegnevNameStr($(this).val())) {
				isValid = false;
			} else if ($("#"+strID+"_cont").hasClass("not_valid")) {
				$("#"+strID+"_cont").removeClass("not_valid");
			}
		});

		if (
			$("#side_effect_is_over_"+numTableID+"_t").attr("checked")
			&& $("#side_effect_end_date_"+numTableID).val() == ""
		) {
			isValid = false;

			if (!$("#side_effect_end_date_"+numTableID+"_cont").hasClass("not_valid")) {
				$("#side_effect_end_date_"+numTableID+"_cont").addClass("not_valid");
			}
		} else if ($("#side_effect_end_date_"+numTableID+"_cont").hasClass("not_valid")) {
			$("#side_effect_end_date_"+numTableID+"_cont").removeClass("not_valid");
		}
	});

	if (isValid) {
		$("#wizard_nav_button_next").show();
		return true;
	} else {
		$("#wizard_nav_button_next").hide();
		return false;
	}
}

function checkPage4 () {
	var isValid = true;
	if ($("#serious_yes_radio").attr("checked")){
		isValid = false;
		$.each($('.container_param .page_4_fill_serious_category'), function(i,e) { 
			   if($(e).attr("checked")){
				   isValid = true;
			   }
		});
	} 
	if (isValid) {
		if ($("#serious_category_cont").hasClass("not_valid")) {
			$("#serious_category_cont").removeClass("not_valid");
		}
		$("#wizard_nav_button_next").show();
		return true;
	} else {
		if (!$("#serious_category_cont").hasClass("not_valid")) {
			$("#serious_category_cont").addClass("not_valid");
		}
		$("#wizard_nav_button_next").hide();
		return false;
	}
}

function checkPage5 () {
	var isValid = true;
	var strArukodRegexp = /^\d{13}$/;
	strArukodRegexp.lastIndex = 0;

	$(".teva_item").each(function () {
		$(this).find(".page_5_fill").each(function () {
			var strID = $(this).attr("id");
			if (!$("#"+strID+"_cont").hasClass("not_valid")) {
				$("#"+strID+"_cont").addClass("not_valid");
			}

			if ($(this).val().replace(/\s/g,"") == "") {
				isValid = false;
			} else if ($("#"+strID+"_cont").hasClass("not_valid")) {
				$("#"+strID+"_cont").removeClass("not_valid");
			}
						
			if ($(this).hasClass("arukod")) {
				var isValidArukod = strArukodRegexp.test($(this).val());
				if (isValid) {
					isValid = isValidArukod; 
				}

				var rowTmp = strID.split('_');
				var numRowID = rowTmp[2];

				if (!isValidArukod && !$("#id_item_"+numRowID+"_input_cont").hasClass("not_valid")) {
					$("#id_item_"+numRowID+"_input_cont").addClass("not_valid");
				} else if (
					isValidArukod && $("#id_item_"+numRowID+"_input_cont").hasClass("not_valid")
					&& $("#id_item_"+numRowID+"_input").val().replace(/\s/g,"") != ""
				) {
					$("#id_item_"+numRowID+"_input_cont").removeClass("not_valid");
				}
			}
		});
	});

	if (isValid) {
		$("#wizard_nav_button_next").show();
		return true;
	} else {
		$("#wizard_nav_button_next").hide();
		return false;
	}
}

function checkPage6 () {
	var isValid = true;

	if ($("#non_teva_usage_t").attr("checked")) {
		$(".medicine_item").each(function () {
			$(this).find(".page_6_fill").each(function () {
				var strID = $(this).attr("id");
				if (!$("#"+strID+"_cont").hasClass("not_valid")) {
					$("#"+strID+"_cont").addClass("not_valid");
				}

				if ($(this).val().replace(/\s/g,"") == "") {
					isValid = false;
				} else if ($(this).hasClass("name") &&  !checkMegnevNameStr($(this).val())) {
					isValid = false;
				} else if ($("#"+strID+"_cont").hasClass("not_valid")) {
					$("#"+strID+"_cont").removeClass("not_valid");
				}
			});
		});
	} else if ($("#non_teva_usage_f").attr("checked")) {
		isValid = true;
	} else {
		isValid = false;
	}
	if (isValid) {
		$("#wizard_nav_button_next").show();
		return true;
	} else {
		$("#wizard_nav_button_next").hide();
		return false;
	}
}

function checkQuestionariPage( numPageID ) {
	var isValidPage = true;
	switch(numPageID) {
		case 0:
			isValidPage = checkPage1();
		break;
		case 1:
			isValidPage = checkPage2();
		break;
		case 2:
			isValidPage = checkPage3();
		break;
		case 3:
			isValidPage = checkPage4();
		break;
		case 4:
			isValidPage = checkPage5();
		break;
		case 5:
			isValidPage = checkPage6();
		break;
		
	}
	return isValidPage;
}

/*function userTypeRadio () {
	if ($("#patient_radio").attr("checked")) {
		$("#healthcare_worker_table").hide();
	} else if ($("#healthcare_radio").attr("checked")) {
		$("#healthcare_worker_table").show();
	}

	checkPage2();
}*/

function isSeriousRadio() {
	if ($("#serious_no_radio").attr("checked")) {
		$("#serious_category_table").hide();
	} else if ($("#serious_yes_radio").attr("checked")) {
		$("#serious_category_table").show();
	}
	checkPage4();
}
function patientAgeType(object) {
	if ($('#patient_age_type option:first').attr('selected')){
			checkNum($(object), false, 120);
	}else{checkNum($(object), false, 36);
	
	}
	checkPage2();
}
function checkNum (obj, isFloat, numMax) {
	var strValue = obj.val();

	if (isFloat == undefined) {
		isFloat = false;
	}

	if (isFloat) {
		var strNumRegexp = /^(|0|[1-9]\d*|[1-9]\d*,\d*|0,\d*)$/;
		var strToNumRegexp = /[1-9]\d*(,\d*)?/;
	} else {
		var strNumRegexp = /^(|0|[1-9]\d*)$/;
		var strToNumRegexp = /[1-9]\d*/; 
	}

	strNumRegexp.lastIndex = 0;
	strToNumRegexp.lastIndex = 0;

	if (!strNumRegexp.test(strValue)) {
		var numVal = ((isFloat) ? ((strToNumRegexp.exec(strValue) == null) ? 0 : parseFloat(strToNumRegexp.exec(strValue))) : Number(strToNumRegexp.exec(strValue)));

		if (numMax != undefined) {
			numVal = ((numVal > numMax) ? numMax : numVal);
		}

		obj.val(numVal);
	} else if (numMax != undefined) {
		var numVal = ((isFloat) ? parseFloat(strValue) : Number(strValue));

		if (numVal > numMax) {
			obj.val( numMax );
		}
	}
}

function objFocusIO( obj , strToCheck ) {
	obj.focusout(function(){
		if ( $(this).val().replace(/\s*/,"") == "" ) {
			$(this).val(strToCheck);
		}
	});
	obj.focusin(function(){
		if ( $(this).val().replace(/\s*/,"") == strToCheck ) {
			$(this).val("");
		}
	});
}

function checkPhoneNumber (strPhoneNum) {
	var strPhoneNumRegExp = /^(\+|00)\d{2}[ /-]?\d{2}[ /-]?(\d{6,7}|\d{3}[ /-]?\d{3,4}|\d{2}[ /-]?\d{2}[ /-]?\d{2,3})$/g;
	strPhoneNumRegExp.lastIndex = 0;

	return strPhoneNumRegExp.test(strPhoneNum);
}

function addSideEffect () {
	var numSideEffectRowCount = $("#sideffect_count").val();

	var objDate = new Date();
	var strYear = objDate.getFullYear();
	var strMonth = objDate.getMonth()+1;
	var strDay = objDate.getDate();

	if(strMonth < 10) strMonth="0" + strMonth;
	if(strDay < 10) strDay = "0"+ strDay;
	
	var strCurrentDate = strYear+"-"+strMonth+"-"+strDay;
	
	var strRes = '';
	strRes += '<fieldset id="side_effect_'+numSideEffectRowCount+'">';
	strRes += '	<legend>Mellékhatás</legend>';
	strRes += '	<table class="side_effect_table">';
	strRes += '		<tr>';
	strRes += '			<td>&nbsp;</td>';
	strRes += '			<td>';
	strRes += '				<input type="button" value="Eltávolítás" onclick="removeSideEffect('+numSideEffectRowCount+')"/>';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td id="effect_name_'+numSideEffectRowCount+'_cont">Észlelt esemény*:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" id="effect_name_'+numSideEffectRowCount+'" name="page3[side_effect]['+numSideEffectRowCount+'][name]" class="page_3_fill name" onkeyup="checkPage3()"/>';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td id="effect_start_'+numSideEffectRowCount+'_cont" >Mikor észlelte először*:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" id="effect_start_'+numSideEffectRowCount+'" name="page3[side_effect]['+numSideEffectRowCount+'][start_date]" class="page_3_fill page_3_datepicker" />';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td>Megszűnt-e:</td>';
	strRes += '			<td>';
	strRes += '				<label>';
	strRes += '					<input type="radio" id="side_effect_is_over_'+numSideEffectRowCount+'_t" name="page3[side_effect]['+numSideEffectRowCount+'][is_over]" onchange="checkSideEffectEndDate('+numSideEffectRowCount+')" value="true" />';
	strRes += '					igen';
	strRes += '				</label>';
	strRes += '				<label>';
	strRes += '					<input type="radio" id="side_effect_is_over_'+numSideEffectRowCount+'_f" name="page3[side_effect]['+numSideEffectRowCount+'][is_over]" onchange="checkSideEffectEndDate('+numSideEffectRowCount+')" value="false" checked="checked" />';
	strRes += '					nem';
	strRes += '				</label>';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td id="side_effect_end_date_'+numSideEffectRowCount+'_cont">Ha igen, mikor<span id="side_effect_end_date_'+numSideEffectRowCount+'_asterix" style="display:none;">*</span>:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" id="side_effect_end_date_'+numSideEffectRowCount+'" name="page3[side_effect]['+numSideEffectRowCount+'][end_date]" class="page_3_datepicker" disabled="disabled" />';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += ' 	<tr>';
	strRes += '			<td id="effect_result_'+numSideEffectRowCount+'_cont">Következmény*:</td>';
	strRes += '			<td>';
	strRes += '				<select id="effect_result_'+numSideEffectRowCount+'" name="page3[side_effect]['+numSideEffectRowCount+'][result]" class="page_3_fill name effect_result" onchange="checkSideEffectResult('+numSideEffectRowCount+')">';
	strRes += '				  	<option value="gyógyult">gyógyult</option>';
	strRes += '				  	<option value="következményekkel gyógyult">következményekkel gyógyult</option>';
	strRes += '				  	<option value="javult">javult</option>';
	strRes += '				  	<option value="fennáll">fennáll</option>';
	strRes += '				  	<option value="rosszabbodott">rosszabbodott</option>';
	strRes += '				  	<option value="halálos kimenetelű">halálos kimenetelű</option>';
	strRes += '				  	<option value="nem ismert">nem ismert</option>';
	strRes += '				</select>';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr style="display:none">';
	strRes += '			<td id="effect_result_details_'+numSideEffectRowCount+'_cont">Következmény leírása*:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" id="effect_result_details_'+numSideEffectRowCount+'" name="page3[side_effect]['+numSideEffectRowCount+'][result_details]" class="" disabled="disabled" onkeyup="checkPage3()"/>'; 
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr style="display:none">';
	strRes += '			<td id="side_effect_date_of_death_'+numSideEffectRowCount+'_cont">Elhalálozás dátuma*:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" id="side_effect_date_of_death_'+numSideEffectRowCount+'" name="page3[side_effect]['+numSideEffectRowCount+'][date_of_death]" class="page_3_datepicker" disabled="disabled" onkeyup="checkPage3()"/>'; 
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td>Egyéb megjegyzés:</td>';
	strRes += '			<td>';
	strRes += '				<table class="tv_tarea_tb w_186">';
	strRes += '					<tr class="tv_tarea_top">';
	strRes += '						<td class="tv_tarea_top_left"></td>';
	strRes += '						<td class="tv_tarea_top_center"></td>';
	strRes += '						<td class="tv_tarea_top_right"></td>';
	strRes += '					</tr>';
	strRes += '					<tr>';
	strRes += '						<td class="tv_tarea_middle_left"></td>';
	strRes += '						<td class="tv_tarea_middle_center">';
	strRes += '							<textarea name="page3[side_effect]['+numSideEffectRowCount+'][note]"></textarea>';
	strRes += '						</td>';
	strRes += '						<td class="tv_tarea_middle_right"></td>';
	strRes += '					</tr>';
	strRes += '					<tr>';
	strRes += '						<td class="tv_tarea_bottom_left"></td>';
	strRes += '						<td class="tv_tarea_bottom_center"></td>';
	strRes += '						<td class="tv_tarea_bottom_right"></td>';
	strRes += '					</tr>';
	strRes += '				</table>';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '	</table>';
	strRes += '</fieldset>';

	$("#sidEffectsList").append(strRes);
	
	$("#side_effect_"+numSideEffectRowCount).find("input.page_3_datepicker").datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: "yy-mm-dd",
		maxDate: strCurrentDate,
		onSelect: function () {
			var strDateRegexp = /^20\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
			strDateRegexp.lastIndex = 0;

			if (strDateRegexp.test($(this).val())) {
				$(this).attr("last_selected",$(this).val());
			}

			checkPage3();
		}
	}).focusout(function () {
		var strDateRegexp = /^20\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
		strDateRegexp.lastIndex = 0;

		if (strDateRegexp.test($(this).attr("last_selected"))) {
			$(this).val($(this).attr("last_selected"));
		} else {
			$(this).val("");
		}

		checkPage3();
	});

	checkPage3();

	$("#side_effect_"+numSideEffectRowCount).find("input").each(function () {
		$(this).blur(function () {
			saveMSQForm();
		});
	});

	$("#side_effect_"+numSideEffectRowCount).find("textarea").each(function () {
		$(this).blur(function () {
			saveMSQForm();
		});
	});

	saveMSQForm();
	numSideEffectRowCount ++;
	$("#sideffect_count").val(numSideEffectRowCount);
}

function checkSideEffectEndDate (numRowID) {
	if ($("#side_effect_is_over_"+numRowID+"_t").attr("checked")) {
		$("#side_effect_end_date_"+numRowID).removeAttr("disabled");
		$("#side_effect_end_date_"+numRowID).addClass("page_3_fill");
		$("#side_effect_end_date_"+numRowID+"_asterix").show();
	} else if ($("#side_effect_is_over_"+numRowID+"_f").attr("checked")) {
		$("#side_effect_end_date_"+numRowID).attr("disabled","disabled");
		$("#side_effect_end_date_"+numRowID).val("");
		$("#side_effect_end_date_"+numRowID).removeClass("page_3_fill");
		$("#side_effect_end_date_"+numRowID+"_asterix").hide();

		if ($("#side_effect_end_date_"+numRowID+"_cont").hasClass("not_valid")) {
			$("#side_effect_end_date_"+numRowID+"_cont").removeClass("not_valid");
		}
	}

	checkPage3();
}
function checkSideEffectResult (numRowID) {
	if ($("#effect_result_"+numRowID).val() == "következményekkel gyógyult") {
		$("#effect_result_details_"+numRowID).removeAttr("disabled");
		$("#effect_result_details_"+numRowID).addClass("page_3_fill");
		
		$("#effect_result_details_"+numRowID+"_cont").parent().css('display','');
	} else {
		$("#effect_result_details_"+numRowID).attr("disabled","disabled");
		$("#effect_result_details_"+numRowID).val("");
		$("#effect_result_details_"+numRowID).removeClass("page_3_fill");

		$("#effect_result_details_"+numRowID+"_cont").parent().css('display','none');
		
		if ($("#effect_result_details_"+numRowID+"_cont").hasClass("not_valid")) {
			$("#effect_result_details_"+numRowID+"_cont").removeClass("not_valid");
		}
	}
	
	if ($("#effect_result_"+numRowID).val() == "halálos kimenetelű") {
		$("#side_effect_date_of_death_"+numRowID).removeAttr("disabled");
		$("#side_effect_date_of_death_"+numRowID).addClass("page_3_fill");
		
		$("#side_effect_date_of_death_"+numRowID+"_cont").parent().css('display','');
	} else {
		$("#side_effect_date_of_death_"+numRowID).attr("disabled","disabled");
		$("#side_effect_date_of_death_"+numRowID).val("");
		$("#side_effect_date_of_death_"+numRowID).removeClass("page_3_fill");

		$("#side_effect_date_of_death_"+numRowID+"_cont").parent().css('display','none');
		
		if ($("#side_effect_date_of_death_"+numRowID+"_cont").hasClass("not_valid")) {
			$("#side_effect_date_of_death_"+numRowID+"_cont").removeClass("not_valid");
		}
	}

	checkPage3();
}

function removeSideEffect (numRowID) {
	$("#side_effect_"+numRowID).remove();
	checkPage3();
	saveMSQForm();
}

function addTevaItem() {
	var numItemCount = $("#teva_item_count").val();
	
	var objDate = new Date();
	var strYear = objDate.getFullYear();
	var strMonth = objDate.getMonth()+1;
	var strDay = objDate.getDate();

	if(strMonth < 10) strMonth="0" + strMonth;
	if(strDay < 10) strDay = "0"+ strDay;
	
	var strCurrentDate = strYear+"-"+strMonth+"-"+strDay;
	
	var strRes = '';

	strRes += '<fieldset id="teva_item_table_'+numItemCount+'">';
	strRes += '	<legend>Teva készítmény</legend>';
	strRes += '	<table class="teva_item">';
	strRes += '		<tr>';
	strRes += '			<td>&nbsp;</td>';
	strRes += '			<td>';
	strRes += '				<input type="button" value="Eltávolítás" onclick="removeTevaItem('+numItemCount+')">';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td id="id_item_'+numItemCount+'_input_cont"><div id="id_arukod_megnev_'+numItemCount+'_cont">Gyógyszer neve*: <br/><span class="note">(Írjon be a gyógyszer nevéből legalább 2 betűt, majd válasszon a legördülő menüből!)</span></div></td>';
	strRes += '			<td>';
	strRes += '				<div id="id_item_'+numItemCount+'" class="quick_search_div" ></div>';
	strRes += '				<input type="hidden" id="id_arukod_'+numItemCount+'" class="page_5_fill arukod" name="page5[items][T]['+numItemCount+'][arukod]" />';
	strRes += '				<input type="hidden" id="id_arukod_megnev_'+numItemCount+'" class="page_5_fill" name="page5[items][T]['+numItemCount+'][megnev]" />';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td id="id_dosage_'+numItemCount+'_cont">Adagolás*:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" id="id_dosage_'+numItemCount+'" class="page_5_fill" name="page5[items][T]['+numItemCount+'][dosage]" value="" onkeyup="checkPage5()" />';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td>Milyen betegségre vagy panaszra javasolták Önnek a gyógyszert:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" name="page5[items][T]['+numItemCount+'][indication]" value="" />';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td>Gyártási szám:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" name="page5[items][T]['+numItemCount+'][serial_number]" value="" />';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td>Gyógyszer alkalmazásának kezdete:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" name="page5[items][T]['+numItemCount+'][start_date]" value="" class="datepicker"/>';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td>Gyógyszer alkalmazásának vége:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" name="page5[items][T]['+numItemCount+'][end_date]" value="" class="datepicker"/>';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '	</table>';
	strRes += '</fieldset>';

	$("#teva_items_list").append(strRes);

	initTevaItemFlexbox(numItemCount);

	
	$("#teva_item_table_"+numItemCount+" input.datepicker").datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: "yy-mm-dd",
		maxDate: strCurrentDate,
		onSelect: function () {
			var strDateRegexp = /^20\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
			strDateRegexp.lastIndex = 0;

			if (strDateRegexp.test($(this).val())) {
				$(this).attr("last_selected",$(this).val());
			}
		}
	}).focusout(function () {
		var strDateRegexp = /^20\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
		strDateRegexp.lastIndex = 0;

		if (strDateRegexp.test($(this).attr("last_selected"))) {
			$(this).val($(this).attr("last_selected"));
		} else {
			$(this).val("");
		}
	});

	$("#teva_item_table_"+numItemCount).find("input").each(function () {
		$(this).blur(function () {
			saveMSQForm();
		});
	});

	$("#teva_item_table_"+numItemCount).find("textarea").each(function () {
		$(this).blur(function () {
			saveMSQForm();
		});
	});

	checkPage5();
	numItemCount ++;
	$("#teva_item_count").val(numItemCount);
}

function removeTevaItem (numRowID) {
	$("#teva_item_table_"+numRowID).remove();
	checkPage5();
	saveMSQForm();
}

function initTevaItemFlexbox(numID) {
	var numInputWidth = 0;
	if (navigator.appName == 'Microsoft Internet Explorer') {
		numInputWidth = 140;
	} else {
		numInputWidth = 176;
	}

	$("#id_item_"+numID).flexbox(
		"ws_modul.php?s=mx_medinfo_item_search"
		, {
			showArrow: false
			, queryDelay: 400
			, width: numInputWidth
			, noResultsText: "A keresési feltételhez nem létezik megfelelő termék."
			, method: "GET"
			, minChars: 2
			, width: 150
			, paging: {
					pageSize: 10
					, showSummary: false
				}
		, onSelect: function() {
				$("#id_arukod_"+numID).val(this.getAttribute("hiddenValue"));
				$("#id_arukod_megnev_"+numID).val(this.value);
			}
		}
	);
	$("#id_item_"+numID+"_input").addClass("page_5_fill");
	$("#id_item_"+numID+"_input").focusout(function(){
		checkPage5();
	});
	if ( $("#id_arukod_megnev_"+numID).val() != '' ) {
		$("#id_item_"+numID+"_input").val($("#id_arukod_megnev_"+numID).val());
	}
	if (navigator.appName == 'Microsoft Internet Explorer') {
		$("#id_item_"+numID+"_ctr").width(350);
	} else {
		$("#id_item_"+numID+"_ctr").width(400);
	}
}

function addNonTevaItem() {
	var numItemCount = $("#non_teva_item_count").val();
	
	var objDate = new Date();
	var strYear = objDate.getFullYear();
	var strMonth = objDate.getMonth()+1;
	var strDay = objDate.getDate();

	if(strMonth < 10) strMonth="0" + strMonth;
	if(strDay < 10) strDay = "0"+ strDay;
	
	var strCurrentDate = strYear+"-"+strMonth+"-"+strDay;
	
	var strRes = '';

	strRes += '<fieldset id="nt_item_table_'+numItemCount+'">';
	strRes += '	<legend>Nem Teva készítmény</legend>';
	strRes += '	<table class="medicine_item">';
	strRes += '		<tr>';
	strRes += '			<td>&nbsp;</td>';
	strRes += '			<td>';
	strRes += '				<input type="button" value="Eltávolítás" onclick="removeNonTevaItem('+numItemCount+')">';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td id="non_teva_item_name_'+numItemCount+'_cont">Gyógyszer neve*:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" id="non_teva_item_name_'+numItemCount+'" class="page_6_fill name" name="page6[items][O]['+numItemCount+'][name]" value="" onkeyup="checkPage6()" />';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td id="non_teva_dosage_'+numItemCount+'_cont">Adagolás*:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" id="non_teva_dosage_'+numItemCount+'" class="page_6_fill" name="page6[items][O]['+numItemCount+'][dosage]" value="" onkeyup="checkPage6()" />';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td>Indikáció:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" name="page6[items][O]['+numItemCount+'][indication]" value="" />';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td>Gyártási szám:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" name="page6[items][O]['+numItemCount+'][serial_number]" value="" />';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td>Gyógyszer alkalmazásának kezdete:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" name="page6[items][O]['+numItemCount+'][start_date]" value="" class="datepicker"/>';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '		<tr>';
	strRes += '			<td>Gyógyszer alkalmazásának vége:</td>';
	strRes += '			<td>';
	strRes += '				<input type="text" name="page6[items][O]['+numItemCount+'][end_date]" value="" class="datepicker"/>';
	strRes += '			</td>';
	strRes += '		</tr>';
	strRes += '	</table>';
	strRes += '</fieldset>';

	$("#non_teva_item_list").append(strRes);

	$("#nt_item_table_"+numItemCount+" input.datepicker").datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: "yy-mm-dd",
		maxDate: strCurrentDate,
		onSelect: function () {
			var strDateRegexp = /^20\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
			strDateRegexp.lastIndex = 0;

			if (strDateRegexp.test($(this).val())) {
				$(this).attr("last_selected",$(this).val());
			}
		}
	}).focusout(function () {
		var strDateRegexp = /^20\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
		strDateRegexp.lastIndex = 0;

		if (strDateRegexp.test($(this).attr("last_selected"))) {
			$(this).val($(this).attr("last_selected"));
		} else {
			$(this).val("");
		}
	});

	$("#nt_item_table_"+numItemCount).find("input").each(function () {
		$(this).blur(function(){
			saveMSQForm();
		});
	});

	checkPage6();
	numItemCount++;
	$("#non_teva_item_count").val(numItemCount);
}

function removeNonTevaItem (numRowID) {
	$("#nt_item_table_"+numRowID).remove();
	checkPage6();
	saveMSQForm();
}

function addExamination () {
	var numRowID = $("#exam_count").val();
	
	var objDate = new Date();
	var strYear = objDate.getFullYear();
	var strMonth = objDate.getMonth()+1;
	var strDay = objDate.getDate();

	if(strMonth < 10) strMonth="0" + strMonth;
	if(strDay < 10) strDay = "0"+ strDay;
	
	var strCurrentDate = strYear+"-"+strMonth+"-"+strDay;
	
	var strRes = '';

	strRes += '<tr class="exam_'+numRowID+'">';
	strRes += '	<td>';
	strRes += '		<fieldset>';
	strRes += '			<legend>Vizsgálat</legend>';
	strRes += '			<table>';
	strRes += '				<tr>';
	strRes += '					<td colspan="2" align="center">';
	strRes += '						<input type="button" value="Eltávolítás" onclick="removeExamination('+numRowID+')" />';
	strRes += '					</td>';
	strRes += '				</tr>';
	strRes += '				<tr>';
	strRes += '					<td>Dátum</td>';
	strRes += '					<td>Vizsgálat</td>';
	strRes += '				</tr>';
	strRes += '				<tr>';
	strRes += '					<td>';
	strRes += '						<div class="tv_input w_80">';
	strRes += '							<input type="text" name="page6[examination]['+numRowID+'][date]" class="datepicker" />';
	strRes += '						</div>';
	strRes += '					</td>';
	strRes += '					<td>';
	strRes += '						<div class="tv_input w_150">';
	strRes += '							<input type="text" name="page6[examination]['+numRowID+'][name]" maxlength="128" />';
	strRes += '						</div>';
	strRes += '					</td>';
	strRes += '				</tr>';
	strRes += '				<tr>';
	strRes += '					<td colspan="2">Leírás</td>';
	strRes += '				</tr>';
	strRes += '				<tr>';
	strRes += '					<td colspan="2">';
	strRes += '						<table class="tv_tarea_tb w_258">';
	strRes += '							<tr class="tv_tarea_top">';
	strRes += '								<td class="tv_tarea_top_left"></td>';
	strRes += '								<td class="tv_tarea_top_center"></td>';
	strRes += '								<td class="tv_tarea_top_right"></td>';
	strRes += '							</tr>';
	strRes += '							<tr>';
	strRes += '								<td class="tv_tarea_middle_left"></td>';
	strRes += '								<td class="tv_tarea_middle_center">';
	strRes += '									<textarea name="page6[examination]['+numRowID+'][descrip]" ></textarea>';
	strRes += '								</td>';
	strRes += '								<td class="tv_tarea_middle_right"></td>';
	strRes += '							</tr>';
	strRes += '							<tr>';
	strRes += '								<td class="tv_tarea_bottom_left"></td>';
	strRes += '								<td class="tv_tarea_bottom_center"></td>';
	strRes += '								<td class="tv_tarea_bottom_right"></td>';
	strRes += '							</tr>';
	strRes += '						</table>';
	strRes += '					</td>';
	strRes += '				</tr>';
	strRes += '			</table>';
	strRes += '		</fieldset>';
	strRes += '	</td>';
	strRes += '</tr>';

	$("#exam_list").append(strRes);

	$(".exam_"+numRowID+" input.datepicker").datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: "yy-mm-dd",
		maxDate: strCurrentDate,
		onSelect: function () {
			var strDateRegexp = /^20\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
			strDateRegexp.lastIndex = 0;

			if (strDateRegexp.test($(this).val())) {
				$(this).attr("last_selected",$(this).val());
			}
		}
	}).focusout(function () {
		var strDateRegexp = /^20\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
		strDateRegexp.lastIndex = 0;

		if (!strDateRegexp.test($(this).val())) {
			if (strDateRegexp.test($(this).attr("last_selected"))) {
				$(this).val($(this).attr("last_selected"));
			} else {
				$(this).val("");
			}
		}
	});

	$(".exam_"+numRowID).find("input").each(function () {
		$(this).blur(function () {
			saveMSQForm();
		});
	});

	$(".exam_"+numRowID).find("textarea").each(function () {
		$(this).blur(function () {
			saveMSQForm();
		});
	});

	numRowID++;
	$("#exam_count").val(numRowID);
}

function removeExamination (numRowID) {
	$(".exam_"+numRowID).remove();
	saveMSQForm();
}

function addTreatment () {
	var numRowID = $("#treatment_count").val();

	var objDate = new Date();
	var strYear = objDate.getFullYear();
	var strMonth = objDate.getMonth()+1;
	var strDay = objDate.getDate();

	if(strMonth < 10) strMonth="0" + strMonth;
	if(strDay < 10) strDay = "0"+ strDay;
	
	var strCurrentDate = strYear+"-"+strMonth+"-"+strDay;
	
	var strRes = '';

	strRes += '<tr class="treatment_'+numRowID+'">';
	strRes += '	<td>';
	strRes += '		<fieldset>';
	strRes += '			<legend>Kezelés</legend>';
	strRes += '			<table>';
	strRes += '				<tr>';
	strRes += '					<td colspan="2" align="center">';
	strRes += '						<input type="button" value="Eltávolítás" onclick="removeTreatment('+numRowID+')" />';
	strRes += '					</td>';
	strRes += '				</tr>';
	strRes += '				<tr>';
	strRes += '					<td>Dátum</td>';
	strRes += '					<td>Kezelés</td>';
	strRes += '				</tr>';
	strRes += '				<tr>';
	strRes += '					<td>';
	strRes += '						<div class="tv_input w_80">';
	strRes += '							<input type="text" name="page6[treatment]['+numRowID+'][date]" class="datepicker" />';
	strRes += '						</div>';
	strRes += '					</td>';
	strRes += '					<td>';
	strRes += '						<div class="tv_input w_150">';
	strRes += '							<input type="text" name="page6[treatment]['+numRowID+'][name]" maxlength="128" />';
	strRes += '						</div>';
	strRes += '					</td>';
	strRes += '				</tr>';
	strRes += '				<tr>';
	strRes += '					<td colspan="2">Leírás</td>';
	strRes += '				</tr>';
	strRes += '				<tr>';
	strRes += '					<td colspan="2">';
	strRes += '						<table class="tv_tarea_tb w_258">';
	strRes += '							<tr class="tv_tarea_top">';
	strRes += '								<td class="tv_tarea_top_left"></td>';
	strRes += '								<td class="tv_tarea_top_center"></td>';
	strRes += '								<td class="tv_tarea_top_right"></td>';
	strRes += '							</tr>';
	strRes += '							<tr>';
	strRes += '								<td class="tv_tarea_middle_left"></td>';
	strRes += '								<td class="tv_tarea_middle_center">';
	strRes += '									<textarea name="page6[treatment]['+numRowID+'][descrip]" ></textarea>';
	strRes += '								</td>';
	strRes += '								<td class="tv_tarea_middle_right"></td>';
	strRes += '							</tr>';
	strRes += '							<tr>';
	strRes += '								<td class="tv_tarea_bottom_left"></td>';
	strRes += '								<td class="tv_tarea_bottom_center"></td>';
	strRes += '								<td class="tv_tarea_bottom_right"></td>';
	strRes += '							</tr>';
	strRes += '						</table>';
	strRes += '					</td>';
	strRes += '				</tr>';
	strRes += '			</table>';
	strRes += '		</fieldset>';
	strRes += '	</td>';
	strRes += '</tr>';

	$("#treatment_list").append(strRes);

	$(".treatment_"+numRowID+" input.datepicker").datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: "yy-mm-dd",
		maxDate: strCurrentDate,
		onSelect: function () {
			var strDateRegexp = /^20\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
			strDateRegexp.lastIndex = 0;

			if (strDateRegexp.test($(this).val())) {
				$(this).attr("last_selected",$(this).val());
			} 
		}
	}).focusout(function () {
		var strDateRegexp = /^20\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
		strDateRegexp.lastIndex = 0;

		if (!strDateRegexp.test($(this).val())) {
			if (strDateRegexp.test($(this).attr("last_selected"))) {
				$(this).val($(this).attr("last_selected"));
			} else {
				$(this).val("");
			}
		}
	});

	$(".treatment_"+numRowID).find("input").each(function () {
		$(this).blur(function () {
			saveMSQForm();
		});
	});

	$(".treatment_"+numRowID).find("textarea").each(function () {
		$(this).blur(function () {
			saveMSQForm();
		});
	});

	numRowID++;
	$("#treatment_count").val(numRowID);
}

function removeTreatment (numRowID) {
	$(".treatment_"+numRowID).remove();
	saveMSQForm();
}

function submitMSQForm() {
	$("#msq_form").submit();
	showLoadingLayer();
}
function saveMSQForm() {
	$.ajax({
		async: false,
		type: "POST",
		url: "ws_modul.php?s=save_msq_session",
		data: $("#msq_form").serialize(),
		success: function ( strData ) {
		}
		
	});
}
function showLoadingLayer() {
	$(".in_progress_bg").show();
	$(".in_progress").show();
}

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

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) {
		$(".in_progress_bg").height(getDocHeight() + 100);
	} else {
		$(".in_progress_bg").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)
	);
}
//------------------------- TEVA 2 TEMPLATE JS FUNCTIONS---------------------------------

$(document).ready(function(){
	$(".menu ul li").each(function(){
		showSubMenu($(this).attr('id'));
	});
});

function showSubMenu( numMenuID ) {
	$("#"+numMenuID).hover(function(){
		clearTimeout($("#"+numMenuID).data('timeoutId'));
    	$(".al_menu_head .al_menu").each(function(){
			if($(this).attr("id") != "al_"+numMenuID){
				$(this).removeClass("active");
				//$(this).fadeOut();	
				$(this).hide();
			}	
    	});
    	if(!($("#al_"+numMenuID).hasClass("active"))){
    		//$("#al_"+numMenuID).fadeIn();
    		$("#al_"+numMenuID).show();
    		$("#al_"+numMenuID).addClass("active");
    	}
	}, function(){
		var myMenu = this;
	    var timeoutId = setTimeout(function(){ 
	    	//$("#al_"+numMenuID).fadeOut();
	    	$("#al_"+numMenuID).hide();
	    	$("#al_"+numMenuID).removeClass("active");
	    }, 600);
	    $(myMenu).data('timeoutId', timeoutId);
	    $("#al_"+numMenuID).hover(function(){
	    	$("#"+numMenuID+" a").addClass("active");
	    	$("#al_"+numMenuID).addClass("active");
			clearTimeout($("#"+numMenuID).data('timeoutId'));
		}, function(){
			if($("#"+numMenuID+" a").hasClass("active")){
				$("#"+numMenuID+" a").removeClass("active");
				$("#al_"+numMenuID).removeClass("active");
			}
			//$("#al_"+numMenuID).fadeOut();
			$("#al_"+numMenuID).hide();
		});
	});
}

function fadeInOutHeaderImages(arrayOfImages, dirOfImages){
	$.each(arrayOfImages, function(key, value) { 
		if(key == 0){
			$("#head_pic").append('<img src="'+dirOfImages+value+'" alt="" class="active"/>');
		} else {
			$("#head_pic").append('<img src="'+dirOfImages+value+'" alt=""/>');	
		}
	});	
	setInterval(function(){
	    var $active = $('#head_pic img.active');
	    if ( $active.length == 0 ) $active = $('#head_pic img:last');
	    var $next =  $active.next().length ? $active.next()
	        : $('#head_pic img:first');
	    $active.addClass('last-active');
	    $next.css({opacity: 0.0})
	        .addClass('active')
	        .animate({opacity: 1.0}, 2000, function() {
	            $active.removeClass('active last-active');
	        });	    
	}, 6000);
}

function preloadImages(tblImages) {
	if (document.tblImages) {
		var i = 0;
		var imageObj = new Image();
		for(i=0; i<=tblImages.length-1; i++) {
			imageObj.src=tblImages[i];
		}
	}

}

function productSearch(type,searchText,atc){
	if(type=='letter'){
		$('#id_search_text').attr('value','');
	}
	$.ajax({
		type: "POST",
		url: "ws_modul.php?s=product_search",
		data: $("#id_item_search").serialize()+"&searchType="+type+"&searchText="+searchText+"&atc="+atc,
		success: function (msg){
			var arrMsg=msg.split("##");
			$(".products").html(arrMsg[0]);
			$(".pager").html(arrMsg[1]);
		}
	});
}

