function addFile2(url_for, id, code, type, param)
{
	dialog = new Ext.ux.UploadDialog.Dialog({
	  url: url_for,
          base_params: {id: id, code: code, type: type, param: param},
	  reset_on_hide: false,
	  allow_close_on_upload: true,
	  upload_autostart: false,
	  post_var_name: 'photo'
	});

	dialog.show();
	
}



function sendOrder(url_for, id)
{
    var win;
    var dlg = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        title: 'Отправить сообщение',
        bodyStyle:'padding:5px 5px 0',
        width: 400,
        defaults: {width: 200},
        defaultType: 'textfield',

        items: [{fieldLabel: 'Email',
                id: 'email',
		name: 'email',
                vtype:'email'},
		{fieldLabel: 'Имя',
                id: 'name',
		name: 'name',
                vtype:'textfield'},
		{fieldLabel: 'Телефон',
                id: 'phone',
		name: 'phone',
                vtype:'textfield'},
		new Ext.form.DateField({
                fieldLabel: 'с ',
		id: 'date1',
                name: 'date1',
		format: 'd-m-Y'
            	})
		,
		new Ext.form.DateField({
                fieldLabel: 'по ',
		id: 'date2',
                name: 'date2',
		format: 'd-m-Y'
            	}),
		{fieldLabel: 'Кол-во человек',
                id: 'people',
		name: 'people',
                vtype:'textfield'},
		new Ext.form.TextArea({
                	fieldLabel:'Заказ и Ваши данные',
	                id: 'post',
        	        name: 'post',
                	height:150,
			value: '',
		        multiline: true,
	        	anchor:'98%'
		})	
	      ],
        buttons: [{
            text:'Отправить',
            disabled: false,
            handler: function(){
                var msg = function (){
                   Ext.MessageBox.show({msg: 'Отправление данных...',
           	   progressText: 'Отправление...',
           	   width:300});
                }
		var dt1 = dlg.getComponent('date1').getValue();
		var dt2 = dlg.getComponent('date2').getValue();
			
 		Ext.Ajax.on('beforerequest', msg, this);
                Ext.Ajax.request({
		  url: url_for,
		  success: function(result){
			Ext.MessageBox.hide();
			alert(result.responseText);	
			win.close();
			},
		  failure: function(result) {
			Ext.MessageBox.hide();
			alert('Не удалось отправить сообщение');
		        },
		  method: 'POST',
		  //Параметры вызова
		  params: {
		           id: id,
			   email: dlg.getComponent('email').getValue(),
			   name: dlg.getComponent('name').getValue(),
			   post: dlg.getComponent('post').getValue(),
			   phone: dlg.getComponent('phone').getValue(),
			   date1: dt1.format("d.m.y"),
			   date2: dt2.format("d.m.y"),
			   people: dlg.getComponent('people').getValue()					
		        }
		})
           }    
                        
        },
	{
           text: 'Закрыть',
           handler: function(){
                   win.close();
               }
        }]

     });
     if(!win){
       win = new Ext.Window({
           layout:'fit',
           width:500,
           height:440,
           closeAction:'close',
           plain: true,
           items: dlg
       });
     }
     win.show();
}

