﻿// Detect Client Browser type
var isIE = (navigator.appVersion.indexOf('MSIE') != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf('win') != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf('Opera') != -1) ? true : false;
var reutrn_form = "none";
var srcChecked = "http://www.jobcity.co.il/graphics/images/icons/checked.png";
var srcUnChecked = "http://www.jobcity.co.il/graphics/images/icons/check.png";
String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

$(document).ready(function() {
        if(isIE)
        {
            if(jQuery.browser.version=="7.0")
                $('#netbiz_s_freesearchDIV').css("padding","4px 0px 0px 0px");
            else if(jQuery.browser.version=="8.0")
                $('#netbiz_s_freesearchDIV').css("padding","2px 0px 0px 0px");
        }
});

/* FREE SEARCH */

function showFreeSearch() {
    $('#netbiz_freesearch_label').hide();
    $('#netbiz_freesearch_text').show();
    $('#netbiz_freesearch_text').focus();
    $('#netbiz_locations_dropdown').hide();
    $('#netbiz_positions_dropdown').hide();
   
}

/* DROPDOWNS */

function toggleDropdowns() {

    //First argument is always the item to display !!!!
    var displayName = arguments[0];
    var hideName;
  
    
    if (!$('#netbiz_' + displayName + '_dropdown').is(':visible')) {
        //Displaying the selected item
        $('#netbiz_' + displayName + '_label').hide();
        $('#netbiz_' + displayName + '_text').show();

        $('#netbiz_' + displayName + '_dropdown').show();
            if(displayName=='locations')
            {
              $('#netbiz_locations_arrow_598').attr('src', 'http://www.jobcity.co.il/graphics/images/icons/arrow.gif');
              showGroupList('locations','598');            
            }
        }
    else {    
        InitSearchField(displayName);
    }
     //Initializing all other items
    for (var index = 1; index < arguments.length; index++) {

        hideName = arguments[index];
        InitSearchField(hideName);
    }
    
    $('#netbiz_' + displayName + '_scroll').jScrollPane({ showArrows: true, scrollbarWidth: 19, arrowSize: 16 });

    if ($('#netbiz_' + displayName + '_hidden').val() == ',') {
        $('#netbiz_' + displayName + '_clear').attr('src', 'http://www.jobcity.co.il/graphics/images/backgrounds/clear_off.png');
    }
    else {
        $('#netbiz_' + displayName + '_clear').attr('src', 'http://www.jobcity.co.il/graphics/images/backgrounds/clear.png')
    }

}
//dan
function showMajorCities()
{
    if ($("#showMajorCities_arrow").attr('src').indexOf('Open') > -1) {
        $("#showMajorCities_arrow").attr('src', 'http://www.jobcity.co.il/graphics/images/icons/arrow.gif');
        $(".MajorCities").hide();
    } else {
    $("#showMajorCities_arrow").attr('src', 'http://www.jobcity.co.il/graphics/images/icons/arrowOpen.gif');
        $(".MajorCities").show();   
          $('#netbiz_locations_scroll').jScrollPane({ showArrows: true, scrollbarWidth: 19, arrowSize: 16 });     
    }
   
 
}

