var mobileurl = "http://m.carsontaylor.co.nz"; var val = cookie("dispMobile"); if (IsMobileBrowser()) { if (window.location.href.indexOf("?full=1") != -1) { cookie("dispMobile", "false"); val = cookie("dispMobile"); } if (val) { if (val == "true") { window.location.replace(mobileurl); } } else { cookie("dispMobile", "true", { expires: 1 }); window.location.replace(mobileurl); } if (!val || val == "false") { addLoadEvent(createImageLink); } } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != "function") { window.onload = func; } else { window.onload = function () { oldonload(); func(); }; } } function createImageLink() { var body = document.getElementsByTagName("body")[0]; if (document.getElementById("mobile-link")) { return; } var rl = document.createElement("a"); rl.setAttribute("href", "javascript:redirectToMobile(mobileurl);"); rl.setAttribute("id", "mobile-link"); rl.setAttribute("OnMouseover", 'window.status="click for mobile version";this.style.backgroundColor="#CCCCCC"; return true;'); rl.setAttribute("OnMouseout", 'this.style.backgroundColor="transparent";'); rl.setAttribute("style", "font-family:Verdana, Geneva, sans-serif;font-size : 13px;font-style : normal; font-weight:normal;color:blue;line-height:30px;height:30px;text-indent:10px;position:absolute;top:2px;right:152px; z-index:1; width:230px;"); rl.innerHTML = 'click here for mobile version'; var child = body.getElementsByTagName("img"); for (var i = 0; i < child.length; i++) { if (child[i].getAttribute("src") != null && child[i].getAttribute("src").indexOf("BannerTop") > -1) { for (var ii = 0; ii < child[i].parentNode.childNodes.length; ii++) { if (child[i].parentNode.childNodes[ii].nodeName == "A") { child[i].parentNode.removeChild(child[i].parentNode.childNodes[ii]); break; } } child[i - 1].parentNode.insertBefore(rl, child[i - 1].parentNode.firstChild); return; } } } function redirectToMobile(mobileurl) { if (cookie("dispMobile")) { cookie("dispMobile", null); } window.location.replace(mobileurl); } function IsMobileBrowser() { var userAgent = navigator.userAgent; var mobPattern = ["midp", "j2me", "avant", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows ce", "mmp/", "blackberry", "mib/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up.b", "audio", "SIE-", "SEC-", "samsung", "HTC", "mot-", "mitsu", "sagem", "sony", "alcatel", "lg", "eric", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "dddi", "moto", "iphone", "ipad", "ipod"]; var mobExclude = ["boie9;enus"]; for (var i = 0; i < mobExclude.length; i++) { var pat = new RegExp(mobExclude[i], "i"); if (pat.test(userAgent)) { return false; } } for (var i = 0; i < mobPattern.length; i++) { var pat = new RegExp(mobPattern[i], "i"); if (pat.test(userAgent)) { return true; } } return false; } function cookie (key, value, options) { if (arguments.length > 1 && String(value) !== "[object Object]") { if (options == undefined) { options = {}; } if (value === null || value === undefined) { options.expires = -1; } if (typeof options.expires === 'number') { var days = options.expires, t = options.expires = new Date(); t.setDate(t.getDate() + days); } value = String(value); return (document.cookie = [encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : ''].join('')); } options = value || {}; var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent; return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null; };