{if $ajax eq 0}
{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_modules.php">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$header.razdel_name}</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>{$header.help.settings}
    </div>
</div>
<div class="cr">&nbsp;</div>
<ul class="tabs">
    <li>
        <a class="current">{$lang.admin_menu.sms_settings}</a>
    </li>
    <li>
        <a href="admin_sms_notifications.php?sel=statistics">{$lang.admin_menu.sms_statistics}</a>
    </li>
</ul>
<div class="user_operation_line" style="height:4px;font-size:0px;"></div><br>

<form action="{$form.action}" method="POST" name="sms_settings_form">
{/if}
	<div id="users_table_div" style="width:100%;">
	<div class="user_status_line" style="margin-bottom:0px;">
		<div style="cursor:pointer;" class="user_status_elem{if $active eq 1}_active{/if}" onclick="ListSettings(1);">{$header.account_settings}</div>
		<div style="cursor:pointer;" class="user_status_elem{if $active eq 2}_active{/if}" onclick="ListSettings(2);">{$header.cost_of_services}</div>
		<div style="cursor:pointer;" class="user_status_elem{if $active eq 3}_active{/if}" onclick="ListSettings(3);">{$header.sms_texts}</div>
		<div style="cursor:pointer;" class="user_status_elem{if $active eq 4}_active{/if}" onclick="ListSettings(4);">{$header.addition_settings}</div>
	</div>
	
	<div class="panel_subtabs">
		<div class="panel_content" style="width:98%;">
		<table border=0 cellspacing=0 cellpadding=0 width="100%">
			{if $active eq 1}
				<input type="hidden" name="sel" value="save_settings">
				<input type="hidden" name="sub_tab" value="account">
				{$form.hiddens}
				<tr height="30px">
					<td width="15%">{$header.clck_username}:</td>
					<td><input type="text" id="clck_username" value="{$sms_settings.clck_username}" name="clck_username"></td>
				</tr>
				<tr height="30px">
					<td>{$header.clck_api_id}:</td>
					<td><input type="text" id="clck_api_id" value="{$sms_settings.clck_api_id}" name="clck_api_id"></td>
				</tr>
				<tr height="30px">
					<td>{$header.clck_password}:</td>
					<td><input type="password" id="clck_password" value="{$sms_settings.clck_password}" name="clck_password"></td>
				</tr>
				<tr height="30px">
					<td>{$header.clck_only_usa}:</td>
					<td><input type="checkbox" id="clck_only_usa" value="1" name="clck_only_usa" {if $sms_settings.clck_only_usa eq 1}checked{/if}></td>
				</tr>
				<tr height="30px">
					<td>{$header.clck_number}:</td>
					<td><input type="text" id="clck_number" value="{$sms_settings.clck_number}" name="clck_number" {if $sms_settings.clck_only_usa eq 0}disabled{/if}></td>
				</tr>
				<tr height="30px">
					<td>&nbsp;</td>
					<td>
					<a class="admin_button" id="check_account_settings" name="check_account_settings" onclick="CheckClickatell(document.getElementById('clck_api_id').value, document.getElementById('clck_username').value, document.getElementById('clck_password').value, document.getElementById('check_status'), 'check_data');">{$header.check_account_settings}<span>&nbsp;</span></a><span style="padding-left:10px;" id="check_status"></span></td>
				</tr>
				<tr height="30px">
					<td>&nbsp;</td>
					<td><a class="admin_button" id="check_balance" name="check_balance" onclick="CheckClickatell(document.getElementById('clck_api_id').value, document.getElementById('clck_username').value, document.getElementById('clck_password').value, document.getElementById('balance_field'), 'check_balance');">{$header.check_balance}<span>&nbsp;</span></a><span style="padding-left:10px;" id="balance_field"></span></td>
				</tr>
				<script type="text/javascript">
				{literal}
					$(document).ready(function() {
						$('#clck_only_usa').click(function(){
													if($('#clck_only_usa').is(':checked')) {
														$('#clck_number').attr('disabled','');
													} else {
														$('#clck_number').attr('disabled','disabled');
													}
												});
					});
					function CheckAccountForm(){
					var check_fields = new Array("clck_username", "clck_api_id","clck_password");
					for (i=0; i < check_fields.length; i++) {
						if (document.getElementById(check_fields[i]).value == ""){
							alert('{/literal}{$header.empty_account_settings}{literal}');
							return false;
							}
						}
					return true;
					}
				{/literal}
				</script>
			{/if}
			{if $active eq 2}
				<input type="hidden" name="sel" value="save_settings">
				<input type="hidden" name="sub_tab" value="cost">
				{$form.hiddens}
				<div style="margin:10px 0;" id='sms_price' name='sms_price'></div>
				<tr>
					<td style="padding-bottom:3px;"><a class="admin_button" onclick="document.getElementById('adding_packet').style.display='inline';">{$header.new_sms_packet}<span>&nbsp;</span></a></td>
				</tr>
				<tr>
					<td>
					<div id="adding_packet" style="display:none;">
						<input type='text' id='price_sms_packet' name='price_sms_packet' style='width:40px;' value="">&nbsp;SMS
						&nbsp;-&nbsp;
						<input type='text' id='price_cost' name='price_cost' style='width:40px;' value="">&nbsp;{$cur}
						&nbsp;
						<a class="admin_button" onclick="if (CheckAddForm(document.getElementById('error_span'))) EditorSmsPrices('add', document.getElementById('sms_price'), document.getElementById('price_sms_packet').value, document.getElementById('price_cost').value, '');">{$button.add}<span>&nbsp;</span></a>&nbsp;
						<span id="error_span"></span>                            
					</div>
					</td>
				</tr>
				<script type="text/javascript">
				{literal}
				function CheckAddForm(error_obj){
    				var check_fields = new Array("price_sms_packet", "price_cost");
    				for (i=0; i < check_fields.length; i++) {        
        				if (document.getElementById(check_fields[i]).value == "" || document.getElementById(check_fields[i]).value.search(/^[0-9\.,]{0,5}$/) == -1){
            				error_obj.innerHTML = '<font color="red">{/literal}{$header.add_sms_empty_fields}{literal}</font>';
            				return false;
        				}
    				}
    				error_obj.innerHTML = '';
    				return true;
				}
				{/literal}
				</script>
				
			{/if}
			{if $active eq 3}
				<input type="hidden" name="sel" value="save_settings">
				<input type="hidden" name="sub_tab" value="text">
				{$form.hiddens}
				<tr>
					<td><small>{$header.help_sms_length}</small></td>
				</tr>
				<tr>
					<td style="padding:0px;">
						<table cellpadding="0" cellspacing="0" width="100%" style="margin-bottom:8px;">
							<tr>
								<td width="15%">{$header.use_unicode}
								</td>
								<td width="16%"><input type="checkbox" name="unicode" value={$sms_settings.unicode} {if $sms_settings.unicode}checked{/if} onclick="ShowField(this, '');CnahgeMaxLen(this);">
								</td>
								<td>
								<a class="admin_button" id="user_tag" onclick="InsertTag('{$header.user_tag}');">{$header.user_tag}<span>&nbsp;</span></a>
								<a class="admin_button" id="site_name_tag" onclick="InsertTag('{$header.site_name_tag}');">{$header.site_name_tag}<span></span>&nbsp;</span></a>
								</td>
							</tr>
						</table>    
					</td>
				</tr>    
				<tr>
					<td>
						<table cellpadding="0" cellspacing="0" width="100%" style="margin:0px;">
						{foreach from=$sms_cases item=item key=key}
						{assign var=lang_str value=about_$item}
						<tr>
							<td width="30%">    
								{$header[$lang_str]}:                
							</td>
							<td align="center">
								<textarea id="sms_text_{$key}" name="sms_text[{$key}]" rows="2" cols="100" style="width:100%;" onkeyup="GetSmsLength('{$key}');" onblur="sms_text_id = '{$key}';">{$sms_texts[$key]}</textarea>
							</td>
							<td align="center" width="6%">
								<span id=length_st_{$key}></span>/<b><span id='max_length_{$key}'>{if $sms_settings.unicode}70{else}160{/if}</span></b>
							</td>
						</tr>    
						{/foreach}
						</table>
					</td>
				</tr>    
			{/if}			
			{if $active eq 4}
				<input type="hidden" name="sel" value="save_settings">
				<input type="hidden" name="sub_tab" value="additional">
				{$form.hiddens}
				<tr>
					<td width="20%;">{$header.use_source_address}
                    </td>
                    <td><input type="checkbox" name="use_source_address" value={$sms_settings.use_source_address} {if $sms_settings.use_source_address}checked{/if} onclick="ShowField(this, document.getElementById('source_address'));">
                    </td>
                    
                </tr>
                <tr>                
                    <td colspan="2" style="padding-left:4px;">
                        <div id="source_address" style="display:{if $sms_settings.use_source_address}inline{else}none{/if};">                   
						<table cellpadding="3" cellspacing="1" width="100%" style="margin-bottom:5px;">
                        <tr>
                            <td width="20%">{$header.source_address}:</td>
                            <td>
                                <input type="text" id="source_address" value="{$sms_settings.source_address}" name="source_address">
                            </td>
                        </tr>
                        </table>
                        </div>
                    </td>
                </tr>
                <tr>
					<td colspan="2" style="padding-left:8px;"><small>{$header.help_source_address}</small></td>
                </tr> 
				<tr><td>&nbsp;</td></tr>
				<tr>
                    <td>{$header.use_delivery_time}</td>
                    <td><input type="checkbox" name="use_delivery_time" value="{$sms_settings.use_delivery_time}" {if $sms_settings.use_delivery_time}checked{/if} onclick="ShowField(this, document.getElementById('delivery_time'));">
                    </td>
                </tr>
                <tr>                
                    <td colspan="2" style="padding-left:4px;">
                        <div id="delivery_time" style="display:{if $sms_settings.use_delivery_time}inline{else}none{/if};">
						<table cellpadding="3" cellspacing="1" class="table_main" width="100%" style="margin-bottom:5px;">
                        <tr>
                            <td width="20%">{$header.delivery_time}:</td>
                            <td>
                                <input type="text" id="delivery_time" value="{$sms_settings.delivery_time}" name="delivery_time" style="width:50px;">&nbsp;{$header.min}
                            </td>
                        </tr>
                        </table>
                        </div>
                    </td>
                </tr>				
                <tr>
					<td colspan="2" style="padding-left:8px;"><small>{$header.help_delivery_time}</small></td>
                </tr>	
				<tr><td>&nbsp;</td></tr>
				<tr>
                    <td>{$header.use_flash_sms}</td>
                    <td width="5px;"><input type="checkbox" name="use_flash_sms" value="{$sms_settings.use_flash_sms}" {if $sms_settings.use_flash_sms}checked{/if} onclick="ShowField(this, '');">
                    </td>
                </tr>
                <tr>
					<td colspan="2" style="padding-left:8px;"><small>{$header.help_flash_sms}</small></td>
                </tr> 
			{/if}
		</table>    
		</div>		 
	</div> 
	</div>
	<div class="cr"></div>
	{if $ajax eq 0}
	<table cellpadding="0" cellspacing="0" width="100%">             
	<tr>
		<td>
			<a class="admin_button_major" onclick="document.sms_settings_form.submit();">{$button.save}<span>&nbsp;</span></a>
		</td>
	</tr>
	</table>
	{/if}
</form>
{literal}
<script>
var req = null;

function ListSettings(par){
	ajaxLoadingImage(1, 'users_table_div');
	$.post("admin_sms_notifications.php?sel=settings", {par:par,ajax:'1'}, function(data){
		ajaxLoadingImage(0, 'users_table_div');
		$('#users_table_div').html(data);
		if (par == 2) $('.admin_button_major').hide();
		else $('.admin_button_major').show();
	});
}

function InitXMLHttpRequest() {
    // Make a new XMLHttp object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
}

function CheckClickatell(api_id, username, password, destination, code){
    InitXMLHttpRequest();
    // Load the result from the response page
    if (req) {
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                destination.innerHTML = req.responseText;
            } else {
                destination.innerHTML = "Check data...";
            }
        }
        req.open("GET", "admin_sms_notifications.php?sel=" + code + "&api_id=" + api_id + "&user=" + username + "&password=" + password, true);
        req.send(null);
    } else {
        destination.innerHTML = 'Browser unable to create XMLHttp Object';
    }
}