function sendRequest(url_for, id)
{
    var win;
    var dlg = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        title: 'Отправить сообщение',
        bodyStyle:'padding:5px 5px 0',
        width: 400,
        defaults: {width: 200},
        defaultType: 'textfield',

        items: [{fieldLabel: 'Email',
                id: 'email',
		name: 'email',
                vtype:'email'},
		{fieldLabel: 'Имя',
                id: 'name',
		name: 'name',
                vtype:'textfield'},
		new Ext.form.TextArea({
                	fieldLabel:'Сообщение',
	                id: 'post',
        	        name: 'post',
                	height:150,
			value: '',
		        multiline: true,
	        	anchor:'98%'
		})	
	      ],
        buttons: [{
            text:'Отправить',
            disabled: false,
            handler: function(){
                var msg = function (){
                   Ext.MessageBox.show({msg: 'Отправление данных...',
           	   progressText: 'Отправление...',
           	   width:300});
                }
 		Ext.Ajax.on('beforerequest', msg, this);
                Ext.Ajax.request({
		  url: url_for,
		  success: function(result){
			Ext.MessageBox.hide();
			alert(result.responseText);	
			win.close();
			},
		  failure: function(result) {
			Ext.MessageBox.hide();
			alert('Не удалось отправить сообщение');
		        },
		  method: 'POST',
		  //Параметры вызова
		  params: {
		           id: id,
			   email: dlg.getComponent('email').getValue(),
			   name: dlg.getComponent('name').getValue(),
			   post: dlg.getComponent('post').getValue()	
		        }
		})
           }    
                        
        },
	{
           text: 'Закрыть',
           handler: function(){
                   win.close();
               }
        }]

     });
     if(!win){
       win = new Ext.Window({
           layout:'fit',
           width:500,
           height:300,
           closeAction:'close',
           plain: true,
           items: dlg
       });
     }
     win.show();
}

function forgetPass(url_for)
{
    var win;
    var els = new Array(1);
    els[0] = new Ext.form.TextField({
                fieldLabel:'Ваш e-mail',
                id: 'email',
                name: '',
		value: '',
                anchor:'98%'
	});
    
     var dlg = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        title: 'Восстановление пароля',
        bodyStyle:'padding:5px 5px 0',
        width: 400,
        defaults: {width: 200},
        defaultType: 'textfield',
        items: els,
        buttons: [{
            text:'Отправить',
            disabled: false,
            handler: function(){
                var msg = function (){
                   Ext.MessageBox.show({msg: 'Отправление данных...',
           	   progressText: 'Отправление...',
           	   width:300});
                }
 		Ext.Ajax.on('beforerequest', msg, this);
                Ext.Ajax.request({
		  url: url_for,
		  success: function(result){
			alert(result.responseText);	
			Ext.MessageBox.hide();
			win.close();
			},
		  failure: function(result) {
			Ext.MessageBox.hide();
			alert('Не удалось отправить сообщение');
		        },
		  method: 'POST',
		  //Параметры вызова
		  params: {
		           email: dlg.getComponent('email').getValue()	
		        }
		})
           }    
                        
        },
	{
           text: 'Закрыть',
           handler: function(){
                   win.close();
               }
        }]

     });
     if(!win){
       win = new Ext.Window({
           layout:'fit',
           width:500,
           height:300,
           closeAction:'close',
           plain: true,
           items: dlg
       });
     }
     win.show();  
}

