<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts EasyCart                      |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
// +----------------------------------------------------------------------+
?>
<?php //echo $javascript->link('jquery.js'); ?>
<?php echo $javascript->link('jquery-1.8.2.js'); ?>
<?php echo $javascript->link('jquery-ui-1.9.0.custom.js'); ?>
<?php echo $javascript->link('alphanumeric.js'); ?>

<script type="text/javascript" language="javascript">
    $(function() {

        var availableTags = <?php echo html_entity_decode($userAutoItem); ?>;

        $('#userItem').autocomplete({
            source: availableTags,
            autoFocus: true,
            select: function (event, ui) {
                $('#userId').val(ui.item.id);
                $('#userEmail').val(ui.item.email);
                $('#userName').html(ui.item.value);
                $('#orderDetails').show('slow');
                $('#productDetails').show('slow');
                $('html, body').animate({scrollTop: $("#orderDetails").offset().top}, 2000);

                // Fill Billing Address

                $('#editbill_id').val(ui.item.b_id);
                $('#editbill_email').val(ui.item.b_email);
                $('#editbill_fname').val(ui.item.b_fname);
                $('#editbill_lname').val(ui.item.b_lname);
                $('#editbill_address').val(ui.item.b_address);
                $('#editbill_city').val(ui.item.b_city);
                $('#editbill_state').val(ui.item.b_state);
                $('#editbill_zip').val(ui.item.b_zip);
                $('#editbill_country').val(ui.item.b_country);
                $('#editbill_phone').val(ui.item.b_phone);
                $('#editbill_mobile').val(ui.item.b_mobile);
                $('#editbill_fax').val(ui.item.b_fax);

                // Fill Shipping Address

                $('#editship_id').val(ui.item.s_id);
                $('#editship_fname').val(ui.item.s_fname);
                $('#editship_lname').val(ui.item.s_lname);
                $('#editship_address').val(ui.item.s_address);
                $('#editship_city').val(ui.item.s_city);
                $('#editship_state').val(ui.item.s_state);
                $('#editship_zip').val(ui.item.s_zip);
                $('#editship_country').val(ui.item.s_country);
                $('#editship_phone').val(ui.item.s_phone);
                $('#editship_mobile').val(ui.item.s_mobile);
                $('#editship_fax').val(ui.item.s_fax);

                fillProduct(ui.item.id);
                popCredits(ui.item.id);

            } });

        // Hide shipping Price Total
        $('#shippingPriceTotal').hide();

        // Add Product

        $("#addProduct").click(function() {
            $('#productItem').val('');
            if($('#productItemArr').val()=='') { // no products selected

                // Error box details
                $('#errProduct').html('Please type in your preferences and choose any product to add to cart');
                $('#errProduct').show('slow');

            } else {

                var productItemArr = $('#productItemArr').val();
                var productObj = $.parseJSON($('#productItemArr').val());

                // Product type check
                // Senario : Non - digital and digital products cannot be purchased together!
                productObj.prodtype;

                var productTypeLength = $("input[name='productType[]']").length;

                var productTypeFlag = true;

                if(productTypeLength > 0){
                    $("input[name='productType[]']").each(function(i,j){
                        if(productObj.prodtype != $(j).val()){
                            productTypeFlag = false;
                        }
                    });
                } //End Product Type check

                if(productTypeFlag==true){
                    var qtyIncFlag = false;

                    var value3;
                    var itemPrefix = '';

                    // check for duplicate
                    if($("input[name='productId[]']").length > 0){

                        $("input[name='productId[]']").each(function(i,j){
                            //
                            var itemId = $(j).attr('id');
                            var namePrefix = itemId.split('pd_')[1];
                            
                            

                            if($(j).val() == productObj.id) { // if the product is already added
                                
                               
                                if( $('#option_id_'+productObj.id+''+productObj.optionId).length ) {
                                    
                                    $('#oqty_'+namePrefix+'_err').html('');
                                var value1 = parseInt($('#oqty_'+namePrefix+'_inp').val());
                                var value2 = parseInt($('#productStock_'+namePrefix).val());
                                value3 = parseInt(value1) + parseInt(1);

                                if(parseInt(value3) > parseInt(value2)){
                                    qtyIncFlag = true;
                                    $('#oqty_'+namePrefix+'_err').html('Current stock is only '+value2+' units');
                                } else {
                                    qtyIncFlag = true;
                                    itemPrefix = namePrefix;
                                    $("#oqty_"+itemPrefix).html(value3);
                                    $("#oqty_"+itemPrefix+"_inp").val(value3);
                                    
                                    calculatePrice1();

                                }
                                    
                                }
                                 
                              

                                //
                                // oqty_"+cartCount+"_E

                                // oqty_"+cartCount+"_inp
                            }

                        });

                    }

                    if(qtyIncFlag==false){


                        // Error box details
                        $('#errProduct').html('');
                        $('#errProduct').hide('slow');

                        productObj.id;
                        productObj.value;
                        productObj.pname;
                        productObj.unitPrice;
                        productObj.category_id;
                        productObj.descr;
                        productObj.combination;
                        productObj.currencySymbol;
                        productObj.priceType;
                        productObj.unitPrice;
                        productObj.additionalPrice;
                        productObj.price;
                        productObj.wholesale_price;
                        productObj.discount_type;
                        productObj.discountValue;
                        productObj.discountAmount;
                        productObj.discountPrice;
                        productObj.totalPrice;
                        productObj.stock;
                        productObj.reorderlevel;
                        productObj.skuno;
                        productObj.weight;
                        productObj.shipping_price;
                        productObj.status;
                        productObj.pdctfile;
                        productObj.prodtype;
                        productObj.optionId;
                        productObj.cname;
                        productObj.imagename;
                        productObj.default_img;
                        productObj.custom_value;
                        productObj.custom_name;
                        if(productObj.optionId=='null'){
                            productObj.put("optionId", "");
                        }
                        
                        productObj.currencySymbol = $("#currencySymbol").val();

                        $('#itemsDetails').show('slow');
                        $('html, body').animate({scrollTop: $("#itemsDetails").offset().top}, 2000);
                        //
                        $('#cartEdit').show('slow'); // cartEdit
                        $('#cartProceed').show('slow'); // cartProceed

                        var cartCount = $('#cartCount').val(); cartCount++; // increment cart item on each addition
                        $('#cartCount').val(cartCount); // set cart count

                        var skuNo = (productObj.skuno === null || productObj.skuno =='')? '-' : productObj.skuno;
                        var combination = (productObj.combination === null || productObj.combination =='')? '-' : productObj.combination;
                        var image_url   = '<?php echo FULL_BASE_URL. $cnfg["sitebasefolder"]."/app/webroot/".IMAGES_URL.'remove.gif'; ?>';
                        var trAppend = "<tr align=\"left\" valign=\"middle\" id=\"list_admin_"+cartCount+"\" class=\"list_admin\">";
                        trAppend += "<td>"+productObj.pname;
                        trAppend += "<input type=\"hidden\" name=\"productId[]\" id=\"pd_"+cartCount+"\" value=\""+productObj.id+"\">";
                        trAppend += "<input type=\"hidden\" name=\"optionId[]\" id=\"option_id_"+productObj.id+""+productObj.optionId+"\" value=\""+productObj.optionId+"\">";
                        trAppend += "<input type=\"hidden\" name=\"productStock[]\" id=\"productStock_"+cartCount+"\" value=\""+productObj.stock+"\">";
                        trAppend += "<input type=\"hidden\" name=\"productSku[]\" value=\""+productObj.skuno+"\">";
                        trAppend += "<input type=\"hidden\" name=\"productCombination[]\" value=\""+productObj.combination+"\">";
                        trAppend += "<input type=\"hidden\" name=\"productType[]\" value=\""+productObj.prodtype+"\">";
                        trAppend += "</td>";
                        trAppend += "<td align=\"center\" >"+skuNo+"</td>";
                        trAppend += "<td align=\"center\">"+combination+"</td>";
                        trAppend += "<td align=\"center\">";
                        var qtyLabelDisplay = ($("#cartSave").css("display")=='none') ? 'block' : 'none';
                        trAppend += "<label name=\"oqty[]\" id=\"oqty_"+cartCount+"\" style=\"display:"+qtyLabelDisplay+";\">1</label>";
                        var qtyInpDisplay = ($("#cartSave").css("display")=='none') ? 'none' : 'block';
                        trAppend += "<label name=\"oqtyE[]\" id=\"oqty_"+cartCount+"_E\" style=\"display:"+qtyInpDisplay+";\">";
                        trAppend += "<input type=\"text\" name=\"qty[]\" id=\"oqty_"+cartCount+"_inp\" value=\"1\" class=\"box3_admin\" size=\"4\"/>";
                        trAppend += "<input type=\"hidden\" name=\" prdAr[]\" value=\""+productItemArr+"\"/>";
                        trAppend += "</label>";
                        trAppend += "<span class=\"error_text_a\" id=\"oqty_"+cartCount+"_err\"></span>";
                        trAppend += "</td>";
                        trAppend += "<td align=\"center\">";
                        trAppend += productObj.currencySymbol+' '+productObj.unitPrice;
                        trAppend += "<input type=\"hidden\" name=\"uPrice[]\" value=\""+productObj.unitPrice+"\"/>";
                        trAppend += "<input type=\"hidden\" name=\"priceType[]\" value=\""+productObj.priceType+"\"/>";
                        trAppend += "</td>";
                        trAppend += "<td align=\"center\">";
                        trAppend += productObj.currencySymbol+' '+productObj.additionalPrice;
                        trAppend += "<input type=\"hidden\" name=\"aPrice[]\" value=\""+productObj.additionalPrice+"\"/>";
                        trAppend += "</td>";
                        trAppend += "<td align=\"center\">";
                        trAppend += productObj.currencySymbol+' '+productObj.discountAmount;
                        trAppend += "<input type=\"hidden\" name=\"dPrice[]\" value=\""+productObj.discountAmount+"\"/>";
                        trAppend += "<input type=\"hidden\" name=\"dValue[]\" value=\""+productObj.discountValue+"\"/>";
                        trAppend += "<input type=\"hidden\" name=\"dType[]\" value=\""+productObj.discount_type+"\"/>";
                        trAppend += "</td>";
                        trAppend += "<td align=\"center\">";
                        trAppend += productObj.currencySymbol+" <span id=\"totalPriceProduct_"+cartCount+"\">"+productObj.totalPrice+"</span>";
                        trAppend += "<input type=\"hidden\" name=\"tPrice[]\" value=\""+productObj.totalPrice+"\"/>";
                        trAppend += "<input type=\"hidden\" name=\"sWeight[]\" value=\""+productObj.weight+"\"/>";
                        trAppend += "<input type=\"hidden\" name=\"shipPrice[]\" value=\""+productObj.shipping_price+"\"/>";
                        trAppend += "</td>";
                        trAppend += "<td align=\"center\" class=\"droplink\"><a href=\"javascript:void(0);\" onclick=\"dropItem('"+cartCount+"')\"><img src=\""+image_url+"\" width=\"15\" height=\"15\" border=\"0\" title=\"Remove Item\" alt=\"\" /></a></td>";
                        trAppend += "</tr>";

                        $('#cartDetails tr:last').before(trAppend);
                        $('#orderProductType').val(productObj.prodtype);

                        // Update Total Price
                        calculatePrice1();
                    } // end add quantity
                }  else {
                    // Error box details
                    $('#errProduct').html('Products of type Non-digital and digital cannot be purchased together!');
                    $('#errProduct').show('slow');

                }

                $('#productItemArr').val('');



            } // End If

        });
        //shipping method on change
        $('#shipmeth').change(function() {
            $('#sOptions').html('');
            doshipping();
        });


        //promocode check
        /**/
        $("#promoCode").keyup(function (event)
        {
            var self = this;
            if (self.timer)
                clearTimeout(self.timer);

            self.timer = setTimeout(function ()
            {
                self.timer = null;
                // do ajax call
                var codeN = $('#promoCode').val();
                var priceN = $('#totalPrice').val();
                var currencySymbol = $('#currencySymbol').val();
                var rootUrl ='<?php echo FULL_BASE_URL.$cnfg["sitebasefolder"]; ?>/Orders/promocodecheck';
                $('#errorPromoCode').html('');
                if(codeN!=''){
                    // Calculate Promocode Discount
                    $.ajax({
                        type: "POST",
                        url: rootUrl,
                        dataType:"json",
                        data: {code:codeN, price:priceN}
                    }).success(function( obj ) {
                        // Expected res {"flag":0,"discount":"0.00","errorMsg":"Invalid Promo Code"}
                        obj.flag;
                        obj.discount;
                        obj.errorMsg;

                        // promoCodeDiscount / totalDiscount

                        var discount = parseFloat(obj.discount);
                        var discountFixed = discount.toFixed(2);
                        $('#promoCodeDiscount').html(currencySymbol+' '+discountFixed);
                        $('#totalDiscount').val(discountFixed);
                        doTaxation();
                        calculategrandTotal();

                        if(obj.flag!=1){
                            // error
                            $('#errorPromoCode').html(obj.errorMsg);
                        } //End If


                    });
                } else {
                    $('#promoCodeDiscount').html(currencySymbol+' '+'0.00');
                    $('#totalDiscount').val('0.00');
                    doTaxation();
                    calculategrandTotal();
                }
                // end
            }, 1000);

        });
        /**/

        /**/

        /**/


        // Cart Save Quantity
        $("#cartSave").click(function() {
            var flgItem = true;
            $("input[name='qty[]']").each(function(i, j){
                var itemId = $(j).attr('id');

                var namePrefix = itemId.split('_inp')[0];
                var namePrefix1 = namePrefix.split('oqty_')[1];

                //alert('Input Value '+$(j).val()+' Available stock '+$('#productStock_'+namePrefix1).val());
                var value1 = parseInt($(j).val());
                var value2 = parseInt($('#productStock_'+namePrefix1).val());

                $('#'+namePrefix+'_err').html('');
                if($(j).val() < 1 || isNaN($(j).val())){

                    flgItem = false;
                    $(j).val('1'); // either we can pre set the value as 1
                    $('#'+namePrefix+'_err').html('Invalid Quantity');

                } else if(parseInt(value1) > parseInt(value2)){

                    flgItem = false;
                    $(j).val(value2);
                    $('#'+namePrefix+'_err').html('Current stock is only '+value2+' units');

                }
            }); // End If

            if(flgItem){
                $("label[name='oqty[]']").each(function(i,j){
                    var itemId = $(j).attr('id');
                    $(j).html($('#'+itemId+'_inp').val());
                    $(j).show();
                });

                $("input[name='qty[]']").each(function(i,j){
                    $(j).hide();
                });

                $('#cartEdit').show();
                $('#cartSave').hide();
                
                calculatePrice1();

            } // End If
        });


        // Cart Proceed
        $('#cartProceed').click(function() {
            // Proceed to Billing details
            $('#billingDetails').show('slow');
            $('html, body').animate({scrollTop: $("#billingDetails").offset().top}, 2000);

            // Disable cart proceed button
            $('#cartProceed').attr("disabled", "disabled");
            $('#cartProceed').removeClass('buttn_admin');
            $('#cartProceed').addClass('buttn_admin2');

            // Disable add product button
            $("#addProduct").attr("disabled", "disabled");
            $("#addProduct").removeClass('buttn_admin');
            $("#addProduct").addClass('buttn_admin2');

            //Disable Edit Button
            $("#cartEdit").attr("disabled", "disabled");
            $("#cartEdit").removeClass('buttn_admin');
            $("#cartEdit").addClass('buttn_admin2');

            //Disable Save Button
            $("#cartSave").attr("disabled", "disabled");
            $("#cartSave").removeClass('buttn_admin');
            $("#cartSave").addClass('buttn_admin2');
        });

        // Billing Proceed
        $('#billingProceed').click(function() {
            // Save Billing Address and Proceed to Final Process  - Promocode and Remarks if purchase is for Digital Products
            // else Proceed to Shipping
            var validate = chkBillAdd();
            if(validate==true) {
            // Save Billing Address
            saveAddressInfo('Billing');


            var orderProductType = $('#orderProductType').val();

            if(orderProductType=='Digital'){
                // proceed to Pricing
                // priceDetails
                calculatePrice1();
                doTaxation();
                calculategrandTotal();
                $('#shippingPriceTotal').hide(); // Hide shipping Price Total
                $('#priceDetails').show('slow'); // Show Pricing Tab
                $('#remarksInfo').show('slow'); // Show Remarks Tab
                $('html, body').animate({scrollTop: $("#priceDetails").offset().top}, 2000);


            } else{
                $('#shippingDetails').show('slow');
                $('html, body').animate({scrollTop: $("#shippingDetails").offset().top}, 2000);
                $('#billingProceed').attr("disabled", "disabled");
                $('#billingProceed').removeClass('buttn_admin');
                $('#billingProceed').addClass('buttn_admin2');
            }
            }
        });

        // Shipping Proceed  click further
        $('#shippingProceed').click(function() {
            var validation = chkShipAdd();
            if(validation==true){
           // Save Address Info
            saveAddressInfo('Shipping');

            // Populate shipping methods
            doshipping();

            $('#shippingMethod').show('slow');
            $('html, body').animate({scrollTop: $("#shippingMethod").offset().top}, 2000);
            $('#shippingProceed').attr("disabled", "disabled");
            $('#shippingProceed').removeClass('buttn_admin');
            $('#shippingProceed').addClass('buttn_admin2');

            /*
             */
            $('#shippingMethodProceed').attr("disabled", "disabled");
            $('#shippingMethodProceed').removeClass('buttn_admin');
            $('#shippingMethodProceed').addClass('buttn_admin2');
        }

        });

        // Shipping Method Proceed  click further
        $('#shippingMethodProceed').click(function() {


            var shipmentProcessFlag = true;

            // shippmentCheck
            if($('#shippmentCheck').val()==0){
                shipmentProcessFlag = false;
            }

            if(shipmentProcessFlag==true) {
                // priceDetails
                calculatePrice1();
                doshipcostUpdate();
                doTaxation();
                               
                calculategrandTotal();
                              
                $('#shippingPriceTotal').show(); // Hide shipping Price Total
                $('#priceDetails').show('slow'); // Show Pricing Tab
                $('#remarksInfo').show('slow'); // Show Remarks Tab
                $('html, body').animate({scrollTop: $("#priceDetails").offset().top}, 2000);
                $('#shippingMethodProceed').attr("disabled", "disabled");
                $('#shippingMethodProceed').removeClass('buttn_admin');
                $('#shippingMethodProceed').addClass('buttn_admin2');

            } else {
                // Falsh Error Message
                // Cannot proceed further without shipping method
                $('shipMethod_err').html('Please enable any shipment method to proceed further');
            }

        });

        $("#extraBill").click(function() {
            var currencySymbol = $('#currencySymbol').val();

            var trAppend = "<tr align=\"left\" valign=\"middle\" class=\"list_admin taxationTab\">";
            trAppend += "<td>Specials</td>";
            trAppend += "<td>";
            trAppend += "<input type=\"text\" name=\"extraBillDetail[]\" class=\"box2_admin\" value=\"\" />&nbsp;Note <input type=\"text\" name=\"extraBillCost[]\" onkeyup=\"specialPriceUpdate()\" class=\"box3_admin\" maxlength=\"5\" value=\"\" />&nbsp;"+currencySymbol+"&nbsp;Cost";
            trAppend += "</td>";

            $('#promocodeTab').before(trAppend);

        });

    });

    function fillProduct(userID){

        var rootUrl ='<?php echo FULL_BASE_URL.$cnfg["sitebasefolder"]; ?>/Orders/productfill';
        $.ajax({
            type: "POST",
            url: rootUrl,
            dataType:"json",
            data: {userid: userID}
        }).success(function( msg ) {
            //alert(msg);
            var availablePdTags = msg;

            $('#productItem').autocomplete({
                source: availablePdTags,
                select: function (event, ui) {
                    var item = ui.item.itemArr;
                    //alert(item);
                    $('#productItemArr').val(item);
                } });
        });

    } // End Function

    function editQty() {
        $('#cartEdit').hide();
        $('#cartSave').show();

        $("label[name='oqty[]']").each(function(i, j){

            var qtyItemId = $(j).attr('id');
            $('#'+qtyItemId).hide();
            $('#'+qtyItemId+'_E').show();
            $('#'+qtyItemId+'_inp').show();
            
            calculatePrice1();
            

        });

    }

    function dropItem(itemPostfix){
        
        if($("#cartProceed").is(":disabled")) { 
           // Do not proceed further if moved to further step
        } else {
      
        var confm = confirm("Are you sure you want to delete the item from the cart ?");
        if(confm==true) {
            $('#list_admin_'+itemPostfix).hide('slow', function(){ $('#list_admin_'+itemPostfix).remove(); });

            var childCount = ($('#list_admin_bottom').get(0).rowIndex - $('#list_admin_top').get(0).rowIndex) - 1;
            childCount -=1;

            if(childCount==0){
                $('#cartEdit').hide('slow'); // cartEdit
                $('#cartSave').hide('slow'); // cartSave
                $('#cartProceed').hide('slow'); // cartProceed
                $('#orderProductType').val(''); // product order type
            }

        }
            }
    } // End Function

    function doflatshipping(){
        var flatShippingFirst = $('#flatShippingFirst').val();
        var flatShippingAdditional = $('#flatShippingAdditional').val();
        var shippingPrice = 0;

        //shipPrice
        var counter = 1;

        $("input[name='shipPrice[]']").each(function(i,j){
            if(counter==1){

                if($(j).val()>0) {
                    shippingPrice = parseFloat(shippingPrice) + parseFloat($(j).val());
                } else {
                    shippingPrice = parseFloat(shippingPrice) + parseFloat(flatShippingFirst);
                }


            } else {

                if($(j).val()>0) {
                    shippingPrice = parseFloat(shippingPrice) + parseFloat($(j).val());
                } else {
                    shippingPrice = parseFloat(shippingPrice) + parseFloat(flatShippingAdditional);
                }
            }
            counter++;
        });

        var shippingPriceFixed = shippingPrice.toFixed(2);
        $('#shippingAmount').val(shippingPriceFixed);
    }

    function getShipWeight() {

        var shippingWeight = 0;

        $("input[name='sWeight[]']").each(function(i,j){
            shippingWeight = parseFloat(shippingWeight) + parseFloat($(j).val());
        });

        var shippingWeightFixed = shippingWeight.toFixed(2);

        $('#shippingWeight').val(shippingWeightFixed);

    } // End Function

    function getQuantity() {
        var quantity = 0;

        $("input[name='qty[]']").each(function(i,j){
            quantity = parseInt(quantity) + parseInt($(j).val());
        });

        quantity = parseInt(quantity);
        return quantity;
    } // End Function

    function doshipping(){


        // Update shipping weight
        getShipWeight();

        // Update flat shipping
        doflatshipping();

        //Quantity
        var quantity = getQuantity();

        if($('#shippmentCheck').val()!=0){

            var user = $('#userId').val();
            var shipmeth = $('#shipmeth').val();
            var weight = $('#shippingWeight').val();
            var charge = $('#shippingAmount').val();
            var prodtype = $('#orderProductType').val();


            var rootUrl = '<?php echo FULL_BASE_URL.$cnfg["sitebasefolder"]; ?>/Orders/doshippingcalculation';
            $.ajax({
                type: "POST",
                url: rootUrl,
                dataType:"json",
                beforeSend: function() {
                    $('#sOptions').addClass('loader_on');
                    $('#shippingMethodProceed').attr("disabled", "disabled");
                    $('#shippingMethodProceed').removeClass('buttn_admin');
                    $('#shippingMethodProceed').addClass('buttn_admin2');
                },
                data: {user : user, shipmeth : shipmeth, weight : weight, charge : charge, qty : quantity, prodtype : prodtype}
            }).success(function( obj ) {
                $('#sOptions').removeClass('loader_on');
                $('#shippingMethodProceed').removeAttr("disabled", "disabled");
                $('#shippingMethodProceed').removeClass('buttn_admin2');
                $('#shippingMethodProceed').addClass('buttn_admin');
                // Expected Result Example
                // {"shipoption":[{"title":"Flat Rate Shipping4","cost":5}],"first_item":"5","additional_item":"4","pshipchrg":5,"shipflag":"no","shipmeth":"Canadapost"}

                var currencySymbol = $('#currencySymbol').val();

                // First Item
                obj.first_item;
                // Additional Item
                obj.additional_item;
                // Shipping Price
                obj.pshipchrg;
                // Shipping Flag
                obj.shipflag;
                // Shipping Method
                obj.shipmeth;
                
                
                var message = '';

                if(obj.shipflag=='no') {
                    message += "<span class=\"error_text\">Sorry, there is no shipping service available to the address you provided.</span><br/>";
                    if(obj.shipoption){
                        message += "Shipping charge for first item will be "+currencySymbol+" "+obj.first_item+" and for each additional item it will charge "+currencySymbol+" "+obj.additional_item+"<br />";
                    }
                }

                var trAppend = '';

                //trAppend += "<tr>";
                //trAppend += "<td>Shipping Options</td>";
                //trAppend += "<td>";
                trAppend += message;

                // Shipping Options
                if(obj.shipoption){
                    var optionCounter = 1;
                    $.each(obj.shipoption, function(i, object) {
                        //alert(object.title + "=" + object.cost);
                        var optionValue = '';
                        optionValue = obj.shipmeth+'|~@~|'+object.title+'|~@~|'+object.cost;
                        var optionLabel = '';
                        optionLabel = object.title + ' (' +currencySymbol+' '+object.cost+ ')';

                        var append= "";

                        append += (optionCounter==1) ? " checked=\"checked\"" : "";

                        trAppend += "<input type=\"radio\" name=\"ship_method\" value=\""+optionValue+"\""+append+"> "+optionLabel;

                        optionCounter++;
                    });
                } // End shipping option

                //trAppend += "</td>";
                //trAppend += "</tr>";

                //$('#shipMethodOptions tr:last').before(trAppend);

                //sOptions

                //Place Shipping Options
                $('#sOptions').html(trAppend);

                // loader_off

            });
        }
    } // End Function

    function saveAddressInfo(type) {

        // save Billing details / Shipping Details

        //var id = (type=='Billing') ? $('#editbill_id').val() : $('#editship_id').val();

        var user_id = $('#userId').val();
        var addr_type = (type=='Billing') ? "Billing" : "Shipping";
        var fname = (type=='Billing') ? $('#editbill_fname').val() : $('#editship_fname').val();
        var lname = (type=='Billing') ? $('#editbill_lname').val() : $('#editship_lname').val() ;
        var address = (type=='Billing') ? $('#editbill_address').val() : $('#editship_address').val();
        var city = (type=='Billing') ? $('#editbill_city').val() : $('#editship_city').val();
        var state = (type=='Billing') ? $('#editbill_state').val() : $('#editship_state').val();
        var zip = (type=='Billing') ? $('#editbill_zip').val() : $('#editship_zip').val();
        var country = (type=='Billing') ? $('#editbill_country').val() : $('#editship_country').val();
        var phone = (type=='Billing') ? $('#editbill_phone').val() : $('#editship_phone').val();
        var mobile = (type=='Billing') ? $('#editbill_mobile').val() : $('#editship_mobile').val();
        var fax = (type=='Billing') ? $('#editbill_fax').val() : $('#editship_fax').val();

        var rootUrl = '<?php echo FULL_BASE_URL.$cnfg["sitebasefolder"]; ?>/Orders/saveaddress';

        $.ajax({
            type: "POST",
            url: rootUrl,
            dataType:"json",
            data: {user_id : user_id, addr_type : addr_type, fname : fname, lname : lname, address : address,city : city, state : state, zip: zip, country : country, phone : phone,mobile : mobile, fax : fax}
        }).success(function( msg ) {
            //alert(msg);

        });

    }

    function doTaxation(){

        var rootUrl = '<?php echo FULL_BASE_URL.$cnfg["sitebasefolder"]; ?>/Orders/dotaxation';

        // price / shipping / user / prdtype

        /* optionValue = obj.shipmeth+'|~@~|'+object.title+'|~@~|'+object.cost; */

        //Shipping Option
        //shipOptionMethod / shipOptionTitle / shipOptionCost
        var shippingmethod = $('#shipOptionMethod').val();
        var shippingtitle = $('#shipOptionTitle').val();
        var shippingcost = $('#shipOptionCost').val();

        // Price
        var priceN = $('#totalPrice').val();

        var extraBill = $('#extraBillAmount').val();

        priceN = parseFloat(priceN) + parseFloat(extraBill);

        var discount = $('#totalDiscount').val();

        priceN = parseFloat(priceN) - parseFloat(discount);

        //User
        var userN = $('#userId').val();

        var prdtypeN = $('#orderProductType').val();

        $.ajax({
            type: "POST",
            url: rootUrl,
            dataType:"json",
            data: {price:priceN, shipping:shippingcost, user:userN, prdtype: prdtypeN}
        }).success(function(obj) {
            // Expected Results
            obj.taxPercent;
            obj.taxName;
            obj.taxAmount;

            var currencySymbol = $('#currencySymbol').val();
            var taxAmount = parseFloat(obj.taxAmount);
            var taxAmountFixed = taxAmount.toFixed(2);

            $('#taxName').html(obj.taxName);
            $('#taxOptionName').val(obj.taxName);

            $('#taxAmount').html(currencySymbol+' '+taxAmountFixed);
            $('#totalTax').val(taxAmountFixed);
           
            calculategrandTotal();
            
        });
    } // End Function

    function doshipcostUpdate(){
        //Shipping Option
        var shipOption = $("input[name='ship_method']:checked").val();
        var shippingmethod = shipOption.split('|~@~|')[0];
        var shippingtitle = shipOption.split('|~@~|')[1];
        var shippingcost = shipOption.split('|~@~|')[2];
        shippingcost = parseFloat(shippingcost);

        var currencySymbol = $('#currencySymbol').val();
        var shippingcostFixed = shippingcost.toFixed(2);

        //shipOptionMethod / shipOptionTitle / shipOptionCost
        $('#shipOptionMethod').val(shippingmethod);
        $('#shipOptionTitle').val(shippingtitle);
        $('#shipOptionCost').val(shippingcostFixed);
        $('#shipAmount').html(currencySymbol+' '+shippingcostFixed);
        $('#shipMethod').html(shippingmethod);


    }

    function calculatePrice(){
        // Calculate Price

        //Currency symbol
        var currencySymbol = $('#currencySymbol').val();

        var totalPrice = 0;

        $("input[name='tPrice[]']").each(function(i,j){
            totalPrice = parseFloat(totalPrice)+ parseFloat($(j).val());
        });

        var totalPriceFixed = totalPrice.toFixed(2);

        $('#totalPriceSub').html(currencySymbol+' '+totalPriceFixed);
        $('#totalPrice').val(totalPriceFixed);

    } // End Function
    
     function calculatePrice1(){
        // Calculate Price

        //Currency symbol
        var currencySymbol = $('#currencySymbol').val();

        var totalPrice = 0;

        $("input[name='tPrice[]']").each(function(i,j){
            var total = 0;
            total = parseFloat(total)+ parseFloat($(j).val());
            
            $("input[name='qty[]']").each(function(k,l){
                 var id = parseInt(k)+parseInt(1);
                    if(k==i){
                        var quantity = parseInt($(l).val());
                       // alert(quantity);
                         total = parseFloat(total)* parseFloat($(l).val());
                         totalPrice = parseFloat(totalPrice)+ parseFloat(total);
                         $("#totalPriceProduct_"+id).html(total.toFixed(2));
                       
                   }
                
             });
            //var quanity = $('#oqty_'+j).val();
            //totalPrice = parseFloat(totalPrice)*parseFloat();
        });
        //alert(totalPrice);

        var totalPriceFixed = totalPrice.toFixed(2);

        $('#totalPriceSub').html(currencySymbol+' '+totalPriceFixed);
        $('#totalPrice').val(totalPriceFixed);

    } // End Function

    function calculategrandTotal(){
        // calculate grand total
        var totalPrice = $('#totalPrice').val();
        var totalTax = $('#totalTax').val();
        var shipOptionCost = $('#shipOptionCost').val();
        var discount = $('#totalDiscount').val();
        var extraBill = $('#extraBillAmount').val();

        var msg = totalPrice+' '+totalTax+' '+shipOptionCost;
        //alert(msg);
        
        // totalPrice / totalTax / shipOptionCost / totalTax

        var currencySymbol = $('#currencySymbol').val();
        var grandTotal = parseFloat(totalPrice) + parseFloat(extraBill) + parseFloat(totalTax) + parseFloat(shipOptionCost) - parseFloat(discount);
        var grandTotalFixed = grandTotal.toFixed(2);

        $('#grandTot').html(currencySymbol+' '+grandTotalFixed);
        $('#grandTotal').val(grandTotalFixed);

    }

    function specialPriceUpdate(){
        var self = this;
        if (self.timer)
            clearTimeout(self.timer);

        self.timer = setTimeout(function ()
        {
            self.timer = null;
            // do special cost calculations
            var extraCost =0;
            $("input[name='extraBillCost[]']").each(function(i,j){
                // Pricing details
                if($(j).val()!='') {
                    if(isNaN($(j).val())){
                        $(j).val('0.00');
                    } else {
                        extraCost = parseFloat(extraCost) + parseFloat($(j).val());
                    }
                }
            });

            var extraCostFixed = extraCost.toFixed(2);
            // extraBillAmount
            $('#extraBillAmount').val(extraCostFixed);
            doTaxation();
            calculategrandTotal();
            // end
        }, 1000);
    }

    function popCredits(userId){
        //
        //Currency symbol
        var currencySymbol = $('#currencySymbol').val();

        var rootUrl = '<?php echo FULL_BASE_URL.$cnfg["sitebasefolder"]; ?>/Orders/getusercredit';

        $.ajax({
            type: "POST",
            url: rootUrl,
            dataType:"json",
            data: {user_id : userId}
        }).success(function( balcredits ) {
            //alert(msg);
            var balanceCreditsFixed = parseFloat(balcredits).toFixed(2);
            var grandTotal = $('#grandTotal').val();
            var usage = (parseFloat(balcredits) >= parseFloat(grandTotal)) ? 'Y' : '';
            $('#creditBal').html(currencySymbol+' '+balanceCreditsFixed);

            $('#creditBalance').val(balanceCreditsFixed);

            if(usage='Y') {

                var appendUsage = '';
                appendUsage += "<a href=\"javascript:void(0)\" id=\"useCredit\" onclick=\"doCreditUsage()\">Use Credits</a>";
                $('#creditUsage').show('slow');
                $('#creditUsage').html(appendUsage);
            }

        });

    } // End Function

    function doCreditUsage() {

        var grandTotal = $('#grandTotal').val();
        var balanceCredit = $('#creditBalance').val();
        var usage = (parseFloat(balanceCredit) >= parseFloat(grandTotal)) ? 'Y' : '';
        $('#credits').val(usage);
        var appendUsage = '';
        appendUsage += "<a href=\"javascript:void(0)\" id=\"useCredit\" onclick=\"redoCreditUsage()\">Redo Credit usage</a>";
        $('#creditUsage').html(appendUsage);

    } // Enad function

    function redoCreditUsage() {
        $('#credits').val('');
        var appendUsage = '';
        appendUsage += "<a href=\"javascript:void(0)\" id=\"useCredit\" onclick=\"doCreditUsage()\">Use Credits</a>";
        $('#creditUsage').html(appendUsage);

    } // End Function

    function chkBillAdd(){
        var errorstr = '';
        var msgstr = "";
        var error = 0;
        var illegalChars = /[_()+]/;  /* For Password validtion*/
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;   /* For Email Address*/
        
      
	if ($.trim($('#editbill_email').val()) == '') { fillMessage('#editbill_email_err', 'Please enter  Email Address.'); error=1; } else { fillMessage('#editbill_email_err','');  }
	if ($.trim($('#editbill_email').val())!='')
	{
            if(reg.test($.trim($('#editbill_email').val())) == false) {  fillMessage('#editbill_email_err', 'Invalid Email Address.'); } else { fillMessage('#editbill_email_err',''); }
	}

        if ($('#editbill_fname').val()== "") { fillMessage('#editbill_fname_err', 'Please enter First name.'); error=1; } else { fillMessage('#editbill_fname_err', ''); }

        if($.trim($('#editbill_fname').val()) != "")
        {
            if(chkname($('#editbill_fname').val())==false) { fillMessage('#editbill_fname_err', 'First name should contain only characters.'); error=1; } else { fillMessage('#editbill_fname_err', ''); }
        }
        
        if($.trim($('#editbill_lname').val()) != "")
        {
            if(chkname($('#editbill_lname').val())==false) { fillMessage('#editbill_lname_err', 'Last name should contain only characters.'); error=1; } else { fillMessage('#editbill_lname_err', ''); }
        }
        
        if ($('#editbill_address').val()=="") { fillMessage('#editbill_address_err', 'Please enter Address.'); error=1; } else { fillMessage('#editbill_address_err', ''); }
        
        if ($('#editbill_country').val() == "") { fillMessage('#editbill_country_err', 'Please select Country.'); error=1; } else { fillMessage('#editbill_country_err', ''); }
       
        if ($('#editbill_zip').val() == "") { fillMessage('#editbill_zip_err','Please enter Zip Code.'); error = 1; } else { fillMessage('#editbill_zip',''); }
       
        var zipval=$('#editbill_zip').val();
        
        if($.trim($('#editbill_country').val()) == 'US')
        {
            if(isNaN(zipval)){ fillMessage('#editbill_zip_err','Zip code should contain only numbers.'); error = 1; } else { fillMessage('#editbill_zip_err',''); }
            
            if(zipval.length < 5 || zipval.length > 5 ) {  fillMessage('#editbill_zip_err','Zip code should contain 5 numeric digits.'); error = 1; } else { fillMessage('#editbill_zip_err',''); }
        }
        if($.trim($('#editbill_country').val()) != 'US')
        {
            if($.trim($('#editbill_state').val()) == "") { fillMessage('#editbill_state_err','Please enter State name.'); error=1; } else { fillMessage('#editbill_state_err',''); }
        }
        var phone = $('#editbill_phone').val();
        if($.trim($('#editbill_phone').val()) != "")
        {
            if(verify(phone)==false) { fillMessage('#editbill_phone_err','Phone number should contain only numbers, spaces, (, ), - and + symbols') } else { fillMessage('#editbill_phone_err',''); }
        }
        var mobile = $('#editbill_mobile').val();
        if($.trim($('#editbill_mobile').val()) != "")
        {
            if(verify(mobile)==false){ fillMessage('#editbill_mobile_err','Mobile number should contain only numbers, spaces, (, ), - and + symbols'); } else { fillMessage('#editbill_mobile_err',''); }
        }

        var fax=$('#editbill_fax').val();
        
        if($.trim($('#editbill_fax').val()) != "") //
        {
            if(verify(fax)==false) { fillMessage('#editbill_fax_err','Fax number should contain only numbers, spaces, (, ), - and + symbols'); } else { fillMessage('#editbill_fax_err',''); }
        }


        if (error==1)
        {          
            return false;
        }
        else
        {
            return true;
        }
    } // End Function

        function chkShipAdd(){
        var errorstr = '';
        var msgstr = "";
        var error = 0;
        var illegalChars = /[_()+]/;  /* For Password validtion*/
        
        if ($('#editship_fname').val()== "") { fillMessage('#editship_fname_err', 'Please enter First name.'); error=1; } else { fillMessage('#editship_fname_err', ''); }

        if($.trim($('#editship_fname').val()) != "")
        {
            if(chkname($('#editship_fname').val())==false) { fillMessage('#editship_fname_err', 'First name should contain only characters.'); error=1; } else { fillMessage('#editship_fname_err', ''); }
        }

        if($.trim($('#editship_lname').val()) != "")
        {
            if(chkname($('#editship_lname').val())==false) { fillMessage('#editship_lname_err', 'Last name should contain only characters.'); error=1; } else { fillMessage('#editship_lname_err', ''); }
        }

        if ($('#editship_address').val()=="") { fillMessage('#editship_address_err', 'Please enter Address.'); error=1; } else { fillMessage('#editship_address_err', ''); }

        if ($('#editship_country').val() == "") { fillMessage('#editship_country_err', 'Please select Country.'); error=1; } else { fillMessage('#editship_country_err', ''); }

        if ($('#editship_zip').val() == "") { fillMessage('#editship_zip_err','Please enter Zip Code.'); error = 1; } else { fillMessage('#editship_zip',''); }

        var zipval=$('#editship_zip').val();

        if($.trim($('#editship_country').val()) == 'US')
        {
            if(isNaN(zipval)){ fillMessage('#editship_zip_err','Zip code should contain only numbers.'); error = 1; } else { fillMessage('#editship_zip_err',''); }

            if(zipval.length < 5 || zipval.length > 5 ) {  fillMessage('#editship_zip_err','Zip code should contain 5 numeric digits.'); error = 1; } else { fillMessage('#editship_zip_err',''); }
        }
        if($.trim($('#editship_country').val()) != 'US')
        {
            if($.trim($('#editship_state').val()) == "") { fillMessage('#editship_state_err','Please enter State name.'); error=1; } else { fillMessage('#editship_state_err',''); }
        }
        var phone = $('#editship_phone').val();
        if($.trim($('#editship_phone').val()) != "")
        {
            if(verify(phone)==false) { fillMessage('#editship_phone_err','Phone number should contain only numbers, spaces, (, ), - and + symbols') } else { fillMessage('#editship_phone_err',''); }
        }
        var mobile = $('#editship_mobile').val();
        if($.trim($('#editship_mobile').val()) != "")
        {
            if(verify(mobile)==false){ fillMessage('#editship_mobile_err','Mobile number should contain only numbers, spaces, (, ), - and + symbols'); } else { fillMessage('#editship_mobile_err',''); }
        }

        var fax=$('#editship_fax').val();

        if($.trim($('#editship_fax').val()) != "") //
        {
            if(verify(fax)==false) { fillMessage('#editship_fax_err','Fax number should contain only numbers, spaces, (, ), - and + symbols'); } else { fillMessage('#editship_fax_err',''); }
        }


        if (error==1)
        {
            return false;
        }
        else
        {
            return true;
        }
    } // End Function

    function fillMessage(itemId, message){
        $(itemId).html(message);
    } // End Function

    function chkname(str)
    {
        return /^[A-Za-z\s]{1,}$/.test(str);
    }
    function verify(str)
    {
        return /^[0-9\-\s\)\(\+]{1,}$/.test(str);
    }

