function changeInteraction(A,L)
{
	if (L.value == '0')
		document.location = document.location.pathname + "?ID=" + A ;
	else
		document.location = document.location.pathname + "?ID=" + A + "_" + L.value;
}

function changeImage(g_obj,Im_name,Im_alt)
{
	g_obj.src = Im_name;
	g_obj.alt = Im_alt; 
}

function checkSampleSearch(g_obj)
{
	if (g_obj.Filter.value.length < 1) 
	{
		alert("Please select the reference of ID Type!");
		return false;
	}
	if (g_obj.QS.value.length < 1)
	{
		alert("Please input the reference of Input Field!");
		return false;
	}
	g_obj.QS.value = g_obj.QS.value.replace(/(^\s*)|(\s*$)/g,"");
	return true;
}

function checkAdvanceSearch(g_obj)
{
	//alert(g_obj.SeqWeight.value);
	if ((g_obj.Spec.value == "-1" || g_obj.Spec.value == "-2") && g_obj.Taxon_ID.value.length < 1 && g_obj.Keyword.value.length < 1
		&& g_obj.Domain.value == "-1" && g_obj.Disulfide.value == "-1" &&  g_obj.Target.value == "-1"
		&& g_obj.SeqLength.value=="-1" && g_obj.MolWeight.value=="-1")
	{
		 alert("Please input reference accord to field name.");
		 return false;
	}
	return true;
}

function checkInteractionSearch(g_obj)
{
	if (g_obj.T_Spec.value == "-1" && g_obj.Type_C.value == "-1")
   {
		 alert("Please select item accord to field name.");
		 return false;
	}
	return true;
		 
}

function CheckDataDownload(a,g_obj)
{
	if (a == "Toxin")
	{
		if (g_obj.Species.value == "-1" && g_obj.Target.value == "-1" && g_obj.Action.value == "-1" && g_obj.Bridged.value.length < 1)
		{
			alert("Please set search condition!");
			return false;
		}
	}
	if (a == "Channel")
	{
		if (g_obj.Species_Channel.value == "-1" && g_obj.Channel_Type.value == "-1" && g_obj.SubType.value == "" && g_obj.Toxin_Species.value == "-1") 
		{
			alert("Please set search condition!");
			return false;
		}
	}
	if (a == "Interaction")
	{
		if (g_obj.Interaction.value == "1" && g_obj.ToxinID.value.length < 9)
		{
			alert("Please input ToxinID. (eg. AT0000003)");
			return false;
		}
		if (g_obj.Interaction.value == "2" && g_obj.ChannelID.value.length < 9)
		{
			alert("Please input ChannelID. (eg. CT0000031)");
			return false;
		}
	}
	return true;
}

function QueryString(qs)
{
    var s = location.search;
    s = s.substr(1,s.length);
    var t = s.split("&");
    var re = "";
    for(i=1;i<t.length;i++)
    {
        if(t[i].indexOf(qs+"=")==0) 
        {
        	re = t[i];
					break;
				}
    }
    return re;
}

function ChangeSpecButton(g_obj)
{
	
	if (g_obj.value == "1.1.1.1.1.1.2.1.1.1.1.1.1.4." ||
		g_obj.value == "1.1.1.1.1.1.2.1.1.2." ||
		g_obj.value == "1.1.2.1.1." ||
		g_obj.value == "1.1.1.1.1.1.1.1.1." ||
		g_obj.value == "1.1.1.1.1.1.5." ||
		g_obj.value == "1.1.1.1.1.1.2._2" ||
		g_obj.value == "-2" || g_obj.value == "1" || 
		g_obj.value == "2" || g_obj.value == "3" || 
		g_obj.value == "4" || g_obj.value == "-3")
	{
		
		getBox = document.getElementById("Toxin"); 
		getBox.checked = false;
		getBox = document.getElementById("Channel");
		getBox.checked = true;
		getBox = document.getElementById("Domain");
		getBox.disabled = true;
		getBox.value = "-1";
		getBox = document.getElementById("Target");
		getBox.disabled = true;
		getBox.value = "-1";
	}
	else
	{
		getBox = document.getElementById("Toxin");
		getBox.checked = true;
		getBox = document.getElementById("Channel"); 
		getBox.checked = false;
		getBox = document.getElementById("Domain");
		getBox.disabled = false;
		getBox = document.getElementById("Target");
		getBox.disabled = false;
	}
}