function addToForum(url_for, id, elem_update)
{
    var win;
    Ext.QuickTips.init(); 
    var els = new Array(2);
    els[0] = new Ext.form.TextField({
                fieldLabel:'Заголовок',
                id: 'title',
                name: 'title',
		value: '',
                anchor:'98%'
	});
    els[1] = new Ext.form.HtmlEditor({
                fieldLabel:'Сообщение',
                id: 'post',
                name: 'post',
                height:150,
		value: '',
	        /*multiline: true,*/
	        anchor:'98%'
	});
   var dlg = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        title: 'Добавить',
        bodyStyle:'padding:5px 5px 0',
        width: 550,
        defaults: {width: 200},
        defaultType: 'textfield',
        items: els,
        buttons: [{
            text:'Отправить',
            disabled: false,
            handler: function(){
                var msg = function (){
                   Ext.MessageBox.show({msg: 'Отправление данных...',
           	   progressText: 'Отправление...',
           	   width:300});
                }
 		Ext.Ajax.on('beforerequest', msg, this);
                Ext.Ajax.request({
		  url: url_for,
		  success: function(result){
			if(elem_update.length > 0)
			{
			   Ext.get(elem_update).update(result.responseText);	
			}
			Ext.MessageBox.hide();
			win.close();
			},
		  failure: function(result) {
			Ext.MessageBox.hide();
			alert('Не удалось отправить сообщение');
		        },
		  method: 'POST',
		  //Параметры вызова
		  params: {
		           id: id,
			   title: dlg.getComponent('title').getValue(),
			   post: dlg.getComponent('post').getValue()	
		        }
		})
           }    
                        
        },
	{
           text: 'Закрыть',
           handler: function(){
                   win.close();
               }
        }]

     });
     if(!win){
       win = new Ext.Window({
           layout:'fit',
           width:650,
           height:300,
           closeAction:'close',
           plain: true,
           items: dlg
       });
     }
     win.show();
}
function getTabs(elem, url_to)
{
	Ext.QuickTips.init(); 
	var win;
	var tabs = new Ext.TabPanel({
 	        resizeTabs:true, // turn on tab resizing
	        minTabWidth: 200,
	        tabWidth:350,
	        enableTabScroll:true,
	        width:500,
	        height:400,
		activeTab:0,
                deferredRender:false,
		defaults: {autoScroll:true}
		
        });
	
	if(elem.tabs.text)
	{
		var els = new Array();
		
		for(i in elem.tabs.text)
		{
			var tmp = elem.tabs.text[i];
			els.push(new Ext.form.TextField({
                		fieldLabel: tmp.code,
                		id: tmp.code,
		                name: tmp.code,
				value: tmp.value,
		                anchor:'98%'
			}));	
			
		}
		tabs.add({
			title:'Текстовые',
	                layout:'form',
        	        defaults: {width: 150},
                	defaultType: 'textfield',
	                items: els
			
		});

		
	}
	
	if(elem.tabs.image)
	{
		var els = new Array();
		
		for(i in elem.tabs.image)
		{
			var tmp = elem.tabs.image[i];
			els.push(new Ext.form.TextField({
                		fieldLabel: tmp.code,
                		id: tmp.code,
		                name: tmp.code,
				value: tmp.value,
		                anchor:'98%'
			}));	
			
		}
		tabs.add({
			title:'Изображения',
	                layout:'form',
        	        defaults: {width: 150},
                	defaultType: 'textfield',
	                items: els
			
		});

		
	}

	if(elem.tabs.html)
	{
		for(i in elem.tabs.html)
		{
			var tmp = elem.tabs.html[i];
			tabs.add({
				title: tmp.code,
		                layout:'form',
        		        items: new Ext.form.TextArea({
        	        		id: tmp.code,
					name: tmp.code,
		        	        value: tmp.value,
					width: 350,
					height: 300
				})
			});
			
			
		}
		
	}

	if(elem.tabs.bool)
	{
		var els = new Array();
		
		for(i in elem.tabs.bool)
		{
			var tmp = elem.tabs.bool[i];
			els.push(new Ext.form.TextField({
                		fieldLabel: tmp.code,
                		id: tmp.code,
		                name: tmp.code,
				value: tmp.value,
		                anchor:'98%'
			}));	
			
		}
		tabs.add({
			title:'Да/Нет',
	                layout:'form',
        	        defaults: {width: 50},
                	defaultType: 'textfield',
	                items: els
			
		});
	}	

	if(elem.tabs.float)
	{
		var els = new Array();
		
		for(i in elem.tabs.float)
		{
			var tmp = elem.tabs.float[i];
			els.push(new Ext.form.TextField({
                		fieldLabel: tmp.code,
                		id: tmp.code,
		                name: tmp.code,
				value: tmp.value,
		                anchor:'98%'
			}));	
			
		}
		tabs.add({
			title:'Вещественные',
	                layout:'form',
        	        defaults: {width: 100},
                	defaultType: 'textfield',
	                items: els
			
		});
	}
	if(elem.tabs.int)
	{
		var els = new Array();
		
		for(i in elem.tabs.int)
		{
			var tmp = elem.tabs.int[i];
			els.push(new Ext.form.TextField({
                		fieldLabel: tmp.code,
                		id: tmp.code,
		                name: tmp.code,
				value: tmp.value,
		                anchor:'98%'
			}));	
			
		}
		tabs.add({
			title:'Целые и ссылочные',
	                layout:'form',
        	        defaults: {width: 100},
                	defaultType: 'textfield',
	                items: els
			
		});
	}
	tabs.add({
		title: 'Вспомогательные',
		layout:'form',
        	defaults: {width: 150},
	        items: [new Ext.form.TextField({
        		id: 'code',
			name: 'code',
		        value: elem.code,
			width: 100
		}),new Ext.form.TextField({
        		id: 'id',
			name: 'id',
		        value: elem.id,
			width: 100
		})
		]
	});	
	/**/
	var form = new Ext.FormPanel({
        		labelWidth: 75, // label settings here cascade unless overridden
		        frame:true,
        		title: 'Элемент',
		        bodyStyle:'padding:5px 5px 0',
		        width: 500,
		        height:400,//defaults: {width: 500},
		        items: tabs,
			buttons: [{
                    		text:'Сохранить',
		                disabled:false,
				handler: function(){
					 		   
			            form.getForm().submit(
					{
						url: url_to, 
						waitMsg: 'Сохранение данных...',
						failure: function(){Ext.MessageBox.hide();}
					}
				   );
			        }
        	        },{
                	    	text: 'Закрыть',
	                	handler: function(){
	                        win.close();
        	            }
                	}]
	});
		
	if(!win){
            win = new Ext.Window({
                layout:'fit',
                width:550,
                height:450,
                closeAction:'hide',
                plain: true,
                items: form
                
            });
        }
        win.show();
	
}

