<script type="text/javascript">
 $(document).ready(function() {
	// validate the comment form when it is submitted

	// validate signup form on keyup and submit
	$("#frmAddAdmin").validate({
		rules: {
			txtLogin: {
                                minlength: <?php echo USERNAME_LENGTH?>,
				required: true

			},
			txtPass: {
				required: true,
				minlength: <?php echo PASSWORD_LENGTH?>
			},
			txtEmail: {
				required: true,
				email: true
			}
		},
		messages: {
			txtLogin: {
				required: "Please enter Login Name",
				minlength: "Your Login Name  must consist of at least  <?php echo USERNAME_LENGTH?> characters"
			},
			txtPass: {
				required: "Please enter Password",
				minlength: "Your password must be at least <?php echo PASSWORD_LENGTH?> characters long"
			},
			txtEmail: {
                            required: "Please enter Email",
                            email: "Please enter valid Email"
                        }
			
		}
	});
      $("#frmEditAdmin").validate({
		rules: {
			txtEmail: {
				required: true,
				email: true
			}
		},
		messages: {
			txtEmail: {
                            required: "Please enter Email",
                            email: "Please enter valid Email"
                        }

		}
	});
      $("#frmEditPass").validate({
        rules: {
                txtPass: {
                    required: true,
                    minlength: <?php echo PASSWORD_LENGTH?>
                },
                txtCpass: {
                    required: true,
                    minlength: <?php echo PASSWORD_LENGTH?>,
                    equalTo: "#txtPass"
                }
        },
        messages: {
                txtPass: {
				required: "Please enter Password",
				minlength: "Your password must be at least <?php echo PASSWORD_LENGTH?> characters long"
			},
                txtCpass: {
                        required: "Please reenter Password",
                        minlength: "Your password must be at least <?php echo PASSWORD_LENGTH?> characters long",
                        equalTo: "Password Mismatch"
                }

        }
    });


 });
function changeStatus(id,status,type)
{
    var data 	= 'id='  + id+'&status='+status+'&type='+type;
    $.ajax({
            url: "<?php echo ConfigUrl::base(); ?>index/updateStatus/",
            type: "POST",
            data: data,
            cache: false,
            success: function (html) {
                    if (html==1) {


                         $('#status'+id).load('<?php echo ConfigUrl::base(); ?>index/ajaxLoadStatus?id='+id+'&type='+type, function() {
                               //alert('Load was performed.');
                            });
                         return false;
                    }
                    else alert('Sorry, unexpected error. Please try again later.');
            }
    });
}
</script>

<div  style="color:red;font-size: 15px " ><?php echo  $this->message; ?></div>

<!-- Category Listing -->
<?php if($this->act  == "edit"){ ?>
<div class="comm_content_block">
					<h3>Manage Sub Admins</h3>

				</div>
<div class="comm_box">
    <h4>Edit Profile</h4>
<form name="frmEditAdmin" id="frmEditAdmin" method="post" action="">
    <input type="hidden" value="<?php echo $id;?>" name="id"/>
    <input type="hidden" value="edit" name="act"/>
    <table border="0" cellpadding="0" cellspacing="0"  class="form_tbls" width="100%" >
    
    <tr>
        <th valign="top" width="30%"> First Name:</th>
            <td><input type="text" class="txt_area" id="txtFname" name="txtFname" value="<?php echo stripslashes($this->resAdmin->vAdminFname);?>"/></td>

    </tr>
     <tr>
            <th valign="top"> Last Name:</th>
            <td><input type="text" class="txt_area" id="txtLname" name="txtLname" value="<?php echo stripslashes($this->resAdmin->vAdminLastname);?>"/></td>

    </tr>
     <tr>
            <th valign="top"> Email<span style="color: red">*</span> :</th>
            <td><input type="text" class="txt_area" id="txtEmail" name="txtEmail" value="<?php echo stripslashes($this->resAdmin->vAdminEmail);?>"/></td>

    </tr>
    <tr>
    <th>&nbsp;</th>
    <td valign="top">
			<input type="button"  value="Back" name="cancel" class="btn_styles" onclick="window.location ='<?php echo ConfigUrl::base()?>index/adminusers'"/>
            <input type="submit"  value="Submit" name="btnProfile" class="btn_styles"/>            
    </td>
    </tr>
    </table>
    </form>
    <H4>Change Profile</H4>
    <form name="frmEditPass" id="frmEditPass"  method="post" action="">
    <input type="hidden" value="<?php echo $id;?>" name="id"/>
    <input type="hidden" value="edit" name="act"/>
    <table border="0" cellpadding="0" cellspacing="0"  class="form_tbls" width="100%" >
    
     <tr>
        <th valign="top" width="30%"> Password<span style="color: red">*</span>:</th>
        <td><input type="password" class="txt_area" id="txtPass" name="txtPass" value=""/></td>

    </tr>
   <tr>
        <th valign="top"> Confirm Password<span style="color: red">*</span>:</th>
        <td><input type="password" class="txt_area" id="txtCpass" name="txtCpass" value=""/></td>
    </tr>
    <tr>
    <th>&nbsp;</th>
    <td valign="top">
	<input type="button"  value="Back" name="Cancel" class="btn_styles" onclick="window.location ='<?php echo ConfigUrl::base()?>index/adminusers'"/>
            <input type="submit"  value="Submit" name="btnPassword" class="btn_styles"/>
               </td>
    </tr>
    </table>
    </form>

</div>

<?php
}
else if($this->act  == "add"){ ?>
<div class="comm_content_block">
					<h3>Add Profile</h3>

				</div>
<form name="frmAddAdmin" id="frmAddAdmin" method="post" action="">
    <input type="hidden" value="add" name="act"/>
    <table border="0" cellpadding="0" cellspacing="0"  class="form_tbls" width="100%" >
    <tr></tr>
    <tr>
        <th valign="top"> Login Name<span style="color: red">*</span> :</th>
        <td><input type="text" class="txt_area" id="txtLogin" name="txtLogin" value="<?php echo stripslashes($this->txtLogin) ?>"/></td>

    </tr>
    <tr>
        <th valign="top"> Password<span style="color: red">*</span> :</th>
        <td><input type="password" class="txt_area" id="txtPass" name="txtPass" value="<?php echo stripslashes($this->txtPass) ?>"/></td>

    </tr>

    <tr>
            <th valign="top"> First Name:</th>
            <td><input type="text" class="txt_area" id="txtFname" name="txtFname" value="<?php echo stripslashes($this->txtFname) ?>"/></td>

    </tr>
     <tr>
            <th valign="top"> Last Name:</th>
            <td><input type="text" class="txt_area" id="txtLname" name="txtLname" value="<?php echo stripslashes($this->txtLname) ?>"/></td>

    </tr>
     <tr>
            <th valign="top"> Email<span style="color: red">*</span> :</th>
            <td><input type="text" class="txt_area" id="txtEmail" name="txtEmail" value="<?php echo stripslashes($this->txtEmail) ?>"/></td>

    </tr>

    <tr>
    <th>&nbsp;</th>
    <td valign="top">
		<input type="button"  value="Back" name="cancel" class="btn_styles" onclick="window.location ='<?php echo ConfigUrl::base()?>index/adminusers'"/>
            <input type="submit"  value="submit" name="btnAdd" class="btn_styles"/>
            
    </td>
    </tr>
    </table>
    </form>

<?php
}

