var notice=[];
var noticenow=0;
var lktopheight=100;
function createXmlHttp() {
	var xmlHttp;
	try{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e){
		var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
										'MSXML2.XMLHTTP.5.0',
										'MSXML2.XMLHTTP.4.0',
										'MSXML2.XMLHTTP.3.0',
										'MSXML2.XMLHTTP',
										'Microsoft.XMLHTTP');
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){
			try { 
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} 
			catch (e) {}
		}
	}
	if (!xmlHttp){
		alert("Error creating the XMLHttpRequest object.");
	}else {
		return xmlHttp;
	}
}
function clock(){
   	var today=new Date();
	var hours=today.getHours();
	var minutes=today.getMinutes();
	var seconds=today.getSeconds();
	var n=hours*60+minutes;
	var d=['日','一','二','三','四','五','六'];
	if(hours<10) hours="0"+hours;
	if(minutes<10) minutes="0"+minutes;
	if(seconds<10) seconds="0"+seconds;
	document.getElementById('mainclock').innerHTML='<span class="globaltext">'+today.getFullYear()+'年'+(today.getMonth()+1)+'月'+today.getDate()+'日</span><span class="globaltext">星期'+d[today.getDay()]+'</span><span class="globaltext">'+hours+':'+minutes+':'+seconds+'</span>';
	if(seconds==0){
		if(n==0) document.getElementById('mainsubtime').innerHTML='凌晨';
		if(n==300) document.getElementById('mainsubtime').innerHTML='清晨';
		if(n==420) document.getElementById('mainsubtime').innerHTML='早上';
		if(n==540) document.getElementById('mainsubtime').innerHTML='上午';
		if(n==720) document.getElementById('mainsubtime').innerHTML='中午';
		if(n==840) document.getElementById('mainsubtime').innerHTML='下午';
		if(n==1080) document.getElementById('mainsubtime').innerHTML='傍晚';
		if(n==1140) document.getElementById('mainsubtime').innerHTML='晚上';
	}
		
}

function subtime(){
	var today=new Date();
	var n=today.getHours()*60+today.getMinutes();
	if(n<300) return '凌晨';
	else if(n<420) return '清晨';
	else if(n<540) return '早上';
	else if(n<720) return '上午';
	else if(n<840) return '中午';
	else if(n<1080) return '下午';
	else if(n<1140) return '傍晚';
	else return '晚上';
}
function sethomepage(){
	if (document.all){
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(document.URL);
	}else if (window.sidebar){
		if(window.netscape){
			try{  
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
			}catch (e){
				alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );  
			}
		} 
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage', document.URL);
	}
}
function addfavorite(){
	try{
		window.external.addFavorite(document.URL, document.title);
	}
	catch (e){
		try{
			window.sidebar.addPanel(document.title, document.URL, "");
		}catch (e){
			alert("加入收藏失败，请使用Ctrl+D进行添加");
		}
	}
}
function fresh(){
	var url = 'http://www.x-un.com/fresh.html';
	xmlHttp.open('POST', url, true);
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				var r=eval('('+xmlHttp.responseText+')');
				document.getElementById('noticenum').innerHTML='<img src="image/impnotice.gif" alt="" title="" /><a href="csmsnotice.html">系统公告[0]</a><img src="image/notice.gif" alt="" title="" /><a href="csmsinfo.html">提醒消息['+r[1]+']</a><img src="image/newmail.gif" alt="" title="" /><a href="csms.html">站内信['+r[2]+']</a>';
				notice=r[4];
				noticenow=0;
				if(r[3]==0 || r[4].length==0){
					document.getElementById('notice_c').innerHTML='<img src="image/impnotice.gif" alt="" title="" />暂无系统公告';
				}else{
					document.getElementById('notice_c').innerHTML='<img src="image/impnotice.gif" alt="" title="" />公告：'+r[4][0].title;
				}
				if(r[3]!=0){
					var k=0;
					for(var i=0;i<r[4].length;i++){
						if(r[4][i].id>r[0]) k++;
						else break;
					}
					document.getElementById('noticenum').innerHTML='<img src="image/impnotice.gif" alt="" title="" /><a href="csmsnotice.html">系统公告['+k+']</a><img src="image/notice.gif" alt="" title="" /><a href="csmsinfo.html">提醒消息['+r[1]+']</a><img src="image/newmail.gif" alt="" title="" /><a href="csms.html">站内信['+r[2]+']</a>';
					var num=k+(r[1]-0)+(r[2]-0);
					if(num) document.getElementById('csmstotalnums').style.display='';
					else document.getElementById('csmstotalnums').style.display='none';
				}
			}
		}
	};
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	xmlHttp.send('id='+Math.random());
}