function ChangeAddress(inCount,inType)
{
	var getBox;
	var getBox_A = "";
	var getBox_P = "";
	var j = 0;
	
	if (inCount >= 0) {
		for (i=0;i<inCount;i++)
		{
			getBox = document.getElementById("checkbox_"+i)
			var tempA = getBox.value;
			if (i < 150) getBox_A = getBox_A + "X" + tempA.substr(5,tempA.length) + ",";
			
			if (getBox.checked == true && j < 150) 
			{
				j++;
				getBox_P = getBox_P + "X" + tempA.substr(5,tempA.length) + ",";
			}
			if (j >= 300)  {
			if (confirm("The number of selected entries is over 150.\n Only the first 150 ones will be used. Are you sure?") == false) return;
			else break; }
		}
		if (getBox_P.length < 1) 
		{
			if (confirm("No entries are selected, All entries (Max number is 150) will be matched into " + inType + " tree. Do you want to continue?") == true) getBox_P = getBox_A;
			else return;
		}
		if (inType == "Species_Toxin") document.location = "../SetAddress?Type=Species&Filter=SpecIDAndToxinID&QS="+getBox_P+"|1.&Page=0&Search=No";
		if (inType == "Species_Channel") document.location = "../SetAddress?Type=Species&Filter=SpecIDAndChannelID&QS="+getBox_P+"|1.&Page=0&Search=No";
		if (inType == "Pathogenesis") document.location = "../SetAddress?Type=Mechanism&Filter=Ontolege_Mechanism_ToxinID&QS="+getBox_P+"|1.3.&Page=0&Search=No";
		if (inType == "Category") document.location = "../SetAddress?Type=Molecule&Filter=Ontolege_Molecule_ToxinID&QS="+getBox_P+"|1.1.&Page=0&Search=No";
		if (inType == "Target") document.location = "../SetAddress?Type=Target&Filter=Ontolege_Target_ToxinID&QS="+getBox_P+"|1.2.&Page=0&Search=No";
		if (inType == "Symptom") document.location = "../SetAddress?Type=Symptom&Filter=Ontolege_Symptom_ToxinID&QS="+getBox_P+"|1.4.&Page=0&Search=No";
		if (inType == "Homology") document.location = "../SetAddress?Type=Homology&Filter=Ontolege_Homology_ChannelID&QS="+getBox_P+"|2.6.&Page=0&Search=No";
		if (inType == "Distribution") document.location = "../SetAddress?Type=Distribution&Filter=Ontolege_Distribution_ChannelID&QS="+getBox_P+"|2.5.&Page=0&Search=No";
		if (inType == "Pathophysiology") document.location = "../SetAddress?Type=Pathophysiology&Filter=Ontolege_Pathophysiology_ChannelID&QS="+getBox_P+"|2.4.&Page=0&Search=No";
		if (inType == "Physiological") document.location = "../SetAddress?Type=Physiological&Filter=Ontolege_Physiological_ChannelID&QS="+getBox_P+"|2.3.&Page=0&Search=No";
	}
	
	if (inCount == -1)  
	{
		if (inType == "Compress=Yes") 
	   {
	      var  temp_location = document.location.search;
	      if (temp_location.indexOf("Compress") != -1)
	      {
	      	  var pos_start=temp_location.indexOf("Compress");
              var pos_end=temp_location.indexOf("&",pos_start);
              if (pos_end == -1)
               	//alert(document.location.pathname + temp_location.substr(0,pos_start) + "Compress=Yes");
               	document.location = document.location.pathname + temp_location.substr(0,pos_start) + "Compress=Yes"
              else 
                //alert(document.location.pathname + temp_location.substr(0,pos_start) + "Compress=Yes" + temp_location(pos_end,temp_location.length));
                document.location = document.location.pathname + temp_location.substr(0,pos_start) + "Compress=Yes" + temp_location(pos_end,temp_location.length)
          }
	      else document.location = document.location + "&Compress=Yes";
	    }
	    
	    if (inType == "Compress=No") 
	   {
	      var  temp_location = document.location.search;
	      if (temp_location.indexOf("Compress") != -1)
	      {
	      	  var pos_start=temp_location.indexOf("Compress");
              var pos_end=temp_location.indexOf("&",pos_start);
              if (pos_end == -1)
               	//alert(document.location.pathname + temp_location.substr(0,pos_start) + "Compress=Yes");
               	document.location = document.location.pathname + temp_location.substr(0,pos_start) + "Compress=No"
              else 
                //alert(document.location.pathname + temp_location.substr(0,pos_start) + "Compress=Yes" + temp_location(pos_end,temp_location.length));
                document.location = document.location.pathname + temp_location.substr(0,pos_start) + "Compress=No" + temp_location(pos_end,temp_location.length)
          }
	      else document.location = document.location + "&Compress=No";
	    } 
	      /* if (temp_location.indexOf("Compress") >=0)  {
	       alert( document.location);
	       		if (temp_location.indexOf("Compress=No") >= 0)
	       		temp_location = temp_location.subString(0,temp_location.indexOf("Compress")) + "Compress=Yes" +  temp_location.subString(temp_location.indexOf("Compress")+11,temp_Location.length);
	       		}
	       else document.location = document.location + "&Compress=Yes";
	    }
	    if (inType == "Compress=No") 
	   {
	       if (temp_location.indexOf("Compress") >=0)  {
	       		if (temp_location.indexOf("Compress=Yes") >= 0)
	       		temp_location = temp_location.subString(0,temp_location.indexOf("Compress")) + "Compress=No" +  temp_location.subString(temp_location.indexOf("Compress")+12,temp_Location.length);
	       		}
	       else document.location = document.location + "&Compress=No";
	    }*/
	    
	}
	
	
	
}

