<?php
/**
 * @package Sj Latest Jobs For Js Jobs
 * @version 1.0.0
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @copyright (c) 2015 YouTech Company. All Rights Reserved.
 * @author YouTech Company http://www.smartaddons.com
 *
 */

defined('_JEXEC') or die;

echo '<div class="sj_newest_jobs_show_newest_jobs_info row">';
    echo '<div class="col-md-8">';
	echo '<div class="sj_newest_jobs_show_newest_jobs_info_title">'.JText::_('Latest').' <span>Jobs</span></div>';
	echo '<div class="sj_newest_jobs_show_newest_jobs_info_descreption">'.$params->get('sj_newest_jobs_des_newest').'</div>';
    echo '</div>';
    echo '<div class="col-md-4"><p><a href="index.php?option=com_jsjobs&view=company&layout=mycompanies&c=company">See all companies </a><i class="fa fa-list"></i></p></div>';
echo '</div>';

echo '<div class="sj_newest_jobs_show_newest_jobs_content">';
		$index = 0;
		foreach($nItems as $item){
			if($index%2 == 0){
				$cls_sj = ' sj_plus';
			}else{
				$cls_sj = ' sj_minus';
			}
			$index++;
			if($item->logo == ''){
				$logo = '<img src="'.JURI::root().'components/com_jsjobs/images/blank_logo.png" alt/>';
			}else{
				$logo = '<img src="'.JURI::root().'jsjobsdata/data/employer/comp_'.$item->companyid.'/logo/'.$item->logo.'" alt/>';
			}
			echo '<div class="box-item '.$cls_sj.'">';
            	echo '<div class="row">';
               		echo '<div class="col-sm-2 text-center">';
               		if($params->get('sj_newest_jobs_newest_show_logo') == 1){
               			echo '<a href="#" class="thumb-img">'.$logo.'</a>';
               		}
                    echo '</div>';
                    echo '<div class="col-sm-10">';
                    if($params->get('sj_newest_jobs_newest_show_category') == 1){
                    	$url = JURI::getInstance();
						$array_url = explode('/index.php',$url);
                        echo '<h2 class="heading p-t-1">'.$item->cat_title.'</h2>';
                    }  
                    if($params->get('sj_newest_jobs_newest_show_department') == 1){
                    	$url = JURI::root();
						$array_url = explode('/index.php',$url);
						echo '<h3 class="heading p-t-0"><a href="'.$array_url[0].'index.php/component/jsjobs/job/viewjob/job-'.$item->alias.'-'.$item->id.'">'.$item->title.'</a></h3>';
                    }   
                        echo '<ul>';
                            echo '<li>';
                            if($params->get('sj_newest_jobs_newest_show_city') == 1){
                            echo '<i class="fa fa-map-marker"></i>';
                            foreach($Cityname as $city) {
								if($city->city_id == $item->city){
									echo $city->cityN;
								}
							} 
                            echo '</li>';
                        	}
                        	if($params->get('sj_newest_jobs_newest_show_type') == 1){
                            echo '<li>';
                            echo '<i class="fa fa-clock-o"></i> '.$item->jobtypetitle.'</li>';
                        	}
                        	if($params->get('sj_newest_jobs_newest_show_created') == 1){
                        		echo '<li>';
                        		$pub = $item->startpublishing;
								$array_pub = explode(' ',$pub);
                            	echo '<i class="fa fa-calendar"></i> '.$array_pub[0].'</li>';
                        	}
                            echo '<li><i class="fa fa-money"></i> $50000 - $81000 a year</li>';
                        echo '</ul>';
                        if($params->get('sj_newest_jobs_newest_show_content') == 1){
	                        $description = str_replace('</p>','',$item->description);
							$description = str_replace('<p>','',$description);
							if(strlen($description) <= $params->get('sj_newest_jobs_newest_limit_content')){
								echo '<p class="content">'.$description.'</p>';
							}else{
								echo '<p class="content">'.JHtmlString::truncate($description,$params->get('sj_newest_jobs_newest_limit_content'),true,false).'</p>';
							}
                    	}
                    	if($params->get('sj_newest_jobs_newest_show_view_job') == 1){
							$url = JURI::root();
							$array_url = explode('/index.php',$url);
							echo '<a class="ht-btn bg-e no-border m-t-30" href="javascript:void(0)" onclick="getApplyNowByJobid('.$item->id.');">'.JText::_('Apply Now').'</a>';
						}
                    echo '</div>';
                echo '</div>';
            echo '</div>';
		}
echo '</div>';
echo '<div class="sj_newest_jobs_show_newest_all_jobs">';
    echo '<a href="index.php?option=com_jsjobs&view=job&layout=myjobs&c=job" class="all-btn"><i class="fa fa-briefcase"></i>'.JText::_('View All Jobs').'</a>';
echo '</div>';
?>
<script type="text/javascript">
  function getApplyNowByJobid(id){
    jQuery.post("index.php?option=com_jsjobs&task=jobapply.applyjob",{jobid : id} , function(data){
        if(data){
            var response = jQuery.parseJSON(data);
            if (typeof response == 'object'){
                if (response[0] === 'popup'){
                    jQuery("div#jspopup_work_area").html(response[1]);
                    jQuery("div#js_jobs_main_popup_back").show();
                    jQuery("div#waiting-wrapper").hide();
                    jQuery("div#jspopup_title").html("Apply Now");
                    jQuery("div#js_jobs_main_popup_area").slideDown('slow');
                }else{
                    window.location = response[1];
                }
            }else{
                if (response === false){
                    //the response was a string "false", parseJSON will convert it to boolean false
                }else{
                    //the response was something else
                }
            }
        }
    });
    jQuery("img#jspopup_image_close").click(function(e){
        jQuery("div#js_jobs_main_popup_area").slideUp("slow");
        setTimeout(function () {
            jQuery("div#js_jobs_main_popup_back").hide();
            jQuery("div#jspopup_work_area").html("");
        }, 700);
    });  
  }
</script>
<div id="js_jobs_main_popup_back"></div>
<div id="js_jobs_main_popup_area">
    <div id="js_jobs_main_popup_head">
        <div id="jspopup_title">Apply Now</div>
        <img id="jspopup_image_close" alt="close" src="<?php echo JURI::root()?>/components/com_jsjobs/images/popup-close.png" />
    </div>
    <div id="jspopup_work_area"></div>
</div>
<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery("img#jspopup_image_close,div#js_jobs_main_popup_back").click(function(){
            jQuery("div#js_jobs_main_popup_area").slideUp('slow');
            setTimeout(function () {
                jQuery("div#js_jobs_main_popup_back").hide();
                jQuery("div#jspopup_work_area").html('');
            }, 700);
        });
    });
</script>