var staticXMLhttp;
var xmHttpUserLogin;
var figuresubmit=0;
function getdocinfo(){
	if(document.getElementById("thslinkwz").getElementsByTagName("a").length>0){
		document.getElementById("thslinkwz").style.display="block";
	}
	staticXMLhttp=createXMLHttpRequestByObject(staticXMLhttp);
	var doctitle=document.getElementById("doc_title").value;
	var docid=document.getElementById("docid").value;
	var dociden=document.getElementById("dociden").value;
	var url="/getdocinfo.do?docid="+docid+"&dociden="+dociden+"&doctitle="+encodeURI(doctitle);
	//判断用户是否存在
	if(getHdCookie(hdCookieName)==null){ 
		//alert(document.getElementById('anonymity'));
	   var anonymity=document.getElementById('anonymity');
		if(anonymity!=null){
			document.getElementById('anonymity').style.display='block';
		}
	   
	   // alert( document.getElementById("anonymity").innerHTML);         
	}
	if(document.getElementById("championiden")!=null){
		url=url+"&championiden="+document.getElementById("championiden").value;
	}
	if(document.getElementById("lateeditiden")!=null){
		url=url+"&lateeditiden="+document.getElementById("lateeditiden").value;
	}
	staticXMLhttp.open("POST", url, true);			
	staticXMLhttp.onreadystatechange = callback_getdocinfo;
	staticXMLhttp.send(null);  
}
function callback_getdocinfo(){
	if (staticXMLhttp.readyState == 4){
		if (staticXMLhttp.status == 200) {
			var statinfo=staticXMLhttp.responseXML.getElementsByTagName("statinfo")[0].firstChild;
			document.getElementById("PIECE_INDEX_HEAD_STA").innerHTML=statinfo.data;
			var loginstate=staticXMLhttp.responseXML.getElementsByTagName("loginstate")[0];
			
//			if(document.getElementById("show_thesaurus").getElementsByTagName("dd").length>0){
//				document.getElementById("show_thesaurus").style.display="block";
//			}
			if(loginstate != null){
				var expertstate=loginstate.getElementsByTagName("expertstate")[0].firstChild.data;
				var networkerstate=loginstate.getElementsByTagName("networkerstate")[0].firstChild.data;
				var adminstate = loginstate.getElementsByTagName("adminstate")[0].firstChild.data;
				var thesureEditor=loginstate.getElementsByTagName("thesureEditor")[0].firstChild.data;
				if(expertstate=="1" || networkerstate=="1" || thesureEditor=="1"){
					var showthesaurusdiv=document.getElementById("show_thesaurus_dt");
					showthesaurusdiv.innerHTML=showthesaurusdiv.innerHTML+'<a id="addthesaurus" href="javascript:thesaurusIfLock();" class="r">我来补充</a>';
					document.getElementById("show_thesaurus").style.display="block";
				}
				if(expertstate=="1"){
					if(document.getElementById("experttopic")!=null){
						document.getElementById("experttopic").style.display="";
					}
				}
				if(adminstate=="1"){
					if(document.getElementById("renamehref")!=null){
						document.getElementById("renamehref").style.display="";
					}
				}
				if(document.getElementById("_loginstate")!=null){
					document.getElementById("_loginstate").value="1";
				}
				//附图上传链接显示
				//if(document.getElementById("addFigure")!=null){
				//	document.getElementById("addFigure").style.display="block";
				//}
			}

			var editlockdiv=document.getElementById("editlock");
			var editlockdl=document.getElementById("editlockdl");
			var editlock=staticXMLhttp.responseXML.getElementsByTagName("editlock")[0];
			if(editlock != null){
				var content='<li>此词条正在被';
				var lockstate=editlock.getElementsByTagName("state")[0].firstChild.data;
				var lockuserid=editlock.getElementsByTagName("userid")[0].firstChild.data;
				if(editlock.getElementsByTagName("userip")[0]!=null){
					var lockuserip=editlock.getElementsByTagName("userip")[0].firstChild.data;
				}
				var lockuseriden=editlock.getElementsByTagName("useriden")[0].firstChild.data;
				var lockusernick=editlock.getElementsByTagName("usernick")[0].firstChild.data;
				if(lockuserid=="0"){
					content=content+"匿名用户("+lockuserip+")锁定编辑中!";
				}else{
					content=content+"<a href='http://wiki.hudong.com/u/"+lockuseriden+"/index'>"+lockusernick+"</a>锁定编辑中!</li>";
				}
				editlockdl.innerHTML=editlockdl.innerHTML.Trim()+content;
				editlockdiv.style.display="";
			}else{
			    var overTwoLocks = staticXMLhttp.responseXML.getElementsByTagName("overTwoLocks")[0];
				if(overTwoLocks != null)
				{
				    editlockdiv.style.display="";
					editlockdl.innerHTML=editlockdl.innerHTML.Trim()+"<li>您已经锁定了两个以上的词条，所以您不能够继续编辑该词条</li>";
				}
			}
			if(editlockdl!=null){
				if(editlockdl.innerHTML.Trim()==''){
					editlockdiv.parentNode.removeChild(editlockdiv);
				}
				else {
					editlockdiv.style.display="";
				}
			}
			
			//document.getElementById("viewnum").parentNode.removeChild(document.getElementById("viewnum"));	
			document.getElementById("viewnum").innerHTML="共被浏览大约 "+staticXMLhttp.responseXML.getElementsByTagName("viewnum")[0].firstChild.data+" 次";
			
			var doccorimg=staticXMLhttp.responseXML.getElementsByTagName("cordocimg")[0];
			if(doccorimg!=null){
				var corimg=document.getElementsByName("corimg");
				for(var i=0;i<corimg.length;i++){
					if(doccorimg.getElementsByTagName("img")[i]!=null){
						corimg[i].src=doccorimg.getElementsByTagName("img")[i].firstChild.data;
					}
				}
			}
			var chamxml=staticXMLhttp.responseXML.getElementsByTagName("champion")[0];
			if(chamxml!=null){
				var championimg=document.getElementById("championimg");
				if(chamxml.getElementsByTagName("portrait")[0].firstChild!=null){
					championimg.src=chamxml.getElementsByTagName("portrait")[0].firstChild.data;
				}else{
					championimg.src="/images/tou.gif";
				}
				if(chamxml.getElementsByTagName("titleimghelp")[0].firstChild!=null && chamxml.getElementsByTagName("titleimg")[0].firstChild!=null){
					var chamhelp=document.getElementById("chamtitleimghelp");
					chamhelp.href=chamxml.getElementsByTagName("titleimghelp")[0].firstChild.data;
					chamhelp.innerHTML="<img title='"+chamxml.getElementsByTagName("titleimgtag")[0].firstChild.data+"' src='"
							+chamxml.getElementsByTagName("titleimg")[0].firstChild.data+"' id='chamtitleimg' class='l v_middle'/>";
				}else{
					document.getElementById("chamtitleimghelp").parentNode
					    .removeChild(document.getElementById("chamtitleimghelp"));
				}
			}
			var latexml=staticXMLhttp.responseXML.getElementsByTagName("lateedit")[0];
			if(latexml!=null){
				var lateimg=document.getElementById("lateimg");
				if(latexml.getElementsByTagName("portrait")[0].firstChild!=null){
					lateimg.src=latexml.getElementsByTagName("portrait")[0].firstChild.data;
				}else{
					lateimg.src="/images/tou.gif";
				}
				if(latexml.getElementsByTagName("titleimghelp")[0].firstChild!=null && latexml.getElementsByTagName("titleimg")[0].firstChild!=null){
					var latehelp=document.getElementById("latetitleimghelp");
					latehelp.href=latexml.getElementsByTagName("titleimghelp")[0].firstChild.data;
					latehelp.innerHTML="<img title='"+latexml.getElementsByTagName("titleimgtag")[0].firstChild.data+"' src='"
							+latexml.getElementsByTagName("titleimg")[0].firstChild.data+"' id='latetitleimg' class='l v_middle'/>";
				}else{
					document.getElementById("latetitleimghelp").parentNode
					    .removeChild(document.getElementById("latetitleimghelp"));
				}
			}
			var topichtml="";
			if(loginstate==null){
				document.getElementById("_doc_flag").value="/wiki/"+document.getElementById("doctitle_utf8").value;					
				if(document.getElementById("topic_email_li")!=null)
					document.getElementById("topic_email_li").style.display="block";
				if(document.getElementById("topic_pwd_li")!=null)
					document.getElementById("topic_pwd_li").style.display="block";
			}else{
				
			}
			
			//维吧发言数目
			var topicnum=staticXMLhttp.responseXML.getElementsByTagName("TopicNum")[0].firstChild;
			if(topicnum!=null){
				var topichrefobj=document.getElementById('topichref');
//				var topicimgobjarr=document.getElementById('editImage')==null?null:document.getElementById('editImage').parentNode.getElementsByTagName('a');
//				var topicimgobj=null;
//				if(topicimgobjarr!=null){
//					if(document.getElementById('relatedImage')==null){
//						topicimgobj=topicimgobjarr[3];
//					}else{
//						topicimgobj=topicimgobjarr[4];
//					}
//				}
				if(topichrefobj!=null){
					if(topicnum.data!='0'){				
						topichrefobj.innerHTML='我要评论（'+topicnum.data+'条）&gt;&gt';
					}else{
						topichrefobj.innerHTML='我要评论&gt;&gt';						
					}
				}	
				//维吧发言数目——词条正文页参与讨论						
//				if(topicimgobj!=null){
//					if(topicnum.data!='0'){					 
//						topicimgobj.innerHTML='参与讨论('+topicnum.data+'条)';
//					}else{
//						topicimgobj.innerHTML='参与讨论';
//					}
//				}		
			}
			
			//正文页讨论区,参与讨论显示唯吧主题及回帖数量
			var totalTopicNum=staticXMLhttp.responseXML.getElementsByTagName("TotalTopicNum")[0].firstChild;			
			if(totalTopicNum!=null){
				var totaltopicnum=totaltopicnum=document.getElementById("totalTopicNum");
		    //正文页讨论区
				if(totaltopicnum!=null){
					if(totalTopicNum.data!=0){
						totaltopicnum.innerHTML='讨论区('+totalTopicNum.data+'条)';
					}else{
						totaltopicnum.innerHTML='讨论区';
					}
				}
			//正文页参与讨论
				var topicimgobjarr=document.getElementById('editImage')==null?null:document.getElementById('editImage').parentNode.getElementsByTagName('a');
			    var topicimgobj=null;
				if(topicimgobjarr!=null){
					if(document.getElementById('relatedImage')==null){
						topicimgobj=topicimgobjarr[3];
					}else{
						topicimgobj=topicimgobjarr[4];
					}
				}	
				if(topicimgobj!=null){
					if(totalTopicNum.data!=0){
						topicimgobj.innerHTML='参与讨论('+totalTopicNum.data+'条)';
					}else{
						topicimgobj.innerHTML='参与讨论';
					}
				}
						
			}
			
			// 正文页留言区唯吧列表	
		      
			if(topicnum!=null&&topicnum.data!='0'){ //显示唯吧列表
				var topicListHtml="";
				var topictable=document.getElementById('topictable'); //取得table标签
				if(topictable!=null){ //显示整个table
					document.getElementById('topictable').style.display=''; //显示thead部分
				}
				//取得唯吧列表
				var Record_topiclist =staticXMLhttp.responseXML.getElementsByTagName("Record_TopicList")[0]; //取得Record_TopicList整体
				if(Record_topiclist!=null){
					var topicArray= Record_topiclist.getElementsByTagName("TopicList"); //取得Record_TopicList中全部TopicList元素
					if(topicArray!=null&&topicArray.length>0){
						//取得每个TopicList中的数据
						var topiclist=null,new_TOPIC_TITLE,new_USER_NICK,new_LAST_POST_TIME,new_LAST_POST_USER_NICK;
						var new_LAST_POST_USER_IP,new_USER_IP,new_USER_ID,new_USER_ID_ENCRYPT,new_DOC_TOPICS_ID_ENCRYPT,new_DOC_TOPICS_ID_ENCRYPT;
						var new_LAST_POST_USER_ID_ENCRYPT,new_LAST_POST_USER_ID;
						var row,cell0,cell1,cell2,cell3,cell4;
						var topicbody= document.getElementById("topiclisttbody"); //取tbody (列表写在此元素中)	
						if(topicbody!=null){
						for(i=0,j=0;i<topicArray.length;i++,j++)
						{
							topiclist =topicArray[i];
							new_TOPIC_TITLE= topiclist.getElementsByTagName("TOPIC_TITLE")[0].firstChild.data;
							new_USER_NICK  = topiclist.getElementsByTagName("USER_NICK")[0].firstChild.data;
							new_LAST_POST_TIME= topiclist.getElementsByTagName("LAST_POST_TIME")[0].firstChild.data;
							new_LAST_POST_USER_NICK= topiclist.getElementsByTagName("LAST_POST_USER_NICK")[0].firstChild.data;
							new_LAST_POST_USER_IP= topiclist.getElementsByTagName("LAST_POST_USER_IP")[0].firstChild.data;
							new_USER_IP= topiclist.getElementsByTagName("USER_IP")[0].firstChild.data;
  							new_USER_ID= topiclist.getElementsByTagName("USER_ID")[0].firstChild.data;
 							new_USER_ID_ENCRYPT= topiclist.getElementsByTagName("USER_ID_ENCRYPT")[0].firstChild.data;
							new_DOC_TOPICS_ID_ENCRYPT= topiclist.getElementsByTagName("DOC_TOPICS_ID_ENCRYPT")[0].firstChild.data;
							new_LAST_POST_USER_ID_ENCRYPT= topiclist.getElementsByTagName("LAST_POST_USER_ID_ENCRYPT")[0].firstChild.data;
							new_LAST_POST_USER_ID= topiclist.getElementsByTagName("LAST_POST_USER_ID")[0].firstChild.data;                
							
                			row=topicbody.insertRow(j);  //增加一tr
                			cell0=row.insertCell(0); //增加一个td，必须用参数，否则firefox有问题
                			cell0.innerHTML="<a href='http://wikibar.hudong.com/posts/"+new_DOC_TOPICS_ID_ENCRYPT+"' target='_blank'>"+new_TOPIC_TITLE+"</a>";
                			cell1=row.insertCell(1); 
							if(new_USER_ID!=null&&new_USER_ID!='0'){
								cell1.innerHTML="<a href='http://wiki.hudong.com/u/"+new_USER_ID_ENCRYPT+"/index' target='_blank'>"+new_USER_NICK+"</a>";   
							}else{
								cell1.innerHTML=new_USER_IP;
                              }              
							cell2=row.insertCell(2);             			
                			cell2.innerHTML=new_LAST_POST_TIME;
                			cell3=row.insertCell(3); 
                			
							if(new_LAST_POST_USER_ID!=null&&new_LAST_POST_USER_ID!='0'){
								cell3.innerHTML="<a href='http://wiki.hudong.com/u/"+new_LAST_POST_USER_ID_ENCRYPT+"/index' target='_blank'>"+new_LAST_POST_USER_NICK+"</a>";
							}else{
								cell3.innerHTML=new_LAST_POST_USER_IP;          	
							}                			
						}
					}
											
					}	
				}            
			} 
//			document.getElementById('topic_title').value='';
//			if(document.getElementById('topic_content')!=null){
//				document.getElementById('topic_content').value='';
//			}
//			if(document.getElementById("topic_seccode_li")!=null){
//				document.getElementById("topic_seccode_li").style.display="none";
//			}
//			if(document.getElementById("captchaimg")!=null){
//				document.getElementById("captchaimg").style.display="none";
//			}
			
			//增加推荐次数
			var recommendObj=document.getElementById("recommend");
			if(recommendObj!=null){
				var recommendnumObj=document.getElementById("recommendnum");
				if(recommendnumObj!=null){
					var recommendNum=staticXMLhttp.responseXML.getElementsByTagName("RecommendNum")[0].firstChild;
					recommendnumObj.innerHTML=recommendNum.data;
				}
			}
			setEnlarge();
		}
	}
}

