//Ext.util.CSS.swapStyleSheet('theme', '../../extjs/resources/css/xtheme-gray-extend.css');
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
photoName = '';
var typeSelect;
var typeSelectSeat;
var routeParams1,r1,pCenter,from,to,travelType;
var playerRoute = new Array();
var xd = Ext.data;

var store = new Ext.data.JsonStore({
	data: {"images": [{"name":"","url":""}]},
         root: 'images',
         fields: ['name', 'url']
});    

var tpl = new Ext.XTemplate(
	'<tpl for=".">',
        '<div class="thumb-wrap" id="{name}">',
	    '<div class="thumb" style="margin-left:110px"><img src="{url}" title="{name}" width="200px"></div>',
    '</tpl>',
    '<div class="x-clear"></div>'
);

var captchaUrlUpdate = "http://"+window.location.hostname+"/?c=general&m=captcha" + '&time=' + new Date().getTime();

var captchaOther =  new Ext.BoxComponent({
	        xtype: 'container',
			id: 'captchaother',
			width: 150,
			height: 30,
            autoEl: {
				cls: 'captcha_box',
				ctCls : 'captcha_box',
				layout: 'fit',
				margins: '0 0 0 0',
				onClick: "updateCaptcha()", 
                tag: 'img',
				width: 150,
				height: 30,	
                id: 'activateOther',
                title: sf_scattafoto_form_ricarica_codice,
                src: captchaUrlUpdate
            }
});

var captchaLink =  new Ext.BoxComponent({
	        xtype: 'container',
			id: 'captchalink',
			width: 150,
			height: 30,
            autoEl: {
				cls: 'captcha_boxlink',
				ctCls : 'captcha_boxlink',
				layout: 'fit',
				margins: '0 0 0 0',
				onClick: "updateCaptchaLink()", 
                tag: 'img',
				width: 150,
				height: 30,	
                id: 'activateLink',
                title: is_form_ricarica_codice,
                src: captchaUrlUpdate
            }
});

var imagesphoto = new Ext.DataView({
            store: store,
            tpl: tpl,
			id: 'imagesphoto',
			width:150,
            autoHeight:true,
            multiSelect: false,
            overClass:'x-view-over',
            itemSelector:'div.thumb-wrap',
            emptyText: sf_form_no_immagine
        });

var images = new Ext.DataView({
            store: store,
            tpl: tpl,
			id: 'images',
			width:150,
            autoHeight:true,
            multiSelect: false,
            overClass:'x-view-over',
            itemSelector:'div.thumb-wrap',
            emptyText: sf_form_no_immagine
        });
		
var imagesInternal = new Ext.DataView({
            store: store,
            tpl: tpl,
			id: 'imagesinternal',
			width:150,
            autoHeight:true,
            multiSelect: false,
            overClass:'x-view-over',
            itemSelector:'div.thumb-wrap',
            emptyText: sf_form_no_immagine
        });		



var photoForm = new Ext.FormPanel({
    xtype: 'form',
    region: 'center',
    method: 'POST',
	buttonAlign: 'center',
	name: 'sendphoto',			
    id: 'sendphoto',
    fileUpload: true,
	labelWidth: 100,
    defaults: {
        width: 250
    },
    frame: true,
    defaultType: 'textfield',
    items: [{
        fieldLabel: sf_form_ragione,
        id: 'ragionesoc',		
        name: 'ragionesoc',
        allowBlank: false
    },{
        fieldLabel: sf_form_padiglione,
        id: 'padiglione',		
        name: 'padiglione',
        allowBlank: false
    },{
        fieldLabel: sf_form_indirizzo,
        id: 'indirizzo',		
        name: 'indirizzo',
        allowBlank: false
    },{
        fieldLabel: sf_form_comune,
        id: 'comune',		
        name: 'comune',
        allowBlank: false
    },{
        fieldLabel: sf_form_cap,
        id: 'cap',		
        name: 'cap',
        allowBlank: false
    },{
        fieldLabel: sf_form_telefono,
        id: 'telefono',		
        name: 'telefono',
        allowBlank: true
    },{
        fieldLabel: sf_form_fax,
        id: 'fax',		
        name: 'fax',
        allowBlank: true
    },{
        fieldLabel: sf_form_email,
        id: 'email',		
        name: 'email',
        vtype: 'email',
        allowBlank: true
    },{
        fieldLabel: sf_form_web,
        id: 'web',		
        name: 'web',
        vtype: 'url',
        allowBlank: true
    },{
        xtype: 'htmleditor',
		enableFont: false,
		enableColors: false,
		enableLinks: false,
		enableFontSize: false,
		enableLists: false,
        enableSourceEdit: false,
        id: 'commento',
        name: 'commento',
        fieldLabel: sf_form_commento,
        height: 150,
        width: 480,
        allowBlank: true
    },{
        xtype: 'checkbox',
        id: 'sponsor',
        name: 'sponsor',
        fieldLabel: sf_form_sponsor
    },images, {
        inputType: 'file',
        id: 'fileupload',
        fieldLabel: sf_form_cambia,
        name: 'fileupload',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    },{
        id: 'hiddencity',
        fieldLabel: '',
		labelSeparator: '',
        name: 'hiddencity',
		hidden: true
    },{
        id: 'hiddenphoto',
        fieldLabel: '',
		labelSeparator: '',
        name: 'hiddenphoto',
		hidden: true
    },{
        id: 'hiddenposition',
        fieldLabel: '',
		labelSeparator: '',
        name: 'hiddenposition',
		hidden: true
    }],
    buttons: [{
        text: sf_form_invia,
		id: 'invia',
		iconCls: 'sendmail',
		scale: 'medium',
		disabled: true,
        handler: function(){
			if (photoForm.getForm().isValid()) {
					photoForm.getForm().submit({
					url: '/?c=general&m=sendExpositorGen',
					waitMsg:label_caricamento,
					success: function(){
					   Ext.MessageBox.show({
				           title: is_invio_titolo_finestra,
				           msg: is_invio_alert,
				           buttons: Ext.MessageBox.OK,
						   animEl: 'animation',
				           icon: Ext.MessageBox.INFO
				       });
						winPhoto.hide();
						drawBusiness();
					},
					failure: function(){
						Ext.Msg.alert(is_invio_titolo_finestra, is_invio_alert_ko);
					}
				});		
			}
        }
    }]
});


