{include file="$admingentemplates/admin_top.tpl"}
<script language="JavaScript" type="text/javascript" src="{$site_root}{$index_theme_path}/js/jquery.form.js"></script>

<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_settings.php">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.currency.list_settings}</div>
<div class="cr">&nbsp;</div>
<div class="cr">&nbsp;</div>
<div class="help_text" style="display:block;">
    <div class="close_help">
        <img src="{$site_root}{$template_root}/images/close_help.png" alt="">
    </div>
    <div class="help_body">
        <span class="help_title">{$lang.help}:</span>{$lang.admin_help.currency_settings}
    </div>
</div>
<div class="cr">&nbsp;</div>
<ul class="tabs">
    <li>
        <a href="admin_pays.php?sel=settings">{$lang.index.payments.paysys}</a>
    </li>
    <li>
        <a class="current">{$lang.settings.site_currency}</a>
    </li>
</ul>
<div class="panel">
    <div class="user_operation_line" style="height:4px;font-size:0px;">
    </div>
    <div class="cr"></div>
    <div class="fl" style="width:100%;">
        <form name="money_form" action="{$form.action}" method="post" {if $settype == "general"}onsubmit="javascript: return checkMoneyForm();"{/if}>
        {$form.hiddens}
        <input type="hidden" name="sel" value="saveset">
        <input type="hidden" name="settype" value="{$settype}">
        <input type="hidden" name="id" value="">
        <input type="hidden" name="count" value="{$count}">    
        <input id="err_count" type="hidden" name="err_count">
