<div  style="color:red;font-size: 15px " id="divCommReq"><?php if(isset($this->message)){ echo  $this->message; } ?></div>

<div class="comm_div">
    <div class="comm_content_block">

        <h3>Manage Inquires</h3>
        <div class="comm_content_block_items">
		
		<div class="row">
			<div class="top_button_outer">
			<form name="frmsearch" method="post" action="<?php echo ConfigUrl::base();?>index/enquiry">
			<div class="col-xs-12 col-sm-1"><span class="label-stl">Search</span></div>
			<div class="col-xs-12 col-sm-4">
				<div class="small_search_outer">
				<input type="text" value="<?php if(isset($_POST['txtSearch'])){ echo $_POST['txtSearch']; }else{ if(isset($this->txtSearch)){ echo $this->txtSearch; } } ?>" class="form-control" name="txtSearch" >
				<button type="submit" name="btnSearch" value="Search" class="small_search">
					<i class="fa fa-search" aria-hidden="true"></i>
				</button>
				</div>
			</div>
		  
			<div class="clearfix"></div>
			</form>
			</div>
		</div>
			
            
			<div class="table-responsive">
            <table width="100%" cellspacing="1" cellpadding="0" border="0" class="table table-bordered table-striped">

                <tbody><tr>
                        <th width="5%" valign="top" align="center">#</th>

                        <th width="16%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/enquiry/1/Username/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Name</a></th>
                        <th width="22%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/enquiry/1/Email/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Email</a></th>
                        <th width="14%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/enquiry/1/vDescription/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Ad Title</a></th>
                        <th width="18%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/enquiry/1/vDescription/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Message</a></th>
                        <th width="10%" valign="top" align="center"><a href="<?php echo ConfigUrl::base()?>index/enquiry/1/dDate/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Posted Date</a></th>
                        <th width="21%" valign="top" align="center"><a href="<?php echo ConfigUrl::base()?>index/enquiry/1/nStatus/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Status</a></th>
                        <th width="12%" valign="top" align="center">Action</th>
                    </tr>






                    <?php
                    if(sizeof($this->resComments)>0) {
                        $i=0;
//                echo '<tr  class="row_color1"><td colspan="6"><div id="commMsg" style="color: red"> </div></td></tr>';
                        foreach($this->resComments as $row) {
                            $i++;
                            ?>

                <div id="rateMsg<?php echo $row->nId;?>" style="color: red"></div>
                <div>

                    <tr id="rate<?php echo $row->nId;?>" class="row_color1">
                        <td valign="top" align="center"><?php echo ($this->page-1)*$this->pageMaxCount +$i; ?></td>
                        <td valign="top" align="left"><?php echo $row->Username?></td>
                        <td valign="top" align="left"><?php echo $row->Email ?></td>
                        <td valign="top" align="left"><a href="javascript:void(0)" onclick="sendreply(event,'<?php echo $row->nId?>','pos')"><?php echo stripslashes($row->Title)?></a></td>
                        <td valign="top" align="left" id="divCommVal"><div onmouseover="showComment(event,'<?php echo $row->nId?>')" onmouseout="hideComment('<?php echo $row->nId?>')" ><?php echo substr(stripslashes($row->vDescription),0,50)."...";?></div></td>
                        <td valign="top" align="center"><?php echo date("m/d/Y",strtotime(stripslashes($row->dDate)))?></td>
                        <td valign="top" align="center" id="divStatusVal"><?php echo ($row->nStatus==1)?"Reply send":"Reply pending";?></td>
                        <td valign="top" align="center">
							<a href="javascript:void(0)" onclick="sendreply(event,'<?php echo $row->nId?>','')">Reply</a>
							 
							<a href="javascript:void(0)" onclick="deleteenquiry(event,'<?php echo $row->nId?>')">Delete</a></td>
                    </tr>
                </div>
                        <?php
                    }
                }
                else
                    echo '<tr class="row_color1">
        <td colspan="8">No Record Found</td></tr>';
                ?>

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

