var url = "http://iphone.woodmancastingx.com";
var message = "Do you want to access to iphone version website ?";

function WriteCookie(name, value)
{
  var argv=WriteCookie.arguments;
  var argc=WriteCookie.arguments.length;
  var expires=(argc > 2) ? argv[2] : null;
  var path=(argc > 3) ? argv[3] : null;
  var domain=(argc > 4) ? argv[4] : null;
  var secure=(argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape(value)+
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString()))+
  ((path == null) ? "" : ("; path="+path))+
  ((domain == null) ? "" : ("; domain="+domain))+
  ((secure == true) ? "; secure" : "");
}

function getCookieVal(offset)
{
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function ReadCookie(name)
{
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen)
  {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal(j);
    i =document.cookie.indexOf(" ",i)+1;
    if (i == 0)
      break;
  }
  return null;
}

if (navigator.userAgent.indexOf('iPhone') != -1 && ReadCookie("mobile_redirect") != "no") {
	  if (confirm(message)) {
	    document.location = url;
	  }else{
	    expiration_cookie=new Date;
	    expiration_cookie.setMonth(expiration_cookie.getDay()+2);
	    WriteCookie("mobile_redirect", "no", expiration_cookie);
	  }
	}

function getScrollXY() {
        var scrOfX = 0, scrOfY = 0;

        if (typeof(window.pageYOffset) == 'number') {
                // Netscape compliant
                scrOfX = window.pageXOffset;
                scrOfY = window.pageYOffset;
        } else if (document.body && ( document.body.scrollLeft || document.body.scrollTop)) {
                // DOM compliant
                scrOfX = document.body.scrollLeft;
                scrOfY = document.body.scrollTop;
        } else if (document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
                // IE6 standards compliant mode
                scrOfX = document.documentElement.scrollLeft;
                scrOfY = document.documentElement.scrollTop;
        }

        return [scrOfX, scrOfY];
}

function getSimpleWindowDim() {
        var width, height;

        if (window.innerWidth) {
                width = window.innerWidth;
                height = window.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientWidth) {
                width = document.documentElement.clientWidth;
                height = document.documentElement.clientHeight;
        }
        else if (document.body) {
                width = document.body.clientWidth;
                height = document.body.clientHeight;
        }
        else {
                alert('IGIITA');
        }
        return [width, height];
}

function getWindowDim() {
        var     dim, scr;

        dim = getSimpleWindowDim();
        scr = getScrollXY();
        return [dim[0] + scr[0], dim[1] + scr[1]];
}

function resizeMe() {
        minWidth = 900;
        minHeight = 300;
        idealWidth = 1024;
        idealHeight = 1024;
	
        dim = getWindowDim();
        myWidth = newWidth = dim[0];
        myHeight = newHeight = dim[1];

          if (myWidth < minWidth)
          {
                  if (screen.width >= idealHeight)
                  {
                          newWidth = screen.width;
                  }
                  else
                {
                        newWidth =  screen.width;
                  }
          }
          if (myHeight < minHeight)
          {
                newHeight = screen.height;
               newWidth =  screen.width;
          }
                if (myWidth != newWidth | myHeight != newHeight)
                {
                window.moveTo(0,0);
                  window.resizeTo(newWidth, newHeight);
                }

}