/**
 * 图片放大器
 */
_setEnlargeImg = function (obj){
	enlargeimg = document.createElement('img');
    enlargeimg.src = "/images/enlarge.gif";
    enlargeimg.setAttribute('name','enlargegif');
    enlargeimg.setAttribute('id','enlargegif');
    var top = 0;
    var left = 0;
    var objclone = obj;
    while (objclone.tagName.toLowerCase() != 'body') {
        top += objclone.offsetTop;
        left += objclone.offsetLeft;
        objclone = objclone.offsetParent;
    }
    top += 5;
    left += obj.offsetWidth-21;
    if (left < 710) {
		obj.parentNode.appendChild(enlargeimg)
		enlargeimg.style.position = "absolute";
		enlargeimg.style.top = top + 'px';
		enlargeimg.style.left = left + 'px';
	}
}
setEnlarge = function(){
	delEnlarge();
	var imgs = document.body.getElementsByTagName('img');
	var leng = imgs.length;
	if(leng>0){
		for (var key = 0; key < ((leng+1)/2); key++) {
			if (imgs[key].src.indexOf('att.hudong.com') > 0) {
				var imgparent = imgs[key].parentNode;
				while (imgparent.parentNode.tagName.toLowerCase()!='li'&&imgparent.tagName.toLowerCase() != 'div') {
					if (imgparent.tagName.toLowerCase() == 'a' && (imgparent.href.indexOf('tupian.hudong.com') > 0)) {
						_setEnlargeImg(imgs[key]);
						break;
					}else {
						imgparent = imgparent.parentNode;
					}
				}
			}
		}
		for (var key1 = leng; key1 >=((leng+1)/2); key1--) {
			if (imgs[key1]&&imgs[key1].src&&imgs[key1].src.indexOf('att.hudong.com') > 0) {
				var imgparent = imgs[key1].parentNode;
				while (imgparent.parentNode.tagName.toLowerCase()!='li'&&imgparent.tagName.toLowerCase() != 'div') {
					if (imgparent.tagName.toLowerCase() == 'a' && (imgparent.href.indexOf('tupian.hudong.com') > 0)) {        
						_setEnlargeImg(imgs[key1]);
						break;
					} else {
						imgparent = imgparent.parentNode;
					}
				}
			}
		}
	}
}
delEnlarge = function() {
	var enlargearrs=document.getElementsByName('enlargegif');
	while(enlargearrs.length>0){
		enlargearrs[0].parentNode.removeChild(enlargearrs[0]);
		delEnlarge();
	}
}
/**
 * 图片放大器end
 */