function ShowField(checkbox, field){    
    if (checkbox.checked == false){
        if (field != ''){
            field.style.display = 'none';
        }
        checkbox.value = 0;
    }else{
        if (field != ''){
            field.style.display = 'inline';
        }
        checkbox.value = 1;
    }
    
    return;
}

function CnahgeMaxLen(checkbox){
    if (checkbox.checked == false){
        {/literal}
        {foreach from=$sms_cases item=item key=key}
        {literal}
        document.getElementById('{/literal}max_length_{$key}{literal}').innerHTML = 160;
        {/literal}
        {/foreach}
        {literal}        
    }else{
        {/literal}
        {foreach from=$sms_cases item=item key=key}
        {literal}
        document.getElementById('{/literal}max_length_{$key}{literal}').innerHTML = 70;
        GetSmsLength('{/literal}{$key}{literal}');
        {/literal}
        {/foreach}
        {literal}
        
    }        
}

function EditorSmsPrices(method, div_obj, par1, par2, par3){
    InitXMLHttpRequest();
    // Load the result from the response page
    if (req) {
        req.onreadystatechange = function() {
            if (req.readyState == 4) {                                
                div_obj.innerHTML = req.responseText;    
                if (method == 'add'){
                    document.getElementById('adding_packet').style.display = 'none';        
                }                
            } else {
                div_obj.innerHTML = "Receive data...";
            }
        }
        switch (method){
            case "get":        $get_url = "admin_sms_notifications.php?sel=sms_prices";break;
            case "add":        $get_url = "admin_sms_notifications.php?sel=add_sms_price&sms_packet=" + par1 + "&cost=" + par2;break;
            case "delete":    $get_url = "admin_sms_notifications.php?sel=delete_sms_price&price_id=" + par1;break;
            case "edit":    $get_url = "admin_sms_notifications.php?sel=edit_sms_price&price_id=" + par1 + "&sms_packet=" + par2 + "&cost=" + par3;break;
        }
        req.open("GET", $get_url, true);
        req.send(null);
    } else {
        destination.innerHTML = 'Browser unable to create XMLHttp Object';
    }
}
function EditSmsPrice(edit_link_id, save_link_id, sms_packet_id, cost_id){
    document.getElementById(sms_packet_id).readOnly = false;
    document.getElementById(sms_packet_id).style.fontWeight = 'bold';
    document.getElementById(sms_packet_id).focus();
    document.getElementById(cost_id).readOnly = false;
    document.getElementById(cost_id).style.fontWeight = 'bold';
    document.getElementById(edit_link_id).style.display = 'none';    
    document.getElementById(save_link_id).style.display = 'inline';    
}