function initForm(url_for, type, object_id, url_to)
{
	var msg = function (){
           Ext.MessageBox.show({msg: 'Инициализация...',
           progressText: 'Инициализация...',
           width:300});
        }
                

	Ext.Ajax.on('beforerequest', msg, this);
        Ext.Ajax.request({
	  url: url_for,
	  success: function(result){
		var tmp = Ext.util.JSON.decode(result.responseText);	
	        if(tmp.id == 0)
		{
			alert(tmp.msg);	
		}else
		{	
			getTabs(tmp, url_to);
		}
		Ext.MessageBox.hide();
	  },
	  failure: function(result) {
		Ext.MessageBox.hide();
		alert('Связь прервалась. Попробуйте еще раз.');
	  },
	  method: 'POST',
	  //Параметры вызова
	  params: {
	       code: type,
	       object_id: object_id	
	  }
       });	
}

function moveImage(move_to)
{
	var first_vis = -1;
	var first_hide = -1;
	var j = 0;
	var el = Ext.query('div#images a');
	if(move_to)
	{
		for(var i = 0; i < el.length; i++)
		{
		    var tmp = Ext.get(el[i]);
		    if(tmp.getStyle('display') == 'inline')
			j ++;	
		    if(tmp.getStyle('display') == 'inline' && first_vis < 0)
		    {
		        first_vis = i;
		    }else
		    {
                
			if(tmp.getStyle('display') == 'none' && first_hide < 0 && first_vis > -1)
			{
                		first_hide = i;
	                }
		    }	
		}	  	
	}else
	{
	 	for(var i = el.length -1; i > -1; i--)
		{
		    var tmp = Ext.get(el[i]);
		    if(tmp.getStyle('display') == 'inline')
			j ++;	
		    if(tmp.getStyle('display') == 'inline' && first_vis < 0)
		    {
		        first_vis = i;
		    }else
		    {
                
			if(tmp.getStyle('display') == 'none' && first_hide < 0 && first_vis > -1)
			{
                		first_hide = i;
	                }
		    }	
		} 
	}

	if(el.length > 5)
	{
	   if(first_vis > -1 && first_hide > -1 && j == 5)
	   {
		tmp = Ext.get(el[first_vis]);
		tmp.setStyle('display', 'none');	
		tmp = Ext.get(el[first_hide]);
		tmp.setStyle('display', 'inline');	
	   }		
	}
	
}