else
{
?>
<div class="comm_div">
				<div class="comm_content_block">
					<h3>Manage Sub Admins</h3>
					<div class="comm_content_block_items">
                                            <table width="100%" cellspacing="1" cellpadding="0" border="0">
                                                <tr><td><div class="comm_div"><a class="textlink" href="<?php echo ConfigUrl::base()?>index/adminusers?act=add">Add Subadmin</a></div></td></tr>
                                                </table>
					<table width="100%" cellspacing="1" cellpadding="0" border="0" class="list_table">

						<tbody><tr>
						  <th width="7%" valign="top" align="left">#</th>
						<th width="39%" valign="top" align="left">User</th>
                                                <th width="40%" valign="top" align="left">Name</th>
                                                <th width="14%" valign="top" align="left">Action</th>
						                        </tr>
                                                
						
            <?php
            if(sizeof($this->resAdmins)>0) {
                $i=0;
                foreach($this->resAdmins as $row) {
                    $i++;
                    ?>
                        <tr  class="row_color1">
                            <td width="7%" valign="top" align="left"><?php echo $i; ?></td>
                            <td valign="top" align="left"><?php echo stripslashes($row->vAdminUsername )?></td>
                            <td valign="top" align="left"><?php echo stripslashes($row->vAdminFname )." ".stripslashes($row->vAdminLastname )?></td>
                            <td  valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/adminusers?act=edit&id=<?php echo $row->nAdminId?>">Edit</a>&nbsp;
                             <?php //echo ($row->eAdminActive==0)? "<a href='".ConfigUrl::base()."index/adminusers?status=1&act=status&id=$row->nAdminId'>Activate</a> " :"<a href='".ConfigUrl::base()."index/adminusers?status=0&act=status&id=$row->nAdminId'>Deactivate</a>";?>
                                <span id="status<?php echo $row->nAdminId?>"> <a href="javascript:void(0)" onclick="changeStatus('<?php echo $row->nAdminId?>','<?php echo $row->eAdminActive?>','admin')"><?php echo ($row->eAdminActive==0)?"Activate":"Deactivate"; ?></a>
                                </span>
                                </td>
                        </tr>

                    <?php
                }
            }
            ?>

        </tbody></table>

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

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

		 <div class="pagination">
           <ul>
       		<li><a href="<?php echo ConfigUrl::base()?>index/adminusers/1/" class="page_first" >First</a></li>
           	<li><a class="page_prev" href="<?php echo ConfigUrl::base()?>index/adminusers/<?php if($this->page != 1) echo $this->page - 1; else echo $this->page; ?>/" >Previous</a></li>
            <li class="pageinfo"><div id="page-info">Page <strong><?php echo $this->page; ?></strong> / <?php echo $this->pageCount; ?></div></li>
         	<li><a class="page_next" href="<?php echo ConfigUrl::base()?>index/adminusers/<?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/adminusers/<?php echo $this->pageCount; ?>/" >Last</a></li>
            </ul>
		<div class="clear"></div>
		</div>
        <?php
        }
       ?>

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

        <!--  end paging................ -->


<?php
}
?>