<?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_once "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);
  $_SESSION = array_map('stripslashes_deep', $_SESSION);
  } */
if (isset($_SESSION["sess_userid"]) and $_SESSION["sess_userid"] != "") {
    $userid = $_SESSION["sess_userid"];
    if (isCartEmpty($userid)) {
        header("Location:viewcart.php");
        exit;
    }

    if (checkDigitalProductsExistsinCart($userid)) {
        header("Location:viewcart.php?msg=cart_error_nondigital");
    }
} else if (isset($_GET['guest_login']) && $_GET['guest_login'] == 1) {
    $guest_login = $_GET['guest_login'];

    $_SESSION['guest_login'] = $guest_login;

    if (isset($_SESSION['guest_login']) && $_SESSION['guest_login'] == 1) {
        $_SESSION["sess_userid"] = '';
    }
} else {
    if (isVisitorCartEmpty(session_id())) {
        header("Location:viewcart.php");
        exit;
    } else {
        if (!isset($_SESSION['guest_login'])) {
            header("Location:" . SITE_URL . "/login.php?action=checkout");
            exit;
        }
    }
}

$_SESSION["sess_addresses_collected"] = false;
if ($_SESSION["sess_userid"] == '' && $_SESSION['guest_login'] == '') {
    $_SESSION["sess_addresses_collected"] = false;

    header("Location:" . SITE_URL . "/login.php?action=checkout");
    exit;
}

$_SESSION["sess_addresses_collected"] = false;
//==================Select shipping Details
$sql = "SELECT * FROM " . $tableprefix . "settings ";
$result = mysql_query($sql);
if (mysql_num_rows($result) != 0) {
    $row = mysql_fetch_array($result);
    $fedexmode = $row['enable_fedexshipping'];
    $upsmode = $row['enable_shipping'];
    $uspsmode = $row['enable_uspsshipping'];
    $canadapost = $row['enable_canadapost'];
    $australiapost = $row['enable_australiapost'];
    $flatrate = $row['enable_flatrate'];
    //$default_flatrate=$row['default_flatrate'];
    //$flatrate_additional=$row['additional_flatrate'];
    //$flatrate_name=stripslashes($row['flatrate_displayname']);
    $flatrate_name = TEXT_OUR_SHIPPING;
    switch ($fedexmode) {
        case "FDXE":
            $fedexShipping = FDXE_TEXT;
            $fedexServiceArray = $fedexService;
            break;
        case "FDXG":
            $fedexShipping = FDXG_TEXT;
            $fedexServiceArray = $fedexGroundService;
            break;
        case "N":
            $fedexShipping = FEDEX_INACTIVE_TEXT;
            break;
         default :
             $fedexShipping = FDXG_TEXT;
            break;
    }// end if

    if ($fedexmode != "N" || $upsmode != "N") {
        $fedex_block_display = "";
        $check_shipping_enable = "Y";
    }

    if ($fedexmode == "N") {
        $fedex_block_display = "none";
    }
} // end number of rows check


/* -------Multicart 2.0 Upgradation--------- */

/* -------function call to check whether cart contains digital or gift coupon products so as to hide shipping--- */

$hide_shipping_division = hideShipping();

/* -------function call to check whether cart contains digital or gift coupon products so as to hide shipping------ */
if ($upsmode != 'N' || $fedexmode != 'N' || $uspsmode != 'N' || $canadapost != 'N' || $australiapost != 'N' || $flatrate == "Y") { // check whether shipping Enabled or Not
    $check_shipping_enable = "Y";
} // end Shipping Check

if ($check_shipping_enable == "Y" && $hide_shipping_division == 1) {
    $shipping_block_display = "";
    $shipping_address_block_display = "";
} else {
    $shipping_block_display = "none";
}
$_SESSION['shipping_enabled'] = "true";
if ($upsmode == 'N' && $fedexmode == 'N' && $uspsmode == 'N' && $canadapost == 'N' && $australiapost == 'N' && $flatrate == "N") {
    $shipping_block_display = "none";
    $shipping_address_block_display = "none";
    $_SESSION['shipping_enabled'] = "false";
}

/* -------Multicart 2.0 Upgradation--------- */


if ($hide_shipping_division == 1) {
    $shipping_address_block_display = "";
} else {
    $shipping_address_block_display = "none";
}

//check Methods Needs to Enable 

$shippingSelection_Needed   =   0;

if($check_shipping_enable=='Y' && $hide_shipping_division==1)
{
    $shippingSelection_Needed   =   1;
}

if (isset($_GET["msg"]) and ($_GET["msg"] != "")) {
    $msg = $_GET["msg"];
    switch ($msg) {
        case "updateqty": $message = UPDATE_QUANTITY_ERROR_MSG."<br>";
            break;
        default:
            ;
    } // switch
}

$txtBillingFirstName = $_POST["txtBillingFirstName"];
$txtBillingLastName = $_POST["txtBillingLastName"];
$txtBillingAddress1 = $_POST["txtBillingAddress1"];
$txtBillingAddress2 = $_POST["txtBillingAddress2"];
$txtBillingCity = $_POST["txtBillingCity"];

$txtBillingZIP = $_POST["txtBillingZIP"];
$txtBillingFAX = $_POST["txtBillingFAX"];
$txtBillingPhone = $_POST["txtBillingPhone"];
$txtBillingEmail = $_POST["txtBillingEmail"];
$ddlBillingCountry = $_POST["bill_country"];
$txtBillingState = $_POST["bill_state"];
$chkSameAsAbove = $_POST["chkSameAsAbove"];



if ($chkSameAsAbove == "on") {
    $txtShippingFirstName = $txtBillingFirstName;
    $txtShippingLastName = $txtBillingLastName;
    $txtShippingAddress1 = $txtBillingAddress1;
    $txtShippingAddress2 = $txtBillingAddress2;
    $txtShippingCity = $txtBillingCity;
    $txtShippingZIP = $txtBillingZIP;
    $txtShippingFAX = $txtBillingFAX;
    $txtShippingPhone = $txtBillingPhone;
    $txtShippingEmail = $txtBillingEmail;
    $ddlShippingCountry = $ddlBillingCountry;
    $txtShippingState = $txtBillingState;

    $sameshipping = 1;
} else {
    $txtShippingFirstName = $_POST["txtShippingFirstName"];
    $txtShippingLastName = $_POST["txtShippingLastName"];
    $txtShippingAddress1 = $_POST["txtShippingAddress1"];
    $txtShippingAddress2 = $_POST["txtShippingAddress2"];
    $txtShippingCity = $_POST["txtShippingCity"];
    $txtShippingZIP = $_POST["txtShippingZIP"];
    $txtShippingFAX = $_POST["txtShippingFAX"];
    $txtShippingPhone = $_POST["txtShippingPhone"];
    $txtShippingEmail = $_POST["txtShippingEmail"];
    $ddlShippingCountry = $_POST["ship_country"];
    $txtShippingState = $_POST["ship_state"];

    $sameshipping = 0;
}

