<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.*,com.csc.library.system.*,com.csc.library.utilities.*,com.csc.library.database.*,com.csc.library.session.*"%>

<jsp:useBean id="MYLOGO" class="com.csc.library.system.Task" scope="page"/>
<%
	MYLOGO.setChannel(request,response);
	CheckNull chk=new CheckNull();
	HelpEntry screen_logo = (HelpEntry)MYLOGO.process("HelpEntry","MLOGOHELP");
	screen_logo.getInquiry().refresh();
	if (screen_logo.getInquiry().recCount()>0){
		screen_logo.nextRec();
		screen_logo.referLangOn();
	}
	UProfile uprofile = null;
	if(session != null ) {
		uprofile = (UProfile)session.getAttribute("userprofile");
	}
	if( uprofile == null ){
		return;
	}
	String lang=uprofile.get("lang");
%>
<link href="../CSS/Bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="../CSS/ADMIN-MENU.css" />
<link rel="stylesheet" href="../CSS/main_mini.css" />
<link rel="stylesheet" href="../CSS/jquery.mCustomScrollbar.css" /> 
<link rel="stylesheet" href="../CSS/font-awesome.css">
<script type="text/javascript" src="../JS/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="../JS/SCREEN.js"></script>
<script type="text/javascript" src="../JS/ICONSMENU.js"></script>
<script type="text/javascript" src="../JS/HOTKEY.js"></script>
<script type="text/javascript" src="../JS/AC_RunActiveContent.js"></script>
<script type="text/javascript" src="../JS/jquery.treeview.noconflict.js"></script>
<script type="text/javascript" src="../JS/jquery.mCustomScrollbar.js"></script>
<script type="text/javascript" src="../JS/angular-1.3.15/angular.js"></script>
<script type='text/JavaScript' src='../JS/ANGULAR/SCREEN_ANGULAR.js'></script>
<script type='text/javascript' src='../JS/bootstrap.js'></script>
<script type="text/javascript" src="/hr/dwr/engine.js"></script>
<script type="text/javascript" src="/hr/dwr/util.js"></script>
<script type="text/javascript" src="/hr/dwr/interface/SystemCode.js"></script>
<script type="text/javascript" src="/hr/dwr/interface/CscCalendar.js"></script>
<script language="JavaScript" > setLang('<%=uprofile.get("lang").toString()%>');</script>
<style>
	.li-click{
		background: #eee;
	}
