var bzFormatSource = function(referer){
if(!referer || referer == ""){
return "";
}
if(referer.charAt(referer.length-1) == "/"){ //remove trailing slashes
referer = referer.slice(0, -1);
}
//remove protocols
referer = referer.replace(/http\:\/\//,"");
referer = referer.replace(/https\:\/\//,"");
return 'source=' + referer;
}
var bzPopupCenter = function (url, title, w, h) {
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(url + "&popup=true", title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
if (window.focus) {
newWindow.focus();
}
};
var bzBuildOpeningsMarkup = function (openings) {
var html = '
';
var i;
for(i = 0; i < openings.length; i++) {
var opening = openings[i];
if(bzFilterBy && bzFilterValue) {
if(bzFilterBy === "department") {
if(!opening.department) continue;
if(opening.department.toLowerCase().trim() !== bzFilterValue.toLowerCase().trim()) continue;
}
if(bzFilterBy === "location") {
if(!opening.location || !opening.location.name) continue;
if(opening.location.name.toLowerCase().trim() !== bzFilterValue.toLowerCase().trim()) continue;
}
if(bzFilterBy === "jobtype") {
if(!opening.type || !opening.type.name) continue;
if(opening.type.name.toLowerCase().trim() !== bzFilterValue.toLowerCase().trim()) continue;
}
}
html += '- ';
if(bzPopupEnabled) {
html += '';
} else {
html += '';
}
html += '';
html += '
' + opening.name + '
';
html += '';
html += '';
html += ' ';
}
html += '
';
return html;
};
var bzBuildOpeningsByCategoryMarkup = function (openings, category) {
var deptOpenings = {};
var deptKeys = [];
for(var i in openings) {
var opening = openings[i]
var key, name;
if(category === "dept") {
if(!opening.department) opening.department = "Other";
key = opening.department.toLowerCase().replace(/\s/g,'');
name = opening.department;
} else if(category === "loc") {
key = opening.location.name.toLowerCase().replace(/\s/g,'');
name = opening.location.name;
}
if(deptKeys.indexOf(key) === -1) {
deptKeys.push(key);
deptOpenings[key] = {
'name': name,
'list': []
};
}
deptOpenings[key].list.push(opening);
}
var html = '';
for(var k in deptKeys.sort()) {
var dept = deptOpenings[deptKeys[k]];
html += '- ';
html += '
' + dept.name + '
';
html += bzBuildOpeningsMarkup(dept.list);
html += ' ';
}
html += '
';
return html;
};
var bzDisplayOpenings = function (html) {
document.getElementById("bzOpeningsContainer").innerHTML += html;
};
var bzGetParameterByName = function (name) {
var url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return;
if (!results[2]) return;
return decodeURIComponent(results[2].replace(/\+/g, " "));
};
var bzDoWork = function () {
var portalUrl = 'https://swa-group.breezy.hr/json';
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var openings = JSON.parse(xmlhttp.responseText);
var html;
if(bzGroupBy === "dept") {
//console.log('Processing group_by=dept');
html = bzBuildOpeningsByCategoryMarkup(openings, "dept");
} else if(bzGroupBy === "loc") {
//console.log('Processing group_by=loc');
html = bzBuildOpeningsByCategoryMarkup(openings, "loc");
} else {
//console.log('Processing...');
html = bzBuildOpeningsMarkup(openings);
}
//console.log("HTML: " + html);
bzDisplayOpenings(html);
}
};
xmlhttp.open('GET', portalUrl, true);
xmlhttp.send();
};
var bzPopupHeight = 700;
var bzPopupWidth = 1000;
var bzPopupEnabled = true;
var bzGroupBy = "none";
var bzFilterBy = "";
var bzFilterValue = "";
var bzWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var bzSource = bzFormatSource(document.referrer);
if(bzWidth < 850) {
bzPopupEnabled = false;
} else if(bzWidth < 1024) {
bzPopupWidth = 750;
bzPopupHeight = 560;
}
bzDoWork();