<?php defined('_JEXEC') or die('Restricted access'); ?>
<?php
$db	=& JFactory::getDBO();
$query='select * from #__content_allarticleannounce_switch limit 1';
$db->setQuery($query);
$result=$db->loadObject();
?>
<script type='text/javascript'>
var xmlhttp;
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
function update()
{
	twitters=document.getElementById("twitter_y");
	facebooks=document.getElementById("facebook_y");
	content_types=document.getElementById("content_type_y");
	content_type_s=document.getElementById("content_type_x");
	twitter=0;
	facebook=0;
	content_type=0
	if(twitters.checked)twitter=1;
	if(facebooks.checked)facebook=1;
	if(content_type_s.checked)content_type=1;
	if(content_types.checked)content_type=2;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	url="index.php?option=com_allarticleannounce&format=raw&task=update&facebook="+facebook+"&twitter="+twitter+"&content_type="+content_type;
	xmlhttp.onreadystatechange=status_change;
	xmlhttp.open("POST",url,true);
	xmlhttp.send(null);
}
function status_change()
{
	if (xmlhttp.readyState==4)
	{
		response=xmlhttp.responseText;
		if(response=='1')
		{
			window.parent.document.getElementById('sbox-window').close();
		}
		else
		{
			alert("Error: "+response);
		}
	}
}


</script>
<form action='index.php' method='post'>
<table>
	<tr>
		<td>
			Publish To Facebook:
		</td>
		<td>
		<?php
		$yes='';
		$no='';
		if($result->facebook=='1')
		{
			$yes='checked';
		}
		else
		{
			$no='checked';
		}
		?>
			<input name='facebook' value='0' type='radio' <?php echo $no;?>/>NO &nbsp;
			<input id='facebook_y' name='facebook' value='1' type='radio' <?php echo $yes;?>/>YES
		</td>
	</tr>
	<tr>
		<td>
			Publish To Twitter:
		</td>
		<td>
		<?php
		$yes='';
		$no='';
		if($result->twitter=='1')
		{
			$yes='checked';
		}
		else
		{
			$no='checked';
		}
		?>
			<input name='twitter' value='0' type='radio' <?php echo $no;?>/>NO &nbsp;
			<input id='twitter_y' name='twitter' value='1' type='radio' <?php echo $yes;?>/>YES
		</td>
	</tr>
	<tr>
		<td>
			Content:
		</td>
		<td>
		<?php
		$global='';
		$yes='';
		$no='';
		if($result->content_type=='0')
		{
			$global='checked';
		}
		else if($result->content_type=='2')
		{
			$yes='checked';
		}
		else
		{
			$no='checked';
		}
		?>
			<input name='content_type' value='0' type='radio' <?php echo $global;?>/>Global Setting<br/>
			<input id='content_type_x'  name='content_type' value='1' type='radio' <?php echo $no;?>/>First 80 Charactars <br/>
			<input id='content_type_y' name='content_type' value='2' type='radio' <?php echo $yes;?>/>Metadata Description	
		</td>
	</tr>
	<tr>
		<td colspan='2'>
			<br/>
			<input type='button' value='Save' onclick="update();"/>
			<input type='button' onclick="window.parent.document.getElementById('sbox-window').close();" value='cancel'/>
		</td>
	</tr>
</table>
<input type='hidden' name='option' value='com_allarticleannounce'/>
<input type='hidden' name='task' value='update'/>
<input type='hidden' name='tmpl' value='component'/>
<?php echo JHTML::_( 'form.token' );?>
</form>