
<script type="text/javascript">

    function CountLeft2(field, count, max) 
    {
        if (field.value.length > max)
        {
            field.value = field.value.substring(0, max);
        }
        else
        {
            count.value=max - field.value.length;
        }
    }
    
    function setserviceval()
    {
        var value1 ='<div class="middle2 fl">';
        value1+='<div class="mtitle1 h70 fl ttu cofy">Mineral Makeup</div>';
        value1+='<div class="mtitle2 fl cofy">Spa Manicure</div>';
        value1+='<div class="mtitle3 fl cofy">Spa Pedicure</div>';
        value1+='<div class="mtitle3 fl cofy">Spa Pedicure</div>';
        value1+='<div class="clear">&nbsp;</div>';
        value1+='</div>';
        
        CKEDITOR.instances.var_home_page_description.insertHtml(value1);
        CKEDITOR.instances.var_home_page_description.updateElement();
    }
    function copytext()
    {
        var abcd=CKEDITOR.instances.var_description.getData();
        
        var def=abcd.replace(/<a(\s[^>]*)?>.*?<\/a>/ig,"")
        var abc = def.replace(/^(\s*)|(\s*)$/g, '').replace(/\s+/g, ' ');
        var maintext=trim(removeHTMLTags(abc));
        
        //        var maintext=trim(removeHTMLTags(CKEDITOR.instances.var_description.getData()));
        if(trim(document.getElementById('var_metatitle').value)=="")
        {
            document.getElementById('var_metatitle').value=trim(document.getElementById('var_title').value).substr(0, 149);
        }
        CountLeft2(document.getElementById('var_metatitle'),document.frmproduct.metatitle_left,200);
        if(trim(document.getElementById('var_metakeyword').value)=='')
        {
            document.getElementById('var_metakeyword').value=trim(document.getElementById('var_title').value).substr(0, 64);
        }
        CountLeft2(document.getElementById('var_metakeyword'),document.frmproduct.metakeyword_left,400);
        if(trim(document.getElementById('var_metadescription').value)=='')
        {
            document.getElementById('var_metadescription').value=maintext.substr(0, 180);
        }
        CountLeft2(document.getElementById('var_metadescription'),document.frmproduct.metadescription_left,400);
    }
    function validate()
    {
        var alias=document.getElementById('var_alias').value;
        if(trim(document.getElementById('var_title').value) == "")
        {
            alert('please enter title.');
            document.getElementById('var_title').focus();
            return false;
        }
        
         
        if(document.getElementById('var_pdffile').value != '')
        {   
            var name = document.getElementById('var_pdffile').value;
            found = name.lastIndexOf('.') + 1;
            var ext = name.substr(found)
            if(!(ext == 'doc' || ext == 'docx' || ext == 'pdf'))  {
                alert('Only .doc, .docx, .pdf file formats are supported.');
                document.getElementById('var_pdffile').focus();
                return false;
            }
        } 
        if(document.getElementById('int_displayorder').value == "" || document.getElementById('int_displayorder').value==0)
        {
            alert('Please enter display order.');
            document.getElementById('int_displayorder').focus();
            return false;
        }
          if(trim(document.getElementById('var_alias').value) != "")
        {

            var str=document.getElementById('var_alias').value;

            var RE=/ /i;

            if (str.match(RE)==' ')
            {
                alert("Alias is not valid. Please remove space.");
                return false;
            }
        }
        
        if(document.getElementById('var_alias').value==" ")
            {
                
                makeLowercase('var_title','var_alias');
            }
            
            
            var text1=document.getElementById('var_alias').value;
            var len1=text1.length;
            if(len1 == 1)
            {
                alert("Alias should be greater then  one character.");
                document.getElementById('var_alias').focus();
                return false;
            }
        
            if(!checkingAlias('var_alias','<?= base64_encode("product") ?>','<?= base64_encode($row['int_glcode']) ?>','<?= base64_encode('int_glcode') ?>',"pages"))
            {
                return false;
            }
            
        copytext();
        document.getElementById('h_save').value ='T';
        return true;
        
        //        copytext();
        //        document.getElementById('h_save').value ='T';
        //        return true;
    }
    function auto_alias(){
            if(document.getElementById('var_title').value != '' && document.getElementById('var_alias').value == '')
            {
                makeLowercase();
            }
        }
     
    function makeLowercase (var_title,var_alias)
        {
            if(typeof var_title=="undefined")
            {
                var_title="var_title";
            }
            if(typeof var_alias=="undefined")
            {
                var_alias="var_alias";
            }
            var str="";
            if($("#"+var_alias).val().length == 0)
                str= document.getElementById(var_title).value.toLowerCase();

            else
                sstr=$("#"+var_alias).val()
            str= str.toLowerCase();
            // alert(str);
            var temp = new String(str);
            temp =  temp.replace(/[^a-z A-Z 0-9 \-]+/g,'');
            temp=trim(temp);

            var strlength = temp.length;
            for(i=0;i<strlength;i++)
            {
                var alias = temp.split(' ').join('-');
            }

            document.getElementById(var_alias).value = alias;
        }
        
    function fun_del_pdf(id,file)
    {
        document.getElementById('divdelbro1').innerHTML='';
        document.getElementById('hidvar_pdffile').value='';
        alert('File is deleted successfully.');
    }
    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 == "ppt" ||  filext == "pptx")
            {
                return true;
            }

            else
            {
                document.getElementById(id).value = "";
                return false;
            }
        }
    }
    function checkdatediscription()
    {
        if(document.getElementById('desc1').style.display =='none' || (document.getElementById('var_description').value= ""))
        {
            document.getElementById('desc1').style.display='';
        }
        else
        {
            document.getElementById('desc1').style.display='none';
        }
    }
    function checkdatediscription1()
    {
        if(document.getElementById('desc2').style.display =='none' || (document.getElementById('var_home_page_description').value= ""))
        {
            document.getElementById('desc2').style.display='';
        }
        else
        {
            document.getElementById('desc2').style.display='none';
        }
    }
    $(document).ready(function () {
      $('#var_price').bind('paste', function (e) {
         return false;
      });
   });
