{include file="$gentemplates/$header_tpl"}

<script language="JavaScript" type="text/javascript" src="{$site_root}{$template_root}/js/location.js"></script>
<script language="JavaScript" type="text/javascript" src="{$site_root}{$template_root}/js/jquery.form.js"></script>

<div style="width:100%;">

	{if $data.err}
	<dl valign="middle">
		<dd>
			<font class="error_msg" id="error_msg_top">{$data.err}</font><br><br>
		</dd>
	</dl>
	{/if}

	<dl valign="middle">
		<dd class=text>
			<h2>{$lang.giftshop.delivery_info}</h2>
			<form name="delivery_form" action="{$file_name}" method="POST" class="gift_delivery_form">
				<input type="hidden" name="sel" value="delivery">
				<input type="hidden" name="act" value="save">
				<input type="hidden" name="h" value="{$hash_for_link}">
				<input type="hidden" name="id_user_to" value="{$id_user_to}">
				<div class="div_name_for_lang">
					<div style="width:100%;">
						<dl>
							<dt id="preview_1" class="name_for_lang preview_width" valign="top">{$lang.giftshop.name} :<font class="error_msg">*</font></dt>
							<dd id="preview_2" class="element">
								<input name="name" value="{$data.name}" style="width:150px" maxlength="200">
							</dd>
						</dl>
					</div>
				</div>	
				<div class="div_name_for_lang">
					<div style="width:100%;">
						<dl>
							<dt id="preview_1" class="name_for_lang preview_width" valign="top">{$lang.giftshop.adress} :<font class="error_msg">*</font></dt>
							<dd id="preview_2" class="element">
								<input name="adress" value="{$data.adress}" style="width:150px" maxlength="200">
							</dd>
						</dl>
					</div>
				</div>	
				<div class="div_name_for_lang">				
					<div style="width:100%;">
						<dl>
							<dt id="preview_1" class="name_for_lang preview_width" valign="top">{$lang.giftshop.country} :<font class="error_msg">*</font></dt>
							<dd id="preview_2" class="element">
								<select name="id_country" style="width:150px" id="country" onchange="ChangeLocation(this);" class="select_registration">
									<option value="0">{$lang.home_page.select_default}</option>
									{foreach from=$countries item=country}
									<option value="{$country.id}" {if $country.sel}selected{/if}>{$country.name}</option>
									{/foreach}
								</select>
							</dd>
						</dl>
					</div>
				</div>					
				<div class="div_name_for_lang">		
					<div style="width:100%;">
						<dl>
							<dt id="preview_1" class="name_for_lang preview_width" valign="top">{$lang.giftshop.region} :<font class="error_msg">*</font></dt>
							<dd id="preview_2" class="element">
							{*if $regions*}
								<span id="region_div">
									<select style="width:150px" name="id_region" id="region" onchange="ChangeLocation(this);">
										{foreach from=$regions item=region}
										<option value="{$region.id}" {if $region.sel}selected{/if}>{$region.name}</option>
										{/foreach}
									</select>								
								</span>
							{*else}	
								<div id="region_div">&nbsp;</div>
							{/if*}	
							</dd>
						</dl>
					</div>
				</div>					
				<div class="div_name_for_lang">					
					<div style="width:100%;">
						<dl>
							<dt id="preview_1" class="name_for_lang preview_width" valign="top">{$lang.giftshop.city} :<font class="error_msg">*</font></dt>
							<dd id="preview_2" class="element">
							{*if $cities*}
								<span id="city_div">
									<select style="width:150px" name="id_city" id="city" onchange="ChangeLocation(this);">
										{foreach from=$cities item=city}
										<option value="{$city.id}" {if $city.sel}selected{/if}>{$city.name}</option>
										{/foreach}
									</select>								
								</span>
							{*else}	
								<div id="city_div">&nbsp;</div>
							{/if*}							
							</dd>
						</dl>
					</div>
				</div>					
				<div class="div_name_for_lang">					
					<div style="width:100%;">
						<dl>
							<dt id="preview_1" class="name_for_lang preview_width" valign="top">{$lang.giftshop.zip} :<font class="error_msg">*</font></dt>
							<dd id="preview_2" class="element">
								<input name="zip" value="{$data.zip}" style="width:150px" maxlength="20">
							</dd>
						</dl>
					</div>
				</div>					
				<div class="div_name_for_lang">					
					<div style="width:100%;">
						<dl>
							<dt id="preview_1" class="name_for_lang preview_width" valign="top">{$lang.giftshop.notes} :</dt>
							<dd id="preview_2" class="element">
								<input name="notes" value="{$data.notes}" style="width:150px" maxlength="255">
							</dd>
						</dl>					
					</div>
				</div>
				<div class="div_name_for_lang">					
					<input class="button" type="button" value="{$lang.button.submit}" onclick="saveForm();">
				</div>	
			</form>
		</dd>
	</dl>
</div>
 
{literal}
<script language="JavaScript" type="text/javascript">

function saveForm() {
	var mandatory_fields = [
		'input[name="name"]',
		'input[name="adress"]',
		'select[name="id_country"]',
		'select[name="id_region"]',
		'select[name="id_city"]',
		'input[name="zip"]'
		];
	var err = 0;
	for ( i = 0; i < mandatory_fields.length; i++ ) {
		var obj = $(mandatory_fields[i]);
		var val = obj.val();
		if (!val || val == 0) {
			err++;
			obj.addClass('error_input');
		} else {
			obj.removeClass('error_input');
		}
	}
	
	if (err) {
		$('#error_msg_top').html('{/literal}{$lang.err.invalid_feilds}{literal}');
		return false;
	}
	
	document.delivery_form.submit();
	
	$("div #delivery").hide();
}

/*var city = $("div #city_div select").val();
var val = $("#region").val();
if (city == undefined){
	$.post(SEO_SITE_ROOT+"/location.php",{sec:'rp',sel:'city', id_region:val},	
		function(data){
			$("div#city_div").html(data);
		}
	);
}*/

$('select').live("change",(function(){
	val = $(this).val();
	name = $(this).attr('name');
	if (name == "id_country") {
		$.post(SEO_SITE_ROOT+"/location.php",{sec:'rp',sel:'region', id_country:val},
			function(data){
				$("div #region_div").html(data);
				$("div #city_div select").val(0);
				$("div #city_div select").text('');
			}
		);
	} else if(name == "id_region") {
		$.post(SEO_SITE_ROOT+"/location.php",{sec:'rp',sel:'city', id_region:val},
			function(data){
				$("div#city_div").html(data);
			}
		);
	}
}));

</script>
{/literal}

{include file="$gentemplates/$footer_tpl"}