function checkshowMajorCities(id)
{

     if ($("#"+id).attr('src').toString().toLowerCase().indexOf(srcChecked) > -1) 
        {
            //un check all MajorCities inclode me
            $('#'+id).attr('src',srcUnChecked);
            if($("#netbiz_locations_sub_checkbox_283").length > 0)
            {
             $("#netbiz_locations_sub_checkbox_283").attr('src',srcUnChecked)
            }
            $("#MajorCities_checkbox_283").attr('src',srcUnChecked);
            if($("#netbiz_locations_sub_checkbox_282").length > 0)
            {
             $("#netbiz_locations_sub_checkbox_282").attr('src',srcUnChecked)
            }
            $("#MajorCities_checkbox_282").attr('src',srcUnChecked);
            if($("#netbiz_locations_sub_checkbox_284").length > 0)
            {
             $("#netbiz_locations_sub_checkbox_284").attr('src',srcUnChecked)
            }
            $("#MajorCities_checkbox_284").attr('src',srcUnChecked);
            if($("#netbiz_locations_sub_checkbox_281").length > 0)
            {
             $("#netbiz_locations_sub_checkbox_281").attr('src',srcUnChecked)
            }
            $("#MajorCities_checkbox_281").attr('src',srcUnChecked);
            //remove ids 
            removeid('283');
            removeid('282');
            removeid('284');
            removeid('281');
            //remove text
            removeText("ערים מרכזיות");
        }
        else
        {
            //un check all MajorCities inclode me
            $('#'+id).attr('src',srcChecked);
                        
            if($("#netbiz_locations_sub_checkbox_283").length > 0)
            {
             $("#netbiz_locations_sub_checkbox_283").attr('src',srcChecked)
            }
            $("#MajorCities_checkbox_283").attr('src',srcChecked);
            
            if($("#netbiz_locations_sub_checkbox_282").length > 0)
            {
             $("#netbiz_locations_sub_checkbox_282").attr('src',srcChecked)
            }            
            $("#MajorCities_checkbox_282").attr('src',srcChecked);
            
            if($("#netbiz_locations_sub_checkbox_284").length > 0)
            {
             $("#netbiz_locations_sub_checkbox_284").attr('src',srcChecked)
            }
            $("#MajorCities_checkbox_284").attr('src',srcChecked);
            
            if($("#netbiz_locations_sub_checkbox_281").length > 0)
            {
             $("#netbiz_locations_sub_checkbox_281").attr('src',srcChecked)
            }
            $("#MajorCities_checkbox_281").attr('src',srcChecked);
            //remove ids 
            addid('283');
            addid('282');
            addid('284');
            addid('281');
            //remove text
            addText("ערים מרכזיות");    
            
                
       }
    return false;
}
  function removeid(id)
    {
        var hidden = document.getElementById('netbiz_locations_hidden');
        if (hidden.value.toString().toLowerCase().indexOf(',' + id + ',') > -1) {
        hidden.value = hidden.value.replace(id + ',', '');
        }
    }
    function addid(id)
    { 
        var hidden = document.getElementById('netbiz_locations_hidden');
        if (hidden.value.toString().toLowerCase().indexOf(',' + id + ',') < 0) {
        hidden.value += id + ',';
        }
    }

    function removeText(string)
    {
        var text = document.getElementById('netbiz_locations_text');

     
        
        
        
        
           
        if (text.value.toString().toLowerCase().indexOf(', ' + string  ) > -1) {
            text.value = text.value.replace(', ' + string  , '');
        }
        else if (text.value.toString().toLowerCase().indexOf( string  ) > -1)
        {
        if(text.value.toString().toLowerCase().indexOf(', ')>-1)
        {
         text.value =text.value.replace(  string +', ' , '');
         }
         else 
         {
         text.value=text.value.replace(string , '');
         }
         }
        
        
        
        }
 
    function addText(string)
    {
        var text = document.getElementById('netbiz_locations_text');
              if (text.value.toString().toLowerCase().indexOf(string) < 0) {
          if (text.value.toString().length==0)
               text.value=string;  
              else 
               text.value+= ', ' + string;
        }   
    }
function mg(id,text)
{
    if ($("#MajorCities_checkbox_"+id).attr('src').toString().toLowerCase().indexOf(srcChecked) > -1) 
    {
        if($("#netbiz_locations_sub_checkbox_"+id).length > 0)
            {
             $("#netbiz_locations_sub_checkbox_"+id).attr('src',srcUnChecked)
            }
            $("#MajorCities_checkbox_"+id).attr('src',srcUnChecked);
            //remove id
            removeid(id);
            //remove text
            removeText(text);
    }
    else
    {
        if($("#netbiz_locations_sub_checkbox_"+id).length > 0)
            {
             $("#netbiz_locations_sub_checkbox_"+id).attr('src',srcChecked)
            }
            $("#MajorCities_checkbox_"+id).attr('src',srcChecked);
            //remove id
            addid(id);
            //remove text
            addText(text);
    }
}
    
//dan
//Displays group sub list.
function showGroupList(fieldName, listId) {

    
    if ($('#netbiz_' + fieldName + '_arrow_' + listId).attr('src').indexOf('Open') > -1) {
        $('#netbiz_' + fieldName + '_arrow_' + listId).attr('src', 'http://www.jobcity.co.il/graphics/images/icons/arrow.gif');
        $('#netbiz_' + fieldName + '_' + listId).hide();
    } else {
    $('#netbiz_' + fieldName + '_arrow_' + listId).attr('src', 'http://www.jobcity.co.il/graphics/images/icons/arrowOpen.gif');
        $('#netbiz_' + fieldName + '_' + listId).show();
    }

    setTimeout(function() {
        fieldName = fieldName.replace('_sub', '');
        $('#netbiz_' + fieldName + '_scroll').jScrollPane({ showArrows: true, scrollbarWidth: 19, arrowSize: 16 });
    }, 300);
}