var otherLink = new Ext.FormPanel({
    xtype: 'form',
    region: 'center',
    method: 'POST',
	buttonAlign: 'center',
	name: 'otherlink',			
    id: 'otherlink',
	labelWidth: 100,
    defaults: {
        //width: 250
    },
    frame: true,
   defaultType: 'textfield',
    items: [{
        fieldLabel: sf_scattafoto_form_nome,
        id: 'nomeother',		
        name: 'nomeother',
        allowBlank: false,
		width: 250
    },{
        fieldLabel: sf_scattafoto_form_cognome,
        id: 'cognomeother',		
        name: 'cognomeother',
        allowBlank: false,
		width: 250
    },{
        fieldLabel: sf_scattafoto_form_email_destinatario,
        id: 'emailother',		
        name: 'emailother',
        vtype: 'email',
        allowBlank: false,
		width: 250
    },{
        fieldLabel: sf_scattafoto_form_oggetto,
        id: 'objectother',
        name: 'objectother',
        allowBlank: false,
		width: 250
    }, {
        xtype: 'htmleditor',
        enableSourceEdit: false,
        id: 'commentother',
        name: 'commentother',
        fieldLabel: sf_scattafoto_form_messaggio,
        height: 150,
        width: 480,
        allowBlank: false
    },captchaOther,{
        fieldLabel: sf_scattafoto_form_codice_sicurezza,
        id: 'captchaconfirm',
        name: 'captchaconfirm',
		minLength: 8,
		maxLength: 8,
        allowBlank: false,
		width: 250
    },imagesphoto,{
		xtype: 'checkbox',
		id: 'privacyother',
		name: 'privacyother',
		boxLabel: sf_scattafoto_form_privacy,
		fieldLabel: '',
		width: 350,
		labelSeparator: '',
		allowBlank: false
	},{
        id: 'hiddenfieldother',
        fieldLabel: '',
		labelSeparator: '',
        name: 'hiddenfieldother',
		hidden: true
    },{
        id: 'othercity',
        fieldLabel: '',
		labelSeparator: '',
        name: 'othercity',
		hidden: true
    },{
        id: 'otherphoto',
        fieldLabel: '',
		labelSeparator: '',
        name: 'otherphoto',
		hidden: true
    }],
    buttons: [{
        text: sf_scattafoto_form_invia,
		id: 'inviaother',
		iconCls: 'sendmail',
		scale: 'medium',		
        handler: function(){
			if (otherLink.getForm().isValid() && Ext.getCmp('privacyother').getValue()) {
				Ext.Ajax.request({
					url: '/?c=general&m=sendOther',
					waitMsg:label_caricamento,
					params: {
						nomeother: Ext.getCmp('nomeother').getValue(),
						cognomeother: Ext.getCmp('cognomeother').getValue(),
						emailother: Ext.getCmp('emailother').getValue(),
						objectother: Ext.getCmp('objectother').getValue(),
						commentother: Ext.getCmp('commentother').getValue(),
						hiddenfieldother: Ext.getCmp('hiddenfieldother').getValue(),
						city: Ext.getCmp('othercity').getValue(),
						photo: Ext.getCmp('otherphoto').getValue(),
						captcha: Ext.getCmp('captchaconfirm').getValue()									
					},
                    success: function(response, opts){

						var result = eval(response.responseText);
						switch (result) {
	                        case true:
							   Ext.MessageBox.show({
						           title: sf_scattafoto_invio_titolo_finestra,
						           msg: sf_scattafoto_invio_alert,
						           buttons: Ext.MessageBox.OK,
								   animEl: 'animation',
						           icon: Ext.MessageBox.INFO
						       });
								winOtherLink.hide();
								break;
	                        case false:
								Ext.Msg.alert(sf_scattafoto_invio_titolo_finestra, sf_scattafoto_invio_alert_ko);
								break;
                   		 }						

                    },					
					failure: function(){
						Ext.Msg.alert(sf_scattafoto_invio_titolo_finestra, sf_scattafoto_invio_alert_ko);
					}
				})					
					
			}
        }
    }]

});

var linksForm = new Ext.FormPanel({
    xtype: 'form',
    region: 'center',
    method: 'POST',
	name: 'sendlinkform',	
    id: 'sendlinkform',
	buttonAlign: 'center',
    fileUpload: true,
	labelWidth: 150,
    defaults: {
        width: 250
    },
    frame: true,
   // errorReader: new Ext.form.XmlErrorReader(),
   defaultType: 'textfield',
    items: [{
        fieldLabel: is_form_nome,
        id: 'nome',
        name: 'nome',
        allowBlank: false
    },{
        fieldLabel: is_form_cognome,
        id: 'cognome',
        name: 'cognome',
        allowBlank: false
    },{
        fieldLabel: is_form_email,
        id: 'email',
        name: 'email',
        vtype: 'email',
        allowBlank: false
    },{
        fieldLabel: is_form_oggetto,
        id: 'object',
        name: 'object',
        allowBlank: false
    }, {
        inputType: 'file',
        id: 'fileupload1',
        fieldLabel: is_form_allegato1,
        name: 'attachment1',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    }, {
        inputType: 'file',
        id: 'fileupload2',
        fieldLabel: is_form_allegato2,
        name: 'attachment2',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    }, {
        inputType: 'file',
        id: 'fileupload3',
        fieldLabel: is_form_allegato3,
        name: 'attachment3',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    }, {
        inputType: 'file',
        id: 'fileupload4',
        fieldLabel: is_form_allegato4,
        name: 'attachment4',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    },{
        id: 'hiddenfield',
        fieldLabel: '',
		labelSeparator: '',
        name: 'hiddenfield',
		hidden: true
    },{
        id: 'hiddencitylink',
        fieldLabel: '',
		labelSeparator: '',
        name: 'hiddencitylink',
		hidden: true
    },{
		xtype: 'textarea',
		id: 'comment',
		name: 'comment',
		fieldLabel: is_form_messaggio,
		height: 150,
		width: 400,
		allowBlank: false		
    },captchaLink,{
        fieldLabel: is_form_codice_sicurezza,
        id: 'captchalinkconfirm',
        name: 'captchalinkiconfirm',
		minLength: 8,
		maxLength: 8,
        allowBlank: false,
		width: 250
    },{
		xtype: 'checkbox',
		id: 'privacylinkform',
		name: 'privacylinkform',
		boxLabel: is_form_privacy,
		fieldLabel: '',
		width: 350,
		labelSeparator: '',
		allowBlank: false
	}],
    
	buttons: [{
        text: is_form_invia,
		iconCls: 'sendmail',
		scale: 'medium',		
		handler: function(){
			if (linksForm.getForm().isValid() && Ext.getCmp('privacylinkform').getValue()) {
				linksForm.getForm().submit({
					url: '/?c=general&m=sendLink',
					//waitMsg: 'Invio email in corso...',
					//waitTitle: 'Attendere prego...',
					success: function(){
					   Ext.MessageBox.show({
				           title: is_invio_titolo_finestra,
				           msg: is_invio_alert,
				           buttons: Ext.MessageBox.OK,
						   animEl: 'animation',
				           icon: Ext.MessageBox.INFO
				       });
						winLink.hide();
					},
					failure: function(){
						Ext.Msg.alert(is_invio_titolo_finestra, is_invio_alert_ko);
					//win.hide();
					}
				});	
			}
        }
    }]

});


