<?php
/**
* @package ccNewsletter
* @version 1.0.9
* @author  Chill Creations <info@chillcreations.com>
* @link    http://www.chillcreations.com
* @copyright Copyright (C) 2008 - 2010 Chill Creations-All rights reserved
* @license GNU/GPL, see LICENSE.php for full license.
* See COPYRIGHT.php for more copyright notices and details.

This file is part of ccNewsletter.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
**/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

function versionCompare()
{
	$jversion = new JVersion();
	$current_version =  $jversion->getShortVersion();
	return substr($current_version,0,3);
}

if(versionCompare()!="1.5")
{
	?>
		<style type="text/css">
		tr, td {
		    border: 0 solid #DDDDDD;
		}
		</style>
	<?php
}
?>
<div class="componentheading">
	<?php echo $this->pageTitle; ?>
</div>
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root();?>components/com_ccnewsletter/views/ccnewsletter/tmpl/stylesheet.css" />
<script language="javascript" type="text/javascript">
function reloadCaptchacom(){
		var i;
		var k=0;
		var tmpstr="";

		for(i=1;i<=document.forms.length;i++)
		{
			tmpstr=document.forms[i].id;
			if(tmpstr.length >19)
			{
				if(tmpstr.substring(0,19)=="subscribeFormModule")
				{
					try
					{
						document.forms[i].captcha.src=document.forms[i].captcha.src+ '?' +new Date();
						if(k==0)
						{
							try
							{
								document.getElementById('captchacom').src=document.getElementById('captchacom').src+ '?' +new Date();
							}
							catch (e)
							{}
							k=1;
						}
					}
					catch (e)
					{}
				}
			}
			else
			{
				if(document.forms.length==i+1 && k==0)
				{
					try
					{
						document.getElementById('captchacom').src=document.getElementById('captchacom').src+ '?' +new Date();
					}
					catch (e)
					{}
				}
			}
		}
	}
function testingsubform(task)
{
		var form= document.subscribeFormcom;
		if(task=="addSubscriber")
		{
			if(form.name.value=="")
			{
				alert("Please enter name!");
				return false;
			}
			if(form.email.value=="")
			{
				alert("Please enter email!");
				return false;
			}
			<?php
				if($this->paramscaptcha=="1")
				{
			?>
					if(form.securecom1.value=="")
					{
						alert("Please enter security code!");
						return false;
					}
					else
					{
						form.task.value = "addSubscriber";
						form.submit();
					}
			<?php
				}
				else
				{
					?>
					if(0)
					{

					}
					else
					{
						form.task.value = "addSubscriber";
						form.submit();
					}
					<?php
				}
				?>
		}
		else if(task == "removeSubscriberByEmail")
		{
			if(form.email.value == "")
			{
				alert('<?php echo "Enter the email"; ?>');
			}
			else
			{
				form.task.value = task;
				form.submit();
			}
		}
		if(task == "back")
		{
			window.history.go(-1);
		}
}

</script>
<form action="" method="post" name="subscribeFormcom" id="subscribeFormcom">
<table >
<tr>
	<td align="left" colspan="2">
		<?php
		echo $this->operationStatus;
		if($this->addSubscriberStatus=="1")
		{
			 ?>
			 <br/><br/><br/>
			<input class="button" type="button" name ="back" value="Back" onclick="testingsubform('back');">
		<?php
		}
		?>
	</td>
</tr>
<?php

	if($this->addSubscriberStatus != '1' or $this->addSubscriberStatus=="")
	{
?>
<tr>
	<td >
		<label for="name">
			<?php echo JText::_( 'CC_NAME' ); ?>:
		</label>
	</td>
	<td>
		<input type="text" name="name" id="name" size="32" maxlength="250" value="<?php echo $this->name;?>" />
	</td>
</tr>
<tr>
	<td >
		<label  for="email">
			<?php echo JText::_( 'CC_EMAIL' ); ?>:
		</label>
	</td>
	<td>
		<input type="text" name="email" id="email" size="32" maxlength="250" value="<?php echo $this->email;?>" />
	</td>
</tr>
<?php
				if($this->paramscaptcha=="1")
				{
			?>
<tr>
	<td align="center" colspan="2">
		<input type="text" name="securecom1" id="securecom1" value="what's the result?" onfocus="this.value=''"  /><br/>
		<span class="explain">click on the image to reload it</span><br/>
		<img src="<?php echo JURI::root();?>modules/mod_ccnewsletter/tmpl/image.php" alt="Click to reload image" title="Click to reload image" id="captchacom" onclick="reloadCaptchacom()" />
	</td>
</tr>
<?php
				}
		if($this->unsubscribe)
		{
		?>
		<tr>
			<td width="100">
				&nbsp;
				</td>
			<td align="center" colspan="2">
				<input class="button"  type="button" id="addSubscriber" name="addSubscriber" value="<?php echo JText::_( 'CC_SUBSCRIBE_BUTTON' );?>"  onclick="testingsubform('addSubscriber');"/>
				<input class="button" type="button" id="removeSubscriberByEmail" name="removeSubscriberByEmail" value="<?php echo JText::_( 'CC_UNSUBSCRIBE_BUTTON' );?>"  onclick="testingsubform('removeSubscriberByEmail');"/>
			</td>
		</tr>
		<?php
		}
		else
		{
		?>
<tr>
	<td align="center" colspan="2">
		<input type="button" name="button" id="addSubscriber" onclick="testingsubform('addSubscriber')" value="<?php echo JText::_( 'CC_SUBMIT' ); ?>"  />
	</td>
</tr>
<?php
         	}
}
?>
</table>
<input type="hidden" name="option" value="com_ccnewsletter" />
<input type="hidden" name="task" value="" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
<br />
