
<script type="text/javascript" src="<?php echo GLOBAL_ADMIN_JS_PATH; ?>highslide/highslide-with-gallery.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo GLOBAL_ADMIN_JS_PATH; ?>highslide/highslide.css" />
<script type="text/javascript">
    hs.graphicsDir = '<?php echo GLOBAL_ADMIN_JS_PATH; ?>highslide/graphics/';
    hs.align = 'center';
    hs.transitions = ['expand', 'crossfade'];
    hs.wrapperClassName = 'dark borderless floating-caption';
    hs.fadeInOut = true;
    hs.dimmingOpacity = .75;

    // Add the controlbar
    if (hs.addSlideshow) hs.addSlideshow({
        slideshowGroup: 'group1',
        interval: 5000,
        repeat: false,
        useControls: true,
        fixedControls: 'fit',
        overlayOptions: {
            opacity: .6,
            position: 'bottom center',
            hideOnMouseOut: true
        }
    });
</script>
<script type="text/javascript">
    function validate()
    {
        if(trim(document.getElementById('var_title').value)== "")
        {
            alert("Please enter title.");
            document.getElementById('var_title').focus();
            return false;
        }
        var j=document.getElementById('link1').checked;
        var k=document.getElementById('link2').checked;
        if((j==false)&&(k==false))
        {
            alert("Please select URL.")
            document.getElementById('link1').focus();
            return false;
        }
        if(valButton(document.frmfilloutform.link)=='i' && (document.getElementById("fk_pages").value=="" ))
        {
            alert("Please select page.");
            document.getElementById('link1').focus();
            return false;
        }
        if(valButton(document.frmfilloutform.link)=='e' && (document.getElementById("var_link").value=="" ))
        {
            alert("Please enter URL.");
            document.getElementById('link2').focus();
            return false;
        }
    

//        if(!isUrl(document.getElementById("var_link").value) && document.getElementById("var_link").value !="" )
//        {
//            alert("Please enter a valid URL.");
//            document.getElementById('var_link').focus();
//            return false;
//        }
        
        
        else if(document.getElementById('Filedata').value=='' && document.getElementById('hidvar_image').value == '')
        {
            alert("Please upload image.");
            document.getElementById('Filedata').focus();
            return false;
        }

        else if(document.getElementById('Filedata').value != '' && !LimitAttach(document.getElementById('Filedata').value,'Filedata'))
        {
            alert('Please upload only *.jpg, *.jpeg, *.png, *.bmp and *.gif image');
            document.getElementById('Filedata').focus();
            return false;
        }
     
        else if(document.getElementById('int_displayorder').value == "")
        {
            alert("Please enter banner display order.");
            document.getElementById('int_displayorder').focus();
            return false;
        }
        else if(document.getElementById('int_displayorder').value==0)
        {
            alert("Please enter banner display order.");
            document.getElementById('int_displayorder').focus();
            return false;
        }

        document.getElementById('h_save').value ='T';
        return true;
        

    }
    function valButton(btn) {
        var cnt = -1;
        for (var i=btn.length-1; i > -1; i--)
        {
            if (btn[i].checked) {cnt = i; i = -1;}
        }
        if (cnt > -1) return btn[cnt].value;
        else return null;
    }

    function isUrl(s) {
        var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
        return regexp.test(s);
    }
    
    
    function showlinkdiv(val)
    {
        //alert(val);
        if(val=="i")
        {
            document.getElementById("Ilink").style.display = "";
            document.getElementById("Elink").style.display = "none";
        }
        else if(val=="e")
        {
            document.getElementById("Ilink").style.display = "none";
            document.getElementById("Elink").style.display = "";
        }

        else
        {
            document.getElementById("Ilink").style.display = "none";
            document.getElementById("Elink").style.display = "none";
        }
    }

    function LimitAttach(file)
    {
        var extArray = new Array(".jpg", ".png", ".bmp",".gif",".jpeg");
        allowSubmit = false;
        if (!file) return;
        while (file.indexOf("\\") != -1)
            file = file.slice(file.indexOf("\\") + 1);
        ext = file.slice(file.indexOf(".")).toLowerCase();
        for (var i = 0; i < extArray.length; i++) {
            if (extArray[i] == ext) { allowSubmit = true; break; }
        }
        if (allowSubmit) return true;
        else
            return false;
    }
   
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#fk_pages').change(function () {
            var pagetypeid = $("#fk_pages option:selected").data('pagetypeid');
            document.getElementById('hidchr_pagetypeid').value = pagetypeid;
        });
    });