var winLink = new Ext.Window({
    title: is_titolo_finestra,
	closeAction: 'hide',
    closable: true,
    width: 630,
    height: 570,
    plain: true,
    layout: 'border',
    items: [linksForm]
});

var winOtherLink = new Ext.Window({
    title: sf_scattafoto_titolo,
	closeAction: 'hide',
    closable: true,
    width: 630,
    height: 580,
    plain: true,
    layout: 'border',
    items: [otherLink]
});

var winPhoto = new Ext.Window({
    title: sf_titolo_finestra,
	closeAction: 'hide',
    closable: true,
    width: 630,
    height: 670,
    plain: true,
    layout: 'border',
    items: [photoForm]
});

winLink.on("show",function(){
	var defaultMessage = getPosition();
	Ext.getCmp('hiddenfield').setValue(defaultMessage);
	Ext.getCmp('hiddencitylink').setValue(document.getElementById("city").value);
	updateCaptchaLink();
});	


winLink.on("beforeshow",function(){
	linksForm.getForm().reset();
	
});	

winOtherLink.on("show",function(){
	var defaultMessage = getPosition();
	Ext.getCmp('hiddenfieldother').setValue(defaultMessage);
	Ext.getCmp('othercity').setValue(document.getElementById("city").value);
	photoName = document.getElementById("city").value+'_'+Math.random()+'.png';
	thisMovie('gmaps').savePic('/save.php', photoName);
	updateCaptcha();
	Ext.getCmp('otherphoto').setValue(photoName);	
});	

winOtherLink.on("beforeshow",function(){
	otherLink.getForm().reset();
	Ext.getCmp('inviaother').disable(true);
	imagesphoto.store.removeAll();	
});

winPhoto.on("show",function(){
	var defaultMessage = getLatLngUV();
	Ext.getCmp('hiddencity').setValue(document.getElementById("city").value);
	Ext.getCmp('hiddenposition').setValue(defaultMessage);	
	photoName = document.getElementById("city").value+'_'+Math.random()+'.png';
	thisMovie('gmaps').savePic('/save.php', photoName);
	Ext.getCmp('hiddenphoto').setValue(photoName);	
});	

winPhoto.on("beforeshow",function(){
	photoForm.getForm().reset();
	Ext.getCmp('invia').disable(true);
	images.store.removeAll();
});	


function getPos(){
	if (this.isReady && this.isOpen())
	{
		return this.getMovie().getLatLongRot();
	}
}

function showMsg(){
	Ext.MessageBox.show({
		title: 'Errore',
		msg: 'Prima di inviare informazioni sul malfunzionamento devi aprire il Player di Geomondo.eu',
		buttons: Ext.MessageBox.OK,
		animEl: 'animation',
		icon: Ext.MessageBox.INFO
	});
}

function showMsgLink(){
	Ext.MessageBox.show({
		title: il_titolo_alert,
		msg: il_alert,
		buttons: Ext.MessageBox.OK,
		animEl: 'animation',
		icon: Ext.MessageBox.INFO
	});
}

function showMsgSeg(){
	Ext.MessageBox.show({
		title: is_titolo_alert,
		msg: is_alert,
		buttons: Ext.MessageBox.OK,
		animEl: 'animation',
		icon: Ext.MessageBox.INFO
	});
}

function showMsgPrint(){
	Ext.MessageBox.show({
		title: sp_titolo_alert,
		msg: sp_alert,
		buttons: Ext.MessageBox.OK,
		animEl: 'animation',
		icon: Ext.MessageBox.INFO
	});
}

function getPosition(){
	var position = getPos();
	position.push(document.getElementById("hiddenid").value);
	return Ext.encode(position);
}

function getOtherPosition(){
	var position = getPos();
	var associati = document.getElementById("city").value;
	var link = '<a href="http://'+window.location.hostname+'/?c='+associati+'&lat='+position[0]+'&lon='+position[1]+'&u='+position[2]+'&v='+position[3]+'">qui<a>';	
	var defaultMessage = 'Utente segnala un problema-disagio posizionato '+link+'.<br><br>';
	return defaultMessage;
}

function getLatLngUV(){
	var position = getPos();
	position.push(document.getElementById("hiddenid").value);
	return Ext.encode(position);
}
	
function updateImage(foto){
	var newImage=new Array()
	newImage['name'] = photoName;
	newImage['url'] = '/tmp/'+photoName;
	var rec = new Ext.data.Record(newImage);
	(foto == 'internal') ? imagesInternal.store.add(rec) : images.store.add(rec);
	store.load();
}	

function updateCaptcha(){
	Ext.get('activateOther').dom.src =  "http://"+window.location.hostname+"/?c=general&m=captcha" + '&time=' + new Date().getTime();
}	

function updateCaptchaLink(){
	Ext.get('activateLink').dom.src =  "http://"+window.location.hostname+"/?c=general&m=captcha" + '&time=' + new Date().getTime();
}

function getDirection(){
	var directionsPanel = document.getElementById("route");
	directions = new GDirections(g_map, directionsPanel);
	if (typeSelect.getValue() == 1) 
		var travelType = G_TRAVEL_MODE_WALKING;
	else if (typeSelect.getValue() == 2) 	
		var travelType = G_TRAVEL_MODE_DRIVING;
	else if (typeSelect.getValue() == 3) 	
		var travelType = G_TRAVEL_MODE_TRANSIT;
    directions.load("from: "+Ext.getCmp('from').getRawValue()+" "+Ext.getCmp('provinciacomune').getValue()+" to: "+Ext.getCmp('to').getRawValue()+" "+Ext.getCmp('provinciacomune').getValue(), {travelMode:travelType});
}	