<div id="tooltip" onclick="hideToolTip()" style="text-align:center; background-color: #FFFFFF; border: 1px dotted; text-align: {$default_left}; position:absolute; display:none; padding:5px;"></div>
{literal}
<script type="text/javascript">
$(function() {
$('#tool_tip_4 *').tooltip();
});
</script>
{/literal}
            <table border="0" cellspacing="1" cellpadding="5" width="100%">
                <tr bgcolor="#ffffff">
                    <td align="left" width="16%" class="main_header_text">{$lang.currency.default_currency}:&nbsp;</td>
                    <td class="main_content_text" align="left">
                        <select name="currency" style="width:195px;" onchange="javascript: getCurseForm(this.value);">
                        {section name=s loop=$currency}
                            <option value="{$currency[s].value}"{if $currency[s].value == $data.site_unit_costunit}selected{/if}>{$currency[s].value}</option>
                        {/section}
                        </select>
                    </td>
                </tr>
                <tr id="exch_tr" style="display:none;">
                    <td>
                        <div align="left"> 
                            {$lang.pays.exchange_rate}
                        </div>
                    </td>
                    <td colspan="2" align="left">
                        <div>
                            <div><span style="float:left;width:75px;">1 {$data.site_unit_costunit} = </span><input id="dct" type="text" name="curr_rate" style="display:inline; width:100px; " onKeyup="javascript: changeByCurr(1,this.value);" />&nbsp;&nbsp;<span id="new_curr"></span></div>
                            <div style="padding-top:2px;"><span style="float:left;width:75px;">{$lang.pays.or} 1 <span id="new_curr2"></span> = </span><input id="inv" type="text" name="curr_rate2" style="display:inline; width:100px;" onKeyup="javascript: changeByCurr(2,this.value);" />&nbsp;&nbsp;{$data.site_unit_costunit}</div>
                        </div>
                    </td>
                </tr>
                <tr id="exch_save" style="display:none;">
                    <td>&nbsp;</td>
                    <td align="center">
                        <div id="money_form_butt_save" style="display:none;">
                            <a href="#" class="admin_button_major" onclick="javascript:document.money_form.submit();">{$lang.button.save}<span>&nbsp;</span></a>
                            {*<input id="money_form_butt_save" type="submit" value="{$lang.button.save}" class="button" style="display:none;">*}
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="padding-left:0px;padding-right:0px;">
                        <input type="hidden" name="language_id" value="{$current_lang_id}"/>
                        <table width="100%" cellpadding="3" cellspacing="0" border="0"  style="margin: 0px; margin-top:10px; margin-bottom:10px;">
                            <tr class="table_header">
                                <td align="left" width="20%">{$lang.currency.currency_abbr}</td>
                                <td align="left">{$lang.currency.currency_name}</td>
                                <td align="left" width="5%">{$lang.currency.currency_symbol}</td>
                                <td align="right" width="20%">{$lang.button.action}</td>
                            </tr>
                            <tr class="odd">
                                <td align="left">
                                    <input type="text" name="currency_abbr">
                                </td>
                                <td align="left">
                                    <input type="text" name="currency_name">
                                </td>
                                <td align="left">
                                    <input type="text" name="currency_symbol">
                                </td>
                                <td align="right">
                                    <a href="#" class="admin_button_major" onclick="javascript:document.forms.money_form.sel.value='add_currency'; document.forms.money_form.submit();">{$lang.button.add}<span>&nbsp;</span></a>
                                    {*<input type="button" value="{$lang.button.add}" onclick="javascript:document.forms.money_form.sel.value='add_currency'; document.forms.money_form.submit();">*}
                                </td>
                            </tr>
							<tr class="table_header">
								<td colspan="4">&nbsp;</td>
							</tr>								
                        </table>
                        <table width="100%" cellpadding="3" cellspacing="0" border="0" style="margin: 0px; margin-top:10px; margin-bottom:15px;">
                        <input type="hidden" name="language_id" value="{$current_lang_id}"/>
                            <tr class="table_header">
                                <td align="left" width="25%" class="main_header_text">{$lang.currency.currency_abbr}</td>
                                <td align="left" class="main_header_text" width="25%">{$lang.currency.currency_name}</td>
                                <td align="left" width="25%" class="main_header_text">{$lang.currency.currency_symbol}</td>
                                <td align="center" width="10%" class="main_header_text">{$lang.currency.currency_symbol_view}</td>
                                <td align="right" width="10%" class="main_header_text">{$lang.button.action}</td>
                            </tr>
                            {section name=e loop=$currency}
                            {*<tr class="table_row {if $smarty.section.e.index mod 2 eq 1}even{else}odd{/if}">*}
                            <input type="hidden" name="id_m[{$currency[e].num}]" value="{$currency[e].id}"/>
                            <input type="hidden"  id="errors_m[{$currency[e].num}]" name="errors_m[{$currency[e].num}]" value=""/>
							<tr {if $smarty.section.e.index mod 2 eq 1}class="even"{else}class="odd"{/if}>                                
                                <td align="left">
                                    <input type="text" id="abbr_m[{$currency[e].num}]" name="abbr_m[{$currency[e].num}]" value="{$currency[e].value}" onblur="check_empty({$currency[e].num})">
                                </td>
                                <td align="left">
                                    <input type="text" id="name_m[{$currency[e].num}]" name="name_m[{$currency[e].num}]" value="{$currency[e].name}" onblur="check_empty({$currency[e].num})">
                                </td>
                                <td align="left">
                                    <input type="text" id="symbol_m[{$currency[e].num}]" name="symbol_m[{$currency[e].num}]" value="{$currency[e].symbol}" onblur="check_empty({$currency[e].num})">
                                </td>
                                <td align="center">{$currency[e].symbol_view}</td>
                                <td align="right">
                                    <div class="block_action">
                                        <div class="action_del" style="display:block;cursor:pointer;" {literal} onclick="javascript: if (confirm ('{/literal}{$lang.currency.confirm_delete|escape:javascript}{literal}')) {document.forms.money_form.sel.value='remove_currency'; document.forms.money_form.id.value={/literal}{$currency[e].id}{literal}; document.forms.money_form.submit()}" {/literal}>
                                            <img height="16" alt="" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" src="{$site_root}{$template_root}/images/photo_delete.png">
                                        </div>
                                    </div>
                                    {*<input type="button" value="{$lang.button.delete}" {literal} onclick="javascript: if (confirm ('{/literal}{$lang.currency.confirm_delete|escape:javascript}{literal}')) {document.forms.money_form.sel.value='remove_currency'; document.forms.money_form.id.value={/literal}{$currency[e].id}{literal}; document.forms.money_form.submit()}" {/literal}>*}
                                </td>
                            </tr>
                            {/section}
							<tr class="table_header">
								<td colspan="5">&nbsp;</td>
							</tr>								
                        </table>
                        <a href="#" class="admin_button_major" onclick="javascript:  sum_errors({$count});document.forms.money_form.sel.value='save_currency'; document.money_form.submit();">{$lang.button.save}<span>&nbsp;</span></a>
                        {*<input type="button" class="button_1" value="{$lang.button.save}" onclick="javascript:  sum_errors({$count});document.forms.money_form.sel.value='save_currency'; document.money_form.submit();">*}
                    </td>
                </tr>
            </table>
