
/*
function gotoMobileSite()
{
	sessionStorage.setItem("site_preference","Mobile");
	document.location = mobile_site;
}

function gotoDesktopSite()
{
	sessionStorage.setItem("site_preference","Desktop");
	document.location = desktop_site;

}
*/

function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}

function redirect()
{

    if(window.sessionStorage)
    {
        if(sessionStorage.getItem("gotomobilesite") == 2)    
        {
            return;
        }
    }
    
    document.url = mobile_site;
    document.location = mobile_site;


    //if(typeof document.red == 'string'

}
function checkMobileRedirect()
{
	//if(sessionStorage.getItem("gotomobilesite") == 2)
	//{

	//}else{
                if(/iPhone|iPod|BlackBerry|Android|webOS|Windows CE|IEMobile|Opera Mini|Opera Mobi|HTC|LG-|LGE|SAMSUNG|Samsung|Symbian|Nokia|PlayStation|PLAYSTATION|NetFront|Nintendo DSi/.test(window.navigator.userAgent.toString())) {
                    redirect();
                }
		if (screen.width <= 699) {
                            redirect();
		}
                if(DetectIphoneOrIpod())redirect();
                if(DetectS60OssBrowser())redirect();
                if(DetectAndroidWebKit())redirect();
                if(DetectWindowsMobile())redirect();
                if(DetectBlackBerry())redirect();
                if(DetectPalmOS())redirect();
                
	//}
}


if(querySt("desktop_site"))
{
     //alert(9);
     if(window.sessionStorage)
     {
        if(querySt("desktop_site")==1)sessionStorage.setItem("gotomobilesite",2);
        if(querySt("desktop_site")==0)sessionStorage.clear();
     }
}

var deviceIphone = "iphone";
var deviceIpod = "ipod";

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();

//**************************
// Detects if the current device is an iPhone.
function DetectIphone()
{
   if (uagent.search(deviceIphone) > -1)
      return true;
   else
      return false;
}

//**************************
// Detects if the current device is an iPod Touch.
function DetectIpod()
{
   if (uagent.search(deviceIpod) > -1)
      return true;
   else
      return false;
}

//**************************
// Detects if the current device is an iPhone or iPod Touch.
function DetectIphoneOrIpod()
{
    if (DetectIphone())
       return true;
    else if (DetectIpod())
       return true;
    else
       return false;
}


var deviceS60 = "series60";
var deviceSymbian = "symbian";
var engineWebKit = "webkit";

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();

//**************************
// Detects if the current browser is the S60 Open Source Browser.
// Screen out older devices and the old WML browser.
function DetectS60OssBrowser()
{
   if (uagent.search(engineWebKit) > -1)
   {
     if ((uagent.search(deviceS60) > -1 ||
          uagent.search(deviceSymbian) > -1))
        return true;
     else
        return false;
   }
   else
      return false;
}


var deviceAndroid = "android";

//**************************
// Detects if the current device is an Android OS-based device.
function DetectAndroid()
{
   if (uagent.search(deviceAndroid) > -1)
      return true;
   else
      return false;
}


//**************************
// Detects if the current device is an Android OS-based device and
//   the browser is based on WebKit.
function DetectAndroidWebKit()
{
   if (DetectAndroid())
   {
     if (DetectWebkit())
        return true;
     else
        return false;
   }
   else
      return false;
}


var deviceWinMob = "windows ce";

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();

//**************************
// Detects if the current browser is a Windows Mobile device.
function DetectWindowsMobile()
{
   if (uagent.search(deviceWinMob) > -1)
      return true;
   else
      return false;
}


var deviceBB = "blackberry";

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();

//**************************
// Detects if the current browser is a BlackBerry of some sort.
function DetectBlackBerry()
{
   if (uagent.search(deviceBB) > -1)
      return true;
   else
      return false;
}

var devicePalm = "palm";

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();

//**************************
// Detects if the current browser is on a PalmOS device.
function DetectPalmOS()
{
   if (uagent.search(devicePalm) > -1)
      return true;
   else
      return false;
}


checkMobileRedirect();
