function login(){
    $("#login").show();
    $("#loginoutmenu").hide();
    $("#username").val("");
    $("#password").val("");
    $("#login").window({
				title: '登录',
				width: 350,
				height: 200,
				modal: true,
				shadow: false,
				closable: false,
				maximizable: false,
				minimizable: false,
				collapsible: false,
				resizable: false,
				iconCls:"icon-save"
	}); 
}
function tiyanLogin(url) {
    $.ajax({
       type: "POST",
       dataType: "json",
       //cache:true,
       url: "json/loginAction_login.action?request_locale=zh_CN",
       data: {userType:-1000},
       success: function(json) {
	         if (json.flag==true) {
	        	 window.location.replace(url+"gpsonline/jsp/monitor/main.jsp");
	         }else {
	        	 $("#logmes").text(json.msg);
	         }
       },
       error: function() {
           // alert('获取账号信息失败...请稍后重试!');
       }
  });
}
function logincheck() {
		
	     var username = $("#username").val();
	     var password =$("#password").val();
	     var  userType=$("#userType").val();
	     if(username==""||password==""){
	        $("#logmes").text("用户名,密码不能为空!");
	        return;
	     }
	     loginSys(username, password,userType);
}

function logincheck2(url) {
	
    var username = $("#username").val();
    var password =$("#password").val();
    var  userType=$("#userType").val();
    if(username==""||password==""){
       $("#logmes").text("用户名,密码不能为空!");
       return;
    }
    loginSys2(username, password,userType,url);
}

function logincheck3(url) {

    var username = $("#gusername").val();
    var password =$("#gpassword").val();
    var  userType=$("#guserType").val();
    if(username==""||password==""){	
       $("#glogmes").text("用户名,密码不能为空!");
       return;
    }
   loginSys3(username, password,userType,url);
}

function loginSysUTF8(username,password,userType,url,nameGKB,username2) {
    $.ajax({
       type: "POST",
       dataType: "json",
       cache:true,
       url: "json/loginAction_login.action?request_locale=zh_CN",
       data: { userName: username, userPass: password,userType:userType},
       success: function(json) {
	         if (json.flag==true) {	  
	        	 window.location.replace(url+"gpsonline/jsp/monitor/main.jsp");
	         }else {
	        	 loginSysUTF82(username2,password,userType,url,nameGKB);
	         }
       },
       error: function() {
            //alert('获取账号信息失败...请稍后重试!');
       }
  });
}
function loginSysUTF82(username,password,userType,url,nameGKB) {
    $.ajax({
       type: "POST",
       dataType: "json",
       cache:true,
       url: "json/loginAction_login.action?request_locale=zh_CN",
       data: { userName: username, userPass: password,userType:userType},
       success: function(json) {
	         if (json.flag==true) {	  
	        	 window.location.replace(url+"gpsonline/jsp/monitor/main.jsp");
	         }else {
	        	 loginSysGBK(nameGKB,password,userType,url);
	         }
       },
       error: function() {
            //alert('获取账号信息失败...请稍后重试!');
       }
  });
}
function loginSysGBK(username,password,userType,url) {
    $.ajax({
       type: "POST",
       dataType: "json",
       //cache:true,
       url: "json/loginAction_login.action?request_locale=zh_CN",
       data: { userName: username, userPass: password,userType:userType},
       success: function(json) {
	         if (json.flag==true) {	        	 
	        	 window.location.replace(url+"gpsonline/jsp/monitor/main.jsp");
	         }else {
	        	 window.location.replace(url+"gpsonline/jsp/login.jsp?jsonmsg=账号密码错误！");
	         }
       },
       error: function() {
            //alert('获取账号信息失败...请稍后重试!');
       }
  });
}


function zlogin(username,password,userType,url,name2){
    $.ajax({
       type: "POST",
       dataType: "json",
       //cache:true,
       url: "json/loginAction_login.action?request_locale=zh_CN",
       data: {userName:username,userPass:password,userType:userType},
       success: function(json){
    	   console.info(json);
	         if (json.flag==true) {
	        	 mapType = g("mapType").value;
	        	 if(mapType=='null')mapType=1;
	        	 window.location.replace(url+"gpsonline/jsp/cmonitor/main.jsp?zMsg=true&mapType="+mapType);
	         }else{
	        	 zlogin2(name2,password,userType,url);
	         }
       },
       error: function(){
            //alert('获取账号信息失败...请稍后重试!');
       }
  });
}
function loginSys2(username,password,userType,url) {
    $.ajax({
       type: "POST",
       dataType: "json",
       //cache:true,
       url: "json/loginAction_login.action?request_locale=zh_CN",
       data: { userName: username, userPass: password,userType:userType},
       success: function(json) {
	         if (json.flag==true) {
	        	 $.cookie("externalPass",password,{expires:1});
	        	 window.location.replace(url+"gpsonline/jsp/monitor/main.jsp");
	        	 recordPassWorld(0);
	         }else {
	        	 $("#glogmes").text(json.msg);
	         }
       },
       error: function() {
           // alert('获取账号信息失败...请稍后重试!');
       }
  });
}
function loginSys3(username,password,userType,url) {
    $.ajax({
       type: "POST",
       dataType: "json",
       //cache:true,
       url: "json/loginAction_login.action?request_locale=zh_CN",
       data: { userName: username, userPass: password,userType:userType},
       success: function(json) {
	         if (json.flag==true) {
	        	 window.location.replace(url+"gpsonline/jsp/monitor/main.jsp");
	        	 rempassworld(2);
	         }else {
	        	 $("#glogmes").text(json.msg);
	         }
       },
       error: function() {
             //alert('获取账号信息失败...请稍后重试!');
       }
  });
}
function zzlogin(username,password,userType,pt,url,name2) {
    $.ajax({
       type: "POST",
       dataType: "json",
       //cache:true,
       url: "json/loginAction_login.action?request_locale=zh_CN",
       data: { userName: username, userPass: password,userType:userType,pt:pt},
       success: function(json) {
    	   console.info(json);
	         if (json.flag==true) {
	        	 window.location.replace(url+"gpsonline/jsp/monitor/main.jsp?isFull=true");
	         }else {
	        	 //$("#logmes").text(json.msg);
	        	 zzlogin2(name2,password,pt,userType,url);
	         }
       },
       error: function() {
            //alert('获取账号信息失败...请稍后重试!');
       }
  });
}
function zzlogin2(username,password,pt,userType,url) {
	
	console.info("username:" + username);
	console.info("password:" + password);
    $.ajax({
       type: "POST",
       dataType: "json",
       url: "json/loginAction_login.action?request_locale=zh_CN",
       data: { userName: username, userPass: password,userType:userType,pt:pt},
       success: function(json){
	         if (json.flag==true){
	        	 window.location.replace(url+"gpsonline/jsp/monitor/main.jsp?isFull=true");
	         }else {
	        	 alert("登录异常");
	         }
       },
       error: function() {
           //alert('获取账号信息失败...请稍后重试!');
       }
  });
}