function checkCoutryItems(fieldName, listId) {
  

    var group = document.getElementById('netbiz_' + fieldName + '_checkbox_' + listId);
    var groupItemsList = document.getElementsByName('netbiz_' + fieldName + '_checkbox_' + listId);
    var hidden = document.getElementById('netbiz_' + fieldName + '_hidden');
    var text = document.getElementById('netbiz_' + fieldName + '_text');
    var regionId;
   
    if (isChecked(group)) {
        group.src = srcUnChecked;

        if (listId == israel) {
            for (var index = 0; index < groupItemsList.length; index++) {
                groupItemsList[index].src = srcUnChecked;               
                regionId = groupItemsList[index].id.split('_');
                regionId = regionId[regionId.length - 1];

                var cities = document.getElementsByName('netbiz_' + fieldName + '_sub_checkbox_' + regionId);
                for (var sub_index = 0; sub_index < cities.length; sub_index++) {
                    cities[sub_index].src = srcUnChecked;
                    //dan
                    x=cities[sub_index].id.split('_'); 
               if($("#MajorCities_checkbox_"+x[x.length - 1]).length > 0)
                {
                 $("#MajorCities_checkbox_"+x[x.length - 1]).attr('src',srcUnChecked)
                } 
                //dan  
                    removeFromLookup(fieldName, cities[sub_index].id, group.alt);
                    removeFromLookup(fieldName, listId, group.alt);
                }


            }
        }
        else {
            removeFromLookup(fieldName, listId, group.alt);
        }

    }
    else {
        group.src = srcChecked;
        if (listId == israel) {
            for (var index = 0; index < groupItemsList.length; index++) {
                groupItemsList[index].src = srcChecked;
                regionId = groupItemsList[index].id.split('_');
                regionId = regionId[regionId.length - 1];

                var cities = document.getElementsByName('netbiz_' + fieldName + '_sub_checkbox_' + regionId);
                for (var sub_index = 0; sub_index < cities.length; sub_index++) {
                    cities[sub_index].src = srcChecked;
                    //dan
                    x = cities[sub_index].id.split('_');
                    if ($("#MajorCities_checkbox_" + x[x.length - 1]).length > 0) {
                        $("#MajorCities_checkbox_" + x[x.length - 1]).attr('src', srcChecked)
                    }
                    //dan
                    addToLookup(fieldName, listId, group.alt);
                }


            }
        }
        else {
            addToLookup(fieldName, listId, group.alt);
        }
    }

    if ($('#netbiz_' + fieldName + '_hidden').val() == ',') {
        $('#netbiz_' + fieldName + '_clear').attr('src', 'http://www.jobcity.co.il/graphics/images/backgrounds/clear_off.png');
    }
    else {
        $('#netbiz_' + fieldName + '_clear').attr('src', 'http://www.jobcity.co.il/graphics/images/backgrounds/clear.png')
    }

}


function checkGroupItems(fieldName, listId) {
    var group = document.getElementById('netbiz_' + fieldName + '_checkbox_' + listId);
   var index_1=1;
    var groupItemsList = document.getElementsByName('netbiz_' + fieldName + '_checkbox_' + listId);
     if (fieldName=="locations") 
     {
     groupItemsList = document.getElementsByName('netbiz_' + fieldName + '_sub_checkbox_' + listId)
        index_1=0;
     }
    if (isChecked(group)) {
        {
            group.src = srcUnChecked;
            for (var index = index_1; index < groupItemsList.length; index++) {
                var id = groupItemsList[index].id.split('_');
                //dan
                if ($("#MajorCities_checkbox_" + id[id.length - 1]).length > 0) 
		{
                    $("#MajorCities_checkbox_" + id[id.length - 1]).attr('src', srcUnChecked)
                }
                //dan     
                removeItem(fieldName, id[id.length - 1], group.alt);
            }
        }
    }
    else {
        group.src = srcChecked;
   
        
        for (var index = index_1; index < groupItemsList.length; index++) {
            var id = groupItemsList[index].id.split('_');
            //dan
               if($("#MajorCities_checkbox_"+id[id.length - 1]).length > 0)
                {
                 $("#MajorCities_checkbox_"+id[id.length - 1]).attr('src',srcChecked)
                } 
                //dan    
                
            addItem(fieldName, id[id.length - 1], group.alt);
        }
    }

    if ($('#netbiz_' + fieldName + '_hidden').val() == ',') {
        $('#netbiz_' + fieldName + '_clear').attr('src', 'http://www.jobcity.co.il/graphics/images/backgrounds/clear_off.png');
    }
    else {
        $('#netbiz_' + fieldName + '_clear').attr('src', 'http://www.jobcity.co.il/graphics/images/backgrounds/clear.png')
    }
}


