<script>
jQuery(document).ready(function() {
	$('select').select2();
	$.each($(".select2-container"), function (i, n) {
            $(n).next().show().fadeTo(0, 0).height("0px").css("left", "auto"); // make the original select visible for validation engine and hidden for us
            $(n).prepend($(n).next());
            $(n).delay(500).queue(function () {
                $(this).removeClass("validate[required]"); //remove the class name from select2 container(div), so that validation engine dose not validate it
                $(this).dequeue();
            });
        });	
	jQuery("#content").find("input").keyup(function() {
		if (jQuery(this).attr('id') == "role") {
			jQuery(this).val(jQuery(this).val().toUpperCase());
		}
	});
});

function submitForm(){
    $.each($(".select2-container"), function (i, n) {
            $(n).next().show().fadeTo(0, 0).height("0px").css("left", "auto"); // make the original select visible for validation engine and hidden for us
            $(n).prepend($(n).next());
            $(n).delay(500).queue(function () {
                $(this).removeClass("validate[required]"); //remove the class name from select2 container(div), so that validation engine dose not validate it
                $(this).dequeue();
            });
        });
        $("#validate").validationEngine('hide');
   if($("#validate").validationEngine('validate')){
    if(confirm('Press OK to continue...')){
        document.getElementById('validate').submit();
    }
   }	
}

function fctresetPwd(me){
    if (!$("#modalForgetPwd").length){
   $("html body").append('\n\
   <div id="modalForgetPwd" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> \n\
        <div class="modal-header">\n\
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>\n\
            <h3 id="myModalLabel">Forget Password</h3>\n\
        </div>\n\
        <div class="modal-body">\n\
            <form class="navbar-form pull-left">\n\
                <input required  minlength="1" data-id="<?php echo $umaster->fldid; ?>" placeholder="New Password" id="fgtNewPassword" type="text" class="span2">\n\
                <a class="btn-form btn-success-form" onclick="fgtpwdSubmit()">Submit</a>\n\
            </form>\n\
        </div>\n\
    </div>');     
         }
         
         $("#modalForgetPwd").modal("show");
}
function fgtpwdSubmit(){
    $("#modalForgetPwd").modal("hide");
    $.ajax({
              type: "POST",
              data: {
                  userID:$("#fgtNewPassword").attr("data-id"),
                  newpwd : $("#fgtNewPassword").val()
              },
              url: "<?php echo base_url() ?>admin/saveNewPwd",
              success: function(data) {
                   if($.trim(data)=="success"){
                      alertbox("Password has been succesfully reset",1);
                   }else {
                      alertbox("Fail to reset User",2);
                   }  
              }
       });
    }

</script>

<div id="content">                        
<div class="wrap">
                  
<div class="head">
	<div class="info">
			<!--<h1><?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
			<?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]</h1>-->
			<ul class="breadcrumb">
            	<li><a href='<?php echo base_url()."home" ?>'><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                <li><a href="home"><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                <li class="active"><?php echo $this->lang->line('title') ?></li>
            </ul>
	</div>
                        
	<div class="search">
		<form action="<?php echo base_url() ?>admin/search" method="post">
			<input name="search_text" type="text" placeholder="search..."/>                                
            <button type="submit"><span class="i-magnifier"></span></button>
		</form>
	</div>                        
</div>  <!-- Head -->                                                                  
                    
