	function gup( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return results[1];
	}
	
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function autoRedirect() {
		
		var mobile = false;
		
		// ---- check if url param is set to by pass mobile auto redirect ----
		// ---- then check if cookie are set to not redirect to mobile ----
		// ---- finally check if user agent is mobile device ----
		// ---- default to false ----
		if (gup('mobile') == 'false') {
			var date = new Date();
			date.setTime(date.getTime()+(30*60*1000));
			var expired = date.toGMTString();
			document.cookie = "noredirect=true; expires="+expired+"; path=/";
			
			mobile = false;
		} else if (readCookie('noredirect') == 'true') {

			mobile = false;
		} else if (
				(navigator.userAgent.match(/iPod|iPhone/i)) ||
				(navigator.userAgent.match(/android/i)) ||
				(navigator.userAgent.match(/opera mini/i)) ||
				(navigator.userAgent.match(/blackberry/i)) ||
				(navigator.userAgent.match(/(palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i)) ||
				(navigator.userAgent.match(/(windows ce; ppc;|windows ce; smartphone;|windows ce; iemobile)/i)) ||
				(navigator.userAgent.match(/(polaris|lge|nokia|samsung)/i))
//		(navigator.userAgent.match(/^(1207|3gso|4thp|501i|502i|503i|504i|505i|506i|6310|6590|770s|802s|a wa|acer|acs-|airn|alav|asus|attw|au-m|aur |aus |abac|acoo|aiko|alco|alca|amoi|anex|anny|anyw)/i)) ||
//		(navigator.userAgent.match(/^(aptu|arch|argo|bell|bird|bw-n|bw-u|beck|benq|bilb|blac|c55|cdm-|chtm|capi|comp|cond|craw|dall|dbte|dc-s|dica|ds-d)/i)) ||
//		(navigator.userAgent.match(/^(ds12|dait|devi|dmob|doco|dopo|el49|erk0|esl8|ez40|ez60|ez70|ezos|ezze|elai|emul|eric|ezwa|fake|sgh-)/i))
		) {
			mobile = true;
		} else {
			mobile = false;
		}
		
		return mobile;
	}
