<?php
/* ---------Multicart 2.0 Upgradation starts---------- */

$username_flag = 1;
$password_flag = 0;
/* ---------Multicart 2.0 Upgradation ends---------- */

function using_ie() {
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    $ub = False;
    if (preg_match('/MSIE/i', $u_agent)) {
        $ub = True;
    }

    return $ub;
}

$userLoggedoutmsg   =   '';

if($_REQUEST['logoff']=='1')
{
    $userLoggedoutmsg   =   MSG_USER_LOGGED_OUT;
    //$_SESSION['LOGOUT_MESSAGE'] =   '';
}

if (isset($_POST['loginbox'])) {

    $txtUserName = $_POST["txtUserName"];

    $txtPassword = $_POST["txtPassword"];
    /* $sql=" SELECT user_id,user_name,password FROM ".$tableprefix."users WHERE user_name='".addslashes($txtUserName)."' AND password = '".addslashes(md5($txtPassword))."' AND deleted = 'N'";
      $result=mysql_query($sql) or die(mysql_error());
      if(mysql_num_rows($result) > 0 ){
      $row = mysql_fetch_array($result);
      $message="Success!";
      $_SESSION["sess_username"] = $row["user_name"];
      $_SESSION["sess_userid"] = $row["user_id"]; */

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


    /* ---------Checking the password---------------- */

    $select_password = "SELECT password
                              FROM " . $tableprefix . "users
                             WHERE LOWER(user_name) = " . strtolower(GetSQLValueString($txtUserName, "text")) . "
                               AND deleted = 'N'";

    $result_password = mysql_query($select_password) or die(mysql_error());
    if (mysql_num_rows($result_password) > 0) {

        $password_row = mysql_fetch_assoc($result_password);

        if (GetSQLValueString($password_row['password'], "text") != GetSQLValueString(md5($txtPassword), "text")) {

            //$messagelog = "Invalid password !!";
            $password_flag = 1;
        }
    }

    //else
    //{

    /* ---------Checking the username---------------- */

    $select_username = "SELECT user_name FROM " . $tableprefix . "users
							WHERE password = " . GetSQLValueString(md5($txtPassword), "text") .
            " AND deleted = 'N'";

    $result_username = mysql_query($select_username) or die(mysql_error());
    if (mysql_num_rows($result_username) > 0) {

        while ($username_row = mysql_fetch_array($result_username)) {

            if (strtolower(GetSQLValueString($username_row['user_name'], "text")) == strtolower(GetSQLValueString($txtUserName, "text"))) {
                $username_flag = 0;
            }
        }
    }

    if ($username_flag == 1 && $password_flag == 0) {
        $messagelog = INVALID_USERNAME_TEXT;
    }

    if ($username_flag == 1 && $password_flag == 1) {
        $messagelog = INVALID_PASSWORD_TEXT;
    }

    //}

    if ($username_flag != 1 && $password_flag != 1) {

        $sql = " SELECT user_id,user_name,password FROM " . $tableprefix . "users
				WHERE user_name='" . addslashes($txtUserName) . "' AND password = '" . addslashes(md5($txtPassword)) . "' AND deleted = 'N'";
        $result = mysql_query($sql) or die(mysql_error());
        if (mysql_num_rows($result) > 0) {
            $row = mysql_fetch_array($result);
            $message = "Success!";
            $_SESSION["sess_username"] = $row["user_name"];
            $_SESSION["sess_userid"] = $row["user_id"];

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

            /* -------function call to manage the different sessions-------- */


            manageSession(3);

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

            if (!isVisitorCartEmpty(session_id())) {
                mergeVisitorCartToUserCart(session_id(), $row["user_id"]);
            }
            if ($action != "") {
                if ($action == "checkout") {
                    echo "<script>location.href='viewcart.php';</script>";
                    //header("Location:viewcart.php");
                    exit;
                }
            } else {

                /* --------Multicart 2.0 starts----------- */

                /* echo "<script>location.href='usermain.php';</script>"; */

                $currentPage = GetCurrentPageName();

                $referer = $_SERVER['HTTP_REFERER'];

                echo "<script>location.href='" . $referer . "';</script>";

                /* --------Multicart 2.0 ends----------- */

                //header("Location:usermain.php");
                exit;
            }
        } else {
            $messagelog = INVALID_USERNAME_PASSWORD_TEXT;
        }
    }

    /* ----------Multicart 2.0 Upgradation ends----------- */
} else if (isset($_POST['newuser'])) {
    echo "<script>location.href='register.php';</script>";
    exit;
}
?>
<style type="text/css">
    .textfield_search{
        width:205px;
        border:1px solid #cfcfcf;
        padding:4px;
        color:#333333;
    }

    .dv_fant{width:180px; height:28px; margin:3px 0 0 0; float:left;
    }


