//页面缓存类
var PageCache=function(MainFrameName,SelfFrameName){
   	this.page_cache=new Array();
	this.currentpage="";
	this.oldpage="";
	var self=this;
	var main_frame_name=MainFrameName;
	var self_frame_name=SelfFrameName;	
	//获取并显示页面内容
	this.GetPageCache=function(pagename,href){
	   if(pagename==this.currentpage)return;
	   if(this.oldpage!=""){      
		  this.SetPageCache();
	   }
	   //显示浏览器缓存页面数量
	   window.status="当前缓存页面数量为:"+this.page_cache.length;
	   var pagehtml="";
	   //从已经保存的页面缓存中查找,如果有则直接返回页面内容
	   for(var i=0;i<this.page_cache.length;i++){
		  if(this.page_cache[i][0]==pagename){
			 pagehtml=this.page_cache[i][1];	
			 parent.document.frames[main_frame_name].document.body.innerHTML=pagehtml;			 
			 this.currentpage=pagename;
			 self.setFormOnSubmit();
			 return false;		 
		  }
	   }
	   
	  
	   
	   this.oldpage=pagename;
	   
	   parent.document.frames[main_frame_name].location.href=href;
	  
	
	}
	//保存的是上一页的内容
	this.SetPageCache=function(){
		  for(var i=0;i<this.page_cache.length;i++){
			  if(this.page_cache[i][0]==this.oldpage){			
				 return false;		 
			  }
		  }
		  var pageArray=new Array();
		  pageArray[0]=this.oldpage;
		  pageArray[1]=this.GetMainPageHtml();
		  this.page_cache[this.page_cache.length]=pageArray;
		 
		  self.setFormOnSubmit();
		 
		 
	}
	//注册页面form的onsubmit事件,当提交表单时清除当页缓存
	this.setFormOnSubmit=function (){
	   
	   var _forms= parent.document.frames[main_frame_name].document.getElementsByTagName('form');
	   if(_forms!=null){
		  for(var i=0;i<_forms.length;i++){
			  
			  var formobj=_forms[i];
			  if(formobj==null) return;
				   var _oldaction=formobj.getAttribute("onsubmit");
				   if(_oldaction==null||_oldaction==""){
					 
					 formobj.onsubmit=function(){return parent.document.frames[self_frame_name].PageCache.cleanPageCache();};
					 
				   }
			  
		  }
		  
	  }
	   
	   
	}
	//清除当前页缓存
	this.cleanPageCache=function(){
	
	   for(var i=0;i<self.page_cache.length;i++){
		  if(self.page_cache[i][0]==self.currentpage){
			 self.page_cache.splice(i,1);
				 
		  }
	   }
	   return true;
	}
	//获取内容页内容
	this.GetMainPageHtml=function(){
	  
	   var pagecontent=parent.document.frames[main_frame_name].document.body.innerHTML;
	   return pagecontent; 
	}
	//测试
	this.Test=function(){
	  alert("ok");	
	}
	//清除所有页面缓存;
	this.Reset=function(){
	   this.page_cache.length=0;
	}
	
}