if (isset($_POST["btnConfirmOrder"])) {

    $txtComments = $_POST['txtComments'];

    $_SESSION["SESS_BUYER_COMMENTS"] = $txtComments;


    if (isset($_SESSION['guest_login']) && $_SESSION['guest_login'] == 1) {

        $chk = "SELECT user_id FROM " . $tableprefix . "users WHERE email='" . addslashes($txtBillingEmail) . "'";

        $chk_email_exists = mysql_query($chk);
        $chk_email_exists_num_rows = mysql_num_rows($chk_email_exists);



        if ($chk_email_exists_num_rows > 0) {

            $rsObj = mysql_fetch_object($chk_email_exists);
            if ($rsObj->user_id != '') {
                $userid = $rsObj->user_id;


                // When User wish to purchase as a guest Check Cart Items  Exists for a user  with same email id Modified By Asha ON 08-10-2012

                $sql_itmesQ = "SELECT * FROM  " . $tableprefix . "cart c
                        LEFT JOIN " . $tableprefix . "cart c1 ON (c1.product_id=c.product_id AND c1.product_option_id=c.product_option_id) where
                        c1.visitor_cart_id ='" . session_id() . "'   AND  c.user_id ='" . $userid . "'  ";

                $rs_itemsQ = mysql_query($sql_itmesQ) or die(mysql_error());

                $cartitems = array();

                if (mysql_num_rows($rs_itemsQ) > 0) {
                    while ($itemsRow = mysql_fetch_array($rs_itemsQ)) {
                        $cartitems[] = $itemsRow['cart_id'];
                    }


                    $cartitemslist = implode("','", $cartitems);

                    // Delete Cart Items which already exists

                    $sql_Delitems = "DELETE  FROM " . $tableprefix . "cart  where cart_id IN ('" . $cartitemslist . "') ";

                    $rs_Delitems = mysql_query($sql_Delitems) or die(mysql_error());
                }



                // End Check
            }
        } else {
            $userstring = strtolower(substr($txtBillingFirstName, 0, 3));
            $get_username = generateUsername(6, 2);

            if ($userstring != '') {
                $username = $userstring . $get_username;
            }

            $guest_password = generatePassword(6, 2);


            $sql = "INSERT INTO " . $tableprefix . "users (
							user_name,
							password,
							first_name,
							last_name,
							address1,
							address2,
							city,
							state,
							country,
							phone,
							fax,
							zip,
							email,
							date_registered
							) VALUES (
							'" . mysql_real_escape_string($username) . "',
							'" . mysql_real_escape_string(md5($guest_password)) . "',
							'" . mysql_real_escape_string($txtBillingFirstName) . "',
							'" . mysql_real_escape_string($txtBillingLastName) . "',
							'" . mysql_real_escape_string($txtBillingAddress1) . "',
							'" . mysql_real_escape_string($txtBillingAddress2) . "',
							'" . mysql_real_escape_string($txtBillingCity) . "',
							'" . mysql_real_escape_string($txtBillingState) . "',
							'" . mysql_real_escape_string($ddlBillingCountry) . "',
							'" . mysql_real_escape_string($txtBillingPhone) . "',
							'" . mysql_real_escape_string($txtBillingFAX) . "',
							'" . mysql_real_escape_string($txtBillingZIP) . "',
							'" . mysql_real_escape_string($txtBillingEmail) . "',
							now()
							)";
            mysql_query($sql) or die(mysql_error());
            $userid = mysql_insert_id();
            $_SESSION["sess_guest_login_id"] = $userid;

            $_SESSION["sess_guest_username"] = $username;

            $_SESSION["sess_guest_password"] = $guest_password;
        }

        $_SESSION["sess_userid"] = $userid;

        // Update Cart with User Id

        if ($_SESSION["sess_userid"] != '') {
            $sql_up = "UPDATE  " . $tableprefix . "cart set user_id ='" . $_SESSION["sess_userid"] . "' ,visitor_cart_id='NULL' where visitor_cart_id ='" . session_id() . "'  ";

            $rs_up = mysql_query($sql_up) or die(mysql_error());

            //$sql_up1	="UPDATE  ".$tableprefix."cart set visitor_cart_id ='' where user_id ='".$_SESSION["sess_userid"]."'  ";
            // $rs_up1	= mysql_query($sql_up1) or die(mysql_error());
        }

        //$_SESSION["sess_guest_user_login_id"]=$userid;
    }


    if ($_POST['shippingmode'] != '') {
        $txtShippingMethod = $_POST['shippingmode'];
    }

    $_SESSION["sessShippingMethod"] = $txtShippingMethod;
    $message = "";

    if (!isset($_SESSION["sess_addresses_collected"]) or ($_SESSION["sess_addresses_collected"] == false )) {
        if (!isNotNull($txtBillingFirstName)) {
            $message .= BILL_FIRST_NAME_EMPTY_MSG."<br>";
        }
        if (!isNotNull($txtBillingAddress1)) {
            $message .= BILL_ADDR_LINE1_EMPTY_MSG."<br>";
        }
        if (!isNotNull($txtBillingCity)) {
            $message .= BILL_CITY_EMPTY_MSG."<br>";
        }
        if (!isNotNull($txtBillingState)) {
            $message .= BILL_STATE_EMPTY_MSG."<br>";
        }

        if (!isNotNull($ddlBillingCountry)) {
            $message .= BILL_COUNTRY_EMPTY_MSG."<br>";
        }
        if (!isNotNull($txtBillingZIP)) {
            $message .= BILL_ZIP_EMPTY_MSG."<br>";
        }
        if (!isNotNull($txtBillingEmail)) {
            $message .= BILL_EMAIL_EMPTY_MSG."<br>";
        } else {
            if (!isValidEmail($txtBillingEmail)) {
                $message .= BILL_INVALID_EMAIL_TEXT."<br>";
            }
        }
        if (!isNotNull($txtBillingPhone)) {
            $message .= BILL_PHONE_EMPTY_MSG."<br>";
        }

        /* ---------Multicart 2.0 Upgradation------------------ */

        if ($sameshipping != 1 && $shipping_address_block_display == "") {

            /* ---------Multicart 2.0 Upgradation------------------ */

            if (!isNotNull($txtShippingFirstName)) {
                $message .= SHIP_FIRST_NAME_EMPTY_MSG."<br>";
            }
            if (!isNotNull($txtShippingAddress1)) {
                $message .= SHIP_ADDR_LINE1_EMPTY_MSG."<br>";
            }
            if (!isNotNull($txtShippingCity)) {
                $message .= SHIP_CITY_EMPTY_MSG."<br>";
            }
            if ($_POST['ship_state'] == '' && $_POST['bill_state'] == '') {
                $message .= SHIP_STATE_EMPTY_MSG."<br>";
            }

            if ($_POST['ship_state'] == '') {
                if ($_POST['bill_state'] != '') {
                    $txtShippingState = $_POST['bill_state'];
                }
            }

            if (!isNotNull($ddlShippingCountry)) {
                $message .= SHIP_COUNTRY_EMPTY_MSG."<br>";
            }
            if (!isNotNull($txtShippingZIP)) {
                $message .= SHIP_ZIP_EMPTY_MSG."<br>";
            }
            if (!isNotNull($txtShippingEmail)) {
                $message .= SHIP_EMAIL_EMPTY_MSG."<br>";
            } else {
                if (!isValidEmail($txtShippingEmail)) {
                    $message .= SHIP_INVALID_EMAIL_TEXT."<br>";
                }
            }
        }
    }



    $quantitiesadjusted = adjustQuantities($userid);
    if ($quantitiesadjusted) {
        $message .= "<br>".LOW_STOCK_QUANTITIES_ADJUSTED;
    }

    if ($message != "") { // error
        $message = "<br>".CORRECT_ERRORS_TEXT."<br>" . $message;
    } else {

        //*******Update user infomation

        if (isset($_SESSION['sess_userid']) && $_SESSION['guest_login'] != 1 && $userid != "") {
            $sql = "UPDATE " . $tableprefix . "users SET
			first_name = '" . addslashes($txtBillingFirstName) . "'";
            if ($txtBillingLastName != "")
                $sql .= ",last_name = '" . addslashes($txtBillingLastName) . "'";
            if ($txtBillingAddress1 != "")
                $sql .= ",address1 = '" . addslashes($txtBillingAddress1) . "'";
            if ($txtBillingAddress2 != "")
                $sql .= ",address2 = '" . addslashes($txtBillingAddress2) . "'";
            if ($txtBillingCity != "")
                $sql .= ",city = '" . addslashes($txtBillingCity) . "'";
            if ($txtBillingState != "")
                $sql .= ",state = '" . addslashes($txtBillingState) . "'";
            if ($ddlBillingCountry != "")
                $sql .= ",country = '" . addslashes($ddlBillingCountry) . "'";
            if ($txtBillingPhone != "")
                $sql .= ",phone = '" . addslashes($txtBillingPhone) . "'";
            if ($txtBillingFAX != "")
                $sql .= ",fax = '" . addslashes($txtBillingFAX) . "'";
            if ($txtBillingZIP != "")
                $sql .= ",zip = '" . addslashes($txtBillingZIP) . "'";
            if ($txtBillingEmail != "")
                $sql .= ",email = '" . addslashes($txtBillingEmail) . "'";

            $sql .= " WHERE user_id =  '" . addslashes($userid) . "'";

            mysql_query($sql) or die(mysql_error());
        }

        //************************



        if ($_SESSION["sess_addresses_collected"] == false) {
            $_SESSION["sessBillingFirstName"] = $txtBillingFirstName;
            $_SESSION["sessBillingLastName"] = $txtBillingLastName;
            $_SESSION["sessBillingAddress1"] = $txtBillingAddress1;
            $_SESSION["sessBillingAddress2"] = $txtBillingAddress2;
            $_SESSION["sessBillingCity"] = $txtBillingCity;
            $_SESSION["sessBillingState"] = $txtBillingState;
            $_SESSION["sessBillingZIP"] = $txtBillingZIP;
            $_SESSION["sessBillingFAX"] = $txtBillingFAX;
            $_SESSION["sessBillingPhone"] = $txtBillingPhone;
            $_SESSION["sessBillingEmail"] = $txtBillingEmail;
            $_SESSION["sessBillingCountry"] = $ddlBillingCountry;


            /* -------------Multicart 2.0 Upgradation----------------- */




            /* -------------Multicart 2.0 Upgradation----------------- */



            $_SESSION["sessShippingFirstName"] = $txtShippingFirstName;
            $_SESSION["sessShippingLastName"] = $txtShippingLastName;
            $_SESSION["sessShippingAddress1"] = $txtShippingAddress1;
            $_SESSION["sessShippingAddress2"] = $txtShippingAddress2;
            $_SESSION["sessShippingCity"] = $txtShippingCity;
            $_SESSION["sessShippingState"] = $txtShippingState;
            $_SESSION["sessShippingZIP"] = $txtShippingZIP;
            $_SESSION["sessShippingFAX"] = $txtShippingFAX;
            $_SESSION["sessShippingPhone"] = $txtShippingPhone;
            $_SESSION["sessShippingEmail"] = $txtShippingEmail;
            $_SESSION["sessShippingCountry"] = $ddlShippingCountry;

            $_SESSION["sess_addresses_collected"] = true;
        }


        if (!isset($_SESSION["sess_stock_adjusted"]) or ($_SESSION["sess_stock_adjusted"] == false )) {
            //$stockadjusted = adjustStock($userid,"-");
            $_SESSION["sess_stock_adjusted"] = true;
        }



        $select_cart_digital = "SELECT ct.cart_id
                                        FROM " . $tableprefix . "cart ct
                                        INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = ct.product_option_id
                                        INNER JOIN " . $tableprefix . "products prd ON prd.product_id = po.product_id
                                        WHERE ct.product_id = prd.product_id AND vdigital_product = 'Y' AND ct.user_id = " . $userid;

        $result_cart_digital = mysql_query($select_cart_digital) or die(mysql_error());

        $select_cart_gift = "SELECT ct.cart_id
                                     FROM " . $tableprefix . "cart ct
                                     INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = ct.product_option_id
                                     INNER JOIN " . $tableprefix . "products prd ON prd.product_id = po.product_id
                                     INNER JOIN " . $tableprefix . "categories ctry ON prd.product_category = ctry.category_id
                                     AND ctry.gift_certificate_flag = 'Y'
							   AND ct.user_id = " . $userid;


        $result_cart_gift = mysql_query($select_cart_gift) or die(mysql_error());

       $check_shipping_enable = checkShippingEnable();
       
        if ($check_shipping_enable == "Y" && $hide_shipping_division == 1) {
            $_SESSION["sessShippingMethod"] = $_POST['shippingmode'];
            //exit();
            $_SESSION['SESS_SHIPPING'] = 1;
            header("location: shipping_options.php");
            exit;
        } else {

            header("Location:paymentoptions.php");
            exit;
        }


        //$secureurl = SECURE_SITE_URL."/payment.php";
        //header("Location:$secureurl");
        //exit;
    }
}