function checkItem(fieldName, itemId, string) {

    var checkbox = document.getElementById('netbiz_' + fieldName + '_sub_checkbox_' + itemId);
    var groupId = checkbox.name.split('_');
    var group = document.getElementById('netbiz_' + fieldName + '_checkbox_' + groupId[groupId.length - 1]);

    if (isChecked(checkbox)) {
     //dan
               if($("#MajorCities_checkbox_"+itemId).length > 0)
                {
                 $("#MajorCities_checkbox_"+itemId).attr('src',srcUnChecked)
                } 
     //dan           
        removeItem(fieldName, itemId, string);
        if(itemId!='1259')
        group.src = srcUnChecked;
    }
    else {
    //dan
        if($("#MajorCities_checkbox_"+itemId).length > 0)
                {
                 $("#MajorCities_checkbox_"+itemId).attr('src',srcChecked)
                } 
   //dan
        addItem(fieldName, itemId, string);

        var groupItemsList = document.getElementsByName(checkbox.name);
        var allChecked = true;

        for (var index = 0; index < groupItemsList.length; index++) {
            if (!isChecked(groupItemsList[index])) {
                allChecked = false;
            }
        }

        if (allChecked && groupId[3]!='12') {
            var groupId = checkbox.name.split('_');
            var group;
            group = document.getElementById('netbiz_' + fieldName + '_checkbox_' + groupId[groupId.length - 1]);
             group.src = srcChecked;
        }
    }

    if ($('#netbiz_' + fieldName + '_hidden').val() == ',') {
        $('#netbiz_' + fieldName + '_clear').attr('src', 'http://www.jobcity.co.il/graphics/images/backgrounds/clear_off.png');
    }
    else {
        $('#netbiz_' + fieldName + '_clear').attr('src', 'http://www.jobcity.co.il/graphics/images/backgrounds/clear.png')
    }
}

/* SEARCH GROUPS */

function checkGroup(groupId) {
    var checkbox = document.getElementById('netbiz_frequent_groups_sub_checkbox_' + groupId);
    if (isChecked(checkbox)) {
        removeItem('frequent_groups', groupId, '');
    }
    else {
        addItem('frequent_groups', groupId, '');
    }
}


function initLimitDrop() {
    $('#netbiz_hours_limit_dropdown').slideToggle();
}

function limitSearchHours(limit, limitText) {
    if (limit == '0') {
     //   $('#netbiz_hours_limit_checkbox').attr('src', srcUnChecked);
    }
    else if (limit=='-1')
    {
  var searchUtilCookie= ReadCookie('JobCitySearchEngineUtilCookie');
  var entrance_info =searchUtilCookie.split(',');
  if(entrance_info[2]!=null)
  {
       limit=entrance_info[2];
  }
  else 
  limit=1;
  var current
    }
    else {
    //    $('#netbiz_hours_limit_checkbox').attr('src', srcChecked);
    }

    $('#netbiz_hours_limit_text').val(limitText);
    $('#netbiz_hours_limit_hidden').val(limit);
    $('#netbiz_hours_limit_dropdown').slideToggle();

}

/* ADVANCED SEARCH */

function InitAdvancedSearch() {
    if ($('.netbiz_searchblack_advanced').is(':visible')) {
        $('#netbiz_searchmore').show();
        $('#netbiz_searchm').removeClass('netbiz_searchm_advanced');
        $('#netbiz_searchm').addClass('netbiz_searchm');
        
    }
    else {
        //$('.netbiz_searchblack_advanced').show();
        $('#netbiz_searchmore').hide();
        $('#netbiz_searchm').removeClass('netbiz_searchm');
        $('#netbiz_searchm').addClass('netbiz_searchm_advanced');
       
      
    }

    $('#netbiz_searchblack_advanced').slideToggle();

}
function InitAdvancedSearchMiddleEngine() {
    if ($('.netbiz_searchblack_advanced_narrow').is(':visible')) {
        $('#netbiz_searchmore').show();
        $('#netbiz_searchm').removeClass('netbiz_searchm_narrow_advanced');
        $('#netbiz_searchm').addClass('netbiz_searchm_narrow');
        
    }
    else {
        //$('.netbiz_searchblack_advanced').show();
        $('#netbiz_searchmore').hide();
        $('#netbiz_searchm').removeClass('netbiz_searchm_narrow');
        $('#netbiz_searchm').addClass('netbiz_searchm_narrow_advanced');
       
      
    }

    $('#netbiz_searchblack_advanced').slideToggle();

}

