//<![CDATA[
function ClearEventTarget() {

  var el = $('[id=__EVENTTARGET]');
  var item = el.val();
  el.val('');

  var hdn = $('[id*="LZHdn"]');
  if (hdn.length > 0)
    hdn.val('');
}

function hasIndustries(validateIndustry)
{
    var outcome = true;

    $(function() {
	    var industryCount = 0;
	    
        if (validateIndustry) {
            $('[id*=selInd] option:selected').each(function() {
                industryCount++;
            });

            if (industryCount > 0) {
                $('.mustdo').toggleClass("none", true);
                outcome = true; 
            }
            else {
                $('.mustdo').toggleClass("none", false);
                outcome = false;                
            }
        }
        else {
            $('.mustdo').toggleClass("none", true);
            outcome = true;
        }
    });

    return outcome;
}

function ShowContent(tab) 
{
	var theTabs = $('[id^=tab_]');
	var theControls = $('div.ctrl');

	var sometab;
	var somecontrol;

	for (i = 0; i < theTabs.length; i++) 
	{
		sometab = theTabs[i];

		if (sometab == tab) {
				$(sometab).addClass('jobsearchtab_on');
				$(sometab).removeClass('jobsearchtab_off');
				somecontrol = document.getElementById(sometab.id.slice(5));
                    
                if (sometab.id == "tab_pqs")
                    configureSearch(somecontrol, "PowerSearch");
                else (sometab.id == "tab_qqs")
                    configureSearch(somecontrol, "QuickSearch");

                if ($(somecontrol).hasClass('none')) $(somecontrol).removeClass('none');
				storeTabView(i);
		}
		else 
		{
				$(sometab).addClass('jobsearchtab_off');
				$(sometab).removeClass('jobsearchtab_on');
				somecontrol = document.getElementById(sometab.id.slice(5));
                    
				if(!$(somecontrol).hasClass('none') && (tab.id.slice(5) != sometab.id.slice(5))) $(somecontrol).addClass('none');
		}
	}
}

function ShowPowerContent(tab, searchType) 
{
    var theTabs = $('[id^=tab_]');
	var theControls = $('div.ctrl');

	var sometab;
	var somecontrol;

	for (i = 0; i < theTabs.length; i++) 
	{
		sometab = theTabs[i];

		if (sometab == tab) {
				$(sometab).addClass('jobsearchtab_on');
				$(sometab).removeClass('jobsearchtab_off');
				somecontrol = document.getElementById(sometab.id.slice(5));
                
                configureSearch(somecontrol, searchType);
                    
                if ($(somecontrol).hasClass('none')) $(somecontrol).removeClass('none');
				storeTabView(i);
		}
		else 
		{
				$(sometab).addClass('jobsearchtab_off');
				$(sometab).removeClass('jobsearchtab_on');
				somecontrol = document.getElementById(sometab.id.slice(5));
                    
				if(!$(somecontrol).hasClass('none')&& (tab.id.slice(5) != sometab.id.slice(5))) $(somecontrol).addClass('none');
		}
	}
}

function configureSearch(control, searchType) {
    
    $(control).attr("SearchType", searchType); 
    var searchPanel = document.getElementById("qs");
    var role = $('[id*=txtTitle]');
    var location = $('[id*=txtLoc]');
    var radius = $('[id*=selRad]');
    var posted = $('[id*=postedBy]');
    var salary = $('[id*=selSalary]');
    var visa = $('[id*=cbVisa]');
    var cats = $('[id*=selCat]');
    var hdn = $('[id*=hdnType]');
    var countries = $('[id*=MyCountries]');
    var mycountrycheckbox = $('[id*=UseMyCountries]');
    
    
	if (searchType == "PowerSearch")			
    {
        $(searchPanel).toggleClass("power", true);

        location.attr("class", "medinput");
        radius.attr("class", "shortdrop");

        role.parent().toggleClass("none", false);
        posted.parent().toggleClass("none", false);
        salary.parent().parent().toggleClass("none", false);
        cats.parent().toggleClass("none", false);
        countries.toggleClass("none", false);   
        visa.parent().parent().parent().toggleClass("none", false);

        hdn.val(searchType);
    }
    else
    {
        $(searchPanel).toggleClass("power", false); 

        location.attr("class", "longinput");
        radius.attr("class", "none"); 
          
        role.parent().toggleClass("none", true);
        posted.parent().toggleClass("none", true);
        salary.parent().parent().toggleClass("none", true);
        cats.parent().toggleClass("none", true);
        countries.toggleClass("none", true);      
        visa.parent().parent().parent().toggleClass("none", true);
        mycountrycheckbox.attr('checked', false);

        hdn.val(searchType);
    }

}

function storeTabView(tab) {
    $(function() {
	
	    var x = 'view=' + tab;
	    $.ajax({
		    contentType: "application/json; charset=utf-8",
		    dataType: "json",
		    type: "POST",
		    url: "/WebServices/JobSearch.asmx/SaveTabView",
		    data: "{'view':'" + tab + "'}",
		    success:
			    function(result) { /* NOP */ },
		    error:
			    function(result) { /* NOP */ }
	    });
    });
}

function ShowThing(thing) {
    $(function() {
	
	    if (thing == 'quality') {
		    $('[id*=_quality]').removeClass('none');
	    }
	    else if (thing == 'help1') {
		    if ($('#helptext').html() == '') {
			    $.ajax({
				    contentType: "application/json; charset=utf-8",
				    dataType: "json",
				    type: "POST",
				    url: "/WebServices/JobSearch.asmx/getHelp",
				    data: "{}",
				    success:
					    function(result) {
						    $('#helptext').html(result.d);
					    },
				    error:
					    function(result) { /* NOP */ }
			    });
		    }
		    $('[id*=_help1]').removeClass('none');
	    }
    });
}

function HideThing(thing) {
    $(function() {
	   
	    if (thing == 'quality')
		    $('[id*=_quality]').addClass('none');
	    else if (thing == 'help1')
		    $('[id*=_help1]').addClass('none');
    });
}

$(function() {
	$('[id*=selInd]').dropdownchecklist({ 
        firstItemChecksAll: true, 
        textFormatFunction: function(options) {
        var selectedOptions = options.filter(":selected");
        var countOfSelected = selectedOptions.size();
        var size = options.size();
        switch(countOfSelected) {
           case 0: return "";
           case 1: return selectedOptions.text();
           case size: return countOfSelected-1 + " " + 'Industries Selected';
           default: return countOfSelected + " " + 'Industries Selected';
            }
        }  
    });
    
    $('.cbdrop').dropdownchecklist();

    $('[id*=selInd-i0]').parent().addClass('ui-dropdownchecklist-default-item');

});

$(function() {
	$('[id*=selJType]').change(function() {
        var option;
        $("[id*=selJType] option:selected").each(function() {
            option = $(this).val();
        });

        if (option == "ANY") { 
            $("[id*=anyContainer]").toggleClass("hidden", false);
            $("[id*=rateContainer]").toggleClass("hidden", true);
            $("[id*=salaryContainer]").toggleClass("hidden", true);
        }
        
        if (option == "PERMANENT") {  
            $("[id*=anyContainer]").toggleClass("hidden", true);
            $("[id*=rateContainer]").toggleClass("hidden", true);
            $("[id*=salaryContainer]").toggleClass("hidden", false);
        }

        if (option == "CONTRACT") {  
            $("[id*=anyContainer]").toggleClass("hidden", true);
            $("[id*=rateContainer]").toggleClass("hidden", false);
            $("[id*=salaryContainer]").toggleClass("hidden", true);
        }
    });

});


//]]>