function getDirectionSeat(){
	var directionsPanel = document.getElementById("route");
	if (typeSelectSeat.getValue() == 1) 
		travelType = PGROUTE_TYPE_PED;
	else if (typeSelectSeat.getValue() == 2) 	
		travelType = PGROUTE_TYPE_CAR;
	else if (typeSelectSeat.getValue() == 3) 	
		travelType = PGROUTE_TYPE_CAR_BEST_DIST;
	else if (typeSelectSeat.getValue() == 4) 	
		travelType = PGROUTE_TYPE_CAR_NO_TOLL;	
	if (Ext.getCmp('roadtype').getValue() == 'Vie') {
		var start = new PGGeoCod({
			provincia: 'VE',
			comune: 'Venezia',
			indirizzo: Ext.getCmp('from').getRawValue(),
			civico: null,
			onComplete: 'afterGeoCodFrom'
		});
		
		var end = new PGGeoCod({
			provincia: 'VE',
			comune: 'Venezia',
			indirizzo: Ext.getCmp('to').getRawValue(),
			civico: null,
			onComplete: 'afterGeoCodTo'
		});
	} else {
	    from = new PGPoint({ lon:Ext.getCmp('longitudestart').getValue(),lat:Ext.getCmp('latitudestart').getValue(),txt: tp_label_partenza});	
		seatMap.pointAdder(from);
	    to = new PGPoint({ lon:Ext.getCmp('longitudeend').getValue(),lat:Ext.getCmp('latitudeend').getValue(), txt: tp_label_arrivo});
		seatMap.pointAdder(to);
		pCenter = seatMap.getRouteCenter([from,to]);
		routeParams1 = {id:'myroute1',
	                  pStart:from,
	                  pEnd:to,
	                  rt: travelType,
	                  rgb:{r:255, g:0, b:0},
					  initZ:pCenter.z,
	                  initLon:pCenter.lon,
	                  initLat:pCenter.lat,				  
	                  lineWidth:15};
	  	seatMap.getRoute(routeParams1, 'afterRoute');	
		Ext.getCmp('winroad').close();				
	}						
}

function afterRoute(route){
  r1 = route;
/*  for(i=0;i<r1.coords.length;i++){
  	    var px = seatMap.getLonLatFromPixel(r1.coords[i].x, r1.coords[i].y);
        var pt = new PGPoint({lon:px.lon, lat:px.lat}); 
		playerRoute.push(pt);
  }*/
  var routeList = [{routeParams:routeParams1, route:r1}];
  seatMap.addRoute(routeList);
}

function afterGeoCodFrom(pgAddress){
  if (pgAddress) {
    from = new PGPoint({ pgAddress:pgAddress,
                                    txt: tp_label_partenza});
    seatMap.pointAdder(from);
  }
}

function afterGeoCodTo(pgAddress){
  if (pgAddress) {
    to = new PGPoint({ pgAddress:pgAddress,
                                    txt: tp_label_arrivo});
    seatMap.pointAdder(to);
	pCenter = seatMap.getRouteCenter([from,to]);
	routeParams1 = {id:'myroute1',
                  pStart:from,
                  pEnd:to,
                  rt: travelType,
                  rgb:{r:255, g:0, b:0},
				  initZ:pCenter.z,
                  initLon:pCenter.lon,
                  initLat:pCenter.lat,				  
                  lineWidth:15};
  	seatMap.getRoute(routeParams1, 'afterRoute');	
	Ext.getCmp('winroad').close();
  }  
}

function showRoadCalc(){
	if (Ext.getCmp('winroad')){
		Ext.getCmp('winroad').show();
	}
	else {		
		typeSelect = new Ext.form.ComboBox({
			fieldLabel: tp_label_percorso,
			id: 'typeroad',
			xtype: 'combo',
			triggerAction: 'all',
			emptyText: tp_value_percorso,
			readOnly: true,
			listWidth: 150,
			width: 150,
			name: 'typeroad',
			allowBlank: false,
			typeAhead: true,
			lazyRender: true,
			mode: 'local',
			store: new Ext.data.ArrayStore({
				id: 0,
				fields: ['myId', 'displayText'],
				data: [[1, tp_value_percorso_ped], [2, tp_value_percorso_auto], [3, tp_value_percorso_pub]]
			}),
			valueField: 'myId',
			displayField: 'displayText'
		});
		
		var readerFromTo = new Ext.data.JsonReader({
			totalProperty: "totalCount",
			root: "address",
			id: "id"
		}, [{
			name: 'id',
			mapping: 'ID',
			type: 'string'
		}, {
			name: 'cap',
			mapping: 'cap',
			type: 'string'
		}, {
			name: 'provincia',
			mapping: 'provincia',
			type: 'string'
		}, {
			name: 'comune',
			mapping: 'comune',
			type: 'string'
		}, {
			name: 'address',
			mapping: 'address',
			type: 'string'
		}]);
		
		var storeFromTo = new Ext.data.Store({
			proxy: new Ext.data.HttpProxy({
				url: '/?c=general&m=loadFromTo&comuneid=' + document.getElementById("hiddenid").value
			}),
			reader: readerFromTo
		});
		
		var addressTpl = new Ext.XTemplate('<tpl for="."><div class="search-item" style="BORDER-BOTTOM: #dfe8f6 1px solid">', '<h3>{address}</h3>{provincia} {comune}', '</div></tpl>');
		
		var roadForm = new Ext.FormPanel({
			xtype: 'form',
			region: 'center',
			method: 'POST',
			buttonAlign: 'center',
			name: 'roadform',
			id: 'roadform',
			//labelWidth: 100,
			frame: true,
			items: [{
				fieldLabel: tp_label_partenza,
				xtype: 'combo',
				width: 250,
				id: 'from',
				store: storeFromTo,
				//		hiddenId: 'idnew',
				//     	hiddenName: 'idnota',		  
				displayField: 'address',
				valueField: 'id',
				loadingText: tp_label_ricerca,
				pageSize: 40,
				minChars: 0,
				queryDelay: 500,
				listWidth: 250,
				triggerAction: 'all',
				forceSelection: false,
				typeAhead: false,
				emptyText: tp_value_partenza,
				tpl: addressTpl,
				itemSelector: 'div.search-item',
				name: 'from',
				allowBlank: false
			}, {
				fieldLabel: tp_label_arrivo,
				xtype: 'combo',
				width: 250,
				store: storeFromTo,
				id: 'to',
				store: storeFromTo,
				displayField: 'address',
				valueField: 'id',
				loadingText: tp_label_ricerca,
				pageSize: 40,
				minChars: 0,
				queryDelay: 500,
				listWidth: 250,
				triggerAction: 'all',
				forceSelection: false,
				typeAhead: false,
				emptyText: tp_value_arrivo,
				tpl: addressTpl,
				itemSelector: 'div.search-item',
				name: 'to',
				allowBlank: false
			}, typeSelect,
			{
				xtype: 'textfield',
		        id: 'provinciacomune',
		        fieldLabel: '',
				labelSeparator: '',
		        name: 'provinciacomune',
				hidden: true				
			}],
			buttons: [{
				text: tp_label_bt_calcola,
				iconCls: 'search',
				scale: 'medium',
				handler: function(){
					if (roadForm.getForm().isValid()) {
						if (typeof(window['directions']) != "undefined") 
							directions.clear();
						getDirection();
					}
				}
			}, {
				text: tp_label_bt_cancella,
				iconCls: 'delete',
				scale: 'medium',
				handler: function(){
					seatMap.removePoint(from);
					seatMap.removePoint(to);
					directions.clear();
				}
			}],
			html: '<div id="route" style="overflow:auto; height:200px;"></div>'
		
		});
		
		var winRoad = new Ext.Window({
			title: tp_titolo_finestra,
			closeAction: 'hide',
			id: 'winroad',
			closable: true,
			width: 430,
			height: 400,
			plain: true,
			layout: 'border',
			items: [roadForm]
		});
		
		typeSelect.on("render", function(){
			this.setValue(1);
		});
		
		Ext.getCmp('from').on("select", function(select, record){
			Ext.getCmp('provinciacomune').setValue(record.data.provincia+' '+record.data.comune);
		});
		
		winRoad.show('animation');
	}
}

