var __mobile = function(){
  return {
    detect:function(){
      var uagent = navigator.userAgent.toLowerCase(); 
      var list = this.mobiles;
      var ismobile = false;
      for(var d=0;d<list.length;d+=1){
        if(uagent.indexOf(list[d])!=-1){
          ismobile = true;
        }
      }
      return ismobile;
    },

    mobiles:[
      "midp","240x320","blackberry","netfront","nokia","panasonic",
      "portalmmm","sharp","sie-","sonyericsson","symbian",
      "windows ce","benq","mda","mot-","opera mini",
      "philips","pocket pc","sagem","samsung","sda",
      "sgh-","vodafone","xda","palm","iphone",
      "ipod","android"
    ]
  };
}();

var args = getArgs();

if (args.donotredirect == 'yes') {
 __setCookie('mobile-donotredirect', 'yes', 365);
}

if (__getCookie('mobile-donotredirect') != 'yes' && __mobile.detect() && args.donotredirect != 'yes') {
  window.location = "http://mobile.movingestimates.com/";
}

function __setCookie(c_name, value, exdays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + exdays);
  var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
  document.cookie = c_name + "=" + c_value;
}

function __getCookie(c_name) {
  var i, x, y, ARRcookies = document.cookie.split(";");

  for (i =0; i<ARRcookies.length; i++) {
    x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
    y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
    x = x.replace(/^\s+|\s+$/g,"");
    if (x == c_name) {
      return unescape(y);
    }
  }
}

function getArgs() {
  var args = new Object();
  var query = window.location.search.substring(1); 
  var pairs = query.split("&"); 
  for(var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf('='); 
    if (pos == -1) continue; 
    var argname = pairs[i].substring(0,pos); 
    var value = pairs[i].substring(pos+1);
    args[argname] = unescape(value); 
  }
  return args; 
}

