<script type="text/javascript">

   $(document).ready(function() {

   });

    function tabs(currentblock){
            if($("#manage_form_table"+currentblock).css('display')=="none"){
                $("#manage_form_table"+currentblock).show("slow");
                $('#'+currentblock).removeClass('expand');
                $('#'+currentblock).addClass('collide');
            } else {
                $("#manage_form_table"+currentblock).hide("slow");
                $('#'+currentblock).removeClass('collide');
                $('#'+currentblock).addClass('expand');
            }
    }

    function saveField(field,act){
        var item = $('#fieldItem'+field).val();
        var name = $.trim($('#vFldname'+field).val());
        name = name.replace(/\s+/g, ''); // Trim the white spaces for Field Name
        var description = $('#vFlddesc'+field).val();
        var type = $('#vFldType'+field).val();
        var input = $('#vInType'+field).val();
        var search = ($('#vFldSearch'+field).is (':checked')) ? 1 : 0;
        var link = ($('#vlink'+field).is (':checked')) ? 1 : 0;
        var mandatory = ($('#nMandatory'+field).is (':checked')) ? 1 : 0;
        var content = '';

        if($('#vFldname'+field).val()=='') {
            alert('Enter field name');
            $('#vFldname'+field).focus();
        } else if($('#vFlddesc'+field).val()==''){
            alert('Enter display name');
            $('#vFldname'+field).focus();
        } else {

          $.ajax({
                    type: "GET",
                    url: "<?php echo ConfigUrl::base();?>index/saveformfields",
                    data: "ac="+act+"&fl="+item+"&nm="+name+"&de="+description+"&ty="+type+"&ip="+input+"&se="+search+"&li="+link+"&md="+mandatory+"&no="+field
          }).done(function(msg) {

              if(msg) {
                  //alert(msg);
                  if(act=='new') {
                      if(msg=='duplicate') {
                        alert("The Field Name exists. Please try another name.")
                      } else {
                         // Change New button to Modify button
                         content ='<input type="hidden" name="fieldItem" id="fieldItem'+field+'" value="'+msg+'" />';
                         content +='<input type="button" class="btn_bg_admin" name="Submit" id="saveField'+field+'" value="Save" onclick="saveField(\''+field+'\',\'modify\')">';
                         content +='<input type="button" class="btn_bg_admin drp_btn" name="Submit" value="Drop" onclick="dropField(\''+field+'\')">';

                         $('#btns_div_fmflds'+field).html(content);
                         // Change the field name
                         $('#fieldLabel'+field).html(name);
                         $('#fieldItem'+field).val(msg); // new field Id
                         //
                      }
                  } else if(act=='modify') {
                      // Change the field name
                      $('#fieldLabel'+field).html(name);
                      $("#okBox").html('<font color="green">Changes saved successfully</font>');
                      $('html, body').animate({scrollTop: $(".HeaderRow").offset().top}, 2000);
                      $("#okBox").slideDown('slow', function(){ setTimeout('hideMsg()', 2000); });
                      $("#manage_form_table"+field).hide("slow");
                  }
              }

             });
             }

    }

    function newField(counter) {
        var items = $('#noNewField').val();
        if(isNaN(items) || items =='') {
            alert('Enter valid numbers to add new fields.');
            $('#noNewField').val('');
            $('#noNewField').focus();
        } else {

            $.ajax({
                        type: "GET",
                        url: "<?php echo ConfigUrl::base();?>index/newformfields",
                        data: "no="+items+"&ct="+counter
              }).done(function(msg) {

                  if(msg) {
                      //alert(msg);
                      $("#fieldContainer ul").append(msg);
                      $('#noNewField').val('');
                  }

              });
          }
    }

    function dropField(field) {

       var item = $('#fieldItem'+field).val();

        $.ajax({
                        type: "GET",
                        url: "<?php echo ConfigUrl::base();?>index/dropformfields",
                        data: "it="+item
              }).done(function(msg) {
                  if(msg) {
                      $('#listItem'+field).remove();
                      $("#okBox").html('<font color="green">Changes saved successfully.</font>');
                      $('html, body').animate({scrollTop: $(".HeaderRow").offset().top}, 2000);
                      $("#okBox").slideDown('slow', function(){ setTimeout('hideMsg()', 2000); });
                  }

        });
    }

    function saveStatus(field) {
        var item = $('#fieldItem'+field).val();
        var status = ($('#nStatus'+field).is (':checked')) ? 1 : 0;
        var fieldNext = parseInt(field)+parseInt(1);
        var fieldPrevious = parseInt(field)-parseInt(1);


        $.ajax({
                        type: "GET",
                        url: "<?php echo ConfigUrl::base();?>index/savestatusformfields",
                        data: "it="+item+"&st="+status
              }).done(function(msg) {
                  if(msg) {

                      if($('#vFldname'+field).val()=='Video') {
                        // Deactivate Video URL if Video is activated
                        if($('#nStatus'+field).is (':checked')) {

                           ($('#nStatus'+fieldNext).is (':checked')) ? $('#nStatus'+fieldNext).attr('checked', false)  : '';
                        }
                      } else if($('#vFldname'+field).val()=='VideoURL') {
                        // Deactivate Video if Video URL is activated
                        if($('#nStatus'+field).is (':checked')) {

                           ($('#nStatus'+fieldPrevious).is (':checked')) ? $('#nStatus'+fieldPrevious).attr('checked', false)  : '';
                        }

                      }

                  }

        });
    }
 function hideMsg(){
        $("#okBox").slideUp('slow');
 }
