// JavaScript Document




function Editor(content){
	
	oEditor = document.wrEditor;
	var strHtml = '<html><style>body{font-size:14px;line-height: 20px; margin:2px;word-break:break-all;width:600;}\ntd, a{color:#0000FF; font-size:14px;}</style><body >'+content+'</body></html>';
	oEditor.document.open();
	oEditor.document.write(strHtml);
	oEditor.document.close();

	oEditor.document.designMode="On";
	oEditor.focus();
}

//上脚标
function uptab()
{
    var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("SuperScript");
	}
}
//下脚标

function downtab()
{
    var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("Subscript");
	}
}
//文字加粗
function bold(){
	var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("bold");
	}
}

//倾斜
function italic(){
	var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("italic");
	}
}
//下划线
function underline(){
	var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("underline");
	}
}
//超链接
function url(){
	var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("createLink");
		oEditor.document.execCommand("ForeColor", "false", "#FF0000");
	}
}
//取消链接
function unurl(){
	var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("unlink");
	}	
}
//插入图片
function image(){
	var arr = showModalDialog("Editor/include/img.htm", window, "dialogWidth:600px; dialogHeight:200px; status:0; help:0");
	if (arr)
	{
		oEditor.document.body.innerHTML+=arr;
	}
	oEditor.focus();
}
//插入Flash
function flash(){
	var arr = showModalDialog("Editor/include/swf.htm", "", "dialogWidth:400px; dialogHeight:180px; status:0; help:0");
	if (arr != null)
	{
		var ss;
		ss=arr.split("*");
		path=ss[0];
		row=ss[1];
		col=ss[2];
		var string;
		//string="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width="+row+" height="+col+"><param name=movie value="+path+"><param name=quality value=high><embed src="+path+" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width="+row+" height="+col+"></embed></object>"
		string="[flash="+row+","+col+"]"+path+"[/flash]";
		oEditor.document.body.innerHTML+=string;
	}
	oEditor.focus();
}
//插入 MediaPlayer 播放器
function wmv(){
	var arr = showModalDialog("Editor/include/wmv.htm", window, "dialogWidth:400px; dialogHeight:220px; status:0; help:0");
	if (arr != null)
	{
		var ss;
		ss=arr.split("*");
		path=ss[0];
		autostart=ss[1];
		width=ss[2];
		height=ss[3];
		var string;
		//string="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width="+row+" height="+col+"><param name=movie value="+path+"><param name=quality value=high><embed src="+path+" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width="+row+" height="+col+"></embed></object>"
		string="[wmv="+ width +","+ height +","+ autostart +"]"+ path +"[/wmv]";
		oEditor.document.body.innerHTML+=string;
	}
	oEditor.focus();
}
//插入 RealPlayer 播放器
function rm(){
	var arr = showModalDialog("Editor/include/rm.htm", window, "dialogWidth:400px; dialogHeight:220px; status:0; help:0");
	if (arr != null)
	{
		var ss;
		ss=arr.split("*");
		path=ss[0];
		autostart=ss[3];
		width=ss[1];
		height=ss[2];
		var string;
		//string="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width="+row+" height="+col+"><param name=movie value="+path+"><param name=quality value=high><embed src="+path+" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width="+row+" height="+col+"></embed></object>"
		string="[rm="+ width +","+ height +","+ autostart +"]"+ path +"[/rm]";
		oEditor.document.body.innerHTML+=string;
	}
	oEditor.focus();
}
/*
参数：left/center/right
*/
function ralign(aStr){
	switch(aStr){
	case 1:
		oEditor.document.execCommand("JustifyLeft");
		break;
	case 2:
		oEditor.document.execCommand("JustifyCenter");
		break;
	case 3:
		oEditor.document.execCommand("JustifyRight");
		break;
	default:
		return false;
	}
}
/*
字体颜色
*/
function FontColor(){
	var arr = showModalDialog("Editor/include/selcolor.htm", window, "dialogWidth:300px; dialogHeight:300px; status:0; help:0");
	if (arr)
	{
		var sText = oEditor.document.selection.createRange();
		if(sText){
			oEditor.document.execCommand("ForeColor", "false", arr);
		}
	}
	oEditor.focus();
}
/*
字体背景颜色
*/
function BackColor(){
	var arr = showModalDialog("Editor/include/selcolor.htm", window, "dialogWidth:300px; dialogHeight:300px; status:0; help:0");
	if (arr)
	{
		var sText = oEditor.document.selection.createRange();
		if(sText){
			oEditor.document.execCommand("BackColor", "false", arr);
		}
	}
	oEditor.focus();
}
/*

*/
function FontSize(value){
	var sText = oEditor.document.selection.createRange();
	if(sText){
		oEditor.document.execCommand("FontSize", "false", value);
	}	
}
/*

*/
function FontName(value){
	var sText = oEditor.document.selection.createRange();
	if(sText){
		oEditor.document.execCommand("FontName", "false", value);
	}	
}
//取消格式
function unformat(){
	var sText = oEditor.document.selection.createRange();
	if(sText){
		oEditor.document.execCommand("RemoveFormat", false, "");
	}	
}
function getContent()
{
	return correctUrl(oEditor.document.body.innerHTML);
}
function correctUrl(cont)
{
	var regExp;
	regExp = /<a([^>]*) href\s*=\s*([^\s|>]*)([^>]*)/gi
	cont = cont.replace(regExp, "<a href=$2 target=\"_blank\"");
	regExp = /<a([^>]*)><\/a>/gi
	cont = cont.replace(regExp, "");
	return cont;
}
//文本编辑器部分
function Fid(id){
return document.getElementById(id);}
function hiddenLoginWnd(){
var e=Fid('news_container');
e.style.display="none";}
function getv(imgcode)
	{
	    
		
		imgcode.src="code.aspx?"+Math.random();
				
	}