function showRoadCalcSeat(){
		typeSelectSeat = new Ext.form.ComboBox({
			fieldLabel: tp_label_percorso,
			id: 'typeroad',
			xtype: 'combo',
			triggerAction: 'all',
			emptyText: tp_value_percorso,
			readOnly: true,
			listWidth: 150,
			width: 150,
			name: 'typeroad',
			allowBlank: false,
			typeAhead: true,
			lazyRender: true,
			mode: 'local',
			store: new Ext.data.ArrayStore({
				id: 0,
				fields: ['myId', 'displayText'],
				data: [[1, tp_value_percorso_ped], [2, tp_value_percorso_auto], [3, tp_value_percorso_pub]]
			}),
			valueField: 'myId',
			displayField: 'displayText'
		});
		
		var readerFromTo = new Ext.data.JsonReader({
			totalProperty: "totalCount",
			root: "address",
			id: "id"
		}, [{
			name: 'id',
			mapping: 'ID',
			type: 'string'
		}, {
			name: 'cap',
			mapping: 'cap',
			type: 'string'
		}, {
			name: 'provincia',
			mapping: 'provincia',
			type: 'string'
		}, {
			name: 'comune',
			mapping: 'comune',
			type: 'string'
		}, {
			name: 'address',
			mapping: 'address',
			type: 'string'
		}]);
		
		
		var readerFromToPoi = new Ext.data.JsonReader({
			totalProperty: "totalCount",
			root: "address",
			id: "id"
		}, [{
			name: 'id',
			mapping: 'ID',
			type: 'string'
		}, {
			name: 'name',
			mapping: 'NAME',
			type: 'string'
		}, {
			name: 'latitude',
			mapping: 'LATITUDE',
			type: 'string'
		}, {
			name: 'longitude',
			mapping: 'LONGITUDE',
			type: 'string'
		}]);		
		
		var storeFromTo = new Ext.data.Store({
			proxy: new Ext.data.HttpProxy({
				url: '/?c=general&m=loadFromTo&comuneid=' + document.getElementById("hiddenid").value
			}),
			reader: readerFromTo
		});

		var storeFromToPoi = new Ext.data.Store({
			proxy: new Ext.data.HttpProxy({
				url: '/?c=general&m=loadFromToPoi&comuneid=' + document.getElementById("hiddenid").value
			}),
			reader: readerFromToPoi
		});				

		var addressTplPoi = new Ext.XTemplate('<tpl for="."><div class="search-item" style="BORDER-BOTTOM: #dfe8f6 1px solid">', '<h3>{name}</h3>', '</div></tpl>');
		
		var addressTpl = new Ext.XTemplate('<tpl for="."><div class="search-item" style="BORDER-BOTTOM: #dfe8f6 1px solid">', '<h3>{address}</h3>{provincia} {comune}', '</div></tpl>');
		
		var roadFormSeat = new Ext.FormPanel({
			xtype: 'form',
			region: 'center',
			method: 'POST',
			buttonAlign: 'center',
			name: 'roadform',
			id: 'roadform',
			//labelWidth: 100,
			frame: true,
			items: [{
				fieldLabel: tp_label_partenza,
				xtype: 'combo',
				width: 250,
				id: 'from',
				store: storeFromTo,	  
				displayField: 'address',
				valueField: 'id',
				loadingText: tp_label_ricerca,
				pageSize: 40,
				minChars: 0,
				queryDelay: 500,
				listWidth: 250,
				triggerAction: 'all',
				forceSelection: false,
				typeAhead: false,
				emptyText: tp_value_partenza,
				tpl: addressTpl,
				itemSelector: 'div.search-item',
				name: 'from',
				allowBlank: false
			}, {
				fieldLabel: tp_label_arrivo,
				xtype: 'combo',
				width: 250,
				id: 'to',
				store: storeFromTo,
				displayField: 'address',
				valueField: 'address',
				loadingText: tp_label_ricerca,
				pageSize: 40,
				minChars: 0,
				queryDelay: 500,
				listWidth: 250,
				triggerAction: 'all',
				forceSelection: false,
				typeAhead: false,
				emptyText: tp_value_arrivo,
				tpl: addressTpl,
				itemSelector: 'div.search-item',
				name: 'to',
				allowBlank: false
			},{
				fieldLabel: tp_label_partenza,
				xtype: 'combo',
				width: 250,
				id: 'fromPoi',
				store: storeFromToPoi,		  
				displayField: 'name',
				valueField: 'name',
				loadingText: tp_label_ricerca,
				pageSize: 40,
				minChars: 0,
				disabled: true,
				queryDelay: 500,
				listWidth: 250,
				triggerAction: 'all',
				forceSelection: false,
				typeAhead: false,
				emptyText: tp_value_partenza_poi,
				tpl: addressTplPoi,
				itemSelector: 'div.search-item',
				name: 'from',
				allowBlank: false
			}, {
				fieldLabel: tp_label_arrivo,
				xtype: 'combo',
				width: 250,
				id: 'toPoi',
				store: storeFromToPoi,
				displayField: 'name',
				valueField: 'name',
				loadingText: tp_label_ricerca,
				pageSize: 40,
				minChars: 0,
				disabled: true,
				queryDelay: 500,
				listWidth: 250,
				triggerAction: 'all',
				forceSelection: false,
				typeAhead: false,
				emptyText: tp_value_arrivo_poi,
				tpl: addressTplPoi,
				itemSelector: 'div.search-item',
				name: 'to',
				allowBlank: false
			}, typeSelectSeat,
			{
		            xtype: 'radiogroup',
		            fieldLabel: tb_label_road_type,
					id: 'roadtype',
		            columns: 2,
					getValue: function() {
					    var v;
					    this.items.each(function(item) {
					        if (!item.getValue()) return true;
					        v = item.getRawValue();
					        return false;
					    });
					    return v;
					},	
		            items: [
		                {boxLabel: tb_label_street, name: 'radiotype', inputValue: 'Vie',checked: true},
		                {boxLabel: 'POI', name: 'radiotype', inputValue: 'POI'}
		            ]
        		},{
				xtype: 'textfield',
		        id: 'provinciacomune',
		        fieldLabel: '',
				labelSeparator: '',
		        name: 'provinciacomune',
				hidden: true				
			},{
				xtype: 'textfield',
		        id: 'latitudestart',
		        fieldLabel: '',
				labelSeparator: '',
		        name: 'latitudestart',
				hidden: true				
			},{
				xtype: 'textfield',
		        id: 'longitudestart',
		        fieldLabel: '',
				labelSeparator: '',
		        name: 'longitudestart',
				hidden: true				
			},{
				xtype: 'textfield',
		        id: 'latitudeend',
		        fieldLabel: '',
				labelSeparator: '',
		        name: 'latitudeend',
				hidden: true				
			},{
				xtype: 'textfield',
		        id: 'longitudeend',
		        fieldLabel: '',
				labelSeparator: '',
		        name: 'longitudeend',
				hidden: true				
			}],
			buttons: [{
				text: tp_label_bt_calcola,
				iconCls: 'search',
				scale: 'medium',
				handler: function(){
					i
					if (roadFormSeat.getForm().isValid() && (Ext.getCmp('from').getValue() != Ext.getCmp('to').getValue() || Ext.getCmp('fromPoi').getValue() != Ext.getCmp('toPoi').getValue())) {
						if (typeof(from) != "undefined") {
							seatMap.removeRoute('myroute1');
							seatMap.removePoint(from);
							seatMap.removePoint(to);							
						}
						if (g_playerIsOpen)
							playerClose();
						getDirectionSeat();
						
					}
				}
			}, {
				text: tp_label_bt_cancella,
				iconCls: 'delete',
				scale: 'medium',
				handler: function(){
					seatMap.removePoint(from);
					seatMap.removePoint(to);
					seatMap.removeRoute('myroute1');
				}
			}],
			html: '<div id="route" style="overflow:auto; height:200px;"></div>'
		
		});
		
		var winRoadSeat = new Ext.Window({
			title: tp_titolo_finestra,
			//closeAction: 'hide',
			id: 'winroad',
			closable: true,
			width: 430,
			height: 400,
			plain: true,
			layout: 'border',
			items: [roadFormSeat]
		});
		
		typeSelectSeat.on("render", function(){
			this.setValue(1);
		});
		
		Ext.getCmp('from').on("select", function(select, record){
			Ext.getCmp('provinciacomune').setValue(record.data.provincia+' '+record.data.comune);
		});
		
		Ext.getCmp('fromPoi').on("select", function(select, record){
			Ext.getCmp('latitudestart').setValue(record.data.latitude);
			Ext.getCmp('longitudestart').setValue(record.data.longitude);
		});
		Ext.getCmp('toPoi').on("select", function(select, record){
			Ext.getCmp('latitudeend').setValue(record.data.latitude);
			Ext.getCmp('longitudeend').setValue(record.data.longitude);
		});
		
		Ext.getCmp('roadtype').on("change",function(group, value){
			var roadtype = Ext.getCmp('roadtype').getValue();
			if (roadtype == 'Vie'){
				Ext.getCmp('from').enable();
				Ext.getCmp('to').enable();	
				Ext.getCmp('fromPoi').disable(true);
				Ext.getCmp('toPoi').disable(true);				
			} else {
				Ext.getCmp('fromPoi').enable();
				Ext.getCmp('toPoi').enable();	
				Ext.getCmp('from').disable(true);
				Ext.getCmp('to').disable(true);					
			}
				
		})		
		
		winRoadSeat.show('animation');
		
		

}