<!--  start paging..................................................... -->
<?php if($this->pageCount > 1) {  ?>

<div class="pagination">
    <ul>
            <?php if($this->page != 1) {?>
        <li><a href="<?php echo ConfigUrl::base()?>index/enquiry/1/" class="page_first" >First</a></li>
        <li><a class="page_prev" href="<?php echo ConfigUrl::base()?>index/enquiry/<?php if($this->page != 1) echo $this->page - 1; else echo $this->page; ?>/" >Previous</a></li>
                <?php
            }?>
        <li class="pageinfo"><div id="page-info">Page <strong><?php echo $this->page; ?></strong> / <?php echo $this->pageCount; ?></div></li>
            <?php if($this->pageCount != $this->page) {?>
        <li><a class="page_next" href="<?php echo ConfigUrl::base()?>index/enquiry/<?php if($this->pageCount != $this->page) echo  $this->page + 1; else echo $this->pageCount; ?>/" >Next</a></li>
        <li><a class="page_last" href="<?php echo ConfigUrl::base()?>index/enquiry/<?php echo $this->pageCount; ?>/" >Last</a></li>
                <?php
            }?>
    </ul>
    <div class="clear"></div>
</div>
    <?php
}
?>
<div id="divComm" style="top: 100px;left: 300px;position: absolute;background-color: #fff;"></div>
<script>
    function showComment(e,id)
    {
        var posx =0;var posy=0;
        if (!e){var e = window.event;}
        if (e.pageX || e.pageY){
            posx = e.pageX;
            posy = e.pageY;
        }
        else if (e.clientX || e.clientY){
            posx = e.clientX;
            posy = e.clientY;
        }
        $('#divCommText'+id).css("top",posy+15);
        $('#divCommText'+id).css("left",posx);
        $('#divCommText'+id).fadeIn();
    }
    function hideComment(id)
    {
        $('#divCommText'+id).fadeOut("slow");
    }




    function sendreply(e,id,p)
    {
        var posx =0;var posy=0;
        if (!e){var e = window.event;}
        if (e.pageX || e.pageY){
            posx = e.pageX;
            posy = e.pageY;
        }
        else if (e.clientX || e.clientY){
            posx = e.clientX;
            posy = e.clientY;
        }
        $('#divComm').fadeIn("slow");
        $('#divComm').css("top",posy-150);
        if(p=='pos'){
//            $('#divComm').css("left",posx);
        }
        else{
//            $('#divComm').css("left",posx-480);
        }
        $('#divComm').load('<?php echo ConfigUrl::base()?>index/sendreply?id='+id, function() {
        });
    }

    function deleteenquiry(e,id){
        var data 	= 'id='  + id;
        $.ajax({
            url: "<?php echo ConfigUrl::base(); ?>index/deleteenquiry/",
            type: "POST",
            data: data,
            cache: false,
            success: function (html) {
                if (html==1) {
                    $("#divComm").fadeOut("slow");
                    if(status==1)$("#divStatusVal").html("Approved");
                    else $("#divStatusVal").html("Not Approved");
                    $("#rateMsg"+id).html('<font color="green">Message deleted Successfully');
                    $("#rateMsg"+id).fadeIn("Slow");
                    setTimeout(function() {$("#rateMsg"+id).fadeOut("slow");$("#rateMsg"+id).html('')},2000);
                    setTimeout(function() {$("#rate"+id).fadeOut("slow");$("#rate"+id).html('')},2000);
                    return false;
                }
                if (html==2)
                    $("#divCommReq").html("Please Enter Comment");

                else alert('Sorry, unexpected error. Please try again later.');
            }
        });
    }

    function load(){

        var subject      =    $("#txtSubject").val();
        var message    =    $("#txtMessage").val();
        var id        =    $("#id").val();
        var toemail   = $("#toemail").val();
        var to        = $("#to").val();
        if(message=="" || id=="" || subject=="")
        {
            $("#divCommReq").html("Please Enter Comment");
        }
        else
        {
            var data 	= 'id='  + id+'&subject='+subject+'&message='+message+'&toemail='+toemail+'&to='+to;
            $.ajax({
                url: "<?php echo ConfigUrl::base(); ?>index/sendmessage/",
                type: "POST",
                data: data,
                cache: false,
                success: function (html) {
                    if (html==1) {
                        $("#divComm").fadeOut("slow");
                        //                                    $("#divCommVal").html(comm);
                        if(status==1)$("#divStatusVal").html("Approved");
                        else $("#divStatusVal").html("Reply Sent");

                        $("#rateMsg"+id).html('<font color="green">Message send Successfully</font>');
                        $("#rateMsg"+id).fadeIn("Slow");
                        setTimeout(function() {$("#rateMsg"+id).fadeOut("slow");$("#rateMsg"+id).html('')},2000);
                        return false;
                    }
                    if (html==2)
                        $("#divCommReq").html("Please Enter Comment");

                    else alert('Sorry, unexpected error. Please try again later.');
                }
            });
        }

    }


</script>



