
  function classWindow(id)
	  {
		this.Window="";
		this.WindowDiv="";
		this.WindowFrame="";
		this.WindowModal="";
		this.WindowForm="";
		this.WindowDocument="";
		this.WindowFrameDocument="";
		this.WindowTitle="";
		this.ShowOnInit="false";
		this.BorderLess=false;
		this.id=id;
		this.width="";
		this.height="";
		this.position="";
		this.top="";
		this.left="";
		this.modal="";
		this.closable="";
		this.movable="";
		this.resizable="";
		this.title="";
		this.zIndex=0;
		this.url="";
		this.isVisible=false;
		this.isLoaded=false;
		this.refreshOnShow=false;
		this.ModalState=false;
		this.OnAfterLoad=null;
		this.OnAfterSubmit=null;
		this.OnBeforeSubmit=null;
		this.OnShow=null;
		this.OnHide=null;
		this.ReloadFlag=null;
		this.SubmitCount=0;
		this.LoadCount=0;
		this.Url = function(url){if(url == null){return this.url;}this.url=url;}
		
		
		
		this.Hide = function(){
									if (this.OnHide != null)
									{
										this.OnHide(this); 
									}
									this.WindowDiv.style.display="none";
									this.isVisible=false;
									if(this.modal== "true")
									{
										this.Modal("false");
									}
									if(this.refreshOnShow=="true" )
									{
										this.Navigate("/WindowWait.cfm?a=1");
										this.SubmitCount=0;
										this.LoadCount=0;
									}

								}
		this.Show = function(){
									if (this.OnShow != null)
									{
										this.OnShow(this); 
									}
									
									if(this.isLoaded != true || this.refreshOnShow=="true" )
									{
										this.Navigate();
									}
									this.zIndex = GCS.Windows.getZindex();
									this.WindowDiv.style.zIndex=this.zIndex;
									this.WindowModal.style.zIndex=this.zIndex-2;
									this.WindowMain.style.zIndex=this.zIndex-1;
									this.WindowDiv.style.display="";
									this.isVisible=true;
									
									if(this.modal== "true")
									{
										
										this.Modal("true");
									}
								}
								
		this.Submit = function()	{
			
											if (this.OnBeforeSubmit != null)
																{
																	//dump(this.OnAfterSubmit,true);
																	this.OnBeforeSubmit(this);
																	
																}	
											this.SubmitCount=this.SubmitCount+1;				
											this.WindowForm.submit();					
																
									}						
								
		this.Navigate = function(url){
										if(url==null)
										{
											url=this.url;
										}
										//alert("Navigate: "+url);
										if(url.indexOf("WindowID")>=0 )   
										{
										this.WindowFrame.src=url;
										}
										else
										{
										this.WindowFrame.src=url+"&WindowID="+this.id;
										}
										this.isLoaded=true;
									}						
		this.NavigateReload = function(url){
										this.Navigate(url);
										this.ReloadFlag=true;
									}	
		this.Title = function(_Title){ 
										if(_Title!=null)
										{
											//_Title= _Title.replace("^","'");
											this.title=_Title;
											this.WindowTitle.innerHTML=this.title;
										}
										else
										{	
											return this.title;
										}
									}	
									
		//this.ReloadFlag = function(_ReloadFlag){
		//								this.ReloadFlag=_ReloadFlag;
		//								return this.ReloadFlag;
		//							}	
									
		this.Width = function(_Width){
										if(_Width!=null)
										{
											this.width=_Width;
											
											this.WindowDiv.style.width=this.width-40+"px";
											this.WindowFrame.style.width=this.width-90+"px";		
										}
										else
										{
											return this.width;
										}
									}									
		this.Height = function(_Height){
										if(_Height!=null)
										{
											//alert(this.Window);
											this.height=_Height;
											//document.getElementById(id).style.height=900;
											
											this.WindowFrame.style.height=this.height-140+"px";
											this.Window.mb_resizeTo(_Height-85);
											
											
										}
										else
										{
											return this.height;
										}
									}										
									
		this.Modal = function(state){ //alert(state);
										if (state=="true")
										{
											this.ModalState=state;
											this.WindowModal.style.display="";
										}
										//else if(this.ModalState=="true")
										else
										{   //alert("else")
											this.ModalState=state;
											this.WindowModal.style.display="none";	
										}
									}
									
	  }
	function classWindows()
							{							
							this.Windows=new Array();	
							this.WindowsVisiable=new Array();	
							this.id="Windows";
							this.zIndex=100;
							this.CreateWindow = function(id,doc){
															var MyWindow = new classWindow(id);
															MyWindow.WindowDiv=doc.getElementById(id);
															MyWindow.WindowFrame=doc.getElementById(id+"_I");
															MyWindow.WindowModal=doc.getElementById(id+"_Modal");
															MyWindow.WindowMain=doc.getElementById(id+"_Main");
															MyWindow.WindowTitle=doc.getElementById(id+"_T");
															MyWindow.WindowDocument=doc;
															
															this.Windows[this.Windows.length]= MyWindow;
															return MyWindow;
															}
							this.getWindow = function(id){
															var Output=null;
															for (i=0;i< this.Windows.length;i++)
																{
																	if(this.Windows[i].id==id)
																	{
																	Output=this.Windows[i];
																	}
																}																
															return Output;
														}
							this.getZindex = function(){
															var Output=this.zIndex+10;
															for (i=0;i< this.Windows.length;i++)
																{
																	
																	if(this.Windows[i].zIndex>Output)
																	{
																	Output=this.Windows[i].zIndex;
																	}
																}
																this.zIndex=Output;
																return Output;
														}
							this.EnableWindow = function(id,windowFrameDocument)	{
															var Window=GCS.Windows.getWindow(id);
															Window.WindowForm=windowFrameDocument.getElementsByTagName('form')[0];
															if(Window.WindowForm != null && Window.WindowForm.action.indexOf("WindowID")==-1 )   {
															Window.WindowForm.action=Window.WindowForm.action+"&WindowID="+id;
															}
															Window.WindowFrameDocument=windowFrameDocument;
															if (Window.OnAfterLoad != null)
															{
																Window.OnAfterLoad(Window); 
															}
															//alert(Window.SubmitCount+";"+Window.LoadCount);
															//alert(Window.SubmitCount);
															/*if (Window.SubmitCount >0 )
															{
																if (Window.OnAfterSubmit != null)
																{
																	Window.OnAfterSubmit(Window); 
																}
															}
															else
															{
															//alert("yes");
															}
															*/
															//alert(isDefined( Window.WindowForm[Window.ID+"_SubmitCounter"] );
															//var mycounter = Window.WindowDocument.createElement("input");
															//mycounter.setAttribute("type","text");
															//mycounter.setAttribute("id", Window.id+"_SubmitCounter");
															//mycounter.setAttribute("name", Window.id+"_SubmitCounter");
															//mycounter.setAttribute("value", "0");
															//mycounter.value="0";
															//Window.WindowForm.appendChild(mycounter);
															//dump(Window.WindowForm,true)
															//Window.LoadCount=Window.LoadCount+1;
															
															
															//if (Window.OnBeforeSubmit != null)
															//	{
															//		Window.WindowForm.addEventListener('submit',function(){alert("kk");},true  );
															//	}
															//alert(Window.WindowForm.getAttribute("SubmitCounter"));
															return Window;
															}														
														
														
							}
							