var editXMLhttp;
function editpower(){
	editXMLhttp=createXMLHttpRequestByObject("editXMLhttp");
	var doctitle=document.getElementById("doc_title").value;
	var url="/editDocAuth.do?submit_type=1&doc_title="+encodeURI(doctitle);
	editXMLhttp.open("GET", url, true);			
	editXMLhttp.onreadystatechange = callback_editXMLhttp;
	editXMLhttp.send(null);	
//	var _doc_type=document.getElementById("_doc_type").value;
//	var doctitle=document.getElementById("doc_title").value;
//	var url='http://www.hudong.com/editdocauth/'+encodeURI(doctitle);
//	if(_doc_type == "2"){
//		var appendcategory_str='<div class="docpagepopwindow"><dl><dt class="a-c"><span class="add_fl">这是一个编辑受限的词条，您没有编辑该词条的权限，请查看帮助！</span></dt><dd class="a-c"><input name="Button2" type="button" value="确 定" onclick="closeFloatWindow()" class="inp-btn btn_black" /></dd></dl></div>';
//		setFloatWindow('编辑词条',appendcategory_str,470,true,true);
//	}else{
//		window.location=url;
//	}
}
function callback_editXMLhttp(){
	if (editXMLhttp.readyState == 4){
		if (editXMLhttp.status == 200) {
			var flag=editXMLhttp.responseXML.getElementsByTagName("Flag")[0].firstChild;
			var doctitle=document.getElementById("doc_title").value;
			var editurl='http://www.hudong.com/editdocauth/'+encodeURI(doctitle);
			if(flag!=null && flag.data=="true"){
				window.location=editurl;
			}else if(flag!=null && flag.data=="false"){
				var reason=editXMLhttp.responseXML.getElementsByTagName("Reason")[0].firstChild;
				var correction_str='<div class="various_mobile">' +
						'<p class="">'+reason.data+'</p>' +
						'<p class="pad_10">请写下您的建议，我们将尽快处理。</p>' +
						'<textarea name="correct_content" id="correct_content" cols="45" rows="10" class="mar-bottom-10 block"></textarea>' +
						'<p class="a-c pad_10"><input class="v_middle input" type="button" value="提 交"  onclick="javascript:submitCorrection(\'3\');" />或<a class="pad10" href="javascript:closeFloatWindow();">放弃</a></p></div>';
				setFloatWindow('为本词条建议：',correction_str,350,false,false);
			}else if(flag!=null && flag.data=="editing"){
				window.location=editurl;
			}else if(flag!=null && flag.data=="locking"){
				window.location=editurl;
			}
		}
	}
}

