<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons">
		<a onclick="$('#stayid').attr('value', '0'); $('#form').submit();" class="button"><span><?php echo $button_save_go; ?></span></a>
		<a onclick="$('#stayid').attr('value', '1'); $('#form').submit();" class="button"><span><?php echo $button_save_stay; ?></span></a>
		<a onclick="location = '<?php echo $cancel; ?>';" class="button"><span><?php echo $button_cancel; ?></span></a>
	  </div>
    </div>
    <div class="content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
	  <input type="hidden" name="stay" id="stayid" value="1">
	  <div class="htabs">
		    <a href="#tab-general"><?php echo $tab_general; ?></a>
		    <a href="#tab-vkontakte"><?php echo $tab_vkontakte; ?></a>
		    <a href="#tab-facebook"><?php echo $tab_facebook; ?></a>
		    <a href="#tab-twitter"><?php echo $tab_twitter; ?></a>
		    <a href="#tab-odnoklassniki"><?php echo $tab_odnoklassniki; ?></a>
		    <a href="#tab-help"><?php echo $tab_help; ?></a>
      </div>
		  
	  <div id="tab-general">
        <table class="form">
          <tbody>
            <tr>
				<td><?php echo $entry_status; ?></td>
				<td>
					<select name="socnetauth_status">
					<?php if ($socnetauth_status) { ?>
						<option value="1" selected="selected"
						><?php echo $text_enabled; ?></option>
						<option value="0"><?php echo $text_disabled; ?></option>
					<?php } else { ?>
						<option value="1"><?php echo $text_enabled; ?></option>
						<option value="0" selected="selected"
						><?php echo $text_disabled; ?></option>
					<?php } ?>
					</select>
				</td>
			</tr>
		</table>
		
		<h3><? echo $entry_popup; ?></h3>
		        <table id="module" class="list">
          <thead>
            <tr>
              <td class="left"><?php echo $entry_layout; ?></td>
              <td class="left"><?php echo $entry_status; ?></td>
              <td></td>
            </tr>
          </thead>
          <?php $module_row = 0; ?>
          <?php foreach ($socnetauth_module as $module) { ?>
          <tbody id="module-row<?php echo $module_row; ?>">
            <tr>
               <td class="left"><select name="socnetauth_module[<?php echo $module_row; ?>][layout_id]">
                  <?php foreach ($layouts as $layout) { ?>
                  <?php if ($layout['layout_id'] == $module['layout_id']) { ?>
                  <option value="<?php echo $layout['layout_id']; ?>" selected="selected"><?php echo $layout['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select></td>
             <td class="left"><select name="socnetauth_module[<?php echo $module_row; ?>][status]">
                  <?php if ($module['status']) { ?>
                  <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                  <option value="0"><?php echo $text_disabled; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_enabled; ?></option>
                  <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                  <?php } ?>
                </select>
				<input type="hidden" name="socnetauth_module[<?php echo $module_row; ?>][position]" value="content_bottom">
				
				<input type="hidden" name="socnetauth_module[<?php echo $module_row; ?>][sort_order]" value="0">
				
				</td> 
              <td class="left"><a onclick="$('#module-row<?php echo $module_row; ?>').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>
            </tr>
          </tbody>
          <?php $module_row++; ?>
          <?php } ?>
          <tfoot>
            <tr>
              <td colspan="2"></td>
              <td class="left"><a onclick="addModule();" class="button"
		><span><?php echo $button_add_module; ?></span></a></td>
            </tr>
          </tfoot>
        </table>
		<p><i><?php echo $text_popup_notice; ?></i></p>
		
		
		<h3><? echo $entry_generator_header; ?></h3>
		<p><i><? echo $entry_generator_notice; ?></i></p>
		<style>
		.otstup td
		{
			padding: 5px;
		}
		</style>
		
	<table>
	<tr>
	<td width=50%>
		<table class="list otstup">
          <tfoot>
			<tr>
				<td width=200><? echo $entry_generator_socnet; ?></td>
				<td>
					<table>
					<tr>
						<td><input type="checkbox" id="generator_vkontakte" value="1" checked>
						<label for="generator_vkontakte"><?php echo $tab_vkontakte; ?></label></td>
					</tr>
					<tr>
						<td><input type="checkbox" id="generator_facebook" value="1" checked>
						<label for="generator_facebook"><?php echo $tab_facebook; ?></label></td>
					</tr>
					<tr>
						<td><input type="checkbox" id="generator_twitter" value="1" checked>
						<label for="generator_twitter"><?php echo $tab_twitter; ?></label>
						</td>
					</tr>
					<tr>
						<td><input type="checkbox" id="generator_odnoklassniki" value="1" checked><label for="generator_odnoklassniki"><?php echo $tab_odnoklassniki; ?></label>
						</td>
					</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td><? echo $entry_generator_size; ?></td>
				<td><input type="text" id="generator_size" value="45" size=1> px
				</td>
			</tr>
			<tr>
				<td><? echo $entry_generator_otstup; ?></td>
				<td><input type="text" id="generator_otstup" value="5" size=1> px</td>
			</tr>
			<tr>
				<td><? echo $entry_generator_type; ?></td>
				<td><select id="generator_type">
						<option value="kvadrat"><? echo $entry_generator_kvadrat; ?></option>
						<option value="hline"><? echo $entry_generator_hline; ?></option>
						<option value="vline"><? echo $entry_generator_vline; ?></option>
					</select>
				</td>
			</tr>
			<tr>
				<td><? echo $entry_generator_hover; ?></td>
				<td><input type="checkbox" id="generator_hover" value="1" checked></td>
			</tr>
			<tr>
				<td></td>
				<td><a class="button" onclick="genarate_links();"><? echo $button_generate; ?></a></td>
			</tr>
			</tfoot>
		</table>
	</td>
	<td valign=top style="padding-left: 20px;">
	 <table border=0 width=100% cellspacing=0 cellpadding=0>
		<tr>
			<td height=130 valign=top>
			<b><? echo $entry_generator_view; ?></b><br>
			<div id="generator_view"></div>
			</td>
		</tr>
		<tr>
			<td height=130 valign=top>
			<b><? echo $entry_generator_code; ?></b><br>
			<textarea cols=70 rows=5 id="generate_code"></textarea>
			</td>
		</tr>
	 </table>
	 <script>
		function genarate_links()
		{
			if( !document.getElementById('generator_vkontakte').checked && 
				!document.getElementById('generator_facebook').checked && 
				!document.getElementById('generator_twitter').checked && 
				!document.getElementById('generator_odnoklassniki').checked 
			)
			{
				alert('<? echo $error_generate_nosocnet; ?>');
				return;
			}
			
			if( document.getElementById('generator_size').value=='' || 
				document.getElementById('generator_size').value==0 	)
			{
				alert('<? echo $error_generate_nosize; ?>');
				return;
			}
			
			var size = document.getElementById('generator_size').value;
			var otstup = document.getElementById('generator_otstup').value;
			
			var hover = '';
			
			if( document.getElementById('generator_hover').checked )
			{
				hover = 'onmouseover="this.style.opacity=\'1\'" onmouseout="this.style.opacity=\'0.8\'" style="opacity: 0.8;"';
			}
			
			
			
			
			var vk_link = '<td style="padding: '+otstup+'px; line-height: 0px; font-size: 0px; " height="'+size+'"><a class="socnetauth_buttons"  style="float: left; padding: 0px; margin: 0px;"  href="/socnetauth/vkontakte.php?first=1"><img width="'+size+'"  height="'+size+'" src="/socnetauth/icons/vk.png" '+hover+' border=0></a></td>';
			
			var od_link = '<td style="padding: '+otstup+'px; line-height: 0px; font-size: 0px; " height="'+size+'"><a class="socnetauth_buttons" style="float: left; padding: 0px; margin: 0px;"  href="/socnetauth/odnoklassniki.php?first=1"><img width="'+size+'"  height="'+size+'" src="/socnetauth/icons/od.png" '+hover+' border=0></a></td>';
			
			var fb_link = '<td style="padding: '+otstup+'px; line-height: 0px; font-size: 0px; " height="'+size+'"><a class="socnetauth_buttons"  style="padding: 0px; margin: 0px;"  href="/socnetauth/facebook.php?first=1"><img width="'+size+'"  height="'+size+'" src="/socnetauth/icons/fb.png" '+hover+' border=0></a></td>';
			
			var tw_link = '<td style="padding: '+otstup+'px; line-height: 0px; font-size: 0px; " height="'+size+'"><a class="socnetauth_buttons"  style="padding: 0px; margin: 0px;"  href="/socnetauth/twitter.php?first=1"><img width="'+size+'"  height="'+size+'" src="/socnetauth/icons/tw.png" '+hover+' border=0></a></td>';
			
			var blocks = new Array();
			
			
			var counter = -1;
			var no_vk = 0;
			var no_od = 0;
			var no_fb = 0;
			var no_tw = 0;
			
			if( document.getElementById('generator_vkontakte').checked ) 
			{
				counter += 1;
				blocks[ counter ] = vk_link;
				no_vk = 1;
			}
			else if( document.getElementById('generator_odnoklassniki').checked )
			{
				counter += 1;
				blocks[ counter ] = od_link;
				no_od = 1;
			}
			else if( document.getElementById('generator_facebook').checked )
			{
				counter += 1;
				blocks[ counter ] = fb_link;
				no_fb = 1;
			}
			else if( document.getElementById('generator_twitter').checked )
			{
				counter += 1;
				blocks[ counter ] = tw_link;
				no_tw = 1;
			}
			
			if( document.getElementById('generator_odnoklassniki').checked && no_od==0 )
			{
				counter += 1;
				blocks[ counter ] = od_link;
				no_od = 1;
			}
			else if( document.getElementById('generator_facebook').checked && no_fb==0 )
			{
				counter += 1;
				blocks[ counter ] = fb_link;
				no_fb = 1;
			}
			else if( document.getElementById('generator_twitter').checked && no_tw==0 )
			{
				counter += 1;
				blocks[ counter ] = tw_link;
				no_tw = 1;
			}

			if( document.getElementById('generator_facebook').checked && no_fb==0 )
			{
				counter += 1;
				blocks[ counter ] = fb_link;
				no_fb = 1;
			}
			else if( document.getElementById('generator_twitter').checked && no_tw==0 )
			{
				counter += 1;
				blocks[ counter ] = tw_link;
				no_tw = 1;
			}
			
			if( document.getElementById('generator_twitter').checked && no_tw==0 )
			{
				counter += 1;
				blocks[ counter ] = tw_link;
			}
			
			
			if( document.getElementById('generator_type').value == 'kvadrat' )
			{
				var code = '<!-- socnetauth block --><table cellpadding=0 cellspacing=0 border=0><tr>';
				
				for(var i=0; i<=counter; i++)
				{
					code += blocks[ i ];
					
					if(i==1 && counter>i) 
					code+= "</tr><tr>";
				}
				
				code += '</tr></table><!-- end socnetauth block -->';
			}
			else if( document.getElementById('generator_type').value == 'hline' )
			{
				var code = '<!-- socnetauth block --><table cellpadding=0 cellspacing=0 border=0><tr>';
				
				for(var i=0; i<=counter; i++)
				{
					code += blocks[ i ];
				}
				
				code += '</tr></table><!-- end socnetauth block -->';
			}
			else if( document.getElementById('generator_type').value == 'vline' )
			{
				var code = '<!-- socnetauth block --><table cellpadding=0 cellspacing=0 border=0>';
				
				for(var i=0; i<=counter; i++)
				{
					code += "<tr>"+blocks[ i ]+"</tr>";
				}
				
				code += '</table><!-- end socnetauth block -->';
			}
			
			document.getElementById('generator_view').innerHTML = code;
			document.getElementById('generate_code').value = code;
		}
	 
		genarate_links();
	 </script>
	</td>
	</tr>
	</table>
		
		<? echo $text_description; ?>
		
	  </div>
	  <div id="tab-vkontakte">
        <table class="form">
          <tbody>
            <tr>
				<td><?php echo $entry_vkontakte_appid; ?></td>
				<td><input type="text" name="socnetauth_vkontakte_appid" style="width: 300px;" value="<?php echo $socnetauth_vkontakte_appid; ?>" /></td>
			</tr>
            <tr>
				<td><?php echo $entry_vkontakte_appsecret; ?></td>
				<td><input type="text" name="socnetauth_vkontakte_appsecret" style="width: 300px;" value="<?php echo $socnetauth_vkontakte_appsecret; ?>" /></td>
			</tr>
		</table>
		<? echo $text_vkontakte_instruction; ?>
		
	  </div>
	  <div id="tab-facebook">
        <table class="form">
          <tbody>
            <tr>
				<td><?php echo $entry_facebook_appid; ?></td>
				<td><input type="text" name="socnetauth_facebook_appid" style="width: 300px;" value="<?php echo $socnetauth_facebook_appid; ?>" /></td>
			</tr>
            <tr>
				<td><?php echo $entry_facebook_appsecret; ?></td>
				<td><input type="text" name="socnetauth_facebook_appsecret" style="width: 300px;" value="<?php echo $socnetauth_facebook_appsecret; ?>" /></td>
			</tr>
		</table>
	  
		<? echo $text_facebook_instruction; ?>
	  </div>
	  <div id="tab-twitter">
        <table class="form">
          <tbody>
            <tr>
				<td><?php echo $entry_twitter_consumer_key; ?></td>
				<td><input type="text" name="socnetauth_twitter_consumer_key" style="width: 300px;" value="<?php echo $socnetauth_twitter_consumer_key; ?>" /></td>
			</tr>
            <tr>
				<td><?php echo $entry_twitter_consumer_secret; ?></td>
				<td><input type="text" name="socnetauth_twitter_consumer_secret" style="width: 300px;" value="<?php echo $socnetauth_twitter_consumer_secret; ?>" /></td>
			</tr>
		</table>
	  
		<? echo $text_twitter_instruction; ?>
	  
	  </div>
	  <div id="tab-odnoklassniki">
        <table class="form">
          <tbody>
            <tr>
				<td><?php echo $entry_odnoklassniki_application_id; ?></td>
				<td><input type="text" name="socnetauth_odnoklassniki_application_id" style="width: 300px;" value="<?php echo $socnetauth_odnoklassniki_application_id; ?>" /></td>
			</tr>
            <tr>
				<td><?php echo $entry_odnoklassniki_public_key; ?></td>
				<td><input type="text" name="socnetauth_odnoklassniki_public_key" style="width: 300px;" value="<?php echo $socnetauth_odnoklassniki_public_key; ?>" /></td>
			</tr>
            <tr>
				<td><?php echo $entry_odnoklassniki_secret_key; ?></td>
				<td><input type="text" name="socnetauth_odnoklassniki_secret_key" style="width: 300px;" value="<?php echo $socnetauth_odnoklassniki_secret_key; ?>" /></td>
			</tr>
			
		</table>
		
		<? echo $text_odnoklassniki_instruction; ?>

		
	  </div>
	  <div id="tab-help">
		<? echo $text_help; ?>
	  </div>
      </form>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
var module_row = <?php echo $module_row; ?>;

function addModule() {	
	html  = '<tbody id="module-row' + module_row + '">';
	html += '  <tr>';
	html += '    <td class="left"><select name="socnetauth_module[' + module_row + '][layout_id]">';
	<?php foreach ($layouts as $layout) { ?>
	html += '      <option value="<?php echo $layout['layout_id']; ?>"><?php echo addslashes($layout['name']); ?></option>';
	<?php } ?>
	html += '    </select></td>';
	html += '    <td class="left"><select name="socnetauth_module[' + module_row + '][status]">';
    html += '      <option value="1" selected="selected"><?php echo $text_enabled; ?></option>';
    html += '      <option value="0"><?php echo $text_disabled; ?></option>';
    html += '    </select><input type="hidden" name="socnetauth_module[' + module_row + '][position]" value="content_bottom"><input type="hidden" name="socnetauth_module[' + module_row + '][sort_order]" value="0"></td>';
	html += '    <td class="left"><a onclick="$(\'#module-row' + module_row + '\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
	html += '  </tr>';
	html += '</tbody>';
	
	$('#module tfoot').before(html);
	
	module_row++;
}
//--></script> 
<script type="text/javascript"><!--
$('.htabs a').tabs(); 
//--></script> 
<?php echo $footer; ?>