//获取地址栏的参数
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i = 0; i < vars.length; i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
	return '';
}
$(function(){
	loginSign();
})

function loginSign(){
	var code = getQueryVariable("code");
	var exiturl = getQueryVariable("exiturl");
	$.ajax({
		type:"Post",
		url:"loginSign/login.do",
		data:{ 
			code:code,
			exiturl:exiturl
		},
		dataType:"json",
		success:function(data){
			//location.href = exiturl;
			localStorage.setItem("Nianjianexiturl", exiturl)
			if(data.success=="true"){
				loginIn()
			}else{
				alert(data.message);
			}
		}
	});	
}

function loginIn(){
	$.ajax({
		type:"Post",
		url:"loginSign/loginIn.do",
		dataType:"json",
		success:function(data){
			if(data.success=='true'){
				var TOKEN=data.message;
				localStorage.setItem(TOKEN, TOKEN);
				localStorage.setItem(TOKEN+"orgid", data.orgid);
				window.location.href="view/index.html?JSONID="+TOKEN;
			}else{
				alert("登录失败");
			}
		}
	});	
}