function changeBlogWin(url_for, elem_update, id, url_res)
{
	var tmp;
	Ext.Ajax.request({
		  url: url_res,
		  success: function(result){
			tmp = Ext.util.JSON.decode(result.responseText);	
			Ext.MessageBox.hide();
			addBlogWin(url_for, elem_update, id, tmp.title, tmp.post);
			Ext.MessageBox.hide();
			},
		  failure: function(result) {
			Ext.MessageBox.hide();
			alert('Не удалось отправить сообщение');
		        },
		  method: 'POST',
		  params: {id: id}	
		});
	return tmp;
}

function addBlogWin(url_for, elem_update, id, title, post)
{
    //Ext.QuickTips.init();
    var win;
    Ext.QuickTips.init(); 
    // create the window on the first click and reuse on subsequent clicks
    var els = new Array(2);
    els[0] = new Ext.form.TextField({
                fieldLabel:'Заголовок',
                id: 'title',
                name: 'title',
		value: title,
                anchor:'98%'
	});
    els[1] = new Ext.form.HtmlEditor({
                fieldLabel:'Текст',
                id: 'post',
                name: 'post',
                height:150,
		value: post,
	        /*multiline: true,*/
	        anchor:'98%'
	});
   /* 
    els[2] = new Ext.form.Checkbox({
                fieldLabel:'Публиковать',
                id: 'ispublished',
                name: 'ispublished',
		height: 10,
		checked: true
	});

    els[3] = new Ext.form.Checkbox({
                fieldLabel:'Разрешить комментарии',
                id: 'allowcomments',
                name: 'allowcomments',
		checked: true,
                anchor: '10%'
	});	
    */
    var dlg = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        title: 'Отправить',
        bodyStyle:'padding:5px 5px 0',
        width: 550,
        defaults: {width: 200},
        defaultType: 'textfield',
        items: els,
        buttons: [{
            text:'Отправить',
            disabled: false,
            handler: function(){
                var msg = function (){
                   Ext.MessageBox.show({msg: 'Отправление данных...',
           	   progressText: 'Отправление...',
           	   width:300});
                }
                

		Ext.Ajax.on('beforerequest', msg, this);
                Ext.Ajax.request({
		  url: url_for,
		  success: function(result){
			if(elem_update.length > 0)
			{
			   Ext.get(elem_update).update(result.responseText);	
			}
			Ext.MessageBox.hide();
			win.close();
			},
		  failure: function(result) {
			Ext.MessageBox.hide();
			alert('Не удалось отправить сообщение');
		        },
		  method: 'POST',
		  //Параметры вызова
		  params: {
		           id: id,
			   title: dlg.getComponent('title').getValue(),
			   post: dlg.getComponent('post').getValue()	
		        }
		})
           }    
                        
        },
	{
           text: 'Закрыть',
           handler: function(){
                   win.close();
               }
        }]

     });
     if(!win){
       win = new Ext.Window({
           layout:'fit',
           width:650,
           height:300,
           closeAction:'close',
           plain: true,
           items: dlg
       });
     }
     win.show();
}

function winToggle(el,lat, lng, message)
{
	var tmp = Ext.get(el);
	if(tmp.getStyle('display') =='block')
	{
		tmp.setStyle('display', 'none');
	}else
	{
		tmp.setStyle('display', 'block');
		initialize(lat, lng, message);
	}

}

function opinionWinToggle(url_for, object_id)
{
    var opinion = Ext.get('opinion1');
    if(opinion.getStyle('visibility')=='hidden')
    {
	Ext.Ajax.request({
	  url: url_for,
	  success: function(result){
	     Ext.get('opinion1').update(result.responseText);
	     Ext.MessageBox.hide();	
	     },
	  failure: function(result) {
	     Ext.MessageBox.hide();		
	     alert('Связь с сервером прервалась.');
	     },
	  method: 'POST',
	     //Параметры вызова
	  params: {
		id : object_id
	    }
	});	
    }
    opinion.toggle(true);
    
}
	