</style>



<script language="javascript" type="text/javascript">


    function clearText(thefield,id){
        if (thefield.defaultValue==thefield.value)
            thefield.value = ""
        identity=document.getElementById(id);
        identity.className='textfield';
    }

    function clearText1(thefield,id){
        if (thefield.defaultValue==thefield.value)
            thefield.value = ""
        identity=document.getElementById(id);
        identity.className='textfield_search';
    }

    function openuserhelp()
    {

        var url = './help/userhelp/index.html'
        window.open(url,"Help","scrollbars=yes");
    }
    $(document).ready(function(){
        var ie7 = false;
        if ( $.browser.msie ) {
            if( $.browser.version == 7.0)
            {
                ie7 = true;
            }
        }


        if(ie7 == true)
        {
            $(".fandtlinks").css('margin','-12px');

        }


    });


</script>
<div id="wrapper">

    <!-- Header Styles Start -->
    <div  id="header">


        <div class="headerleft">
            <div class="logo"><a href="<?php echo SITE_URL ?>/index.php">
                    <img src="<?php echo SITE_URL ?>/banners/<?php echo $logoimage ?>" alt=""  border="0" />
                </a>
               
            </div>
            <?php //}?>

        </div>

        <div class="headerright">
                <?php if($userLoggedoutmsg!=''){ ?>
            
                        <!--<span class="success_message" align="left"><?php echo $messagelog; ?></span>-->
                        
                        <?php } ?>
           
<?php
if (isset($_SESSION["sess_userid"]) and $_SESSION["sess_userid"] != "") {
    ;
} else if (basename($_SERVER['PHP_SELF']) != "login.php" and $_SESSION['guest_login'] == '') {
    ?>
                <div class="login_sec"><!-- onSubmit="return checkLoginForm();" -->
                    <form name="frmLogin" action="<?php echo SITE_URL ?>/index.php" method="POST">
                        
                        <h6><?php echo USER_LOGIN_TEXT;?><span><?php echo $messagelog; ?></span></h6>


                        <input name="txtUserName" type="text"  class="textfield2" value="" placeholder="<?php echo USERNAME_TEXT;?>" size="20"  id="txtUserName"/>

                        <input name="txtPassword" type="password"  class="textfield2" value="" placeholder="<?php echo PASSWORD_TEXT;?>" size="20" id="txtPassword"/>

                        <input name="loginbox" type="submit" class="button" value="<?php echo SUBMIT_BUTTON;?>" />

                    </form>

                    <p>&nbsp;<a href="register.php"><?php echo REGISTRATION_LINK_TEXT;?></a> &nbsp;|&nbsp;
                        <a href="forgotpassword.php"><?php echo FORGOTPASSWORD_LINK_TEXT;?></a></p>
                    <div class="clear"></div>
                </div>
<?php } ?>
<?php
if ($_SESSION["sess_userid"] != "" && $_SESSION['guest_login'] == '') {

    $select_user_name = "SELECT first_name,last_name,password FROM " . $tableprefix . "users WHERE user_id = " . $_SESSION["sess_userid"];

    $result_user_name = mysql_query($select_user_name) or die(mysql_error());

    if (mysql_num_rows($result_user_name) > 0) {

        $user_name_row = mysql_fetch_assoc($result_user_name);
        ?>

                    <div class="login_sec2">
                        <h1>
                            <?php echo WELCOME_TEXT;?>&nbsp; <?php echo $user_name_row['first_name'] ?>&nbsp;<?php echo $user_name_row['last_name'] ?> <br />

                        </h1>

                        <a href="<?php echo SITE_URL ?>/myaccount.php" class="my_account_login_btt"><?php echo MY_ACCOUNT_TEXT; ?></a>
                        <a href="<?php echo SITE_URL ?>/logout.php" class="my_account_login_btt"><?php echo LOGOUT_TEXT; ?></a>


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

                    <?php
                }
            } else {
                if ($_SESSION['guest_login'] != '' && !isset($_GET['guest_login'])) {
                    ?>
                    <div class="login_sec2">
                        <h1>
                            Welcome&nbsp; Guest <br />

                        </h1>

                        <a href="<?php echo SITE_URL ?>/logout.php" class="my_account_login_btt">Logout</a>

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

        <?php
    }
}
?>

            <?php
            if (basename($_SERVER['PHP_SELF']) == "login.php" && $_SESSION["sess_userid"] == "") {
                ?>

                <div class="login_sec"> &nbsp;</div>

            <?php } ?>






