<script type="text/javascript">
    function sortCategory() {
        //Text Sort value
        var textsort = $('#txtcategory').val();
        if(textsort!=''){
            
             $.ajax({
                        type: "GET",
                        url: "<?php echo ConfigUrl::base();?>postads/sortcategory",
                        data: "tx="+textsort
              }).done(function(msg) {
                  if(msg) {
                      //
                      if(msg!='') {
                        $('#categoryBox').html(msg);
                      }
                      
                  }

            });
        }
        
    } //End Function
</script>

<script>

     $(document).ready(function(){
    $("#frmPostads").validate({
        rules: {
            planid: {required: true}
             
        },
        messages: {
            planid: {required:"Enter Plan Name"}
            
        }
    });
}
  )
    </script>


<style type="text/css">
    .grey{
        color:#AEAEAE;
    }
    .green{
        color:#5CA45C;
    }
    .messageBox {
        background-color: #EAEAEA;
        border: 1px solid #C9C9C9;
        padding: 25px 15px;
        width: 850px;
        margin-bottom: 10px;
    }   
</style>
<div class="inner_rightpanel">
    <h1>Post Ad </h1>
    
    <?php
        if(!empty($this->error) || !empty($this->message)) {
            $messageClass = (!empty($this->error)) ? 'red' : 'green';
            $flashMessage = (!empty($this->error)) ? $this->error : $this->message;
    ?>
    <div class="messageBox"><span class="<?php echo $messageClass ?>"><?php echo $flashMessage; ?></span></div>
    <?php
        } //
    ?>
    <div class="postad_div">
        <form method="post" name="frmPostads" id="frmPostads" action="<?php echo ConfigUrl::base(); ?>index/add" enctype="multipart/form-data">
        <table width="100%"  class="form_tbl" border="0" cellspacing="0" cellpadding="0">
           <?php
           if(!isset($_SESSION['user']['userID']) && $_SESSION['user']['userID']=='') {
           ?>
           <!--<tr>
                <td width="33%"><p>Email<span class="red">*</span></p></td>
                <td width="3%">:</td>
                <td width="64%"><input type="text" class="txt_area" name="email" value="<?php  echo $_POST['email']?>"></td>
           </tr>-->
           <?php
           }
           ?>
            <tr>
                <td>Users</td>
                <td>:</td>
                
                
                <td>
                    <?php            
                      echo $this->select('users',$this->userslist , $_POST['users'], '','','users','');
                    ?>
                </td>
            </tr>
            <?php
            if(!empty($this->activeFields)) {
                //Title Field
                if(strtolower($this->activeFields[0]->vFldname)==strtolower('Title')) {
                    ?>
                    <tr>
                        <td width="33%"><p><?php echo $this->activeFields[0]->vFlddesc ?><?php if($this->activeFields[0]->nMandatory==1) { ?><span style="color: red">*</span><?php } ?></p></td>
                        <td width="3%">:</td>
                        <td width="64%"><input type="text" class="txt_area" name="<?php echo $this->activeFields[0]->vFldname ?>" value="<?php echo $_POST[$this->activeFields[0]->vFldname] ?>"></td>
                    </tr>
                    <?php
                } //Title Field End

                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td><p>Select Category</p></td>
                <td>:</td>
                <td>
                    <!--<select class="select_drpbx" name="select">
                        <option>Category</option>
                    </select>-->
                    <?php
                    //if(!empty($this->category_title)) { asort($this->category_title); }
                    ?>                    
                    <?php echo $this->select('category', $this->category_title, $_POST['category'], 'select_drpbx','','category',' size="10"'); ?>
                </td>
            </tr>
            <tr><td>&nbsp;</td></tr>
                <?php
                foreach($this->activeFields as $activeFld) {
                   
                    if(in_array($activeFld->vFldname, $this->staticFieldArr)) {

                        switch(strtolower($activeFld->vFldname)) {
                            case 'title':
                                break;
                            case 'description':
                                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td valign="top"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td>&nbsp;</td>
                <td><textarea class="txtarea" name="<?php echo $activeFld->vFldname; ?>"><?php echo $_POST[$activeFld->vFldname] ?></textarea></td>
            </tr>

                                <?php
                                break;
                            case 'image':
                                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td width="3%">:</td>
                <td width="64%"><input type="file"   class="txt_area" name="<?php echo $activeFld->vFldname; ?>" ><br><span class="grey">Allowed image type : jpg/jpeg</span></td>
            </tr>
                                <?php
                                break;
                            case 'video':
                                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td width="3%">:</td>
                <td width="64%"><input type="file" class="txt_area" name="<?php echo $activeFld->vFldname; ?>">
                    <br><span class="grey">Supported video formats : mp4,webm,ogv,flv
                        <br>Maximum File Upload Size allowed by your server - <?php echo ini_get('upload_max_filesize'); ?>
                        </span>
                </td>
            </tr>
            <tr><td>&nbsp;</td></tr>
                                <?php
                                break;
                            case 'videourl':
                                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td width="3%">:</td>
                <td width="64%"><input type="text" class="txt_area" name="<?php echo $activeFld->vFldname; ?>" value="<?php echo $_POST[$activeFld->vFldname] ?>"></td>
            </tr>
                                <?php
                                break;
                            case 'zipcode':
                                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td width="3%">:</td>
                <td width="64%"><input type="text"  value="<?php echo $_POST[$activeFld->vFldname] ?>" class="txt_area" name="<?php echo $activeFld->vFldname; ?>"></td>
            </tr>
                                <?php
                                break;
                            case 'address':
                                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td valign="top"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td>&nbsp;</td>
                <td><textarea class="txtarea" name="<?php echo $activeFld->vFldname; ?>"><?php echo $_POST[$activeFld->vFldname] ?></textarea></td>
            </tr>
                                <?php
                                break;
                                case 'country':
                                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td width="3%">:</td>
                <td width="64%">
                    <select  name="<?php echo $activeFld->vFldname; ?>"  class="txt_area">
                        <option value="">Select Country</option>
                        <?php
                         $selectedCountry    =  $_POST[$activeFld->vFldname];
                         if($selectedCountry=="") $countryKey   ="US";
                         else
                         $countryKey = $selectedCountry;
                         global $countries;
                        foreach( $countries as $key => $value)
                        {

                        ?>
                        <option value="<?php echo $key?>" <?php if($key==$countryKey) echo "selected";?>><?php echo $value;?></option>
                        <?php
                        }
                         ?>
                        <option value="undefined">undefined</option>
                  </select>
                </td>
            </tr>
                                <?php
                                break;
                        } //End Switch

                    } // End If

                       if(!in_array($activeFld->vFldname, $this->staticFieldArr)) {
                        switch(($activeFld->vInType)) {
                            case 'text':
                                  ?>
            <tr><td>&nbsp;</td></tr>
           <tr>
                <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td width="3%">:</td>
                <td width="64%"><input type="text" class="txt_area" name="<?php echo $activeFld->vFldname; ?>"  value="<?php echo $_POST[$activeFld->vFldname] ?>"></td>
            </tr>
                                <?php
                                break;
                            
                            case 'textarea':
                                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td valign="top"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td>&nbsp;</td>
                <td><textarea class="txtarea" name="<?php echo $activeFld->vFldname; ?>"><?php echo $_POST[$activeFld->vFldname] ?></textarea></td>
            </tr>
                                <?php
                                break;
                            case 'file-doc/txt':
                                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td width="3%">:</td>
                <td width="64%"><input type="file" class="txt_area" name="<?php echo $activeFld->vFldname; ?>">
                <br><span class="grey">Supported file formats : doc,pdf,xls</span>
                </td>
            </tr>
                                <?php
                                break;
                            case 'checkbox':
                                ?>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td width="3%">:</td>
                <td width="64%"><?php echo $this->checkbox($activeFld->vFldname, '1', '', 'chkbx_manage',$activeFld->vFldname); ?></td>
            </tr>
                                <?php                                
                                break;
                            
                        } // End Switch
                    } // End If

                } //
            } // End If
            ?>

            <!--<tr>
                <td width="33%"><p>Security Code</p></td>
                <td width="3%">:</td>
                <td width="64%"></td>
            </tr>  -->
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td width="33%"><p>Plans <?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></p></td>
                <td width="3%">:</td>
                <td width="64%"><select  name="planid"  class="txt_area slct_area">
                        <option value="">Select Plans</option>
                        <?php
                        $selectedplan    =  $_POST['planid'];
                        foreach( $this->planfields as $key => $value)
                        {

                        ?>
                        <?php
                        if($value->vPlanDuration==0)
                                {

                        $status='(unlimited period-$'.$value->vPlanAmount.')';}
                        else{

                             $status='('.$value->vPlanDuration.'months-$'.$value->vPlanAmount.')';
                        }
                        ?>
                        <option value="<?php echo $value->nPlanId?>" <?php if($value->nPlanId==$selectedplan) echo "selected";?> id="planid"><?php echo $value->vPlanName.$status?></option>
                        <?php
                        }
                         ?>

                  </select>
                 </td>
            </tr>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                
                <td>
              <div class="postad_btn">
                        <input name="" class="btn_styles" value="POST AD" type="submit">
                    </div>
                </td>
               
            </tr>

            
        </table>
        </form>

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

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


<div class="clear"></div>
</div>
<!-- Inner Content Wrap End -->
<div class="clear"></div>
</div>
