<script type="text/javascript">
    function validate()
    {
        if(trim(document.getElementById('var_title').value)== "")
        {
            alert("Please enter the title.");
            document.getElementById('var_title').value= "";
            document.getElementById('var_title').focus();
            return false;
        }

        if(document.getElementById('var_pdffile').value=='' && document.getElementById('hidvar_pdffile').value == '')
        {
            alert("Please upload file.");
            document.getElementById('var_pdffile').focus();
            return false;
        }
        else if(document.getElementById('var_pdffile').value != '' && !LimitAttach_Pdf(document.getElementById('var_pdffile').value,'var_pdffile'))
        {   
            alert('Only .doc, .docx, .pdf, .rar and .zip  file formats are supported.');
            document.getElementById('var_pdffile').focus();
            return false;
        }
        else if(chkObject('int_displayorder') && document.getElementById('int_displayorder').value == "")
        {
            alert("Please enter display order.");
            document.getElementById('int_displayorder').focus();
            return false;
        }   
        if(document.getElementById('int_displayorder').value == "" || document.getElementById('int_displayorder').value==0)
        {
            alert("Please enter proper display order.");
            document.getElementById('asignbannerdisplay').style.display='';
            document.getElementById('int_displayorder').focus();
            return false;
        }

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

    function makeLowercase()
    {
        var str= document.getElementById('var_title').value.toLowerCase();
        var temp = new String(str);
        temp =  temp.replace(/[^a-zA-Z0-9.]+/g,'');

        var strlength = temp.length;
        for(i=0; i < strlength; i++)
        {
            var str1 = temp.split(' ').join('');
            var alias=str1.split('.').join('');
        }
        document.getElementById('var_alias').value = alias;
    }

    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 LimitAttach_Pdf(file,id)
    {
        var imgpath = document.getElementById(id).value;
        if(imgpath != "")
        {
            var arr1 = new Array;
            arr1 = imgpath.split("\\");
            var len = arr1.length;
            var img1 = arr1[len-1];
            var filext = img1.substring(img1.lastIndexOf(".")+1);
            // Checking Extension

            if(filext == "doc"  || filext == "docx" || filext == "pdf" || filext == "rar" || filext == "zip")
            {
                return true;
            }

            else
            {
                document.getElementById(id).value = "";
                return false;
            }
        }
    }

    function chkObject (theVal)
    {
        if (document.getElementById(theVal) != null)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
</script>
<?php if ($_REQUEST['action'] != '') $action = ucwords($_REQUEST['action']); ?>
<div class="breadcrumbs"><a href="index.php">Home </a>&nbsp;>&nbsp; <a href="index.php?module=commonpdf">Manage Common Files</a>&nbsp; >&nbsp; <span class="current"><?= $action ?> Common File</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 ?> Common File</h2>
</div>
<?= $messagebox ?>
<form  id="frmcommonpdf" name="frmcommonpdf"  id="frmcommonpdf" action="<?php echo $frmcommonpdf; ?>&QT=1" method="post"  onSubmit="return validate();" enctype="multipart/form-data" >
    <input type="hidden" name="fk_modules" id="fk_modules" value="<?php echo $fk_modules ?>">
    <input type="hidden" name="old_displayorder" id="old_displayorder" value="<?= $row['int_displayorder'] ?>">
    <input name="h_save" type="hidden" id="h_save" value="T" />
    <input name="hidvar_pdffile" type="hidden" id="hidvar_pdffile" value="<?= $row['var_pdffile']; ?>" />
    <?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';
    }
    ?>
    <div class="web-booking-main">
        <div class="grid-list-subtitle-bg" style="margin-top:10px; cursor:pointer" onClick="javascript:expandcollapsepanel('asignbanner1');" >
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="left" valign="top" class="grid-td-left">Common File Information</td>
                </tr>
            </table>
        </div>
        <div class="information-white-bg" id="asignbanner1" >
            <div class="clear"></div>
            <div class="grid-list-inner-table-text">
                <table width="100%" border="0" cellspacing="3" cellpadding="3" >
                    <tr>
                        <td width="212" align="left" valign="top" class="add-new-user-text">Title: <span>(required)</span> </td>
                        <td width="856" colspan="3" align="left"  valign="top">
                            <input name="var_title" type="text"  class="add-new-user-textarea" id="var_title" value="<?= $row['var_title']; ?>"  maxlength="255" style="width:362px;"   />
                        </td>
                    </tr>
                  
                    <tr>
                        <td width="230" align="left" valign="top" class="add-new-user-text">Common File: <span>(required)</span></td>
                        <td width="218" align="left" valign="top">

                            <input name="var_pdffile" id="var_pdffile" type="file" ></td>
                        <td width="678" align="left" valign="middle">
                            <?php
                            if ($row['var_pdffile'] != '') {
                                $fileexntension = substr(strrchr($row['var_pdffile'], '.'), 1);

                                $p = explode('.', $row['var_pdffile']);
                                if ($fileexntension == 'doc' || $fileexntension == 'docx') {
                                    $t = 'WORD.png';
                                } else if ($fileexntension == 'zip' || $fileexntension == 'rar') {
                                    $t = 'zip-icon.jpeg';
                                } else if ($fileexntension == 'ppt' || $fileexntension == 'pptx') {
                                    $t = "ppt-icon.png";
                                } else {
                                    $t = 'acrobate-readericon.png';
                                }
                                ?>
                            <? } ?>  
                            <div style="float:left;" id="divdelbro">
                                <?php if ($row['var_pdffile'] != "") { ?>
                                    <a href="download.php?f=upimages/commonpdf/<?= $row['var_pdffile'] ?>&module=commonpdf"><img  height="16" width="16" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?><?= $t ?>"" style="vertical-align:middle;cursor:pointer;" alt="Download" /></a>
                                <?php } else { ?>  &nbsp
                                <?php } ?><span>(File type should be .doc, .docx, .pdf, .rar, .zip)</span>
                            </div>
                        </td>
                    </tr>
                   
                </table>
            </div>
        </div>
        <?php { ?>
        </div>
    <?php } ?>
    <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>
    <?php
        if ($row['int_displayorder'] != '')
            $int_disporder = $row['int_displayorder'];
        else
            $int_disporder = '1';
        ?>
    <div class="information-white-bg" id="asignbannerdisplay" style="display:none;">
        <div class="clear"></div>
        <div class="grid-list-inner-table-text">
            <table width="100%" border="0" cellspacing="3" cellpadding="3">
                 <tr>
                        <td width="21%" align="left" valign="top" class="add-new-user-text">Display Order: <span>(required)</span></td>
                        <td width="91" align="left" valign="top">
                            <input name="int_displayorder" type="text" class="date-textarea fl" id="int_displayorder" value="<?= $int_disporder; ?>" maxlength="3" onkeypress="return KeycheckOnlyNumeric(event);" />
                            <div class=" contact-comment-new position-relative mgt5 mgl10 fl" >
                                <span class="help-icon1"></span>
                                <div class="contact-hint fl" style="width: 590px; height: 30px; top: 10px; left:10px;position: absolute ;" ><?php echo "Promotions are usually ordered alphabetically, but you may choose to put a number in the display order fields to change the services listing priority."; ?></div>
                            </div> 
                        </td>
                    </tr>
                <tr>
                    <td height="30" width="21%" align="left" valign="top" class="add-new-user-text">Display: <span>(required)</span></td>
                    <td width="91" height="30" align="left" valign="middle" class="add-new-user-text2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="55%">
                                    <?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;">
                                        Yes</a></td>
                                <td width="52%"> <?php if ($row['chr_publish'] == 'N') { ?>
                                        <input name="chr_publish" type="radio" class="form-rediobutton " checked="checked" id="chr_publishN" value="N"    />
                                    <?php } else { ?>
                                        <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;">
                                        No</a>
                                </td>
                            </tr>
                        </table></td>
                    <td width="864" 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>
    <div class="add-new-user-button"></div>
</div>
</form>