</script>



<?php if ($_REQUEST['action'] != '') $action = ucwords($_REQUEST['action']); ?>
<div class="breadcrumbs"><a href="index.php">Home </a>&nbsp;>&nbsp;&nbsp;<a href="index.php?module=pages">Manage Pages </a> &nbsp;>&nbsp;  <a href="index.php?module=banner">Manage Banners</a>&nbsp; >&nbsp; <span class="current"><?= $action ?> Banner</span>  </div>
<div class="add-new-user-title">
    <h2><img alt="add-new-listing" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>/add-new-user-icon.png"><?= $action ?> Banner</h2>
</div>
<?= $messagebox ?>
<form  name="frmfilloutform"  id="frmfilloutform" action="<?= $frmaction ?>" method="post" onSubmit="return validate();" enctype="multipart/form-data" >

    <input type="hidden" name="h_save" id="h_save" value="T">
    <input type="hidden" name="fk_modules" id="fk_modules" value="<?php echo $fk_modules ?>">
    <input name="hidchr_validthumb" type="hidden" id="hidchr_validthumb" value="<?= $row['var_filepath']; ?>" />
    <input name="hidvar_imagepath" type="hidden" id="hidvar_imagepath" value="<?= $row['hidchr_validthumb']; ?>" />
    <input name="hidvar_link" type="hidden" id="hidvar_link" value="<?= $row['var_link']; ?>" />
    <input name="hidvar_image" type="hidden" id="hidvar_image" value="<?= $row['var_imagepath']; ?>" />
    <input type="hidden" name="old_displayorder" id="old_displayorder" value="<?= $row['int_displayorder'] ?>">
    <input name="hidchr_validphoto" type="hidden" id="hidchr_validphoto" value="<?php echo $row['chr_validphoto']; ?>" />
    <input name="hidchr_cropphoto" type="hidden" id="hidchr_cropphoto" value="<?php echo $row['chr_cropphoto']; ?>" />
    <input name="hidchr_pagetypeid" type="hidden" id="hidchr_pagetypeid" value="<?php echo $row['fk_pagetypeid']; ?>" />

    <?php
    if ($row['int_displayorder'] != '') {
        $int_disporder = $row['int_displayorder'];
    } else {
        $int_disporder = '1';
    }

    if ($row['chr_publish'] != '') {
        $hidden_chr_publish = $row['chr_publish'];
    } else {
        $hidden_chr_publish = 'Y';
    }

    if ($_REQUEST['action'] == 'edit') {
        $sql = "UPDATE " . DB_PREFIX . "banner SET chr_read='Y' where int_glcode=" . $_REQUEST['eid'];
        $banner->configObj->glDbObj->query($sql);
    }
    ?>

    <div class="web-booking-main">
        <div class="grid-list-subtitle-bg" style="margin-top:10px; cursor:pointer" onClick="javascript:expandcollapsepanel('asignbanner');" >
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="left" valign="top" class="grid-td-left">Banner Information</td>
                </tr>
            </table>
        </div>
        <div class="information-white-bg" id="asignbanner" >
            <div class="clear"></div>
            <div class="grid-list-inner-table-text">
                <table width="100%" border="0" cellspacing="3" cellpadding="3">

                    <tr>
                        <td width="156" align="left" valign="top" class="add-new-user-text" >Title: <span>(required)</span> </td>
                        <td width="850" align="left" valign="top"><input name="var_title" type="text" class="add-new-user-textarea" style="width:55%;" id="var_title" value="<?= $row['var_title']; ?>" maxlength="100"   />

                        </td>
                    </tr>

<!--                    <tr>
                        <td width="156" align="left" valign="top" class="add-new-user-text">Display Banner In : <span>(required)</span></td>
                        <td width="856" align="left" valign="top">
                            <input name="link1" type="radio" id="link11" value="d"/>Desktop
                            <input name="link1" type="radio" id="link21" value="m" />Mobile
                        </td>

                    </tr>-->
                    
