<? global $vis_language;?>
<script>
	$(document).ready(function(){
		function change_password_strength(strengthPercentage, is_valid){
			$("#password_strength_per").val(strengthPercentage);
			var show_password_result;
				if(strengthPercentage>=0 && strengthPercentage<50){show_password_result='<span class="label vh-yellow-bg"> <?=$vis_language['TXTWEAK'];?> </span>';}
				else if(strengthPercentage>=50 && strengthPercentage<70){show_password_result='<span class="label vh-green-bg"> <?=$vis_language['TXTMEDIUM'];?> </span>';}
				else if(strengthPercentage>=70 && strengthPercentage<90){show_password_result='<span class="label vh-orange-bg"> <?=$vis_language['TXTSTRONG'];?> </span>';}
				else if(strengthPercentage>=90 && strengthPercentage<=100){show_password_result='<span class="label vh-red-bg"> <?=$vis_language['TXTVERYSTRONG'];?> </span>';}
				if(is_valid=='not_allowed') $('#password_strenght_id').html('<? echo $vis_language['TXTPASSWORDSRENGTH']."&nbsp;&nbsp;"; ?> '+show_password_result+ '&nbsp;&nbsp; <?=$vis_language['TXTNOTALLOWED']?>');
				else if(is_valid=='allowed') $('#password_strenght_id').html('<? echo $vis_language['TXTPASSWORDSRENGTH']."&nbsp;&nbsp;"; ?> '+show_password_result+ '&nbsp;&nbsp; <?=$vis_language['TXTALLOWED']?>');
				return true;
		}

		$('#vis_password').pStrength({
			'changeBackground'          : false,
			'onPasswordStrengthChanged' : function(passwordStrength, strengthPercentage) {
				if(passwordStrength!=0){change_password_strength(strengthPercentage,'not_allowed');}
			},
			'passwordValidFrom': '<?=$security_password_details[0]['content']?>',
			'onValidatePassword': function(strengthPercentage) {
				change_password_strength(strengthPercentage,'allowed');
			}
		});
	});
</script>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
    <div class="col-sm-6">
        <h3 class="m-b-xs text-black"><? echo $vis_language['TXTCLIENTS']; ?></h3>
        <ul class="breadcrumb bg-empty no-border m-b-xxs no-padder">
            <li><a class="link" href="#/home/quick_view/<? echo $vis_language['TXTHOME']; ?>"><? echo $vis_language['TXTHOME']; ?></a></li>
            <li><a class="link" href="#/client/view_clients/<? echo $vis_language['TXTCLIENTS']; ?>" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTCLIENTS']; ?>',{'vis_module':'client','vis_operation':'view_clients'});"><? echo $vis_language['TXTCLIENTS']; ?></a></li>
            <? if(isset($operation['vis_client_id']) && $operation['vis_client_id'] !=0){ ?><li><a class="link" href="#/client/client_details/<? echo $client_details[0]['first_name']." ".$client_details[0]['last_name']."/".$client_details[0]['client_id']; ?>" ><? echo $client_details[0]['first_name'].' &lt; '.$client_details[0]['email'].' &gt;'; ?></a></li><? } ?>
            <li class="active"><? echo (isset($operation['vis_client_id']) && $operation['vis_client_id'] !=0)?$vis_language['TXTADDCONTACT']:$vis_language['TXTADDCLIENT']; ?></li>
        </ul>
    </div>
