detectmobile = function(){

	var uagent = navigator.userAgent.toLowerCase(); 
	var list = ["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 ismobile = false;
			
	for(var d=0;d<list.length;d+=1){
		if(uagent.indexOf(list[d])!=-1){
			ismobile = true;
		}
	}
	return ismobile;
}
 
getvar = function(){

  var vars = new Array;
	var url = document.location.href;
	
	var exists = false;
	if(url.indexOf('rv=true')!=-1){
		exists = true;
	}
	return exists;
}

function setCookie(n,v){

 	var now = new Date();
 	var then = now.getTime();
  var exp = '; expires=' + then.toGMTString();
  document.cookie = n + "=" + escape(String(v)) + '; path=/' + exp;
  
}

function checkCookie(cookiename){
  if(document.cookie.length > 0 && document.cookie.indexOf(cookiename) != -1 ) {
  	return true;
  }else{
    return false;
  }
}


function init() {
  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  // kill the timer
  if (_timer) clearInterval(_timer);

  a = document.createElement('a');
  a.innerText = 'Diese Seite gibt es auch als Web-App auf deinem Smartphone. Hier klicken.';
  a.textContent = 'Diese Seite gibt es auch als Web-App auf deinem Smartphone. Hier klicken.';
  a.href = "http://moboox.com/app/"+uid+"?sl=1";
  a.setAttribute('style', 'font-size:9px;color:#a1a1a1;display:block; padding:5px 0; width:100%; text-align:right; background-color:#010101;text-decoration:none;position:fixed;bottom:0px;');  
 
  document.getElementsByTagName('body')[0].appendChild(a);
  
};

if(detectmobile() && typeof(uid) != "undefined"){
  if(getvar() || checkCookie('rv')){
    setCookie('rv','1');
  }else{
    document.location.href = "http://moboox.com/app/"+uid+"?sl=1";
  }
}else{
  /* for Mozilla/Opera9 */
  if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
  }
  
  /* for Internet Explorer */
  /*@cc_on @*/
  /*@if (@_win32)
    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    var script = document.getElementById("__ie_onload");
    script.onreadystatechange = function() {
      if (this.readyState == "complete") {
        init(); // call the onload handler
      }
    };
  /*@end @*/
  
  /* for Safari */
  if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
      if (/loaded|complete/.test(document.readyState)) {
        init(); // call the onload handler
      }
    }, 10);
  }

  window.onload = init;
}

