﻿/*!
 * Ext JS Library 3.1.0
 * Copyright(c) 2006-2009 Ext JS, LLC
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
//
// This is the main layout definition.
//
// Add the additional 'advanced' VTypes
Ext.apply(Ext.form.VTypes, {
    password : function(val, field) {
        if (field.initialPassField) {
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
        }
        return true;
    },
    passwordText : 'Sifreler birbiriyle uyusmuyor.'
});

Ext.onReady(function(){
	Ext.QuickTips.init();
	// This is an inner body element within the Details panel created to provide a "slide in" effect
	// on the panel body without affecting the body's box itself.  This element is created on
	// initial use and cached in this var for subsequent access.
	var detailEl;	
	// This is the main content center region that will contain each example layout panel.
	// It will be implemented as a CardLayout since it will contain multiple panels with
	// only one being visible at any given time.
	var _ifrmIcerik = {
	contentEl: 'ifrmIcerik',
	layout: 'fit'
	} ;
	var _divAnaSayfa = {
	contentEl: 'divAnaSayfa',
	layout: 'fit',
	items: [
			_ifrmIcerik
		]
	};
	var	divGuney = {contentEl: 'divGuney', margins: {bottom:10},region: 'south',bodyStyle: 'background:#eee;'};
	var contentPanel = {
		id: 'content-panel',
		region: 'center', // this is what makes this panel into a region within the containing layout
		layout: 'card',
		cls: 'ikiYanaYasla',
		margins: '2 5 5 0',
		activeItem: 0,
		border: false,
		items: [
			_divAnaSayfa
		]
	};

	// Go ahead and create the TreePanel now so that we can use it below
    var treePanel = new Ext.tree.TreePanel({
    	id: 'tree-panel',
    	title: 'Menü',
        region:'north',
        split: true,
        height: 210,
        minSize: 150,
        autoScroll: true,
        
        // tree-specific configs:
        rootVisible: false,
        lines: false,
        singleExpand: true,
        useArrows: true,
        
        loader: new Ext.tree.TreeLoader({
            dataUrl:'JsonDondur.aspx?pSecim=1'
        }),
        
        root: new Ext.tree.AsyncTreeNode()
    });
    
	// Assign the changeLayout function to be called on tree node click.
    treePanel.on('click', function(n){
    	var sn = this.selModel.selNode || {}; // selNode is null on initial selection
    	if(n.leaf && n.id != sn.id){  // ignore clicks on folders and currently selected node
    		if (n.attributes.adres)
    		{    			
    			if (n.attributes.adres.indexOf('mailto')>=0)
    			{	
    				window.location = n.attributes.adres + window.location ;
    				//window.location = n.attributes.adres ;
    				return ;
    			}
    			Ext.getCmp('content-panel').getEl().mask('Yukleniyor...');
    			if (n.attributes.adres == 'Default.aspx') 
    			{
    				Ext.getDom('ifrmIcerik').src = '' ;
    				window.location = n.attributes.adres ;	   			
    			}
    			else
    			{
    				Ext.getDom('ifrmIcerik').src =  n.attributes.adres ;
				}
    		}
    	}
    });
    
	// This is the Details panel that contains the description for each example layout.
	var divDetayIstatistik = {
		id: 'divDetayIstatistik',
        title: '',
        region: 'center',
        bodyStyle: 'padding-bottom:15px;background:#eee;',
		autoScroll: true,
		//contentEl: 'divDetayIstatistik'
		//html: '<p class="details-info">When you select a layout from the tree, additional details will display here.</p>'
		html: Ext.getDom('divDetayIstatistik').innerHTML
    };
	
	// Finally, build the main layout once all the pieces are ready.  This is also a good
	// example of putting together a full-screen BorderLayout within a Viewport.
    new Ext.Viewport({
		layout: 'border',			
		title: 'Ext Layout Browser',
		items: [{
			xtype: 'box',
			region: 'north',
			applyTo: 'header',
			height: 30
		},{
			layout: 'border',
	    	id: 'layout-browser',
	        region:'west',
	        border: false,
	        split:true,
			margins: '2 0 5 5',
	        width: 215,
	        minSize: 100,
	        maxSize: 500,
			items: [treePanel, divDetayIstatistik]
		},
			contentPanel, divGuney
		],
        renderTo: Ext.getBody()	        
    });
    		Ext.get('loading').remove();
	        Ext.get('loading-mask').fadeOut({remove:true});
	//iframe yuklenince bekleme divi kapansin.
    if (Ext.getDom('ifrmIcerik').addEventListener) 
    	Ext.getDom('ifrmIcerik').addEventListener('load', ifrmYuklendi, false);

    else if (Ext.getDom('ifrmIcerik').attachEvent) 
    	Ext.getDom('ifrmIcerik').attachEvent('onload', ifrmYuklendi);
         
	Ext.getDom('ifrmYenilikler').src = "kayanyazilar/Default.html" ;
	
	if (Ext.isGecko) // firefox icin bu hareket.
		setTimeout("iframeLeriTekrarYukle()", 1000); // 1 saniye kadar beklesin. 
			
});

function iframeLeriTekrarYukle()
{
    // firefox bug i icin. bu hareketi yapmazsak iframe icerikleri karisiyor.   
    var f = document.getElementsByTagName('iframe');
	for (var i=0; i<f.length; i++)
	{
		if (f[i].id != 'ifrmYenilikler') // iki kere yuklenmesin bu diye. 
			f[i].src = f[i].src;
	}
}

function ifrmYuklendi()
{
	if (Ext.getCmp('content-panel'))
		Ext.getCmp('content-panel').getEl().unmask();
}

function uyelikPenceresiniAc(pUyeId) { 
	var pencere = Ext.getCmp('pencereUyelik')  ;
	if (pencere)
	{
		if(pencere.hidden)
			pencere.show() ;
	}
	else
	{	
		pencere = new Ext.Window({
		 	width: 351,
			id: 'pencereUyelik', 	 
			height: 437,
			title: "Yeni Uyelik",
			autoScroll: true,
			modal: true,
			html: ' ',
			layout: 'fit',
			closable: false,
			animateTarget: Ext.getBody(),
			items: new Ext.FormPanel({
			        frame:true,
			        title: 'Uyelik Formu',
			        bodyStyle:'padding:1px 1px 0',
			        labelWidth: 95,
			        //width: 540,
			        //renderTo: '_divForm',
			        id: 'formUyelik',
			        onSubmit: Ext.emptyFn
		        	 ,defaults:{anchor:'-24'}
		        	 ,monitorValid:true
		        	 ,autoScroll:true
		        	 // ,buttonAlign:'right'
		        	 ,items:[{
		        	 	xtype:'fieldset',
			            /*checkboxToggle:true,*/
			            title: 'Doldurulmasi Mecburi Olan Alanlar',
			            autoHeight:true,
			            anchor: '100%',
			            defaults: {width: 190},
			            defaultType: 'textfield',
			            collapsible: true,
			            collapsed: false,
						items:[{
				        	 name:'txtKullaniciAdi'
				        	 ,id:'txtKullaniciAdi'
				        	 ,fieldLabel:'Kullanici Adi'
				        	 ,allowBlank:false
				        	 ,xtype:'textfield'
				        	 },{
				        	 name:'txtAdSoyad'
				        	 ,id:'txtAdSoyad'
				        	 ,fieldLabel:'Ad-Soyad'
				        	 ,allowBlank:true
				        	 ,xtype:'textfield'
				        	 },{
				        	 name:'txtEPosta'
				        	 ,id:'txtEPosta'
				        	 ,fieldLabel:'E-Posta'
				        	 ,allowBlank:false
				        	 ,xtype:'textfield'
				        	 ,vtype:'email'	
				        	 },{
				        	 name:'txtGizliUyeId'
				        	 ,id:'txtGizliUyeId'
				        	 ,fieldLabel:'Uye Id'
				        	 ,allowBlank:true
				        	 ,xtype:'hidden'
				        	 },{
				        	 name:'txtSifre1'
				        	 ,id:'txtSifre1'
				        	 ,fieldLabel:'Sifre'
				        	 ,allowBlank:false
				        	 ,xtype:'textfield'
				        	 ,inputType:'password'
				        	 },{
				        	 name:'txtSifre2'
				        	 ,id:'txtSifre2'
				        	 ,fieldLabel:'Sifre (Tekrar)'
				        	 ,allowBlank:false
				        	 ,xtype:'textfield'
				        	 ,inputType:'password'
				        	 ,vtype: 'password'
	        				 ,initialPassField: 'txtSifre1' // id of the initial password field
				        	 }]
				     	},{
				     	xtype:'fieldset',
			            /*checkboxToggle:true,*/
			            title: 'Doldurulmasi Mecburi Olmayan Alanlar',
			            autoHeight:true,
			            anchor: '100%',
			            defaults: {width: 190},
			            defaultType: 'textfield',
			            collapsible: true,
			            collapsed: false,
						items:[{
				        	 name:'txtDogumTarihi'
				        	 ,id:'txtDogumTarihi' 
				        	 ,fieldLabel:'Dogum Tarihi'
				        	 ,xtype:'datefield'
				        	 ,format: 'd.m.Y'
				        	 ,allowBlank:true
				        	 },
				        	 {
				        	 name:'cmbMemleket'
							 ,fieldLabel:'Memleket'
							 ,xtype:'combo'
							 ,triggerAction:'all'
							 ,mode:'local'
							 ,editable:false
							 ,store:new Ext.data.JsonStore({
								 fields:['ilKodu', 'ilAdi'],
								 root: 'strIller',
								 url: 'JsonDondur.aspx?pSecim=5',
								 autoLoad: true
							 })
							 ,displayField:'ilAdi'
							 ,valueField:'ilKodu'
							 ,hiddenName:'cmbMemleket'			        	 
				        	 },
				        	 {
				            // Use the default, automatic layout to distribute the controls evenly
				            // across a single row
				            xtype: 'radiogroup',
				            id: 'rdbCinsiyet',
				            fieldLabel: 'Cinsiyet',
				            items: [
				                {boxLabel: 'Bay', name: 'rdbCinsiyet', inputValue: 'Bay'},
                				{boxLabel: 'Bayan', name: 'rdbCinsiyet', inputValue: 'Bayan'}
				            ]
				        }
		        	 	]}],
				        buttons: [
			        	{
				        	text:'Gonder'
				        	,formBind:true
				        	//,type:'submit'
				        	//,scope:this
				        	,handler: function(){ 
				        		var pIslem = "" ;
				        		var res = null ;
								pIslem = "UyeEkleGuncelle" ;									
								Ext.getCmp('formUyelik').getForm().submit({
								url:'JsonDondur.aspx', 
								method: 'POST',
								waitTitle:'Bekleyiniz',
                        		waitMsg:'Lutfen bekleyiniz...',
								params:{pSayfa:'Uyelik', pIslem:pIslem}, 
								success: function(form, action) {
									res = new Object();
          							res = Ext.util.JSON.decode(action.response.responseText);
									if (!pUyeId)
									{
										Ext.getDom('hrefUyeOlDuzenle').innerHTML  = 'Uyelik Bilgileri' ;
										Ext.getDom('hrefUyeOlDuzenle').title = "Uyelik Bilgileri icin tiklayiniz...";
										Ext.getDom('hrefUyeOlDuzenle').href = "javascript:uyelikPenceresiniAc(" + res.uyeid + ");";
										Ext.getDom('hrefGirisCikis').innerHTML  = 'Cikis' ;
										Ext.getDom('hrefGirisCikis').title = "Cikis yapmak icin tiklayiniz...";
										Ext.getDom('hrefGirisCikis').href = "Cikis.aspx";
									}
									Ext.getCmp('formUyelik').getForm().getEl().dom.reset();
									if (Ext.getCmp('pencereUyelik'))
          								Ext.getCmp('pencereUyelik').hide();
								},
								failure: function(form, action) {
									res = new Object();
          							res = Ext.util.JSON.decode(action.response.responseText);
						            Ext.MessageBox.alert('Sunucu Hatasi', res.hata);
						        },
								waitMsg:'Lutfen bekleyiniz...', 
								submitEmptyText: false});}
				        	},
				        {
				            text: 'Temizle',
				            handler: function(){ Ext.getCmp('formUyelik').getForm().getEl().dom.reset(); } 
				        }]
			}),			 
			buttons: [
		        {
	            text: 'Kapat',
	            handler: function(){
	                pencere.hide();
	            }
        	}],
			listeners:{
                'close':function(){
					return false ;
                 },
                'hide':function(){
                	 return false ;
                 }
        	}
		});		
		pencere.show();
	}
	if (pUyeId)
	{
		Ext.getCmp('txtGizliUyeId').setValue(pUyeId); // guncelleme icin.
		Ext.getCmp('formUyelik').getForm().load({
			url:'JsonDondur.aspx',
			params:{pSayfa:'Uyelik', pIslem:'UyeBilgileriniGetir', txtGizliUyeId: pUyeId},  
			waitMsg:'Yukleniyor...'}
		);
		Ext.getCmp('txtEPosta').disable();
		Ext.getCmp('txtKullaniciAdi').disable();
	}	
} 