/* --------Multicart 2.0 Begins------------ */

if ($_SESSION["sess_userid"] != '') {

    $select_user_details = "SELECT * FROM " . $tableprefix . "users WHERE user_id = " . $_SESSION["sess_userid"];
    $result_user_details = mysql_query($select_user_details) or die(mysql_error());

    if (mysql_num_rows($result_user_details) > 0) {

        $user_details_row = mysql_fetch_assoc($result_user_details);

        $txtBillingFirstName = $user_details_row['first_name'];
        $txtBillingLastName = $user_details_row['last_name'];
        $txtBillingAddress1 = $user_details_row['address1'];
        $txtBillingAddress2 = $user_details_row['address2'];
        $txtBillingCity = $user_details_row['city'];
        $txtBillingState = $user_details_row['state'];
        $txtBillingZIP = $user_details_row['zip'];
        $txtBillingFAX = $user_details_row['fax'];
        $txtBillingPhone = $user_details_row['phone'];
        $txtBillingEmail = $user_details_row['email'];
        $ddlBillingCountry = $user_details_row['country'];
    }
}


/* --------Multicart 2.0 Ends------------ */



$countrylist = makeCountryList();

/* display the active template */

$active_template = displayTemplate();
$adminCurrency = GetAdminCurrency();

$txtCurrency = $adminCurrency['currency_code'];
$deafultCountry = $currencyBasedCountries[$txtCurrency];