function addFigure(){	
	figuresubmit=0;
	var useriden="";
	var date=new Date();
	date.setTime(date.getTime()+24*3600*1000);
	document.cookie='nextURL='+document.location.href+';expire='+date.toGMTString()+';path=/;domain=.hudong.com;';
	if(getHdCookie(hdCookieName)==null){
		location="http://www.hudong.com/user/login/userLogin.jsp";//到登陆界面
		return true;
	}else {
		var doctitle=document.getElementById("doc_title").value;
	  
		xmHttpUserLogin = false;
		xmHttpUserLogin= createXMLHttpRequestByObject(xmHttpUserLogin)
		xmHttpUserLogin.open("GET", '/ajaxGetUserLoginInfo.do', true);
		xmHttpUserLogin.onreadystatechange = function(){
			if (xmHttpUserLogin.readyState == 4) {
				if (xmHttpUserLogin.status == 200) {
					useriden=getUseriden(xmHttpUserLogin);
					if(!useriden||useriden=="undefined"){
						useriden="";
					} 				
                      				
					var adddiv='<div class="figure" id="figurediv">'
					+'<form name="uploadFileForm" method="post" action="http://a5.att.hudong.com/uploadFileNew.wiki" enctype="multipart/form-data" target="uploadFigure">'
					+'<ul>'
					+'<li><strong>选择图片：</strong><input id="photofile" name="photofile" size="30" type="file" onchange="previewpic(this);" /> <label>图片格式为：jpg、gif，大小限制:1M（1024KB）</label></li>'		
					+'<input name="img_type" id="img_type" type="hidden" value="16"/>'
					+'<input name="picWidthHeight" id="picWidthHeight" type="hidden" value="2"/>'
					+'<input name="img_src_action" id="img_src_action" type="hidden" value="/figure"/>'
					+'<input name="doc_title" id="doc_title" type="hidden" value="'+doctitle+'"/>'
					+'<input type="hidden" name="curuser_iden" id="curuser_iden" value="'+useriden+'" />'
					+'<li class="mar-t8 a-c" id="loading" name="loading" style="display:none"><img src="/images/loading.gif" /><p class="mar-t8">图片上传中</p></li>'
					+'<li class="mar-t8 a-c" style="display:none" id="preshow" name="preshow"><img id="figure_pic_src" name="figure_pic_src" src="" alt="预览图片" onload="AutoResizeImage(this)"/></li>'
					+'<li class="mar-t8"><strong>图片标题：</strong><input type="text" name="picAlt" id="picAlt" class="inp_txt" size="40" />'
					+'</ul></form>'		
					+'<p class="a-c mar-t10"><input class="inp-btn btn_black" type="submit" value="提 交" onclick="javascript:saveFigure();" id="btnFigure" name="btnFigure"/>'
					+'<input class="inp-btn" type="button" value="取 消"  onclick="javascript:closeFloatWindow();" name="Button3"/></p>'
					+'<iframe style="display:none" id="uploadFigure" name="uploadFigure"></iframe>'
					+'</div>';
					setFloatWindow('添加附图：',adddiv,375,false,false);
				}
			}
		}   
		xmHttpUserLogin.send (null);
	}
}
function getFullPath(obj){
	if(obj){
		if (window.document.all){//ie 
			obj.select();
			return document.selection.createRange().text;
		}else if(!window.document.all){//firefox 
			if(obj.files){
				return obj.files.item(0).getAsDataURL(); 
			}
			return obj.value; 
		}
		return obj.value;
	}
} 
	
