function check(){
	var oEditer = FCKeditorAPI.GetInstance("dizcontent") ;
	var content = oEditer.GetHTML(true); //content就是编辑器的内容的html源码了
	if(content.length<5){
		window.alert("内容过于简短，请勿灌水！");
		return false;
	} else if(content.length>10000){
		window.alert("单篇内容不能超过1万字！");
		return false;
	}
	return true;
}
function site(divid, replyer) {
	var oEditer = FCKeditorAPI.GetInstance("dizcontent") ;
	var reply = document.getElementById(divid).innerHTML;
	//window.alert(reply);
	if(reply.length>200) {
		reply = reply.substring(0, 200) + "......";
	}
	reply = "<div style='border:1px #ccc solid;padding:5px 5px 5px 5px;'>"+reply+"</div><br>to "+replyer+":<br>";
	oEditer.InsertHtml(reply);
	oEditer.Focus();
}
function replyTo(replyer) {
	var oEditer = FCKeditorAPI.GetInstance("dizcontent") ;
	var reply = "to "+replyer+":<br>";
	oEditer.InsertHtml(reply);
	oEditer.Focus();
}
function checkReply() {
	var vcode = document.getElementById("vcode").value;
	if(vcode.length == 0) {
		window.alert("请输入验证码！");
		return false;
	}
	if(!check()) {
		return false;
	}
	document.replyForm.submit();
}

var lbodyOrig = "";
var topOrig = "";
var regUserName = "";
var regPassword = "";

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>凌晨好!frank&nbsp;&nbsp;&nbsp;&nbsp;<a href='/logout.shtml'>退出</a> | <a href='/index.shtml'>首页</a>";
	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  = "1";
		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='/logout.shtml'>退出</a> | <a href='/index.shtml'>首页</a> | <a href='/bizcenter.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 quickRegister() {
	over(4);
}

function doQuickRegister() {
	var username = document.getElementById("regUserName").value;
	var pass1 = document.getElementById("password1").value;
	var pass2 = document.getElementById("password2").value;
	if(username == null) {
		window.alert("请输入注册名！");
		return false;
	}
	if(pass1 != pass2) {
		window.alert("两次密码输入不一样！");
		return false;
	}
	if(pass1.length<6) {
		window.alert("密码长度必须长于6位！");
		return false;
	}
	var lbody4 = document.getElementById("lbody4");
	var showHtml = "<table><tr><td height=150 align=center valign=middle><img src='/images/indi_2.gif'> 正在注册...</td></tr></table>";
	lbody4.innerHTML = showHtml;
	regUserName = username;
	regPassword = pass1;
	UserBoundry.register(username,pass1,afterQuickRegisterDo);
}

function afterQuickRegisterDo(result) {
	if(result == false) {
		var lbody4 = document.getElementById("lbody4");
		var showHtml = "<table><tr><td height=150 align=center valign=middle>注册失败，用户名已存在。</td></tr></table>";
		lbody4.innerHTML = showHtml;
		return false;
	} else {
		var lbody4 = document.getElementById("lbody4");
		var showHtml = "<table><tr><td height=150 align=center valign=middle><img src='/images/indi_2.gif'> 正在登陆...</td></tr></table>";
		lbody4.innerHTML = showHtml;
		//登陆
		document.getElementById("loginuser").value = regUserName;
		document.getElementById("password").value = regPassword;
		doLogin();
		unover(4);
	}
}

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)
{
	//window.alert(document.body.clientHeight + "-" + document.body.clientWidth);
	document.getElementById("overlay").style.height = document.body.clientHeight;
	document.getElementById("overlay").style.width = document.body.clientWidth;	
 	document.getElementById("overlay").style.display="block";
	locateCenter("lightbox"+index);
	document.getElementById("lightbox"+index).style.display="block";
 	if(lbodyOrig.length == 0) {
 		lbodyOrig = document.getElementById("lbody"+index).innerHTML;
 	}
}

function subsearch() {
	var stype = "4";
	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) {
	//window.alert("good");
	var stype = "5";
	var word = document.getElementById("word").value;
	if(stype == 1) {
		window.location = "/search_company.shtml?wo="+word;
	} else if(stype == 2) {
		window.location = "/search_provide.shtml?wo="+word;
	} else if(stype == 3) {
		window.location = "/search_purchase.shtml?wo="+word;
	} else if(stype == 4) {
			//window.alert("good");
		window.location = "/search_article.shtml?wo="+word;
	} else if(stype == 5) {
		window.location = "/search_discuss.shtml?wo="+word;
	}
}

function locateCenter(elem)  
{  
	var temp=document.getElementById(elem);   
	temp.style.top=document.documentElement.scrollTop+400;  
	temp.style.left=Math.round((document.body.clientWidth-temp.style.width)/2);  
}  