</style>
<script>
	var Gol_status=0;
	var click_status='';
	var this_lang = '<%=lang%>';

	function CheckSession(){
	/*$.ajax
		({
			type: "POST",
			url: "../CHECKPROFILE.jsp",
			cache: false,
			success : function(result){
				if (result!=""){
					Gol_status=1;
					window.top.location.href ="../LOGINERROR.jsp";
				}
				else
				{
					Gol_status=2;
				}
			},
			async: false
		});
		Gol_status=2;*/
	}

	function CheckOpenMenu(){

		click_status = $("#main_menu").css("display");

		if (click_status=="block")
		{
			RemoveClickHead(); 
			$("#main_menu").fadeOut("500",function(){$("#main_menu").css("display","none")});
		}
	}

	$("a").click(function(){
		//CheckSession();
	});


	function openSystemLog(pages,logs){
		CheckSession();
		CheckOpenMenu();
		if (Gol_status!=1)
		{
			win = window.open(pages+".jsp",logs,"left=150,top=150,width=600,height=400,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
			if(win) win.focus();
		}
	}

	dwr.engine.setErrorHandler(function(message) {});

	function checkPM() {
		CheckSession();
		CheckOpenMenu();
		hiddenPm();
		dwr.engine.beginBatch();
		SearchDWR.searchAll(new Array("PMINBOX","messageid,companyid,senderid,receivedate,receivetime,topic,pmessage,flag","userid='<%=(String)uprofile.get("employeeid")%>' and flag='0'","messageid","langon"),pm); 
		dwr.engine.endBatch({
		  async:false
		});
		setTimeout("checkPM();",300000);
	}

	function hiddenPm(){
		test.innerHTML="<img src='../IMAGES/BUTTON/SWAP/PM24.gif' border='0' align='middle' alt='Private message'>";
	}

	function showPm(){
		test.innerHTML="<img src='../IMAGES/BUTTON/SWAP/NEWPM24.gif' border='0' align='middle' alt='Private message'>";
	}

	function linkPm(){
		window.parent.location = "../EMPVIEW/PM_INBOX.jsp";
	}

	function logout(){
		CheckSession();
		window.parent.location = "../MAIN.jsp";
	}

	function RemoveClickHead(){
		$("span").removeClass("li-click");
		$("a").removeClass("li-click");
	}

	$(document).ready(function(){
		var window_hight=$(window).height();
		var window_width=$(window).width();
		var menu_height=$(".menu-container").css("height");
		var menu_width=$(".block-tree").width();
		var link_width="";

		$(".content").mCustomScrollbar({  
			theme:"dark-thick",
			scrollButtons:{
				enable:true
			}
		});
		
		//set size of main menu
		//$("#main_menu").css("width", window_width-(window_width*39/100));
		//$("#main_menu").css("height", window_hight-(window_hight*38/100));


		//menu left
		 $("ul.filetree").treeview({
			collapsed: true,
			persist: "location",
		});

		function SlideMenu(){
			/*link_width=Math.max.apply(Math, $("li").find("a").map(function(){ return $(this).width(); }).get());
			my_blocktree=ResizeWidthMenu(parseInt(menu_width),parseInt(link_width)+70);
			$(".block-tree").animate({width: my_blocktree },70);

			$(".myiframe").animate({"width":parseInt(window_width)-parseInt(my_blocktree)},70);*/
		}

		function SlideBack(){
			$(".block-tree").animate({"width": "16%"},70); 
			$(".myiframe").animate({"width":"84%"},70);
		}

		function RemoveHover(){
			var color_bg =$(".block-tree").css("background-color"); 
			$(".treeview-hover").css("background-color",color_bg);
			$("span").removeClass("treeview-hover");
		}
				
		function RemoveClick(){

			$("span").removeClass("li-click");
			$("a").removeClass("a-click");
		}

		$(".treeview span").click(function(){
			CheckSession();
			RemoveClick();
			CheckOpenMenu();
			$(this).addClass("bg-click");
			$(".bg-click").css("width",menu_width+500);
			$(this).closest("a").addClass("a-click");
		});	

		$("li").click(function(){
			SlideMenu();
		});



		//menu head
		function RemoveHoverHead(){
			var bg_color=$(".menu-bar").css("background-color");

			$(".li-hover").css("background-color",bg_color);
			$(".li").removeClass("li-hover");
		}

		// เพิ่มคลาส hover ให้ exit Natthapong 3/9/2558
		$(".li-main").hover(function(){
			$(".exit").addClass("li-hover"); 
			var bg_color = $(".menu-bar").css("background-color");

			$(".li-hover").css("background-color",ShadeColor(bg_color,30));
		},function(){
			RemoveHoverHead();
		});


		$(".li").hover(function(){
			$(this).closest(".li").addClass("li-hover"); 
			var bg_color = $(".menu-bar").css("background-color");

			$(".li-hover").css("background-color",ShadeColor(bg_color,30));
		},function(){
			RemoveHoverHead();
		});


		$("li a").click(function(){
			if ($(this).hasClass("head_menu_list")==false){
				CheckSession();
				RemoveClickHead();
				if ($(this).parent().get(0).tagName=="LI"){
					$(this).addClass("li-click");
				}else if($(this).parent().get(0).tagName=="SPAN" && $(this).parent().hasClass("tree-nochild")){
					$(this).parent("span").addClass("li-click");
				}

				//สั่งปิดเมนูย่อย หากมีการคลิก li ตัวอื่น  --Maiwan 3/9/2558
				$(".li-menu").css("display","none");
				$(".li-menu-sub").css("display","none");
			}
		});

		$("span").click(function(){
			if ($(this).hasClass("tree-toggler")){
				RemoveClickHead();
				$(this).addClass("li-click");
			}
			
		});

		$(".tree-nochild").click(function(){
			/*var myhref = $(this).children().get(0).href;
			myhref = myhref.substring(myhref.indexOf(":")+1,myhref.indexOf("("));
			if (myhref == "linkpageHol"){
				console.log("1");
				var link1 = $(this).children().get(0).href;
				//console.log( = link1.substring(link1.indexOf("'")+1,link1.indexOf(",")-1));
				link1 = link1.substring(link1.indexOf("'")+1,link1.indexOf(",")-1);
				var link2 = $(this).children().get(0).href;
				link2 = link2.substring(link2.indexOf(",")+2,link2.lastIndexOf("'"));

				console.log(link1+" "+link2);
				linkpageHol(link1,link2);
			}else if (myhref == "linkpageImport"){
				var link1 = $(this).children().get(0).href;
				link1 = link1.substring(link1.indexOf("'")+1,link1.indexOf(",")-1);
				var link2 = $(this).children().get(0).href;
				link2 = link2.substring(link2.indexOf(",")+2,link2.lastIndexOf("'"));

				linkpageImport(link1,link2);
			} else if (myhref== "linkpageReport2"){
				var link = $(this).children().get(0).href;

				link = link.substring(link.indexOf("'")+1,link.lastIndexOf("'"));
				
				linkpageReport2(link);
			} else if (myhref == "linkpageReport1"){
				var link = $(this).children().get(0).href;

				link = link.substring(link.indexOf("'")+1,link.lastIndexOf("'"));
				linkpageReport1(link);
			} else if (myhref == "linkpageProcess"){
				var link = $(this).children().get(0).href;

				link = link.substring(link.indexOf("'")+1,link.lastIndexOf("'"));
				linkpageProcess(link);
			} else if (myhref == "linkpageShowData"){
				var link = $(this).children().get(0).href;

				link = link.substring(link.indexOf("'")+1,link.lastIndexOf("'"));

				linkpageShowData(link);
			} else{
				console.log(myhref);
				myhref = $(this).children().get(0).href;
				myhref = myhref.substring(myhref.indexOf("'")+1,myhref.lastIndexOf("'"));

				$("#mainFrame").attr('src',myhref);
			}*/
		});


		//สั่งเปิดเมนูย่อยเวลาคลิกปุ่ม User Manage(ชื่อพนักงาน)-- Maiwan 3/9/2558
		$(".li-main").click(function(){
			RemoveClickHead();
			$(".exit").addClass("li-click");
			click_status = $(".li-menu").css("display");
			$(".li-menu").toggle(50);

			if (click_status=="block"){
				RemoveClickHead();
			}
		});

		// เปิดเมนู sub menu ย่อยในเมนูย่อยเมื่อเกิดการ hover -- Maiwan 3/9/2558
		$(".li-menu").hover(function(){
			$(this).addClass("li-hover"); 
			var bg_color = $(".li-menu").css("background-color");
			$(".li-hover").css("background-color",ShadeColor(bg_color,30));

			$(this).dequeue().stop(true, true).find(".li-menu-sub").toggle(70);
		}, function(){

			var bg_color=$(".li-menu").css("background-color");
			$(".li-hover").css("background-color",ShadeColor(bg_color,-30));
			$(this).removeClass("li-hover");

			$(this).find(".li-menu-sub").toggle(70); 
		});

		// แสดงสีเมื่อ hover ใน list ของ sub menu -- Maiwan 3/9/2558 
		$(".li-sub-child").hover(function(){
			$(this).addClass("li-hover-sub"); 
			var bg_color = $(".li-menu-sub").css("background-color");
			$(".li-hover-sub").css("background-color",ShadeColor(bg_color,30));
		},function(){
			var bg_color=$(".li-menu-sub").css("background-color");
			$(".li-hover-sub").css("background-color",ShadeColor(bg_color,-30));
			$(this).removeClass("li-hover-sub");
		});



		//iframe
		$("#mainFrame").load(function(){
			var frame_name=$("#mainFrame").contents();
			//$("#mainFrame").contents().find("img[name=Image13]").parent().attr('href','javascript:showHelpPage(\'test\',\'testfile\')');
			frame_name.click(function(event){
				CheckOpenMenu();
				/*CheckSession();
				if (Gol_status!=2)
				{
					event.preventDefault();
				}*/
			});
			setTimeout(function(){$("#__sysisedit").val("false")},500);
		});
	});

	function linkpage(jsppage){
		CheckSession();
		var check = true;

		if ($("#__sysisedit").val()=="true"){
			aCon=confirm(MyCode[238]);
			if (aCon==false)	{
				check = false;						
			}

			//$("#__sysisedit").val("");
		}
		else if($("#__sysisedit").val()=="upload"){
			alert(MyCode[239]);
			check =false;;
		}

		if (check)
		{
			$("#__sysisedit").val("false");
			$("#mainFrame").attr('src',jsppage);
		}
	}

	function linkpageReportLog(jsppage){
		CheckSession();
		var fixcon="";
		fixcon = " owner ='TA' ";
		$("#mainFrame").attr('src',jsppage+"?__fixCon="+fixcon);
	}

	function linkpageReport(jsppage){
		CheckSession();
		var fixcon="";
		fixcon = " employee ='<%=uprofile.get("employeeid").toString()%>' and company='<%=uprofile.get("companyid").toString()%>'";

		$("#mainFrame").attr('src',jsppage+"?__fixCon="+fixcon);	
	}

	function linkpageReport1(jsppage){
		$("#mainFrame").attr('src',"ASR001.jsp?__screen="+jsppage); 
	}
	
	function linkpageReport2(jsppage){
		$("#mainFrame").attr('src',"../ASR001_STD.jsp?__screen="+jsppage); 
	}

	function linkpageProcess(jsppage){
		var fixcon=" ename ='Time Attendance' and companyid='<%=uprofile.get("companyid").toString()%>'";
		var ename="Time Attendance";
		$("#mainFrame").attr('src',jsppage+"?__fixCon="+fixcon+"&__ename="+ename);
	}

	function ShowDialog(){
		CheckSession();
		if (Gol_status!=1)
		{
			//click_status = $("#admin_menu").css("display");
			//$("#admin_menu").fadeToggle("500");
			$("#module_menu").css( 'display', 'table' );
			if (click_status=="block")
			{
				RemoveClickHead(); 
			}
		}
	}


	function linkModule(jsppage){
		CheckSession();
		if (Gol_status!=1)
		{

			$("#modulename").val(jsppage.substring(0, jsppage.lastIndexOf("/")));
			$("#modulepath").val($("#modulename").val());
			$("#linkaction").val(jsppage);
		
			$("#cscforms").attr("action","../CHECKMODULE.jsp");
			$("#cscforms").submit();
		}
	}
	
	function linkpageEmp(jsppage){
		CheckSession();
		var mfixcon;
		var check = true;
		if ($("#__sysisedit").val()=='true'){
			aCon=confirm(MyCode[238]);
			if(aCon==false){
				check=false;
			}
		}

		if(check){
			$("#__sysisedit").val("false");
			if ($("#__empid").val()!=""){
				mfixcon= "__employeeid$"+$("#__empid").val()+";__companyid$<%=uprofile.get("companyid").toString()%>";
				//action = jsppage+"?__cmd=search&__help="+mfixcon+"&__employeeid="+__empid.value;

				$("#mainFrame").attr('src',jsppage+"?__cmd=search&__help="+mfixcon+"&__employeeid="+$("#__empid").val());
			}
			else{
				$("#mainFrame").attr('src',jsppage);
			}
		}
	}

	function changeLang(lang){
		if (this_lang!=lang){
			$.ajax({
				type:"POST",
				url:"<%=request.getContextPath()%>/EMPVIEW/EMV_SETLANG.jsp",
				cache: false,
				data: "lang="+lang,
				success: function(){
					location.reload();
				}
			});
		}
	}

	function linkpageShowData(jsppage){
		var fixcon=" employeeid ='<%=uprofile.get("employeeid").toString()%>' ";
		var employeeid= "<%=uprofile.get("employeeid").toString()%>";
		$("#mainFrame").attr('src',jsppage+"?__fixCon="+fixcon+"&__employeeid="+employeeid);
	}

	function linkpageHol(jsppage,pagei){
		$("#mainFrame").attr('src',jsppage+"?__pageIframe="+pagei); 
	}

	function linkpageImport(jsppage,typeimport){
		var check = true;
		if ($("#__sysisedit").val()=='true'){
			aCon=confirm(MyCode[238]);
			if (aCon==false){
				check =false;						
			}
		}
		if (check){
			$("#__sysisedit").val("false");
			$("#mainFrame").attr("src",jsppage+"?__typeimport="+typeimport);
		}
	}

	$(document).ready(function(){

		$('span.tree-toggler').parent().children('ul.tree').toggle();

		$('span.tree-toggler').click(function () {
			$(this).toggleClass( "expandable" )
			$(this).parent().children('ul.tree').toggle(100);
		});
		
		$("a.dropdown-toggle").click(function () {
			if($("#module_menu").css("display")!="none"){
				$("#module_menu").css("display","none");
			}
		});

		var listObjectPermission = {
			"__isSave" : "saveStatus" ,
			"__isEdit" : "editStatus" ,
			"__isDelete" : "deleteStatus" ,
			"__isActive" : "activeStatus"
		};
		for( var key in listObjectPermission ){
			var objInput = $("#"+key);
			if(objInput.length == 0){
				$("form[name=cscform]").append("<input type=\"hidden\" id=\""+key+"\" name=\""+key+"\" value=\"0\">");
			}
		}
		$("a[activestatus]").click(function(){
			var target = $(this);
			if( target.attr("activeStatus") == "1" ){
				window.PermissionAction = {
					isSave : target.attr("saveStatus"),
					isEdit : target.attr("editStatus"),
					isDelete : target.attr("deleteStatus")
				}
			}else{
				window.PermissionAction ={
					isSave : "1",
					isEdit : "1",
					isDelete : "1"
				}
			}
			$("#__isSave").val(target.attr("saveStatus"));
			$("#__isEdit").val(target.attr("editStatus"));
			$("#__isDelete").val(target.attr("deleteStatus"));
			$("#__isActive").val(target.attr("activeStatus"));
		});
	});
</script>
<nav class="navbar navbar-default" >
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header" style="width:20%;text-align:center;">
    	<span class="navbar-brand" style="width:100%;"><%=chk.chkNullString(screen_logo.getString("elogotxt"),"Logo")%></span>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

      <ul class="nav navbar-nav">
        <li><a class="head_menu_list" href="javascript:openSystemLog('../CSCQUQUE04');" swlang code='SW011918'>Server List</a></li>
        <li><a class="head_menu_list" href="javascript:openSystemLog('../CSCLOG001','SettingLog');" swlang code='SW011919'>Log</a></li>
        <li><a class="head_menu_list" href="javascript:openSystemLog('../CSCQUQUE03','SystemLog');" swlang code='SW011920'>Queue</a></li>
      </ul>

      <ul class="nav navbar-nav navbar-right" >
		<li ><a class="head_menu_list " href="javascript:ShowDialog();" swlang code='SW011921'>Admin Menu</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><%=uprofile.get("fullname")%> <span class="caret"></span></a>
          <ul class="dropdown-menu">
			<li class="dropdown-header" swlang code='SW011922'>Langauge</li>
			<li >
				<a href="Javascript:changeLang('tha')">
					<%=(lang.equals("tha"))?"<i class='fa fa-check'></i>":"<span style='padding-left:20px;'></span>"%>
					<span style='padding-left:10px;' swlang code='SW000840'>Thai</span>
				</a>
			</li>
			<li >
				<a href="Javascript:changeLang('eng')">
					<%=(lang.equals("eng"))?"<i class='fa fa-check'></i>":"<span style='padding-left:20px;'></span>"%> 
					<span style='padding-left:10px;' swlang code='SW002129'>English</span>
				</a>
			</li>
            <li role="separator" class="divider"></li>
            <li><a href="../LOGOUT.jsp" swlang code='SW011923'>Logout</a></li>
          </ul>
        </li>
      </ul>

    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
<% 
	screen_logo.getInquiry().closeConnection(); 
%>
<form name="cscform" target="mainFrame" method="post"> 
	<input type="hidden" name="__sysisedit" id="__sysisedit" value="">
	<input type="hidden" name="__screen" id="__screen" value="AP_MenuMX">
	<input type="hidden" name="__pageIframe" id="__pageIframe" value="">
	<input type="hidden" name="__help" id="__help" value="">
	<input type="hidden" name="__empid" id="__empid" value="">
	<input type="hidden" name="modulename" id="modulename" value="">
	<input type="hidden" name="modulepath" id="modulepath" value="">
	<input type="hidden" name="linkaction" id="linkaction" value="">
	<input type="hidden" name="__language" value="<%=uprofile.get("lang")%>">
</form>