function GetSmsLength(id){
    document.getElementById('length_st_'+id).innerHTML = document.getElementById('sms_text_'+id).value.length;
    if (document.getElementById('sms_text_'+id).value.length > document.getElementById('max_length_'+id).innerHTML){
                
        document.getElementById('sms_text_'+id).value = document.getElementById('sms_text_'+id).value.substring(0, document.getElementById('max_length_'+id).innerHTML);
        document.getElementById('length_st_'+id).innerHTML = document.getElementById('max_length_'+id).innerHTML;
    }else{        
    }
}

var sms_text_id=1;
function InsertTag(tag){
    if ((document.getElementById('sms_text_'+sms_text_id).value.length + tag.length-1) < document.getElementById('max_length_'+sms_text_id).innerHTML){
        document.getElementById('sms_text_'+sms_text_id).value = document.getElementById('sms_text_'+sms_text_id).value + tag;    
        GetSmsLength(sms_text_id);
    }
    document.getElementById('sms_text_'+sms_text_id).focus();
}
var active = '{/literal}{$active}{literal}	';


if (active == 2){
	EditorSmsPrices('get', document.getElementById('sms_price'), '', '', '');
}	
	if (active == 3){
{/literal}	
	
    {foreach from=$sms_cases item=item key=key}
{literal}
   GetSmsLength('{/literal}{$key}{literal}');
{/literal}
    {/foreach}
	
{literal}   }     
</script>
{/literal}
{if $ajax eq 0}
{include file="$admingentemplates/admin_bottom.tpl"}
{/if}