
    var cvs0;
    var ctx0;
    var cvs1;
    var ctx1;
    var cvs2;
    var ctx2;
    var cvs3;
    var ctx3;
    var cvs4;
    var ctx4;
    var cvs5;
    var ctx5;
    var cvs6;
    var ctx6;
	var cvs7;
	var ctx7;
	var cvs8;
	var ctx8;
	var cvs9;
	var ctx9;
	var cvs10;
	var ctx10;
	
    var frameCell;
    var frameCellwoI;
    var frameTitle;
    var frameNav;
    var frameChr;
    var frameTrack;
    var frameTrackwR;
    var frameSNP;
	
	var frameZoomb;
	
    var ONSEARCH=false;
    var Objects=new Object();
	var timerArray = new Array();
	
    function render() {

      // Checking HTML5
      var canvasSupported = !!window.HTMLCanvasElement;
      if (!canvasSupported) document.location="./bin/error.php?prm_error_mode=HTML5";

      cvs0=document.getElementById("cvs_track_list");
      ctx0=cvs0.getContext("2d");
      cvs1=document.getElementById("cvs_tracks");
      ctx1=cvs1.getContext("2d");
      cvs2=document.getElementById("cvs_nav");
      ctx2=cvs2.getContext("2d");
      cvs3=document.getElementById("cvs_list");
      ctx3=cvs3.getContext("2d");
      cvs4=document.getElementById("cvs_view");
      ctx4=cvs4.getContext("2d");
      cvs5=document.getElementById("cvs_snpt");
      ctx5=cvs5.getContext("2d");
      cvs6=document.getElementById("cvs_snpg");
      ctx6=cvs6.getContext("2d");
	  cvs7=document.getElementById("cvs_ind");
      ctx7=cvs7.getContext("2d");
	  cvs8=document.getElementById("cvs_ind_blk");
      ctx8=cvs8.getContext("2d");
	  cvs9=document.getElementById("cvs_zbar");
      ctx9=cvs9.getContext("2d");
	  cvs10=document.getElementById("cvs_cellinf");
      ctx10=cvs10.getContext("2d");
	  
	  
      // Clear localStorage when url is sub directory on same domain
      if ( localStorage.getItem('_Url') != location.href ) localStorage.clear();

      _showLoading();
      _initCache();
      _execCanvas();

      // When first time
      if ( localStorage.getItem('_Count') == "1" ) {
        localStorage.setItem('_Count',"2");
      }

      $("#tasuke").css("background-color",_setColor().bgcolor);
    }

    ///////////////////////////////////////////////////////////
    // Initialize localStorage
    ///////////////////////////////////////////////////////////
    function _initCache() {
      if(_isEmpty(localStorage.getItem("_Url"))){
        localStorage.setItem("_Url",location.href);
      }
      if(_isEmpty(localStorage.getItem("_Ref"))){
        localStorage.setItem("_Ref","Reference");
      }
      if(_isEmpty(localStorage.getItem("_Zoom"))){
        localStorage.setItem("_Zoom","1k");
      }
      if(_isEmpty(localStorage.getItem("_Pos"))){
        localStorage.setItem("_Pos","1");
      }
      if(_isEmpty(localStorage.getItem("_Mode"))){
        localStorage.setItem("_Mode","s");
      }
      if(_isEmpty(localStorage.getItem("_Eff"))){
        localStorage.setItem("_Eff","off");
      }
      if(_isEmpty(localStorage.getItem("_Snpblock"))){
        localStorage.setItem("_Snpblock","off");
      }
      if(_isEmpty(localStorage.getItem("_QUAL"))){
        localStorage.setItem("_QUAL","20");
      }
      if(_isEmpty(localStorage.getItem("_DP"))){
        localStorage.setItem("_DP","2");
      }
      if(_isEmpty(localStorage.getItem("_DP4"))){
        localStorage.setItem("_DP4","2");
      }
      if(_isEmpty(localStorage.getItem("_Name"))){
        localStorage.setItem("_Name","id");
      }
      if(_isEmpty(localStorage.getItem("_NameSub"))){
        localStorage.setItem("_NameSub","subvariety");
      }
      if(_isEmpty(localStorage.getItem("_TitleW"))){
        localStorage.setItem("_TitleW","120");
      }
      if(_isEmpty(localStorage.getItem("_BlockW"))){
        localStorage.setItem("_BlockW","10");
      }
      if(_isEmpty(localStorage.getItem("_BlockH"))){
        localStorage.setItem("_BlockH","12");
      }
      if(_isEmpty(localStorage.getItem("_Block"))){
        localStorage.setItem("_Block","100");
      }
      if(_isEmpty(localStorage.getItem("_Indicator"))){
        localStorage.setItem("_Indicator","on");
      }
      if(_isEmpty(localStorage.getItem("_Amino"))){
        localStorage.setItem("_Amino","on");
      }
      if(_isEmpty(localStorage.getItem("_DirRef"))){
        localStorage.setItem("_DirRef","+");
      }
      if(_isEmpty(localStorage.getItem("_Null"))){
        localStorage.setItem("_Null","true");
      }
      if(_isEmpty(localStorage.getItem("_Keyword"))){
        localStorage.setItem("_Keyword","");
      }
      if(_isEmpty(localStorage.getItem("_History"))){
        localStorage.setItem("_History","[]");
      }
      if(_isEmpty(localStorage.getItem("_Color"))){
        localStorage.setItem("_Color","0");
      }
      if(_isEmpty(localStorage.getItem("_Count"))){
        localStorage.setItem("_Count","1");
      }
      if(_isEmpty(localStorage.getItem("_ListsDeleted"))){
        localStorage.setItem("_ListsDeleted","[]");
      }
      if(_isEmpty(localStorage.getItem("_Env"))){
        _execEnv();
      }
      if(_isEmpty(localStorage.getItem("_Lists"))){
        _execLists();
      }
      if(_isEmpty(localStorage.getItem("_Chr"))){
        _execChr();
        localStorage.setItem("_Chr",_getChr().id);
      }
	  if(_isEmpty(localStorage.getItem("_Onebase"))){
		localStorage.setItem("_Onebase", "off");
	  }
   }

    ///////////////////////////////////////////// Cheking empty
    function _isEmpty(value){
      return (value == null || value.length == 0);
    }

    ///////////////////////////////////////////////////////////
    // Ajax: get environment settings
    ///////////////////////////////////////////////////////////
    function _execEnv() {
      $.ajax({
        url: "./bin/env.php",
        cache: false,
        async: false,
        success: function(data) {
          localStorage.setItem("_Env", data);
        }
      });
    }

    ///////////////////////////////////////////////////////////
    // Ajax: get chromosome
    ///////////////////////////////////////////////////////////
    function _execChr() {
      $.ajax({
        url: "./bin/chr.php",
        cache: false,
        async: false,
        success: function(data) {
          localStorage.setItem("_Chrs", data);
        }
      });
    }

    ///////////////////////////////////////////////////////////
    // Ajax: get snpblock
    ///////////////////////////////////////////////////////////
    function _execSnpblock(keyword) {
      $.ajax({
        url: "./bin/snpblock.php",
        cache: false,
        async: false,
        data: {
          "prm_accession": keyword
        },
        success: function(data) {
          localStorage.setItem("_Snpblock", data.replace(/^[ 　\t\r\n]+|[ 　\t\r\n]+$/g, ""));
        }
      });
    }

    ///////////////////////////////////////////////////////////
    // Ajax: get list of accessions & tracks
    ///////////////////////////////////////////////////////////
    function _execLists() {
      $.ajax({
        url: "./bin/list.php",
        cache: false,
        async: false,
        success: function(data) {
          var a=data.split("|");
          localStorage.setItem("_Lists", a[0]);
          localStorage.setItem("_Lists-origin", a[0]);
          localStorage.setItem("_Tracks", a[1]);
        }
      });
    }

    ///////////////////////////////////////////////////////////
    // Ajax: Load information of cell
    ///////////////////////////////////////////////////////////
    function _execInfoCell(x,y) {

      var o=new Object(JSON.parse(localStorage.getItem('_Lists')));
	  var ct=-2;
	  for(var i in o){ct++;}
	  if(y >(Objects.BlockH*ct)){
		y=Objects.BlockH*ct;
	  }else if(y < 0){
		y=0;
	  }
      var id=o[parseInt(y/Objects.BlockH)].db;
      var b=Math.abs(parseInt((x/Objects.BlockW)));
	  if(b > Objects.Block-1){//when over cvs_view
		b = Objects.Block-2;
	  }
      var p=Objects.Pos+b;

      if ( _cvtZoom(Objects.Zoom) > 4000 ) { // When over 1k
        _drawInfoCell(id,b,y,"[]");
      } else {
        $.ajax({
          url: "./bin/info.php",
          type: "GET",
          cache: false,
          data: {
            "prm_Zoom":Objects.Zoom,
            "prm_Chr":Objects.Chr,
            "prm_Mode":Objects.Mode,
            "prm_Pos":p,
            "prm_QUAL":localStorage.getItem("_QUAL"),
            "prm_DP":localStorage.getItem("_DP"),
            "prm_DP4":localStorage.getItem("_DP4"),
            "prm_Acc":id
          },
          success: function(datas) {
            _drawInfoCell(id,b,y,datas);
          }
        });
      }

    }

    ///////////////////////////////////////////////////////////
    // Ajax: Search ID
    //       1K zoom will setted
    ///////////////////////////////////////////////////////////
    function _execSearch(keyword) {
	  var target=keyword.split("|");
	  var cnt=0;
	  for(var i in target){cnt++;}
	  if(cnt>4){
			var len = target[2]-target[1];
			var blks = parseInt((len*1.1)/Objects.Block);
			var optBlks="";
			var locString="the target";
			var leftPos=1;
			var b=0;
			var c=0;
			var modLeftPos=0;
			if(blks < 1){blks=1;}
			var scale = Math.floor(Math.log(blks)/Math.log(10))+1;
			if(scale==3 && blks > 900){scale=4;}
			if (scale > 1){//processing for Block-size and postion
				b = (blks/Math.pow(10,(scale-1)));
				c = parseInt(b)*Math.pow(10,(scale-1));
				if(scale < 4){
					if(len*1.1 > c*Objects.Block){c = parseInt(b+1)*Math.pow(10,(scale-1));}
					leftPos=parseInt(target[1]/c)-(parseInt((Objects.Block-parseInt(len/c)-2)/2));
					optBlks=c+"b";
				}else{
					if(len*1.1 > c*1000*Objects.Block){c = parseInt(b+1)*Math.pow(10,(scale-1));}
					leftPos=parseInt(target[1]/c)-(parseInt((Objects.Block-parseInt(len/c))/2));
					optBlks=c/1000+"k";
				}
			}else{
				b = (blks/Math.pow(10,(scale-1)));
				c = parseInt(b)*Math.pow(10,(scale-1));
				if(len*1.1 > c*Objects.Block){c = parseInt(b+1)*Math.pow(10,(scale-1));}
				leftPos=parseInt(target[1]/c)-(parseInt((Objects.Block-parseInt(len/c)-2)/2));
				optBlks=c+"b";
			}
			if(scale < 4){
				p=_checkPos_Chr(leftPos*c,optBlks,target[3]);
			}else{
				p=_checkPos_Chr(parseInt(leftPos*c),optBlks,target[3]);
			}
			localStorage.setItem("_Keyword", target[0]);
			localStorage.setItem("_Chr", target[3]);
			localStorage.setItem("_Zoom", optBlks);
			localStorage.setItem("_Pos", p);
			_changeChromosomeSearch(target[0]);
	  }
    }

	///////////////////////////////////////////////////////////
    // Ajax: Search ID
    //       for  candidates
    ///////////////////////////////////////////////////////////
	
	function _preExecSearch(keyword,mode) {
      $.ajax({
        url: "./bin/search.php",
        type: "GET",
        cache: false,
        data: {
          "prm_chr":localStorage.getItem("_Chr"),
          "prm_zoom":localStorage.getItem("_Zoom"),
          "prm_keyword":keyword
        },
        success: function(datas) {
		   var spdatas = datas.split("~");
		   var cnt=-1;
		   var ls="<OPTGROUP label=\"&lt;ID&gt;&nbsp;&nbsp;&nbsp;&lt;Chromosome&gt;&nbsp;&nbsp;&nbsp;&lt;Start&#045;End&gt;&nbsp;&nbsp;&nbsp;&lt;Note&gt;\"></OPTGROUP>";
		   var tc=0;
		   var num="";
		   var submit="";
		   
		   for(var i in spdatas){cnt++;}
		   for(var t=0; t < cnt; t++){
			   var a=spdatas[tc].split("|");
			   var id = _delLFCR(a[0]);
			   var st = _delLFCR(a[1]);
			   var ed = _delLFCR(a[2]);
			   var c = _delLFCR(a[4]);
			   var note ="";
			   var raw_note="";
				if(a[5]){
					note = _delLFCR(a[5]);
					raw_note=note;
					var all=id+""+st+""+ed+""+c+""+note;
					if (all.length > 70){
						note=note.substring(0, (70-(all.length-note.length)));
						note=note+"...";
					}
				}
			   if(a[1]>0){
				 if(t==0){
					 ls = ls+"<option value='"+id+"|"+st+"|"+ed+"|"+c+"' selected title='"+raw_note+"'>"+id+"&#009;"+c+"&#009;"+st+"&#045;"+ed+"&#009;"+note+"</option>";
					 submit="<input type=\"submit\" id=\"prm_keyword_res\" value=\"GO\" onClick=\"_searchID(event)\"/>";
					 num="Search&nbsp;results&nbsp;:&nbsp;"+a[3];
				 }else{
					ls = ls+"<option value='"+id+"|"+st+"|"+ed+"|"+c+"' title='"+raw_note+"'>"+id+"&#009;"+c+"&#009;"+st+"&#045;"+ed+"&#009;"+note+"</option>";
					submit="<input type=\"submit\" id=\"prm_keyword_res\" value=\"GO\" onClick=\"_searchID(event)\"/>";
					num="Search&nbsp;results&nbsp;:&nbsp;"+a[3];
				 }
				 if(a[3] >= 1000){
					num="&nbsp;<font color='red'>Too&nbsp;many&nbsp;results&nbsp;were&nbsp;found.&nbsp;(Displayed&nbsp;only&nbsp;1&nbsp;to&nbsp;1000&nbsp;of&nbsp;"+a[3]+"&nbsp;results)<br>&nbsp;Try&nbsp;it&nbsp;again&nbsp;with&nbsp;other&nbsp;keywords.</font>";
				 }
			   } else {
					 if(st=="false1"){ 
						 ls = "<option value='NF' disabled>&nbsp;Note&nbsp;is&nbsp;not&nbsp;installed&nbsp;in&nbsp;TASUKE.&nbsp;&nbsp;</option>";
						 submit = "<input type=\"submit\" id=\"prm_keyword_res\" value=\"GO\" disabled />";
						 num="&nbsp;";
						 break;
					}else{
						 ls = "<option value='NF' disabled>&nbsp;Not&nbsp;found&nbsp;:&nbsp;"+_escapeHTML(keyword)+"</option>";
						 submit = "<input type=\"submit\" id=\"prm_keyword_res\" value=\"GO\" disabled />";
						 num="&nbsp;";
						 break;
					 }
			   }
			   tc++;
		   }
		   var cr = document.getElementById("prm_keyword_res_str");
		   cr.innerHTML=num;
           $('#prm_keyword_res').find('option').remove().end().append(ls);
		   $('#prm_keyword_res_sb').find('input').remove().end().append(submit);
        }
      });
    }
	
	//// replace LF and CR for Search
	function _delLFCR(string){
		string = string.replace( /\r\n/g , "\n" );	
		string = string.replace( /^(\n+)|(\n+)$/g , "" );
		return string
	}
	
    ///////////////////////////////////////////////////////////
    // Ajax: Get track&depth&variant and drawing
    ///////////////////////////////////////////////////////////
    function _execCanvas(p,b,s) {
	var thread=4;
      
      // Depth&Variants
      if (_isEmpty(p)) {
          p=localStorage.getItem("_Pos"); 
          b=localStorage.getItem("_Block"); 
      }
	  
	  baseobj=new Object(_getList("db"));
	  var countaAc=parseInt(baseobj.length/thread);
	  var mod = (baseobj.length)%thread;
	  var acLen = new Array();
	  var acPos = new Array();
	  acLen[0]=0;
	  acPos[0]=1;
	  if(countaAc==0){thread=1;}
	  for (var i = 1; i <= thread; i++) {
			acLen[i]=countaAc;
			if(i <= (mod)){
				acLen[i]++;
			}
			acPos[i]=acPos[i-1]+acLen[i-1];
	  }
	  
	  if(thread != 1){
		var jqXHRList = [];
		jqXHRList.push($.ajax({
			url: "./bin/track.php",
			type: "GET",
			cache: false,
			data: {
				"prm_Zoom":localStorage.getItem("_Zoom"),
				"prm_Chr":localStorage.getItem("_Chr"),
				"prm_Pos":localStorage.getItem("_Pos"),
				"prm_Block":localStorage.getItem("_Block"),
				"prm_Tracks":new Object(_getTrack("list"))
		    }
		}
		));
		for (var i = 1; i <= thread; i++) {
			jqXHRList.push($.ajax({ 
				url: "./bin/data.php",
				type: "POST",
				cache: false,
				data: {
				"prm_Ref":localStorage.getItem("_Ref"),
				"prm_width":localStorage.getItem("_BlockW"),
				"prm_Zoom":localStorage.getItem("_Zoom"),
				"prm_Chr":localStorage.getItem("_Chr"),
				"prm_Pos":p,
				"prm_QUAL":localStorage.getItem("_QUAL"),
				"prm_DP":localStorage.getItem("_DP"),
				"prm_DP4":localStorage.getItem("_DP4"),
				"prm_Block":b,
				"prm_Lists":new Object(_NgetList("db",acPos[i],acLen[i]))
				}
			}
			));
		}
		
		$.when.apply($, jqXHRList).done(function () {
			var datas = [];
			var statuses = [];
			var jqXHRResultList = [];
			var trdatas = [];
			var trstatuses = [];
			var trjqXHRResultList = [];
			
			var trresult = arguments[0];
				trdatas.push(trresult[0]);
				trstatuses.push(trresult[1]);
				trjqXHRResultList.push(trresult[3]);
				
			var n=trdatas[0].split("|");
			for (var i=0; i<_getTrack("list").length;i++){
			  localStorage.setItem("_Track_"+i, n[i]);
			}
			if ( localStorage.getItem("_Zoom") == '1b' ) {
			  localStorage.setItem("_FASTA", n[n.length-1]);
			}
			
			for (var i = 1; i < thread+1; i++) {
				var result = arguments[i];
				datas.push(result[0]);
				statuses.push(result[1]);
				jqXHRResultList.push(result[3]);
			}
			var dvdata="";
			for (var i = 0; i < arguments.length-1; i++) {
				if(i==0){
					dvdata=datas[i];
				}else{
					dvdata=dvdata+";"+datas[i];
				}
			}
			for(var x=0; x<timerArray.length; x++){	clearInterval(timerArray.shift());} // animation
			var d=dvdata.replace(/^\s+|\s+$/g, "");
			if (_isEmpty(s)) {
			  _setData(d);
			} else {
			  _setData_p(d,s,b);
			}
			_drawCanvas();
			DATAPFLAG=false;
		});
	  }else{
		// Track
		$.ajax({
			url: "./bin/track.php",
			type: "GET",
			cache: false,
			async: false,
			data: {
				"prm_Zoom":localStorage.getItem("_Zoom"),
				"prm_Chr":localStorage.getItem("_Chr"),
				"prm_Pos":localStorage.getItem("_Pos"),
				"prm_Block":localStorage.getItem("_Block"),
				"prm_Tracks":new Object(_getTrack("list"))
			},
			success: function(datas) {
				var n=datas.split("|");
				for (i=0; i<_getTrack("list").length;i++){
				  localStorage.setItem("_Track_"+i, n[i]);
				}
				if ( localStorage.getItem("_Zoom") == '1b' ) {
				  localStorage.setItem("_FASTA", n[n.length-1]);
				}
			}
		});
		$.ajax({
          url: "./bin/data.php",
          type: "POST",
          cache: false,
          data: {
            "prm_Ref":localStorage.getItem("_Ref"),
			"prm_width":localStorage.getItem("_BlockW"),
            "prm_Zoom":localStorage.getItem("_Zoom"),
            "prm_Chr":localStorage.getItem("_Chr"),
            "prm_Pos":p,
            "prm_QUAL":localStorage.getItem("_QUAL"),
            "prm_DP":localStorage.getItem("_DP"),
            "prm_DP4":localStorage.getItem("_DP4"),
            "prm_Block":b,
            "prm_Lists":new Object(_getList("db"))
          },
          success: function(datas) {
            var d=datas.replace(/^\s+|\s+$/g, "");
            if (_isEmpty(s)) {
              _setData(d);
            } else {
              _setData_p(d,s,b);
            }
			for(var x=0; x<timerArray.length; x++){	clearInterval(timerArray.shift());} // animation
            _drawCanvas();
			DATAPFLAG=false;
          }
		});
	  }
    }

	function _NgetList(str,num,count) {
      var a=new Array();
      var o=new Object(JSON.parse(localStorage.getItem("_Lists")));
	  var acCount=0;
	  var start=parseInt(num-1);
	  var end=parseInt(num-1+count);
      for(var i=start;i<end;i++){
        if(str=="id"){
          a[acCount]=o[i].id;
        }else if(str=="db"){
          a[acCount]=o[i].db;
        }else if(str=="name"){
          a[acCount]=o[i].name;
        }else if(str=="grp"){
          a[acCount]=o[i].grp;
        }else if(str=="variety"){
          a[acCount]=o[i].variety;
        }else if(str=="origin"){
          a[acCount]=o[i].origin;
        }else if(str=="type"){
          a[acCount]=o[i].type;
        }
		acCount++;
      }
      return a;
    }
	
    ///////////////////////////////////////////////////////////
    // Double click for zoom in
    ///////////////////////////////////////////////////////////
    function _execDblClick(x) {
      if(_cvtZoom(Objects.Zoom)>1){
        var t=parseInt(x/Objects.BlockW);
        if (t==0) t=1;
        var b=(parseInt(Objects.Pos)+t)*_cvtZoom(Objects.Zoom);
        var p=_checkPos(parseInt(b/_cvtZoom(_cvtZoomDown(Objects.Zoom)))-(Objects.Block/2)+1,_cvtZoomDown(Objects.Zoom));
        localStorage.setItem("_Pos", new String(p));
        localStorage.setItem("_Zoom", _cvtZoomDown(Objects.Zoom));
        _showLoading();
        _drawMessageOnScreen("zoomInPos",x);
        _messageOnScreen("Zoom in "+Objects.Zoom+" to "+_cvtZoomDown(Objects.Zoom)+" per block");
        _execCanvas();
      } else {
        _messageOnScreen("Minimum zoom scale");
      }
      // Unlink cell information
      $("#dialog_infocell").dialog("close");
    }

    ///////////////////////////////////////////// Get chromosome
    function _getChr(id) {
      var a=new Object();
      var o=new Object(JSON.parse(localStorage.getItem("_Chrs")));
      if (_isEmpty(id)) {
        a.id=o[0].id;
        a.size=o[0].size;
        a.centromere=o[0].centromere;
      } else if (id == "max") {
        a.size=0;
        for(i=0;i<o.length;i++){
          if(parseInt(o[i].size)>parseInt(a.size)){
            a.size=o[i].size;
          }
        }
      } else {
        for(i=0;i<o.length;i++){
          if(o[i].id==id){
            a.id=o[i].id;
            a.size=o[i].size;
            a.centromere=o[i].centromere;
            break;
          }
        }
      }
      return a;
    }
    ///////////////////////////////////////////// Get list of accession by mode
    function _getList(str) {
      var a=new Array();
      var o=new Object(JSON.parse(localStorage.getItem("_Lists")));
      for(var i=0;i<o.length;i++){
        if(str=="id"){
          a[i]=o[i].id;
        }else if(str=="db"){
          a[i]=o[i].db;
        }else if(str=="name"){
          a[i]=o[i].name;
        }else if(str=="grp"){
          a[i]=o[i].grp;
        }else if(str=="variety"){
          a[i]=o[i].variety;
        }else if(str=="origin"){
          a[i]=o[i].origin;
        }else if(str=="type"){
          a[i]=o[i].type;
        }
      }
      return a;
    }

    ///////////////////////////////////////////// Get list of tracks
    function _getTrack(str) {
      var s=0;
      var a=new Array();
      var o=new Object(JSON.parse(localStorage.getItem("_Tracks")));
      if (str=="list") {
        for(var i=0;i<o.length;i++){
          a[i]=o[i].track;
        }
        return a;
      }
      if ( str=="view" ) {
        for(var i=0;i<o.length;i++){
          if (o[i].p==1){
            a.push(o[i].track);
          }
        }
        return a;
      }
    }

    ///////////////////////////// Set accession data to localStorage
    function _setData(str) {
      var n=str.split(";");
      for (var i=0; i<n.length; i++) {
         var a=n[i].split("|");
         localStorage.setItem(a[0], a[1]); // Rewrite if exists
      }
    }

    ///////////////////////////// Hide loading 
    function _hideLoading() {
      document.body.style.cursor = "default";
      _initEvents();
    }

    ///////////////////////////// Show loading 
    function _showLoading() {
      document.body.style.cursor = "wait";
      _removeEvents();
    }
 
    ///////////////////////////// Moving head or tail
    function _moveEdge(pos) {
      if ( pos == "s" ) {
        localStorage.setItem("_Pos", "1");
        msg="head";
      } else { 
        localStorage.setItem("_Pos",new String(_last(Objects.Zoom)-Objects.Block+1));
        msg="last";
      } 
      _showLoading();
      _messageOnScreen("Moving "+msg+" of "+Objects.Chr);
      _execCanvas();
    }

    ///////////////////////////// Moving page
    function _movePage(str) {
      var p=Objects.Pos;
      var b=Objects.Block;
      var msg;
      if (str == "+") {
        var c=0;
        if ((p+b+b-1)>_last(Objects.Zoom)) {
          localStorage.setItem("_Pos",new String(_last(Objects.Zoom)-b+1));
        } else {
          localStorage.setItem("_Pos", new String(p+b));
        }
        msg="right";
      } else {
        if (p-b<1) {
          localStorage.setItem("_Pos", new String(1));
        } else {
          localStorage.setItem("_Pos", new String(p-b));
        }
        msg="left";
      }

      _setHistory("position,"+Objects.Chr+","+p+","+Objects.Zoom);
      _drawMessageOnScreen(msg);
      _showLoading();
      _execCanvas();
    }

    ///////////////////////////// Initialize canvas with size
    function _initCanvas() {

      cvs0.width=Objects.titleWidth;
      cvs0.height=Objects.TrackH;
      ctx0.fillRect(0,0,cvs0.width, cvs0.height);
      ctx0.setTransform(1, 0, 0, 1, 0, 0);
      ctx1.font="11px 'Courier'";

      cvs1.width=Objects.canvasWidth;
      cvs1.height=Objects.TrackH;
      ctx1.fillRect(0,0,cvs1.width, cvs1.height);
      ctx1.setTransform(1, 0, 0, 1, 0, 0);
      ctx1.font="11px 'Courier'";

      cvs2.width=Objects.canvasWidth;
      cvs2.height=Objects.NavH;
      ctx2.fillRect(0,0,cvs2.width, cvs2.height);
      ctx2.setTransform(1, 0, 0, 1, 0, 0);
      ctx2.font="11px 'Century'";

      cvs3.width=Objects.titleWidth;
      cvs3.height=Objects.canvasHeight;
      ctx3.fillRect(0,0,cvs3.width,cvs3.height);
      ctx3.setTransform(1, 0, 0, 1, 0, 0);
      ctx3.font="11px 'Courier'";

      cvs4.width=Objects.canvasWidth;
      cvs4.height=Objects.canvasHeight;
      ctx4.fillStyle="#ffffff";
      ctx4.fillRect(0,0,cvs4.width,cvs4.height);
      ctx4.setTransform(1, 0, 0, 1, 0, 0);
      ctx4.font="10px 'Courier'";

      cvs5.width=Objects.titleWidth;
      cvs5.height=20;
      ctx5.fillStyle=_setColor().bgcolor;
      ctx5.fillRect(0,0,cvs5.width,cvs5.height);
      ctx5.setTransform(1, 0, 0, 1, 0, 0);
      ctx5.font="12px 'Courier'";

      cvs6.width=Objects.canvasWidth;
      cvs6.height=20;
      ctx6.fillStyle=_setColor().bgcolor;
      ctx6.fillRect(0,0,cvs6.width,cvs6.height);
      ctx6.setTransform(1, 0, 0, 1, 0, 0);
      ctx6.font="11px 'Courier'";
	
	  if(Objects.canvasHeight < 130){
		  var elementind = document.getElementById("ind"); 
		  var indmode=localStorage.getItem("_Mode");
		  if(indmode == "s" || indmode == "i" || indmode == "dp"){
			elementind.style.marginTop = ((-150)+(95-Objects.canvasHeight))+"px"; 
		  }else if(indmode == "dp+s" || indmode == "dp+i" || indmode == "si"){
			elementind.style.marginTop = ((-150)+(113-Objects.canvasHeight))+"px"; 
		  }else if(indmode == "dp+a"){
			elementind.style.marginTop = ((-150)+(130-Objects.canvasHeight))+"px"; 
		  }
	  }
	
	  cvs7.width=150;
      cvs7.height=135;
	  ctx7.fillStyle='rgba(0,0,0,0)';
      ctx7.fillRect(0,0,cvs7.width,cvs7.height);
	  ctx7.fillStyle='rgba(255,255,255,0.6)';
      ctx7.fillRect(4,cvs7.height-28,cvs7.width-8,23);
	  ctx7.strokeStyle="#acacb3";
      ctx7.lineWidth=1;
      ctx7.strokeRect(4,cvs7.height-28,cvs7.width-8,23);
      ctx7.setTransform(1, 0, 0, 1, 0, 0);
      ctx7.font="10px 'Courier'";
	  
	  cvs8.width=Objects.canvasWidth;
	  cvs8.height=1;
	  ctx8.fillStyle='rgba(0,0,0,0)';
      ctx8.fillRect(0,0,cvs8.width,1);
      ctx8.setTransform(1, 0, 0, 1, 0, 0);
      ctx8.font="10px 'Courier'";
//	  
	  cvs9.width=450;
      cvs9.height=44;
	  ctx9.fillStyle=_setColor().bgcolor;
      ctx9.fillRect(0,0,cvs9.width,cvs9.height);
	  ctx9.strokeStyle="#302833";
	  ctx9.lineWidth=30;
	  ctx9.beginPath();
	  ctx9.moveTo(3,21);
	  ctx9.lineTo(451,21);
	  ctx9.stroke();
	  ctx9.closePath();
	  ctx9.lineWidth=23;
	  ctx9.beginPath();
	  ctx9.lineCap = "round";
	  ctx9.moveTo(14,12);
	  ctx9.lineTo(440,12);
	  ctx9.stroke();
	  ctx9.closePath();
	  ctx9.beginPath();
	  ctx9.lineCap = "round";
	  ctx9.moveTo(14,34);
	  ctx9.lineTo(440,34);
	  ctx9.stroke();
	  ctx9.closePath();
	  
	  ctx9.shadowOffsetX = 0;
	  ctx9.shadowOffsetY = 0;
	  ctx9.shadowBlur = 0;
	  ctx9.strokeStyle="#999999";
	  ctx9.lineWidth=3;
	  ctx9.beginPath();
	  ctx9.arc(384, 19, 9, 0, Math.PI*2, false);
	  ctx9.stroke();
	  ctx9.beginPath();
	  ctx9.arc(419, 19, 9, 0, Math.PI*2, false);
	  ctx9.stroke();
	  ctx9.lineWidth=4;
	  ctx9.beginPath();
	  ctx9.moveTo(392,26);
	  ctx9.lineTo(405,37);
	  ctx9.closePath();
	  ctx9.stroke();
	  ctx9.beginPath();
	  ctx9.moveTo(425,26);
	  ctx9.lineTo(438,37);
	  ctx9.closePath();
	  ctx9.stroke();
	  ctx9.fillStyle=_setColor().zoombar;
	  ctx9.fillRect(383,13,2,12);
      ctx9.fillRect(378,17.5,12,2);
      ctx9.fillRect(413,17.5,12,2);

	  ctx9.setTransform(1, 0, 0, 1, 0, 0);
	  ctx9.font="10px 'Courier'";
	  frameZoomb=ctx9.getImageData(0, 0, cvs9.width, cvs9.height);
//
	  var elementcell = document.getElementById("cellinf"); 
	  elementcell.style.top = '1px'; 
	  elementcell.style.left = '1px';
	  cvs10.width=1;
	  cvs10.height=1;
	  ctx10.fillStyle='rgba(0,0,0,0)';
      ctx10.fillRect(0,0,cvs10.width,cvs10.height);
      ctx10.setTransform(1, 0, 0, 1, 0, 0);
      ctx10.font="10px 'Courier'";

      // Set to main canvas height
      var offset=20;
      var divHeight=window.innerHeight-$('#content').offset().top-$('#content2').height()-$('#bottom').height()-offset;
      if ( Objects.canvasHeight < divHeight ) {
        divHeight=Objects.canvasHeight+10;
      }
      $('#content').css("height", divHeight);

      // Changing height during resize
      $(window).bind("resize", resizeWindow);
      function resizeWindow( e ) {
        divHeight=$(window).height()-$('#content').offset().top-$('#content2').height()-$('#bottom').height()-offset;
        if ( Objects.canvasHeight < divHeight ) {
          divHeight=Objects.canvasHeight+10;
        } $('#content').css("height", divHeight);
      }

   }

    ///////////////////////////// Print area
    function _printArea(area) {
      t=area*_cvtZoom(Objects.Zoom);
      if (t<1000) {
        return String(t)+" bp";
      } else if (t>=1000 && t<1000000) {
        return String(t/1000)+" kbp";
      } else if (t>=1000000) {
        return String(t/1000000)+" mbp";
      }
    }

    ///////////////////////////// Print pos by zoom
    function _printPos(pos) {
      z=_cvtZoom(Objects.Zoom);
      t=parseInt(pos*z);
      if (z<1000) {
        return String(t)+" b";
      } else if (z>=1000 && z<1000000) {
        return String((t/1000))+" k";
      } else if (z>=1000000) {
        return String((t/1000000))+" m";
      }
    }

    ///////////////////////////// Drawing Snpblock: Estimation of SNP "blocks"
    function _getSnpblock(str) {
      var o=new Object(JSON.parse(localStorage.getItem('_Snpblock')));
      for (var x=0; x<o.length; x++) {
        var pattern=new RegExp(str);
        if(o[x].id.match(pattern)) {
          return o[x].rate;
        }
      }
    }
 
    /////////////////////////////////////////////// Stop drag when mouse up
    function _getData_p(d) {
        var s;
        var t=0;
        var p=0
        var b=Math.abs(parseInt(d/Objects.BlockW));
        var setP;
        if (d>0){
            s="right";
            t=Objects.BlockW-d%Objects.BlockW;
            n=d+t;
            b=parseInt(n/Objects.BlockW);
            if(Objects.Pos-b<1){
              //n=parseInt(localStorage.getItem("_Pos"))*parseInt(Objects.BlockW)-6;
              n=0;
              b=Objects.Pos-1;
              p=1;
            } else {
              p=Objects.Pos-b;
            }
            setP=p;
        } else {
            s="left";
            t=Objects.BlockW+d%Objects.BlockW;
            n=d-t;
            b=Math.abs(n/Objects.BlockW);
            max=_last(Objects.Zoom);
            p=Objects.Pos+Objects.Block;
            if(p+b-1>max){
              p=max-(max-p);
              n=-((max-p+1)*Objects.BlockW);
              b=(max-p+1);
            }
            setP=p-Objects.Block+b;
        }

        // Set canvas by block width
        ctx2.clearRect(0, 30, cvs2.width, 30);
        ctx4.clearRect(0, 0, Objects.canvasWidth, Objects.canvasHeight);
        ctx4.putImageData(frameCellwoI, n, 0);
        ctx1.clearRect(0, 0, cvs1.width, cvs1.height);
        ctx1.putImageData(frameTrack, n, 0);
        ctx0.clearRect(0, 0, cvs0.width, cvs0.height);
        ctx0.putImageData(frameTrackTitle, 0, 0);
        ctx6.putImageData(frameSNP, n, 0);
        _drawMeter(setP,null);
        _drawRules();

        if (Objects.Indicator=="on") {
          _drawIndicator();
          _drawDirection();
        }

        // If occured gap
        if (b>0) {
          _showLoading();
          localStorage.setItem("_Pos", setP);  // need load, first position
          _setHistory("position,"+Objects.Chr+","+setP+","+Objects.Zoom);
          _execCanvas(p,b,s);   // Load part of datas
        }
    }

    ///////////////////////////// Stringfy of array data
    function _mergeObject(o){
      var str;
      str="{\"dp\":\"";
      if(o.dp == null){
        str=str+"";
      } else {
        str=str+o.dp;
      }
      str=str+"\"";
      if(o.s != undefined){
        str=str+",\"s\":\""+o.s+"\"";
      }
      if(o.i != undefined){
        str=str+",\"i\":\""+o.i+"\"";
      }
      if(o.d != undefined){
        str=str+",\"d\":\""+o.d+"\"";
      }
	  if(o.hs != undefined){
        str=str+",\"hs\":\""+o.hs+"\"";
      }
	  if(o.hi != undefined){
        str=str+",\"hi\":\""+o.hi+"\"";
      }
	  if(o.hd != undefined){
        str=str+",\"hd\":\""+o.hd+"\"";
      }
      str=str+"}";
      return str; 
    }

    ///////////////////////////// Set part of data
    function _setData_p(datas,s,b) {
      var n=datas.split(";");
      for (var i=0; i<n.length; i++) {
        var a=n[i].split("|");
        var o=JSON.parse(localStorage.getItem(a[0]));
        var j=new Object(JSON.parse(a[1]));
        var t="[";
        if(s=="left"){
        for(var k=0; k<o.length-b; k++) {
        t=t+_mergeObject(o[k+b])+",";
        }
        for(var k=0; k<b; k++) {
        t=t+_mergeObject(j[k]);
        if(k<b-1){t=t+",";}
        }
        } else {
        for(var k=0; k<b; k++) {
        t=t+_mergeObject(j[k])+",";
        }
        for(var k=0; k<o.length-b; k++) {
        t=t+_mergeObject(o[k]);
        if(k<o.length-b-1){t=t+",";}
        }
        }
        var t=t+"]";
        localStorage.setItem(a[0], t); // Rewrite if exists
      }
    }

    Array.prototype.remove = function(from, to) {
      var rest = this.slice((to || from) + 1 || this.length);
      this.length = from < 0 ? this.length + from : from;
      return this.push.apply(this, rest);
    };

    /////////////////////////////////////////////// Change display mode
    function _changeMode(str){
      if ( Objects.Snpblock == "off" ) {
        localStorage.setItem("_Mode", str);
        _drawCanvas();
      } else {
        _messageOnScreen("Mode is fixed reason why 'Snpblock' is on.");
      }
    }
	
	/////////////////////////////////////////////// Change display mode(switch)
    function _changeModeSW(str){
      if ( Objects.Snpblock == "off" ) {
		if (localStorage.getItem("_Mode") == str){
			localStorage.setItem("_Mode", "dp");
		} else {
			localStorage.setItem("_Mode", str);
		}
		_drawCanvas();
      } else {
        _messageOnScreen("Mode is fixed reason why 'Snpblock' is on.");
      }
    }
	

    /////////////////////////////////////////////// Change direction of reference
    function _changeDirRef(){
      if ( localStorage.getItem("_DirRef") == "+" ) {
        localStorage.setItem("_DirRef", "-");
      } else {
        localStorage.setItem("_DirRef", "+");
      }
    }

    /////////////////////////////////////////////// Change select chromosome for search ID
    function _changeChromosomeSearch(kwd){
      var chr=$('#prm_chr').val();
      $('#prm_chr').blur(); // focus out from select box
      _showLoading();
      _messageOnScreen("Moving to "+kwd);
      _execCanvas();
	  
      // Set chromosome option on dialog 'Search'
      $('#prm_position_chr').val(chr);
    }
	
	/////////////////////////////////////////////// Change select chromosome 
	function _changeChromosome(){
      var chr=$('#prm_chr').val();
      localStorage.setItem('_Chr', chr);
      localStorage.setItem('_Pos', '1');
      $('#prm_chr').blur(); // focus out from select box

      _showLoading();
      _messageOnScreen("Loading "+chr);
      _execCanvas();

      // Set chromosome option on dialog 'Search'
      $('#prm_position_chr').val(chr);
    }

    /////////////////////////////////////////////// Change zoom
    function _changeZoomS(zoom){

      var msg;
      var flag;
      var cZoom=_cvtZoom(Objects.Zoom);
      var tZoom=_cvtZoom(zoom);
	  var scrMsg="";
	  var toZoom="";
	  
      // Zoom in when over 1b
      if(zoom=='+') { 
        if ( _cvtZoom(Objects.Zoom) > 1 ){
          var b=(parseInt(Objects.Pos)+(Objects.Block/2))*_cvtZoom(Objects.Zoom);
          var p=_checkPos(parseInt(b/_cvtZoom(_cvtZoomDown(Objects.Zoom)))-(Objects.Block/2)-1,_cvtZoomDown(Objects.Zoom));
          localStorage.setItem("_Pos", new String(p));
          localStorage.setItem("_Zoom", _cvtZoomDown(Objects.Zoom));
          msg="zoomIn";
          flag=true;
        } else {
          msg="Minimum zoom scale";
          flag=false;
        }
      }

      // Zoom out when under 100k
      if(zoom=='-') {
        if (_cvtZoom(Objects.Zoom) < 100000){
          var b=(parseInt(Objects.Pos)+(Objects.Block/2))*_cvtZoom(Objects.Zoom);
          var p=_checkPos(parseInt(b/_cvtZoom(_cvtZoomUp(Objects.Zoom)))-(Objects.Block/2)+1,_cvtZoomUp(Objects.Zoom));
          localStorage.setItem("_Pos", new String(p));
          localStorage.setItem("_Zoom", _cvtZoomUp(Objects.Zoom));
          flag=true;
          msg="zoomOut";
        } else {
          msg="Maximum zoom scale";
          flag=false;
        }
      }

      if(msg=="zoomIn"){
        _drawMessageOnScreen(msg);
		scrMsg="Zoom in "+Objects.Zoom+" to "+_cvtZoomDown(Objects.Zoom)+" per block";
        _messageOnScreen(scrMsg);
		toZoom=_cvtZoomDown(Objects.Zoom);
      } else if ( msg=="zoomOut") {
		scrMsg="Zoom out "+Objects.Zoom+" to "+_cvtZoomUp(Objects.Zoom)+" per block";
        _messageOnScreen(scrMsg);
		toZoom=_cvtZoomUp(Objects.Zoom);
      } else {
        _messageOnScreen(msg);
      }
	
      if(flag){
		drCnt=0;
		timerArray.push(setInterval(function(){_trfMain(scrMsg,Objects.Zoom,toZoom);},50));
        _showLoading();
        _execCanvas();
      }
		
    }
	
	
	////////////////////////////////////////animation
	function _trfMain(m,czoom,zoom){
		var scale=_cvtZoom(zoom)/_cvtZoom(czoom);
		if(scale <= 1){
			scale=Math.pow(1-(1-scale), 1/10);
			ctx4.putImageData(frameCell, 0, 0);
			ctx4.drawImage(cvs4,parseInt((Objects.canvasWidth-(Objects.canvasWidth*scale))/2) ,0 ,parseInt(Objects.canvasWidth*scale) ,Objects.canvasHeight ,0,0 ,Objects.canvasWidth ,Objects.canvasHeight );
			frameCell=ctx4.getImageData(0, 0, cvs4.width, cvs4.height);
			_messageOnScreen(m);
			drCnt++;
			if( drCnt > 9 ){
				for(var x=0; x<timerArray.length; x++){
					clearInterval(timerArray.shift());
				}
			}
		}else{
			scale=Math.pow(scale, 1/10);  
			ctx4.putImageData(frameCell, 0, 0);
			ctx4.drawImage(cvs4,0 ,0 ,Objects.canvasWidth ,Objects.canvasHeight ,parseInt((Objects.canvasWidth/2)-Objects.canvasWidth/2/scale),0 ,parseInt(Objects.canvasWidth/scale) ,Objects.canvasHeight );
			frameCell=ctx4.getImageData(0, 0, Objects.canvasWidth , cvs4.height);
			ctx4.fillStyle="#ffffff";
			ctx4.fillRect(0, 0, parseInt((Objects.canvasWidth/2)-Objects.canvasWidth/2/(scale*Math.pow(scale, drCnt+1))), Objects.canvasHeight);
			ctx4.fillRect(parseInt((Objects.canvasWidth/2)+Objects.canvasWidth/2/(scale*Math.pow(scale, drCnt+1))), 0, parseInt((Objects.canvasWidth/2)-Objects.canvasWidth/2/(scale*Math.pow(scale, drCnt+1))), Objects.canvasHeight);
			_messageOnScreen(m);
			drCnt++;
			if( drCnt > 9){
				for(var x=0; x<timerArray.length; x++){
					clearInterval(timerArray.shift());
				}
			}
		}
		
	}
	
    /////////////////////////////////////////////// Change zoom
    function _changeZoom(zoom){

      var msg;
      var flag;
      var cZoom=_cvtZoom(Objects.Zoom);
      var tZoom=_cvtZoom(zoom);
	  var scrMsg="";

      if(zoom != Objects.Zoom){
        var b=(parseInt(Objects.Pos)+(Objects.Block/2))*_cvtZoom(Objects.Zoom);
        var p=_checkPos(parseInt(b/_cvtZoom(zoom))-(Objects.Block/2)+1,zoom);
        localStorage.setItem('_Pos', new String(p));
        localStorage.setItem('_Zoom', zoom);
        if ( cZoom > tZoom ) { msg="zoomInC" }
        else { msg="zoomOut"; }
        flag=true;
      } else {
        msg="Currently zoom scale is "+Objects.Zoom+" per block";
        flag=false;
      }

      if(msg=="zoomInC"){
        _drawMessageOnScreen(msg,tZoom,cZoom);
		scrMsg="Zoom in "+Objects.Zoom+" to "+zoom+" per block";
        _messageOnScreen(scrMsg);
      } else if ( msg=="zoomOut" ) {
		scrMsg="Zoom in "+Objects.Zoom+" to "+zoom+" per block";
        _messageOnScreen(scrMsg);
      } else {
       _messageOnScreen(msg);
      }
	  
      if(flag){
        drCnt=0;
		timerArray.push(setInterval(function(){_trfMain(scrMsg,Objects.Zoom,zoom);},50));
		_showLoading();
        _execCanvas();
      }

      // Set zoom option on dialog 'Search'
      $('#prm_position_zoom').val(zoom);

    }

    /////////////////////////////////////////////// Details accession
    function _changeRef(){
	  var i=document.getElementById("prm_chref").value;
      var o=new Object(JSON.parse(localStorage.getItem('_Lists')));
      if ( localStorage.getItem("_Ref") != o[i].db ) {
        _changeEff('off');
		_changeOnebase('off');
        localStorage.setItem("_Ref", o[i].db);
        msg="Changing reference "+o[i].id;
      } else {
        localStorage.setItem("_Ref", "Reference");
        msg="Reset reference";
      }
      // Estimation of SNP 'blocks' in changing reference
      if (localStorage.getItem("_Snpblock") != "off") {
        _execSnpblock(localStorage.getItem("_Ref"));
      }

      _changeNull();
	  _changeNull();//require
      _showLoading();
      _messageOnScreen(msg);
      _execCanvas();
	  _dlg_chref_cancel()
    }

    /////////////////////////////////////////////// Message on screen
    function _messageOnScreen(str){
      ctx4.textAlign="left";
      ctx4.fillStyle="#ffffff";
	  if(cvs4.height < 37){
		  ctx4.fillRect(((cvs4.width-350)/2),1,350,11);
		  ctx4.strokeStyle="#b0c4de";
		  ctx4.lineWidth=2;
		  ctx4.strokeRect(((cvs4.width-350)/2),1,350,11);
		  ctx4.font="Bold 8px 'Century'";
		  ctx4.fillStyle="#000000";
		  ctx4.fillText(str,((cvs4.width-350)/2)+20,1+9);
	  }else if(cvs4.height < 74){
		  ctx4.fillRect(((cvs4.width-350)/2),cvs4.height/6,350,35);
		  ctx4.strokeStyle="#b0c4de";
		  ctx4.lineWidth=5;
		  ctx4.strokeRect(((cvs4.width-350)/2),cvs4.height/6,350,35);
		  ctx4.font="Bold 13px 'Century'";
		  ctx4.fillStyle="#000000";
		  ctx4.fillText(str,((cvs4.width-350)/2)+20,cvs4.height/6+20);
	  }else{
		  ctx4.fillRect(((cvs4.width-350)/2),cvs4.height/4,350,60);
		  ctx4.strokeStyle="#b0c4de";
		  ctx4.lineWidth=7;
		  ctx4.strokeRect(((cvs4.width-350)/2),cvs4.height/4,350,60);
		  ctx4.font="Bold 13px 'Century'";
		  ctx4.fillStyle="#000000";
		  ctx4.fillText(str,((cvs4.width-350)/2)+20,(cvs4.height/4)+35);
	  }
    }
	
	function _changeOnebase(base){
		var en=new Object(JSON.parse(localStorage.getItem("_Env")));
		var zm = _cvtZoom(en.nuc_max);
		if(!zm){zm=4000;}
		if ( localStorage.getItem("_Ref") == "Reference") {
			if (localStorage.getItem('_Onebase')=="on" || base == "off"){
				localStorage.setItem('_Onebase', "off");
			}else{
				if (_cvtZoom(Objects.Zoom) > zm){
					localStorage.setItem("_Onebase", "off");
				}else{
					localStorage.setItem('_Onebase', "on");
				}
			}
			if ( localStorage.getItem("_Snpblock") != "off" && localStorage.getItem('_Onebase') == "on" ) {
            localStorage.setItem('_Onebase', "off");
          }
		}
		_drawCanvas();
	}
	
    /////////////////////////////////////////////// Change variant Effect
    function _changeEff(eff){
      if ( localStorage.getItem("_Ref") == "Reference") {
          if (localStorage.getItem('_Eff')=="on" || eff == "off") {
            localStorage.setItem('_Eff', "off");
          } else {
            localStorage.setItem('_Eff', "on");
          }
          if ( localStorage.getItem("_Snpblock") != "off" && localStorage.getItem('_Eff') == "on" ) {
            localStorage.setItem('_Snpblock', "off");
          }
      }
      _drawCanvas();
    }

    /////////////////////////////////////////////// Change snpblock
    function _changeSnpblock(){
      if ( localStorage.getItem("_Snpblock")=="off" ) {
        localStorage.setItem('_Eff', "off");
        //localStorage.setItem('_Mode', "dp+s");
		localStorage.setItem('_Mode', localStorage.getItem("_Mode"));
        _execSnpblock(localStorage.getItem("_Ref"));
      } else {
        localStorage.setItem("_Snpblock", "off");
      }
      _drawCanvas();
      if ( localStorage.getItem('_Snpblock') == "[]" ) {
        _messageOnScreen("Snpblock data is not found");
      }
    }

    /////////////////////////////////////////////// Change NULL on/off
    function _changeNull(){
      if (localStorage.getItem("_Null")=="false"){
        localStorage.setItem("_Null", "true");
      } else {
        localStorage.setItem("_Null", "false");
      }
      _drawCanvas();
    }

	/////////////////////////////////////////////// escape HTML
	function _escapeHTML(str) {
		return str.replace(/&/g, '&amp;')
			.replace(/</g, '&lt;')
			.replace(/>/g, '&gt;')
			.replace(/"/g, '&quot;')
			.replace(/'/g, '&#039;');
	}
	
	