function uyeGirisPenceresiniAc() { 
	var pencere = Ext.getCmp('pencereUyeGiris')  ;
	if (pencere)
	{
		if(pencere.hidden)
			pencere.show() ;
	}
	else
	{	
		pencere = new Ext.Window({
		 	width: 351,
			id: 'pencereUyeGiris', 	 
			height: 237,
			title: "Uye Giris",
			autoScroll: true,
			modal: true,
			html: ' ',
			layout: 'fit',
			closable: false,
			animateTarget: Ext.getBody(),
			items: new Ext.FormPanel({
			        frame:true,
			        title: 'Giris Formu',
			        bodyStyle:'padding:1px 1px 0',
			        labelWidth: 95,
			        //width: 540,
			        //renderTo: '_divForm',
			        id: 'formUyeGiris',
			        onSubmit: Ext.emptyFn
		        	 ,defaults:{anchor:'-24'}
		        	 ,monitorValid:true
		        	 ,autoScroll:true
		        	 // ,buttonAlign:'right'
		        	 ,items:[{
		        	 	xtype:'fieldset',
			            /*checkboxToggle:true,*/
			            title: 'Kullanici Adi - Sifre',
			            autoHeight:true,
			            anchor: '100%',
			            defaults: {width: 190},
			            defaultType: 'textfield',
			            collapsible: true,
			            collapsed: false,
						items:[{
				        	 name:'txtUyeGirisAdi'
				        	 ,id:'txtUyeGirisAdi'
				        	 ,fieldLabel:'Kullanici Adi'
				        	 ,allowBlank:false
				        	 ,xtype:'textfield'
				        	 	 ,value:''
				        	 },{
				        	 name:'txtUyeGirisSifre'
				        	 ,id:'txtUyeGirisSifre'
				        	 ,fieldLabel:'Sifre'
				        	 ,allowBlank:false
				        	 ,xtype:'textfield'
				        	 ,inputType:'password'
				        	 ,vtype: 'password'
	        				 	 ,value:''
				        	 }]
				     	}],
				        buttons: [
			        	{
				        	text:'Giris'
				        	,formBind:true
				        	//,type:'submit'
				        	//,scope:this
				        	,handler: function(){uyeGirisFormunuPostala() ;}},
				        {
				            text: 'Temizle',
				            handler: function(){ Ext.getCmp('formUyeGiris').getForm().getEl().dom.reset(); } 
				        }]
			}),			 
			buttons: [
		        {
	            text: 'Kapat',
	            handler: function(){
	                pencere.hide();
	            }
        	}],
			listeners:{
                'close':function(){
					return false ;
                 },
                'hide':function(){
                	 return false ;
                 }
        	}
		});		
		pencere.show();
	}	
}

