/* ************************************************************************************************
										Simple window, Pop up and frames
 **************************************************************************************************/

rialto.frameDemo=function(objPar){
	
	this.filename="popup.js";
	
	if(!objPar){
		var objPar={title : "Popup and Frames" ,
					parent : document.body ,
					icone:'images/imgFenSimple/picto-gr_default.gif'
					}
	}
    this.simpleWindow=new rialto.widget.SimpleWindow(objPar);
	var oThis=this;
	
								    	
	var help = new rialto.widget.Image('../rialtoEngine/imagesDemo/idea.png','10','10',this.simpleWindow,"",'../rialtoEngine/imagesDemo/ktip.png');									    	
	var labHelp= new rialto.widget.Label("",15,30,this.simpleWindow,"The 3 dynamic frame have accordeon behavior","libelleTip");
	labHelp.setVisible(false);
	help.onmouseover=function(){labHelp.setVisible(true);}
	help.onmouseout=function(){labHelp.setVisible(false);}

	//first dynamic frame
	var frmDyn1 = new rialto.widget.Frame({name:'CADREC',top:'35',left:'10',width:'98%',height:'240',
										  title:'Dynamic frame',open:true,dynamic:true,autoResizableW:true,
										  position:'relative',draggable:false,parent:this.simpleWindow});
	var frmSple = new rialto.widget.Frame({name:'CADRE1',top:'10',left:'0',width:'98%',height:'165',
										   title:'Simple frame',open:true,
										   dynamic:false,position:'absolute',draggable:false,parent:frmDyn1});
	//button to open alert popup
    var btnAlert = new rialto.widget.Button(10,20,"Alert popup","Click to open a Alert popup",frmSple,{enable:true,adaptToText:true,width:88,widthMin:88});
    btnAlert.onclick=function(){
    	new rialto.widget.Alert("Alert....");
    }
   	//button to open wait popup
	var btnWait = new rialto.widget.Button(10,150,"Wait popup","Click to open a Wait popup",frmSple,{enable:true,adaptToText:true,width:88,widthMin:88});		    
	btnWait.onclick=function(){
    	new rialto.widget.WaitWindow( {text:"CHARGEMENT" ,canBeCancel: true});
    }
	var btnSimplePopup = new rialto.widget.Button(10,280,"Simple popup","Click to open a Simple popup",frmSple,{enable:true,adaptToText:true,width:88,widthMin:88});		    				    	
   	//button to open simple popup	
	btnSimplePopup.onclick=function(){
    	var sPopup = new rialto.widget.PopUp('test',150,420,'260','80','',"Gray background",'gray');
    	var btn2pop = new rialto.widget.Button(30,65,"Again ?","Show the help",sPopup);
		btn2pop.onclick=function () {
    		var sPopup = new rialto.widget.PopUp('test',270,520,'260','80','',"Transparent background",'transparent');           
		};
    }
   	//button to open complex popup	    
	var btnComplexPopup = new rialto.widget.Button(10,410,"Complex popup","Click to open a Complex popup",frmSple,{enable:true,adaptToText:true,width:88,widthMin:88});		    		
	btnComplexPopup.onclick=function(){
    	var sPopup = new rialto.widget.PopUp('test',50,50,'600','500','',"FORM",'gray');
    	
    	var CADREC = new rialto.widget.Frame({name:'CADREC',top:'15',left:'10',width:'100',height:'335',title:'Search criteria',
										  open:true,dynamic:true,
									      position:'relative',draggable:false,
									      parent:sPopup,autoResizableW:true});
			
	    var CADRE1 = new rialto.widget.Frame({name:'CADRE1',top:'10',left:'0',width:'395',height:'265',title:'Patient id',
	    									  open:true,dynamic:false,position:'absolute',
	    									  draggable:false,parent:CADREC});
		var lib = new rialto.widget.Label('lib',15,10,CADRE1,"Folder from",'libelle1');
	    var DOSA = new rialto.widget.Text('DOSA',10,80,80,'A',CADRE1,{autoUp:false,isRequired:false,disable:false,rows:5,accessKey:'',tabIndex:'',initValue:""});
		lib = new rialto.widget.Label('lib',15,168,CADRE1,"to",'libelle1');
		var DOSB = new rialto.widget.Text('DOSB',10,180,80,'A',CADRE1,{autoUp:false,isRequired:false,disable:false,rows:5,accessKey:'',tabIndex:'',initValue:""});
		lib = new rialto.widget.Label('lib',45,10,CADRE1,"Name",'libelle1');
		var NOM = new rialto.widget.Text('NOM',40,80,200,'A',CADRE1,{autoUp:false,isRequired:true,disable:false,rows:5,accessKey:'',tabIndex:'',initValue:""});	
	    var PHON = new rialto.widget.Checkbox('PHON',40,280,CADRE1,'Phonetics',false,'libelle1');				
	    lib = new rialto.widget.Label('lib',75,10,CADRE1,"First name",'libelle1');
	    var PRENOM = new rialto.widget.Text('PRENOM',70,80,200,'A',CADRE1,{autoUp:false,isRequired:false,disable:false,rows:5,accessKey:'',tabIndex:'',initValue:""});
	    lib = new rialto.widget.Label('lib',75,290,CADRE1,"Sex",'libelle1');
	    var SEXE = new rialto.widget.Combo('','SEXE',70,320,40,CADRE1,{suggest:true,enable:true,heightItem:0});
	    SEXE.addItem("M","M");
	    SEXE.addItem("F","F");
	    SEXE.addItem(" ","?");
	    lib = new rialto.widget.Label('lib',105,10,CADRE1,"Maiden name",'libelle1');
	    var NOMJF = new rialto.widget.Text('NOMJF',100,80,200,'A',CADRE1,{autoUp:false,isRequired:false,disable:false,rows:5,accessKey:'',tabIndex:'',initValue:""});                   
	    lib = new rialto.widget.Label('lib',135,10,CADRE1,"Born on",'libelle1');
	    var DATNAI = new rialto.widget.Text('DATNAI',130,80,200,'D',CADRE1,{autoUp:false,isRequired:false,disable:false,rows:5,accessKey:'',tabIndex:'',initValue:""});				      
	    lib = new rialto.widget.Label('lib',135,195,CADRE1,"Age",'libelle1');
	    var AGEIN = new rialto.widget.Text('AGEIN',130,240,50,'N',CADRE1,{autoUp:false,isRequired:false,disable:false,rows:5,accessKey:'',tabIndex:'',initValue:""});				
	    lib = new rialto.widget.Label('lib',135,293,CADRE1,"to",'libelle1');
	    var AGEOUT = new rialto.widget.Text('AGEOUT',130,305,50,'N',CADRE1,{autoUp:false,isRequired:false,disable:false,rows:5,accessKey:'',tabIndex:'',initValue:""});				
	    lib = new rialto.widget.Label('lib',165,10,CADRE1,"Committee",'libelle1');
	    var CCOM = new rialto.widget.codeLabel('CCOM',160,80,250,CADRE1,{withLabel:true,submitOnload:true,alwaysRefresh:true,codeWidth:0,url:'../RechCodeLibelle'});                        
	    var CADRE5 = new rialto.widget.Frame({name:'CADRE5',top:'205',left:'8',width:'345',height:'40',title:'Medical inscription',open:true,dynamic:false,position:'absolute',draggable:false,parent:CADRE1});	
	    var T =  new rialto.widget.Radio('T',7,10,CADRE5,'INSC','All',true,'libNormal');
	    var P =  new rialto.widget.Radio('P',7,85,CADRE5,'INSC','Provisional',false,'libNormal');
	    var D =  new rialto.widget.Radio('D',7,177,CADRE5,'INSC','Final',false,'libNormal');
	    var A =  new rialto.widget.Radio('A',7,260,CADRE5,'INSC','Opinion',false,'libNormal');                               	
	    
	    lib = new rialto.widget.Label('lib',290,10,CADREC,"Numbers maximum posted patients",'libelle2');
	    var NBENR = new rialto.widget.Text('NBENR',285,230,40,'N',CADREC,{autoUp:false,isRequired:false,disable:false,rows:5,accessKey:'',tabIndex:'',initValue:""});                
	    var BRES = new rialto.widget.Button(290,290,"Reset","Effacer toute la saisie",CADREC,{enable:true,adaptToText:true,width:88,widthMin:88});
	    var BRECH = new rialto.widget.Button(290,380,"Find","Lancer la recherche",CADREC,{enable:true,adaptToText:true,width:88,widthMin:88});
	               
	    // Initialisation du champs NBENR ? 100
	    NBENR.setValue("100");
	    BRES.onclick=function () {            
	        FORM1.resetForm();
	        NBENR.champs.value="100";
		    T.setCheck(true);
	        //on simule le clik des checkbox (pour le coding applicatif)
	        oGrid.deleteLines();
		};
	
	    //Bouton rechercher                                                        
		BRECH.onclick=function () {           		            
	        if (NOM.getValue()==""){
	        	info = new rialto.widget.Alert("Champ(s) obligatoire(s)");     
				NOM.showAsRequired();
				return true;
			}
			var nom=NOM.getValue()+" "+PRENOM.getValue();	
			var datN=DATNAI.getValue();					
							
	        var tab = new Array;
	        for (var i =0;i<50;i++){
				if(datN==""){datN="01/12/"+(1975+i);}
				tab.push([i,nom,datN,'010']); 
			}        			     
			oGrid.fillGrid(tab);
		};
			
		
		var CADRER = new rialto.widget.Frame({name:'CADRER',top:'15',left:'10',width:'98%',height:'160',
											  title:'Results of research',open:true,dynamic:true,
											  position:'relative',draggable:false,
											  parent:sPopup,autoResizableW:true,autoResizableH:true});
		var oGrid = new rialto.widget.Grid({top:0,left:5,height:130,
		 								   arrHeader:[{title:"Folder",type:"string",width:80},
													  {title:"Surname-First  name",type:"string",width:200},
													  {title:"Date of birth",type:"date",width:100},
													  {title:"Committee",type:"date",width:60}],
										   name:'oGrid',parent:CADRER,bNavig:false,rang:5,
										   cellActive:false,
										   asynchLoad:true,
										   sortable:true,multiSelect:false,lineHeight:16,boolPrint:true,switchable:true,
										   clickable:true,autoResizableW:true,autoResizableH:true,
										   writable:true});
    	
    	
    	
    }
    //2nd dynamic frame
	var frmDyn2 = new rialto.widget.Frame({name:'CADREC',top:'35',left:'10',width:'98%',height:'240',
										  title:'Dynamic frame',open:false,dynamic:true,autoResizableW:true,
										  position:'relative',draggable:false,parent:this.simpleWindow});
										  
	var objPar={title : "A simple window" ,
			parent : frmDyn2 ,
			autoResizableW:true,autoResizableH:true,
			overOpenWindow:false,
			icone:'images/imgFenSimple/picto-gr_default.gif'}
	
    var simpleWindow=new rialto.widget.SimpleWindow(objPar);										  
	new rialto.widget.Label('lib4',45,10,simpleWindow,"In frame 2",'libelle2');
	//third dynamic frame	
	var frmDyn3 = new rialto.widget.Frame({name:'CADREC',top:'35',left:'10',width:'98%',height:'240',
										  title:'Dynamic frame',open:false,dynamic:true,autoResizableW:true,
										  position:'relative',draggable:false,parent:this.simpleWindow});										  
	var objPar={title : "A simple window" ,
			parent : frmDyn3 ,
			autoResizableW:true,autoResizableH:true,
			overOpenWindow:false,
			icone:'images/imgFenSimple/picto-gr_default.gif'}
	
    var simpleWindow=new rialto.widget.SimpleWindow(objPar);										  
	new rialto.widget.Label('lib4',45,10,simpleWindow,"In frame 3",'libelle2');
	//save the open frame
	frmOpen=frmDyn1;
	//Accordeon behavior with onOpen event
	frmDyn1.onOpen = frmDyn2.onOpen = frmDyn3.onOpen =function(open){
		if(this.open){
			if(frmOpen && frmOpen!=this){
				frmOpen.setOpen(false);	
			}
		}
		frmOpen=this;
	}
}
