var lbodyOrig = "";
var topOrig = "";

function initTop() {
	var tophtml = "<span><a href='/' onclick=style.behavior='url(#default#homepage)';setHomePage('http://www.soidc.net');>设为首页</a>&nbsp;|&nbsp;<a href='javascript:saveme()'>收藏本站</a></span><form name=f1 onsubmit='doLogin()'>用户名：<input type='text' name='loginUserName' id='loginuser' class='in1' />&nbsp;密码：<input type='password' name='password' id='password' class='in1' />&nbsp;<input name=imageField type=image src='/images/bt01.gif' value='登录'/>&nbsp;<img src='/images/bt02.gif' style='cursor:pointer' onclick=\"location.replace('http://www.soidc.net/register_form.shtml')\"/>&nbsp;<img src='/images/findpass.gif' style='cursor:pointer' onclick='findPassword()'/></form>";
	var top = document.getElementById("top");
	top.innerHTML = tophtml;
}

function doLogin() {
 	if(topOrig.length == 0) {
 		topOrig = document.getElementById("top").innerHTML;
 	}
	var loginUser = document.getElementById("loginuser").value;
	var password = document.getElementById("password").value;
	var top = document.getElementById("top");
	var loginHtml = "<img src='/images/indi.gif'> 正在登录...";
	top.innerHTML = loginHtml;
	LoginBoundry.login(loginUser,password,afterLogin);
}

function afterLogin(user) {
	if(user == "-1") {
		window.alert("登录错误，请确认用户名和密码。");
		document.getElementById("top").innerHTML = topOrig;
	} else {
		var top = document.getElementById("top");
		var uname = user;
		var hello = "";
		var hours  = "20";
		if(hours >= 1 && hours < 5) {
			hello = "凌晨好!";
		} else if(hours >= 5 && hours < 11) {
			hello = "早上好!";
		} else if(hours >= 11 && hours < 13) {
			hello = "中午好!";
		} else if(hours >= 13 && hours < 18) {
			hello = "下午好!";
		} else if(hours >= 18 && hours < 23) {
			hello = "晚上好!";
		} else {
			hello = "午夜好!";
		}
		var a = "<span><a href='/' onclick=style.behavior='url(#default#homepage)';setHomePage('http://www.soidc.net');>设为首页</a>&nbsp;|&nbsp;<a href='javascript:saveme()'>收藏本站</a></span>";
		var tophtml = a + hello + uname;
		tophtml =  tophtml + "&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.soidc.net/logout.shtml'>退出</a> | <a href='http://www.soidc.net/index.shtml'>首页</a>";
		top.innerHTML = tophtml;
	}
}

function findPassword() {
	over(1);
}

function findPasswordDo() {
	var regname = document.getElementById("regname").value;
	var regmail = document.getElementById("regmail").value;
	var lbody1 = document.getElementById("lbody1");
	var showHtml = "<table><tr><td height=150 align=center valign=middle><img src='/images/indi_2.gif'> 正在为您找回...</td></tr></table>";
	lbody1.innerHTML = showHtml;
	//window.alert(regname+"==="+regmail);
	UserBoundry.getPassword(regname,regmail,afterFindPasswordDo);
}

function afterFindPasswordDo(result) {
	var lbody1 = document.getElementById("lbody1");
	var showHtml = "<table><tr><td height=150 align=center valign=middle>已经为您生成新密码，请去邮箱收取。</td></tr></table>";
	if(result == false) {
		showHtml = "<table><tr><td height=150 align=center valign=middle><img src='/images/error.gif'> 找回失败，用户名不存在或邮箱有误。</td></tr></table>";
	}
	lbody1.innerHTML = showHtml;
}

function saveme(){ 
	url = "http://www.soidc.net";
	title = "IDC专家网";
	window.external.AddFavorite(url,title); 
} 

function unover(index)
{
  	document.getElementById("overlay").style.display="none";
  	document.getElementById("lightbox"+index).style.display="none";
  	document.getElementById("lbody"+index).innerHTML = lbodyOrig;
}

function over(index)
{
	document.getElementById("overlay").style.height = document.body.clientHeight;
	document.getElementById("overlay").style.width = document.body.clientWidth;	
	document.getElementById("lightbox"+index).style.display="block";
 	document.getElementById("overlay").style.display="block";
 	if(lbodyOrig.length == 0) {
 		lbodyOrig = document.getElementById("lbody"+index).innerHTML;
 	}
}

function subsearch() {
	var stype = "1";
	if(stype == 1) {
		over(2);
		var word = document.getElementById("word").value;
		SearchBoundry.searchCompany(word, afterSearch);
	} else if(stype == 2) {
		over(2);
		var word = document.getElementById("word").value;
		SearchBoundry.searchProvide(word, afterSearch);
	} else if(stype == 3) {
		over(2);
		var word = document.getElementById("word").value;
		SearchBoundry.searchPurchase(word, afterSearch);
	} else if(stype == 4) {
		over(2);
		var word = document.getElementById("word").value;
		SearchBoundry.searchArticle(word, afterSearch);
	} else if(stype == 5) {
		over(2);
		var word = document.getElementById("word").value;
		SearchBoundry.searchDiscuss(word, afterSearch);
	}
	return false;
}

function afterSearch(result) {
	var stype = "4";
	var word = document.getElementById("word").value;
	if(stype == 1) {
		window.location = "http://www.soidc.net/search_company.shtml?wo="+word;
	} else if(stype == 2) {
		window.location = "http://www.soidc.net/search_provide.shtml?wo="+word;
	} else if(stype == 3) {
		window.location = "http://www.soidc.net/search_purchase.shtml?wo="+word;
	} else if(stype == 4) {
		window.location = "http://www.soidc.net/search_article.shtml?wo="+word;
	} else if(stype == 5) {
		window.location = "http://www.soidc.net/search_article.shtml?wo="+word;
	}
}

