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

	// validate signup form on keyup and submit
        
        $('#txtUser').keyup(function(){
            if($(this).val()=='')
                $('#frmsearch').submit();
        })
        
	$("#frmUsers").validate({
		rules: {
			txtLoginName: {
                          	required: true
                                
			},
			<?php
			if($this->act  == "add"){?>
			txtPass: {
                    required: true,
                    minlength: <?php echo PASSWORD_LENGTH?>
                },
			<?php
			}?>
                        txtEmail: {
                          	required: true,
                                email: true
			},

			txtFname: {
				required: true
				
			},
			txtLname: {
				required: true
				
			}
		},
		messages: {
			txtLoginName: {
				required: "Please enter Username"
			},
			<?php
			if($this->act  == "add"){?>
				txtPass: {
				required: "Please enter Password",
				minlength: "Your password must be at least <?php echo PASSWORD_LENGTH?> characters long"
			},
			<?php
			}?>
                        txtEmail: {
				required: "Please enter Email",
				 email: "Please enter valid Email"
			},
			txtFname: {
				required: "Please enter First Name"
				
			},
			txtLname: {
                            required: "Please enter Last Name"
                        }

		}
	});
      $("#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 updateState(selObj)
{
    country = selObj.options[selObj.selectedIndex].value;

    if(country == 'US')
    {
        document.getElementById("txtState1").style.display = "none";
        document.getElementById("txtState").style.display = "block";
    }
    else
    {
        document.getElementById("txtState1").style.display = "block";
        document.getElementById("txtState").style.display = "none";
    }
}
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>

<!-- Category Listing -->
<?php if($this->act  == "edit" || $this->act  == "add"){ ?>
<?php if($this->act  == "edit")
        {

         $user='Edit User';

        }
        else
        {

         $user='Add User';
            
        }
        ?>
<div class="comm_div">
				<div class="comm_content_block">
					<h3><?php echo $user?></h3>

				</div>
			</div>
<div  style="color:green;" ><?php echo  $this->message; ?></div>

<form name="frmUsers" id="frmUsers" method="post" action="">
    <input type="hidden" value="<?php echo $this->id;?>" name="id"/>
    <input type="hidden" value="<?php echo ($this->act  == "edit")?'edit':'add'?>" name="act"/>
	
    <table border="0" cellpadding="0" cellspacing="0" class="form_tbls"  width="100%">
    <tr>
        <th valign="center">Username<span style="color: red">*</span> : </th>
        <td><input type="text" <?php if($this->act  == "edit"){?>readonly="1" <?php }?>class="txt_area" id="txtLoginName"  name="txtLoginName" value="<?php echo stripslashes($this->resUsers->vLoginName);?>"/></td>
    </tr>
	<?php if($this->act  == "add"){ ?>
		 <tr>
			<th valign="center" width="22%"> Password<span style="color: red">*</span> :</th>
			<td valign="top"><input type="password" class="txt_area" id="txtPass" name="txtPass" value=""/></td>
	
		</tr>
	<?php
	}?>
    <tr>
        <th valign="center">Email<span style="color: red">*</span> : </th>
        <td valign="top"><input type="text"  class="txt_area" id="txtEmail"  name="txtEmail" value="<?php echo stripslashes($this->resUsers->vEmail);?>"/></td>
    </tr>
    <tr>
            <th valign="center"> First Name<span style="color: red">*</span> :</th>
            <td><input type="text" class="txt_area" id="txtFname" name="txtFname" value="<?php echo stripslashes($this->resUsers->vFirstName);?>"/></td>

    </tr>
     <tr>
            <th valign="center"> Last Name<span style="color: red">*</span> :</th>
            <td><input type="text" class="txt_area" id="txtLname" name="txtLname" value="<?php echo stripslashes($this->resUsers->vLastName);?>"/></td>

    </tr>
     <tr>
            <th valign="center"> Address1:</th>
            <td><input type="text" class="txt_area" id="txtAddress1" name="txtAddress1" value="<?php echo stripslashes($this->resUsers->	vAddress1);?>"/></td>

    </tr>
     <tr>
            <th valign="center"> Address2:</th>
            <td><input type="text" class="txt_area" id="txtAddress2" name="txtAddress2" value="<?php echo stripslashes($this->resUsers->vAddress2);?>"/></td>

    </tr>
     <tr>
            <th valign="center"> City:</th>
            <td><input type="text" class="txt_area" id="txtCity" name="txtCity" value="<?php echo stripslashes($this->resUsers->vCity);?>"/></td>

    </tr>
   
	
    <tr>
        <th valign="center">Country:</th>
        <td>
            <select onchange="updateState(this)" name="txtCountry" id="txtCountry" class="txt_area">
                <option value="">Select Country</option>
                <?php

                 if($selectedCountry=="") $countryKey   ="US";
                 else
                 $countryKey = $selectedCountry;
                 global $countries;
                foreach( $countries as $key => $value)
                {

                ?>
                <option value="<?php echo $key?>" <?php if($key==$countryKey) echo "selected";?>><?php echo $value;?></option>
                <?php
                }
                 ?>
                <option value="undefined">undefined</option>
            </select>
        </td>
    </tr>
    
     <tr>
        <th valign="center"> State:</th>
        <td>
            <?php
            $selDisplay ="";
            $inputDiaply ="";
            $selectedCountry    = stripslashes($this->resUsers->vCountry);
            if($selectedCountry=="US" || $selectedCountry=="") $inputDiaply="none";
            else
                $selDisplay ="none";
           ?>
            <select validate="required:true" name="txtState" id="txtState" class="txt_area" style="display:<?php echo $selDisplay?> ">
                  <?php
                  $selectedState    =  stripslashes($this->resUsers->vState);
                  global $usStates;
                  foreach($usStates  as $key => $value)
                  {
                 ?>
                  <option value="<?php echo $key?>" <?php if($key==$selectedState) echo "selected";?>><?php echo $value;?></option>
                  <?php
                  }
                 ?>
             </select>
            <input name="txtState1"  id="txtState1" class="txt_area" type="text" value="<?php echo ($this->txtState)?$this->txtState:stripslashes($this->resUsers->vState)?>" style="display:<?php echo $inputDiaply?> ">
        </td>
    </tr>
    <tr>
            <th valign="center"> Zip:</th>
            <td><input type="text" class="txt_area" id="txtZip" name="txtZip" value="<?php echo stripslashes($this->resUsers->nZip);?>"/></td>

    </tr>


     
     <tr>
            <th valign="center"> Phone:</th>
            <td><input type="text" class="txt_area" id="txtPhone" name="txtPhone" value="<?php echo stripslashes($this->resUsers->vPhone);?>"/></td>

    </tr>
     <tr>
            <th valign="center"> Fax:</th>
            <td><input type="text" class="txt_area" id="txtFax" name="txtFax" value="<?php echo stripslashes($this->resUsers->vFax);?>"/></td>

    </tr>
     <tr>
            <th valign="center"> URL:</th>
            <td>
                <input type="text" class="txt_area" id="txtUrl" name="txtUrl" value="<?php echo stripslashes($this->resUsers->vUrl);?>"/>
                 <span class="help"><a href="#" title="Your site url"><img src="<?php echo ConfigUrl::images('default')?>question_mark.jpg" border="0" height="15"></a></span>

            </td>
          
               

    </tr>
    <tr>
            <th valign="center"> Gender :</th>
            <td><input type="radio" name="radGender" value="M" checked/>Male<input type="radio"  name="radGender" value="F" <?php echo ($this->resUsers->vGender=="F")?"checked":"";?>/>Female</td>

    </tr>
    <tr>
            <th valign="center"> Education:</th>
            <td><input type="text" class="txt_area" id="txtEdu" name="txtEdu" value="<?php echo stripslashes($this->resUsers->vEducation);?>"/></td>

    </tr>
    <tr>
            <th valign="center"> Description:</th>
            <td><textarea  class="txt_area" id="txtDesc" name="txtDesc"><?php echo stripslashes($this->resUsers->vDescription);?></textarea></td>

    </tr>
   <!--   <tr>
            <th valign="top"> AlertStatus:</th>
            <td><input type="radio" name="radAlert" value="Y" checked/>Y<input type="radio" name="radAlert" value="N" <?php echo ($this->resUsers->vAlertStatus=="N")?"checked":"";?>/>N</td>

    </tr>
  <!--  <tr>
            <th valign="top"> NLStatus:</th>
           <td><input type="radio"   name="radNLStatus" value="Y" checked/>Y<input type="radio"  name="radNLStatus" value="N" <?php echo ($this->resUsers->vNLStatus=="N")?"checked":"";?>/>N</td>
    </tr>-->
    <tr>
            <th valign="center">Status:</th>
           <td><input type="radio"   name="radStatus" value="1" checked/>Enabled<input type="radio"  name="radStatus" value="0" <?php echo ($this->resUsers->vStatus=="0")?"checked":"";?>/>Disabled</td>
    </tr>
    <tr>
    <th>&nbsp;</th>
    <td valign="top">
	<input type="button"  value="Back" name="submit" class="btn_styles" onclick="window.location ='<?php echo ConfigUrl::base()?>index/users'"/>
            <input type="submit"  value="<?php echo ($this->act  == "add")?'Add':'Update'?>" name="btnProfile" class="btn_styles"/>
            
    </td>
    </tr>
    </table>
    <input type="hidden" value="hidden" name="hidInput" />
    </form>
<?php if($this->act  == "edit" ){ ?>

<div class="comm_box">
<h4>Change Password</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="center" width="22%"> Password<span style="color: red">*</span> :</th>
        <td><input type="password" class="txt_area" id="txtPass" name="txtPass" value=""/></td>

    </tr>
   <tr>
        <th valign="center"> 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/users'"/>
            <input type="submit"  value="Submit" name="btnPassword" class="btn_styles"/>
               </td>
    </tr>
    </table>
    </form>
</div>

<?php
}
}
else
{
?>
<div class="comm_div">
				<div class="comm_content_block">
					<h3>Manage Users</h3>

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


    <table width="99%">
                 <tbody><tr>

                     <td width="50%">
         <div class="comm_content_block_items">
                                               <form name="frmsearch" id="frmsearch" method="post" action="<?php echo ConfigUrl::base();?>index/users">
                                                   <span class="labelstyle">Search </span>
                                                           <input type="text" value="<?php echo ($_POST['txtSearch'])?$_POST['txtSearch']:$this->txtSearch?>" class="txt_area_2 txt_bx" name="txtSearch" id="txtUser" >
                                                           <input class="btn_styles" type="submit" name="btnSearch" value="Search" style="margin-bottom:5px;">
                                                      
                                                
                                               &nbsp;&nbsp;&nbsp; 
                                                </form>
                                             </div>
                         </td><td width="40%">
</td>
                         <td width="64%" align="right">
        <div>
            <a href="<?php echo ConfigUrl::base()?>index/users?act=add" class="btn_styles" style="text-decoration: none;">Add User</a>
        </div>
                   </td></tr>
             </tbody></table>
   
	<div class="comm_content_block_items">
					<table width="100%" cellspacing="1" cellpadding="0" border="0" class="list_table">

    <tr>
						<th width="7%" valign="top" align="center">#</th>
                                                <th width="37%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/users/vFirstName/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Name</a></th>
						<!--<th width="40%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/users/vLoginName/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Username</a></th>-->
                                                <th width="40%" valign="top" align="left"><a href="<?php echo ConfigUrl::base()?>index/users/vLoginName/<?php echo $this->order == 'ASC' ? 'DESC' : 'ASC'?>">Email</a></th>
                                                
                                                <th width="16%" valign="top" align="left">Action</th>
						                        </tr>
            <?php
            if(sizeof($this->resUsers)>0) {
                $i=0;
                foreach($this->resUsers as $row) {
                    $i++;
                    ?>
                        <tr class="row_color1">
                             <td valign="top" align="center"><?php echo ($this->page-1)*$this->pageMaxCount +$i; ?></td>
                             <td  valign="top" align="left"><?php echo stripslashes($row->vFirstName)." ".stripslashes($row->vLastName)?></td>
                            <!--<td valign="top" align="left"><?php echo stripslashes($row->vLoginName )?></td>-->
                              <td valign="top" align="left"><?php echo stripslashes($row->vEmail )?></td>
                            
                            <td   valign="top" align="left">
                                <a href="<?php echo ConfigUrl::base()?>index/users?act=edit&id=<?php echo $row->nUserId?>">Edit</a>&nbsp;&nbsp;/&nbsp;&nbsp;
                                        <?php //echo ($row->vStatus==0)? "<a href='".ConfigUrl::base()."index/users?status=1&act=status&id=$row->nUserId'>Activate</a> " :"<a href='".ConfigUrl::base()."index/users?status=0&act=status&id=$row->nUserId'>Deactivate</a>";?>
                                 <span id="status<?php echo $row->nUserId?>"> <a href="javascript:void(0)" onclick="changeStatus('<?php echo $row->nUserId?>','<?php echo $row->vStatus?>','user')"><?php echo ($row->vStatus==0)?"Activate":"Deactivate"; ?></a>
                                </span></td>
                        </tr>

                    <?php
                }
            }
            else {
                echo '<tr class="row_color1">
                      <td colspan="4">No Record Found</td></tr>';
            }
            ?>

        </tbody></table>
</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/users/<?php echo $this->sortfield?>/<?php echo $this->order?>?page=1&txtSearch=<?php echo $this->txtSearch?>" class="page_first" >First</a></li>
                    <li><a class="page_prev" href="<?php echo ConfigUrl::base()?>index/users/<?php echo $this->sortfield?>/<?php echo $this->order?>?page=<?php if($this->page != 1) echo $this->page - 1; else echo $this->page; ?>&txtSearch=<?php echo $this->txtSearch?>" >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/users/<?php echo $this->sortfield?>/<?php echo $this->order?>?page=<?php if($this->pageCount != $this->page) echo  $this->page + 1; else echo $this->pageCount; ?>&txtSearch=<?php echo $this->txtSearch?>">Next</a></li>
                <li><a class="page_last" href="<?php echo ConfigUrl::base()?>index/users/<?php echo $this->sortfield?>/<?php echo $this->order?>?page=<?php echo $this->pageCount; ?>&txtSearch=<?php echo $this->txtSearch?>" >Last</a></li>
            <?php
            }?>
            </ul>
		<div class="clear"></div>
		</div>
        <?php
        }
       ?>


<?php
}
?>