﻿var password;
var passport;
var journalId = 0;
var textId = 0;

function GoLawReport(jid, tid) {
	journalId = jid;
	if (tid != null) {textId = tid;}

	var l = new RequestAdapter();
	l.handleXML = function(xml) {
		HasLogin(xml);
	}
	var req = new Request(l);
	req.doGet('/Ajax/Login.aspx?time='+Math.random());
}

function HasLogin(xml) {
	node = xml.documentElement;
	var login = parseInt(node.getAttribute('islogin'));
	if (login==0) {
		ReportLoginForm();
	}
	else {GoReport();}
}

function GoReport() {
	var url = '/UI/EJournal/LawReport.aspx?JournalID=' + journalId + '#T' + textId;
	document.location.href = url;
	top.moveTo(0,0);
	top.resizeTo(screen.availWidth, screen.availHeight);

//	var theFrom = document.getElementById('LawReportForm');
//	if (theFrom == null) {
//		theForm = document.createElement('form');
//		theForm.id = "LawReportForm";
//	}
//	theForm.target = '_blank';
//	theForm.method = 'post';
//	theForm.action = '/UI/EJournal/LawReport.aspx?JournalID=' + journalId + '#T' + textId;
//	document.body.appendChild(theForm);
//	alert(theForm.action);
//	theForm.submit();
//	var anchor = document.getElementById('LawReportLink');
//	if (anchor == null) {
//		anchor = document.createElement('A');
//		anchor.id = 'LawReportLink';
//	}
//	anchor.setAttribute('href', url);
//	anchor.setAttribute('target', '_blank');
//	anchor.setAttribute('style', 'display:none;');
//	document.body.appendChild(anchor);
//	alert(anchor.href);
//	anchor.click();
}

function OpenReportLoginForm() {
	window.open('');
}

function ReportLoginForm() {
	var sb = [];
	sb[sb.length] = '	<div id="ReportLoginForm" style="width:457px; border: 1px solid #000000;position:absolute;position:absolute;left:auto;top:600;z-index:9;">';
	sb[sb.length] = '		<div style="height:30px;text-align:right;background-color:#1A54AD;"><img src="/Images/delete.png" alt="关闭" onclick="ReportLoginFormClose();" style="margin: 8px 10px 0px 0px;cursor:pointer;" /></div>';
	sb[sb.length] = '		<div style="width:456px; height:234px; background-image:url(/Images/bg.login.jpg); text-align:center;">';
	sb[sb.length] = '			<div style="height:80px;"></div>';
	sb[sb.length] = '			<div style="width:250px; color:#333333; text-align:left;">';
	sb[sb.length] = '				法律报告每月发布由会员专享。<br/>涵盖行业法律咨询和法律风险提示等内容。<br/>如果您是会员，请直接登录：';
	sb[sb.length] = '			</div>';
	sb[sb.length] = '			<div style="width:250px;color:#333333;text-align:left;margin:10px 0px 0px 100px;">';
	sb[sb.length] = '				<div>帐号 <input type="text" name="reportport" class="txtGray" style="width:100px;" onkeypress="document.onkeydown=KeyReportLogin;" /></div>';
	sb[sb.length] = '				<div>';
	sb[sb.length] = '					密码 <input type="password" name="reportpass" class="txtGray" style="width:100px;" onkeypress="document.onkeydown=KeyReportLogin;" />';
	sb[sb.length] = '					<input type="button" id="btnReportLogin" class="btnRed" value="登 录" onclick="ReportLogin()" />';
	sb[sb.length] = '				</div>';
	sb[sb.length] = '			</div>';
	sb[sb.length] = '			<div style="color:#333333;margin-top:10px;">如果您尚未成为会员，请<a href="/UI/Corp/ContactUs.aspx" style="color:#333333;">联系我们</a></div>';
	sb[sb.length] = '		</div>';
	sb[sb.length] = '	</div>';

	var node = document.getElementById('ReportLoginForm');
	if (node == null) {
		var body = document.body;
		node = document.createElement('div');
		node.innerHTML = sb.join('');
		//node.style.posTop = document.documentElement.scrollTop + 300;
		body.appendChild(node);
		node = document.getElementById('ReportLoginForm');
	}
	node.style.display = 'block';
	//node.style.posTop = document.documentElement.scrollTop + 300;
}

function ReportLoginFormClose() {
	var node = document.getElementById('ReportLoginForm');
	if (node != null) {
		node.style.display = 'none';
	}
}

function ReportLogin() {
	if (!ReportLoginCheck()) { return false; }

	password = document.getElementById('reportpass');
	passport = document.getElementById('reportport');
	var l = new RequestAdapter();
	l.handleXML = function(xml) {
		VerifyLogin(xml);
	}
	var req = new Request(l);
	req.doGet('/Ajax/Login.aspx?password='+password.value+'&passport='+passport.value+'&time='+Math.random());
}

function VerifyLogin(xml) {
	node = xml.documentElement;
	var login = parseInt(node.getAttribute('islogin'));
	var errormsg = node.getAttribute('errormsg');
	if (login==0) {
		alert(errormsg);
	}
	else{
		ReportLoginFormClose();
		GoReport();
	}
}

function ReportLoginCheck() {
	password = document.getElementById('reportpass');
	passport = document.getElementById('reportport');

	if (passport.value == '') {
		alert('请输入登录帐号！');
		passport.focus();
		passport.select();
		return false;
	}
	if (password.value == '') {
		alert('请输入登录密码！');
		password.focus();
		password.select();
		return false;
	}

	return true;
}

function KeyReportLogin() {
	if (event.keyCode == 13) {
		var node = document.getElementById('btnReportLogin');
		node.click();
	}
}