<?php
if (strstr($_SERVER['SCRIPT_FILENAME'], 'index.php') == TRUE) {
    $link_selected_index = "activelink";
} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'categorydetail.php') == TRUE) {
    $link_selected_category = "activelink";
} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'viewcart.php') == TRUE) {
    $link_selected_cart = "activelink";
} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'postfeedback.php') == TRUE) {
    $link_selected_feedback = "activelink";
} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'faq.php') == TRUE) {
    $link_selected_faq = "activelink";
} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'about_us.php') == TRUE) {
    $link_selected_aboutus = "activelink";
} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'contact_us.php') == TRUE) {
    $link_selected_contactus = "activelink";
} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'help.php') == TRUE) {
    $link_selected_help = "activelink";
} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'allseller.php') == TRUE) {
    $link_selected_sellers = "activelink";
} elseif (strstr($_SERVER['SCRIPT_FILENAME'], 'site-feedback.php') == TRUE) {
    $link_selected_feedback = "activelink";
}
?>
            <div class="header_inneright" style="position:relative; ">


                <div class="cart_section">



                    <h4><a href="<?php echo SITE_URL ?>/viewcart.php"><?php echo CART_TEXT;?><span> <?php
            if ($_SESSION["sess_userid"] != "") {
                echo GetUserCartCount($_SESSION["sess_userid"]);
            } else {
                echo GetVisitorCartCount(session_id());
            }
?> <?php echo CART_ITEMS_COUNT_TEXT;?></span></a></h4>

                </div>

                <div class="search_topheader">
                    <form action="search.php" method="get" name="frmSearch">
                        <input name="chkProductName" type="hidden" value="on">
                        <input name="chkIncludeSubcategories" type="hidden" value="on">
                        <input name="sd" type="hidden" value="1">
                        <div align="right" class="search_area">
                            <input type="text" class="f_right_marg tp_srch_marg" style="border:1px solid #CFCFCF; padding:5px 5px 5px 5px; " name="txtSearch" value="<?php echo stripslashes($_REQUEST["txtSearch"]); ?>" />

            <?php
            $catlist = make_selectlist(0, 0);


            echo makeDropDownList_search("ddlCategory", $catlist, $ddlCategory, true, "topsearch_fld f_right_marg", $properties, $behaviors);
            ?>

                            <input name="Submit" type="submit" class="f_right_marg"  style="background-color:#000000; border:1px solid #000000; color:#FFFFFF; padding:4px 5px 4px 5px; cursor:pointer; " value="<?php echo SEARCH_BUTTON;?> "/>

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



                <div class="topnavsec" style="float:right; padding-top:2px; width:380px;margin-bottom:0px; ">

                    <div  class="dv_fant">
<?php
$sqlSM = "SELECT title,logo,link 
        FROM " . $tableprefix . "social_media
            WHERE active='Y'";
$resultSM = mysql_query($sqlSM) or die(mysql_error());