function opinionWin(url_for, object_id)
{
    Ext.QuickTips.init();
    var win;
    // create the window on the first click and reuse on subsequent clicks
    var els = new Array(1);
    els[0] = new Ext.form.TextArea({
                fieldLabel:'Отзыв',
                id: 'opinion',
                name: 'opinion',
                height:150,
	        multiline: true,
	        anchor:'98%'
	});
    var dlg = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        title: 'Отправить',
        bodyStyle:'padding:5px 5px 0',
        width: 400,
        defaults: {width: 200},
        defaultType: 'textfield',
        items: els,
        buttons: [{
            text:'Отправить',
            disabled: false,
            handler: function(){
                var msg = function (){
                   Ext.MessageBox.show({msg: 'Отправление данных...',
           	   progressText: 'Отправление...',
           	   width:300});
                }
                

		Ext.Ajax.on('beforerequest', msg, this);
                Ext.Ajax.request({
		  url: url_for,
		  success: function(result){
			Ext.MessageBox.hide();
			win.close();
			},
		  failure: function(result) {
			Ext.MessageBox.hide();
			alert('Не удалось отправить сообщение');
		        },
		  method: 'POST',
		  //Параметры вызова
		  params: {id : object_id, 
		           msg: dlg.getComponent('opinion').getValue()
		  }
		})
           }    
                        
        },
	{
           text: 'Закрыть',
           handler: function(){
                   win.close();
               }
        }]

     });
     if(!win){
       win = new Ext.Window({
           layout:'fit',
           width:500,
           height:300,
           closeAction:'close',
           plain: true,
           items: dlg
       });
     }
     win.show();
}


function updateObjectType1(url_for, elem_id,new_name)
{
	Ext.get("obj_head").update(new_name);
	
	Ext.Ajax.request({
		    url: url_for,
		    //success request
		    success: function(result){
		    	Ext.get("obj_content").update(result.responseText);          
                        initLightbox();
			Ext.MessageBox.hide();
		    },
		    failure: function(){
			Ext.MessageBox.hide();	
		    	alert('Error of connect' + url_for);
		    },
		    //method´
		    method: 'POST',
			params: {id: elem_id}
		});
}

function updateSimpleDiv(url_for, div_id)
{
	Ext.Ajax.request({
		    url: url_for,
		    //success request
		    success: function(result){
		    	Ext.get(div_id).update(result.responseText);          
			Ext.MessageBox.hide();
			initLightbox();
		    },
		    failure: function(){
			Ext.MessageBox.hide();
		    	alert('Error of connect');
		    },
		    //method´
		    method: 'POST'
		});
}

function updateInformer(tab_name, url_for)
{
	/*if(tab_name == 'weather')
	{
		Ext.get('img_weather').dom.src = '/images/tab1.gif';
		Ext.get('img_curs').dom.src = '/images/tab2.gif';
	}
	else
		if(tab_name == 'curs')
		{
			Ext.get('img_weather').dom.src = '/images/tab2.gif';
			Ext.get('img_curs').dom.src = '/images/tab1.gif';
		}		
	*/
	Ext.Ajax.request({
		    url: url_for,
		    //success request
		    success: function(result){
			Ext.MessageBox.hide();
		    	Ext.get('informer').update(result.responseText);          
		    },
		    failure: function(){
			Ext.MessageBox.hide();
		    	alert('Error of connect');
		    },
		    //method´
		    method: 'POST'
		});
}

function nextNews(url_for, currpage, perpage, pagecount, with_pagination, update_id)
{
	Ext.Ajax.request({
		    url: url_for,
		    //success request
		    success: function(result){
			Ext.MessageBox.hide();
		    	Ext.get(update_id).update(result.responseText);          
		    },
		    failure: function(){
			Ext.MessageBox.hide();
		    	alert('Error of connect');
		    },
		    //method´
		    method: 'POST',
		    //params
		    params: {perpage: perpage, currpage: currpage, pagecount: pagecount, with_p: with_pagination}
		});

}