include "includes/htmltop.php";

/* Top File Name */

include_once ("includes/" . $active_template[0]);
?>
<script type="text/javascript">
    defaultCountryCode = '<?php echo $deafultCountry; ?>';
</script>
<script language="javascript" src="includes/function.js"></script>
<script language="javascript">
function validateEmail(email) {
  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  if( !emailReg.test(email ) ) {
    return false;
  } else {
    return true;
  }
}
    function ConfirmCheck()
    {

        var shipStatus = $(".clscheckbox:checked").length;

        var shippingOption = '<?php echo $hide_shipping_division; ?>';
        
        var shippingNeeded = '<?php echo $shippingSelection_Needed;?>';

        if($("#txtBillingFirstName").val()=='')
        {
            alert("<?php echo ALERT_FIRST_NAME_MSG; ?>");
            $('#txtBillingFirstName').focus();
            return false;
        }

        if($("#txtBillingAddress1").val()=='')
        {
            alert("<?php echo ALERT_ADDR_LINE1_MSG; ?>");
            $('#txtBillingAddress1').focus();
            return false;
        }

        if($("#txtBillingCity").val()=='')
        {
            alert("<?php echo ALERT_CITY_MSG; ?>");
            $('#txtBillingCity').focus();
            return false;
        }
        if($("#billCountrySelect").val()=='')
        {
            alert("<?php echo ALERT_STATE_MSG; ?>");
            $('#billCountrySelect').focus();
            return false;
        }

        if($("#billStateSelect").val()=='')
        {
            alert("<?php echo ALERT_COUNTRY_MSG; ?>");
            $('#billStateSelect').focus();
            return false;
        }

        if($("#txtBillingZIP").val()=='')
        {
            alert("<?php echo ALERT_ZIP_MSG; ?>");

            $('#txtBillingZIP').focus();
            return false;
        }

        var txtBillingEmail = $("#txtBillingEmail").val();  
        if(txtBillingEmail=='')
        {
            alert("<?php echo ALERT_EMAIL_MSG; ?>");
            $('#txtBillingEmail').focus();
            return false;
        }
        
        if(txtBillingEmail!='')
        {
            if( !validateEmail(txtBillingEmail)){
	             alert("<?php echo ALERT_INVALID_BILLING_EMAIL_MSG; ?>");
                        $('#txtBillingEmail').focus();
                        return false;
	        }
           
        }

        if($("#txtBillingPhone").val()=='')
        {
            alert("<?php echo ALERT_PHONE_MSG; ?>");
            $('#txtBillingPhone').focus();
            return false;
        }

         if(shipStatus==0 && shippingOption==1){
            if($("#txtShippingFirstName").val()=='')
            {
                alert("<?php echo ALERT_FIRST_NAME_MSG_SHIP; ?>");
                $('#txtShippingFirstName').focus();
                return false;
            }

            if($("#txtShippingAddress1").val()=='')
            {
                alert("<?php echo ALERT_ADDR_LINE1_MSG_SHIP; ?>");
                $('#txtShippingAddress1').focus();
                return false;
            }

            if($("#txtShippingCity").val()=='')
            {
                alert("<?php echo ALERT_CITY_MSG_SHIP; ?>");
                $('#txtShippingCity').focus();
                return false;
            }

            if($("#shipCountrySelect").val()=='')
            {
                alert("<?php echo ALERT_STATE_MSG_SHIP; ?>");
                $('#shipCountrySelect').focus();
                return false;
            }


            if($("#shipStateSelect").val()=='')
            {
                alert("<?php echo ALERT_COUNTRY_MSG_SHIP; ?>");
                $('#shipStateSelect').focus();
                return false;
            }

            if($("#txtShippingZIP").val()=='')
            {
                alert("<?php echo ALERT_ZIP_MSG_SHIP; ?>");
                $('#txtShippingZIP').focus();
                return false;
            }
             var txtShippingEmail = $("#txtShippingEmail").val(); 
            if(txtShippingEmail=='')
            {
                alert("<?php echo ALERT_EMAIL_MSG_SHIP; ?>");
                $('#txtShippingEmail').focus();
                return false;
            }
            
            if(txtShippingEmail!='')
        {
                if( !validateEmail(txtShippingEmail)){
	             alert("<?php echo ALERT_INVALID_SHIPPING_EMAIL_MSG; ?>");
                        $('#txtShippingEmail').focus();
                        return false;
	        }
           
        }

            if(shippingNeeded=='1') {
                var strlen=$(".checkbox:checked").length;
                if(strlen==0)
                {
                    alert("<?php echo ALERT_SHIPPING_METHOD; ?>");
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }


        else
        {
            return true;
        }
    }


    function verifyEmail(){
        var email =$('#txtBillingEmail').val();

        var guestflag= '<?php echo $_SESSION['guest_login']; ?>';
        if(email!='' && guestflag=='1' ){

            var postData = {email:email};
            $.ajax({url:'verifyemail.php',
                type:'post',
                dataType:'json',
                data:postData,
                beforeSend:function()
                {
                    // showAjaxLoader($("#productDetailsTD"))
                },
                complete:function()
                {
                    // hideAjaxLodaer();
                },
                success:function(reply)
                {

                    if(reply.response=='exists' && reply.items=='exists')
                    {

                        alert("<?php echo USER_ADDR_EXISTS_MSG; ?>");
                        return false;
                    }

                    if(reply.response=='exists' && reply.items=='notexists')
                    {
                        alert("<?php echo USER_EMAIL_EXISTS_MSG; ?>");
                        return false;
                    }
                    else
                    {
                        return true;
                    }




                }
            });


        }


    }
    function sameAsAbove(){
        var frm = document.frmCheckout;
        if(frm.chkSameAsAbove.checked==true){
            document.getElementById("divShippingAddress").style.display = "none";
        }else{
            document.getElementById("divShippingAddress").style.display = "";
        }
    }
    function checkSameAsAbove(same){
        var frm = document.frmCheckout;
        if(same == 1){
            sameAsAbove();
        }
    }
    function popupWindow(url) {
        window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=1000,height=500,screenX=150,screenY=150,top=150,left=150')
    }
    function checkShipping()
    {
        if(document.frmCheckout.shippingEnable.value == "")
        {
            if(eval(document.frmCheckout.totalShippingWeight.value) > eval(document.frmCheckout.maxShippingWeight.value))
            {
                alert('<?php echo SHIPPING_WEIGHT_MSG; ?>');
                return false;
            }
        }
    }
    function Togglecheck()
    {
        var strlen=$(".checkbox:checked").length;
        if(strlen==0)
        {
            alert("<?php echo ALERT_SHIPPING_METHOD; ?>");
            return false;
        }
        else
        {
            return true;
        }
    }
</script>

<div align="left" class="main_body">
    <!--mainbody area start -->
    <?php
    if ($ddlBillingCountry == '') {
        $ddlBillingCountry = $deafultCountry;
    }
    $enable_commentbox = getSettingsValue('enable_commentbox');
    ?>
    <form name="frmCheckout" action="<?php echo $_SERVER["PHP_SELF"] ?>" method="POST">
        <!-- The id of the country field(s).  If more than one, seperate with spaces -->
        <input type="hidden" value="shipCountrySelect billCountrySelect" name="cs_config_country_field" id="cs_config_country_field">
        <input type="hidden" value="shipStateSelect billStateSelect"     name="cs_config_state_field"   id="cs_config_state_field">
        <!-- The id of the the fields holding the default values.  If more than one, seperate with spaces -->
        <input type="hidden" value="shipCountryDefault billCountryDefault" name="cs_config_country_default" id="cs_config_country_default">
        <input type="hidden" value="shipStateDefault billStateDefault"     name="cs_config_state_default"   id="cs_config_state_default">
        <!-- The actual default values -->
        <input type="hidden" value="<?php echo $ddlBillingCountry ?>" name="shipCountryDefault" id="shipCountryDefault">
        <input type="hidden" value="<?php echo $txtBillingState; ?>"   name="shipStateDefault"   id="shipStateDefault">
        <input type="hidden" value="<?php echo $ddlBillingCountry ?>" name="billCountryDefault" id="billCountryDefault">
        <input type="hidden" value="<?php echo $txtBillingState; ?>"   name="billStateDefault"   id="billStateDefault">
        <SCRIPT type="text/javascript" SRC="js/country-state.js"></SCRIPT>
        <div align="left" id="item_details">
            <!--items display area start -->
            <div align="left" id="items_top_area">
                <div align="left" class="crthdstyles" id="items_top_area_ttl"><?php echo YOUR_CART_TEXT; ?></div>
            </div>
            <br>
            <div class="text_information" align="center"><?php echo $message ?></div>
            <div>
                <?php
                $sql_check_digital = "SELECT c.*, p.product_name,(p.product_price+po.additional_price) AS product_price,po.discount,po.product_shipping_weight,p.vdigital_product
				      FROM " . $tableprefix . "cart c
                                      INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id
                                      INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id
                                      WHERE c.user_id = '" . addslashes($_SESSION["sess_userid"]) . "'";

                $res_check_digital = mysql_query($sql_check_digital) or die(mysql_error());
                if (mysql_num_rows($res_check_digital) > 0) {
                    /* ---------Check whether cart product is digital so that shipping needs to be disabled----- */
                    while ($check_digital_row = mysql_fetch_array($res_check_digital)) {
                        if ($check_digital_row["vdigital_product"] == "Y") {
                            $shipping_block_display = "none";
                            $shipping_address_block_display = "none";
                        }
                    }
                }
                /* ------------Multicart 2.0 Upgradation------------ */
                $currency_attributes = displayCurrencyType();
                /* ------------Multicart 2.0 Upgradation------------ */

                $total = 0;
                $cartitems = "";
                $total_shipping_weight = 0;

                if ($_SESSION["sess_userid"] != '') {
                    $sql = "SELECT c.*, p.product_id,p.product_name,(p.product_price+po.additional_price) AS product_price,p.product_artist_id, gm.ngift_id,po.discount,po.product_shipping_weight,p.vdigital_product
			  FROM " . $tableprefix . "cart c
                          INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id
                          INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id
                          LEFT JOIN " . $tableprefix . "giftcoupon_master gm ON gm.ngift_product_id=c.product_id
		          WHERE  c.user_id = '" . addslashes($_SESSION["sess_userid"]) . "'
                          ";
                } else {

                    $sql = "SELECT c.*, p.product_id,p.product_name,(p.product_price+po.additional_price) AS product_price,p.product_artist_id, gm.ngift_id,po.discount,po.product_shipping_weight,p.vdigital_product
                          FROM " . $tableprefix . "cart c
                          INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id
                          INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id
                          LEFT JOIN " . $tableprefix . "giftcoupon_master gm ON gm.ngift_product_id=c.product_id
                          WHERE c.visitor_cart_id = '" . addslashes(session_id()) . "'
                          ";
                }



                $cnt = 1;
                $res = mysql_query($sql);
                if (mysql_num_rows($res) > 0) {
                    echo "<fieldset class='yourcrtstyles'><table width=\"100%\"  border=\"0\" cellspacing=\"1\" cellpadding=\"6\">";
                    echo "<tr><td width='1%' class='bgcolor_head_checkout'>&nbsp;</td><td width='55%' class='bgcolor_head_checkout'  ><b >".PRODUCT_TEXT."</b></td>
					<td width='5%' align='right' class='bgcolor_head_checkout'><b>".QUANTITY_TEXT."</b></td>
					";

                    echo "<td width='5%' class='bgcolor_head_checkout'>";

                    if ($check_shipping_enable == "Y" && $shipping_block_display != "none") {
                        echo " ".WEIGHT_TEXT." ";
                    } else {
                        echo " &nbsp; ";
                    }

                    echo "</td>";

                    echo "
					<td width='30%' align='right' class='bgcolor_head_checkout'><b>".RATE_TEXT."</b></td>
					<td width='10%' align='right' class='bgcolor_head_checkout'><b>".PRICE_TEXT."</b></td>
				</tr>
				<tr>
					<td colspan='6'><hr></td>
				</tr>";
                    while ($rw = mysql_fetch_array($res)) {
                        $productname = $rw["product_name"];
                        //$product_id  = $rw["product_id"];

                        $giftId = $rw["ngift_id"];

                        if (!empty($giftId)) {
                            $giftflag = "true";
                        } else {

                            $giftflag = "false";
                        }

                        /* ------------Multicart 2.0 Upgradation------------ */



                        $conversionRate = ConvertedCurrencyRate($currency_attributes[2]);
                        $converted_price = $rw['product_price'] * $conversionRate;

                        $rate = $converted_price;
                        /* ------------Multicart 2.0 Upgradation------------ */
                        $product_option_id = $rw["product_option_id"];
                        $qty = $rw["quantity"];
                        $price = $qty * $rate;
                        $product_weight = $qty * $rw["product_shipping_weight"];
                        $discountstr = "";
                        if ($rw["discount"] != "0") {
                            $price = number_format($price, 2, ".", "");
                            $discountprice = $rate - ($rate * $rw["discount"]) / 100;
                            $discountprice = number_format($discountprice, 2, ".", "");
                            $discountrate = ($discountprice * $qty);
                            $price = $discountrate;
                            $discountstr = "<br>".strtolower(DISCOUNT_TEXT)."(" . $rw["discount"] . "%)";
                        }
                        $optionsStr = "";
                        $optionVal = getProductOptionsName($product_option_id);
                        if ($optionVal != "") {
                            $optionsStr = "<br>" . $optionVal;
                        }
                        $total += $price;
                        $total_shipping_weight += $product_weight;

                        echo "<tr class=\"whitebg\"><td width='5%' >" . $cnt . "</td>
				<td align='left' style='word-break:break-all;'>" . ($productname) . $discountstr . $optionsStr . "</td>
				<td align='right'>" . $qty . "</td>
				";
                        echo "<td align='right'>";
                        if ($check_shipping_enable == "Y" && $shipping_block_display != "none") {
                            echo "" . $product_weight . "";
                        } else {
                            echo "&nbsp;";
                        }
                        echo "</td>";
                        echo "
				<td align='right' width='30%'>";

                        if ($rw["discount"] != "0") {
                            echo $currency_attributes[0] . "&nbsp;" . $discountprice . "&nbsp;";

                            echo " ( <strike>" . $currency_attributes[0] . "&nbsp;" . number_format($rate, 2, ".", "") . "&nbsp;" . "</strike> ) ";
                        } else {
                            echo $currency_attributes[0] . "&nbsp;" . number_format($rate, 2, ".", "") . "&nbsp;";
                        }


                        echo "<td align='right' class=\"\">" . $currency_attributes[0] . "&nbsp;" . number_format($price, 2, ".", "") . "</td></tr>";
                        $cartitems .= "," . $rw["cart_id"];

                        $cnt++;
                    }
                    $cartitems = substr($cartitems, 1);
                    
                    $_SESSION['SESS_shipping_weight'] = number_format($total_shipping_weight, 2, ".", "");
                     
                    $_SESSION['SESS_shipping_maxweight'] = $shipping_row['vvalue'];
                    echo "<tr class=\"whitebg\">
					<td align='right' colspan='5'><b><span class='product_amounthd'>".PRODUCT_TOTAL_TEXT."&nbsp;:&nbsp;</span></b>&nbsp;</td>
					<td align='right' colspan='1'><b><span class='product_amounthd'>" . $currency_attributes[0] . "&nbsp;" . number_format($total, 2, ".", "") . "</span></b></td>
				</tr>";


                    echo "<tr class=\"whitebg\"><td width='100%' colspan='6' >&nbsp;</td></tr>";
                    echo "<tr class=\"whitebg\"><td width='100%' colspan='6' align='center'>";
                    echo "<input type='hidden' value='" . $cartitems . "' name='cartitems' >&nbsp;&nbsp;";
                    echo "</td></tr>";
                } else {
                    echo "<table width=\"100%\"  border=\"0\" cellspacing=\"1\" cellpadding=\"6\">";
                    echo "<tr><td width='100%' align='center'>".CART_EMPTY_MSG."</td></tr>";
                    echo "<tr><td width='100%' ><input class='button' type='button' value='Continue Shopping' onClick='window.location.href=\"categorydetail.php\"'></td></tr>";
                }
                ?>
                </table></fieldset></td>
                </tr>

                </table>

                </td>
                </tr>
                <?php if (!isset($_SESSION["sess_addresses_collected"]) or ($_SESSION["sess_addresses_collected"] == false )) { ?>
                <tr>
                    <td colspan="3">
                        <fieldset class="billaddress_sec">
                            <legend><?php echo BILL_ADDR_TEXT; ?></legend>
                            <div class="billaddres">
                                <table width="100%" callpadding=2 cellspacing=2 border="0">
                                    <tr><td width="20%" align="left"><?php echo FIRST_NAME_TEXT; ?>&nbsp;<span class="required">*</span></td><td width="5%">&nbsp;</td><td width="75%" align="left"><input type="text" name="txtBillingFirstName" value="<?php echo $txtBillingFirstName; ?>"  class="textarea" size="40" maxlength="100" id="txtBillingFirstName"></td></tr>
                                    <tr><td align="left"><?php echo LAST_NAME_TEXT; ?></td><td align="left">&nbsp;</td><td align="left"><input type="text" name="txtBillingLastName" value="<?php echo $txtBillingLastName; ?>" size="40" maxlength="100" class="textarea" id="txtBillingLastName" ></td></tr>
                                    <tr><td align="left"><?php echo ADDR_LINE1_TEXT; ?>&nbsp;<span class="required">*</span></td><td align="left">&nbsp;</td><td align="left"><input type="text" name="txtBillingAddress1" value="<?php echo $txtBillingAddress1; ?>" size="40" class="textarea"  maxlength="100" id="txtBillingAddress1"></td></tr>
                                    <tr><td align="left"><?php echo ADDR_LINE2_TEXT; ?></td><td align="left">&nbsp;</td><td align="left"><input type="text" name="txtBillingAddress2" value="<?php echo $txtBillingAddress2; ?>" size="40" maxlength="100" class="textarea" id="txtBillingAddress2"></td></tr>
                                    <tr><td align="left"><?php echo CITY_TEXT; ?>&nbsp;<span class="required">*</span></td><td align="left">&nbsp;</td><td align="left"><input type="text" name="txtBillingCity" value="<?php echo $txtBillingCity; ?>" size="40" class="textarea"  maxlength="100" id="txtBillingCity"></td></tr>
                                    
                                    <tr><td align="left"><?php echo COUNTRY_TEXT; ?>&nbsp;<span class="required">*</span></td><td align="left">&nbsp;</td><td align="left">
                                            <select id='billCountrySelect' name='bill_country' onchange='updateState(this.id)'>
                                            </select>
                                            <SCRIPT  type="text/javascript">initCountry(); </SCRIPT>
                                        </td></tr>
                                    <tr>
                                        <td align="left"><?php echo STATE_LABEL; ?><span class="required">*</span></td>
                                        <td align="left">&nbsp;</td>
                                        <td align="left"> <select id='billStateSelect' name='bill_state'>
                                            </select></td>
                                    </tr>
                                    <tr><td align="left"><?php echo ZIP_TEXT; ?>&nbsp;<span class="required">*</span></td><td align="left">&nbsp;</td><td align="left"><input type="text" name="txtBillingZIP" value="<?php echo $txtBillingZIP; ?>" size="10" maxlength="20" class="textarea" id="txtBillingZIP"></td></tr>
                                    <tr><td align="left"><?php echo FAX_TEXT; ?></td><td align="left">&nbsp;</td><td align="left"><input type="text" name="txtBillingFAX" value="<?php echo $txtBillingFAX; ?>" size="20"  class="textarea" maxlength="30" id="txtBillingFAX"></td></tr>
                                    <tr><td align="left"><?php echo EMAIL_LABEL; ?>&nbsp;<span class="required">*</span></td><td align="left">&nbsp;</td><td align="left"><input type="text"  class="textarea" name="txtBillingEmail" value="<?php echo $txtBillingEmail; ?>" size="30" maxlength="100" id="txtBillingEmail" onblur="return verifyEmail();"></td></tr>
                                    <tr><td align="left"><?php echo PHONE_TEXT; ?><span class="required">*</span></td><td align="left">&nbsp;</td><td align="left"><input type="text" name="txtBillingPhone"  class="textarea" value="<?php echo $txtBillingPhone; ?>" size="20" maxlength="30" id="txtBillingPhone"></td></tr>
                                </table>
                                <div class="clear"></div>
                            </div>
                        </fieldset>
                    </td>
                </tr>
                <tr><td colspan="3">&nbsp;</td></tr>

                <tr>
                    <td colspan="3">
                            <?php
                            if ($hide_shipping_division == 1) {
                                ?>
                        <div class="shippinghd">
                            <legend ><?php echo SHIP_ADDR_TEXT; ?></legend>
                        </div>
                                <?php } ?>
                        <div id="shipping_address_block" class="boxborder" style="display:<?php echo $shipping_address_block_display ?>">

                            <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                <tr>
                                    <td colspan="3">
                                        <fieldset>

                                            <table width="100%" callpadding=2 cellspacing=2 border="0" class="message">
                                                <tr><td width="100%" align="left" colspan="3"><input type="checkbox" name="chkSameAsAbove" class="clscheckbox" onClick="sameAsAbove();" <?php
                                                            if ($sameshipping == 1) {
                                                                echo " CHECKED ";
                                                            }
                                                                                                         ?>>&nbsp;<?php echo SAME_AS_ABOVE_TEXT; ?></td></tr>
                                            </table>
                                            <div id="divShippingAddress">
                                                <table width="100%" callpadding=2 cellspacing=2 border="0" class="heading">
                                                    <tr><td width="20%" align="left" class="heading"><?php echo FIRST_NAME_TEXT; ?>&nbsp;<span class="required">*</span></td><td width="5%" align="left">&nbsp;</td><td width="75%" align="left"><input  class="textarea" type="text" name="txtShippingFirstName" value="<?php echo $txtShippingFirstName; ?>" size="40" maxlength="100" id="txtShippingFirstName"></td></tr>
                                                    <tr><td align="left" class="heading"><?php echo LAST_NAME_TEXT; ?></td><td align="left">&nbsp;</td><td align="left"><input  class="textarea" type="text" name="txtShippingLastName" value="<?php echo htmlentities($txtShippingLastName); ?>" size="40" maxlength="100" id="txtShippingLastName"></td></tr>
                                                    <tr><td align="left"><?php echo ADDR_LINE1_TEXT; ?>&nbsp;<span class="required">*</span></td><td align="left">&nbsp;</td><td align="left"><input type="text"  class="textarea" name="txtShippingAddress1" value="<?php echo htmlentities($txtShippingAddress1); ?>" size="40" maxlength="100" id="txtShippingAddress1"></td></tr>
                                                    <tr><td align="left"><?php echo ADDR_LINE2_TEXT; ?></td><td align="left">&nbsp;</td><td align="left"><input class="textarea" type="text" name="txtShippingAddress2" value="<?php echo htmlentities($txtShippingAddress2); ?>" size="40" maxlength="100" id="txtShippingAddress2"></td></tr>
                                                    <tr><td align="left"><?php echo CITY_TEXT; ?>&nbsp;<span class="required">*</span></td><td align="left">&nbsp;</td><td align="left"><input  class="textarea" type="text" name="txtShippingCity" value="<?php echo htmlentities($txtShippingCity); ?>" size="40" maxlength="100" id="txtShippingCity"></td></tr>
                                                    
                                                    <tr><td align="left"><?php echo COUNTRY_TEXT; ?>&nbsp;<span class="required">*</span></td><td align="left">&nbsp;</td><td align="left">
                                                            <select id='shipCountrySelect' name='ship_country' onchange='updateState(this.id)'>
                                                            </select>

                                                        </td></tr>
                                                    <tr>
                                                        <td align="left"><?php echo STATE_LABEL; ?></td>
                                                        <td align="left">&nbsp;</td>
                                                        <td align="left">   <select id='shipStateSelect' name='ship_state'>
                                                            </select></td>
                                                    </tr>

                                                    <tr><td align="left"><?php echo ZIP_TEXT; ?>&nbsp;<span class="required">*</span></td><td align="left">&nbsp;</td><td align="left"><input type="text" name="txtShippingZIP"  class="textarea" value="<?php echo $txtShippingZIP; ?>" size="10" maxlength="20" id="txtShippingZIP"></td></tr>
                                                    <tr><td align="left"><?php echo FAX_TEXT; ?></td><td align="left">&nbsp;</td><td align="left"><input type="text" name="txtShippingFAX" class="textarea"  value="<?php echo $txtShippingFAX; ?>" size="20" maxlength="30" id="txtShippingFAX"></td></tr>
                                                    <tr><td align="left"><?php echo EMAIL_LABEL; ?>&nbsp;<span class="required">*</span></td><td align="left">&nbsp;</td><td align="left"><input  class="textarea" type="text" name="txtShippingEmail" value="<?php echo $txtShippingEmail; ?>" size="30" maxlength="100" id="txtShippingEmail"></td></tr>
                                                    <tr><td align="left"><?php echo PHONE_TEXT; ?></td><td align="left">&nbsp;</td><td align="left"><input type="text" name="txtShippingPhone" class="textarea"  value="<?php echo $txtShippingPhone; ?>" size="20" maxlength="30" id="txtShippingPhone"></td></tr>
                                                </table>
                                            </div>

                                        </fieldset>
                                    </td>
                                </tr>

                            </table>

                            <input type="hidden" name="guest_login" value="<?php echo $guest_login; ?>">
                        </div>

                    </td>
                </tr>
                <SCRIPT  type="text/javascript">initCountry(); </SCRIPT>

                    <?php
                }
                if ($giftflag == "true") {
                    $shipping_block_display = "none";
                }
                ?>

                <tr>
                    <td colspan="3">

                        <?php
                        if ($_SESSION['shipping_enabled'] == "false" && $hide_shipping_division == 1) {
                            ?>
                        <table cellpadding="4" cellspacing="4" border="0" width="100%">
                            <tr><td>&nbsp;</td></tr>
                            <tr>
                                <td class="text_information" colspan="2"><h4><?php echo SHIP_METHODS_NOT_AVAILABLE_TEXT; ?></h4></td>
                            </tr>
                            <tr><td>&nbsp;</td></tr>
                        </table>
                            <?php } ?>

                        <div id="shipping_block" style="display:<?php echo $shipping_block_display ?>">

                            <fieldset>
                                <!--Shipping Block Division Starts-->
                                <legend><b><?php echo SHIP_METHODS_TEXT; ?></b></legend>


                                <div class="shippingmthd">

                                    <?php
                                    if ($_POST['shippingmode'] != '') {
                                        $shippingmode = $_POST['shippingmode'];
                                    } else if ($_SESSION["sessShippingMethod"] != '') {
                                        $shippingmode = $_SESSION["sessShippingMethod"];
                                    } else {
                                        if ($upsmode == 'Y') {
                                            $shippingmode = 'UPS';
                                        } elseif ($uspsmode == 'Y') {
                                            $shippingmode = 'USPS';
                                        } elseif ($canadapost == 'Y') {
                                            $shippingmode = 'CP';
                                        } else {
                                            $shippingmode = 'Flat Rate';
                                        }

                                        if ($txtCurrency == 'AUD') {
                                            $shippingmode = 'AP';
                                        }
                                    }
                                    ?>
                                    <table cellpadding="4" cellspacing="4" border="0" width="100%">

                                        <?php if ($upsmode != "N" && $txtCurrency != 'AUD') {
                                            ?>
                                        <tr><td><input type="radio" name="shippingmode" value="<?php echo "UPS"; ?>" <?php
                                                    if ($shippingmode == 'UPS') {
                                                        echo "checked";
                                                    }
                                                           ?> class="checkbox"><?php echo UPS_TEXT; ?></td>
                                            <td><img src="images/ups.gif" ></td>
                                        </tr>
                                            <?php } ?>
                                        <?php
                                        if ($fedexmode != "N" && $txtCurrency != 'AUD') {
                                            ?>
                                        <tr><td height="51"><input type="radio" name="shippingmode" value="FDXG" <?php
                                                    if ($shippingmode == $fedexmode) {
                                                        echo "checked";
                                                    }
                                                                       ?> class="checkbox"><?php echo $fedexShipping; ?></td>
                                            <td><img src="images/fedex.gif" width="113" height="31"></td>
                                        </tr>
                                            <?php } ?>
                                        <?php if ($uspsmode == "Y" && $txtCurrency != 'AUD') {
                                            ?>
                                        <tr><td><input type="radio" name="shippingmode" value="<?php echo "USPS"; ?>" <?php
                                                    if ($shippingmode == 'USPS') {
                                                        echo "checked";
                                                    }
                                                           ?> class="checkbox"><?php echo USPS_TEXT; ?></td>
                                            <td><img src="images/usps.gif"></td>
                                        </tr>
                                            <?php } ?>
                                        <?php if ($canadapost == "Y" && $txtCurrency != 'AUD') {
                                            ?>
                                        <tr><td><input type="radio" name="shippingmode" value="<?php echo "CP"; ?>" <?php
                                                    if ($shippingmode == 'CP') {
                                                        echo "checked";
                                                    }
                                                           ?> class="checkbox"><?php echo CANADA_POST_TEXT; ?></td>
                                            <td><img src="images/canadapost.gif"></td>
                                        </tr>
                                            <?php } ?>
                                        <?php if ($australiapost == "Y") {
                                            ?>
                                        <tr><td><input type="radio" name="shippingmode" value="<?php echo "AP"; ?>" <?php
                                                    if ($shippingmode == 'AP') {
                                                        echo "checked";
                                                    }
                                                           ?> class="checkbox"><?php echo AUSTRALIA_POST_TEXT; ?></td>
                                            <td><img src="images/australiapost.jpg"></td>
                                        </tr>
                                            <?php } ?>

                                        <?php if ($flatrate == "Y") {
                                            ?>
                                        <tr><td><input type="radio" name="shippingmode" value="<?php echo "Flat Rate"; ?>" <?php
                                                    if ($shippingmode == 'Flat Rate') {
                                                        echo "checked";
                                                    }
                                                           ?> class="checkbox"><?php echo $flatrate_name; ?>
                                            </td>
                                            <td>&nbsp; </td>
                                        </tr>
                                            <?php } ?>


                                    </table>

                                    <div class="clear"></div>
                                </div>

                            </fieldset>
                        </div>

                        <!--Shipping Block Division Ends-->

                    </td>
                </tr>

                <tr>


                    <?php if ($enable_commentbox == 'Y' && $giftflag == "false") { ?>

                <tr><td colspan="3">
                        <div class="billaddres">

                            <table cellpadding="0" cellspacing="" border="0" width="100%">
                                <tr><td>
                                        <?php echo ENTER_COMMENTS_TEXT;?> </td><td align="left"><textarea name="txtComments" cols="35" rows="5"><?php echo stripslashes($_POST['txtComments']); ?></textarea>
                                </tr></table>

                        </div>
                    </td> </tr>

                    <?php } ?>

                <td colspan="3">&nbsp;</td></tr>

                </table>

                <div align="center"><input type='submit' class="button" value='<?php echo CONFIRM_ORDER_BUTTON; ?>' name='btnConfirmOrder'  onClick="return ConfirmCheck();"></div>

            </div>


            <div align="left" class="float_clear1"></div>


            <!--items display area end -->
        </div>

    </form>
    <!--center content area end-->


    <div align="left" class="clear"></div>
    <!--mainbody area end -->
</div>
<div align="left" class="clear"></div>


<?php
include "includes/" . $active_template[2]; /* Bottom File Name */
?>