</script>


<?php
if ($_REQUEST['action'] != '') {
    $action = ucwords($_REQUEST['action']);
}
if ($_REQUEST['mode'] == 'copy') {
    $action = 'Add';
}
?>
<div class="breadcrumbs">
    <a href="index.php">Home </a>&nbsp;>&nbsp; <a href="index.php?module=product<?php echo ($_REQUEST['productcategory'] != '') ? '&productcategory=' . $_REQUEST['productcategory'] : ''; ?>">Manage Products</a>&nbsp; >&nbsp; <span class="current"><?= $action ?> Product</span>  
    <?php if ($_REQUEST['productcategory'] != '') { ?>
        <span style="float:right; margin-right:15px; margin-top:-15px; "><a href="index.php?module=productcategory"><img src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>back-button-blue.gif"></a></span>
    <?php } ?>
</div>

<div class="add-new-user-title">

    <h2><img src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>/add-new-user-icon.png"><?= $action ?> Product
        <?php
        if ($_REQUEST['action'] == 'edit') {
            $title = $productObj->catnews($row['int_glcode']);
            echo "- " . $title;
        }
        ?>
    </h2>


</div>
<?= $messagebox ?>

<?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 . "product SET chr_read='N' where int_glcode=" . $_REQUEST['eid'];
    $productObj->configObj->glDbObj->query($sql);
}
?>
<form  name="frmproduct"  id="frmproduct" action="<?php echo $frmproduct; ?>" method="post" onSubmit="return validate();" enctype="multipart/form-data" >
    <input name="hidvar_pdffile" type="hidden" id="hidvar_pdffile" value="<?= $row['var_pdffile']; ?>" />
    <div class="web-booking-main">
        <input type="hidden" name="old_displayorder" id="old_displayorder" value="<?= $row['int_displayorder'] ?>">
        <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">Product 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 align="left" valign="top" class="add-new-user-text">Title: <span>(required)</span></td>
                        <td width="75%" align="left" valign="top">
                            <?php
                            if ($_REQUEST['mode'] == 'copy') {
                                $title = 'Copy of ' . $row['var_title'];
                            } else {
                                $title = $row['var_title'];
                            }
                            ?>
                            <input name="var_title" type="text" class="add-new-user-textarea" id="var_title" style="width: 350px; float: left;" value="<?= htmlspecialchars($title); ?>" maxlength="100" />
                        </td>
 
                    </tr>

                    <?php if (DISPLAY_ALIAS == 'Y') { ?>
                        <tr>
                            <td  align="left" valign="top" class="add-new-user-text">Alias: <span>(auto)</span>  </td>
                            <td  width="75%" align="left" valign="top">
                                <table>
                                    <tr>
                                        <td>
                                            <input name="var_alias" onkeypress="return KeycheckAlphaNumeric(event);"  type="text" style="width:350px;"  onblur="auto_alias();"  class="add-new-user-textarea fl" id="var_alias" value="<?= $row['var_alias']; ?>" maxlength="100"  />

                                            <div class="fl contact-comment-new position-relative mgl5 mgt5">
                                                <span class="help-icon1"></span>
                                                <div class="contact-hint fl" style="width: 390px; height:90px;  float: left;"><?php echo GLOBAL_ALIAS_NOTE; ?></div>
                                            </div>
                                        </td>
                                        <td>
                                            <a herf="javascript:;" onclick="checkingAlias('var_alias','<?= base64_encode("product") ?>','<?= base64_encode($row['int_glcode']) ?>','<?= base64_encode('int_glcode') ?>','pages');">Check Alias</a>
                                        </td>
                                        <td>
                                            <div id="aliasmsg" ></div>
                                        </td>
                                    </tr>
                                </table>
                            </td>

                        </tr>
                    <?php } else { ?>
                        <input name="var_alias" type="hidden" class="add-new-user-textarea" id="var_alias" value="<?= $row['var_alias']; ?>" maxlength="255"  />
                    <?php } ?>

                    
                    <tr>
                        <?php
                        $select = "select * from  ecl_general_settings";
                        $query = mysql_query($select);
                        $value = mysql_fetch_array($query);
                        $value['var_currencysymbol'];
                        ?>
                        <td width="257" align="left" valign="top" class="add-new-user-text">Price(<?php echo $value['var_currencysymbol']; ?>):  </td>
                        <td width="824" colspan="3" align="left" valign="top">
                            <input name="var_price" maxlength="10" type="text"  style="width: 350px;" class="add-new-user-textarea" id="var_price" value="<?= htmlspecialchars($row['var_price']); ?>" onkeypress="return KeycheckOnlyNumeric(event)"  />
                        </td>
                    </tr>
                    <tr>
                        <td  align="left" valign="top" width="212" class="add-new-user-text">Upload File:</td>
                        <td width="856" align="left">
                            <table>
                                <tr>
                                    <td>
                                        <input name="var_pdffile" id="var_pdffile" type="file"  />
                                    </td>
                                    <td>
                                       <?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';
                                }
                                ?>
                            <?php } ?>  
                            <div style="float:left;" id="divdelbro1">
                                <?php if ($row['var_pdffile'] != "") { ?>
                                    <a href="download.php?f=upimages/special/<?= $row['var_pdffile'] ?>&module=special"><img  height="16" width="16" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?><?= $t ?>" style="vertical-align:middle;cursor:pointer;" alt="Download" /></a>
                                     <a href="javascript:;" onclick="fun_del_pdf(<?= $row['int_glcode'] ?>,'<?= $row['var_pdffile']; ?>');">Delete</a>&nbsp;&nbsp;&nbsp;&nbsp;
                                <?php } else { ?>  &nbsp
                                <?php } ?><span>(File type should be .doc, .docx, .pdf, .rar, .zip)</span>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr> 
                    
                    
                        <!--******************************* New ****************-->
                    
                      <tr>
                        <td align="left" valign="top" class="add-new-user-text"> Home Page Caption: </td>
                        <td width="75%" align="left" valign="top">
                            <input name="var_homepagecaption" type="text" class="add-new-user-textarea" id="var_homepagecaption" style="width: 350px; float: left;" value="<?php echo $row['var_homepagecaption'] ?>" maxlength="200" />
                        </td>
                    </tr>
                    
                    
                    <tr>
                        <td align="left" valign="top" class="add-new-user-text"> Home Page Title: </td>
                        <td width="75%" align="left" valign="top">
                            <input name="var_homepagetitle" type="text" class="add-new-user-textarea" id="var_homepagetitle" style="width: 350px; float: left;" value="<?php echo $row['var_homepagetitle'] ?>" maxlength="200" />
                        </td>
                    </tr>
                    
                    
                                        <tr>
                        <td align="left" valign="top" class="add-new-user-text"> Home Page Description: </td>
                        <td width="75%" align="left" valign="top">
                            
                            <textarea id="var_short_description" name="var_homepagedescription" class="textarea2" maxlength="500" style="width:350px;" 
                                      onKeyDown="CountLeft(this.form.var_homepagedescription,this.form.description_left,500);"
                                      onKeyUp="CountLeft(this.form.var_homepagedescription,this.form.description_left,500);"><?= trim($row['var_homepagedescription']) ?></textarea>
                            <input disabled="disabled" type="text" name="description_left" value="<?= (500 - strlen($row['var_homepagedescription'])) ?>" class="add-new-user-textarea" style="width:35px;"/><span valign="bottom" style="color:#000000;"> characters left</span>
                           
                        </td>
                    </tr>
                    
                    
                    <tr>
                        <td  align="left" valign="top" width="25%" class="add-new-user-text">Description: </td>
                          <?php
                            if ($row['var_description'] != '') {
                                $id = 'checked = "checked"';                                
                                ?>
                                <?php
                            } else {                                
                                $id='';
                            }
                            ?>
                        <td><input style="float: left" type="checkbox" id="var_desc" name="var_desc" <?php echo $id; ?> value="Y" onclick="checkdatediscription()"></td>
                    </tr>
                    <?php
                    if ($row['var_description'] != '') {
                        $style = 'style="display:;"';
                    } else {
                        $style = 'style="display:none;"';
                    }
                    ?>
                    <tr id="desc1" <?= $style ?>>
                        <td  align="left" valign="top" colspan="3" width="25%" class="add-new-user-text" >
                            <?php echo $configObj->glLibraryObj->load_ckeditor('var_description', $row['var_description']); ?> 
                        </td>
                    </tr>
                     <?php
                        if ($row['var_home_page_description'] != '') {
                            $id_h = 'checked = "checked"';                                
                            ?>
                            <?php
                        } else {                                
                            $id_h='';
                        }
                        ?>