var poiUserGen = new Ext.Panel({
	xtype: 'panel',
	region: 'center',
	margins: '0 0 0 0',
	activeTab: 0,
	id: 'poiusergen',
	defaults: {
		autoScroll: true
	},
	layout: 'fit',
	defaultType: "iframepanel",
	frame: false,
	items: [{
		id: 'poiusergenframe',
		loadMask: {
			msg: label_caricamento
		}
	}]
});

var winPoiUserGen = new Ext.Window({
	title: gw_titolo_finestra,
	id: 'poiusergenwin',
	closable: true,
	closeAction: 'hide',
	modal: false,
	width: 555,
	height: document.documentElement.clientHeight - 50,
	layout: 'border',
	x: document.documentElement.clientWidth - 570,
	items: [poiUserGen]
});

var poiUserGenBest= new Ext.Panel({
	xtype: 'panel',
	region: 'center',
	margins: '0 0 0 0',
	activeTab: 0,
	id: 'poiusergenbest',
	defaults: {
		autoScroll: true
	},
	layout: 'fit',
	defaultType: "iframepanel",
	frame: false,
	items: [{
		id: 'poiusergenframebest',
		loadMask: {
			msg: label_caricamento
		}
	}]
});

var winPoiUserGenBest = new Ext.Window({
	title: mp_titolo_finestra,
	id: 'poiusergenwinbest',
	closable: true,
	closeAction: 'hide',
	modal: false,
	width: 555,
	height: document.documentElement.clientHeight - 50,
	layout: 'border',
	x: document.documentElement.clientWidth - 570,
	items: [poiUserGenBest]
});


