﻿var mobileDetect = {
	init: function() {
		this.userAgent = navigator.userAgent.toLowerCase();
	},
	isIphone: function() {
		this.isBrowser = (this.userAgent.indexOf(this.mobileAgent["iphone"].productFamily) == -1) ? false : true;
		return this.isBrowser;
	},
	isIpod: function() {
		this.isBrowser = (this.userAgent.indexOf(this.mobileAgent["ipod"].productFamily) == -1) ? false : true;
		return this.isBrowser;
	},
	isBlackberry: function() {
		this.isBrowser = (this.userAgent.indexOf(this.mobileAgent["blackberry"].productFamily) == -1) ? false : true;
		return this.isBrowser;
	},
	isAndroid: function() {
		this.isBrowser = (this.userAgent.indexOf(this.mobileAgent["android"].productFamily) == -1) ? false : true;
		return this.isBrowser;
	},
	isIemobile: function() {
		this.isBrowser = (this.userAgent.indexOf(this.mobileAgent["iemobile"].productFamily) == -1) ? false : true;
		return this.isBrowser;
	},
	isPalmPre: function() {
		this.isBrowser = (this.userAgent.indexOf(this.mobileAgent["palm pre"].productFamily) == -1) ? false : true;
		return this.isBrowser;
	},
	getMobileAgent: function() {
		var strMobile;
		for (var property in this.mobileAgent) {
			if (this.userAgent.indexOf(this.mobileAgent[property].productFamily) != -1) {
				strMobile = property;
				if (this.mobileAgent[property].model) {
					var tempProp = property;
					for (var property1 in this.mobileAgent[tempProp].model) {
						for (var i = 0; i < this.mobileAgent[tempProp].model[property1].length; i++) {
							if (this.userAgent.indexOf(this.mobileAgent[tempProp].model[property1][i]) != -1) {
								strMobile += ", " + property1;
							}
						}
					}
				}
				return strMobile;
			}
		}
		return null;
	},
	mobileAgent: {
		"iphone": {
			"productFamily": "iphone"
		},
		"ipod": {
			"productFamily": "ipod"
		},
		"blackberry": {
			"productFamily": "blackberry",
			"model": {
			    "torch": ["blackberry 9800"],
				"tour": ["blackberry9630"],
				"storm": ["blackberry9500", "blackberry9530"],
				"bold": ["blackberry9000", "blackberry9100"],
				"88XX": ["blackberry8800", "blackberry8820", "blackberry8830"],
				"electron": ["blackberry8700", "blackberry8700c", "blackberry8700f", "blackberry8700g", "blackberry8700r", "blackberry8700v", "blackberry8703", "blackberry8703e", "blackberry8705g", "blackberry8707", "blackberry8707v"],
				"curve": ["blackberry8300", "blackberry8310", "blackberry8320", "blackberry8330", "blackberry8350i", "blackberry8900"],
				"pearl flip": ["blackberry8220", "blackberry8230"],
				"pearl": ["blackberry8100", "blackberry8110", "blackberry8120", "blackberry8130"]
			}
		},
		"palm pre": {
			"productFamily": "pre/1.0"
		},
		"android": {
			"productFamily": "android"
		},
		"iemobile": {
			"productFamily": "iemobile"
		}
	}
};

mobileDetect.init();

if (tradingSystem == 'forextrader') {
    var qs = new Querystring();
    var redir = qs.get('redir');
    var redir2 = GetCookie('redir');    
    
    if ((redir != '0') && (redir2 != '0') && siteid!='de') {
        if (mobileDetect.isIphone() || mobileDetect.isIpod() || mobileDetect.isAndroid() || mobileDetect.isPalmPre() || (mobileDetect.getMobileAgent()=="blackberry, torch")) {
            var showLand = Cookie.read('showLand');
            var locURL = 'mobile/Index.aspx';
            if (mobileDetect.isIphone() || mobileDetect.isIpod()) {
                if (showLand == null) {
                    Cookie.write('showLand', 'no', { duration: 30 });
                    locURL = "land-iphone.html";
                }
            }
            else if (mobileDetect.isAndroid()) {
                if (showLand == null) {
                    Cookie.write('showLand', 'no', { duration: 30 });
                    locURL = "land-android.html";
                }
            }
            window.location.href = locURL;
        } else if (mobileDetect.isBlackberry() || mobileDetect.isIemobile() || /midp/.test(mobileDetect.getMobileAgent())) {
            switch (GetCookie('wsEntity')) {
                case 'NA': window.location.href = "http://wap.forex.com"; break;
                case 'EU': window.location.href = "http://ssl.efxnow.com/mobile/default.aspx?6272616E64%3d6763756B%266C616E67%3d656E%26%3d"; break;
                case 'AU': window.location.href = "http://ssl.efxnow.com/mobile/default.aspx?6272616E64%3d67636175%266C616E67%3d656E%26%3d"; break;
                default: window.location.href = "http://wap.forex.com"; break;
            }
        }
    } 
}