<!--                    <tr>
                        <td width="270" align="left" valign="top" class="add-new-user-text">Display Banner In:  </td>
                        <td width="" colspan="3" align="left"  valign="top">                   
                            <input name="banner_type" style="margin :5px;" type="radio" <?= ($row["banner_type"] == 'D' ? 'checked' : 'checked') ?>  id="banner_type" value="D"/>Desktop
                            <input name="banner_type" style="margin :5px;"  type="radio"  <?= ($row["banner_type"] == 'M' ? 'checked' : '') ?> id="banner_type" value="M"/>Mobile
                        </td>
                    </tr>-->
                    
                    <tr>
                        <td width="156" align="left" valign="top" class="add-new-user-text" >Caption:</td>
                        <td width="856" align="left" valign="top">
                            <textarea id="var_caption" name="var_caption" class="textarea2" maxlength="150" style="width:55%;" onkeydown="CountLeft(this.form.var_caption,this.form.description_left,150);" onkeyup="CountLeft(this.form.var_caption,this.form.description_left,150);"><?= $row['var_caption']; ?></textarea>
                            <input disabled="disabled" type="text" name="description_left" value="<?= (150 - strlen($row['var_caption'])) ?>" class="add-new-user-textarea" style="width:35px;"/><span valign="bottom" style="color:#000000;"> characters left</span>

                        </td>
                    </tr>
                    <tr>
                        <td width="156" align="left" valign="top" class="add-new-user-text">Link : <span>(required)</span></td>
                        <td width="856" align="left" valign="top">
                            <input name="link" type="radio" id="link1" <?= $checkedi ?> value="i" onClick="showlinkdiv(this.value);"/>Internal Link
                            <input name="link" type="radio" id="link2" <?= $checkede ?> value="e" onClick="showlinkdiv(this.value);" />External Link
                        </td>
                        <?php
                        if ($row['fk_pageid'] != 0 && $row['var_link'] == '') {
                            $style = 'style="display:none"';
                            $style1 = 'style=""';
                        } else if ($_REQUEST['action'] == 'add') {
                            $style = 'style="display:none"';
                            $style1 = 'style="display:none"';
                        } else {
                            $style = 'style=""';
                            $style1 = 'style="display:none"';
                        }
                        ?>
                    </tr>
                    <tr <?php echo $style1; ?>  id="Ilink">
                        <td width="156" >
                            Internal Link :<span>(required)</span> </td>
                        <td width="800" align="left" style="float:left;" valign="top">&nbsp;&nbsp;
                            <?= $pagetree ?>
                        </td>
                    </tr>
                    <tr <?php echo $style; ?>  id="Elink">
                        <td width="156" align="left" valign="top" style="padding-left: 8px;" class="add-new-user-text">External Link : <span>(required)</span> </td>
                        <td width="800" align="left" valign="top">&nbsp;&nbsp;
                            <input name="var_link" type="text" style="float:left;" id="var_link" class="add-new-user-textarea" value="<?= $row['var_link'] ?>" /><span>(e.g. : http://google.com)</span>
                        </td>
                    </tr>

                    <tr>
                        <td width="156" align="left" valign="top" class="add-new-user-text">Upload Image: <span>(required)</span></td>
                        <td width="856" align="left" valign="middle">

                            <input name="Filedata" type="file" id="Filedata" style="float:left;" />
                            <div style="float:left;margin-left: 10px;" id="divdelbro">

                                <?php
                                if ($row['var_imagepath'] != "") {
                                    ?>
                                    <a href="<?php echo "../upimages/banner/images/" . 'thumb_' . $row['var_imagepath']; ?>" onClick="return hs.expand(this);" ><img src="<?php echo "../upimages/banner/images/thumb_" . $row['var_imagepath']; ?>" width="20" height="20" border="1" align="absmiddle" id="myimage"   title="view banner" ></a>
                                <?php }
                                ?>
                            </div>
                        </td>

                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2"><span> (Width * Height)=<?php echo'(' . BANNER_THUMB_WIDTH . 'px ' ?>  x  <?php echo '' . BANNER_THUMB_HEIGHT . 'px' . ')' ?></span>&nbsp;<span>(Only .jpg, .png, .bmp, .gif & .jpeg Image Formats are supported.)</span></td>
                    </tr>
                    <?php
//                    $selected_chk = '';
//                    if ($row['var_banner'] == 'Y') {
//                        $selected_chk = "checked=''";
//                    }
                    ?>
<!--                    <tr>
                        <td width="200" align="left" valign="top" class="add-new-user-text"> Display Banner In Mobile: </td>
                        <td width="724" align="left" valign="top">
                            <input type="checkbox"  name="var_banner" value="Y" id="var_banner" <?php echo $selected_chk; ?> style="float: left">

                        </td>
                    </tr>-->
                </table>
            </div>
        </div>

        <div class="clear"></div>


        <div class="grid-list-subtitle-bg" style="margin-top:10px; cursor:pointer" onClick="javascript:expandcollapsepanel('asignbannerdisplay');" >
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="left" valign="top" class="grid-td-left">Display Information</td>
                </tr>
            </table>
        </div>

        <div class="information-white-bg" id="asignbannerdisplay" >
            <div class="clear"></div>
            <div class="grid-list-inner-table-text">
                <table width="100%" border="0" cellspacing="3" cellpadding="3">

                    <tr>
                        <td width="17%" align="left" valign="top" class="add-new-user-text">Display Order :<span>(required)</span></td>
                        <td colspan="2" align="left" valign="top">
                            <input name="int_displayorder" type="text" class="date-textarea" id="int_displayorder" value="<?= $int_disporder; ?>" maxlength="5" onkeypress="return KeycheckOnlyNumeric(event);"  />
                        </td>
                    </tr>

                    <input name="int_displayorder" type="hidden"  id="int_displayorder" value="<?= $int_disporder; ?>"   />

                    <tr>
                        <td height="30" width="17%" align="left" valign="top" class="add-new-user-text">Display:<span>(required)</span></td>
                        <td height="30"  width="85" align="left" valign="middle" class="add-new-user-text2"><table width="98%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="">
                                        <?php if ($row['chr_publish'] == 'Y') { ?>
                                            <input type="radio" name="chr_publish" id="chr_publishY" value="Y" checked="checked" class="form-rediobutton " />
                                        <?php } else { ?>
                                            <input type="radio" name="chr_publish" id="chr_publishY" value="Y"  checked="checked" class="form-rediobutton " /><?php } ?>
                                        <a href="javascript:" onClick="if(document.getElementById('chr_publishY').checked!=true) document.getElementById('chr_publishY').checked=true;" style="text-decoration:none;">
                                            <td>Yes</td></a></td>
                                    <td width=""> <?php if ($row['chr_publish'] == 'N') { ?>
                                            &nbsp;<input name="chr_publish" type="radio" class="form-rediobutton " checked="checked" id="chr_publishN" value="N"    />
                                        <?php } else { ?>
                                            &nbsp;<input name="chr_publish" type="radio" class="form-rediobutton " id="chr_publishN" value="N"  /><?php } ?>
                                        <a href="javascript:" onClick="if(document.getElementById('chr_publishN').checked!=true) document.getElementById('chr_publishN').checked=true;" style="text-decoration:none;">
                                            <td>No</td></a>
                                    </td>
                                </tr>

                            </table></td>
                        <td width="866" align="left" valign="middle" class="add-new-user-text2"><img width="16" height="16" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>help.png" onmouseover="showDiv(event,'dvhlpvarwebsite')" onmouseout="hidediv('dvhlpvarwebsite');" alt="">
                            <div id="dvhlpvarwebsite" style=" z-index:99999; position: absolute;background-color: #d5ecfa;width: 400px;height:35px;padding: 10px;color:#0b336a;border: #95d0f2 2px solid;display: none;font-family:Tahoma, Arial, Verdana;font-size:13px;font-weight:bold;">Note : Please select 'Yes' if you want to display / activate this record. Otherwise please select 'NO'.</div></td>
                    </tr>

                </table>
            </div>
        </div>

        <br />
        <?= $BottomSubmitButtons ?>

        <div class="clear"></div><br><br>
        <div class="add-new-user-button"></div>
    </div>
</form>