</script>




<div class="inner_rightpanel">
<div class="bread_crumb">






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

<div class="content_area_div">
<div style="color:maroon;font-size: 15px; background:#CCC; margin-bottom: 10px;" id="okBox"><?php echo  $this->message; ?></div>
<div class="content_area">
<div class="comm_content_block">
<h3>Manage Form Fields</h3>
<div class="admin_tab_container">
        
	<div class="admin_tab_menu">
	<ul>
	<li><a href="<?php echo ConfigUrl::base();?>index/settings">General Settings</a></li>
        <?php if(SITE_PAYMENT_MODE=="paid") {?>
            <li><a href="<?php echo ConfigUrl::base();?>index/paymentsettings">Payment Settings</a></li>
        <?php
        }?>
         <li><a href="<?php echo ConfigUrl::base();?>index/formfields" class="selected">Manage Form Fields</a></li>
         <li><a href="<?php echo ConfigUrl::base();?>index/metatag"> Manage Meta-tags</a></li>
	</ul>
	<div class="clear"></div>
	</div>
	<div class="admin_tab_contents">

<!-- Details Comment Section End -->
<div style="color:black;font-size: 12px;  margin-bottom: 10px;" id="okBox">All fields created here will appear in the form for creating ads.</div>
<div class="manageform_divwrap" id="fieldContainer">

    <ul>
   <?php
   $i=0;
   
    if(!empty($this->formFields)) {
    ?>
    <?php

        foreach($this->formFields as $field) {
        ++$i;

        //Static Fields / Restricted Fields
        switch(strtolower($field->vFldname)) {
            case 'title':
                        $contentType = $this->contentTypeStatic;
                        $inputType = $this->inputTypeStatic;
                        $staticStatus = ' disabled="disabled"';
                        break;
            case 'description':
                        $contentType = $this->contentTypeStatic;
                        $inputType = $this->inputTypeStatic;
                        $staticStatus = ' disabled="disabled"';
                        break;
            case 'image':
                        $contentType = $this->contentTypeStatic;
                        $inputType = $this->inputTypeImage;
                        $staticStatus = '';
                        break;
            case 'video':
                        $contentType = $this->contentTypeStatic;
                        $inputType = $this->inputTypeVideo;
                        $staticStatus = '';
                        break;
            case 'videourl':
                        $contentType = $this->contentTypeStatic;
                        $inputType = $this->inputTypeStatic;
                        $staticStatus = '';
                        break;
            case 'address':
                        $contentType = $this->contentTypeStatic;
                        $inputType = $this->inputTypeStatic;
                        $staticStatus = '';
                        break;
            case 'zipcode':
                        $contentType = $this->contentTypeStatic;
                        $inputType = $this->inputTypeStatic;
                        $staticStatus = '';
                        break;
           default:
                        $contentType = $this->contentType;
                        $inputType = $this->inputType;
                        $staticStatus = '';
                        break;
        }
    ?>
        <li id="listItem<?php echo $i; ?>">
            <div class="manage_frm_div">

                <div class="manage_frn_title"><?php $fieldStatus = ($field->nStatus==1) ? 'checked="checked"' : '';  ?>
                    <div class="manage_title_dv"><input name="nStatus" id="nStatus<?php echo $i ?>" class="chkbx_div" type="checkbox" <?php echo $staticStatus; ?>value="1" <?php echo $fieldStatus ?>onchange="saveStatus('<?php echo $i ?>')"><span id="fieldLabel<?php echo $i; ?>"><?php echo $field->vFldname ?></span></div>
                    <div class="manage_title_controlls expand" id="<?php echo $i; ?>" onclick="tabs('<?php echo $i; ?>')">
                        <a href="javascript:void(0)">Edit&nbsp;<!--<img src="<?php echo ConfigUrl::images();?>/down_arrow_admin.png" border="0" alt="Downarrow" title="Click to Expand/Collide"><img src="<?php echo ConfigUrl::images();?>/up_arrow_admin.png" border="0" alt="Downarrow">--></a>
                    </div>
                    <div class="clear"></div>
                </div>

                <div class="manage_form_table" id="manage_form_table<?php echo $i; ?>" style="display: none;">
                    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="16%" class="brder_right">
                                <p>Field Name </p>
                                <?php $editable=($field->nEditable==1) ? '' : ' readonly="readonly"' ?>
                                <input name="vFldname" id="vFldname<?php echo $i; ?>" class="txt_area_manage" type="text" <?php echo $editable ?>value="<?php echo $field->vFldname ?>">
                            </td>
                            <td width="16%" class="brder_right">	<p>Display Name  </p>
                                <input name="vFlddesc" id="vFlddesc<?php echo $i; ?>" class="txt_area_manage" type="text" value="<?php echo $field->vFlddesc ?>">
                            </td>
                            <td width="16%" class="brder_right">	<p> Input Content Type </p>
                                <?php echo $this->select('vFldType', $contentType, $field->vFldType, 'dropdwn_manage', '', 'vFldType'.$i); ?>
                            </td>
                            <td width="15%" class="brder_right"><p>Input Type </p>
                                <?php echo $this->select('vInType', $inputType, $field->vInType, 'dropdwn_manage','', 'vInType'.$i); ?>
                            </td>
                            <td width="12%" class="brder_right"><div align="center"><p >Display in advanced search  </p>
                               <?php echo $this->checkbox('vFldSearch', '1', $field->vFldSearch, 'chkbx_manage','vFldSearch'.$i); ?>
                                </div></td>
                            <td width="9%" class="brder_right"><div align="center"><p>Is  it a Link? </p>
                                    <?php echo $this->checkbox('vlink', '1', $field->vlink, 'chkbx_manage','vlink'.$i); ?>
                                </div></td>
                            <td width="8%" class="brder_right"> <div align="center"><p>Mandatory </p>
                                    <?php echo $this->checkbox('nMandatory', '1', $field->nMandatory, 'chkbx_manage','nMandatory'.$i); ?>
                                </div></td>
                            <td width="8%">
                                <div align="center" class="btns_div_fmflds" id="btns_div_fmflds<?php echo $i ?>">
                                    <input type="hidden" name="fieldItem" id="fieldItem<?php echo $i ?>" value="<?php echo $field->id ?>" />
                                    <input type="button" class="btn_bg_admin" name="Submit" id="saveField<?php echo $i ?>" value="Save" onclick="saveField('<?php echo $i ?>','modify')">
                                    <?php //if($field->nRemovable==1) { ?>
                                     <?php 
                                     $flg = in_array(strtolower($field->vFldname), $this->mandatoryFields);
                                     if(!$flg) { ?>
                                    <input type="button" class="btn_bg_admin drp_btn" name="Submit" value="Drop" onclick="dropField('<?php echo $i ?>')">
                                    <?php } ?>
                                    <?php //} ?>
                                </div>
                            </td>
                        </tr>
                    </table>

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

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

        </li>
        <?php
        }
        ++$i;
        //------------------------------------Display Default new field-------------------------------------
         $contentType = array('text' => 'big text', 'varchar' => 'small text', 'int' => 'Integer', 'date' => 'Date');
         $inputType = array('text' => 'Text', 'textarea' => 'Textarea', 'file-doc/txt' => 'File-Doc/txt', 'checkbox' => 'CheckBox');
        ?>
        <li id="listItem<?php echo $i; ?>">
            <div class="manage_frm_div">

                <div class="manage_frn_title">
                    <div class="manage_title_dv"><input name="nStatus" id="nStatus<?php echo $i ?>" class="chkbx_div" type="checkbox" value="1" onchange="saveStatus('<?php echo $i ?>')"><span id="fieldLabel<?php echo $i; ?>"><?php echo "New Field" ?></span></div>
                    <div class="manage_title_controlls expand" id="<?php echo $i; ?>" onclick="tabs('<?php echo $i; ?>')">
                        <a href="javascript:void(0)">Edit&nbsp;<!--<img src="<?php echo ConfigUrl::images();?>/down_arrow_admin.png" border="0" alt="Downarrow" title="Click to Expand/Collide"><img src="<?php echo ConfigUrl::images();?>/up_arrow_admin.png" border="0" alt="Downarrow">--></a>
                    </div>
                    <div class="clear"></div>
                </div>

                <div class="manage_form_table" id="manage_form_table<?php echo $i; ?>" style="display: none;">
                    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="16%" class="brder_right">
                                <p>Field Name </p>
                               <input name="vFldname" id="vFldname<?php echo $i; ?>" class="txt_area_manage" type="text" value="">
                            </td>
                            <td width="16%" class="brder_right">	<p>Display Name  </p>
                                <input name="vFlddesc" id="vFlddesc<?php echo $i; ?>" class="txt_area_manage" type="text" value="">
                            </td>
                            <td width="16%" class="brder_right">	<p> Input Content Type </p>
                                <?php echo $this->select('vFldType', $contentType, '', 'dropdwn_manage', '', 'vFldType'.$i); ?>
                            </td>
                            <td width="15%" class="brder_right"><p>Input Type </p>
                                <?php echo $this->select('vInType', $inputType,'', 'dropdwn_manage','', 'vInType'.$i); ?>
                            </td>
                            <td width="12%" class="brder_right"><div align="center"><p >Display in advanced search  </p>
                               <?php echo $this->checkbox('vFldSearch', '1', '', 'chkbx_manage','vFldSearch'.$i); ?>
                                </div></td>
                            <td width="9%" class="brder_right"><div align="center"><p>Is  it a Link? </p>
                                    <?php echo $this->checkbox('vlink', '1', '', 'chkbx_manage','vlink'.$i); ?>
                                </div></td>
                            <td width="8%" class="brder_right"> <div align="center"><p>Mandatory </p>
                                    <?php echo $this->checkbox('nMandatory', '1', '', 'chkbx_manage','nMandatory'.$i); ?>
                                </div></td>
                            <td width="8%">
                                <div align="center" class="btns_div_fmflds" id="btns_div_fmflds<?php echo $i ?>">
                                    <input type="hidden" name="fieldItem" id="fieldItem<?php echo $i ?>" value="" />
                                    <input type="button" class="btn_bg_admin" name="Submit" id="saveField<?php echo $i ?>" value="Save" onclick="saveField('<?php echo $i ?>','new')">
                                    <?php //if($field->nRemovable==1) { ?>
                                     <?php                                     
                                     $flg = in_array(strtolower($field->vFldname), $this->mandatoryFields);
                                     if(!$flg) { ?>
                                    <input type="button" class="btn_bg_admin drp_btn" name="Submit" value="Drop" onclick="dropField('<?php echo $i ?>')">
                                     <?php //} ?>
                                    <?php } ?>
                                    
                                   
                                </div>
                            </td>
                        </tr>
                    </table>

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

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

        </li>
        <?php
        ++$i;
        ////------------------------------------Default new field------------------------------------- 
}
?>
    </ul>

    <div class="adbew_flds">
        <label>Number of new fields to add&nbsp;</label><input name="noNewField" id="noNewField" class="fld_styles" type="text" value="" />
        <input type="button" class="btn_bg_admin" name="Submit" value="Add New" onclick="newField('<?php echo $i ?>')">
    </div>
    <div class="clear"></div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
<div class="clear"></div>








</div>





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


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


