﻿/* Expand / collapse the form */
function SwitchSearchOptions(ext, std, btn) {
    var extended = document.all ?
                document.all[ext] :
                document.getElementById(ext);
    var standard = document.all ?
                document.all[std] :
                document.getElementById(std);
    var button = document.all ?
                document.all[btn] :
                document.getElementById(btn);

    if (extended) {
        // switch the link
        if (extended.className.startsWith('Exp_')) {
            extended.className = extended.className.substr(4);
        } else {
            extended.className = 'Exp_' + extended.className;
        }
    }

    if (standard) {
        // switch the link 
        if (standard.className.startsWith('Exp_')) {
            standard.className = standard.className.substr(4);
        } else {
            standard.className = 'Exp_' + standard.className;
        }
    }

    if (button) {
        // switch the button
        if (button.className.startsWith('Exp_')) {
            button.className = button.className.substr(4);
        } else {
            button.className = 'Exp_' + button.className;
        }
    }

    // switch the container elements
    var containers = document.getElementsByTagName('div');
    for (var i = 0; i < containers.length; i++) {
        if (containers[i].id.endsWith('_outer')) {
            if (containers[i].className.startsWith('Exp_')) {
                containers[i].className = containers[i].className.substr(4);
            }
            else {
                containers[i].className = 'Exp_' + containers[i].className;
            }
        }
    }
}

function fOpenJobLink(idc, id, idp, jobid, action) {
    var win = window.open('popjobdetail.aspx?idc=' + idc + '&guiditem=' + id + '&idp=' + idp + '&jobid=' + jobid + '&aktion=' + action + '', 'jobdetail', '' + screen.width - 50 + ',' + screen.height - 50 + ',left=50,top=50,scrollbars=yes,resizable=yes');
    if (win) {
        win.focus();
    }
}


function fFocusOnLoad(obj) {
    if (obj.location.pathname.indexOf('suchergebnis') > -1) {
        obj.window.BodyResultsDiv.focus();
    }
}

var prefix_opt_std = 'ctl00_ContentPlaceHolder1_Search_';
var prefix_opt_svz = 'ctl00_ContentPlaceHolder1_SearchSVZ_';

// #T06606
var options = new Array(
            'SearchText',
            'CityText',
            'JobAreaSelection_DropDownList1',
            'JobPeriodSelection',
            'OfferTypeSearch_RadioButtonList1_0',
            'OfferTypeSearch_RadioButtonList1_1',
            'OfferTypeSearch_RadioButtonList1_2',
            'OfferTypeSearch_RadioButtonList1_3',
            'SearchTitleOpt',
            'OperatorOptions_0',
            'OperatorOptions_1',
            'SFOptionsList_0',
            'SFOptionsList_1',
            'SFOptionsList_2',
            'SFOptionsList_3'
        );


function fCheckKeyDown(evt) {
    if ((evt && evt.keyCode == 13) || event.keyCode == 13)
    {
        //debugger;
        if (document.activeElement && document.activeElement.id.endsWith('SearchRegioCat_CBSearchRegion_Input')) {
            if (fCheckSubmit(document.activeElement)) {
                __doPostBack('ctl00$ContentPlaceHolder1$SearchRegioCat$SearchButton', '');
                return false;
            }
        }
        // 
        else if (document.activeElement && document.activeElement.id.search(prefix_opt_std) > -1) 
        {
            var blankid = document.activeElement.id.replace(prefix_opt_std, '');
            if (options.join(' ').search(blankid) > -1) {
                __doPostBack('ctl00$ContentPlaceHolder1$Search$SearchButton', ''); 
                return true;
            }
        }
        // 
        else if (document.activeElement && document.activeElement.id.search(prefix_opt_svz) > -1) {
        var blankid = document.activeElement.id.replace(prefix_opt_svz, '');
            if (options.join(' ').search(blankid) > -1) {
                __doPostBack('ctl00$ContentPlaceHolder1$SearchSVZ$SearchButton', '');
                return true;
            }
        }
        return false;
    }
}

function fCheckSubmit(obj) {
    var t = document.getElementById(obj.id.replace('SearchButton', 'CBSearchRegion'));
    if (t) {
        if (t.value == '' || IsNumeric(t.value))
            return false;
    }
    return true;
}

function IsNumeric(input) {
    return (input - 0) == input && input.length > 0;
}

String.prototype.startsWith = function(c) {
    if (this.indexOf(c) == 0) {
        return true;
    }
    return false;
}

String.prototype.endsWith = function(str) {
    return (this.match(str + "$") == str)
}


function fOpenWindow(fn) {
    var win = window.open(fn, 'popwin', 'width=900,height=560,left=50,top=50,scrollbars=yes,resizable=no');
    if (win) {
        win.focus();
    }
}