function homestylebgss(type){
	xmlHttp.open('POST', 'ajaxphoto.html', true);
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				if(xmlHttp.responseText){
					var info=eval('('+xmlHttp.responseText+')');
					if(info[0]=='0'){ alert(info[1]);	return;	}
					var s=info[3];
					var i;
					stylebgimglist=info[2];
					document.getElementById('lktitle').innerHTML='<img src="image/info.png" alt="" title="" />&nbsp;&nbsp;'+((type==1) ? '全站' : ((type==2) ? '个人中心' : '社区'))+'页面背景设置：';
					for(i=0;i<info[1].length;i++) s+='<a href="javascript:void(0);" onclick="homestyleselalbum('+info[1][i][0]+')" >'+info[1][i][1]+'['+info[1][i][2]+']</a>';
					s+='<div id="homestyleselbox"><img class="homestyleselimg" src="image/browleft1.gif" width="18" height="53" onclick="homestylebgset('+(info[2].length-1)+')" onmouseover="this.src=\'image/browleft2.gif\'" onmouseout="this.src=\'image/browleft1.gif\'" />';
					s+='<div class="homestylemid"></div>';
					s+='<div class="homestylemidsel"><img src="system/image/photo/'+info[2][0][2]+'" alt="" title="" width="132" height="99" /></div>';
					s+='<div class="homestylemid">'+((info[2].length>1) ? '<img src="system/image/photo/'+info[2][1][2]+'" alt="" title=""  onclick="homestylebgset(1)" width="132" height="99" />' : '')+'</div>';
					s+='<img class="homestyleselimg" src="image/browright1.gif" width="18" height="53" onclick="homestylebgset('+((info[2].length>1) ? 1 : 0)+')" onmouseover="this.src=\'image/browright2.gif\'" onmouseout="this.src=\'image/browright1.gif\'" /></div>';
					s+='<input type="hidden" id="homestylebgsettype" value="'+type+'" /><input type="hidden" id="homestylebglistsel" value="0" />';
					s+='<p align="center"><input type="image" src="image/confirm1.gif" onclick="homestylebgsetss()" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="image" src="image/cancel1.gif" onclick="lkcloses()" /></p>';
					document.getElementById('lkcontent').innerHTML=s;
					document.getElementById('lkbg').style.display='';
					document.getElementById('lkbox').style.display='';
				}else{
					alert('登录超时');
				}
			}
		}
	};
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	xmlHttp.send('type='+type+'&act=homebg');
}
function homestyleselalbum(id){
	xmlHttp.open('POST', 'ajaxphoto.html', true);
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				if(xmlHttp.responseText){
					stylebgimglist=eval('('+xmlHttp.responseText+')');
					var s='<img class="homestyleselimg" src="image/browleft1.gif" width="18" height="53" onclick="homestylebgset('+(stylebgimglist.length-1)+')" onmouseover="this.src=\'image/browleft2.gif\'" onmouseout="this.src=\'image/browleft1.gif\'" />';
					s+='<div class="homestylemid"></div>';
					s+='<div class="homestylemidsel"><img src="system/image/photo/'+stylebgimglist[0][2]+'" alt="" title="" width="132" height="99" /></div>';
					s+='<div class="homestylemid">'+((stylebgimglist.length>1) ? '<img src="system/image/photo/'+stylebgimglist[1][2]+'" alt="" title=""  onclick="homestylebgset(1)" width="132" height="99" />' : '')+'</div>';
					s+='<img class="homestyleselimg" src="image/browright1.gif" width="18" height="53" onclick="homestylebgset('+((stylebgimglist.length>1) ? (1) : 0)+')" onmouseover="this.src=\'image/browright2.gif\'" onmouseout="this.src=\'image/browright1.gif\'" /></div>';
					document.getElementById('homestylebglistsel').value=0;
					document.getElementById('homestyleselbox').innerHTML=s;
				}
			}
		}
	};
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	xmlHttp.send('id='+id+'&act=homebgalbum');
}
function homestylebgset(id){
	var s='<img class="homestyleselimg" src="image/browleft1.gif" width="18" height="53" onclick="homestylebgset('+(id ? (id-1) : (stylebgimglist.length-1))+')" onmouseover="this.src=\'image/browleft2.gif\'" onmouseout="this.src=\'image/browleft1.gif\'" />';
	s+='<div class="homestylemid">'+(id ? '<img src="system/image/photo/'+stylebgimglist[id-1][2]+'" alt="" title=""  onclick="homestylebgset('+(id-1)+')" width="132" height="99" />' : '')+'</div>';
	s+='<div class="homestylemidsel"><img src="system/image/photo/'+stylebgimglist[id][2]+'" alt="" title="" width="132" height="99" /></div>';
	s+='<div class="homestylemid">'+((id+1<stylebgimglist.length) ? '<img src="system/image/photo/'+stylebgimglist[id+1][2]+'" alt="" title=""  onclick="homestylebgset('+(id+1)+')" width="132" height="99" />' : '')+'</div>';
	s+='<img class="homestyleselimg" src="image/browright1.gif" width="18" height="53" onclick="homestylebgset('+((stylebgimglist.length>id+1) ? (id+1) : 0)+')" onmouseover="this.src=\'image/browright2.gif\'" onmouseout="this.src=\'image/browright1.gif\'" /></div>';
	document.getElementById('homestylebglistsel').value=id;
	document.getElementById('homestyleselbox').innerHTML=s;
}
function homestylebgsetss(){
	var id=parseInt(document.getElementById('homestylebglistsel').value);
	var type=parseInt(document.getElementById('homestylebgsettype').value);
	var length=0;
	try{
		length=(type==3) ? 0 : (document.getElementById('homebglength').selectedIndex+1);
	}catch(e){}
	xmlHttp.open('POST', 'ajaxphoto.html', true);
	xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200){ 
		if(xmlHttp.responseText){
			if(xmlHttp.responseText){
				var info=eval('('+xmlHttp.responseText+')');
				if(info[0]){
					location.reload();
				}else{
					alert(info[1]);
				}
			}else{
				alert('登录超时');
			}
		}
	} } };
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	xmlHttp.send('id='+stylebgimglist[id][0]+'&length='+length+'&type='+type+'&act=homebgset');
}


