<?php

/**

 * @package SJ JobSearch for JS Jobs

 * @version 1.1.0

 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL

 * @copyright (c) 2014 YouTech Company. All Rights Reserved.

 * @author YouTech Company http://www.smartaddons.com

 *

 */

defined('_JEXEC') or die;

JHtml::stylesheet('modules/' . $module->module . '/assets/css/style.css');
if (!defined('SMART_JQUERY') && $params->get('include_jquery', 0) == "1") {
    JHtml::script('modules/' . $module->module . '/assets/js/jquery-1.8.2.min.js');
    JHtml::script('modules/' . $module->module . '/assets/js/jquery-noconflict.js');
    define('SMART_JQUERY', 1);
}

echo '<div id="sj_job_search_id_'.$module->id.'" class="sj_job_search '.$params->get('moduleclass_sfx').'">';
    echo '<div class="sj_job_search_show_info">';
        echo '<div class="sj_job_search_show_info_title">'.$params->get('sj_job_search_title').'</div>';
        echo '<div class="sj_job_search_show_info_descreption">'.$params->get('sj_job_search_descreption').'</div>';
    echo '</div>';
    echo '<div class="sj_job_search_show_type_search">';
        $cls_j = ' sj_chose';
        $cls_r = ' sj_chose';

        if($params->get('sj_job_search_type') == 0){
            if($params->get('sj_job_search_type_preload') == 0){
                $cls_j = ' sj_chose_type';
                $cls_r = '';
            }else{
                $cls_j = '';
                $cls_r = ' sj_chose_type';
            }
			echo '<div class="js_job_search_tabs">';
			echo '<div class="sj_job_search_show_type_search_item sj_job_search_show_type_search_job'.$cls_j.'" data-type="job">'.$params->get('sj_job_search_text_job').'</div>';
			echo '<div class="sj_job_search_show_type_search_item sj_job_search_show_type_search_resume'.$cls_r.'" data-type="resume">'.$params->get('sj_job_search_text_resume').'</div>';
			echo '</div>';
        }

        if($params->get('sj_job_search_type') == 1){
            $cls_j = ' sj_chose_type';
            echo '<div class="sj_job_search_show_type_search_job'.$cls_j.'" data-type="job" style="background: none;">'.$params->get('sj_job_search_text_job').'</div>';
        }

        if($params->get('sj_job_search_type') == 2){
            $cls_r = ' sj_chose_type';
            echo '<div class="sj_job_search_show_type_search_resume'.$cls_r.'" data-type="resume" style="background: none;">'.$params->get('sj_job_search_text_resume').'</div>';
        }
    echo '</div>';
    echo '<div class="sj_job_search_show_content">';
        echo '<div class="sj_job_search_show_content_item sj_job_search_item">';
            echo '<input value="" placeholder="'.JText::_('MOD_ENTER_KEYWORD').'"/>';
        echo '</div>';
        echo '<div class="sj_job_search_show_localtion_item sj_job_search_item">';
            echo '<input value="All Type" placeholder="All Type"/>';
            echo '<div class="sj_select_items  sfilter1">';
            echo '<div class="sj_select_item sj_chose" data-val="">'.JText::_('MOD_ALL_TYPE').'</div>';
            echo '<div class="sj_select_item" data-val="1">'.JText::_('MOD_FULL_TIME').'</div>';
            echo '<div class="sj_select_item" data-val="2">'.JText::_('MOD_PART_TIME').'</div>';
            echo '<div class="sj_select_item" data-val="3">'.JText::_('MOD_INTERNSHIP').'</div>';
            echo '</div>';
        echo '</div>';
        echo '<div class="sj_job_search_show_categories_item sj_job_search_item">';
            echo '<input value="" placeholder="All Categories"/>';
            echo '<div class="sj_select_items sfilter2">';
                if($params->get('sj_job_search_category_preload') == 0){
                    echo '<div class="sj_select_item sj_chose" data-val="0">'.JText::_('MOD_ALL_CATEGORY').'</div>';
                }else{
                    echo '<div class="sj_select_item" data-val="0">'.JText::_('MOD_ALL_CATEGORY').'</div>';
                }
                foreach($categories as $category){
                    if($params->get('sj_job_search_category_preload') == $category->id){
                        $cls = ' sj_chose';
                    }else{
                        $cls = '';
                    }
                    echo '<div class="sj_select_item'.$cls.'" data-val="'.$category->id.'">'.$category->cat_title.'</div>';
                }
            echo '</div>';
        echo '</div>';
        echo '<div class="sj_job_search_show_submit_item">';
            echo '<div class="sj_job_search_btn_submit">'.JText::_('MOD_SEARCH').'</div>';
        echo '</div>';
    echo '<div class="clearfix"></div></div>';