<script type="text/javascript">
{literal}
		function showToolTip(e,text){
			if(document.all)e = event;
			var obj = document.getElementById('tooltip');
			obj.innerHTML = text;
			obj.style.display = 'block';
			var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
			if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0;
			var leftPos = e.clientX - $('#tooltip').width()-10;
			if(leftPos<0)leftPos = 0;
			obj.style.left = leftPos + 'px';
			obj.style.top = e.clientY - obj.offsetHeight -10 + st + 'px';
		}
		function hideToolTip(){
			document.getElementById('tooltip').style.display = 'none';
		}
{/literal}		
</script>
        </form>
    </div>
</div>
<script type="text/javascript">
{literal}

$(document).ready(function() {
    $("tr.table_row").hover(
        function(){
            $(this).addClass('select_tr');
                $('.block_action', this).css('display', 'block');
            },
            function () {
                $(this).removeClass('select_tr');
                $('.block_action', this).css('display', 'none');
            }
    );
});

///globals
dct_obj = document.getElementById("dct");
inv_obj = document.getElementById("inv");

function getCurseForm(curr){
	new_curr_obj = document.getElementById("new_curr");
	new_curr2_obj = document.getElementById("new_curr2");
//	exch_table_obj = document.getElementById("exch_table");
//  exch_table_obj_1 = document.getElementById("exch_table_1");    
    var exch_tr = document.getElementById("exch_tr");    
    var exch_save = document.getElementById("exch_save");    
	money_form_butt_save_obj = document.getElementById("money_form_butt_save");
//	if (exch_table_obj.style.display=='none') exch_table_obj.style.display = 'block';
	if (exch_tr.style.display=='none') exch_tr.style.display = '';
	if (exch_save.style.display=='none') exch_save.style.display = '';
//    if (exch_table_obj_1.style.display=='none') exch_table_obj_1.style.display = 'block';    
	if (money_form_butt_save_obj.style.display=='none') money_form_butt_save_obj.style.display = 'block';
	new_curr_obj.innerHTML = curr;
	new_curr2_obj.innerHTML = curr;
}
function changeByCurr(direction,value){
	switch (direction){
		case 1:
		dct_obj.value = extParseFloat(dct_obj.value);
		inv_obj.value = 1/extParseFloat(dct_obj.value);
		break;
		case 2:
		inv_obj.value = extParseFloat(inv_obj.value);
		dct_obj.value = 1/extParseFloat(inv_obj.value);
		break;
	}
}

function extParseFloat(value){
	while(isNaN(value)){
		value = value.substr(0,value.length-1);
	}
	if (value == "") value = 1;
	return value;
}

function checkMoneyForm(){

	substr_slash_n = "[slash_n]";
	substr_first_curr = "[first_curr]";
	substr_value = "[value]";
	substr_second_curr = "[second_curr]";
	notify = "{/literal}{$lang.pays.notify_money_form|escape:javascript}{literal}";
	currency_obj = document.money_form.currency;
	value = document.getElementById("dct").value;
	value = Math.round(value*1000)/1000// rounding to 0.xx
	document.getElementById("dct").value = value;

	if (isNaN(value) || value==0){
		dct_obj.value = 1;
		inv_obj.value = 1;
		{/literal}
		alert("{$lang.pays.wrong_format|escape:javascript}");
		document.money_form.curr_rate.focus();
		{literal}
		return false;
	}

	notify = notify.replace(substr_slash_n,"\n");
	notify = notify.replace(substr_first_curr,"{/literal}{$data.site_unit_costunit|escape:javascript}{literal}");
	notify = notify.replace(substr_value,value);
	notify = notify.replace(substr_second_curr,currency_obj.options[currency_obj.selectedIndex].text);
	if (confirm(notify)) return true;
	else return false;

}

function check_empty(num){
    if ((document.getElementById('abbr_m['+num+']').value == '')||(document.getElementById('name_m['+num+']').value == '')||(document.getElementById('symbol_m['+num+']').value == ''))
        document.getElementById('errors_m['+num+']').value = 1; else document.getElementById('errors_m['+num+']').value = 0;
    return;
}

function sum_errors(num){
    summ = 0;
    for (i=0; i<num; i++)
        if (document.getElementById('errors_m['+i+']').value !=0) summ++;    
    document.getElementById('err_count').value=summ;
    return;
}

{/literal}
</script>
{include file="$admingentemplates/admin_bottom.tpl"}