function SmallInitAdvancedSearch() {

    if ($('#netbiz_searchblack_advanced').is(':visible')) {
        $('#netbiz_searchblack_advanced').hide();
        $('#netbiz_searchmore').show();
        $('#netbiz_s_searchblackdiv').removeClass('netbiz_leftsearch_s_searchblack');
        $('#netbiz_s_searchblackdiv').addClass('netbiz_leftsearch_s_searchblack_advanced');
    }
    else {
        $('#netbiz_searchblack_advanced').show();
        $('#netbiz_searchmore').hide();
        $('#netbiz_s_searchblackdiv').removeClass('netbiz_leftsearch_s_searchblack');
        $('#netbiz_s_searchblackdiv').addClass('netbiz_leftsearch_s_searchblack_advanced');
    }



}

function checkFromLastEnter(limit) {
    var checkbox = document.getElementById('netbiz_lastenter_limit_checkbox');
    if (isChecked(checkbox)) {
        checkbox.src = srcUnChecked;
        $('#netbiz_lastenter_limit_hidden').val('0');

    }
    else {
        checkbox.src = srcChecked;
        $('#netbiz_lastenter_limit_hidden').val(limit);
    }
}


function checkHumanResources() {
    var checkbox = document.getElementById('netbiz_human_resources_checkbox');
    if (isChecked(checkbox)) {
        checkbox.src = srcUnChecked;
        $('#netbiz_human_resources_hidden').val('0');

    }
    else {
        checkbox.src = srcChecked;
        $('#netbiz_human_resources_hidden').val('1');
    }
}


/* GENERAL */

//Initializing search field
function InitSearchField(fieldName) {

    if ($('#netbiz_' + fieldName + '_text').val() == '') {
        $('#netbiz_' + fieldName + '_label').show();
        $('#netbiz_' + fieldName + '_text').hide();
    }

    $('#netbiz_' + fieldName + '_dropdown').hide(200);
   
 
}

function ReInitSearchField() {
    $('#netbiz_locations_label').show();
    $('#netbiz_locations_text').hide();
    $('#netbiz_locations_text').val('');
    $('#netbiz_locations_dropdown').hide(200);

    $('#netbiz_positions_label').show();
    $('#netbiz_positions_text').hide();
    $('#netbiz_positions_text').val('');
    $('#netbiz_positions_dropdown').hide(200);

    $('#netbiz_freesearch_label').show();
    $('#netbiz_freesearch_text').val('');
    $('#netbiz_freesearch_text').hide();
    $('#netbiz_freesearch_dropdown').hide(200);

    $('#netbiz_hours_limit_text').val('ב-3 חודשים האחרונים');
    $('#netbiz_hours_limit_hidden').val('100');

    var images = document.getElementsByTagName('img');
    for (var i = 0; i < images.length; i++) {
        if (isChecked(images[i])) {
            images[i].src = srcUnChecked;
        }
    }
    $('#netbiz_frequent_groups_hidden').val('');
    $('#netbiz_human_resources_checkbox').attr('src', srcChecked);
    $('#netbiz_human_resources_hidden').val('1');
    
    //dan
    ReInitLocations();
    ReInitPositions();
    //dan
 
}

function ReInitPositions() {

    $('#netbiz_positions_label').show();
    $('#netbiz_positions_text').hide();
    $('#netbiz_positions_text').val('');
    $('#netbiz_positions_hidden').val(',');

    //$('#netbiz_positions_dropdown').hide(200);

    var images = document.getElementsByTagName('img');

    for (var i = 0; i < images.length; i++) {
        if (isChecked(images[i]) && images[i].name.toString().toLowerCase().indexOf('netbiz_positions') > -1) {

            images[i].src = srcUnChecked;
        }
    }
}


