//页面缓存类
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];	
			 
			 if(document.all){
			      window.parent.document.frames(main_frame_name).document.body.innerHTML=pagehtml;	
			 }else{
			      window.parent.document.getElementById(main_frame_name).contentWindow.document.body.innerHTML=pagehtml;	
			  }		 
			 this.currentpage=pagename;
			 self.setFormOnSubmit();
			 return false;		 
		  }
	   }
	   
	  
	   
	   this.oldpage=pagename;
	   if(document.all){
	       window.parent.document.frames(main_frame_name).location.href=href;
	   }else{
	        window.parent.document.getElementById(main_frame_name).src=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;
	   if(document.all){
          _forms= parent.document.frames[main_frame_name].document.getElementsByTagName('form');
       }else{         
         _forms= window.parent.document.getElementById(main_frame_name).contentWindow.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==""){
					 if(document.all){
	                      formobj.onsubmit=function(){return window.parent.document.frames[self_frame_name].PageCache.cleanPageCache();};
	                  }else{
	                     formobj.onsubmit=function(){return window.parent.document.getElementById(main_frame_name).contentWindow.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="";
	  if(document.all){
	      pagecontent=window.parent.document.frames[main_frame_name].document.body.innerHTML;
	  }else{
	      pagecontent=window.parent.document.getElementById(main_frame_name).contentWindow.document.body.innerHTML	
	  }	
	  
	   return pagecontent; 
	}
	//测试
	this.Test=function(){
	  alert("ok");	
	}
	//清除所有页面缓存;
	this.Reset=function(){
	   this.page_cache.length=0;
	}
	
}