function formuPostala2(pUyeId)
{
	var pIslem = "" ;
	if (pUyeId)
		pIslem = "UyeGuncelle" ;
	else
		pIslem = "UyeEkle" ;
		
	Ext.getCmp('formUyelik').getForm().submit({
						url:'JsonDondur.aspx', 
						params:{pSayfa:'Uyelik', pIslem:pIslem}, 
						success:basariliOldu,
						failure:basarisizOldu,
						waitMsg:'Lutfen bekleyiniz...', 
						submitEmptyText: false});
/*
	var fmURL = 's2logbak.jsp?' + Ext.urlEncode({txtTarih: replaceAll(Ext.getCmp('_txtTarih').getRawValue(), '/', '')}); //The url that will process the form
	Ext.getCmp('formLogTakip').getForm().getEl().dom.action = fmURL;
	Ext.getCmp('formLogTakip').getForm().getEl().dom.submit({
        method: 'POST'
    }) ;
*/
}

function uyeGirisFormunuPostala()
{
	var fmURL = 'JsonDondur.aspx?pSecim=6' ;
	Ext.getCmp('formUyeGiris').getForm().getEl().dom.action = fmURL;
	Ext.getCmp('formUyeGiris').getForm().getEl().dom.submit({
        method: 'POST'
    }) ;
}

