// JScript 文件

function createHTML(){
    this.menuid=null;   //生成哪一个栏目  0 生成全部栏目
    this.createDown=0;  //是否生成子栏目 0 不包含
    this.createMenu=1;  //是否生成栏目的HTML页
	this.menuType=1;     //只生成有子栏目的  2 只生成没有子栏目的  3 不设置
	this.clearSet=0;
	this.isIndex=0;     // 是否生成首页. 
    
    this.createArticle=1; //是否生成内容页
    this.createDate=1;     //生成多少天之内更新的
	this.clear=1;
	this.isStop=0;
    
    var mList=null;    //将要生成的栏目列表
    var aList=null;    //将要生成的内容页列表
    var z=0;
	
	
	
    this.start=function(){
       	this.isStop=0;
    	var objResponse=new JHttpResponse();
		
    	objResponse.write("menuid",this.menuid);
    	objResponse.write("menuType",this.menuType);
    	objResponse.write("createDown",this.createDown);
		if (this.createMenu==1){ 
			out=objAjax.getText("post","createHTML.aspx?type=readMenuList",objResponse,null);
			//alert(out);
			mList=comminute(out,c1,c2);
		}
		
		
		if (this.createArticle==1){
		    objResponse.write("createDate",this.createDate);
		    objResponse.write("clearHTML",this.clear);
		    objResponse.write("clearSet",this.clearSet);
			//alert(this.clearSet);
		    out=objAjax.getText("post","createHTML.aspx?type=readArticleList",objResponse,null);
			//alert(out);
			//$("sql").innerText=out;
		    aList=comminute(out,c1,c2);
		}
		//alert("准备开始栏目页");
		this.cMenu();
		//setTimeout("cr.cMenu()",100);

    }
    
    var page=1; //当前页码
    var endPage=1; //结束页码
    var isEnd="0"; //是不是结束了
	var i=-1;
	var nObj=null;
	
    this.cMenu=function(){
        if (this.createMenu==0){
			this.createMenuEnd();
			return;
		}
		if (i==mList.length-1 | i>mList.length-1 ){
			this.createMenuEnd();
			return;
		}
		//alert(i);
		//mid,mname,isdown,pageUrl
		page=1;
		endPage=1;
		var obj=$("inputInfo");
		nObj=cObj(obj,"div");
		 i++;
		 this.createMenuPage();
         return;
    }
    
	this.createMenuPage=function(){
		
		if (page>endPage){
			this.cMenu();
			return;
		}
		if (mList[i][0]==null){
			this.createMenuEnd();
			return;
		}
		
		if (mList[i][0]==""){
			this.createMenuEnd();
			return;
		}
		
		if (this.isStop==1){
			 this.userEnd();
			return;	
		}
		
		
		nObj.innerText="开始生成栏目“"+mList[i][1]+"”, 页:"+(page)+"/"+endPage;
		var objResponse=new JHttpResponse();
		objResponse.write("id",mList[i][0]);
		objResponse.write("isdown",mList[i][2]);
		objResponse.write("pageUrl",mList[i][3]);
		objResponse.write("menuPage",page);
		out=objAjax.getText("post","createHTML.aspx?type=createMenu",objResponse,null);
		//alert(out);return;
		
		if ( out.indexOf(c1)==-1){
			alert("写文件失败\n建议稍后再试或重启一下IIS再试一次\n"+erStr(out));
			return;
		}
		out=out.split(c1);
		endPage=parseInt(out[0]);
		
		isEnd=out[1];
		if (isEnd=="1" & endPage<page){
			//alert("准备跳"+out.toString()+","+page)
			this.cMenu();
			return;
		}
		
		
		page++;
		 setTimeout("cr.createMenuPage()",10);
		 return;
	}
	
	var er=0;
	
	this.createMenuEnd=function(){
		if (this.createMenu==1){
			var obj=$("inputInfo");
			nObj=cObj(obj,"div")
			nObj.innerText="栏目页生成完毕";
		}
		i=-1;
		this.cArticle()
	}
	
    this.cArticle=function(){
        if (this.createArticle==0){
			this.createArticleEnd();
			return;
		}
		i++;
		if (i>aList.length-1 | i==aList.length-1){
			this.createArticleEnd();
			return;
		}
		if ( aList[i][1]==null  ){
			this.createArticleEnd();
			return;
		}
		if ( aList[i][1]==""  ){
			this.createArticleEnd();
			return;
		}
		
		if (this.isStop==1){
			 this.userEnd();
			return;	
		}
		
		if (i==0){
			var obj=$("inputInfo");
			nObj=cObj(obj,"div")
		}
		nObj.innerHTML="生成内容页  "+(i+1)+"/"+(aList.length-1)+"  "+parseInt((i+1)/(aList.length-1)*100)+"% <br> 正在创建:“"+aList[i][3]+"”";
		///tabid,tabname,mid,title
		var objResponse=new JHttpResponse();
		//alert(aList[i]);
		objResponse.write("id",aList[i][2]);
		objResponse.write("tabName",aList[i][1]);
		objResponse.write("tabid",aList[i][0]);
		out=objAjax.getText("post","createHTML.aspx?type=createArticle",objResponse,null);
		if (out=="OK"){
			z++
			if (z==100){ //每生成200篇, 系统暂停3秒
				z=0;
				setTimeout("cr.cArticle()",2000);
			}else{
				setTimeout("cr.cArticle()",100);
			}
		}else{
			er++;
			$("erInfo").innerText="发生错误"+er+"次";
			var erObj=$("erList");
			var nEr=cObj(erObj,"div");
			nEr.innerText="错误"+er+": tab="+aList[i][1]+", tabid="+aList[i][0]+", menuid="+aList[i][2];
			//alert(out)
			if (er>50){
				alert("可能由于生成静态页时, 数据库压力太大,\n以至于程序连续发生错误,\n建议重启一下SQL数据库,释放一些内存在试一次");	
				return;
			}
			setTimeout("cr.cArticle()",100);
		}
		
		
		
    }
    
    
  this.createArticleEnd=function(){
		if (this.createArticle==1){
			var obj=$("inputInfo");
			nObj=cObj(obj,"div")
			nObj.innerText="内容页生成完毕";
		}
		this.createIndex();
	}
    
    
	this.createIndex=function(){
		if (this.isIndex==1){
			out=objAjax.getText("post","createHTML.aspx?type=createIndex",null,null);
			if (out=="OK"){
				this.createIndexEnd();
			}
			else{
				alert(erStr(out));
			}
		}else{
			this.createIndexEnd();
		}
	}
	
   this.createIndexEnd=function(){
	   if (this.isIndex==1){
			var obj=$("inputInfo");
			nObj=cObj(obj,"div")
			nObj.innerText="首页生成完毕";
		}
		alert("生成全部完成")
  }
  
  this.userEnd=function(){
   	alert("用户中止");
	 $("create").style.display="none";
     $("setup").style.display="block";  
  }
    
}