function CheckObjectNum(g_obj)
{
	    if (g_obj.name == "EVALUE")
	    {
	       	var get_Value = g_obj.value;
	        if(!	checknum(get_Value))
	        {
	           g_obj.value=0.05;
	        }
		}
}

function checknum(p)
{
   if (p == "") 
   {alert ("The entry is empty!"); 
  return false; 
} 
var l = p.length; 
var count=0; 
for(var i=0; i<l; i++) 
{ 
var digit = p.charAt(i); 
if(digit == "." ) 
{ 
  ++count; 
  if(count>1) 
  {alert ("The entry should be number!"); 
   return false; 
  } 
  } 
else if(digit < "0" || digit > "9") 
  {alert ("The entry should be number!"); 
   return false; 
  } 
  } 
return true; 
}

function CreateOption(ID,SL)
{
	
	var t = document.getElementById(ID);
	t.options.length = 0;
	if (SL != "-1")
	{
		var p = SL.split("|");
		for (var i=0;i<p.length;i++)
		{
		   var TT = p[i].split("#");
		   t.options[i] = new Option(TT[0],TT[1]);
		}
		t.focus();
	}
}

function ChangeEndable(p)
{
	var t;
	if (p == '1')
	{
		t = document.getElementById('ToxinID');
		t.disabled = false;
		t.focus();
		t = document.getElementById('ChannelID');
		t.disabled = true;
	}
	else 
	{
		t = document.getElementById('ToxinID');
		t.disabled = true;
		t = document.getElementById('ChannelID');
		t.disabled = false;
		t.focus();
	}
}


	