function sharecontent(type, sid){
	if(type==0 || sid==0){
		return;
	}
	xmlHttp.open('POST', 'ajaxshare/create.html', true);
	xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200){ 
		if(xmlHttp.responseText){
			alert(xmlHttp.responseText);
		}else{
			alert('请先登录');
		}
	} } };
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	xmlHttp.send('sid='+sid+'&type='+type);
}
function reportcontent(){
	if(currentuid==0){
		alert('请先登录');
		return;
	}
	document.getElementById('lktitle').innerHTML='<img src="image/info.png" alt="" title="" />&nbsp;&nbsp;请填写举报理由：';
	document.getElementById('lkcontent').innerHTML='<textarea id="reportreason" cols="60" rows="4" style="overflow:hidden"></textarea><div class="clear"></div><input type="image" src="image/submit.gif" alt="" title="" onclick="reportscontent(); return false;" style="margin: 12px;" />';
	document.getElementById('lkbg').style.display='';
	document.getElementById('lkbox').style.display='';
}
function reportscontent(){
	var reason=document.getElementById('reportreason').value;
	if(reason==''){
		alert('理由不能为空');
		return false;
	}
	xmlHttp.open('POST', 'ajaxcore/report.html', true);
	xmlHttp.onreadystatechange = function(){if (xmlHttp.readyState == 4){if (xmlHttp.status == 200){
		alert(xmlHttp.responseText);
		document.getElementById('lkbg').style.display='none';
		document.getElementById('lkbox').style.display='none';
	}}};
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	xmlHttp.send('reason='+encodeURIComponent(reason)+'&url='+encodeURIComponent(document.URL));
}
function replycontent(){
	var d=document.msgform.elements;
	var type=parseInt(d['type'].value);
	var sid=parseInt(d['sid'].value);
	var replyto=parseInt(d['replyto'].value);
	var uid=parseInt(d['uid'].value);
	var total=parseInt(d['total'].value);
	var page=parseInt(d['page'].value);
	var msg=d['msg'].value.replace(/(^\s*)|(\s*$)/g,"");
	if(msg==''){
		alert('请填写评论内容');
		return;
	}
	if(type && sid){
		xmlHttp.open('POST', 'ajaxcore/reply.html', true);
		xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200){ 
			var info=eval('('+xmlHttp.responseText+')');
			if(info[0]){
				var totalpage=Math.ceil(total/12);
				if(totalpage==0) totalpage=1;
				if(totalpage==page){
					document.getElementById('replyboxmain').innerHTML+=info[1];
				}else{
					alert('评论成功');
				}
				d['msg'].value='';
				d['replyto'].value='';
			}else{
				alert(info[1]);
			}
		} } };
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
		xmlHttp.send('sid='+sid+'&type='+type+'&replyto='+replyto+'&uid='+uid+'&msg='+encodeURIComponent(msg));
	}
}
function getcontentreply(type, sid, page){
	var d=document.msgform.elements;
	var uid=parseInt(d['uid'].value);
	var total=parseInt(d['total'].value);
	xmlHttp.open('POST', 'ajaxcore/replypage.html', true);
	xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200){ 
		var info=eval('('+xmlHttp.responseText+')');
		if(info[0]){
			document.getElementById('replyboxmain').innerHTML=info[1];
			document.getElementById('replypagesplit').innerHTML=info[2];
			d['msg'].value='';
			d['replyto'].value='';
			d['page'].value=page;
		}else{
			alert(info[1]);
		}
	} } };
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	xmlHttp.send('uid='+uid+'&sid='+sid+'&total='+total+'&type='+type+'&page='+page);
}
function replytouser(id, name){
	document.msgform.elements['replyto'].value=id;
	document.msgform.elements['msg'].focus();
	document.msgform.elements['msg'].value='回复'+name+'：';
}
function refresh(){
	fresh();
	setTimeout('refresh()',300000);
}
var xmlHttp = createXmlHttp();