function ReInitLocations() {

    $('#netbiz_locations_label').show();
    $('#netbiz_locations_text').hide();
    $('#netbiz_locations_text').val('');
    $('#netbiz_locations_hidden').val(',');
    //$('#netbiz_locations_dropdown').hide(200);
    var images = document.getElementsByTagName('img');
    for (var i = 0; i < images.length; i++) {
        if (isChecked(images[i]) && images[i].name.toString().toLowerCase().indexOf('netbiz_locations') > -1) {
            images[i].src = srcUnChecked;
        }
        if (images[i].name.toString().toLowerCase().indexOf('majorcities_checkbox') > -1 && $("#" + images[i].name).attr('src').toString().toLowerCase().indexOf(srcChecked) > -1) {
            $("#" + images[i].name).attr('src', srcUnChecked)
        }

    }
      

}


function isChecked(checkBox) {
    if (checkBox.src.toString().toLowerCase().indexOf(srcChecked) > -1) {
        return true;
}
        return false;
    }

    function addItem(fieldName, itemId, string) {
     var checkbox;
              if(document.getElementById('netbiz_' + fieldName + '_sub_checkbox_' + itemId))
              {
          checkbox = document.getElementById('netbiz_' + fieldName + '_sub_checkbox_' + itemId);
        }
        else
        {
         checkbox = document.getElementById('netbiz_' + fieldName + '_checkbox_' + itemId);
        }
        checkbox.src = srcChecked;
        addToLookup(fieldName,itemId, string);
    }

    function removeItem(fieldName, itemId, string) {

 var checkbox;
 
 if (document.getElementById('netbiz_' + fieldName + '_sub_checkbox_' + itemId))
 {
    checkbox = document.getElementById('netbiz_' + fieldName + '_sub_checkbox_' + itemId)
      }
        else 
        {
         checkbox = document.getElementById('netbiz_' + fieldName + '_checkbox_' + itemId)
        }
         checkbox.src = srcUnChecked;
        removeFromLookup(fieldName, itemId, string);
    }

    function addToLookup(fieldName, itemId, string) {
        var hidden = document.getElementById('netbiz_' + fieldName + '_hidden');

        if (hidden.value.toString().toLowerCase().indexOf(',' + itemId + ',') < 0) {
            hidden.value += itemId + ',';
        }

        var text = document.getElementById('netbiz_' + fieldName + '_text');

        if (text.value.toString().toLowerCase().indexOf(string) < 0) {
          if (text.value.toString().length==0)
               text.value=string;  
              else 
               text.value+= ', ' + string;
             
            
        }
    }

    function removeFromLookup(fieldName, itemId, string) {

        var hidden = document.getElementById('netbiz_' + fieldName + '_hidden');

        if (hidden.value.toString().toLowerCase().indexOf(',' + itemId + ',') > -1 ||  hidden.value.toString().toLowerCase().indexOf(itemId + ',')==0) {
            hidden.value = hidden.value.replace(itemId + ',', '');
        }


        var text = document.getElementById('netbiz_' + fieldName + '_text');
           
        if (text.value.toString().toLowerCase().indexOf(', ' + string  ) > -1) {
            text.value = text.value.replace(', ' + string  , '');
        }
        else if (text.value.toString().toLowerCase().indexOf( string  ) > -1)
        {
        if(text.value.toString().toLowerCase().indexOf(', ')>-1)
        {
         text.value =text.value.replace(  string +', ' , '');
         }
         else 
         {
         text.value=text.value.replace(string , '');
         }
         }
        
        
    
    };

    function isAllIsraelChecked() {
        var groupItemsList = document.getElementsByName('netbiz_locations_checkbox_' + israel);
        var country = document.getElementById('netbiz_locations_checkbox_' + israel);

        var allChecked = true;
        for (var index = 0; index < groupItemsList.length; index++) {
            if (groupItemsList[index] != country && !isChecked(groupItemsList[index])) {
                allChecked = false;
            }
        }


        if (allChecked) {
            country.src = srcChecked;
        }
        else {
            country.src = srcUnChecked;
            removeFromLookup('locations', israel, country.alt);
        }
    }


    /* SUBMIT */


    function submitSearch() { 
    
    if( document.getElementById('SearchProgress'))
                $('#SearchProgress').removeAttr('style').hide().fadeIn();

          var postToUrl = 'http://match.jobcity.co.il/Search/PublicSearch.aspx?';
         //     var postToUrl = 'http://localhost/default.aspx?';

        var parameters = '';

        if ($('#netbiz_positions_hidden').val() != ',') {
            parameters += 'subfieldid=' + $('#netbiz_positions_hidden').val().substring(1, $('#netbiz_positions_hidden').val().length - 1);
        }

        if ($('#netbiz_locations_hidden').val() != ',') {

            if (parameters != '' && parameters.indexOf(parameters.length) != '&' && parameters.indexOf(parameters.length) != '?') {
                parameters += '&';
            }
            parameters += 'cityid=' + $('#netbiz_locations_hidden').val().substring(1, $('#netbiz_locations_hidden').val().length - 1);
        }

        if ($('#netbiz_freesearch_text').val() != '') {
            if (parameters != '' && parameters.indexOf(parameters.length) != '&' && parameters.indexOf(parameters.length) != '?') {
                parameters += '&';
            }
            parameters += 'expression=' + escape($('#netbiz_freesearch_text').val());
        }

        if ($('#netbiz_frequent_groups_hidden').val() != '' && $('#netbiz_frequent_groups_hidden').val().substring(1, $('#netbiz_frequent_groups_hidden').val().length - 1).trim() != ',') {
            if (parameters != '' && parameters.indexOf(parameters.length) != '&') {
                parameters += '&';
            }

            parameters += 'searchgroups=' + $('#netbiz_frequent_groups_hidden').val().substring(0, $('#netbiz_frequent_groups_hidden').val().length-1);
}
   


        if ($('#netbiz_hours_limit_hidden').val() == '0') {
            if ($('#netbiz_lastenter_limit_hidden').val() != '') {
                if (parameters != '' && parameters.indexOf(parameters.length) != '&' && parameters.indexOf(parameters.length) != '?') {
                    parameters += '&';
                }
                parameters += 'postedwithin=' + $('#netbiz_lastenter_limit_hidden').val();
            }
        }
        else {
            if (parameters != '' && parameters.indexOf(parameters.length) != '&' && parameters.indexOf(parameters.length) != '?') {
                parameters += '&';
            }
            parameters += 'postedwithin=' + $('#netbiz_hours_limit_hidden').val();
        }
       if( $('#netbiz_frequent_groups_hidden').val())   contain_advenced_search=true;  else  contain_advenced_search=false;
        SaveSearchParameters($('#netbiz_freesearch_text').val(),$('#netbiz_positions_hidden').val(),$('#netbiz_frequent_groups_hidden').val(),$('#netbiz_hours_limit_hidden').val(),$('#netbiz_locations_hidden').val(),$('#netbiz_locations_text').val(),$('#netbiz_human_resources_checkbox').val(),$('#netbiz_positions_text').val(),$('#netbiz_lastenter_limit_hidden').val(),contain_advenced_search);
        window.top.location.href= postToUrl + parameters + "&IsExternalSearch=1";


    };
    
   function SaveSearchParameters(freesearch_text,positions_hidden,frequent_groups_hidden,hours_limit_hidden,locations_hidden,location_text,human_resources_checkbox,positions_text,no_item)
   {
    var groupsval = $('#netbiz_frequent_groups_hidden').val();
   if (contain_advenced_search && groupsval!="," )
   {
       
   document.cookie = 'searchCookie=*'+escape(freesearch_text) +   '*'+positions_hidden +   '*'+frequent_groups_hidden+ '*'+hours_limit_hidden +  '*'+locations_hidden+   '*'+escape(location_text)+   '*'+' '+'*'+ escape(positions_text) + '*' + groupsval + ' ;domain=.jobcity.co.il ; '; 
   }
    else 
     document.cookie = 'searchCookie=*'+escape(freesearch_text) +   '*'+positions_hidden +   '*'+frequent_groups_hidden+ '*'+hours_limit_hidden +  '*'+locations_hidden+   '*'+escape(location_text)+   '*'+ ' ' +'*'+ escape(positions_text) + '*' +    ' ; domain=.jobcity.co.il ; ' ; 
  
      
   };
   
 
 function  LoadSearchParameters( )
 {
      
   
     var searchCookie = ReadCookie('searchCookie');
     if (searchCookie!=null)
     {
 
           var items=searchCookie.split('*');
           //free search parameter
           if (items[1]!=null)
           {
             if(items[1].trim()!="")
             {
                    $('#netbiz_freesearch_text').val( unescape(items[1]));
                    $('#netbiz_freesearch_label').hide();
                    $('#netbiz_freesearch_text').show();
            }
           }//end 1
           
            //location parameter
           if (items[5]!=null && items[6]!=null)
           {
             if(items[5].length>0)
             {
               //set location hidden
               $('#netbiz_locations_hidden').val(items[5]);
               var locations = items[5].split(',');
               for (i=0;i<locations.length;i++)
               { 
                   if (locations[i]!="")
                   {
                     if (document.getElementById('netbiz_locations_sub_checkbox_text_'+locations[i]))
                        {
                          checkItem('locations',locations[i], document.getElementById('netbiz_locations_sub_checkbox_text_'+locations[i]).value); 
                        }
                    }
                }
                  centralCityCheckCounter=0;
                  for (i=0;i<locations.length;i++)
                  {
                    if (locations[i]=='281' || locations[i]=='282' || locations[i]=='283' || locations[i]=='284' )
                      centralCityCheckCounter++;
                   
                           if (locations[i]=='1259')
                             {
                             checkItem('locations','1259','חוץ לארץ'); 
                             }
                             
                   }
                  if (centralCityCheckCounter==4)
                 checkshowMajorCities('MajorCities_checkbox');
                  if (centralCityCheckCounter>0)
            if( document.getElementById('showMajorCities_arrow').src.indexOf('Open')==-1){ $("#showMajorCities_arrow").attr('src', 'http://www.jobcity.co.il/graphics/images/icons/arrowOpen.gif');
        $(".MajorCities").show();  }
                  
      
          
             
     
              
                //set location text
               if(items[6].trim()!="")
               {
                $('#netbiz_locations_text').val(unescape(items[6]));
                $('#netbiz_locations_text').show();
                $('#netbiz_locations_label').hide();
                 
                }
             }}
        //set positions 
              if (items[2]!=null&& items[8]!=null)
              {
               
                    if (items[8].trim()!="")
                    {
                    positions_text_items=items[8].split(',');
                    $('#netbiz_positions_text').val(unescape(items[8]));
                    $('#netbiz_positions_text').show();
                    $('#netbiz_positions_label').hide();
                    }
                       if(items[2].length>0)
                    {
                     $('#netbiz_positions_hidden').val(items[2]);
                   var positions = items[2].split(',');
                           for (i=0;i<positions.length;i++)
                           { 
                                   if (positions[i]!="")
                                       {
                                        checkItem('positions',positions[i], ""); 
                                                 //set group box text if neccesary
                                        var element = $('#netbiz_positions_sub_checkbox_' +positions[i]);
                                        id=element.attr('name').split('_')[3];
                                         
                                        var groupItemsList = document.getElementsByName('netbiz_positions_checkbox_' + id) ;
                                          var counterPositionGroup=0;
                                       
                                          if (id)
                                          { 
                                           for (k=0; k<groupItemsList.length;k++)
                                           { 
                                          if(  !groupItemsList[k].src.toString().toLowerCase().indexOf(srcChecked) > -1)
                                          {
                                                                                    counterPositionGroup++;
                                                                                 }    
                                                                                 if (counterPositionGroup==groupItemsList.length)
                                                                                 {  var groupid=element.attr('name').split('_'); 
                                                                                  $('#netbiz_positions_checkbox_'+groupid[3].toString()).attr('src',srcChecked);
                                                                                 }
                                             
                                          }
                                          }
                                        
                                       }              
                           }//end   for (i=0;i<positions.length;i++)
                   }//end    if(items[2].length>0)
                
               }//end   if (items[2]!=null&& items[8]!=null)
           if (items[3]!=null)
           {
            if (items[3].trim()!="")
            {
              var searchgroups=items[3].split(',');
              $('#netbiz_frequent_groups_hidden').val(items[3]);
               for (ii=0; ii<searchgroups.length;ii++)
              {
              if (searchgroups[ii].trim()!=""  )
               checkGroup(searchgroups[ii]);
              }
              
            }//end  if (items[3].trim()!="")
           }
     }
 }

 function ReadCookie(cookieName) {
     var theCookie = "" + document.cookie;
     var ind = theCookie.indexOf(cookieName);
     if (ind == -1 || cookieName == "") return "";
     var ind1 = theCookie.indexOf(';', ind);
     if (ind1 == -1) ind1 = theCookie.length;
     return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
 }

function freeSearchTextEnterKeyPress(e)
{ 
  
   if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)){
   
            if (!is_auto_complete_selected_item)
                  submitSearch();
                  else 
                  is_auto_complete_selected_item=false;
        
             
          
          
        
      

  };
  }
  