</script>
<script language="javascript" type="text/javascript">
    function submi(){
        document.sts.submit();
    }
</script>

<div align="center" class="subheading">
    <div align="left">ORDER DETAILS</div>
</div>
<br />
<form name="frmPlaceOrder" action="" method="POST">
    <div align="left" id="item_details_admin">
        <?php if($session->check('Message.flash')) { ?><div id="okbox"><font color="#446423"><?php $session->flash(); ?></font></div><?php } ?>
        <!--items display area start -->
        <!-- *************************** User Details area start *******************  -->
        <div id="userDetails">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" id="user_display_area_admin_table">
                <tr>
                    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td class="boxtopheader">User Details </td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                            <tr align="left" valign="middle" id="list_admin_top">
                                <td width="48%">Type in username and select from dropdown</td>
                                <td><input type="text" name="userItem" id="userItem" class="box2_admin" value="" />
                                    <input type="hidden" name="userId" id="userId" value="" />
                                </td>
                            </tr>
                            <tr align="left" valign="middle" id="list_admin_top">
                                <td width="48%">User Email</td>
                                <td><input type="text" name="userEmail" value="" id="userEmail" class="box2_admin" readonly="readonly"></td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="admin_bottom">
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table></td>
                </tr>
            </table>
            <br/></div>
        <!-- *************************** Order Details area *******************  -->
        <div id="orderDetails" style="display: none;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
                <tr>
                    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td class="boxtopheader">Order Details </td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                            <tr align="left" valign="middle" id="list_admin_top">
                                <td width="48%">Order Status </td>
                                <td width="15%">Order Date</td>
                                <td width="24%">User Name</td>
                                <td width="13%" align="center">Currency</td>
                            </tr>
                            <tr align="left" valign="middle" id="list_admin">
                                <td><?php echo $osts[4]; //Order Satus as Item Ordered default value 1 ?>
                                    <input type="hidden" name="orderStatus" id="orderStatus" value="4" />
                                </td>
                                <td><?php echo date("m-d-Y"); ?><input type="hidden" name="orderDate" id="orderDate" val="<?php echo date("Y-d-m"); ?>" /></td>
                                <td><div id="userName"><!-- User Name --></div></td>
                                <td align="center"><?php echo $currencyCode; ?><input type="hidden" name="currencyCode" id="currencyCode" value="<?php echo $currencyCode; ?>" /></td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="admin_bottom">
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table></td>
                </tr>
            </table>
            <br /></div>
        <!-- *************************** Product Details area start *******************  -->
        <div id="productDetails" style="display:none;">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="user_display_area_admin_table">
                <tr>
                    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td class="boxtopheader">Product Details </td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                            <tr align="left" valign="middle" id="list_admin_top">
                                <td width="48%">Type in Product</td>
                                <td><input type="text" name="productItem" value="" id="productItem" class="box2_admin" /><input type="hidden" name="productItemArr" value="" id="productItemArr">&nbsp;<input type="button" class="buttn_admin" name="addProduct" value="Add" id="addProduct"><br/><span id="errProduct" class="error_text" style="display:none;"></span></td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="admin_bottom">
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table></td>
                </tr>
            </table>
            <br/></div>
        <!-- *************************** Items Details area start *******************  -->
        <div id="itemsDetails" style="display:none;">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
                <tr>
                    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td class="boxtopheader">Items Details </td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="1" cellpadding="6" id="cartDetails">
                            <tr align="left" valign="middle" id="list_admin_top">
                                <td width="15%">ProductName</td>
                                <td width="9%" align="center">Skuno</td>
                                <td width="18%" align="center">Combination</td>
                                <td width="10%" align="center">Quantity</td>
                                <td width="10%" align="center">Unit Price</td>
                                <td width="11%" align="center">Additional cost</td>
                                <td width="11%" align="center">Discount</td>
                                <td width="11%" align="center">Price</td>
                                <td width="11%" align="center">Options</td>
                            </tr>
                            <tr align="left" valign="middle" id="list_admin_bottom" class="list_admin">
                                <td colspan="10" align="right">
                                    <input id="cartEdit" type="button" class="buttn_admin" onClick="javascript:return editQty();" value="Edit" />
                                    <input id="cartSave" type="button" style="display:none;" class="buttn_admin" value="Save" />
                                    <input id="cartProceed" type="button" class="buttn_admin" value="Proceed" />
                                    <input id="hidtotcnt" type="hidden" name="hidtotcnt"  value="1" />
                                    <input id="cartItemArr" type="hidden" name="cartItemArr" value="" />
                                    <input id="cartCount" type="hidden" name="cartCount" value="0" />
                                    <input id="currencySymbol" type="hidden" name="currencySymbol" value="<?php echo $currencySymbol; ?>" />
                                    <input id="shippingWeight" type="hidden" name="" value="0.00" />
                                    <input id="shippingAmount" type="hidden" name="" value="0.00" />
                                    <input id="flatShippingFirst" type="hidden" name="flatShippingFirst" value="<?php echo $flatShippingFirst; ?>" />
                                    <input id="flatShippingAdditional" type="hidden" name="flatShippingAdditional" value="<?php echo $flatShippingAdditional; ?>" />
                                    <input id="orderProductType" type="hidden" name="orderProductType" value="" />
                                </td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="admin_bottom">
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table></td>
                </tr>
            </table>
            <br />
        </div>
        <!-- *************************** Billing Details area start *******************  -->
        <div id="billingDetails" style="display:none;">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
                <tr>
                    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td class="boxtopheader">Billing Address</td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                            <tr align="left" valign="middle" id="list_admin">
                                <td>
                                    <div id="bill_addr2">
                                        <table>
                                            <tr><td width="200">Email<span class="required_field">*</span></td><td width="161"><input type="text" id="editbill_email" name="editbill_email" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editbill_email_err" class="error_text"></span></td></tr>
                                            <tr><td>First Name<span class="required_field">*</span></td><td><input type="text" id="editbill_fname" name="editbill_fname" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editbill_fname_err" class="error_text"></span></td></tr>
                                            <tr><td>Last Name</td><td><input type="text" id="editbill_lname"  name="editbill_lname" class="box2_admin" value=""  />&nbsp;&nbsp;<span id="editbill_lname_err" class="error_text"></span></td></tr>
                                            <tr><td>Address<span class="required_field">*</span></td><td><input type="text" id="editbill_address"  name="editbill_address" class="box2_admin" value=""  />&nbsp;&nbsp;<span id="editbill_address_err" class="error_text"></span></td></tr>
                                            <tr><td>City<span class="required_field">*</span></td><td><input type="text" id="editbill_city"  name="editbill_city" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editbill_city_err" class="error_text"></span></td></tr>
                                            <tr><td>State<span class="required_field">*</span></td><td><input type="text" id="editbill_state"  name="editbill_state" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editbill_state_err" class="error_text"></span></td></tr>
                                            <tr><td>Zip code<span class="required_field">*</span></td><td><input type="text" id="editbill_zip"  name="editbill_zip" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editbill_zip_err" class="error_text"></span></td></tr>
                                            <tr><td>Country<span class="required_field">*</span></td><td><input type="text" id="editbill_country"  name="editbill_country" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editbill_country_err" class="error_text"></span></td></tr>
                                            <tr><td>Phone<span class="required_field">*</span></td><td><input type="text" id="editbill_phone"  name="editbill_phone" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editbill_phone_err" class="error_text"></span></td></tr>
                                            <tr><td>Mobile</td><td><input type="text" id="editbill_mobile"  name="editbill_mobile" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editbill_mobile_err" class="error_text"></span></td></tr>
                                            <tr><td>Fax</td><td><input type="text" id="editbill_fax" name="editbill_fax" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editbill_fax_err" class="error_text"></span></td></tr>
                                            <tr><td>&nbsp;</td>
                                                <td>
                                                    <input type="hidden" name="editbill_id" id="editbill_id" value="" />
                                                    <input type="button" class="buttn_admin" id="billingProceed" value="Proceed" />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="0" cellpadding="3" id="admin_bottom">
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table></td>
                </tr>
            </table>
            <br/></div>
        <!-- *************************** Shipping Details area start *******************  -->
        <div id="shippingDetails" style="display:none;">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
                <tr>
                    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td class="boxtopheader">Shipping Address</td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                            <tr align="left" valign="middle" id="list_admin">
                                <td>
                                    <div id="ship_addr2">
                                        <table>
                                            <tr><td width="200">First Name<span class="required_field">*</span></td><td width="161"><input type="text" id="editship_fname" name="editship_fname" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editship_fname_err" class="error_text"></span></td></tr>
                                            <tr><td>Last Name</td><td><input type="text" id="editship_lname"  name="editship_lname" class="box2_admin" value=""  />&nbsp;&nbsp;<span id="editship_lname_err" class="error_text"></span></td></tr>
                                            <tr><td>Address<span class="required_field">*</span></td><td><input type="text" id="editship_address"  name="editship_address" class="box2_admin" value=""  />&nbsp;&nbsp;<span id="editship_address_err" class="error_text"></span></td></tr>
                                            <tr><td>City<span class="required_field">*</span></td><td><input type="text" id="editship_city"  name="editship_city" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editship_city_err" class="error_text"></span></td></tr>
                                            <tr><td>State<span class="required_field">*</span></td><td><input type="text" id="editship_state"  name="editship_state" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editship_state_err" class="error_text"></span></td></tr>
                                            <tr><td>Zip code<span class="required_field">*</span></td><td><input type="text" id="editship_zip"  name="editship_zip" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editship_zip_err" class="error_text"></span></td></tr>
                                            <tr><td>Country<span class="required_field">*</span></td><td><input type="text" id="editship_country"  name="editship_country" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editship_country_err" class="error_text"></span></td></tr>
                                            <tr><td>Phone</td><td><input type="text" id="editship_phone"  name="editship_phone" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editship_phone_err" class="error_text"></span></td></tr>
                                            <tr><td>Mobile</td><td><input type="text" id="editship_mobile"  name="editship_mobile" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editship_mobile_err" class="error_text"></span></td></tr>
                                            <tr><td>Fax</td><td><input type="text" id="editship_fax"  name="editship_fax" class="box2_admin" value="" />&nbsp;&nbsp;<span id="editship_fax_err" class="error_text"></span></td></tr>
                                            <tr><td>&nbsp;</td>
                                                <td>
                                                    <input type="hidden" name="editship_id" id="editship_id" value="" />
                                                    <input type="button" class="buttn_admin" id="shippingProceed" value="Proceed" />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="admin_bottom">
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table></td>
                </tr>
            </table>
            <br/></div>
        <!-- *************************** Shipping Method area start *******************  -->
        <div id="shippingMethod" style="display:none;">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
                <tr>
                    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td class="boxtopheader">Shipping Method</td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                            <tr align="left" valign="middle" id="list_admin">
                                <td>
                                    <div id="ship_addr2">
                                        <table id="shipMethodOptions">
                                            <tr><td>Shipping Method</td><td>

                                                    <select name="shipmeth" id="shipmeth" class="box2_admin">
                                                        <?php
                                                        if(!empty($shipmentMethods)) {
                                                            ?>
                                                            <?php
                                                            foreach($shipmentMethods as $smeth) {
                                                                if(trim($smeth) <> '') {
                                                                    ?>
                                                        <option value="<?php echo $smeth; ?>"><?php echo $smeth; ?></option>
                                                                    <?php
                                                                }
                                                            }
                                                        }
                                                        ?>
                                                    </select>
                                                    <?php

                                                    $shipmentCheck = (!empty($shipmentMethods)) ? 1 : 0;
                                                    ?>
                                                    <span class="error_text" id="shipMethod_err">
                                                        <?php
                                                        if($shipmentCheck==0) {
                                                            echo 'Please enable any shipment method to proceed further';
                                                        }
                                                        ?>
                                                    </span>
                                                    <input type="hidden" name="shippmentCheck" id="shipmentCheck" value="<?php echo $shipmentCheck; ?>" />
                                                </td></tr>
                                            <tr>
                                                <td>Shipping Options</td>
                                                <td id="sOptions" class="loader_off">
                                                </td>
                                            </tr>
                                            <tr><td>&nbsp;</td>
                                                <td>

                                                    <input type="button" class="buttn_admin" id="shippingMethodProceed" value="Proceed" />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="admin_bottom">
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table></td>
                </tr>
            </table>
            <br/></div>
        <!-- *************************** Price Details area start *******************  -->
        <div id="priceDetails" style="display:none;">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
                <tr>
                    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td class="boxtopheader">Price Details</td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                            <tr align="left" valign="middle" class="list_admin">
                                <td width="44%">Total Price</td>
                                <td width="56%"><span id="totalPriceSub"></span><input type="hidden" name="totalPrice" id="totalPrice" value="0.00" /></td>
                            </tr>
                            <tr align="left" valign="middle" class="list_admin">
                                <td>Tax Name </td>
                                <td><span id="taxName"></span><input type="hidden" name="taxOptionName" id="taxOptionName" />
                                </td>
                            </tr>
                            <tr align="left" valign="middle" class="list_admin">
                                <td>Tax</td>
                                <td><span id="taxAmount"></span><input type="hidden" name="totalTax" id="totalTax" value="0.00" /></td>
                            </tr>
                            <!-- Specials -->

                            <tr align="left" valign="middle" class="list_admin" id="promocodeTab">
                                <td>Enter Promo Code</td>
                                <td><input type="text" name="promoCode" id="promoCode" class="box2_admin" value="" />&nbsp;<span id="errorPromoCode" class="error_text"></span></td>
                            </tr>

                            <tr align="left" valign="middle" class="list_admin">
                                <td>Promo Code Discount </td>
                                <td><span id="promoCodeDiscount"><?php echo $currencySymbol; ?> 0.00</span><input type="hidden" name="totalDiscount" id="totalDiscount" value="0.00" /></td>
                            </tr>
                            <tr align="left" valign="middle" class="list_admin" id="shippingPriceTotal">
                                <td>Shipping</td>
                                <td><span id="shipAmount"></span>&nbsp;<span id ="shipMethod"></span><input type="hidden" name="shipOptionMethod" id="shipOptionMethod" value="" /><input type="hidden" name="shipOptionTitle" id="shipOptionTitle" value="" /><input type="hidden" name="shipOptionCost" id="shipOptionCost" value="0.00" /></td>
                            </tr>
                            <tr align="left" valign="middle" class="list_admin">
                                <td>Balance Credits</td>
                                <td><span id="creditBal"></span>&nbsp;&nbsp;&nbsp;<span id="creditUsage" style="display:none;"><a href="javascript:void(0)" id="useCredit">Use Credits</a></span><input type="hidden" name="credits" id="credits" value="" /><input type="hidden" name="creditBalance" id="creditBalance" value="0.00" /></td>
                            </tr>
                        </table>
                        <table width="100%"  border="0" cellspacing="0" cellpadding="3" id="admin_bottom">
                            <tr>
                                <td width="44%">Grand Total</td>
                                <td width="55%" class="toplinks"><span id="grandTot"></span><input type="hidden" name="grandTotal" id="grandTotal" value="0.00" /><input type="hidden" name="extraBillAmount" id="extraBillAmount" value="0.00" /></td>
                                <td align="right"><input type="button" class="buttn_admin" id="extraBill" value="Extra Bill" /></td>
                            </tr>
                        </table></td>
                </tr>
            </table>
            <br />
        </div>
        <!-- *************************** Remarks area start *******************  -->
        <div id="remarksInfo" style="display:none;">

            <table width="100%">
                <tr>
                    <td>    <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
                            <tr>
                                <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                        <tr>
                                            <td class="boxtopheader">Remarks</td>
                                        </tr>
                                    </table>

                                    <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                                        <tr align="left" valign="middle" id="list_admin">
                                            <td width="31%">Order note </td>
                                            <td width="69%">
                                                <textarea name="note" id="note" class="box2_admin"></textarea></td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table></td>
                    <td><table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
                            <tr>
                                <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                        <tr>
                                            <td class="boxtopheader">Comments For Customer</td>
                                        </tr>
                                    </table>

                                    <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                                        <tr align="left" valign="middle" id="list_admin">
                                            <td width="31%">Comments</td>
                                            <td width="69%">
                                                <textarea name="comment" id="comment" class="box2_admin"></textarea></td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table></td>
                </tr>


            </table>


            <br />
            <div id="saveDetails">
                <input name="Submit" type="submit" class="buttn_admin" value="Save" />

            </div>
        </div>

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