function isempty(key){
	key =key.replace(/(^\s*)|(\s*$)/g,"");
	if(key == ""){
		return true;
	}
	return false;
}

function issuitvar(str){ 
	var reg=/[^A-Za-z0-9_]/g ;
	if (reg.test(str)){ 
		return false; 
	}else{ 
		return true;
	} 
}

function isnumber( s ){ 
	var regu = "^[0-9]+$"; 
	var re = new RegExp(regu); 
	if (s.search(re) != -1) { 
		return true; 
	} else { 
	return false; 
	} 
} 

function   isphone(String){  
	var   Letters   =   "1234567890-";
	var   i;
	var   c;
	if(String.charAt(0)=='-'){
		return   false;
	}
	if(String.charAt(String.length-1) == '-'){
		return   false;
	}
	for(i = 0; i < String.length; i++ ){  
		c = String.charAt(i);
		if(Letters.indexOf(c) == -1){
			return   false;
		}
	}
	return   true;
}


function isemail( str ){ 
	var myReg = /^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/; 
	if(myReg.test(str)){
		return true; 
	} 
	return false; 
} 

function isip(strIP) { 
 
	var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g;
	if(re.test(strIP)) { 
		if( RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256){
			return true; 
		} 
	} 
	return false; 
}

function ismoney( s ){ 
	var regu = "^[0-9]+[\.][0-9]{0,3}$"; 
	var re = new RegExp(regu); 
	if (re.test(s)) { 
		return true; 
	} else { 
		return false; 
	} 
}
function getwebbrower(){
	var str=navigator.userAgent; 
	if(str.indexOf('MSIE')>0) return 'IE';
	if(str.indexOf('Firefox')>0) return 'FF'; 
	if(str.indexOf('Safari')>0) return 'Safari';  
	if(str.indexOf('Camino')>0) return 'Camino'; 
	if(str.indexOf('Gecko/')>0) return 'Gecko'; 
	return '';
}
var webbrower=getwebbrower();

function copytext(txt){
	if(window.clipboardData){
		window.clipboardData.clearData();
		window.clipboardData.setData("Text",txt);
		alert('地址已复制，您可以方便的把它发送给好友');
	}else if(navigator.userAgent.indexOf("Opera")!=-1){
		window.location=txt;
		alert('地址已复制，您可以方便的把它发送给好友');
	}else if(window.netscape){
		try{
	 		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}catch(e){
			alert("您的firefox安全限制限制您进行剪贴板操作，请打开’about:config’将signed.applets.codebase_principal_support’设置为true’之后重启firefox，相对路径为firefox根目录/greprefs/all.js");
			return false;
		}
		var clip=Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if(!clip)return;
		var trans=Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if(!trans)return;
		trans.addDataFlavor('text/unicode');
		var str=new Object();
		var len=new Object();
		var str=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext=txt;str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if(!clip)return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
		alert('地址已复制，您可以方便的把它发送给好友');
	}
}
function lkcloses(){
	document.getElementById('lkbg').style.display='none';
	document.getElementById('lkbox').style.display='none';
}
function bannerhit(id){
	xmlHttp.open('POST', 'ajaxbanner/hit.html', true);
	xmlHttp.onreadystatechange = function(){};
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	xmlHttp.send('id='+id);
}