function previewpic(imgfilepath){	
	//alert(imgfilepath);
	//var arr=new Array();
	//arr=imgfilepath.split(" ");
	//var myfile="file:///"+arr[1];
	var myfile=getFullPath(imgfilepath);
	//alert(myfile);
	if (window.document.all){ 
		var fileext=myfile.substring(myfile.lastIndexOf("."),myfile.length);
		fileext=fileext.toLowerCase();
		if ((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')){
			alert("对不起，系统仅支持标准格式的照片，请您调整格式后重新上传，谢谢 ！");
			return false;
		}else {	
			if(document.getElementById("preshow")!=null){
				if(document.getElementById('figure_pic_src')!=null){
					document.getElementById("preshow").removeChild(document.getElementById('figure_pic_src'));
				}
				document.getElementById("preshow").innerHTML='<div id="pre_pic" name="pre_pic" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);"></div>';
				var pic = document.getElementById("pre_pic");
				pic.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src =myfile;
				pic.style.width="140px";
				pic.style.height="140px";		   
				document.getElementById("preshow").style.display="block";
			}
		}
	} else if(!window.document.all) {
		var version=0;
		var ua = window.navigator.userAgent;
		var p =ua.lastIndexOf("/"); 
		if(p!=-1){
			version=ua.substring(p+1,p+2);
		}
  
	// alert(version);
		if(version>=3){
			if(myfile.indexOf("image")==-1){
				alert("对不起，系统仅支持标准格式的照片，请您调整格式后重新上传，谢谢 ！");	  
				return false;
			} 
			if(document.getElementById("figure_pic_src")!=null){
				document.getElementById("figure_pic_src").src=myfile; 
				if(document.getElementById("preshow")!=null){
					document.getElementById("preshow").style.display="block";
				}
			}
		}else {
			var fileext=myfile.substring(myfile.lastIndexOf("."),myfile.length);
			fileext=fileext.toLowerCase();
			if ((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')){
				alert("对不起，系统仅支持标准格式的照片，请您调整格式后重新上传，谢谢 ！");
				return false;
			}    
			if(document.getElementById("figure_pic_src")!=null){
				document.getElementById("figure_pic_src").src="file:///"+myfile; 
				if(document.getElementById("preshow")!=null){
					document.getElementById("preshow").style.display="block";
				}
			}
		}
	}
}
	
function AutoResizeImage(objImg){
	var maxWidth=140;
	var maxHeight=140;
	var img = new Image();
	img.src = objImg.src;
	var hRatio;
	var wRatio;
	var Ratio = 1;
	var w = img.width;
	var h = img.height;
	wRatio = maxWidth / w;
	hRatio = maxHeight / h;
	if (maxWidth ==0 && maxHeight==0){
		Ratio = 1;
	}else if (maxWidth==0){
		if (hRatio<1) {
			Ratio = hRatio;
		}
	}else if (maxHeight==0){
		if (wRatio<1){
			Ratio = wRatio;
		}
	}else if (wRatio<1 || hRatio<1){
		Ratio = (wRatio<=hRatio?wRatio:hRatio);
	}
	if (Ratio<1){
		w = w * Ratio;
		h = h * Ratio;
	}
	objImg.height = h;
}

function saveFigure(){
	if(document.getElementById("photofile")!=null){
		var photofile=document.getElementById("photofile").value;
		if(!photofile||(photofile&&photofile.length<=0)){
			alert("您还没选择需上传的图片");
			return false;
		}
	}
	if(document.getElementById("picAlt")!=null){
		var picAlt=document.getElementById("picAlt").value;
		
		if(!picAlt||(picAlt&&picAlt.length<=0)){
			alert("图片标题不能为空，请填写");
			return false;
		}
	}
	if(figuresubmit==0){
		document.uploadFileForm.submit();
		figuresubmit=1;
		if(document.getElementById("loading")!=null){
			document.getElementById("loading").style.display="block";
		}
	}else{
		alert("此图片已经上传!请不要重复上传");
		return false;
	}	
}
	
	
function getUseriden(xmHttpUserLogin){
	if(xmHttpUserLogin.responseXML!=null){	
		//var ele_islogin=xmHttpUserLogin.responseXML.getElementsByTagName("islogin")[0];
		var uiden=xmHttpUserLogin.responseXML.getElementsByTagName("user_iden")[0].firstChild.data; 
		if(uiden == null) {		
			return "";
		}else{
			return uiden;
		}
	}
 }
 
function gotoFigure(){
	var urlstr=window.location.href;
	var iPos=urlstr.indexOf("#");
	if(iPos != -1){
		var arr = new Array();
		arr=urlstr.split("#");
		if(arr.length==2&&arr[1]=="_figurea"){
			window.location.hash="#_figurea";
		}
	}
}