var useAjaxPost=1;
var post_time=10;  //倒计时 秒数
var n=post_time;
function gid(id) {
	var itm = null;
	if (document.getElementById) {itm = document.getElementById(id);}
	else if (document.all) {itm = document.all[id];}
	else if (document.layers) {itm = document.layers[id];}
	return itm;
}
function getByName(_name) {return document.getElementsByName(_name);}
function AjaxPost(){
	var base=this;
	this.postForm=function(_form){
		if (useAjaxPost != 1) return true;
		var data="";		
		if(_form){		
			postErr(0,1);
			data+="action=chkpwd&pwd="+escape(escape(String(_form.elements[0].value)))+"&id="+_form.elements[1].value+"&ajaxpost="+useAjaxPost+"&memberid="+escape(_form.elements[3].value)+"";
			//alert(data);
			var xmlhttp;
			try{
				xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try{
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(e){
					try{
						xmlhttp= new XMLHttpRequest();
					}catch(e){}
				}
			}
			xmlhttp.onreadystatechange=function(){
				if(xmlhttp.readyState==4)
				{
					base.xmlhttp = xmlhttp;
					if(xmlhttp.status==200){
						//postErr(xmlhttp.responseText);
						base.onsuccess();
					}else{
						base.onfailure();
					}
				}				
			}
			xmlhttp.open(_form.method, _form.action, true);
			xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			xmlhttp.send(data.replace("&&","&"));
		}
		return false;
	}
	this.onsuccess=function(){};
	this.onfailure=function(){};
	this.replace=function(str){
		var con=str;
			con=con.replace(/%A0/gi,"%20");
			con=con.replace(/\+/gi,"%2B");
			return con;
	}
}
var ajaxpost=new AjaxPost()
var trycount=5;
ajaxpost.onsuccess=function(){
var sucmsg=this.xmlhttp.responseText;
var suc=sucmsg.split(",");
if (suc.length<2){postErr(sucmsg,0);return false;}
if (parseInt(suc[3])==0){postErr("请登录论坛后操作",0);gid("chk").disabled=true;return false;}
	if (parseInt(suc[1])==1){ /*密码正确s*/
	 delCookie(suc[2]+"trycount"+suc[3]);
	window.location.href="dv_album.asp?action=show&id="+suc[2]+"";
	return;
	  /*密码正确e*/
	}else{ /*密码错误s*/
			if (readCookie(suc[2]+"trycount"+suc[3])>=5)
			{
				postErr("明天再试试",0);
				gid("chk").disabled=true;
				return false;
			}
			else
			{
				var c=(readCookie(suc[2]+"trycount"+suc[3]))?parseInt(readCookie(suc[2]+"trycount"+suc[3]))+1:1;
				createCookie(suc[2]+"trycount"+suc[3],c,1)	
				if(parseInt(trycount-c)==0){postErr("明天再试试",0); gid("chk").disabled=true;return false;}else{postErr(suc[0]+",今天还有"+parseInt(trycount-c)+"次机会",0);}
			}
			/*密码错误e*/
	}
}
ajaxpost.onfailure=function()
{
	postErr(this.xmlhttp.responseText,0);
}
function checkLogin(theform)
{
	if (theform.pwd.value=="" )
	{
		postErr("请输入您的密码",0);
		theform.pwd.focus();
		return false;
	}
	return ajaxpost.postForm(theform);
	/*return true;*/
}
function postErr(str,tp)
{
	var lg=gid("msg")
	if(tp==0)
	{
		lg.innerHTML='<img src="images/note_error.gif" width="16" height="16" alt="Err" />&nbsp;&nbsp;<span style="color:#ff0000;">'+str+'</span>';	
	}
	else
	{
		lg.innerHTML='<img src="images/loading_small.gif" alt="登录中">登录中...';
	}
}
function createCookie(name,value,days)
{
	var expires = "";
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c =ca[i].replace( /^\s*/,"");
		if (c.indexOf(nameEQ) == 0)
		{
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}
function delCookie(name)
{
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=readCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
var copytoclip=1;
function copyToClipboard(theField,isalert) {
	var tempval=gid(theField);	
	if (navigator.appVersion.match(/\bMSIE\b/)){
		tempval.select();
		if (copytoclip==1){
			therange=tempval.createTextRange();
			therange.execCommand("Copy");
			if(isalert!=false)alert("复制成功。现在您可以粘贴（Ctrl+v）到Blog 或 BBS中了。");
		}
		return;
	}else{
		alert("您使用的浏览器不支持此复制功能，请使用Ctrl+C或鼠标右键。");
		tempval.select();
	}
}
// 根据鼠标或焦点事件，设置文本框和按钮样式,此函数会与样式相关
function IEvent(sType,oInput)
{
	var onStyle,offStyle,eleType;
	eleType = oInput.type;
	// 设置关联样式
	if("button" == eleType || "submit" == eleType || "reset" == eleType || "textarea" == oInput.tagName)
	{
		onStyle = "button_on";
		offStyle = "button_off";
	}
	else
	{
		onStyle = "input_on";
		offStyle = "input_off";
	}
	// 根据事件选择样式
	switch (sType)
	{
		case "focus" :
			oInput.isfocus = true;
		case "mouseover" :
			oInput.className = onStyle;
			break;
		case "blur" :
			oInput.isfocus = false;
		case "mouseout" :
			if(!oInput.isfocus)
			{
				oInput.className = offStyle;
			}
			break;
	}
}
function chkpwd(){
	if ((gid("Radio_1_2").checked)&&gid("accesspwd").value=="")
	{
		gid("msg_password").innerHTML="<font color=red>请输入密码</font>";
	}else{
    	gid("msg_password").innerHTML="";
	}
}
function showfm(chk,id){gid(id).style.display=chk?'block':'none';}
function showfmimg(file){
var o=document.getElementById("albumfm");
o.style.width="100";
o.alt="编辑时此图为封面";
o.src=file;
}
function chkform(f){
	if (f.albumtitle.value==""){
		gid("msg_title").innerHTML="<font color=red>标题不能为空</font>";return false;
	}else if(f.albumtext.value==""){
		gid("msg_text").innerHTML="<font color=red>描述不能为空</font>";return false;
	}else if ((gid("Radio_1_2").checked)&&gid("accesspwd").value==""){
		gid("msg_password").innerHTML="<font color=red>请输入密码</font>";return false;
	}
	return true;
}
function SetCover(){
	//Attribute
	var this_=this;
	var a=navigator.userAgent;
	this.isIE=a.search('MSIE')>0;
	this.isIE8=a.search('MSIE 8.0')>0;
	this.isFF=a.indexOf('Gecko')!=-1&&!(a.indexOf('KHTML')>-1||a.indexOf('Konqueror')>-1||a.indexOf('AppleWebKit')>-1);
	this.isFF=this.isFF;
	a=window;a.s__=a.s__||new Array();a.s__.push(this);
	this.i=a.s__.length-1;
	var b='set_'+this.i+'_';
	this.x={c:b+'_css',t:b+'_top',r:b+'_right',b:b+'_bottom',l:b+'_left',s:b+'_show',i:b+'_id',ty:b+'_type'};
	this.d='window.s__['+this.i+']';
    this.c=null;
	this.show='<div unselectable="on">请输入图片地址，仅支持jpg,gif,png,jpeg,bmp。<br/>（如：http://bbs.niutou.net/images/logo.gif）</div>';
	this.show+='<div unselectable="on"><input id="'+this.x.b+'_image_url" type="text" class="dveditborder" value="http://" style="width:300px;" /></div>';
	this.show+='<div unselectable="on"><input unselectable="on" type="button" value="确定" onclick="'+this.d+'.simg()" /> <input unselectable="on" type="button" value="取消" onclick="'+this.d+'.close()" /></div>';
	this.x.ty='jpg,gif,png,jpeg,bmp';
	//Method
	this.$=function(o){var itm = null;if (document.getElementById) {itm = document.getElementById(o);}else if (document.all) {itm = document.all[o];}else if (document.layers) {itm = document.layers[o];}return itm;};
	this.$t=function(t,d){return (d||document).getElementsByTagName(t)};
	this.simg=function(){
	if (!this.cty()){alert('图片格式不正确');return;}
	var a=this.$("albumfm"),b=this.$("albumcover");
	a.src=this.$(this.x.b+'_image_url').value;
	a.alt=this.$(this.x.b+'_image_url').value;
	a.width="100";
	b.value=this.$(this.x.b+'_image_url').value;
	};
	this.cty=function(){
	var s=this.$(this.x.b+'_image_url').value;
	s=s.substring(s.lastIndexOf('.')+1);
	if (this.x.ty.indexOf(s)==-1){return false;}return true;
	};
	this.loadCss=function(p,re){var a=this.$t('link'),o=null;if (a){for (var i=a.length-1;i>=0;--i){if (-1!=a[i].href.indexOf('main')){if (re){o=a[i];}else{return;}}}};if (!o){o=document.createElement('link');o.rel='stylesheet';o.type='text/css';};o.href=p;try{this.$t('head')[0].appendChild(o);}catch(e){;}};
	this.open=function(){
		var w=this.$('set_0__id');
		w.innerHTML=this.show;
		w.style.display="block";
	};
	this.close=function(){
		var w=this.$('set_0__id'),b=this.$("albumcover");
		w.style.display="none";
		var a=this.$("albumfm");
		a.src="albumfiles/img/nophoto_bk.gif";
		a.alt="未设置封面";
		a.width="72";
		b.value="albumfiles/img/nophoto_bk.gif";
	};
	this.init=function(){
	this.loadCss('albumfiles/css/main.css',false);
	document.writeln('<div id="'+this.x.i+'" style="display:none;" class="dvedittoolbar" style="text-align:left;text-indent:0;"></div>');
	};
	this.init();
}
function changecover(id){
	var data="id="+id;
	var xmlhttp;
	try{
		xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			try{
				xmlhttp= new XMLHttpRequest();
			}catch(e){alert("您的浏览器太老不支持");}
		}
	}
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			if(xmlhttp.status==200){
				showresult(xmlhttp.responseText);
			}else{
				showresult(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.open("post","dv_albumimg.asp?action=changecover", true);
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlhttp.send(data.replace("&&","&"));
}
function showresult(str){
	var re,img;
	re=str.split(",");
	img=document.getElementById("albumcover");
	if (parseInt(re[0])==0){
		img.src=re[1];
		img.style.width="100";
	}else{
		alert(re[1]);
	}
}
function show(id){
var o=gid('edit_'+id);
o.style.display='none';
o=gid('bbs_'+id);
o.style.display='none';
o=gid('e_bbs_'+id);
o.style.display='block';
}
function close2(id){
var o=gid('edit_'+id);
o.style.display='block';
var e=gid('bbs_'+id);
e.style.display='block';
var t=gid('e_bbs_'+id);
t.style.display='none';
}
function ae(o,t,h){if (o.addEventListener){o.addEventListener(t,h,false);}else if(o.attachEvent){o.attachEvent('on'+t,h);}else{try{o['on'+t]=h;}catch(e){;}}}
function closeAjaxDiv(id) {gid(id).style.display = "none";}
var ajaxpostalbumbbs=new AjaxPostAlbumBbs()

function DvAlbumBbs(){
	var a=arguments;
	this.$=function(o){return document.getElementById(o);}
	this.frm=a[0]||document.forms[0];//发表表单对象
	this.evt=a[1]||window.event;//事件对象
	this.mode=a[2]||'fastre';//发表模式
	this.max_content_length=a[4]||200;//内容最大长度
	this.isok=true;
	this.chk_content=function(o){
		var len=o.value.length;
		if(0==len){
			this.$(o.name+"_chk").innerHTML='<font color="#FF0000">←评论内容不能为空。</font>';
			try{o.focus();}catch(e){}
			this.isok=false;
		};
		if(o.value.length>this.max_content_length){
			this.$(o.name+"_chk").innerHTML=' <font color="#FF0000">←评论内容长度不能大于'+this.max_content_length+',您已经输入了'+o.value.length+'个字</font>';
			try{o.focus();}catch(e){}
			this.isok=false;
		}
	};
	this.prevent=function(){
		try{if(this.evt.preventDefault){this.evt.preventDefault();}else{this.evt.returnValue=false;}}catch(er){alert(er.message);}
	};
	this.send=function(){
		if (this.isok){
			try{
				if (typeof(ajaxpostalbumbbs)!="undefined"){
					if(!ajaxpostalbumbbs.postForm(this.frm)){
						this.prevent();
					}
				}
			}
			catch (e){}
		}else{
			this.prevent();
		}
		return this.isok;
	};
}

ajaxpostalbumbbs.onsuccess=function(){
	var s=null;
	s=this.xmlhttp.responseText;
	if (s.indexOf("ajax快速评论成功")!=-1){
		try{
			var ajaxInsert = gid("ajaxInsert");
			ajaxInsert.style.display="block";
			ajaxInsert.innerHTML +=s;
			ajaxpostalbumbbs.show("添加评论成功！",0);		
		}catch (er){alert(er.message);}
	}
	if (s.indexOf("评论提交失败")!=-1){
		s=s.split(',');
		//ajaxInsert.style.display="block";
		//ajaxInsert.innerHTML =s;
		ajaxpostalbumbbs.show(s[1],2);
	}
}
ajaxpostalbumbbs.onfailure=function(){
	var Str="错误代号"+this.xmlhttp.statu+"<br />"+this.xmlhttp.responseText;
	ajaxpostalbumbbs.show(Str,2);
}
function AjaxPostAlbumBbs(){
	var base=this;
	this.postForm=function(_form){

		if (useAjaxPost != 1) return true;
		var data="";		
		if(_form){		
		base.show(0,1);		
		data+="action=sadd&imgid="+String(_form.elements[0].value)+"&bbstext="+escape(String(_form.elements[1].value))+"&ajaxpost="+useAjaxPost;
			var xmlhttp;
			try{
				xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try{
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(e){
					try{
						xmlhttp= new XMLHttpRequest();
					}catch(e){}
				}
			}
			xmlhttp.onreadystatechange=function(){
				if(xmlhttp.readyState==4)
				{
					base.xmlhttp = xmlhttp;
					if(xmlhttp.status==200){
						base.onsuccess();
					}else{
						base.onfailure();
					}
				}				
			}
			xmlhttp.open(_form.method, _form.action, true);
			xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			xmlhttp.send(data.replace("&&","&"));
		}
		return false;
	};
	this.show=function(str,t){
		if (t==1){
			gid("bbstext_chk").innerHTML='<img src="images/loading_small.gif" alt="正在提交">正在提交111...';
		}else if(t==2){
			gid("bbstext_chk").innerHTML='<img src="images/note_error.gif" width="16" height="16" alt="Err" />&nbsp;&nbsp;<span style="color:#ff0000;">'+str+'</span>';
			document.fbbs.bbstext.value = "";
		}else if(t==0){
			gid("bbstext_chk").innerHTML='<img src="images/note_ok.gif" width="19" height="16" alt="Ok" />&nbsp;操作信息：<font color="#33CC00">'+str+'</font>';		
			window.setTimeout("closeAjaxDiv('bbstext_chk')",3000);
			n=post_time;
			disp=window.setInterval(base.ShowInfo,1000);
			document.fbbs.bbstext.value = "";
		}
	};
this.ShowInfo=function(){
	var strInfo =  "请缓一下,再添加...";
	n--;
	if(n <= 0){
		document.fbbs.submit.value = "发表评论";
		document.fbbs.submit.disabled = false;
		post=0;
		clearInterval(disp);
	}
	else{
		document.fbbs.submit.value = strInfo + n +"秒";
		document.fbbs.submit.disabled = true;
	}   
} ;
	this.onsuccess=function(){};
	this.onfailure=function(){};
	this.replace=function(str){var con=str;con=con.replace(/%A0/gi,"%20");con=con.replace(/\+/gi,"%2B");return con;}};
function chkedit2(f,e,id){
var ajaxeditalbumbbs=new AjaxEditAlbumBbs()
var isok=false;
var b=gid("e_bbstext");
var edit=gid("bbstext_chk_edit");
var bbs=gid("bbs_"+id);
	if (b.value.length==0){
		edit.innerHTML="<font color=red>评论不能为空</font>";
		b.focus();
		isok=false ;
	}else if (b.value.length>200){
		edit.innerHTML="<font color=red>评论字数不能超过200</font>";
		b.focus();
		isok= false ;	
	}else{isok=true;}
	if (isok){
		try{
			if (typeof(ajaxeditalbumbbs)!="undefined"){
				if(!ajaxeditalbumbbs.EditForm(f)){
							ajaxeditalbumbbs.onsuccess=function(){
								var s=null;
								s=e_xmlhttp.responseText;
								edit.innerHTML="<font color=greed>编辑评论成功</font>";
								bbs.innerHTML=s;
								setTimeout("closeDownBlock2()",1000);
							}
							ajaxeditalbumbbs.onfailure=function(){
								var Str="错误代号"+e_xmlhttp.statu+"<br />"+e_xmlhttp.responseText;
								edit.innerHTML="<font color=red>"+Str+"</font>";
							}
					prevent(e);
				}
			}
		}catch (er){alert(er.message);}
	}else{
		prevent(e);
	}
	if(!isok){
			gid('e_submit').disabled=false;
		}
}

function prevent(evt){
		try{if(evt.preventDefault){evt.preventDefault();}else{evt.returnValue=false;}}catch(er){alert("错误:"+er.message);}
}
function returnxmlhttp(){
			var xmlhttp=null;
			try{
				xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try{
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(e){
					try{
						xmlhttp= new XMLHttpRequest();
					}catch(e){}
				}
			}
	return xmlhttp;
}	
var e_xmlhttp;
function AjaxEditAlbumBbs(){
	var base_e=this;
	e_xmlhttp=returnxmlhttp();
	this.EditForm=function(_form){

		if (useAjaxPost != 1) return true;
		var data="";		
		if(_form){		
		data+="action=sedit&id="+String(_form.elements[0].value)+"&bbstext="+escape(String(_form.elements[1].value))+"&ajaxpost="+useAjaxPost;
			e_xmlhttp.onreadystatechange=function(){
				if(e_xmlhttp.readyState==4)
				{
					if(e_xmlhttp.status==200){
						base_e.onsuccess();
					}else{
						base_e.onfailure();
					}
				}				
			}
			e_xmlhttp.open(_form.method, _form.action, true);
			e_xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			e_xmlhttp.send(data.replace("&&","&"));
		}
		return false;
	};
	this.onsuccess=function(){};
	this.onfailure=function(){};
}
function collect(url,act,id){
	var data="action="+act+"&id="+id+"&ajaxpost="+useAjaxPost;

	var xmlhttp;
	try{
		xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			try{
				xmlhttp= new XMLHttpRequest();
			}catch(e){alert("您的浏览器太老不支持");}
		}
	}
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			if(xmlhttp.status==200){
						eval("var msg="+xmlhttp.responseText);
						if(msg.retype==0){
						alert(msg.message[0]);
						}else{
						alert(msg.message[0]);						
						}
			}else{
				alert(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.open("post",url, true);
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlhttp.send(data.replace("&&","&"));
}
function ajaxchkform(f){
	var incept=gid("boardmasters");
	var title=gid("title");
	var content=gid("content");
	var showresult=gid("showresult");
	var albumid=gid("albumid");
	var albumimgid=gid("albumimgid");
	var page=gid("page");
	var data="action=saveprosecution&incept="+escape(String(incept.value))+"&title="+escape(String(title.value))+"&content="+escape(String(content.value))+"&albumid="+albumid.value+"&albumimgid="+albumimgid.value+"&page="+page.value+"&ajaxpost="+useAjaxPost;
	var xmlhttp;
	try{
		xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			try{
				xmlhttp= new XMLHttpRequest();
			}catch(e){alert("您的浏览器太老不支持");}
		}
	}
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			if(xmlhttp.status==200){
						eval("var msg="+xmlhttp.responseText);
						if(msg.retype==0){
						showresult.innerHTML="<font color=greed>"+msg.message[0]+"</font>";
						setTimeout("closeDownBlock2()",2000);
						}else{
						showresult.innerHTML=msg.message[0];
						}
			}else{
				showresult.innerHTML=xmlhttp.responseText;
			}
		}
	}
	xmlhttp.open("post","dv_album.asp", true);
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlhttp.send(data.replace("&&","&"));
return false;
}