</section>
<section class="padder">
    <section class="panel panel-default">
        <header class="panel-heading sub_header"><? echo (isset($operation['vis_client_id']) && $operation['vis_client_id'] !=0)?$vis_language['TXTADDCONTACT']:$vis_language['TXTADDCLIENT']; ?></header>
        <div class="panel-body">
            <form class="form-horizontal" role="form" id="vis_new_client_form" name="vis_new_client_form" method="post">
				<input type="hidden" name="vis_client_id" id="vis_client_id" value="<? echo $operation['vis_client_id']; ?>" />
				<div class="form-group">
					<label for="vis_domain" class="col-sm-2 control-label"><? echo $vis_language['TXTDOMAIN']; ?></label>
					<div class="col-sm-10">
						<select class="form-control selectpicker" name="vis_domain" id="vis_domain"<? if(count($domain_details)>10) echo ' data-live-search="true"';?>>
						<?
							for($i=0;$i<count($domain_details);$i++){
								echo '<option value="'.$domain_details[$i]['domain_id'].'">'.$domain_details[$i]['domain_name'].'</option>';
							} ?>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTFIRSTNAME']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_firstname" id="vis_firstname">
					</div>
				</div>
				<div class="form-group">
					<label for="vis_lastname" class="col-sm-2 control-label"><? echo $vis_language['TXTLASTNAME']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_lastname" id="vis_lastname">
					</div>
				</div>

                <div class="form-group">
                    <label class="col-sm-2 control-label p-d-sm"><?= $vis_language['TXTCLIENTTYPE']; ?></label>
                    <div class="col-sm-10">
                         <div class="radio i-checks m-r-lg pull-left"><label>
                          <input type="radio" name="vis_client_type" <?php echo ($client_details['client_type']==0)?'checked="checked"':''?> id="vis_client_type1" value="0"><i></i>
                          <?= $vis_language['TXTEMAILCLIENT']; ?></label>  </div>
                          <div class="radio i-checks m-r-lg pull-left"><label>
                          <input type="radio"  name="vis_client_type" <?php echo ($client_details['client_type']==1)?'checked="checked"':''?> id="vis_client_type2" value="1"><i></i>
                           <?= $vis_language['TXTCALLCLIENT']; ?></label>  </div>
                    </div>
                </div>
                
                 <div class="form-group">
			<label class="col-sm-2 control-label p-d-sm"><?= $vis_language['TXTISMANAGER']; ?></label>
			<div class="col-sm-10">
				 
                  <div class="radio i-checks m-r-lg pull-left"><label>
                  <input type="radio"  name="vis_is_manager" <?php echo ($client_details['is_manager']==1)?'checked="checked"':''?> id="vis_is_manager" value="1"><i></i>
                   <?= $vis_language['TXTYES']; ?></label>  </div>
                   <div class="radio i-checks m-r-lg pull-left"><label>
                  <input type="radio" name="vis_is_manager" <?php echo ($client_details['is_manager']==0)?'checked="checked"':''?> id="vis_is_manager" value="0"><i></i>
                  <?= $vis_language['TXTNO']; ?></label>  </div>
			</div>	
		</div>
                
				<div class="form-group">
					<label for="vis_email" class="col-sm-2 control-label"><? echo $vis_language['TXTEMAIL']; ?></label>
					<div class="col-sm-10">
						<input type="email" class="form-control input-sm" data-type="email" data-required="true" name="vis_email" id="vis_email">
					</div>
				</div>
				<div class="form-group">
					<label for="vis_username" class="col-sm-2 control-label"><? echo $vis_language['TXTUSERNAME']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm" name="vis_username" id="vis_username">
					</div>
				</div>
                <input type="hidden" name="vis_auto_pass" value="1" id="vis_auto_pass" value="1">
				<div class="form-group" id="org_id">
					<label class="col-sm-2 control-label"><? echo $vis_language['TXTORGANIZATION']; ?></label>
					<div class="col-sm-10">
					    <!--<input type="text" class="form-control input-sm" name="vis_organization" id="vis_organization" onkeypress="tokIp()" onclick="tokIp()">-->
						<input type="text" class="form-control input-sm" name="vis_organization" id="vis_organization" onkeypress="tokIp($('#vis_domain option:selected').val(),0)" />
						<input type="hidden" name="vis_group" id="vis_group">
					</div>
					<script type="text/javascript">
						function tokIp(d,m){
							//var d=$('#vis_domain option:selected').val();
							$("#vis_organization").tokenInput(
								"index.php?vis_module=client&vis_operation=get_groupname&vis_domain="+d+"&vis_add_client_m=1",
								{
									theme: "facebook",
									searchDelay: 300,
									minChars: 2,
									queryParam: "vis_data",
									propertyToSearch: "group_name",
									tokenValue: "group_name",
									tokenLimit: 1,
									noResultsText: "<? echo $vis_language['TXTNOMATCHFOUND']; ?>",
									preventDuplicates: true,
									resultsFormatter: function(item) {
										return "<li>" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'><i class='vh vh-organisation'></i> " + item.group_name + "</div></div></li>";
									},
									tokenFormatter: function(item) {
										return "<li><p>" + item.group_name + "</p></li>";
									},
									onAdd: function(item)
									{
										$('#vis_group').val(item.id);
										if(m!=0){
											$(".token-input-list-facebook").prev().remove();
										}
									}
								}
							);
							$("div.token-input-dropdown-facebook").css('width', $(".token-input-list-facebook").width() + 2 + 'px');
							//$("#vis_organization").tokenInput("add", {id: '<?=$client_group[0]['group_id'];?>', group_name: "<?=$client_group[0]['group_name']; ?>"});
							$("#token-input-vis_organization").parent().css('width','100%');
							if(m!=0){
								$(".token-input-list-facebook").prev().remove();
							}
						}
					</script>
				</div>
				<div class="form-group" id="vis_contact">
					<label for="PhoneNumber" class="col-sm-2 control-label"><? echo $vis_language['TXTCONTACTNUMBER']; ?></label>
					<div class="col-sm-10">
						<input type="tel" class="form-control input-sm" name="vis_contact_number" id="vis_contact_number" data-type="phone"placeholder="<? echo $vis_language['TXTPHONEEG']; ?>">
						</div>
				</div>
				<div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['MSGSENDREGISTRATIONEMAIL']; ?> </label>
               <div class="col-sm-10">
                  <label class="checkbox-inline i-checks">
                  <input type="checkbox" name="vis_sent_mail" value="1" id="vis_sent_mail" ><i></i>
                  </label>
               </div>
            </div>
				<?
				if(isset($operation['vis_client_id']) && $operation['vis_client_id'] !=0){ ?>
					 <div class="b-2x b-t m-b-md"></div>
                        <div class="form-group">
                          <div class="col-sm-2">
                             <label class="checkbox-inline i-checks pull-right">
                                <input type="checkbox" name="vis_openticket" id="vis_openticket" value="1" checked="checked"><i></i>
                             </label>
                          </div>
                          <div class="col-sm-10"><label class="control-label"><? echo $vis_language['TXTVIEWREPLYSELFTICKET']; ?></label></div>
                       </div>
                        <div class="form-group">
                          <div class="col-sm-2">
                             <label class="checkbox-inline i-checks pull-right">
                                <input type="checkbox" name="vis_billingacess" id="vis_billingacess" value="1"><i></i>
                             </label>
                          </div>
                          <div class="col-sm-10"><label class="control-label"><? echo $vis_language['TXTBILLINGACCESS']; ?></label></div>
                       </div>
                        <div class="form-group">
                            <div class="col-sm-2">
                               <label class="checkbox-inline i-checks pull-right">
                               <input type="checkbox" name="vis_view_tickets" id="vis_view_tickets" value="1" ><i></i>
                               </label>
                            </div>
                            <div class="col-sm-10"><label class="control-label"><? echo $vis_language['TXTTKTPSTGRM']; ?></label></div>
                       </div>
                       <div class="form-group">
                          <div class="col-sm-2">
                             <label class="checkbox-inline i-checks pull-right">
                             <input type="checkbox" name="vis_replyticket" id="vis_replyticket" value="1" ><i></i>
                             </label>
                          </div>
                          <div class="col-sm-10"><label class="control-label"><? echo $vis_language['TXTRTKTPSTGRM']; ?></label></div>
                       </div>
                    <? }?>
					<?php echo $custom_field_var;?>
            </form>
           <div class="b-2x b-t m-b-md"></div>
				<div class="col-sm col-sm-offset-2">
					  <button type="button" class="btn btn-primary" onclick="$(this).visExecution('submit_form',{'vis_module':'client', 'vis_operation':'add_client', 'vis_form':'vis_new_client_form','vis_parent_client_id':'<? echo $client_details[0]['client_id']; ?>'})"><? echo $vis_language['TXTADD']; ?></button>
				</div> <br/>  </div>
    </section>
</section>
<script>

tokIp(1,0);

$(function(){
	$("#vis_domain").change(function(){
		var d = $(this).val();
		tokIp(d,1);
	});
});

$(".selectpicker").selectpicker();
enter_pass();
function enter_pass()
{
  if ($('#vis_auto_pass').is(":checked"))
   {
    $('#vis_pass').hide();
   }
   else
   {
     $('#vis_pass').show();
   }
}
 if ($('#vis_client_type1').is(":checked"))
   {
    $('#vis_contact').hide();
   }
	$(document).ready(function () {
	   $('#vis_client_type1').click(function () {
		  $('#vis_contact').hide();
   });
   $('#vis_client_type2').click(function () {                   
		 $('#vis_contact').show();
	});
  });

function toggleType() {
    var obj = document.getElementById('vis_password');
    var obj1 = document.getElementById('vis_confirm');
    if (obj.type == 'text' && obj1.type == 'text') {
        obj.type = 'password';
        obj1.type = 'password';
    } else {
        obj.type = 'text';
        obj1.type = 'text';
    }
}
</script>
</section>
