<?xml version="1.0"?>
<?xml-stylesheet href="../skin/styles_ovl.css" type="text/css"?>
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<script>
<![CDATA[
	function openPays(zn)
	{
		var params =
		{
			inn:
			{
				noms:		'Pays',
				zone:		'pays'+zn,
				table: 	'tbl_pays',
				prefix:	'pay_',
				verif:	'verifDeletePays'
			},
			
			out:null
		};
		 
		popupDialog('dlg_listes.xul', 1, 0, 0, params);
		
		$('pays1_datas').builder.rebuild();
		$('pays2_datas').builder.rebuild();
	}

	function verifDeletePays(val)
	{
		return false;
		
		var sql = "SELECT tit_id FROM" + TABLE +
							"WHERE tit_fk_produits=?1 " +
							"LIMIT 1";
				
		var req=_exec_sql(sql, val);
	
		if (req.executeStep())
			return false;
			
		return true;
	}
   
  function openCpBe(zn)
  {
		var pays= $('pays'+zn).value;
		
		if (pays>1)
			return false;

		var params ={};

		popupDialog('dlg_cp_be.xul', 1, 0, 0, params);

		if (params.out)
		{
			$('cp'+zn).value=		params.out.cp;
			$('ville'+zn).value=params.out.ville;
		}
  }
	
	function inverseAdresses()
	{
		var pays=		$('pays1').value;
		var rue=		$('rue1').value;
		var cp=			$('cp1').value;
		var ville=	$('ville1').value;
		var etat=		$('etat1').value;
		
		$('pays1').value=		$('pays2').value;
		$('rue1').value=		$('rue2').value;
		$('cp1').value=			$('cp2').value;
		$('ville1').value=	$('ville2').value;
		$('etat1').value=		$('etat2').value;
		
		$('pays2').value=		pays;
		$('rue2').value=		rue;
		$('cp2').value=			cp;
		$('ville2').value=	ville;
		$('etat2').value=		etat;
	}
]]>
</script>

<vbox id="ovl_adresses">
<hbox>

<grid>
	<columns>
		<column />
    <column />
		<column />
  </columns>
	
	<rows>
		<row align="center">
			<label value="Pays" control="pays1" />
			<menulist id="pays1">
				<menupopup
								id="pays1_datas"
								datasources="datas/datas.sqlite"
								querytype="storage"
								ref="*">
					<menuitem value="0" label="-" />
			
					<template>
						<query>
							SELECT pay_id, pay_libelle
							FROM tbl_pays
							ORDER BY 2
						</query>
			
						<action>
							<menuitem uri="?" value="?pay_id" label="?pay_libelle" />
						</action>
					</template>
				</menupopup>
			</menulist>
			<toolbarbutton image="img/application_form_edit.png" tooltiptext="Ouvre la gestion des pays" oncommand="openPays(1)" />
		</row>
		<row align="center">
			<label value="Adresse" control="rue1" />
			<textbox id="rue1" multiline="true" />
		</row>
		<row align="center">
			<label value="CP" control="cp1" />
			<box align="center">
				<textbox size="7" id="cp1" />
				<label value="Ville" control="ville1" />
				<textbox id="ville1" />
			</box>
			<toolbarbutton image="img/house.png" tooltiptext="Ouvre la gestion des codes postaux" oncommand="openCpBe(1)" />
		</row>
		<row align="center">
			<label value="État" control="etat1" />
			<textbox id="etat1" />
		</row>
	</rows>
</grid>
	
<!--
-->
	<box style="padding-bottom:50px;" align="center">
		<toolbarbutton image="img/arrow_refresh.png" tooltiptext="Inverse les adresses" oncommand="inverseAdresses()" />
	</box>
<!--
-->
<grid>
  <columns>
		<column />
    <column />
		<column />
  </columns>
	
	<rows>
		<row align="center">
			<label value="Pays" control="pays2" />
			<menulist id="pays2">
				<menupopup
								id="pays2_datas"
								datasources="datas/datas.sqlite"
								querytype="storage"
								ref="*">
					<menuitem value="0" label="-" />
				
					<template>
						<query>
							SELECT pay_id, pay_libelle
							FROM tbl_pays
							ORDER BY 2
						</query>
			
						<action>
							<menuitem uri="?" value="?pay_id" label="?pay_libelle" />
						</action>
					</template>
				</menupopup>
			</menulist>
      <toolbarbutton image="img/application_form_edit.png" tooltiptext="Ouvre la gestion des pays" oncommand="openPays(2)" />
    </row>
    <row align="center">
      <label value="Adresse" control="rue2" />
      <textbox id="rue2" multiline="true" />
    </row>
		<row align="center">
			<label value="CP" control="cp2" />
			<box align="center">
				<textbox size="7" id="cp2" />
				<label value="Ville" control="ville2" />
				<textbox id="ville2" />
			</box>
			<toolbarbutton image="img/house.png" tooltiptext="Ouvre la gestion des codes postaux" oncommand="openCpBe(2)" />
		</row>
		<row align="center">
			<label value="État" control="etat2" />
			<textbox id="etat2" />
		</row>
	</rows>
</grid>
</hbox>
</vbox>

</overlay>