function popupCredits(){
 	var url = "/?c=general&m=credits&comune="+document.getElementById("city").value;
	if (Ext.getCmp('creditsframe')) {
		Ext.getCmp('creditsframe').setLocation(url);
	}
 	else {
		var credits = new Ext.Panel({
			xtype: 'panel',
			region: 'center',
			margins: '0 0 0 0',
			activeTab: 0,
			id: 'credits',
			defaults: {
				autoScroll: true
			},
			layout: 'fit',
			defaultType: "iframepanel",
			frame: false,
			items: [{
				id: 'creditsframe',
				loadMask: {
					msg: label_caricamento
				}
			}]
		});
		
		var winCredits = new Ext.Window({
			title: cr_titolo_finestra,
			id: 'winCredits',
			closable: true,
			modal: false,
			width: 655,
			height: document.documentElement.clientHeight - 50,
			layout: 'border',
			x: document.documentElement.clientWidth - 670,
			items: [credits]
		});
		
		winCredits.show();
		
		Ext.getCmp('creditsframe').setLocation(url);
	}
	winCredits.setPagePosition(document.documentElement.clientWidth - 670,15);
}

function popupHelp(video){
 	//var url = "/?c=general&m=helpVideo&comune="+document.getElementById("city").value+video;
	var url = "/general/helpVideo/"+document.getElementById("city").value+video;
	if (Ext.getCmp('helpframe')) {
		Ext.getCmp('helpframe').setLocation(url);
	}
 	else {
		var help = new Ext.Panel({
			xtype: 'panel',
			region: 'center',
			margins: '0 0 0 0',
			activeTab: 0,
			id: 'help',
			defaults: {
				autoScroll: true
			},
			layout: 'fit',
			defaultType: "iframepanel",
			frame: false,
			items: [{
				id: 'helpframe',
				loadMask: {
					msg: label_caricamento
				}
			}]
		});
		
		var winHelp = new Ext.Window({
			title: la_titolo_finestra,
			id: 'winHelp',
			closable: true,
			modal: false,
			width: 715,
			height: document.documentElement.clientHeight - 150,
			layout: 'border',
			x: document.documentElement.clientWidth - 930,
			items: [help]
		});
		winHelp.show();
		
		Ext.getCmp('helpframe').setLocation(url);
	}
	Ext.getCmp('winHelp').setWidth(715);
	Ext.getCmp('winHelp').setHeight(document.documentElement.clientHeight - 150);
	winHelp.setPagePosition(document.documentElement.clientWidth - 800,120);
}



var poiSponsor = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
		//url: '',
		disableCaching : true
	}),
	reader: new Ext.data.JsonReader({
		totalProperty: 'totalCount',
		root: 'poisponsor',
		id: 'id'
		}, [
		{name: 'id', mapping: 'id', type: 'int'},
		{name: 'nome', mapping: 'nome', type: 'string'}		  
	])
});

var associatiSelect = new Ext.form.ComboBox({		
	fieldLabel: sf_form_associa,
	id: 'associati',
	xtype: 'combo',
	hiddenId: 'idnew',
	hiddenName: 'idpoi',		  
	displayField:'nome',
	valueField: 'id',
	loadingText: 'Ricerca...',
	triggerAction: 'all',
	width:250,
	listWidth:250,
	forceSelection: true,
	minChars:0,
	typeAhead: true,	
	name: 'aifa',
	store: poiSponsor,
	typeAhead: true,
	emptyText: 'Seleziona il POI...',
	allowBlank: false
});		  	  


var sponsorForm = new Ext.FormPanel({
    xtype: 'form',
    region: 'center',
    method: 'POST',
	buttonAlign: 'center',
	name: 'sponsorphoto',			
    id: 'sponsorphoto',
    fileUpload: true,
	labelWidth: 100,
    defaults: {
        width: 250
    },
    frame: true,
    defaultType: 'textfield',
    items: [{
        fieldLabel: sf_form_nomeogg,
        id: 'nomeoggetto',		
        name: 'nomeoggetto',
        allowBlank: false
    },{
        xtype: 'htmleditor',
		enableFont: false,
		enableColors: false,
		enableLinks: false,
		enableFontSize: false,
		enableLists: false,
        enableSourceEdit: false,
        id: 'commentosponsor',
        name: 'commentosponsor',
        fieldLabel: sf_form_commento,
        height: 150,
        width: 480,
        allowBlank: true
    },associatiSelect,{
        inputType: 'file',
        id: 'video1',
        fieldLabel: 'Video 1',
        name: 'video1',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    },{
        inputType: 'file',
        id: 'video2',
        fieldLabel: 'Video 2',
        name: 'video2',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    },{
        inputType: 'file',
        id: 'video3',
        fieldLabel: 'Video 3',
        name: 'video3',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    },{
        inputType: 'file',
        id: 'foto1',
        fieldLabel: 'Foto 1',
        name: 'foto1',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    },{
        inputType: 'file',
        id: 'foto2',
        fieldLabel: 'Foto 2',
        name: 'foto2',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    },{
        inputType: 'file',
        id: 'foto3',
        fieldLabel: 'Foto 3',
        name: 'foto3',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    },{
        inputType: 'file',
        id: 'attach',
        fieldLabel: sf_form_allegato,
        name: 'attach',
        buttonCfg: {
            text: '',
            iconCls: 'upload-icon'
        }
    },imagesInternal,{
        id: 'hiddenphotosponsor',
        fieldLabel: '',
		labelSeparator: '',
        name: 'hiddenphotosponsor',
		hidden: true
    },{
        id: 'hiddenpositionsponsor',
        fieldLabel: '',
		labelSeparator: '',
        name: 'hiddenpositionsponsor',
		hidden: true
    }
	],
    buttons: [{
        text: sf_form_invia,
		id: 'inviaSponsor',
		iconCls: 'sendmail',
		scale: 'medium',
		disabled: true,
        handler: function(){
			if (sponsorForm.getForm().isValid()) {
					sponsorForm.getForm().submit({
					url: '/?c=general&m=sendExpositorInternal',
					waitMsg:label_caricamento,
					success: function(){
					   Ext.MessageBox.show({
				           title: is_invio_titolo_finestra,
				           msg: is_invio_alert,
				           buttons: Ext.MessageBox.OK,
						   animEl: 'animation',
				           icon: Ext.MessageBox.INFO
				       });
						winSponsor.hide();
					},
					failure: function(){
						Ext.Msg.alert(is_invio_titolo_finestra, is_invio_alert_ko);
					}
				});		
			}
        }
    }]
});

