var __writeBetIframe = function (){
  /* iframe height */
  var iHeight = 2000;
  /* iframe width */
  var iWidth = 240;
  /* iframe Init URL */
  var iFirstSrc = "/mobile/home";
  /* iframe cookie name*/
  var iCookieName = "BETSRC_2010"

  var doc = window.document;
  /* creates iframe-url by Cookie values */
  var beforeSrc = "";
  var getBeforeSrc = function (){
    var cVals = doc.cookie.split(";");
    for(var i=0; i<cVals.length; i++){
      var _val = cVals[i];
      _val = _val.replace(/^\s+|\s+$/g, ""); // trim
      _idx = _val.indexOf("=");
      if(_val.substring(0,_idx) == iCookieName){
        return unescape(_val.slice(_idx+1));
      }
    }
  }
  var beforeSrc = getBeforeSrc();

  /* If cookie values was empty, sets by Home.  */
  if(!beforeSrc) beforeSrc = iFirstSrc;

  /* Confirm page is can't see, because the page was shown by Post Method.  */
  beforeSrc = beforeSrc.replace(/\/confirm/g, "");


  /* write iframe. */
  doc.write('<iframe marginheight="0" marginwidth="0" scrolling="no" allowtransparency="true" frameborder="0" style="border: 0px;" id="betif" height="'+iHeight+
              '" width="'+iWidth+'" src="'+ beforeSrc +'"></iframe>');

  var ifrm = doc.getElementById("betif");

  /* iframe event handling */
  var onLoadIframe = function () {
    /* to page's top */
    window.scroll(0,ifrm.offsetTop );
    /* registry iframe src to cookie */
    doc.cookie = iCookieName + "=" + escape(ifrm.contentWindow.location);
  }

  /* IE */
  if(doc.all){
    ifrm.onreadystatechange = function() {
      if (this.readyState != "complete") return;
      onLoadIframe();
    }
  }
  /* other Browser */
  else {
    ifrm.onload = function() {
      onLoadIframe();
    }
    ifrm.onload = function() {
      onLoadIframe();
    }
  }
  /* Parent page moved  */
  window.onbeforeunload = function(){
    if(getBeforeSrc().indexOf("/confirm") != -1) {
      return "※ページを移動すると編集中の内容は消えてしまいます！";
    }
  }

}();