function basariliOldu()
{
	Ext.Msg.show({
		title:'Success'
		,msg:'Form submitted successfully'
		,modal:true
		,icon:Ext.Msg.INFO
		,buttons:Ext.Msg.OK
		});
}

function basarisizOldu() 
{
	this.showError(action.result.error || action.response.responseText);
}

// yenilikler xml ini duzenleme kismi
var xmlHttp = null ;
function kayanYaziyiGetir()
{
    xmlHttp = xmlHttpDondur() ;
    if (xmlHttp != null)
    {
        xmlHttp.onreadystatechange = kayanYaziGeldi ;
        xmlHttp.open("GET", "XmlDondur.aspx?KayanYazi=1", true) ;
        xmlHttp.send(null) ;
    }
}//function kayanYaziyiGetir()

function kayanYaziGeldi()
{
    var xmlDoc = null ;
    var strGonder = '' ;
    if (xmlHttp.readyState == 4)
    {// 4 = "loaded"
        if (xmlHttp.status == 200)
        {// 200 = OK
            xmlDoc = xmlDocDondur(xmlHttp) ;
            if (Ext.isIE)
            	strGonder = ssN(xmlDoc, '//YENILIKLER').xml ; 
            else
            	strGonder = new XMLSerializer().serializeToString(ssN(xmlDoc, '//YENILIKLER')) ;	              
            yenilikEkleDuzenlePenceresiAc(strGonder)
        }//if (xmlHttp.status == 200)
    }//if (xmlHttp.readyState == 4)
}//function kayanYaziGeldi()
function yenilikEkleDuzenlePenceresiAc(pStrGonder) { 
	var pencere = Ext.getCmp('pencereYenilikDuzenle')  ;
	if (pencere)
	{
		if(pencere.hidden)
			pencere.show() ;
	}
	else
	{	
		pencere = new Ext.Window({
		 	width:581,
			id:'pencereYenilikDuzenle', 	 
			height:363,
			title:"Yenilik Duzenle",
			autoScroll:true,
			modal:true,
			html:' ',
			animateTarget: Ext.getBody() , 
			items: new Ext.FormPanel({
			        labelAlign: 'top',
			        frame:true,
			        title: 'Duzenleme Formu',
			        bodyStyle:'padding:1px 1px 0',
			        //width: 540,
			        //renderTo: '_divForm',
			        id: 'formYenilikDuzenle',
			        items: [
			        {
			            xtype:'textarea',
			            id:'txtYenilikDuzenle',
			            /*fieldLabel:'Icerik',*/
			            height:201,
			            anchor:'100%'
			        }],
			        buttons: [{
			            text: 'Kaydet',
			            id:'btnKaydet',
			            formBind: true,
			            listeners: {
			                click: function(){
			                	if(Ext.getCmp('formYenilikDuzenle').form.isValid()){
			                		ajaxLaFormuGonder('', '1') ;
			                	}
			                }
			            }                
			        },
			        {
			            text: 'Temizle',
			            handler: function(){ Ext.getCmp('txtYenilikDuzenle').setValue(''); } 
			        }]
			}),
	        buttons: [
	        {
            text: 'Kapat',
            handler: function(){
                pencere.hide();
            }
        }]
		});	
		Ext.getCmp('txtYenilikDuzenle').setValue(pStrGonder) ;
		pencere.show();
	}	
} 

function ajaxLaFormuGonder(pHikayeId, pIslem)
{	
   	var _pStrXml = Ext.getCmp('txtYenilikDuzenle').getValue() ;
	Ext.Ajax.request({
	    url:'JsonDondur.aspx', 
	  	params:{pSayfa:'AnaSayfa', pIslem: 'YenilikDuzenle', pStrXml: _pStrXml},
	  	success: function(result, request)
        {
	  		var res = new Object();
          	res = Ext.util.JSON.decode(result.responseText);
          	if (res.success == true)
          	{
          		if (Ext.getCmp('pencereYenilikDuzenle'))
          			Ext.getCmp('pencereYenilikDuzenle').hide();
          		Ext.getDom('ifrmYenilikler').src = "kayanyazilar/Default.html" ;
          	}
          	else
          	{
          		Ext.MessageBox.alert('Sunucu Hatasi', res.hata);
          	}
        }        
	});        
} 

function sayfayiYukle(pAdres)
{
	Ext.getCmp('content-panel').getEl().mask('Yukleniyor...');
	Ext.getDom('ifrmIcerik').src =  pAdres ;
}