if (mysql_num_rows($resultSM) != 0) {
    ?>
                            <div  class="dvfbk" style="float:left; clear:left;  ">
    <?php
    while ($rowSM = mysql_fetch_object($resultSM)) {
        $smLInk = $rowSM->link != '' ? $rowSM->link : '#';
        ?>


                                    <a  class="fandtlinks" href="<?php echo $smLInk; ?>" target="_blank"

                                        style="margin:0px 5px 0 0; height:26px; display:block;  padding:0; "

                                        title="<?php echo $rowSM->title; ?>" >&nbsp;&nbsp;<img  style="float:left; "src="<?php echo $site_url; ?>/social_media/<?php echo $rowSM->logo; ?>" /></a>
        <?php
    }
    ?>
                                <div class="clear"></div>
                            </div>
    <?php
}
?>


                    </div>

                        <?php
                        if ($adminCurrency['currency_code'] != '') {
                            $currency_code = $adminCurrency['currency_code'];
                        } else {
                            $currency_code = 'USD';
                        }

                        if ($_SESSION['SESS_currency_type'] == '') {
                            $_SESSION['SESS_currency_type'] = $adminCurrency['currency_code'];
                        }
                        ?>
                    <input type="hidden" value="<?php echo $currency_code; ?>" name="currency_type">
                            <?php
                            if (getSettingsValue('enable_multicurrency') == 'Y') {
                                ?>
                        <form name="frmCurrencyType" method="post">

                            <div class="topnavsec1" style="width:180px; height:28px; "><?php echo CURRENCY_TEXT;?> &nbsp;&nbsp;
                                <select name="currency_type" class="topsearch_fld" onChange="Javascript:document.frmCurrencyType.submit();">
    <?php
    $currency_type = $_SESSION['SESS_currency_type'];
//echo $currency_type;exit;
    if ($currency_type == '') {
        $currency_type = 'USD';
    }
    $select_currency = "SELECT vcurrency_code,ncurrency_id,vcurrency_name FROM " . $tableprefix . "currency_master WHERE vactive = 'Y' ORDER BY vcurrency_name";
    $result_currency = mysql_query($select_currency) or die(mysql_error());

    while ($currency_row = mysql_fetch_array($result_currency)) {

        if ($currency_type == $currency_row['vcurrency_code']) {

            $currency_selected = "selected";
        } else {
            $currency_selected = "";
        }
        ?>
                                        <option value="<?php echo $currency_row['vcurrency_code'] ?>" <?php echo $currency_selected ?>><?php echo $currency_row['vcurrency_name'] ?></option>

                            <?php
                        }
                        ?>
                                </select>



                            </div>

                        </form>
                    <?php } ?>
                    <!--
                    <div class="topnavsec2" style="float:right;padding-top:5px;" >
                    <a href="<?php echo SITE_URL ?>/contact_us.php" id="<?php echo $link_selected_index ?>">Site Feedback</a>
                    <a href="<?php echo SITE_URL ?>/contact_us.php" id="<?php echo $link_selected_index ?>">Contact Us </a>
                    <a href="<?php echo SITE_URL ?>/terms_conditions.php" id="<?php echo $link_selected_index ?>"> Terms &amp; Conditions |</a>


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

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

        <div class="clear"></div>
    </div>
    <!-- Header Styles End -->



    <!-- Top Nav Section Start -->
    <div class="navtop" style="height:auto; ">

        <ul>
            <li><a href="<?php echo SITE_URL ?>/index.php" class="<?php echo $link_selected_index ?>"><?php echo HOME_LINK;?></a></li>
            <li><a href="<?php echo SITE_URL ?>/categorydetail.php" class="<?php echo $link_selected_category ?>"><?php echo CATALOG_LINK;?></a></li>
            <li><a href="<?php echo SITE_URL ?>/viewcart.php" class="<?php echo $link_selected_cart ?>"><?php echo VIEW_CART_LINK;?></a></li>
            <li><a href="<?php echo SITE_URL ?>/allseller.php" class="<?php echo $link_selected_sellers; ?>"><?php echo SELLER_LINK;?></a></li>
                                <?php
                                $enableAffiliate = getSettingsValue('enable_affiliates');
                                if ($enableAffiliate == 'Y') {
                                    ?>
                <li><a href="<?php echo SITE_URL ?>/affiliates/login.php"><?php echo AFFILIATES_LINK;?></a></li>
                                <?php } ?>
            <li><a href="<?php echo SITE_URL ?>/about_us.php" class="<?php echo $link_selected_aboutus; ?>"><?php echo ABOUT_LINK;?></a></li>
            <li><a href="<?php echo SITE_URL ?>/faq.php" class="<?php echo $link_selected_faq ?>"><?php echo FAQ_LINK;?></a></li>
            <li><a href="<?php echo SITE_URL ?>/site-feedback.php" class="<?php echo $link_selected_feedback ?>"><?php echo SITE_FEEDBACK_LINK;?></a></li>
            <li><a href="<?php echo SITE_URL ?>/help.php" class="<?php echo $link_selected_help ?>"><?php echo HELP_LINK;?></a></li>

        </ul>
        <div class="featuredproduct_btn"><a href="<?php echo SITE_URL ?>/index.php?featured=N"><?php echo NEW_PRODUCTS_TEXT; ?></a></div>
        <div class="clear"></div>
    </div>
    <!-- Top Nav Section End -->




    <!-- Content Area Start -->

    <div class="contentarea">

        <!-- content Area Left start -->
        <div class="contentarea_left">

            <!--<div class="search_top">
            <form name="frmSearch" action="search.php">
                                            <input name="chkProductName" type="hidden" value="on">
                                            <input name="chkIncludeSubcategories" type="hidden" value="on">
                                            <input name="sd" type="hidden" value="1">
                            <div style="float:left;"><input type="text"  class="textfield_serach" size="36" value="Product Search"   name="txtSearch" onfocus="clearText1(this,'txtSearch');"  id="txtSearch"/></div>
                            <div style="float:left;"><input name="btnSearch" type="submit" class="button" value="Go" /></div>
            <div class="clear"></div>

            </form>
            </div>-->

<?php
include_once("includes/categorylist.php");
?>			
            <div class="clear"></div>
        </div>
        <!-- content Area Left End -->


        <!-- content Area Right start -->
        <div class="contentarea_right">
