<script type="text/javascript">
$(document).ready(function(){
	$("#frm-giftcard").submit(function(e){
            if(!validate_giftcard()){
                e.preventDefault();
            }
	});
        $("#giftcard_code").blur(function(){
            var code = $("#giftcard_code");
            var codemsg = $("#msg_giftcard_code");
            if(code.val()==""){
                code.addClass('error');code.focus();codemsg.html('Please enter code').show();
                return false;
            }
            if($("#giftcard_id").length > 0){var giftcard_id = $("#giftcard_id").val();
            }else{var giftcard_id = '';}
                $("#submit").prop('disabled', true);
            $.ajax({
                url: "giftcardadd.php",
                data: 'act=validate_code&code='+code.val()+'&giftcard_id='+giftcard_id,
                method: 'POST',
                success: function(msg){
                    if(msg!=''){
                        code.addClass('error');code.focus();codemsg.html(msg).show();
                        return false;
                    }else{
                        $("#submit").prop('disabled', false);
                        code.removeClass('error');codemsg.hide();
                    }
                }
            });
	});
});
function validate_giftcard(){
    var title = $("#giftcard_title");var titlemsg = $("#msg_giftcard_title");
    var cost = $("#giftcard_cost");var costmsg = $("#msg_giftcard_cost");
    var code = $("#giftcard_code");var codemsg = $("#msg_giftcard_code");
    var image = $("#giftcard_image");var imagemsg = $("#msg_giftcard_image");
    var logo = $("#hidden_logo");
    
    
    if(title.val()==''){title.addClass('error');title.focus();titlemsg.html('Please enter title').show();
     return false;
    }else{title.removeClass('error');titlemsg.hide();}
    
    if(code.val()==''){
          code.addClass('error');code.focus();codemsg.html('Please enter code').show();return false;
    }else{code.removeClass('error');codemsg.hide();}

    if(cost.val()==''){cost.addClass('error');cost.focus();costmsg.html('Please enter cost').show();return false;
    }else{cost.removeClass('error');costmsg.hide();}

    if(logo.val()=='' && image.val()==''){image.addClass('error');image.focus();imagemsg.html('Please enter image').show();return false;
    }else{image.removeClass('error');imagemsg.hide();}
    
    return true;
}

</script>
<div class="breadcrumb">
    <h1>Giftcards</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Add New Giftcard</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">Add New Giftcard</div>
                <form action="" id='frm-giftcard' method="post" enctype="multipart/form-data">
                    <?php if(isset($giftcardDetail->giftcard_id) && $giftcardDetail->giftcard_id!=0) { ?>
                       <input type="hidden" id="giftcard_id" name="giftcard_id" value="<?php echo $giftcardDetail->giftcard_id ?>" />
                    <?php } ?>
                    <div class="row">
                    	<div class="col-md-6 form-group mb-3">
                            <label for="giftcard_title">Title <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="giftcard_title" name="giftcard_title" value="<?php echo $giftcardDetail->giftcard_title; ?>" placeholder="Enter title">
                            <div class="invalid-tooltip" id="msg_giftcard_title"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="giftcard_code">Code <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="giftcard_code" name="giftcard_code" value="<?php echo $giftcardDetail->giftcard_code; ?>" placeholder="Enter unique code">
                            <div class="invalid-tooltip" id="msg_giftcard_code"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="giftcard_cost">Cost <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="giftcard_cost" name="giftcard_cost" value="<?php echo $giftcardDetail->giftcard_cost; ?>" placeholder="Enter Gift Card Cost">
                            <div class="invalid-tooltip" id="msg_giftcard_cost"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="giftcard_dob">Image <span class="asterisk">*</span></label>
                            <input type="file" class="form-control col-md-6" id="giftcard_image" name="giftcard_image" />
                            <?php if($giftcardDetail->giftcard_image!='' && file_exists(DIR_UPLOAD_GIFT.$giftcardDetail->giftcard_image)){ ?>
                                <img src="<?php echo DIR_UPLOAD_GIFT_SHOW.$giftcardDetail->giftcard_image ?>" width="100px" />
                            <?php } ?>
                            <input type="hidden" name="hidden_logo" id="hidden_logo" value="<?php echo $giftcardDetail->giftcard_image ?>">
                            <div class="invalid-tooltip" id="msg_giftcard_image"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="giftcard_gender">Tango Card Id </label>
                            <input type="text" class="form-control" id="giftcard_tangoCardId" name="giftcard_tangoCardId" value="<?php echo $giftcardDetail->giftcard_tangoCardId; ?>" placeholder="Enter Tango Card Id">
                            <div class="invalid-tooltip" id="msg_giftcard_tangoCardId"></div>
                        </div>
                        
                        <div class="col-md-3 form-group mb-3">
                            <label class="control-label">Status</label>
                            <div class="controls">

                            <label class="switch switch-primary mr-3">
                                <input type="checkbox" id="giftcard_status" name="giftcard_status" <?php echo ($giftcardDetail->giftcard_status=='1') ? "checked='checked'" : "" ?>>
                                <span class="slider"></span>
                            </label>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Submit">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>