Ext.namespace("Divo.app");


function loadWindow() {
	

  var form = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        layout:'absolute',
       // url:'save-form.php',
	   	Style : "text-align:right;direction:rtl",		
        defaultType: 'textfield',

        items: [{
            x: 0,
            y: 0,
            name: 'name',
            anchor:'75%'  // anchor width by percentage
        } , {
            x: 370,
            y: 5,
            xtype:'label',
            text: 'الإسم'
        } ,{
            x: 370,
            y: 35,
            xtype:'label',
            text: 'إسم الشركة'
        },{
            x: 370,
            y: 65,
            xtype:'label',
            text: 'البريد الإلكتروني'
        },{
            x: 370,
            y: 95,
            xtype:'label',
            text: 'التليفون|المحمول'
        },{
            x: 370,
            y: 125,
            xtype:'label',
            text: 'مكان الإعلان'
        },{
            x: 0,
            y: 35,
            xtype:'label',
            text: 'Subject:'
        },{
            x: 0,
            y: 30,
            name: 'comname',
            anchor: '75%'  // anchor width by percentage
        },{
            x: 0,
            y: 60,
            name: 'email',
			vtype:'email',
            anchor: '75%'  // anchor width by percentage
        },{
            x: 0,
            y: 90,
            name: 'phone',
            anchor: '75%'  // anchor width by percentage
        },{
            x: 0,
            y: 120,
            name: 'adplace',
            anchor: '75%'  // anchor width by percentage
        },{
            x:0,
            y: 150,
            xtype: 'textarea',
            name: 'msg',
            anchor: '100% 100%'  // anchor width and height
        }]
    });
  
  var mywindow = new Ext.Window({
        title: '<div align=right>إعلن معنا</div>',
        width: 500,
		Style : "text-align:right;",		
		//closeAction : 'hide',
        height:300,
        minWidth: 300,
        minHeight: 200,
        layout: 'fit',
        plain:true,
		resizable : false,
		//hideMode : 'visibility',
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: form,

        buttons: [{
            text: 'إرسال',
			handler: function(){
				
				if(form.getForm().isValid() )
				{
            		form.getForm().submit({url:'test.php', waitMsg:'<div align=right>......جاري إرسال طلبك</div>', waitTitle  : '<div align=right>إرسال</div>', success : closeme() });
					//mywindow.close();
				}
       		 }
        },{
            text: 'إلغاء',
			handler: function(){
				mywindow.hide();
			 }
        }]
    });
  
	function closeme()
	{
		mywindow.hide();
	}
	mywindow.show();

}


Divo.app.PortletDemo = function() {
	/* ----------------------- private properties ----------------------- */
	var portId = 'app-portal-demo-res-portal';
	var settingId = 'app-portal-demo-ext-div';

	var portalState;
	var portalMgr;

	/* ----------------------- private method ----------------------- */
	function createLayout() {
		new Ext.Viewport( {
			id : 'app-portal-demo-main-view',
			layout : 'border',
			style : ' overflow-y: auto;position:relative;',
			items : [{
						region: 'north',
						contentEl : 'header',
						autoHeight: true,
						border: false,
						margins: '0 0 5 0'
					},
					{
						region : 'east',
						id : 'app-portal-demo-settings-panel',
						title : '<h1>أقسام الموقع</h1>',
						style : 'overflow: auto;',
						split : true,
						width : 200,
						//minSize : 175,
						//maxSize : 400,
						//height : 2000,
						//deferHeight : false,
						collapsible : false,
						margins : '5 20	 5 0',
						cmargins : '5 15 5 0',
						layout : 'anchor',
						border : true,
						items : [{
							//html : "<div id='"+settingId+"' dir=rtl style='display:'></div>",
							//region : 'north',
							//id : 'app-portal-demo-settings-exts',
							contentEl : 'menu',
							autoScroll : false,
							autoHeight : true,
							layout : 'fit'

						} , {
							html : "<div id='"+settingId+"' dir=rtl style='display:'></div>",
							title : '<h1>خصائص الصفحة</h1>',
							//region : 'north',
							id : 'app-portal-demo-settings-exts',
							//contentEl : 'menu',
							autoScroll : false,
							collapsible : true,
							autoHeight : true,
							margins : '5 0 5 0'
						} ,  {
							html : '<a title="powred by  And company" href="http://andcompanyonline.com"><img src="images/andco.jpg" border="0" alt="powred by And Company"></a>'
						} , {	
							//contentEl : 'menu',
							//region : 'center',
							text : 'الطقس',
							title : '<h1>الطقس </h1>',
							autoScroll : false,
							autoHeight : true,
							collapsible : true,
							layout : 'fit',
							autoLoad:  {url:'Blocks/weatherblock.php', scripts:true}
							},{	
							//contentEl : 'menu',
							//region : 'center',
							text : 'مواقيت الصلاة',
							title : '<h1>مواقيت الصلاة </h1>',
							autoScroll : false,
							collapsible : true,
							autoHeight : true,
							layout : 'fit',
							autoLoad:  {url:'prayers/prayerscalc_new.php', scripts:true}
							}, {
							html : '<img src="images/blueadv.jpg" style="cursor:pointer;" onclick="loadWindow();">'
						}]
					},
					{
						region : 'center',
						margins : '5 5 5 0',
						id : 'app-portal-demo-center-regn',
						layout : 'fit',
						style : 'overflow: auto;',

							autoHeight: true,

						items : [{
							xtype : 'portal',
							id : portId,
							autoHeight: true,

							items : [ {
								columnWidth : .42,
								style : 'padding:3px 0 3px 3px'
							}, {
								columnWidth : .58,
								style : 'padding:3px 3px 3px 3px'
							} ]
						},{
						html : ' <p align=center>Copyright © 2008 Egypt.com Inc. All rights Reserved <br></p>'
					}]
					}]
		});
	}

	/* ----------------------- public method ----------------------- */
	return {

		init : function() {
			Ext.state.Manager.setProvider(new Ext.state.CookieProvider( {
				exprires : new Date().add(Date.MONTH, 6)
			}));

			createLayout();

		//	portalState = new Divo.app.PortalState();
			//portalState.init(portId);

			//portalMgr = new Divo.app.PortalManager();
			//portalMgr.init(settingId,portId,portalState);

			//Ext.ComponentMgr.get(portId).on("drop", function() {
			//	portalState.save();
			//});
		}

	}; // return

}();

