<script type="text/javascript">
    $.validator.setDefaults({
	submitHandler: function() {
           document.getElementById("frm_chgPasword").submit();
	}
    });

    $().ready(function(){
        var flip_1 = 1;
        $("#lblFormUsername").click(function () {
            $("#frm_user").toggle( flip_1++ % 2 == 0 );
        });

        var flip_2 = 0;
        $("#lblFormPassword").click(function () {
            $("#content_form_passwd").toggle( flip_2++ % 2 == 0 );
        });
        
	$("#frm_chgPasword").validate({
            rules: {
                oldpasswd: "required",
                newpasswd: "required",
                retypepasswd:  {
                    required: true,
                    equalTo: "#newpasswd"
                }
            },
            messages: {
                oldpasswd: "Required Field.",
                newpasswd: "Required Field.",
                retypepasswd: "Password incorrect!"
            }
	});
    });
</script>
<style type="text/css">
#content_form_passwd label.error {display:block;width:auto;color:#F00;clear:both; padding-left:150px; background: none}
</style>
<?php
    $title      = "";
    $txt_state  = "";
    
    switch($method){
        case "edit": $title = "Edit User";
            break;
        case "view": $title = "Info User";
            break;
    }
    switch($usuario['state']){
        case 1: $txt_state = "Active";
            break;
        case 2: $txt_state = "Locked";
            break;
        case 3: $txt_state = "Deleted";
            break;
        case 4: $txt_state = "First Login";
            break;
        case 5: $txt_state = "Reset";
            break;
    }
?>
<form name="frm_editUser" id="frm_editUser" method="post" action="index.php">
<?php if($_SESSION['usersession']['iduser'] != $iduser){ ?>
<div class="toolbar_right">
<ul>
    <li>
        <a href="index.php?option=com_users&controller=Users&action=dolist">
            <img src="../imagenes/icon-cancel.png" alt="Cancel" border="0" />
        </a>
    </li>
</ul>
</div>
<div style="clear:both; overflow: hidden"></div>
<?php } ?>
<span class="title_form" id="lblFormUsername"><label class="txt_title_form"><?php echo $title; ?></label></span>
<div id="frm_user">
    <div id="frm_img_user">
        <div class="row_reg">
            <?php if(($usuario['photo'] != NULL) || ($usuario['photo'] != "")){ ?>
            <img src="../files/photos/<?php echo $usuario['photo']; ?>" />
            <?php } else { ?>
            <img src="../files/photos/avatar.jpg" />
            <?php } ?>
            <?php if($edit){ ?><input type="file" name="fphoto" title="" alt="fileimage" /><?php } ?>
            <div style="clear:both; overflow: hidden"></div>
        </div>
    </div>
    <div id="frm_data_user">
        <div class="row_reg">
            <label class="lblform">Username:</label>
            <?php if($edit){ ?>
            <input class="form_input" type="text" name="newusername" size="20" value="<?php echo $usuario['username']; ?>" readonly />
            <?php }else{ ?>
            <label class="lblform_right"><?php echo $usuario['username']; ?></label>
            <?php } ?>
            <div style="clear:both; overflow: hidden"></div>
        </div>
        <div class="row_reg">
            <label class="lblform">Firstname:</label>
            <?php if($edit){ ?>
            <input class="form_input" type="text" name="firstname" title="Firstname" alt="texto" value="<?php echo $usuario['firstname']; ?>" />
            <?php }else{ ?>
            <label class="lblform_right"><?php echo $usuario['firstname']; ?></label>
            <?php } ?>
            <div style="clear:both; overflow: hidden"></div>
        </div>
        <div class="row_reg">
            <label class="lblform">Lastname:</label>
            <?php if($edit){ ?>
            <input class="form_input" type="text" name="lastname" title="Lastname" alt="texto" value="<?php echo $usuario['lastname']; ?>"/>
            <?php }else{ ?>
            <label class="lblform_right"><?php echo $usuario['lastname']; ?></label>
            <?php } ?>
            <div style="clear:both; overflow: hidden"></div>
        </div>
        
        <div class="row_reg">
            <label class="lblform">State:</label>
            <?php if($edit){ ?>
            <div>
            <select name="state" class="form_select">
                <option value=1 <?php if($usuario['state'] == 1) echo "selected"; ?>>Active</option>
                <option value=2 <?php if($usuario['state'] == 2) echo "selected"; ?>>Locked</option>
                <option value=3 <?php if($usuario['state'] == 3) echo "selected"; ?>>Deleted</option>
                <option value=4 <?php if($usuario['state'] == 4) echo "selected"; ?>>FLogin</option>
                <option value=5 <?php if($usuario['state'] == 5) echo "selected"; ?>>Reset</option>
            </select>
            </div>
            <?php }else{ ?>
            <label class="lblform_right"><?php echo $txt_state; ?></label>
            <?php } ?>
            <div style="clear:both; overflow: hidden"></div>
        </div>
        <?php if($edit){ ?>
        <div class="row_button">
            <input type="submit" name="submit" value="Change Name" class="btn_submit" id="btn_chgName" />
            <div style="clear:both; overflow: hidden"></div>
        </div>
        <?php } ?>
    </div>
</div>
<div style="clear:both; overflow: hidden"></div>
    <input type="hidden" name="option" value="com_users" />
    <input type="hidden" name="iduser" value="<?php echo $usuario['iduser']; ?>" />
    <input type="hidden" name="controller" value="Users" />
    <input type="hidden" name="action" value="updateUser" />
</form>
<?php if($edit){ ?>
<div id="change_user_passwd">
    <span class="title_form"><label for="title_div_chgpasswd" id="lblFormPassword" class="txt_title_form">Password</label></span>
    <div id="content_form_passwd">
    <form name="frm_chgPasword" id="frm_chgPasword" method="post" action="index.php">
        <div class="row_reg">
            <label for="lbloldpasswd" class="column_left">Old Password:<br/><small>(required)</small></label>
            <input class="form_input" type="password" id="oldpasswd" name="oldpasswd" value="" />
            <div style="clear:both; overflow: hidden"></div>
        </div>
        <div class="row_reg">
            <label for="lblnewpasswd" class="column_left">New Password:<br/><small>(required)</small></label>
            <input class="form_input" type="password" id="newpasswd" name="newpasswd" value="" />
            <div style="clear:both; overflow: hidden"></div>
        </div>
        <div class="row_reg">
            <label for="lblcheckpasswd" class="column_left">Confirm Password:<br/><small>(required)</small></label>
            <input class="form_input" type="password" id="retypepasswd" name="retypepasswd" value="" />
            <div style="clear:both; overflow: hidden"></div>
        </div>
        <div class="row_button">
            <!--<a href="#" onclick="validarFormulario('frm_chgPasword','?controller=Users&action=changePasswd',0);">Change Password</a>-->
            <input type="submit" name="submit" value="Change Password" class="btn_submit" id="enviarxxxx" />
            <div style="clear:both; overflow: hidden"></div>
        </div>
        <input type="hidden" name="option" value="com_users" />
        <input type="hidden" name="controller" value="Users" />
	<input type="hidden" name="action" value="changePasswd" />
        <input type="hidden" name="iduser" value="<?php echo $iduser; ?>" />
        <input type="hidden" name="chgPasswd" value="1" />
    </form>
    </div>
</div>
<?php } ?>