
<script type="text/javascript">

    function loadSubCategories(catId,subCatId){
        //alert(catId);return false;
        if(catId!=''){
            $.ajax({
            type: "POST",
            url: "<?php echo ConfigUrl::base('default');?>postads/loadSubCategories",
            data: {
                categoryId: catId,
                subcategory  : subCatId
            },
            success: function(html) {                
                var selarray = html.split('option');
             if((selarray.length)>1)
              { 
                $('#subcat').show();
                $('#sub').html(html);
              }else  
                  $('#subcat').hide();
            }


        });
        }
    }
    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: {
            	Title: {required: true},
                planid: {required: true},
                email : {required: true},
                category : {required: true}

            },
            messages: {
            	Title: {required:"Enter Ad Title"},
                planid: {required:"Select Plan Name"},
                email: {required:"Enter Email Address"},
                category : {required:"Select Category"}

            }
        });
 
 	});
 
</script>


<div class="fw-text">
<div class="col-xs-12 col-sm-2 col-md-3"></div>
<div class="col-xs-12 col-sm-8 col-md-6">
	 <?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
    } //
    ?>
	
	<form method="post" name="frmPostads" id="frmPostads" action="<?php echo ConfigUrl::base(); ?>postads/index" enctype="multipart/form-data">
	<div class="form_main_outer">
		<h1>Post Ad</h1>
		
		 <?php
			if(!isset($_SESSION['user']['userID']) && $_SESSION['user']['userID']=='') {
		  ?>
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label>Your email<span class="red">*</span></label>
					<input type="text" class="form-control" name="email" value="<?php  echo $_POST['email']?>">
					<span class="grey">(Your email address will not be displayed in public)</span>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		  <?php
			}
			?>
			<?php
			if(!empty($this->activeFields)) {
			//Title Field
			if(strtolower($this->activeFields[0]->vFldname)==strtolower('Title')) {
		  ?>
		   
					
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $this->activeFields[0]->vFlddesc ?><?php if($this->activeFields[0]->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
                                        <input type="text" class="form-control" name="<?php echo $this->activeFields[0]->vFldname ?>" value="<?php if(isset($_POST[$this->activeFields[0]->vFldname])){ echo $_POST[$this->activeFields[0]->vFldname]; } ?>">
				</div>
			</div>
		<div class="clear"></div>
		</div>
		<?php
			} //Title Field End	
		?>
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label>Select category<span class="red">*</span></label>
					 <?php 
                                         if(isset($this->category_title) && isset($_POST['category'])){
                                             echo $this->select('category', $this->category_title, $_POST['category'], 'select_drpbx','','',' size="4" onChange = loadSubCategories(this.value)'); 
                                         }
                                         else if(isset($this->category_title) && !isset($_POST['category'])){
                                             echo $this->select('category', $this->category_title, '', 'select_drpbx','','',' size="4" onChange = loadSubCategories(this.value)'); 
                                         }
                                         else if(!isset($this->category_title) && isset($_POST['category'])){
                                             echo $this->select('category', '', $_POST['category'], 'select_drpbx','','',' size="4" onChange = loadSubCategories(this.value)'); 
                                         }
                                         else{
                                             echo $this->select('category', '', '', 'select_drpbx','','',' size="4" onChange = loadSubCategories(this.value)'); 
                                         }
                                         ?>
				</div>
			</div>
		<div class="clear"></div>
		</div>
  		<div class="form_main_inner" id="subcat" <?php if(isset($this->SubCategory) && $this->SubCategory>0){ ?> <?php }else {?>style="display:none"<?php } ?>>
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label>Select subcategory</label>
					<div  id ="sub">
						<?php
							if($_POST['category']!=''){?>
						<script>
							loadSubCategories('<?php echo $_POST['category']?>','<?php echo $_POST['subcategory']?>');
						</script>
						<?php
						}else{?>
							<?php echo $this->select('subcategory','', '', 'select_drpbx','','subcategory',' size="4"'); ?>
						<?php 
						}?>
					</div>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		
		<?php
		foreach($this->activeFields as $activeFld) {
		
		if(in_array($activeFld->vFldname, $this->staticFieldArr)) {
		
			switch(strtolower($activeFld->vFldname)) {
				case 'title':
					break;
				case 'description':
			?>
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
                                        <textarea class="txtarea" name="<?php echo $activeFld->vFldname; ?>"><?php if(isset($_POST[$activeFld->vFldname])){ echo $_POST[$activeFld->vFldname]; } ?></textarea>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		 <?php
				break;
			case 'image':
			?>
		
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
					<input type="file" name="<?php echo $activeFld->vFldname; ?>" >
					<span class="grey">Allowed image type : jpg/jpeg</span>
					<span class="grey">Ads with photos get more replies!</span>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		
		 <?php
				break;
			case 'video':
		   ?>                      
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
					<input type="file" name="<?php echo $activeFld->vFldname; ?>">
					<span class="grey">
						Supported video formats : mp4,webm,ogv,flv
						<div class="clear"></div>
						Maximum File Upload Size allowed by your server - <?php echo ini_get('upload_max_filesize'); ?>
					</span>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		 <?php
				break;
			case 'videourl':
			?>
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
					<input type="text" class="txt_area" name="<?php echo $activeFld->vFldname; ?>" value="<?php echo $_POST[$activeFld->vFldname] ?>">
				</div>
			</div>
		<div class="clear"></div>
		</div>
		<?php
				break;
			case 'zipcode':
				?>       
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
                                        <input type="text"  value="<?php if(isset($_POST[$activeFld->vFldname])){ echo $_POST[$activeFld->vFldname]; } ?>" class="txt_area" name="<?php echo $activeFld->vFldname; ?>">
				</div>
			</div>
		<div class="clear"></div>
		</div>
		  <?php
				break;
			case 'address':
				?>
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
                                        <textarea class="txtarea" name="<?php echo $activeFld->vFldname; ?>"><?php if(isset($_POST[$activeFld->vFldname])){ echo $_POST[$activeFld->vFldname]; } ?></textarea>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		
		 <?php
				break;
			case 'country':
		  ?>
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
					<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>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		<?php
			break;
			} //End Switch
			
			} // End If
			
			if(!in_array($activeFld->vFldname, $this->staticFieldArr)) {
			switch(($activeFld->vInType)) {
			case 'text':
		?>			
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
                                        <input type="text" class="txt_area" name="<?php echo $activeFld->vFldname; ?>"  value="<?php if(isset($_POST[$activeFld->vFldname])){  echo $_POST[$activeFld->vFldname]; } ?>">
				</div>
			</div>
		<div class="clear"></div>
		</div>
		
		<?php
			break;
			case 'textarea':
		?>        
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
                                        <label><?php if(isset($activeFld->vFlddesc)){ echo $activeFld->vFlddesc; } ?><?php if(isset($activeFld->nMandatory) && $activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
                                        <textarea class="txtarea" name="<?php if(isset($activeFld->vFldname)){ echo $activeFld->vFldname; } ?>"><?php if(isset($_POST[$activeFld->vFldname])){ echo $_POST[$activeFld->vFldname]; } ?></textarea>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		  <?php
				break;
			case 'file-doc/txt':
			?>
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
						<input type="file" name="<?php echo $activeFld->vFldname; ?>">
                        <span class="grey">Supported file formats : doc,pdf,xls</span>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		<?php
			break;
			case 'checkbox':
		?>
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
					<?php echo $this->checkbox($activeFld->vFldname, '1', '', 'chkbx_manage',$activeFld->vFldname); ?>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		<?php
								break;
						} // End Switch
					} // End If

				} //
			} // End If
		?>
		<?php  if($this->settings[0]->value=='paid') {?>
		<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label>Choose Plan <?php if($activeFld->nMandatory==1) { ?><span class="red">*</span><?php } ?></label>
					<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='&nbsp;[unlimited period-$'.$value->vPlanAmount.']';
								}
								else {
	
									$status='&nbsp;['.$value->vPlanDuration.'months-$'.$value->vPlanAmount.']';
								}
								?>
						<option value="<?php echo $value->nPlanId?>" <?php if($value->nPlanId==$selectedplan) echo "selected";?> id="planid"><?php echo $value->vPlanName?></option>
								<?php
	}
							?>
	
					</select>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		
		
    <?php }?>
	
	<?php if(PRODUCT_CAPTCHA_MODE == 'Y') { ?>
    	<div class="form_main_inner">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<label>Security Code</label>
					<?php echo $this->recaptchaHTML; ?>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		<?php }?>
		
		<div class="form_main_btt_outer">
			<div class="row">
				<div class="col-xs-12 col-sm-12">
					<?php  if($this->settings[0]->value=='paid') {?>
					<input name="postadd" id="postadd" class="button" value="NEXT" type="submit">
					<?php } else {?>
					<input name="postadd" id="postadd" class="button" value="POST AD" type="submit">
					<?php  }?>
				</div>
			</div>
		<div class="clear"></div>
		</div>
		
		 <!-- <?php  if($this->settings[0]->value=='planbased') {?>   <div style="float:left; height: 120px; width:160px;  margin-right: 50px; ">

        <a title="Paypal" href="<?php echo ConfigUrl::base();?>paypal/process/2"><img border="0" src="<?php echo ConfigUrl::images();?>paypal.jpg"></a>

        </div> <?php }?>-->
		
	</div>
	</form>
</div>
<div class="col-xs-12 col-sm-2 col-md-3"></div>

</div>

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