echo '</div>';

$user = JFactory::getUser();
$job_link = JRoute::_('index.php?option=com_jsjobs&c=job&view=job&layout=jobsearch');
$re_link = JRoute::_('index.php?option=com_jsjobs&c=resume&view=resume&layout=resume_searchresults');
?>

<div id="sj_job_search_for_job_id_<?php echo $module->id;?>" class="sj_job_search_for_job">
    <form action="<?php echo $job_link; ?>" method="post" name="adminFormJob" id="adminFormJob" class="jsautoz_form">
        <input type="hidden" name="issearchform" value="1">
        <div class="fieldvalue title">
            <input class="inputbox" type="text" name="jobtitle" value="" size="40" maxlength="255">
        </div>
        <div class="fieldvalue jobcategory">
            <input class="inputbox" type="text" name="category[]" value="" size="40" maxlength="255">
        </div>
        <div class="jobcategory ">
            <input class="inputbox jobtype" type="text" name="jobtype[]" value="" size="40" maxlength="255">
        </div>

        <input type="hidden" name="c" value="job">
        <input type="hidden" name="view" value="job">
        <input type="hidden" name="layout" value="jobs">
        <input type="hidden" name="uid" value="0">
        <input type="hidden" name="option" value="com_jsjobs">
        <input type="hidden" name="task11" value="view">
        <input type="hidden" id="default_longitude" name="default_longitude" value="74.3833333">
        <input type="hidden" id="default_latitude" name="default_latitude" value="31.5166667">
    </form>
</div>

<div id="sj_job_search_for_resume_id_<?php echo $module->id;?>" class="sj_job_search_for_job">
    <form action="<?php echo $re_link;?>" method="post" name="adminFormResume" id="adminFormResume" class="jsautoz_form">
        <div class="fieldvalue title">
            <input class="inputbox" type="text" name="keywords" value="" size="40" maxlength="255">
        </div>
        <div class="fieldvalue jobcategory">
            <input class="inputbox " type="text" name="jobcategory" value="" size="40" maxlength="255">
        </div>
        <div class="jobcategory">
            <input class="inputbox jobtype" type="text" name="jobtype" value="" size="40" maxlength="255">
        </div>

        <input type="hidden" name="isresumesearch" value="1">
        <input type="hidden" name="c" value="resume">
        <input type="hidden" name="view" value="resume">
        <input type="hidden" name="layout" value="resume_searchresults">
        <input type="hidden" name="uid" value="<?php echo $user->get('id'); ?>">
        <input type="hidden" name="option" value="com_jsjobs">
        <input type="hidden" name="task11" value="view">

        <script type="text/javascript">
            function fj_getsubcategories(src, val){
                jQuery("#"+src).html("Loading ...");
                jQuery.post('index.php?option=com_jsjobs&c=subcategory&task=listsubcategoriesForSearch',{val:val},function(data){
                    if(data){
                        jQuery("#"+src).html(data);
                        jQuery("#"+src+" select.jsjobs-cbo").chosen();
                    }else{
                        jQuery("#"+src).html('<input type="text" name="jobsubcategory" value="">');
                    }
                });
            }
        </script>
    </form>
</div>

