<?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.
**/
// no direct access
defined('_JEXEC') or die('Restricted access');
/* Import newsletter css */
jimport( 'joomla.application.component.view');

$unsubscribe = $parameters['unsubscribe_button'];
$terms = $parameters['showterm_text'];

$id = $parameters['article'];
$cid='index.php?option=com_content&amp;view=article&id='.$id.'&tmpl=component';
$popuptype = $parameters['popuptype'];

$jversion = new JVersion();
$current_version =  $jversion->getShortVersion();
$current_version= substr($current_version,0,3);
if($current_version!="1.5")
{
	?>
		<style type="text/css">
		tr, td {
		    border: 0 solid #DDDDDD;
		}
		</style>
	<?
}
//unsubscribe form code
if($subscribe_flag == 'u')
{
?>

	<div class="mainnewsletter">
	<p><?php echo $parameters['introduction']; ?></p>
	<br/>
	<form action="<?php echo JRoute::_( 'index.php?option=com_ccnewsletter&view=unsubscribe', true, 0); ?>" method="post" name="subscribeForm" id="subscribeForm">
		<input type="hidden" name="email" id="email"  value="<?php echo $email; ?>" />
		<center><input class="button" type="submit" name="submit" value="<?php echo $parameters['unsubscribe']; ?>" /></center>
		<div class="clr"></div>
		<input type="hidden" name="option" value="com_ccnewsletter" />
		<input type="hidden" name="task" value="removeSubscriberByEmail" />
		<?php echo JHTML::_( 'form.token' ); ?>
	</form>
	<br/>
	</div>
<?php
}
else
{
?>


	<script type="text/javascript">
	function formsubmit(task,formname)
	{
		str='addSubscriber';
		strchk=task.search(str);
		var form = formname;
		if(strchk == "0")
		{
			<?php
				if($configurationrow->captcha=="1") {
			?>
			if(form.secure.value=="")
			{
				alert("Please enter captcha code!");
				return false;
			}
			<?php } ?>
			if(form.name.value=="")
			{
				alert('<?php echo $parameters['namewarning']; ?>');
			}
			else if(form.email.value == "")
			{
				alert('<?php echo $parameters['emailwarning']; ?>');
			}
			else if(( form.email.value.search("@") == -1) || ( form.email.value.search("[.*]" ) == -1 ))
			{
				alert('<?php echo $parameters['emailwarning']; ?>');
			}
			<?php if($parameters['showterm'])
			{
			?>
			else if(form.terms_condition_ch.checked == false)
			{
				alert ('<?php echo $parameters['terms_cond_warn']; ?>');
			}
			<?php
			}
			?>
			else
			{
				form.task.value = "addSubscriber";
				form.submit();
			}
		}
		else if(task == "removeSubscriberByEmail")
		{
			if(form.email.value == "")
			{
				alert('<?php echo $parameters['emailwarning']; ?>');
			}
			else if(( form.email.value.search("@") == -1) || ( form.email.value.search("[.*]" ) == -1 ))
			{
				alert('<?php echo $parameters['emailwarning']; ?>');
			}
			else
			{
				form.task.value = "removeSubscriberByEmail";
				form.submit();
			}
		}
	}
	</script>
<?php

	if($configurationrow->captcha=="1") {
?>
<script type="text/javascript">
	function reloadCaptcha(formname)
	{
		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)
					{}
				}
			}
		}
	}
