
var DeviceDetector = function(){};

DeviceDetector.getUserAgent = function (request) {
    
    var operaUA = request.getHeader('HTTP_X_OPERAMINI_PHONE_UA');
    if (operaUA) {
        return operaUA;
    }
    
    var skyfireUA = request.getHeader('HTTP_X_SKYFIRE_PHONE');
    if (skyfireUA) {
        return skyfireUA;
    }
    
    var defaultUA = request.getHeader('HTTP_USER_AGENT');
    if (defaultUA) {
        return defaultUA;
    }
    
    return null;
};

DeviceDetector.isDesktop = function (request) {
    var ua = DeviceDetector.getUserAgent(request);
    if (ua) {
        return !DeviceDetector.RegExp.RE_MOBILE.test(ua) &&
                DeviceDetector.RegExp.RE_DESKTOP.test(ua) ||
                DeviceDetector.RegExp.RE_BOT.test(ua);
    }
    return true;
};

// wykrywanie urzadzen typu desktop
DeviceDetector.RegExp = {};
DeviceDetector.RegExp.RE_MOBILE = /(iphone|ipod|blackberry|android|palm|windows\s+ce)/i;
//DeviceDetector.RegExp.RE_MOBILE = /(kindle|htc|mobi|phone|ipod|blackberry|android|palm|windows\s+ce)/i;
DeviceDetector.RegExp.RE_DESKTOP = /(windows|linux|os\s+[x9]|solaris|bsd)/i;
//DeviceDetector.RegExp.RE_DESKTOP = /(windows|linux|os\s+[x9]|solaris|bsd|macintosh|winnt|win98|win95|beos|amigaos|irix|sunos|cros|dragonfly)/i;
DeviceDetector.RegExp.RE_BOT = /(spider|crawl|slurp|bot)/i;

exports.DeviceDetector = DeviceDetector;