function doMobileDetectRedirect(){

if(!checkCookie()) //check to see if cookie exists, if no cookie carry out test for mobile device
	{
	var expdays = 1;

	// detect if user device is desktop or mobile device
	if (!Liferay.Browser.isMobile())
		{
		// set user preference  
		setCookie('Device_pref','desktop',expdays);
		}
	else 
		{
		// set user preference  
		setCookie('Device_pref','mobile',expdays);
		
		//function to redirect user to mobile site, check if to redirect them to a specific page
		gotoMobilesite();
		
		}
	}
else if(checkCookie()) // if cookie is set, read cookie value
	{
	// if cookie preference is set to mobile
	if (getCookie('Device_pref') =='mobile')
		{
		gotoMobilesite();
		}
		
	}
				
}

function gotoMobilesite(){	 
	
	if(typeof RedirectToMobileSite == 'function') { 
		window.location.href = RedirectToMobileSite();
	}
	else window.location.href = "http://business.uea.ac.uk/mobile/";
}	


function linkToMobilesite(){	 
	var expdays = 1;
		
	setCookie('Device_pref','mobile',expdays);
	gotoMobilesite();
	
}	


function isAndroid(){
	var uagent = navigator.userAgent.toLowerCase(); 
	if (uagent.search('android') > -1)
		{
		return true;
		}
	else
		return false;
}

function getScreenWidth(){
	return screen.width;
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? '' : ';path=/; expires='+exdate.toUTCString());
document.cookie=c_name + '=' + c_value;
}

function checkCookie()
{
  if (getCookie('Device_pref') != null)
  {
  return true;
  }
else 
  {
  return false;
  }
} 

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);
    }
  }
}