<!--                    <tr>
                        <td  align="left" valign="top" width="25%" class="add-new-user-text" >Home Page Description: </td>
                        <td><input style="float: left" type="checkbox" id="var_h_desc" name="var_h_desc" <?php echo $id_h; ?> value="Y" onclick="checkdatediscription1()"></td>
                    </tr>-->
                     <?php
                    if ($row['var_home_page_description'] != '') {
                        $style1 = 'style="display:;"';
                    } else {
                        $style1 = 'style="display:none;"';
                    }
                    ?>
<!--                    <tr id="desc2" <?= $style1 ?>>
                        <td  align="left" valign="top"colspan="3" width="25%" class="add-new-user-text" >
                        <td  align="left" valign="top"colspan="3" width="" class="add-new-user-text" >
                            <span style="cursor: pointer;height: 10px;" href="javascript:;" onclick="return  setserviceval('true');"><u>Default Product Format</u><br/><br/></span> 
                            <?php echo $configObj->glLibraryObj->load_ckeditor('var_home_page_description', $row['var_home_page_description']); ?> 
                        </td>
                    </tr>-->
                    <input name="h_save" type="hidden" id="h_save" value="T" />
                </table>
            </div>
        </div>
        <div class="clear"></div>
        <?php // if ($configObj->glSessionObj->value('admin_id') == '1' || DISPLAY_ALL_SEO == 'Y') { ?>
            <div class="grid-list-subtitle-bg" style="margin-top:10px; cursor:pointer;" onClick="javascript:expandcollapsepanel('asignbannerseo');" >
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td align="left" valign="top" class="grid-td-left">SEO Information</td>
                    </tr>
                </table>
            </div>
            <div class="information-white-bg" id="asignbannerseo" style="display:none;">
                <div class="clear"></div>
                <div class="grid-list-inner-table-text">
                    <?php echo $configObj->glLibraryObj->seo_textdetails($row['var_metatitle'], $row['var_metakeyword'], $row['var_metadescription']); ?>
                </div>
            </div>
            <div class="clear"></div>
        <?php // } else { ?>