<script>
    jQuery(document).ready(function($){
        $('body').on('click','.sj_job_search_show_categories_item input,.sj_job_search_show_localtion_item input',function(){
            $(this).val('');
        })

        var check = 0;
        for(var i = 0; i < $('#sj_job_search_id_<?php echo $module->id;?> .sj_chose').length; i++){
            var val = $('#sj_job_search_id_<?php echo $module->id;?> .sj_chose').eq(i).text();
            var parent = $('#sj_job_search_id_<?php echo $module->id;?> .sj_chose').eq(i).parent().parent().find('input').val(val);
        }

        $('body').on('click','#sj_job_search_id_<?php echo $module->id;?> .sj_job_search_show_type_search_item',function(){
            $('#sj_job_search_id_<?php echo $module->id;?> .sj_job_search_show_type_search_item').removeClass('sj_chose_type');
            $(this).addClass('sj_chose_type');
        });

        $('body').on('click','#sj_job_search_id_<?php echo $module->id;?> .sj_job_search_show_localtion_item,#sj_job_search_id_<?php echo $module->id;?> .sj_job_search_show_categories_item',function(){
            check = 1;
            if($(this).find('.sj_show').length == 0){
                $('#sj_job_search_id_<?php echo $module->id;?> .sj_show').removeClass('sj_show');
                $(this).find('.sj_select_items').addClass('sj_show');
            }else{
                $('#sj_job_search_id_<?php echo $module->id;?> .sj_show').removeClass('sj_show');
            }
        });

        $('body').click(function(){
            if(check == 1){check = 0;return;}
            $('#sj_job_search_id_<?php echo $module->id;?> .sj_show').removeClass('sj_show');
        })

        $('body').on('click','#sj_job_search_id_<?php echo $module->id;?> .sj_select_item',function(){
            var val = $(this).text();
            var parent = $(this).parent().parent();
            parent.find('input').val(val);
            parent.find('.sj_select_item').removeClass('sj_chose');
            $(this).addClass('sj_chose');
        })

        $('body').on('click','#sj_job_search_id_<?php echo $module->id;?> .sj_job_search_btn_submit',function(){
            var type = $('#sj_job_search_id_<?php echo $module->id;?> .sj_job_search_show_type_search').find('.sj_chose_type').attr('data-type');
            var searchT = $('#sj_job_search_id_<?php echo $module->id;?> .sj_job_search_show_content_item').find('input').val();
            var searchC = $('#sj_job_search_id_<?php echo $module->id;?> .sj_job_search_show_categories_item').find('.sj_chose').attr('data-val');
            var searchJT = $('#sj_job_search_id_<?php echo $module->id;?> .sj_job_search_show_localtion_item').find('.sj_chose').attr('data-val');
            
            if(parseInt(searchC) == 0){
                searchC = '';
            }

            $('#sj_job_search_for_'+type+'_id_<?php echo $module->id;?>').find('form').find('.title input').val(searchT);
            $('#sj_job_search_for_'+type+'_id_<?php echo $module->id;?>').find('form').find('.jobcategory input').val(searchC);
            $('#sj_job_search_for_'+type+'_id_<?php echo $module->id;?>').find('form').find('.jobcategory .jobtype').val(searchJT);

            <?php if($user->username == null){?>
                if(type == "resume"){
                    alert('You have login');return;
                }
            <?php } ?>

            $('#sj_job_search_for_'+type+'_id_<?php echo $module->id;?>').find('form').submit();
        })

        <?php if($params->get('sj_job_search_chose_background') == 1){?>
            var html = $('#sj_demo_<?php echo $module->id;?>').html();
            $('#sj_demo_<?php echo $module->id;?>').remove();
            $('<?php echo $params->get('sj_job_search_in_class');?>').append(html);
        <?php }?>

        <?php if($params->get('sj_job_search_type') != 0){ ?>
            $('.sj_job_search_show_localtion_item .sj_select_items').css('overflow','hidden');
        <?php } ?>
    })
</script>