function zlogin2(username,password,userType,url) {
    $.ajax({
       type: "POST",
       dataType: "json",
       //cache:true,
       url: "json/loginAction_login.action?request_locale=zh_CN",
       data: { userName: username, userPass: password,userType:userType},
       success: function(json) {
//    	   console.info("----------------------");
	         if (json.flag==true) {
	        	 window.location.replace(url+"gpsonline/jsp/cmonitor/main.jsp?zMsg=true");
	         }else {
	        	 alert("登录异常");
	         }
       },
       error: function() {
           //alert('获取账号信息失败...请稍后重试!');
       }
  });
}

	//登陆操作
function loginSys(username,password,userType) {
         $.ajax({
	        type: "POST",
	        dataType: "json",
	        //cache:true,
	        url: "json/loginAction_login.action?request_locale=zh_CN",
	        data: { userName: username, userPass: password,userType:userType},
	        success: function(json) {
		         if (json.flag==true) {
			          $("#login").hide();
			          $('#login').window('close');//关闭弹出框
			          getGroup(); //加载组数据
			          $("#time").text($("#ss").val());//开始计时刷新
			          $("#name").text(json.data[0].userName);
			          $("#userType").text(gettextType(json.data[0].userType));
		         }else {
		            $("#logmes").text(json.msg);
		         }
	        },
	        error: function() {
	            // alert('获取账号信息失败...请稍后重试!');
	        }
	   });
}
	function outSys() {
         $.ajax({
	        type: "POST",
	        dataType: "json",
	        //cache:true,
	        url: "json/loginAction_out.action?request_locale=zh_CN",
	        success: function(json) {
		         if (json.flag==true) {
			          
			          // deletePointAndrows();//删除地图中的所有点和表格中的数据 
			           //deleteALLGroup();//删除所有组数据
			           //$("#time").text("");//关闭倒计时
			           window.location.href = "index.jsp";
			           map.toCenter(103,32,2);//还原map
		         }else {
		            $.messager.alert('错误', json.msg, 'error');
		         }
	        },
	        error: function() {
	             $.messager.alert('错误', '获取账号信息失败...请联系管理员!', 'error');
	        }
	   });
	}
//加载类型设置
function loadTypeSet(){
    var loadType=$.cookie('loadType');
    if(loadType==0){
       $("#loadGroup").attr("checked", "checked");
    }
    
    $("#loadTypeSet").show();
	$("#loadTypeSet").window({
		title: '系统设置',
		width: 300,
		height: 150,
		modal: true,
		shadow: false,
		closable: true,
		maximizable: false,
		minimizable: false,
		collapsible: false,
		resizable: false,
		iconCls:"icon-save"
	}); 
}

function setLoadType(){
     var type=$("input[name='loadtype']:checked").val();   
     $.cookie('loadType',type);
     $('#loadTypeSet').window('close');
     $("#loadTypeSet").hide();
}
$(function(){
	$(document).keydown(function(event){
		if ((event.altKey)&& 
		  ((event.keyCode==37)||   //屏蔽 Alt+ 方向键 ← 
		   (event.keyCode==39)))   //屏蔽 Alt+ 方向键 → 
	   { 
		   event.returnValue=false; 
		   var r=confirm("是否离开当前页面,当前数据将清空!"); 
		   return r;
	   } 
		if(event.keyCode==116){
			var r=confirm("是否离开当前页面,当前数据将清空!"); 
		   return r; //屏蔽F5刷新键 
		}
		if((event.ctrlKey) && (event.keyCode==82)){
			var r=confirm("是否离开当前页面,当前数据将清空!"); 
		   return r; //屏蔽alt+R 
		}
	});
});
function gettextType(data){
  var msg;
  switch(data)
  {
    case 0:
	  msg="系统管理员";
	  break;
	case 1:
	  msg="一级管理员";
	  break;
	case 2:
	  msg="二级管理员";
	  break;
    case -1:
      msg="普通监控员";
      break;
    case 10:
     msg="演示账号";
     break;
    case -100:
     msg="个人用户";
     break;
  }
  
  return msg;
}