function mask_news_form()
{
	
	
	var newMask  = document.createElement("div");
  	newMask.id = "mask_news";

 	 newMask.style.width = document.body.scrollWidth + "px";
 	 newMask.style.height = (document.body.scrollHeight > document.body.clientHeight)?document.body.scrollHeight:document.body.clientHeight + "px";
 	 newMask.style.filter = "alpha(opacity=30)";
 	 newMask.style.opacity = "0.30";
  	 newMask.className ="mask";
	 document.body.appendChild(newMask);
}
function closewin()
{
	if(Fid('mask_news'))
	{
		var e=Fid('mask_news');
		document.body.removeChild(e);
	}
	if(Fid('news_container'))
	{
		var e=Fid('news_container');
		document.body.removeChild(e);
	}
	if(Fid('login_container'))
	{
		var e=Fid('login_container');
		document.body.removeChild(e);
	}
//	document.execCommand('Refresh');
}
function form_ok(news_type)
	{
	    
	    if(form_checknewsform())
	    {
	       
	        form_newsadd(news_type);
	    }
	}
	function form_checknewsform()
	{

        
	    var strtitle=document.getElementById('form_news_title').value;
    
        strtitle = String(strtitle).replace(/(^\s*)|(\s*$)/g,"");
        
        var strcontent=getContent();
    
        strcontent = String(strcontent).replace(/(^\s*)|(\s*$)/g,"");
        
        var strcode=document.getElementById('form_newscodeid').value;
    
        strcode = String(strcode).replace(/(^\s*)|(\s*$)/g,"");
        
        if(strtitle=='')
        {
            alert('请正确填写新闻标题!');
            return false;
        }
        if(strcontent=='')
        {
            alert('请正确填写新闻内容!');
            return false;
        }
        if(strcode=='')
        {
            alert('请正确填写图片验证码!');
            return false;
        }
        return true;
       
	}
	
	 var xmlHttp;
     function form_newsadd(news_type)
        {
                
                
                if(window.ActiveXObject)
                {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                else if(window.XMLHttpRequest)
                {
                    xmlHttp=new XMLHttpRequest();
                }
           
            
            function CreateDomDoc()   //创建XML文档对象

        {

         var signatures = ["Msxml2.DOMDocument.5.0","Msxml2.DOMDocument.4.0","Msxml2.DOMDocument.3.0","Msxml2.DOMDocument","Microsoft.XmlDom"];

         for(var i=0;i<signatures.length;i++)

            {

                   try

                   {

                          var domDoc = new ActiveXObject(signatures[i]);

                          return domDoc;

                   }

                   catch(e)

                   {

                   }

            }

            return null;
     }
    function CreateXml(doc,news_type)
        {
               
                var root= doc.createElement("root");

               var title= doc.createElement("title");

               title.text= document.getElementById("form_news_title").value;

               root.appendChild(title);

               var content = doc.createElement("content");

               content.text= getContent();

               root.appendChild(content);
               
               var code = doc.createElement("code");

               code.text= document.getElementById("form_newscodeid").value;

               root.appendChild(code);
               
               var kind = doc.createElement("kind");

               kind.text= news_type;

               root.appendChild(kind);

              doc.appendChild(root);

             

               return doc.xml;

        }

            var domDoc = CreateDomDoc(); //创建对象 将用send发送到服务器端
             if(domDoc!=null)
             {
                     
                     var xml = CreateXml(domDoc,news_type); //写入xml 返回xml文档
                   
             }
             else
             {
                    alert("未安装MSXML控件");
             }
            
//            url="news_add.ashx?nt="+document.getElementById('form_news_title').value+"&nc="+getContent()+"&code="+document.getElementById('form_newscodeid').value+"&nk="+news_type;
            xmlHttp.open("POST","news_add.ashx?type=add",true);
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); 
            xmlHttp.onreadystatechange=form_doUpdate;
            xmlHttp.send(domDoc); //发送一定是domDoc文档对象,如果只发送xml将出错”statue=500” 
            
           
            
            
        }
        function form_doUpdate()
        {
               
            
            if(xmlHttp.readyState==4)
            {
                document.getElementById('ul_add_text').style.display = '';
                document.getElementById('ul_newsloading').style.display = 'none';
                var e=document.getElementById('lbltishi_news');
                switch(xmlHttp.responseText)
                {
                    case '1':
                        e.innerHTML='<img src="images/cha.gif" align="absmiddle"/>验证码错误!';
                        getv(document.getElementById('img_code')); 
                        break;
                    case '2':
                        e.innerHTML='<img src="images/cha.gif"/>用户名或密码错误!';
                        getv(document.getElementById('img_code'));  
                        break;
                    case '3':
                        e.innerHTML='<img src="images/cha.gif"/>登陆错误!';
                        getv(document.getElementById('img_code'));  
                        break;
                    case '4':
                        e.innerHTML='<img src="images/cha.gif"/>数据传输错误!';
                        getv(document.getElementById('img_code'));  
                        break;
                    case '5':
                        e.innerHTML='<img src="images/cha.gif"/>非法字符!';
                        getv(document.getElementById('img_code'));  
                        break;     
                    case '6':
                        closewin();
                        document.execCommand('Refresh');
                        break;
                    default:
                        e.innerHTML='<img src="images/cha.gif"/>未知错误!';
                        getv(document.getElementById('img_code'));  
                        break;
                }
                 
          }
          else
          {
               
                document.getElementById('ul_add_text').style.display = 'none';
                document.getElementById('ul_newsloading').style.display = '';
          }

      
      }
      function getCookie(name)
            {
              var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
              if(arr != null) return unescape(arr[2]); return null;
            }
        function news_form(news_type)
        {
            mask_news_form();
            var result=getCookie("userid");
            if(result!=null)
            {
                news(news_type);
            }
            else
            {
                login_form();
            }
            window.scrollTo(0,0);
        }
        function news(news_type)
        {
	       
	        var dflt_css="news_add.css";	
	        if(!css_obj){
		        var css_obj=document.createElement('link');
		        css_obj.id='news_css';
		        css_obj.rel='stylesheet';
		        css_obj.type='text/css';
		        css_obj.media='screen';
		        css_obj.href=dflt_css;
		        document.body.appendChild(css_obj);
		        }

	        if(!Fid('news_container'))
        	
	        {
		        var e=document.createElement('div');
		        e.id='news_container';
        		
		        e.style.position="absolute";
//		        e.style.top=(parseInt(document.documentElement.scrollTop)+100)+"px";
                e.style.top="100px";
		        e.style.left = (parseInt(document.body.scrollWidth) - 650) / 2 + "px"; // 居中
		        var s='';
        		
		        s+='<div id="news_add">';
		        s+='<div id="add_top">';
		        s+='<ul id="ul_addtop"><li class="left">发布新闻</li><li class="right"><a href="javascript:closewin()"><img  src="images/add_close.gif" border="0"/></a></li></ul>';
		        s+='</div>';	
		        s+='<div id="add_down">';
		        s+='<ul id="ul_add_text">';
		        s+='<li style="margin-bottom:0">新闻标题:';
		        s+='<input type="text" id="form_news_title"  size="50" style="height:18px;" onkeydown="if(event.keyCode==13) form_ok('+news_type+');"/>';		  
		        s+='</li>';
		        s+='<li style="margin-bottom:0">';
		        s+='<TEXTAREA NAME="content" id="content" ROWS="1" COLS="1" style="display:none"></TEXTAREA>';
	            s+='<li >';  
	                s+='<ul id="add_btn"><li style="width:140px"><select name="font_name" id="font_name" onChange="FontName(this.options[this.selectedIndex].value)">'; 
			        s+='<option class="heading" selected>字体';
			        s+='<option value="宋体">宋体';
			        s+='<option value="黑体">黑体';
			        s+='<option value="楷体_GB2312">楷体';
			        s+='<option value="仿宋_GB2312">仿宋';
			        s+='<option value="隶书">隶书';
			        s+='<option value="幼圆">幼圆';
			        s+='<option value="新宋体">新宋体';
			        s+='<option value="细明体">细明体';
			        s+='<option value="Arial">Arial';
			        s+='<option value="Arial Black">Arial Black';
			        s+='<option value="Arial Narrow">Arial Narrow';
			        s+='<option value="Bradley Hand ITC">Bradley Hand ITC';
			        s+='<option value="Brush Script	MT">Brush Script MT';
			        s+='<option value="Century Gothic">Century Gothic';
			        s+='<option value="Comic Sans MS">Comic Sans MS';
			        s+='<option value="Courier">Courier';
			        s+='<option value="Courier New">Courier New';
			        s+='<option value="MS Sans Serif">MS Sans Serif';
			        s+='<option value="Script">Script';
			        s+='<option value="System">System';
			        s+='<option value="Times New Roman">Times New Roman';
			        s+='<option value="Viner Hand ITC">Viner Hand ITC';
			        s+='<option value="Verdana">Verdana';
			        s+='<option value="Wide Latin">Wide Latin';
			        s+='<option value="Wingdings">Wingdings</option>';
			        s+='</select></li>';
			        s+='<li style="width:60px"><select name="font_size" id="font_size" onChange="FontSize(this.options[this.selectedIndex].value)">';
                      s+='<option value="1">字号</option>';
			          s+='<option value="1">1</option>';
                      s+='<option value="2">2</option>';
                     s+=' <option value="3">3</option>';
                     s+='<option value="4">4</option>';
                     s+=' <option value="5">5</option>';
                      s+='<option value="6">6</option>';
			          s+='<option value="7">7</option>';
                   s+=' </select></li>';
			        s+='<li><a href="javascript:FontColor()"><IMG SRC="Editor/images/fgcolor.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="字体颜色"></a></li>';
			        s+='<li><a href="javascript:BackColor()"><IMG SRC="Editor/images/fbcolor.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="背景颜色"></a></li>';
			        s+='<li><a href="javascript:bold()"><IMG SRC="Editor/images/bold.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="加粗"></a></li>';
			        s+='<li><a href="javascript:italic()"><IMG SRC="Editor/images/italic.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="倾斜"></a></li>';
			        s+='<li><a href="javascript:underline()"><IMG SRC="Editor/images/underline.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="下划线"></a></li>';
			        s+='<li><a href="javascript:ralign(1)"><IMG SRC="Editor/images/aleft.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="居左"></a></li>';
			        s+='<li><a href="javascript:ralign(2)"><IMG SRC="Editor/images/center.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="居中"></a></li>';
			        s+='<li><a href="javascript:ralign(3)"><IMG SRC="Editor/images/aright.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="居右"></a></li>';
			        s+='<li><a href="javascript:uptab()"><IMG SRC="Editor/images/superscript.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="上标"></a></li>';
			        s+='<li><a href="javascript:downtab()"><IMG SRC="Editor/images/subscript.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="下标"></a></li>';
			        s+='<li><a href="javascript:url()"><IMG SRC="Editor/images/wlink.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="超级链接"></a></li>';
			        s+='<li><a href="javascript:unurl()"><IMG SRC="Editor/images/unlink.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="取消链接"></a></li>';
			        s+='<li><a href="javascript:image()"><IMG SRC="Editor/images/img.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="插入图片"></a></li>';
			        s+='<li><a href="javascript:flash()"><IMG SRC="Editor/images/swf.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="插入Flash"></a></li>';
			        s+='<li><a href="javascript:wmv()"><IMG SRC="Editor/images/wmv.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="插入Windows Media"></a></li>';
			        s+='</ul> ';
	            s+='</li>';    
	            s+='<li style="margin:0;overflow:visible;">';   
	            s+='<iframe name="wrEditor" id="wrEditor" width="600" height="400" src="about:blank" style="border: 1px solid #cccccc"  frameborder=0 framespacing="0"></iframe>';      
	            s+='</li>';            
		        s+='</li>';
                s+='<li><ul id="ul_control"><li style="width:70px">验 证 码:</li><li style="width:70px"><input type="text" id="form_newscodeid"  size="8" style="height:18px;" onkeydown="if(event.keyCode==13) form_ok('+news_type+');"/></li><li style="width:70px"><img id="img_code" align="absmiddle" src="code.aspx" onclick="getv(this)" style="cursor:pointer" border="0" alt="看不清?请点我"/></li><li style="width:120px"><p id="lbltishi_news"></p</li><li style="width:70px; float:right"><a href="javascript:form_ok('+news_type+')"><img  src="images/news_ok.gif" border="0"/></a></li></ul></li>';
                s+='</ul> ';
                s+='<ul id="ul_newsloading" style="margin-top:150px;margin-left:250px;list-style:none;display:none"><li><img  src="images/newsloading.gif" />信息发布中......</li></ul>';
                
         /*       s+='<ul id="ul_loginform" style="margin-top:150px;margin-left:250px;list-style:none;display:none"><li>发布信息前请先登陆</li><li>马上注册</li></ul>';*/
                
		        s+='</div>';
                s+='</div>';
                
		        e.innerHTML=s;
		        document.body.appendChild(e);
	            Editor(document.getElementById("content").value);
	            getv(img_code);
        	
        		
	        }
	        else
	        {
		        var e=Fid('news_container');	
		        e.style.display='';
	        }
        	
        }