</script>
<?php } ?>
<?php

	if($parameters['showterm'])
	{
		if($popuptype)
		{
			JHTML::_('behavior.modal', 'a.modal');
		}
		else
		{
			?>
			<script type="text/javascript">
			function newPopup(url)
			{
				popupWindow = window.open(url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no')
			}
			</script>
			<?php
		}
	}
	/* Import css and js for appropriate stye selected from parameter */
//subscribe form code
	if($parameters['style']== 'dropdown')//dropdown style code
	{
		//name and email inlinepopup files
	JHTML::script('popuphighslide-with-html.js', JURI::base() .'modules/mod_ccnewsletter/template/inlinepopup/');
	JHTML::stylesheet('popuphighslide.css', JURI::base() . 'modules/mod_ccnewsletter/template/inlinepopup/');
JHTML::script('dropdown.js', JURI::base() . 'modules/mod_ccnewsletter/template/dropdown/');
?>
	<script type="text/javascript">
	    hs.graphicsDir = '<?php echo JURI::base() ?>modules/mod_ccnewsletter/template/inlinepopup/graphics/';
	    hs.outlineType = 'rounded-white';
	    hs.outlineWhileAnimating = true;
	</script>
		<!--new code for dropdown -->
		<form action="<?php echo JRoute::_('index.php?option=com_ccnewsletter&amp;view=subscribe');?>" method="post" name="subscribeFormModule<?php echo $module->id; ?>" id="subscribeFormModule<?php echo $module->id; ?>">
		<center><a href="javascript:;" onmousedown="slideupdown('mydiv<?php echo $module->id; ?>');"> <input type="button" name="button1" id="button1" value="<?php echo $title; ?>" /> </a></center>
			<div id="mydiv<?php echo $module->id; ?>" style="display:none; overflow:hidden; height:230px;">
				<table>
					<tr>
						<td align="right">
								<?php echo $parameters['name']; ?>:
						</td>
						<td align="left">
							<input type="text" name="name" id="name" size="15" maxlength="35" value="<?php echo $name; ?>" />
						</td>
					</tr>
					<tr>
						<td align="right">
								<?php echo $parameters['email']; ?>:
						</td>
						<td align="left">
							<input type="text" name="email" id="email" size="15" maxlength="60" value="<?php echo $email; ?>" />
						</td>
					</tr>

				<!-- //captcha -->
				<?php

				 		if($configurationrow->captcha=="1")
						{
				?>
					<tr>
						<td align="center" colspan="2">
						<input type="text" name="secure" id="secure" value="<?php echo $parameters['captchacode'] ?>" onfocus="this.value=''"  />
	        			<img src="<?php echo JURI::root();?>modules/mod_ccnewsletter/tmpl/image.php" alt="Click to reload image" title="Click to reload image" name="captcha" id="captcha" onclick="reloadCaptcha(this.form)"  />
						</td>
					</tr>
				<?php
						}
				?>
				<!--close captcha code -->
				<!--start terms and condition -->
				<?php if($parameters['showterm'])
				{
					if($id!="0")
					{
						if($popuptype)
						{
							?>
								<!-- high slide start-->
						<tr>
							<td align="center" colspan="2">
								<div class="newsletterbuttonpopup_highslidepopup">
									<input id="ccnewsletter" name="terms_condition_ch" class="inputbox" type="checkbox">
									<a href='<?php echo $cid; ?>' onclick="return hs.htmlExpand( this, {objectType: 'iframe', outlineType: 'rounded-black',outlineWhileAnimating: true, preserveContent: false } )" class="highslidepopup"><?php echo $terms;?></a>
								</div>
							</td>
						</tr>
								<!-- high slide end-->
							<?php
						}
						else
						{
						?>
					<tr>
						<td align="center" colspan="2">
							<input id="ccnewsletter" name="terms_condition_ch" class="inputbox" type="checkbox">
							<a style="font-size:14px;color:#4E4E51;margin:0px 0px 0px 5px;text-decoration:none;" href="JavaScript:newPopup('<?php echo JRoute::_('modules/mod_ccnewsletter/helper/popup.php?id='.$id)?>');"><?php echo $terms;?></a>
						</td>
					</tr>
						<?php
						}
					}
				}
				 ?>
				 <!--end terms and condition -->
				<?php
				if($unsubscribe)
				{
				?>
				<tr>
					<td align="center" colspan="2">
						<input class="button"  type="button" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber',this.form);"/>
						<input class="button" type="button" id="removeSubscriberByEmail" name="removeSubscriberByEmail" value="<?php echo $parameters['unsubscribe']; ?>"  onclick="formsubmit('removeSubscriberByEmail',this.form);"/>
					</td>
				</tr>
				<?
				}
				else
				{
					$argvar="addSubscriber".$module->id;
				?>
				<tr>
					<td align="center" colspan="2">
						<input class="button"  type="button" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber',this.form);"/>
					</td>
				</tr>
				<?php
				}
				?>
			</table>
				<input type="hidden" name="option" value="com_ccnewsletter" />
				<!--<input type="hidden" name="task" value="addSubscriber" />-->
				<input type="hidden" name="task" value="" />
				<?php echo JHTML::_( 'form.token' ); ?>

			</div>
			</form>
			<!--end code for dropdown -->
<?php
	}
	else if($parameters['style']== 'inlinepopup')//inline style code
	{
		//name and email inlinepopup files
		JHTML::script('inlinepopup-with-html.js', JURI::base() .'modules/mod_ccnewsletter/template/inlinepopup/');
		JHTML::stylesheet('inlinepopup.css', JURI::base() . 'modules/mod_ccnewsletter/template/inlinepopup/');
?>
		<script type="text/javascript">
		    hs.graphicsDir = '<?php echo JURI::base() ?>modules/mod_ccnewsletter/template/inlinepopup/graphics/';
		</script>
		<div class="mainnewsletter">
		<p><?php echo $parameters['introduction'] ?></p>
		<div class="newsletterbutton_inlinepopup">
			<p><a href="#" onclick="return hs.htmlExpand(this, { contentId: 'inlinepopup-html' } )" class="inlinepopup"><input type="button" name="openform" value="<?php echo $title; ?>"></a></p>
		</div>
		<br/>
		<div class="inlinepopup-html-content" id="inlinepopup-html">
			<div class="inlinepopup-header">
		  	<table border="0" width="100%">
			<tr>
			<td width="50%"></td>
			  <td width="20%">
				&nbsp;
			  </td>
			  <td width="28%">
				<div class="inlinepopup-close" style="float:right;" >
				 <a href="#" onclick="return hs.close(this)">X</a>
				</div>
			  </td>
            </tr>
           </table>
			</div>
			<div class="inlinepopup-body">

			<form action="<?php echo JRoute::_('index.php?option=com_ccnewsletter&amp;view=subscribe');?>" method="post" name="subscribeFormModule<?php echo $module->id; ?>" id="subscribeFormModule<?php echo $module->id; ?>">
				<table>
					<tr>
						<td align="right">
							<?php echo $parameters['name']; ?>:
						</td>
						<td align="left">
							<input type="text" name="name"  id="name" size="15" maxlength="35" value="<?php echo $name; ?>" />
						</td>
					</tr>
					<tr>
						<td align="right">
							<?php echo $parameters['email']; ?>:
						</td>
						<td align="left">
							<input type="text" name="email"  id="email" size="15" maxlength="60" value="<?php echo $email; ?>" />
						</td>
					</tr>
				<!-- //captcha -->
				<?php
				 		if($configurationrow->captcha=="1")
						{
				?>
						<tr>
							<td align="center" colspan="2">
								<input type="text" name="secure" id="secure" value="<?php echo $parameters['captchacode'] ?>" onfocus="this.value=''"  />
			        			<img src="<?php echo JURI::root();?>modules/mod_ccnewsletter/tmpl/image.php" alt="Click to reload image" title="Click to reload image" name="captcha" id="captcha" onclick="reloadCaptcha(this.form)" />
				<?php
						}
				?>
				<!--close captcha code -->
				<!--start terms and condition -->
				<?php if($parameters['showterm'])
				{

					if($id!="0")
					{

						if($popuptype)
						{

						?>

							<!-- high slide start-->

						<tr>
							<td align="center" colspan="2">
								<input id="ccnewsletter" name="terms_condition_ch" class="inputbox" type="checkbox">
								<a style="text-decoration:none;" class="modal"  rel="{handler: 'iframe', size: {x: 900, y: 500}}" href='<?php echo $cid; ?>' ><?php echo $terms;?></a>
							</td>
						</tr>
							<!-- high slide end-->
						<?php
						}
						else
						{
						?>
						<tr>
							<td align="center" colspan="2">
								<input id="ccnewsletter" name="terms_condition_ch" class="inputbox" type="checkbox">
								<a style="font-size:14px;color:#4E4E51;margin:0px 0px 0px 5px;text-decoration:none;" href="JavaScript:newPopup('<?php echo JRoute::_('modules/mod_ccnewsletter/helper/popup.php?id='.$id)?>');"><?php echo $terms;?></a>
							</td>
						</tr>
						<?php
						}
					}
				}
				?>
				<!--end terms and condition -->
				<?php
				if($unsubscribe)
				{
				?>
				<tr>
					<td align="center" colspan="2">
						<input class="button" type="button" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber',this.form);"/>
						<input class="button" type="button" id="removeSubscriberByEmail" name="removeSubscriberByEmail" value="<?php echo $parameters['unsubscribe']; ?>"  onclick="formsubmit('removeSubscriberByEmail',this.form);"/>
					</td>
				</tr>
				<?php
				}
				else
				{
				?>
				<tr>
					<td align="center" colspan="2">
						<input class="button" type="button" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber',this.form);"/>
					</td>
				</tr>
				<?php
				}
				?>
				</table>
				<input type="hidden" name="option" value="com_ccnewsletter" />
				<!--<input type="hidden" name="task" value="addSubscriber" />-->
				<input type="hidden" name="task" value="" />
				<?php echo JHTML::_( 'form.token' ); ?>
				</form>
		</div>
	    <div class="inlinepopup-footer">
	        <div>
	            <span class="inlinepopup-resize" title="Resize">
	                <span></span>
	            </span>
	        </div>
	    </div>
	</div>
	</div>
<?php
	}
	else if($parameters['style']== 'horizontal')//horizontal style code
	{
		JHTML::script('popuphighslide-with-html.js', JURI::base() .'modules/mod_ccnewsletter/template/inlinepopup/');
	JHTML::stylesheet('popuphighslide.css', JURI::base() . 'modules/mod_ccnewsletter/template/inlinepopup/');

?>
	<script type="text/javascript">
	    hs.graphicsDir = '<?php echo JURI::base() ?>modules/mod_ccnewsletter/template/inlinepopup/graphics/';
	    hs.outlineType = 'rounded-white';
	    hs.outlineWhileAnimating = true;
	</script>

	<div class="mainnewsletter" style="width:720px;">
		<p><?php echo $parameters['introduction'] ?></p>
		<div >
		<form action="<?php echo JRoute::_('index.php?option=com_ccnewsletter&amp;view=subscribe');?>" method="post" name="subscribeFormModule<?php echo $module->id; ?>" id="subscribeFormModule<?php echo $module->id; ?>">
			<table >
			<tr>
				<td>
				<input type="text" name="name"  id="name" size="15" maxlength="35" value="<?php echo $name; ?>" /></td>
				<td><input type="text" name="email"  id="email" size="15" maxlength="60" value="<?php echo $email; ?>" />
                                </td>
				<!-- //captcha -->
				<?php
				 		if($configurationrow->captcha=="1")
						{
				?>
				<td>
						<input type="text" name="secure" id="secure" value="<?php echo $parameters['captchacode'] ?>" onfocus="this.value=''"  /></td>
	        			<td><img src="<?php echo JURI::root();?>modules/mod_ccnewsletter/tmpl/image.php" alt="Click to reload image" title="Click to reload image" name="captcha" id="captcha" onclick="reloadCaptcha(this.form)" />
					</td>
				<?php
						}
				?>
				<!--close captcha code -->
				<!--start terms and condition -->
				<?php if($parameters['showterm'])
				{
					if($id!="0")
					{
						if($popuptype)
						{
						?>
						<td>
							<!-- high slide start-->
							<div class="newsletterbuttonpopup_highslidepopup">
								<p>
								<input id="ccnewsletter" name="terms_condition_ch" class="inputbox" type="checkbox">
								<a href='<?php echo $cid; ?>' onclick="return hs.htmlExpand( this, {objectType: 'iframe', outlineType: 'rounded-black',outlineWhileAnimating: true, preserveContent: false } )" class="highslidepopup"><?php echo $terms;?></a>
								</p>
							</div>
							<!-- high slide end-->

						</td>
						<?php
						}
						else
						{
						?>	<td>
							<input id="ccnewsletter" name="terms_condition_ch" class="inputbox" type="checkbox">
							<a style="font-size:14px;color:#4E4E51;margin:0px 0px 0px 5px;text-decoration:none;" href="JavaScript:newPopup('<?php echo JRoute::_('modules/mod_ccnewsletter/helper/popup.php?id='.$id)?>');"><?php echo $terms;?></a>
								</td>
						<?php
						}
					}
				}
				?>
				<!--end terms and condition -->
				<?php
				if($unsubscribe)
				{
				?>
				<td>
				<input class="button" type="button" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber',this.form);"/>
				<input class="button" type="button" id="removeSubscriberByEmail" name="removeSubscriberByEmail" value="<?php echo $parameters['unsubscribe']; ?>"  onclick="formsubmit('removeSubscriberByEmail',this.form);"/>
				</td>
				<?php
				}
				else
				{
				?>
					<td>
					<input class="button" type="button" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber',this.form);"/>
					</td>
				<?php
				}
				?>
				<input type="hidden" name="option" value="com_ccnewsletter" />
				<!--<input type="hidden" name="task" value="addSubscriber" />-->
				<input type="hidden" name="task" value="" />
				<?php echo JHTML::_( 'form.token' ); ?>
                                </form>
                               </tr>
                             </table>

		</div>
	</div>
	<?php
	}
	else//normal style code
	{
		JHTML::stylesheet('newsletter.css', JURI::base() . 'modules/mod_ccnewsletter/template/normal/');
?>
	<div class="mainnewsletter">
		<p><?php echo $parameters['introduction'] ?></p>
		<div class="normalsublayout">
		<form action="<?php echo JRoute::_('index.php?option=com_ccnewsletter&amp;view=subscribe');?>" method="post" name="subscribeFormModule<?php echo $module->id; ?>" id="subscribeFormModule<?php echo $module->id; ?>">
			<table>
				<tr>
					<td align="right">
						<?php echo $parameters['name']; ?>:
					</td>
					<td align="left">
						<input type="text" name="name"  id="name" size="15" maxlength="35" value="<?php echo $name; ?>" />
					</td>
				</tr>
				<tr>
					<td align="right">
						<?php echo $parameters['email']; ?>:
					</td>
					<td align="left">
						<input type="text" name="email"  id="email" size="15" maxlength="60" value="<?php echo $email; ?>" />
					</td>
				</tr>

				<!-- //captcha -->
				<?php
				 		if($configurationrow->captcha=="1")
						{
				?>
				<tr>
					<td align="center" colspan="2">
						<input type="text" name="secure" id="secure" value="<?php echo $parameters['captchacode'] ?>" onfocus="this.value=''"  />
	        			<img src="<?php echo JURI::root();?>modules/mod_ccnewsletter/tmpl/image.php" alt="Click to reload image" title="Click to reload image" name="captcha" id="captcha" onclick="reloadCaptcha(this.form)" />
					</td>
				</tr>
				<?php
						}
		JHTML::script('popuphighslide-with-html.js', JURI::base() .'modules/mod_ccnewsletter/template/inlinepopup/');
		JHTML::stylesheet('popuphighslide.css', JURI::base() . 'modules/mod_ccnewsletter/template/inlinepopup/');
?>
		<script type="text/javascript">
		    hs.graphicsDir = '<?php echo JURI::base() ?>modules/mod_ccnewsletter/template/inlinepopup/graphics/';
		    hs.outlineType = 'rounded-black';
		    hs.outlineWhileAnimating = true;
		</script>
				<!--close captcha code -->
				<!--start terms and condition -->
			<?php if($parameters['showterm'])
			{
				if($id!="0")
				{
					if($popuptype)
					{
						?>
							<!-- high slide start-->
					<tr>
						<td align="center" colspan="2">
							<div class="newsletterbuttonpopup_highslidepopup">
								<input id="ccnewsletter" name="terms_condition_ch" class="inputbox" type="checkbox">
								<a href='<?php echo $cid; ?>' onclick="return hs.htmlExpand( this, {objectType: 'iframe', outlineType: 'rounded-black',outlineWhileAnimating: true, preserveContent: false } )" class="highslidepopup"><?php echo $terms;?></a>
							</div>
						</td>
					</tr>
							<!-- high slide end-->
					<?php
					}
					else
					{
						?>
					<tr>
						<td align="center" colspan="2">
							<input id="ccnewsletter" name="terms_condition_ch" class="inputbox" type="checkbox">
							<a style="font-size:14px;color:#4E4E51;margin:0px 0px 0px 5px;text-decoration:none;" href="JavaScript:newPopup('<?php echo JRoute::_('modules/mod_ccnewsletter/helper/popup.php?id='.$id)?>');"><?php echo $terms;?></a>
						</td>
					</tr>
						<?php
					}
				}
			}
			// end terms and condition
			if($unsubscribe)
			{
			?>
			<tr>
				<td align="center" colspan="2">
					<input class="button" type="button" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber',this.form);"/>
					<input class="button" type="button" id="removeSubscriberByEmail" name="removeSubscriberByEmail" value="<?php echo $parameters['unsubscribe']; ?>"  onclick="formsubmit('removeSubscriberByEmail',this.form);"/>
				</td>
			</tr>
			<?php
			}
			else
			{
			?>
			<tr>
				<td align="center" colspan="2">
					<input class="button" type="button" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber',this.form);"/>
				</td>
			</tr>
			<?php
			}
			?>
			</table>
			<input type="hidden" name="option" value="com_ccnewsletter" />
			<!--<input type="hidden" name="task" value="addSubscriber" />-->
			<input type="hidden" name="task" value="" />
			<?php echo JHTML::_( 'form.token' ); ?>
			</form>
		</div>
	</div>
<?php
	}
}
?>