var winSponsor = new Ext.Window({
    title: sf_titolo_finestra,
	closeAction: 'hide',
    closable: true,
    width: 630,
    height: 670,
    plain: true,
    layout: 'border',
    items: [sponsorForm]
});

winSponsor.on("show",function(){
	var defaultMessage = getLatLngUV();
	Ext.getCmp('hiddenpositionsponsor').setValue(defaultMessage);	
	photoName = document.getElementById("city").value+'_'+Math.random()+'.png';
	thisMovie('gmaps').savePic('/save.php', photoName);
	Ext.getCmp('hiddenphotosponsor').setValue(photoName);	
});	

winSponsor.on("beforeshow",function(){
	sponsorForm.getForm().reset();
	Ext.getCmp('inviaSponsor').disable(true);
	imagesInternal.store.removeAll();
	delete poiSponsor.proxy.api;
	poiSponsor.proxy.setUrl('/?c=general&m=getPoiSponsor&evento='+id_comune,true);
	poiSponsor.load()
});



// definisco ifrom poi autogenerati
var addPoiPanel = new Ext.Panel({
	xtype: 'panel',
	region: 'center',
	margins: '0 0 0 0',
	activeTab: 0,
	id: 'addpoi',
	defaults: {
		autoScroll: true
	},
	layout: 'fit',
	defaultType: "iframepanel",
	frame: false,
	items: [{
		id: 'addpoiframe',
		loadMask: {
			msg: label_caricamento
		}
	}]
});

//definisco finestra poi autogenerati
var winAddPoi = new Ext.Window({
	title: gw_titolo_finestra,
	id: 'addpoiwin',
	closeAction: 'hide',
    closable: true,
    width: 630,
    height: 500,
    plain: true,
	layout: 'border',
	items: [addPoiPanel]
});

// redirigo la finesrta di add poi con il suo di aggiunta poi
function popupAddpoi() {
	
	var url = '/general/addpoiuser/'+id_comune;
	Ext.getCmp('addpoiwin').show();
	Ext.getCmp('addpoiframe').setLocation(url);
	
}

function hideAddpoi() {
	
	Ext.getCmp('addpoiwin').hide();
		
}


function getPos(){
    var mov = thisMovie("gmaps");
    var path = mov.getLatLongRot();
	var latlonguv = path.split(','); // split on commas
	return latlonguv;
}

function savePicResultError() {
	Ext.Msg.alert(errore_salva_immagine_titolo, errore_salva_immagine);	
}

function savePicResultComplete(){
	if (Ext.getCmp('imagesphoto').isVisible()) {
		Ext.getCmp('inviaother').enable();
		updateImage('internal');
	} else {
		Ext.getCmp('invia').enable();
		updateImage();
	}
	
}

function openFrame(link) {
	var site = [link+'?iframe=true&width=85%&height=95%'];
	$.prettyPhoto.open(site);
}

function openHelp(video) {
	var url = "/general/helpVideo/"+$("#city").val()+video;
	var site = [url+'?iframe=true&width=700&height='+$(document).height()*.8];
	$.prettyPhoto.open(site);
}

function openCredits() {
	var url = "/?c=general&m=credits&comune="+$("#city").val();
	var site = [url+'&iframe=true&width=670&height='+$(document).height()*.8];
	$.prettyPhoto.open(site);
}

function openPrint(){
	if (seatMap.getMapType() == 1)
		var map = 'map';
	else if (seatMap.getMapType() == 2)
		var map = 'orto';
	else if (seatMap.getMapType() == 3)
		var map = 'mix';		
	var geocoderMap = new PGGeoRevCod({lon:g_marker.lon,lat:g_marker.lat,onComplete:'afterGeoRevCod'});
	if (g_playerIsOpen){
		var photoNameRand = $("#city").val()+'_'+Math.random()+'.png';
		thisMovie('gmaps').savePic('/save.php', photoNameRand);
	} else {
		var photoNameRand = "";
	}
 	var url = "/?c=general&m=printMap&x="+g_marker.lon+"&y="+g_marker.lat+"&sm="+map+"&playeropen="+g_playerIsOpen+"&address="+addressMap+"&playerpic="+photoNameRand;
	var site = [url+'?iframe=true&width=950&height='+$(document).height()*.8];
	$.prettyPhoto.open(site);
}

function popupPrint() {
/*	if (seatMap.getMapType() == 1)
		var map = 'map';
	else if (seatMap.getMapType() == 2)
		var map = 'orto';
	else if (seatMap.getMapType() == 3)
		var map = 'mix';		
	var geocoderMap = new PGGeoRevCod({lon:g_marker.lon,lat:g_marker.lat,onComplete:'afterGeoRevCod'});
	*/
	if (g_playerIsOpen){
		var photoNameRand = document.getElementById("city").value+'_'+Math.random()+'.png';
		thisMovie('gmaps').savePic('/save.php', photoNameRand);
	} else {
		var photoNameRand = "";
	}
	var pointPrint = g_marker.getLatLng();
	geocoder = new GClientGeocoder();
	getAddress(pointPrint);
	
 	var url = "/?c=general&m=printMap&x="+pointPrint.lng()+"&y="+pointPrint.lat()+"&sm=map&playeropen="+g_playerIsOpen+"&address="+addressMap+"&playerpic="+photoNameRand;
	if (Ext.getCmp('printframe')) {
		Ext.getCmp('printframe').setLocation(url);
	}
 	else {
		var print = new Ext.Panel({
			xtype: 'panel',
			region: 'center',
			margins: '0 0 0 0',
			activeTab: 0,
			id: 'print',
			defaults: {
				autoScroll: true
			},
			layout: 'fit',
			defaultType: "iframepanel",
			frame: false,
			items: [{
				id: 'printframe',
				loadMask: {
					msg: label_caricamento
				}
			}]
		});
		
		var winPrint = new Ext.Window({
			title: stampa_titolo_finestra,
			id: 'winPrint',
			closable: true,
			modal: true,
			width: 750,
			height: document.documentElement.clientHeight - 50,
			layout: 'border',
			items: [print]
		});
		
		winPrint.show();
		winPrint.setWidth(800);
		Ext.getCmp('printframe').setLocation(url);
	}
}
