/*
   JS Mobile redirection
*/
if (doDeviceDetect() == 1)
{
	var device_type = isMobileDevice();
	/* if client device is a smart phone, then redirect to an smartphone specific page */
	if (location == "http://www.boq.com.au/")
	{
		if (device_type == 2)
		{
			location.replace("/sphone");
		}
		if (device_type == 1)
		{
			location.replace("/mobile");
		}
	}
	if (location == "http://www.boq.com.au/mobile/default.htm")
	{
		if (device_type == 2)
		{
			location.replace("http://www.boq.com.au/sphone/mobileweb.htm");
		}
	}
}

function doDeviceDetect()
{
  var loc = location.search.substring(1, location.search.length);
  var param_value = 1;

  var params = loc.split("&");
  for (i = 0; i < params.length; i++)
  {
      param_name = params[i].substring(0, params[i].indexOf('='));
      if (param_name == 'detect')
      {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  return param_value;
}

/*
	Detects if the user string is a mobile device. Returns the following:
	0 - if not a mobile
	1 - is a mobile
	2 - is a smartphone
*/
function isMobileDevice()
{
	if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) ||
	    navigator.userAgent.match(/BlackBerry9500/i) || navigator.userAgent.match(/BlackBerry9520/i)   ||
	    navigator.userAgent.match(/BlackBerry9530/i) || navigator.userAgent.match(/BlackBerry9550/i)   ||
      navigator.userAgent.match(/HTC_Touch_Diamond/i) || navigator.userAgent.match(/HTC_Touch_Pro2/i) ||
	    navigator.userAgent.match(/HTC Magic/i) || navigator.userAgent.match(/HTC_Touch_HD_T8282/i)	   ||
		  navigator.userAgent.match(/Palm850/i) || navigator.userAgent.match(/SAMSUNG-SGH-F480/i)        ||
	    navigator.userAgent.match(/SAMSUNG-SGH-i900/i) || navigator.userAgent.match(/SAMSUNG-S8300/i)  ||	    
		  navigator.userAgent.match(/LG-GC900/i) || navigator.userAgent.match(/LG-KM900/i)               ||
	    navigator.userAgent.match(/LG-KP500/i) || navigator.userAgent.match(/LG-GM730/i)               ||
	    navigator.userAgent.match(/Nokia5800/i) || navigator.userAgent.match(/NokiaN97/i)              ||
	    navigator.userAgent.match(/Nexus One/i))
	{
		return 2;
	}
	/* Samsung specific checks */
	if (navigator.userAgent.match(/SAMSUNG/i) &&
			(navigator.userAgent.match(/i8000/i) || navigator.userAgent.match(/I8910/i) ||
			 navigator.userAgent.match(/B7610/i) || navigator.userAgent.match(/B7300/i)))
	{
		return 2;
	}
	/* LG specific checks */
	if (navigator.userAgent.match(/LG/i) && 
	    (navigator.userAgent.match(/KC910/i) || navigator.userAgent.match(/KU990/i)))
	{
		return 2;
	}
	
	/* Check for generic phones */
	if (navigator.userAgent.match(/blackberry/i) || navigator.userAgent.match(/HTC-/i)    || 
	    navigator.userAgent.match(/HTC_/i) ||	navigator.userAgent.match(/LGE/)            ||		
	    navigator.userAgent.match(/MOT-/) ||  navigator.userAgent.match(/series60/i)      || 
	    navigator.userAgent.match(/symbian/i) || navigator.userAgent.match(/windows ce/i) ||
	    navigator.userAgent.match(/palm/i) ||	navigator.userAgent.match(/android/i))
	{
		return 1;
	}
	/* assume a PC  */
	return 0;
}