<!--            <input name="var_metatitle" type="hidden"  id="var_metatitle" value="<?//= $row['var_metatitle']; ?>"  />
            <input name="var_metakeyword" type="hidden"  id="var_metakeyword" value="<?//= $row['var_metakeyword']; ?>" />
            <input type="hidden"  id="var_metadescription" name="<?//= $row['var_metadescription']; ?>" />-->
        <?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" >
            <div class="clear"></div>
            <div class="grid-list-inner-table-text">
                <table width="100%" border="0" cellspacing="3" cellpadding="3">
                    <tr>
                        <td width="20%" align="left" valign="top" class="add-new-user-text">Display Order: <span>(required)</span></td>
                        <td colspan="2" align="left" valign="top">
                            <input style="float :left; text-align: center; width: 77px;" name="int_displayorder" type="text" class="date-textarea" 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: 700px; height: 30px;"><?php echo "Product are usually ordered alphabetically, but you may choose to put a number in the display order fields to change the ourteam listing priority." ?></div>
                            </div> 
                        </td>
                    </tr>

                    <tr>
                        <td height="20%" width="15%" align="left" valign="top" class="add-new-user-text">Publish: <span>(required)</span></td>
                        <td width="106" height="30" align="left" valign="middle" class="add-new-user-text2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="48%">
                                        <?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><br><br>
        <div class="add-new-user-button"></div>
    </div>
</form>