<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com © 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";
include "../includes/arrays.inc.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}


$message="";
$success_message ="";
if(isset($_POST['submit']))
{
	
	$taxrate=addslashes($_POST['taxrate']);
	
	$tax=trim(addslashes($_POST['tax']));
	if($taxrate=="2" and empty($tax))
	{
		$message=ENTER_TAX_RATE;
	}
	if($taxrate=="2" and $tax=="0")
	{
		$message=ENTER_TAX_RATE;
	}
	
	if($taxrate=="2" )
	{
	  if(!empty($tax) && $tax=='0')
	  {
		$message=TAX_POSITIVE_VALUE;
	}
	  
	}
	
	$sql_update="update ".$tableprefix."settings SET enable_tax='".$taxrate."' ";
	$result=mysql_query($sql_update);
	
	if($message=="")
	{	
		if($taxrate=="2" and !empty($tax))
		{
			$sql_update="update ".$tableprefix."settings SET defaulttax_rate='".$tax."' ";
			$result=mysql_query($sql_update) or die(mysql_error());
		}
	}
	if($message==""){
	$success_message = MSG_SETTINGS;
        }
	
}	

$sql = "SELECT * FROM ".$tableprefix."settings ";
		$result = mysql_query($sql);
		if(mysql_num_rows($result) != 0)
		{
			$row = mysql_fetch_array($result);
			
			$taxrate=$row['enable_tax'];
			$tax=$row['defaulttax_rate'];
	
		} // end result check 
		if($taxrate=="2")
		{
			$tax_block = "";
		}
		else
		{
			$tax_block="none";
		}		
$message=($message!='')?$message:$msg_succ;	
		
//selecting settings for fedex shipping
include "../includes/htmltop.php";

?>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<body>
<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
<?php
		include_once("../includes/admintopmenu.php")
?>
		
		<form action="" method="post" name="frmtax"  onSubmit="return validatetax();">
		
		<div align="left" class="content_area">
				<!--content area start -->
				<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr><td height="35"><?php include_once("../includes/taxmenu.php")?></td>
			</tr>
				<tr>
				<td>
				
						<div align="left" class="page_title"><?php echo TAX_SETTINGS;?> </div>
						<div align="center" class="text_information grey_tr"><?php echo $message?></div>
                                                <div align="center" class="text_information_success grey_tr">
                                                     <?php echo $success_message; ?>
                                                </div>
            			<br>
						<div align="left">
						
								<table width="100%" border="0" cellpadding="1" cellspacing="1" class="manage_table">
								<tr>
								  <td width="25%"  height="40"><SPAN class="required">*</SPAN> <?php echo TAX_SETTINGS;?>: </td>
								  <td width="75%"><LABEL for=taxtype3>
                                  <input name="taxrate" type="radio" value="0" checked onClick="return checktax();" >
<?php echo TXT_NO_TAX;?></LABEL>
                                    <BR></td>
								</tr>
								<tr>
								  <td  height="40">&nbsp;</td>
								  <td><input name="taxrate" type="radio" value="1" <?php if($taxrate=="1") { echo "checked";}?> onClick="return checktax();">
<?php echo TXT_I_WANT_TO_APPY_TAX;?></td>
								</tr>
								<tr>
								  <td  height="40">&nbsp;</td>
								  <td><input name="taxrate" type="radio"  id='taxid' value="2" <?php if($taxrate=="2") { echo "checked";}?> onClick="return checktax();">
<?php echo TXT_ONE_TAX_RATE;?></td>
								</tr>
								<tr>
								  <td  height="40">&nbsp;</td>
								  <td align="left" valign="top">&nbsp;
								    <div id="taxblock" style="display:<?php echo $tax_block;?>">
                                    <table width="60%"  border="0" cellspacing="2" cellpadding="2">
                                      <tr>
                                        <td><?php echo ENTER_TAX_RATE;?> <span class="style1">*</span> </td>
                                        <td><input name="tax" type="text" id="tax" value="<?php echo $tax;?>" size="10" maxlength="5">
                                        %</td>
                                      </tr>
                                    </table>							      
                                    </div></td>
								  </tr>
								</table>

						</div>
						<div align="center"><input type="submit" name="submit" value="<?php echo UPDATE;?>" class="button" ></div>
						
				<!--content area end-->
				</td>
			</tr>
		</table>				
												
		  </div>
				
				</form>
				
					<div align="left" class="clear_float"><img src="../images/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
?>

<script language="javascript">
function validatetax()
{	
	
	if(document.frmtax.taxrate[2].checked == true)
		{
			if(document.frmtax.tax.value=="")
			{
				return confirm("<?php echo ENTER_TAX_RATE?>");
				document.frmtax.tax.focus();
				return false;
			}	
			if(isNaN(document.frmtax.tax.value))
			{
				return confirm("<?php echo TXT_TAX_RATE_INTEGER?>");
			document.frmtax.tax.focus();
			document.frmtax.tax.select();
			return false;
			}
		
		}
		
else
    return true;
		

}

function checktax()
	{
	
	
		if(document.frmtax.taxrate[2].checked == true)
		{
			document.getElementById("taxblock").style.display ="";
		
		}
		else
		{
		
			document.getElementById("taxblock").style.display ="none";
		
		}
	
	
	
	
	
	}


</script>