//Ext.onReady(Divo.app.PortletDemo.init, Divo.app.PortletDemo, true);

// EOP

Ext.onReady(function(){
					 
	var portId = 'app-portal-demo-res-portal';
	var settingId = 'app-portal-demo-ext-div';

	var portalState;
	var portalMgr;

		new Ext.Viewport( {
			id : 'app-portal-demo-main-view',
			layout : 'border',
			style : ' overflow-y: auto;position:relative;',
			items : [{
						region: 'north',
						contentEl : 'header',
						autoHeight: true,
						border: false,
						margins: '0 0 5 0'
					},
					{
						region : 'east',
						id : 'app-portal-demo-settings-panel',
						title : '<h1>أقسام الموقع</h1>',
						style : 'overflow: auto;',
						split : true,
						width : 200,
						//minSize : 175,
						//maxSize : 400,
						//height : 2000,
						//deferHeight : false,
						collapsible : false,
						margins : '5 20	 5 0',
						cmargins : '5 15 5 0',
						layout : 'anchor',
						border : true,
						items : [{
							//html : "<div id='"+settingId+"' dir=rtl style='display:'></div>",
							//region : 'north',
							//id : 'app-portal-demo-settings-exts',
							contentEl : 'menu',
							autoScroll : false,
							autoHeight : true,
							layout : 'fit'

						} , {
							html : "<div id='"+settingId+"' dir=rtl style='display:'></div>",
							title : '<h1>خصائص الصفحة</h1>',
							//region : 'north',
							id : 'app-portal-demo-settings-exts',
							//contentEl : 'menu',
							autoScroll : false,
							collapsible : true,
							autoHeight : true,
							margins : '5 0 5 0'
						} ,  {
							html : '<a title="powred by  And company" href="http://andcompanyonline.com"><img src="images/andco.jpg" border="0" alt="powred by And Company"></a>'
						} , {	
							//contentEl : 'menu',
							//region : 'center',
							text : 'الطقس',
							title : '<h1>الطقس </h1>',
							autoScroll : false,
							autoHeight : true,
							collapsible : true,
							layout : 'fit',
							autoLoad:  {url:'Blocks/weatherblock.php', scripts:true}
							},{	
							//contentEl : 'menu',
							//region : 'center',
							text : 'مواقيت الصلاة',
							title : '<h1>مواقيت الصلاة </h1>',
							autoScroll : false,
							collapsible : true,
							autoHeight : true,
							layout : 'fit',
							autoLoad:  {url:'prayers/prayerscalc_new.php', scripts:true}
							}, {
							html : '<img src="images/blueadv.jpg" style="cursor:pointer;" onclick="loadWindow();">'
						}]
					},
					{
						region : 'center',
						margins : '5 5 5 0',
						id : 'app-portal-demo-center-regn',
						layout : 'fit',
						style : 'overflow: auto;',

						autoHeight: true,

						items : [{
							//xtype : 'portal',
							//id : portId,
							autoHeight: true,
							items : [{
										 title:'<h1>:مـــــن نـــحـــن</h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus.html'}
										 }, {
										 title:'<h1>:مــــــاذا نقدم فى موقعنا ايجبــت.كـــوم </h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus1.html'}
										 } , {
										 title:'<h1>: دليل الشركات</h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus_coindex.html'}
										 }, {
										 title:'<h1>:دليل المواقع </h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus_webdir.html'}
										 }, {
										 title:'<h1>:دليل السياحة </h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus_tourism.html'}
										 }, {
										 title:'<h1>:تاريخ مصر  </h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus_history.html'}
										 }, {
										 title:'<h1>:دليل وظائف مصر </h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus_jobs.html'}
										 }, {
										 title:'<h1>:دليل المدينة </h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus_aroundtown.html'}
										 }, {
										 title:'<h1>:منتديات و مدونات و دردشة مصر  </h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus_forum.html'}
										 }, {
										 title:'<h1>:موقع المراة و الاسرة </h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus_lifestyle.html'}
										 } , {
										 title:'<h1>:الاعلانات المبوبة </h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus_classifieds.html'}
										 } , {
										 title:'<h1>:صحافة زمان </h1>',
										 collapsible : true,
										 autoLoad :{url : 'aboutus_oldpress.html'}
										 }     ]
						
						},{
						html : ' <p align=center>Copyright © 2008 Egypt.com Inc. All rights Reserved <br></p>'
					}]
					}]
		});
		
			var ds = new Ext.data.Store({
				//proxy: new Ext.data.HttpProxy({url: 'http://server.egypt.com/egypt/egydirectoryar/collector/searchtest.php',		
				proxy: new Ext.data.HttpProxy({url: 'fromgoogle.php',									
											  
				headers: {
					
					
				'Content-Type': 'application/x-www-form-urlencoded; charset=windows-1256'
				},
				method : 'GET',
				params : {MM:'1'}
				})
			  
			  
			  
			  ,
				reader: new Ext.data.JsonReader({
					root: 'topics',
					totalProperty: 'totalCount',
					//url: 'http://localhost/newegyptcom/examples/egypt/searchtest.php',
					id: 'post_id'
				}, [
					{name: 'title', mapping: 'topic_title'},
					{name: 'topicId', mapping: 'topic_id'},
					{name: 'author', mapping: 'author'},
					{name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
					{name: 'excerpt', mapping: 'post_text'}
				])
			});
		
		
		
			var googlrds = new Ext.data.Store({
				//proxy: new Ext.data.HttpProxy({url: 'http://server.egypt.com/egypt/egydirectoryar/collector/fromgoogle.php',		
				proxy: new Ext.data.HttpProxy({url: 'fromgoogle.php',									
											  
				headers: {
					
					
				'Content-Type': 'application/x-www-form-urlencoded; charset=windows-1256'
				},
				method : 'GET',
				params : {MM:'1'}
				})
			  
			  
			  
			  ,
				reader: new Ext.data.JsonReader({
					root: 'topics',
					totalProperty: 'totalCount',
					//url: 'http://localhost/newegyptcom/examples/egypt/searchtest.php',
					id: 'post_id'
				}, [
					{name: 'title', mapping: 'topic_title'},
					{name: 'topicId', mapping: 'topic_id'},
					{name: 'titletosend', mapping: 'titleencoded'},
					{name: 'lastPost', mapping: 'post_time'},
					{name: 'excerpt', mapping: 'post_text'}
				])
			});
		
		
			// Custom rendering Template
			var resultTpl = new Ext.XTemplate(
				'<tpl dir=rtl for="."><div dir=rtl class="search-item">  ',
					'<b>{title}</b>',
				'</div></tpl>'
			);
			
			var resultTpl_google = new Ext.XTemplate(
				'<tpl dir=rtl for="."><div dir=rtl class="search-item22" style="width:100%">  ',
					'<div style="float:right"><b>{title}</b></div><div style="float:left">{lastPost}</div>',
				'</div></tpl>'
			);
			
			
			var search = new Ext.form.ComboBox({
				store: ds,
				displayField:'title',
				typeAhead: false,
				loadingText: 'Searching...',
				//width: 570,
				pageSize:10,
				hideTrigger:true,
				tpl: resultTpl,
				mode : 'remote',
				applyTo: 'keyword',
				itemSelector: 'div.search-item',
				onSelect: function(record){ // override default onSelect to do redirect
					document.getElementById('keyword').value = record.data.title;
					document.form_search1.submit();
				   // window.location =
					 //   String.format('http://extjs.com/forum/showthread.php?t={0}&p={1}', record.data.topicId, record.id);
				}
			});
			
			
			var google_search = new Ext.form.ComboBox({
				store: googlrds,
				displayField:'title',
				typeAhead: false,
				loadingText: 'Searching...',
				//width: 570,
			  //  pageSize:20,
				hideTrigger:true,
				tpl: resultTpl_google,
				mode : 'remote',
				applyTo: 'q',
				itemSelector: 'div.search-item22',
				onSelect: function(record){ // override default onSelect to do redirect
					window.location = String.format('http://www.google.com.eg/search?complete=1&hl=en&q={0}&btnG=Google+Search&meta=cr%3DcountryEG&aq=f', record.data.titletosend);
				}	
			});
	
		
		
			document.getElementById('ext-gen11').style.height = 'auto'
			document.getElementById('search_3').style.display = 'none';

});