<div class="content">
                    
	<div class="row-fluid">
		<div class="span12">
			<?php 
				$hidden = array('order_time' => date('Y-m-d H-i-s'), 
					'fldid' => $umaster->fldid, 
					'password' => $umaster->password);
				$attrib = array('id'=>'validate'); 
				echo form_open_multipart('', $attrib, $hidden);?>
            	<div class="block">
                	<div class="head">
                    	<h2><?php echo $this->lang->line('title') ?></h2>
                        <div class="side fr">
                        <button class="btn-form btn-danger-form" onClick="clear_form('#validate');" type="button">Clear form</button>
                    </div>
				</div>
				<div class="content np">    
                	<div class="controls-row">
                    	<div class="span2">User ID:</div>
                   	<div class="span10">
                            	<?php 								
								$data = array(
									'name'=>'userid', 
									'id'=>'userid', 
									'class'=>'span3 validate[required],minSize[3]]',);
								$js='Readonly';	 
								echo form_input($data, $umaster->userid, $js); ?>
                                <span class="help-inline">Required, min size = 3</span>
                  </div>
                  </div>
                  <div class="controls-row">
                  	<div class="span2"><?php echo form_label('Name:','username');?></div>
                   	<div class="span10">
						<?php
							$data = array(
									'name'=>'username', 
									'id'=>'username', 
									'class'=>'span5 validate[maxSize[150]]',); 
							echo form_input($data, $umaster->username); ?>                       
                    </div>                        
                  </div>
                  <div class="controls-row">
                  	<div class="span2"><?php echo form_label('Position:','position');?></div>
                   	<div class="span10">
						<?php
							$data = array(
									'name'=>'position', 
									'id'=>'position', 
									'class'=>'span5 validate[maxSize[50]]',); 
							echo form_input($data, $umaster->position); ?>                       
                    </div>                        
                  </div>
                  <!--div class="controls-row">
                  	<div class="span2"><?php echo form_label('Department:','department');?></div>
                   	<div class="span5">
						<?php
							$preseldept = $umaster->department;
							$options[NULL] = '--Please Select--';
							if ($deptrec)
							foreach($deptrec as $row){
								$options[$row->code] = $row->description;
							}
							$js = "class='span10'";
							echo form_dropdown('department', $options, $preseldept, $js);
						?>       
                     </div>                
                   	 <div class="span5">
                  	 <div class="span2 TAR"><?php echo form_label('Section:','section');?></div>
                   		<div class="span10">
						<?php
							$preselsec = $umaster->section;
							$optsec[] = '--Please Select--';
							if ($secrec)
							foreach($secrec as $row){
								$optsec[$row->code] = $row->description;
							}
							$js = "class='span10'";
							echo form_dropdown('section', $optsec, $preselsec, $js);
						?>                       
                    </div>                        
                    </div>                        
                  </div-->
                  <div class="controls-row">
                  	<div class="span2"><?php echo form_label('Office Phone:','phone_off');?></div>
                   	<div class="span10">
						<?php
							$data = array(
									'name'=>'phone_off', 
									'id'=>'phone_off', 
									'class'=>'span5 validate[maxSize[30]]',); 
							echo form_input($data, $umaster->phone_off); ?>                       
 							 <span class="help-inline"><?php echo $this->lang->line('example') ?>: +603-2261 4180</span>
                     </div>                
                  </div>
                  <div class="controls-row">
                  	<div class="span2"><?php echo form_label('Mobile:','phone_mobile');?></div>
                   	<div class="span10">
						<?php
							$data = array(
									'name'=>'phone_mobile', 
									'class'=>'span5 validate[maxSize[30]]',); 
							echo form_input($data, $umaster->phone_mobile); ?>                       
 							 <span class="help-inline"><?php echo $this->lang->line('example') ?>: 601-9339 3995</span>
                    </div>                        
                  </div>
                  <div class="controls-row">
                  	<div class="span2">Email:</div>
                   	<div class="span10">
						<?php
							$data = array(
									'name'=>'email', 
									'class'=>'span5 validate[custom[email]]',); 
							echo form_input($data, $umaster->email); ?>                       
							<span class="help-inline"><?php echo $this->lang->line('example') ?>: sps@salihin.com.my</span>
                    </div>                        
                  </div>
                  <div class="controls-row">
                  	<div class="span2"><?php echo form_label($this->lang->line('language'),'language');?></div>
                   		<div class="span5">
						<?php
							$presellang = $umaster->language;
							$option = '';
							$option[NULL] = $this->lang->line('select');
							foreach($language as $row){
								$option[$row->code] = $row->description;
							}
							$js = "class='span10 validate[required]'";
							echo form_dropdown('language', $option, $presellang, $js);
						?>                       
                    </div>                        
                  </div>
                  <div class="controls-row">
                  	<div class="span2"><?php echo form_label($this->lang->line('userfile'),'userfile');?></div>
                   		<div class="span5">
						<?php
							$data = array(
									'name'=>'userfile', 
									'id'=>'userfile',
									'value'=>''); 
							echo form_upload($data, set_value('userfile')); ?>                       
                    </div>
                   		<div class="span5">
                 	<div id="gallery">
                        	<div class="pic" align="center">
                            	<?php
                            	$path = parse_url(base_url(). 'images/thumbs/' . $umaster->fldid . '.JPG', PHP_URL_PATH);
								//To get the dir, use: dirname($path)
								//echo $_SERVER['DOCUMENT_ROOT'] . $path; 
                            	if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $path)) {
								    $image = base_url(). 'images/thumbs/' .'default-user.png';
								}else{
									$image = base_url(). 'images/thumbs/' . $umaster->fldid . '.JPG';
								}
								?>
                            	<a class="fancybox" href="<?php echo $image; ?>">
                                	<img class="img-polaroid" style="width:50px;" src="<?php echo $image; ?>" />
                                </a>
                            </div>
                    </div>
                    </div>
                 </div>  <!-- row control -->                      
			</div>
            <div class="footer">
            	<div class="side fr">
                	<div class="btn-group">
                        <?php 
                                                        $data = array(
                                                                        
									'name'=>'validat', 
									'class'=>'btn-form btn-warning-form',
									'onClick'=>"$('#validate').validationEngine('hide');"); 
							echo form_button($data,'Hide prompts');
                                                        
                                                        $data = array(
                                                                        'style' =>'margin-right: 5px; margin-left: 10px;',
									'name'=>'resetPwd', 
									'class'=>'btn-form btn-success-form',
									'onClick'=>"fctresetPwd(this)"); 
							echo form_button($data,'Reset Password');
                                                        
							
                                                        
							$data = array(
									'name'=>'mysubmit', 
									'class'=>'btn-form btn-success-form');
                                                        $js='onclick="return confirm(\'Press OK to continue...\')"';
							//$js='onclick="submitForm()"';
							echo form_submit($data,'Submit', $js);
							?>
                    </div>
                </div>
            </div>                                    
		</div>
	</form>
</div>
</div>                        
</div>
</div>
</div>
