var TimerID; 
var FastTimerID; 
var HighlightStart = "<SPAN class=RealTimePCRHighlight>";
var HighlightEnd = "</SPAN>";
var isIE = document.all?true:false;
var isNS = document.layers?true:false;
//var LocktbSelectionStart = false;
var oCaretPosHold = 0;
var oCaretPosHoldEnd = -1;



//For Select All Checkbox Sequence and Image Selection from TargetInfo
function SelectAllSeqCheckbox(loc, ControlName, IntronCount, TotalExons)
{

   //alert("Hit SelectAllSeqCheckbox:");
   var cbAllExon = loc + "cbAllExon";
   var cbAllIntron = loc + "cbAllIntron";
   
   
  
        for (i=1;i<=(TotalExons);i=i+1) 
        {
            

                var Exon =  ControlName + "_cbExon" + i;
                var ExonImageName = ControlName + "_SequenceImage_Box"+ i;
                $get(Exon).checked = $get(cbAllExon).checked;
                
                if($get(cbAllExon).checked == true)
                {
                    imgOn=eval('pic1on.src');
                    $get(ExonImageName).src = imgOn;
                }
                else
                {
                    imgOn=eval('pic1off.src');
                    $get(ExonImageName).src = imgOn;        
                }
//            }
            //alert("Hit SelectAllSeqCheckbox: " + i);            
         
        }
        for (i=1;i<=(IntronCount);i=i+1) 
        {
            var Intron =  ControlName + "_cbIntron" + i;
            var IntronImageName = ControlName + "_SequenceImage_Line" + i;
            $get(Intron).checked = $get(cbAllIntron).checked;
            
            if($get(cbAllIntron).checked == true)
            {
                imgOn=eval('pic1on.src');
                $get(IntronImageName).src = imgOn;
            }
            else
            {
                imgOn=eval('pic1off.src');
                $get(IntronImageName).src = imgOn;        
            }
        
        }

    

//        for (i=1;i<=(TotalExons);i=i+1) 
//        {
//            var Intron =  ControlName + "_cbIntron" + i;
//            var IntronImageName = ControlName + "_SequenceImage_Line" + i;
//            $get(Intron).checked = $get(cbAllIntron).checked ;
//            imgOn=eval('pic1on.src');
//            $get(IntronImageName).src = imgOn;

//        }

   
   
}

function SelectAllCheckbox(loc, ControlName, CDSAdjustment1, CDSAdjustment2, FivePrimeUTR, FivePrimeAndCDS, CDS, ThreePrimeAndCDS, TotalExons)
{
    //if exon and/or intron is selected and nothing else
    //exon
   var cbAllExon = loc + "cbAllExon";
   var cbAllIntron = loc + "cbAllIntron";
   var cbFivePrimeUTR = loc + "cbFivePrimeUTR";
   var cbCDS = loc + "cbCDS";
   var cbThreePrimeUTR = loc + "cbThreePrimeUTR";
      
    if (($get(cbAllExon).checked == true) && ($get(cbFivePrimeUTR).checked == false) && ($get(cbCDS).checked == false) && ($get(cbThreePrimeUTR).checked == false))
    {
        for (i=1;i<=(TotalExons + CDSAdjustment1 + CDSAdjustment2);i=i+1) 
        {
            var Exon =  ControlName + "_cbExon" + i;
            var ExonImageName = ControlName + "_SequenceImage_Box"+ i;
            $get(Exon).checked = true;
            imgOn=eval('pic1on.src');
            $get(ExonImageName).src = imgOn;
        }
    }
    else if (($get(cbAllExon).checked == false) && ($get(cbFivePrimeUTR).checked == false) && ($get(cbCDS).checked == false) && ($get(cbThreePrimeUTR).checked == false)) 
    {
        for (i=1;i<=(TotalExons + CDSAdjustment1 + CDSAdjustment2);i=i+1) 
        {
            var Exon = ControlName + "_cbExon" + i;
            var ExonImageName = ControlName + "_SequenceImage_Box" + i;
            $get(Exon).checked = false;
            imgOn=eval('pic1off.src');
            $get(ExonImageName).src = imgOn;
        }
    }    
    //intron
   if (($get(cbAllIntron).checked == true) && ($get(cbFivePrimeUTR).checked == false) && ($get(cbCDS).checked == false) && ($get(cbThreePrimeUTR).checked == false))
   {  
        for (i=1;i<TotalExons;i=i+1) 
        {
            var Intron =  ControlName + "_cbIntron" + i;
            var IntronImageName = ControlName + "_SequenceImage_Line" + i;
            $get(Intron).checked = true;
            imgOn=eval('pic1on.src');
            $get(IntronImageName).src = imgOn;
        }
   }
   else if (($get(cbAllIntron).checked == false) && ($get(cbFivePrimeUTR).checked == false) && ($get(cbCDS).checked == false) && ($get(cbThreePrimeUTR).checked == false)) 
   {
          for (i=1;i<TotalExons;i=i+1) 
        {
            var Intron = ControlName + "_cbIntron" + i;
            var IntronImageName = ControlName + "_SequenceImage_Line" + i;
            //var IntronImageName = ControlName + "_SequenceImage_Line" + i;
            $get(Intron).checked = false;
            imgOn=eval('pic1off.src');
            $get(IntronImageName).src = imgOn;

        }
    }
        
    //if 5'UTR is selected
   if (($get(cbFivePrimeUTR).checked == true) || ($get(cbCDS).checked == true) || ($get(cbThreePrimeUTR).checked == true))
   {   
        if (FivePrimeAndCDS > 0)
        {
            if (($get(cbAllExon).checked == false) && ($get(cbAllIntron).checked == false) && ($get(cbFivePrimeUTR).checked == true)) 
            {

                for (i=1;i<FivePrimeAndCDS + CDSAdjustment1;i=i+1) 
                {
                    var Exon = ControlName + "_cbExon" + i;
                    var ExonImageName = ControlName + "_SequenceImage_Box" + i;
                    $get(Exon).checked = true;
                    imgOn=eval('pic1on.src');
                    $get(ExonImageName).src = imgOn;
                 }
                 for (i=1;i<FivePrimeAndCDS;i=i+1) 
                 {
                    var Intron = ControlName + "_cbIntron" + i;
                    var IntronImageName = ControlName + "_SequenceImage_Line" + i;
                    $get(Intron).checked = true;
                    imgOn=eval('pic1on.src');
                    $get(IntronImageName).src = imgOn;
                }
           }

           else 
           {
                if ($get(cbFivePrimeUTR).checked == true)
                {
                    for (i=1;i<FivePrimeAndCDS + CDSAdjustment1;i=i+1) 
                    {
                        var AllExon = ControlName + "_cbAllExon";
                        var Exon = ControlName + "_cbExon" + i;
                        var ExonImageName = ControlName + "_SequenceImage_Box" + i;
                        $get(Exon).checked = $get(AllExon).checked;

                        if ($get(AllExon).checked)
                        {
                            imgOn=eval('pic1on.src');
                        }
                        else 
                        {
                            imgOn=eval('pic1off.src');
                        }

                        $get(ExonImageName).src = imgOn;
                    }
                    for (i=1;i<FivePrimeAndCDS;i=i+1) 
                    {
                        var AllIntron = ControlName + "_cbAllIntron";
                        var Intron = ControlName + "_cbIntron" + i;
                        var IntronImageName =  ControlName + "_SequenceImage_Line" + i;
                        $get(Intron).checked =  $get(AllIntron).checked;

                        if ($get(AllIntron).checked)
                        {
                            imgOn=eval('pic1on.src');
                        }
                        else 
                        {
                            imgOn=eval('pic1off.src');
                        }

                        $get(IntronImageName).src = imgOn;
                    }
                }
                else 
                {
                    for (i=1;i<FivePrimeAndCDS + CDSAdjustment1;i=i+1) 
                    {
                        var Exon = ControlName + "_cbExon" + i;
                        var ExonImageName = ControlName + "_SequenceImage_Box" + i;
                        $get(Exon).checked = false;
                        imgOn=eval('pic1off.src');
                        $get(ExonImageName).src = imgOn;
                    }
                    for (i=1;i<FivePrimeAndCDS;i=i+1) 
                    {
                        var Intron = ControlName + "_cbIntron" + i;
                        var IntronImageName = ControlName + "_SequenceImage_Line" + i;
                        $get(Intron).checked = false;
                        imgOn=eval('pic1off.src');
                        $get(IntronImageName).src = imgOn;
                    }
                }
            }
        }
        
        
       //if CDS is selected

        if (($get(cbAllExon).checked == false) && ($get(cbAllIntron).checked == false) && ($get(cbCDS).checked == true))
        {                       
            for (i=FivePrimeAndCDS + CDSAdjustment1;i<=CDS + CDSAdjustment1 + CDSAdjustment2;i=i+1) 
            {
                if(i>0)
                {
                    var Exon = ControlName + "_cbExon" + i;
                    var ExonImageName = ControlName + "_SequenceImage_Box" + i;
                    $get(Exon).checked = true;
                    imgOn=eval('pic1on.src');
                    $get(ExonImageName).src = imgOn;
                }
            }
            for (i=FivePrimeAndCDS;i<ThreePrimeAndCDS;i=i+1) 
            {
                if(i>0)
                {
                    var Intron = ControlName + "_cbIntron" + i;
                    var IntronImageName = ControlName + "_SequenceImage_Line" + i;
                    $get(Intron).checked = true;
                    imgOn=eval('pic1on.src');
                    $get(IntronImageName).src = imgOn;
                }
            }
        }
        else 
        {
            if ($get(cbCDS).checked == true)
            {


                for (i=FivePrimeAndCDS + CDSAdjustment1;i<=CDS + CDSAdjustment1 + CDSAdjustment2;i=i+1) 
                {
                    if(i>0)
                    {
                        var Exon = ControlName + "_cbExon" + i;
                        var ExonImageName = ControlName + "_SequenceImage_Box" + i; 
                        //alert("Exon: " + Exon + "  cbAllExon: " + cbAllExon);             
                        $get(Exon).checked = $get(cbAllExon).checked;

                        if ($get(cbAllExon).checked)
                        {
                            imgOn=eval('pic1on.src');
                        }
                        else 
                        {
                            imgOn=eval('pic1off.src');
                        }

                        $get(ExonImageName).src = imgOn;
                    }
                    
                }
                for (i=FivePrimeAndCDS;i<ThreePrimeAndCDS;i=i+1) 
                {
                    if(i>0)
                    {
                        var Intron = ControlName + "_cbIntron" + i;
                        var IntronImageName = ControlName + "_SequenceImage_Line" + i;
                        $get(Intron).checked = $get(cbAllIntron).checked;

                        if ($get(cbAllIntron).checked)
                        {
                            imgOn=eval('pic1on.src');
                        }
                        else 
                        {
                            imgOn=eval('pic1off.src');
                        }

                        $get(IntronImageName).src = imgOn;
                    }
                }
            }
            else 
            {
//                if(FivePrimeAndCDS < CDS)
//                {
                    for (i=FivePrimeAndCDS + CDSAdjustment1;i<=CDS + CDSAdjustment1 + CDSAdjustment2;i=i+1) 
                    {
                        if(i>0)
                        {
                        var Exon = ControlName + "_cbExon" + i;
                        var ExonImageName = ControlName + "_SequenceImage_Box" + i;
                        $get(Exon).checked = false;
                        imgOn=eval('pic1off.src');
                        $get(ExonImageName).src = imgOn;
                        }
                        
                    }
                    for (i=FivePrimeAndCDS;i<ThreePrimeAndCDS;i=i+1) 
                    {
                    if(i>0)
                        {
                        var Intron = ControlName + "_cbIntron" + i;
                        var IntronImageName = ControlName + "_SequenceImage_Line" + i;
                        $get(Intron).checked = false;
                        imgOn=eval('pic1off.src');
                        $get(IntronImageName).src = imgOn;
                        }
                    }
                //}
            }
        }
        
        
        
        
        //if 3'UTR is selected
         if (($get(cbAllExon).checked == false) && ($get(cbAllIntron).checked == false) && ($get(cbThreePrimeUTR).checked == true))
         {
            if(CDS < ThreePrimeAndCDS)
            {
                for (i=ThreePrimeAndCDS + CDSAdjustment1 + CDSAdjustment2;i<=TotalExons + CDSAdjustment1 + CDSAdjustment2;i=i+1) 
                {
                    var Exon = ControlName + "_cbExon" + i;
                    var ExonImageName = ControlName + "_SequenceImage_Box" + i;
                    $get(Exon).checked = true;
                    imgOn=eval('pic1on.src');
                    $get(ExonImageName).src = imgOn;
                }
                for (i=ThreePrimeAndCDS;i<TotalExons;i=i+1) 
                {
                    var Intron = ControlName + "_cbIntron" + i;
                    var IntronImageName = ControlName + "_SequenceImage_Line" + i;
                    $get(Intron).checked = true;
                    imgOn=eval('pic1on.src');
                    $get(IntronImageName).src = imgOn;
                }
            }
            

        }
        else 
        {
            if ($get(cbThreePrimeUTR).checked == true)
            {
                if(CDS < ThreePrimeAndCDS)
                {
                    for (i=ThreePrimeAndCDS + CDSAdjustment1 + CDSAdjustment2;i<=TotalExons + CDSAdjustment1 + CDSAdjustment2;i=i+1) 
                    {
                        var Exon = ControlName + "_cbExon" + i;
                        var ExonImageName = ControlName + "_SequenceImage_Box" + i;
                        $get(Exon).checked = $get(cbAllExon).checked;

                        if ($get(cbAllExon).checked)
                        {
                            imgOn=eval('pic1on.src');
                        }
                        else 
                        {
                            imgOn=eval('pic1off.src');
                        }
                        $get(ExonImageName).src = imgOn;
                    }
                }
                for (i=ThreePrimeAndCDS;i<TotalExons;i=i+1) 
                {
                    var Intron = ControlName + "_cbIntron" + i;
                    var IntronImageName = ControlName + "_SequenceImage_Line" + i;
                    $get(Intron).checked = $get(cbAllIntron).checked;

                    if ($get(cbAllIntron).checked)
                    {
                        imgOn=eval('pic1on.src');
                    }
                    else
                    {
                        imgOn=eval('pic1off.src');
                    }
                    $get(IntronImageName).src = imgOn;
                }

            }
            else 
            {
                if(CDS < ThreePrimeAndCDS)
                {
                    for (i=ThreePrimeAndCDS + CDSAdjustment1 + CDSAdjustment2;i<=TotalExons + CDSAdjustment1 + CDSAdjustment2;i=i+1) 
                    {
                        var Exon = ControlName + "_cbExon" + i;
                        var ExonImageName = ControlName + "_SequenceImage_Box" + i;
                        $get(Exon).checked = false;
                        imgOn=eval('pic1off.src');
                        $get(ExonImageName).src = imgOn;
                    }
                    for (i=ThreePrimeAndCDS;i<TotalExons;i=i+1) 
                    {
                        var Intron = ControlName + "_cbIntron" + i;
                        var IntronImageName = ControlName + "_SequenceImage_Line" + i;
                        $get(Intron).checked = false;
                        imgOn=eval('pic1off.src');
                        $get(IntronImageName).src = imgOn;
                    }
                }
            }
        }
    }
}



function StopIncrementSequence(theSequence, count)
{
//var tbSequencePosition =  replace(theSequenceID, "ForwardArrow", "tbSequencePosition");//"SequenceInfo0_tbSequencePosition"; 
//document.frmMain[tbSequencePosition].value = 'off';
clearInterval(TimerID);
TimerID = ''
   
 //HighlightAreas();
}



 
 function IncrementSequence(theSequence, count, ImageLength, SequenceLength)
{
//ForwardArrow
//TargetInfo0_SequenceDisplay
    clearInterval(TimerID);
    TimerID = ''
//    LocktbSelectionStart = false;
    oCaretPosHold = 0;

    var theSequenceID = theSequence.id;
     
    var tbSequencePosition =  replace(theSequenceID, "ForwardArrow", "tbSequencePosition");
    tbSequencePosition =  replace(tbSequencePosition, "SequenceDisplay", "tbSequencePosition");
    
    var tbSequenceDisplay = replace(tbSequencePosition, 'tbSequencePosition', 'SequenceDisplay'); 
    var tbSequence = replace(tbSequencePosition, 'tbSequencePosition', 'tbSequence'); 
    var tbSequenceSelection = replace(tbSequencePosition, 'tbSequencePosition', 'tbSequenceSelection'); 
    $get(tbSequenceSelection).style.display = 'none'; 
    $get(tbSequence).style.display = 'none';     
    $get(tbSequenceDisplay).style.display = 'block'; 

    
    TimerID = setInterval("Increment('" + theSequenceID + "','" + ImageLength + "','" + SequenceLength + "')",100);
    

 }

function Increment(theSequenceID, ImageLength, SequenceLength)
{
    //TargetInfo0_tbSequencePosition TargetInfo0_tbSequence
    //TargetInfo0_tbSequencePosition TargetInfo0_tbSequence
    var tbSequencePosition =  replace(theSequenceID, "ForwardArrow", "tbSequencePosition") //"SequenceInfo0_tbSequencePosition"; 
    tbSequencePosition =  replace(tbSequencePosition, "SequenceDisplay", "tbSequencePosition");
    var tbSequence = replace(theSequenceID, "ForwardArrow", "tbSequence") //'SequenceInfo0_tbSequence';
    tbSequence =  replace(tbSequence, "SequenceDisplay", "tbSequence");
    //document.write(tbSequencePosition + ' ' + tbSequence);
    
    var thePosition = document.frmMain[tbSequencePosition].value;
    var Sequence = document.frmMain[tbSequence].value;
    
    
    if(thePosition  <= Sequence.length  - 50)
    {
      thePosition++;
    document.frmMain[tbSequencePosition].value = thePosition;
    }
   
        
  
    UpdateSequenceSegment(theSequenceID, ImageLength, SequenceLength);

}

function DecrementSequence(theSequence, count, ImageLength, SequenceLength)
{
    clearInterval(TimerID);
    TimerID = ''
//    LocktbSelectionStart = false;
    oCaretPosHold = 0;

    var theSequenceID = theSequence.id;
    var tbSequencePosition =  replace(theSequenceID, "ReverseArrow", "tbSequencePosition") //"SequenceInfo0_tbSequencePosition"; 
    var thePosition = document.frmMain[tbSequencePosition].value;
    var tbSequenceDisplay = replace(tbSequencePosition, 'tbSequencePosition', 'SequenceDisplay'); 
    var tbSequence = replace(tbSequencePosition, 'tbSequencePosition', 'tbSequence'); 
    var tbSequenceSelection = replace(tbSequencePosition, 'tbSequencePosition', 'tbSequenceSelection'); 
    
    $get(tbSequenceSelection).style.display = 'none'; 
    $get(tbSequence).style.display = 'none';     
    $get(tbSequenceDisplay).style.display = 'block'; 
     

    TimerID = setInterval("Decrement('" + theSequenceID + "','" + ImageLength + "','" + SequenceLength + "')",100);
    
 }

function Decrement(theSequenceID, ImageLength, SequenceLength)
{
    var tbSequencePosition =  replace(theSequenceID, "ReverseArrow", "tbSequencePosition") //"SequenceInfo0_tbSequencePosition"; 
    var thePosition = document.frmMain[tbSequencePosition].value;
    
    if (thePosition > 1)     
    {
        thePosition--;
        document.frmMain[tbSequencePosition].value = thePosition;
        
    } 
    
    UpdateSequenceSegment(theSequenceID, ImageLength, SequenceLength);
}



function StopFastIncrementSequence(theSequence, count)
{

    clearInterval(FastTimerID);


}

function FastIncrementSequence(theSequence, count, ImageLength, SequenceLength)
{

    var theSequenceID = theSequence.id;
    var tbSequencePosition =  replace(theSequenceID, "ForwardArrow", "tbSequencePosition");
    var thePosition = document.frmMain[tbSequencePosition].value;
    
    clearInterval(FastTimerID);
    FastTimerID = '';
    FastTimerID = setInterval("FastIncrement('" + theSequenceID + "','" + ImageLength + "','" + SequenceLength + "')",10);
  
 }

function FastIncrement(theSequenceID, ImageLength, SequenceLength)
{
    var tbSequencePosition =  replace(theSequenceID, "ForwardArrow", "tbSequencePosition") //"SequenceInfo0_tbSequencePosition"; 
    var tbSequence = replace(theSequenceID, "ForwardArrow", "tbSequence") //'SequenceInfo0_tbSequence';
    var thePosition = document.frmMain[tbSequencePosition].value;
    var Sequence = document.frmMain[tbSequence].value;
        
    if(thePosition  <= Sequence.length  - 50)
    {
      thePosition++;
    document.frmMain[tbSequencePosition].value = thePosition;
    }
    else
    {
        clearInterval(FastTimerID);
    } 
    UpdateSequenceSegment(theSequenceID, ImageLength, SequenceLength);

}

function FastDecrementSequence(theSequence, count, ImageLength, SequenceLength)
{
    var theSequenceID = theSequence.id;
    var tbSequencePosition =  replace(theSequenceID, "ReverseArrow", "tbSequencePosition") //"SequenceInfo0_tbSequencePosition"; 
    var thePosition = document.frmMain[tbSequencePosition].value;

    clearInterval(FastTimerID);
    FastTimerID = '';
    FastTimerID = setInterval("Decrement('" + theSequenceID + "','" + ImageLength + "','" + SequenceLength + "')",10);
    
 }
 
function FastDecrement(theSequenceID, ImageLength, SequenceLength)
{
    var tbSequencePosition =  replace(theSequenceID, "ReverseArrow", "tbSequencePosition") //"SequenceInfo0_tbSequencePosition"; 
    
    var thePosition = document.frmMain[tbSequencePosition].value;
    
    if (thePosition > 1)     
    {
        thePosition--;
        document.frmMain[tbSequencePosition].value = thePosition;
    } 
    else
    {
        clearInterval(FastTimerID);
    }
    UpdateSequenceSegment(theSequenceID, ImageLength, SequenceLength);
}


function storeCaret(ftext) 
{
	if (ftext.createTextRange ) 
	{
		selectedRange = document.selection.createRange().duplicate();
		selectedInputArea = ftext;
	}
}

function CaretPosition()
{
 var start = null;
 var end = null;
}

function sethasFocus(ftext) 
{
	for (i=0;i<document.frmMain.length;i=i+1) 
		{
			if (document.frmMain.elements[i].type == 'textarea') 
			{
					if (document.frmMain.elements[i].name == ftext.name )
				{
					document.frmMain.elements[i].hasFocus = true;
				}
				else
				{
					document.frmMain.elements[i].hasFocus = false;
				}
			}
		}

}
//store the selected area of the last selected input 
function storeCaretImproved(textE1) 
{

	if (textE1.createTextRange ) 
	{
		selectedRange = document.selection.createRange().duplicate();
		selectedInputArea = textE1;
	}	
}

//put text infto the last selected place
function InsertAtCursor(txtToInsert) {

		var retval;
		//set default textarea, in case no cursor exists
		retval = 'OligoAnalyzer_SequenceSettingsControl_tbSequence';
		
		for (i=0;i<document.frmMain.length;i=i+1) 
			{
			
				if (document.frmMain.elements[i].type == 'textarea') 
				{
					if (document.frmMain.elements[i].hasFocus  )
					{
						retval = document.frmMain.elements[i].id;
					}
				}
			}
		var vtext;
		vtext = eval('document.frmMain.' + retval);
		//alert (txtToInsert.substring(0,2));
		//check for 5 prime
		//insert at front
		if (txtToInsert.substring(0,2) == '/5')
		{
				vtext.value = txtToInsert + vtext.value;
				vtext.focus();
		}
		//check for 3 prime
		//insert at end
		else if (txtToInsert.substring(0,2) == '/3')
		{
			vtext.value = vtext.value + txtToInsert;
			vtext.focus();
		}
		//internal or unknown
		//insert at cursor position or at the end of the sequence
		else
		{
			if (vtext.createTextRange && vtext.caretPos) 
			{
				var caretPos = vtext.caretPos;
				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? txtToInsert + ' ' : txtToInsert;
				vtext.focus();
			}
			else
			{
				vtext.value+=txtToInsert;
				vtext.focus();
			} 
		}	
}

function TargetInputOnload(ControlNM)
{
    var tbSequence = ControlNM + '_tbSequence';
    var tbSequenceSelection = ControlNM + '_tbSequenceSelection';
    $get(tbSequence).style.display = 'none';
    $get(tbSequenceSelection).style.display = 'none';    
    var CommitTable = ControlNM + '_SelectionCommit_CommitTable';
    var tbSelectionEnd = ControlNM + '_SelectionCommit_tbSelectionEnd';
    
    if (!($get(tbSelectionEnd).value > 0)) 
    {
        $get(CommitTable).style.display = 'none'
    }
}


function SelectAllSeqGlobalClick(cbAll, Count)
{
//cbGlobalExons
    var FunctionName = "";
    var FunctionNumber;
    var Counter = 0;
    var cbGlobal = cbAll.id
    cbGlobal = replace(cbGlobal, "cbGlobalExons","cb1Global");
    cbGlobal = replace(cbGlobal, "cbGlobalIntrons","cb1Global");    
    var cbGlobalExons = replace(cbGlobal, "cb1Global","cbGlobalExons");
    var cbGlobalIntrons = replace(cbGlobal, "cb1Global","cbGlobalIntrons");

    for (i=1;i<=Count - 1;i=i+1) 
    {        
        Counter = i;
        var cbAllExon = 'SequenceInfo' + i + '_cbAllExon';
        var cbAllIntron = 'SequenceInfo' + i + '_cbAllIntron';       
        if ($get(cbGlobalExons).checked == true)
        {
            $get(cbAllExon).checked = true;
        }
        else
        {
            $get(cbAllExon).checked = false;
        }
         if ($get(cbGlobalIntrons).checked == true)
        {
            $get(cbAllIntron).checked = true;
        }
        else
        {
            $get(cbAllIntron).checked = false;
        }
        FunctionName = "ExonClickSequenceInfo" + i + "();";         
        CallFunction(FunctionName); 
        i = Counter;
    } 
}

function SelectAllGlobalClick(cbAll, Count)
{
//cbGlobalExons
    var FunctionName = "";
    var FunctionNumber;
    var Counter = 0;
    var cbGlobal = cbAll.id
    cbGlobal = replace(cbGlobal, "cbGlobalExons","cb1Global");
    cbGlobal = replace(cbGlobal, "cbGlobalIntrons","cb1Global");
    cbGlobal = replace(cbGlobal, "cbGlobal5UTR","cb1Global");
    cbGlobal = replace(cbGlobal, "cbGlobalCDS","cb1Global");
    cbGlobal = replace(cbGlobal, "cbGlobal3UTR","cb1Global");

    
    var cbGlobalExons = replace(cbGlobal, "cb1Global","cbGlobalExons");
    var cbGlobalIntrons = replace(cbGlobal, "cb1Global","cbGlobalIntrons");
    var cbGlobal5UTR = replace(cbGlobal, "cb1Global","cbGlobal5UTR");
    var cbGlobalCDS = replace(cbGlobal, "cb1Global","cbGlobalCDS");
    var cbGlobal3UTR = replace(cbGlobal, "cb1Global","cbGlobal3UTR");
    
    
    for (i=0;i<=Count - 1;i=i+1) 
    {
        
        Counter = i;
        var cbAllExon = 'TargetInfo' + i + '_cbAllExon';
        var cbAllIntron = 'TargetInfo' + i + '_cbAllIntron';
        var cbFivePrimeUTR = 'TargetInfo' + i + '_cbFivePrimeUTR';
        var cbCDS = 'TargetInfo' + i + '_cbCDS';
        var cbThreePrimeUTR = 'TargetInfo' + i + '_cbThreePrimeUTR';

        if ($get(cbGlobalExons).checked == true)
        {
            $get(cbAllExon).checked = true;
        }
        else
        {
            $get(cbAllExon).checked = false;
        }
         if ($get(cbGlobalIntrons).checked == true)
        {
            $get(cbAllIntron).checked = true;
        }
        else
        {
            $get(cbAllIntron).checked = false;
        }
        
         if ($get(cbGlobal5UTR).checked == true)
        {
            $get(cbFivePrimeUTR).checked = true;
        }
        else
        {
            $get(cbFivePrimeUTR).checked = false;
        }
         if ($get(cbGlobalCDS).checked == true)
        {
            $get(cbCDS).checked = true;
        }
        else
        {
            $get(cbCDS).checked = false;
        }
         if ($get(cbGlobal3UTR).checked == true)
        {
            $get(cbThreePrimeUTR).checked = true;
        }
        else
        {
            $get(cbThreePrimeUTR).checked = false;
        }
        FunctionName = "ExonClickTargetInfo" + i + "();";         
        CallFunction(FunctionName); 
        i = Counter;
    } 
}

function CallFunction(FunctionName)
{
    eval(FunctionName); 
}

function BaseCounter(theSequence, ObjectID)
{
var tbSequencePosition =  "SequenceInfo0_tbSequencePosition"; 
var tbSequence = 'SequenceInfo0_tbSequence';
var Position = document.frmMain[tbSequencePosition].value;
Position = (Position * 1) - 1;
var textareaName =  ObjectID;
ViewLocations(theSequence);
$get(tbSequence).style.display = 'none';
 var SequenceArea = 'SequenceInfo0_SequenceDisplay';

		
var textareaValue = theSequence.value;

if (theSequence.createTextRange) 
{
    theSequence.caretPos = document.selection.createRange().duplicate(); 
}
var oCaretPos = new CaretPosition();

if(document.selection)
{
    var SequenceLength = $get(SequenceArea).innerHTML.length;
    $get(SequenceArea).focus();
    var oSel = document.selection.createRange().duplicate();
    var selectionLength = oSel.text.length;
    var Selection = oSel.text;
    oSel.pasteHTML("|" + Selection);
    var SequenceString = $get(SequenceArea).innerHTML;

    SequenceString = replace(SequenceString, HighlightStart, "")
    SequenceString = replace(SequenceString, HighlightEnd, "")
    oCaretPos.start = SequenceString.indexOf('|') + 1;
    oCaretPos.end = oCaretPos.start + selectionLength - 1;
    $get(SequenceArea).innerHTML = replace($get(SequenceArea).innerHTML, "|", "");
    oSel.moveStart ('character', oCaretPos.start -1);
    oSel.moveEnd ('character',   oCaretPos.end - SequenceLength);
    oSel.select ();
 }
 // Firefox support
 else if (window.getSelection)
 {
     var s = window.getSelection();
     var AddCaret = '|' + s;
    // This is easier in Firefox

    if(s.anchorOffset <= s.focusOffset) 
    {
     oCaretPos.start  =  s.anchorOffset + 1;
      oCaretPos.end  = s.focusOffset;
    }
    else
    {
     oCaretPos.end  =  s.anchorOffset;
      oCaretPos.start  = s.focusOffset + 1;
    }
 }
 var EmptySelection = 1

 for (i=1;i<5;i=i+1) 
 {

    var textareaEndPosition =  replace(textareaName,":SequenceDisplay","_SequencingLocations" + i + "_EndPosition"); //'SequenceInfo0_SequencingLocations1_EndPosition';	
    var textareaStartPosition =  replace(textareaName,":SequenceDisplay","_SequencingLocations" + i + "_StartPosition"); //'SequenceInfo0_SequencingLocations1_EndPosition';	
    var textareaPrevPosition  
    if (document.frmMain[textareaEndPosition].value.length < 1) 
	{	
		EmptySelection = i;	
        break;
		
	}
	else if (oCaretPos.start >= document.frmMain[textareaStartPosition].value && oCaretPos.start < document.frmMain[textareaEndPosition].value ) 
	{	
		EmptySelection = i;	
        break;
		
	}
	else if (document.frmMain[textareaEndPosition].value < oCaretPos.start && document.frmMain[textareaEndPosition].value > oCaretPos.end) 
	{
	   EmptySelection = i;	
        break;
	}
	else if ((document.frmMain[textareaEndPosition].value == oCaretPos.end) || (document.frmMain[textareaEndPosition].value == oCaretPos.start) || (document.frmMain[textareaStartPosition].value == oCaretPos.end) || (document.frmMain[textareaStartPosition].value == oCaretPos.start) )
	{	
		EmptySelection = i;	
        break;	
	}
	else
	{
	   EmptySelection = 9;
	}
 }

 var textareaStartPosition = replace(textareaName,":SequenceDisplay","_SequencingLocations" + EmptySelection + "_StartPosition"); //'SequenceInfo0_SequencingLocations1_StartPosition';
 var textareaEndPosition =  replace(textareaName,":SequenceDisplay","_SequencingLocations" + EmptySelection + "_EndPosition"); //'SequenceInfo0_SequencingLocations1_EndPosition';	

 if (oCaretPos.start < oCaretPos.end ) //they selected left to right
  {
    document.frmMain[textareaStartPosition].value = oCaretPos.start + Position;  
    document.frmMain[textareaEndPosition].value = oCaretPos.end + Position;
  }
  else if (oCaretPos.start - 1 > oCaretPos.end ) //they selected from right to left
  {
    document.frmMain[textareaStartPosition].value = oCaretPos.end + Position;  
    document.frmMain[textareaEndPosition].value = oCaretPos.start + Position;
  }
  else //only one base is selected
  {
  document.frmMain[textareaStartPosition].value = oCaretPos.start + Position;
  
    document.frmMain[textareaEndPosition].value = oCaretPos.start + Position;
  }    
  UpdateSequenceSegment(theSequence);
  HighlightAreas(theSequence);	
}

function UpdateSequenceSegment(theSequence, ImageLength, SequenceLength)
{
    var tbSequencePosition =  replace(theSequence, "ForwardArrow", "tbSequencePosition");
    tbSequencePosition = replace(tbSequencePosition, "ReverseArrow", "tbSequencePosition");
    tbSequencePosition =  replace(tbSequencePosition, "SequenceDisplay", "tbSequencePosition");    
    var thePosition = document.frmMain[tbSequencePosition].value;
    var tbSequence =  replace(tbSequencePosition, "tbSequencePosition", "tbSequence");
    var SequenceDisplay =  replace(tbSequencePosition, "tbSequencePosition", "SequenceDisplay"); 
    var Sequence = document.frmMain[tbSequence].value;
    var theEndPosition;        
        
    thePosition--;
    theEndPosition = thePosition;
    theEndPosition = theEndPosition * 1;
    theEndPosition += 50;
    
    $get(SequenceDisplay).innerHTML = Sequence.substring(thePosition, theEndPosition);
    var tbSequenceEndPosition =  replace(tbSequencePosition, "tbSequencePosition", "tbSequenceEndPosition");//"SequenceInfo0_tbSequenceEndPosition"; 
    document.frmMain[tbSequenceEndPosition].value = theEndPosition;
    var theImageID =  replace(tbSequence, "_tbSequence", "");
    theImageID =  replace(theImageID, "SequenceInfo", "SequenceInfoIndicator");
    theImageID =  replace(theImageID, "TargetInfo", "TargetInfoIndicator");
    myObj = $get(theImageID);        
     if (isIE) 
     {        
        var tbSequenceSelection = replace(tbSequenceEndPosition, 'tbSequenceEndPosition', 'tbSequenceSelection'); 
        var SelectionStart = 3000;

        if(thePosition < 3500)
        {
            SelectionStart = 3500;
        }
        else
        {
            SelectionStart = thePosition;
        }        
        $get(tbSequenceSelection).value = Sequence.substring(SelectionStart - 3500);

        if (theImageID!=null)  
        {
           myObj.style.position = 'absolute';
           myObj.style.left = 27 + Math.round((ImageLength/SequenceLength) * thePosition);// test; //thePosition;
        
        }       
     }
     else
     {
       // theImageID =  replace(theImageID, "OuterDiv", "Indicator");
        myObj = $get(theImageID);
        myObj.style.position = 'absolute';
        var x = parseInt(myObj.style.left);
        x = x + 10;
        myObj.style.left = 27 + Math.round((ImageLength/SequenceLength) * thePosition);
     }        
}
function ViewLocations(theSequence)
{
    var textareaTest9 =  "SequenceInfo0_SequencingLocations9_Locations"; //'SequenceInfo0_SequencingLocations1_EndPosition';	
    $get(textareaTest9).innerHtml = "Testing";
    var ShowLocation = true;

 for (i=1;i<10;i=i+1) 
    {
        var textareaEndPosition =  'SequenceInfo0_SequencingLocations' + i + '_EndPosition'; //replace(textareaName,":SequenceDisplay","_SequencingLocations" + i + "_EndPosition"); //'SequenceInfo0_SequencingLocations1_EndPosition';	
        var textareaNextEndPosition = 'SequenceInfo0_SequencingLocations' + i + '_EndPosition'; //replace(textareaName,":SequenceDisplay","_SequencingLocations" + i + "_StartPosition"); //'SequenceInfo0_SequencingLocations1_EndPosition';	
        var SequencingLocation =  'SequenceInfo0_SequencingLocations' + i + '_Locations'; //'SequenceInfo0_SequencingLocations1_EndPosition';	
        if (ShowLocation == true)
            {
                $get(SequencingLocation).style.display = 'block';
            }
        else
            {
                $get(SequencingLocation).style.display = 'none';
            }
            
        if (((document.frmMain[textareaEndPosition].length < 1) || (document.frmMain[textareaEndPosition].value < 1))  && ((document.frmMain[textareaNextEndPosition].length < 1) ||(document.frmMain[textareaNextEndPosition].value < 1)) )
            {            
                ShowLocation = false;
            }
        else
            {
                ShowLocation = true;
            }
    }

}
function HighlightAreas(theControl)
{
    var theControlID = theControl.id
    var ParentElement = theControlID.substring(0, theControlID.indexOf('_') + 1);
    var tbSequencePosition = ParentElement + 'tbSequencePosition';
    var SequenceDisplay = ParentElement + 'SequenceDisplay';
    var tbSequence = ParentElement + 'tbSequence';
    var thePosition = $get(tbSequencePosition).value;    
    var Sequence = $get(tbSequence).value;    
    
    theEndPosition = thePosition;
    theEndPosition = theEndPosition * 1;
    theEndPosition += 50;    
    $get(SequenceDisplay).innerHTML = Sequence.substring(thePosition - 1, theEndPosition - 1);
    var theSequence = $get(SequenceDisplay).innerHTML;
    var NewSequence  = Sequence.substring(thePosition - 1, theEndPosition - 1);      
    var theEndPosition;    
    thePosition = (thePosition * 1) - 1

    for (i=1;i<100;i=i+1) 
    {
        var textareaEndPosition =   ParentElement + 'SequencingLocations' + i + '_tbEndPosition';	
        var textareaStartPosition =  ParentElement + 'SequencingLocations' + i + '_tbStartPosition';
        var FirstString = "";
        var HighlightString = "";
        var LastString = "";
        var CountHighlights = 0;
        var CountMidHighlights = 0;
        var FirstStringStart = 0;
        var FirstStringEnd = -1;
        var SelectedStringStart = -1;
        var SelectedStringEnd = -1;
        var LastStringStart = -1;
        var LastStringEnd = -1;            
        
        if ((($get(textareaEndPosition).value >= thePosition) && ($get(textareaEndPosition).value <= thePosition + 50))||(($get(textareaStartPosition).value <= (thePosition + 50)) && ($get(textareaStartPosition).value >= thePosition )) || (($get(textareaStartPosition).value < (thePosition)) && ($get(textareaEndPosition).value > (thePosition + 50) )))
        {
            if ($get(textareaStartPosition).value > thePosition)
                {
                    FirstStringEnd = $get(textareaStartPosition).value;
                    SelectedStringStart = $get(textareaStartPosition).value;
                }
            else
                {
                    FirstStringEnd = 0;
                    SelectedStringStart = thePosition + 1;
                }            
            if ($get(textareaEndPosition).value < (thePosition + 50))
                {
                    SelectedStringEnd = $get(textareaEndPosition).value;
                    LastStringStart = $get(textareaEndPosition).value;
                    LastStringEnd = thePosition + 50;          
                }
            else
                {
                    SelectedStringEnd = thePosition + 50;
                    LastStringStart = -1;
                    LastStringEnd = -1;            
                }            
            if (FirstStringEnd > 0)
                {
                     FirstString = NewSequence.substring(FirstStringStart - thePosition, FirstStringEnd +1 - thePosition);
                     //alert("FirstString: " + FirstString);
                     if ((FirstString.indexOf('|') >= 0 ) || (FirstString.indexOf('~') >= 0 ))
                     {
                       for ( var Count = 0; Count <= FirstString.length; Count++)
                        //for ( var Count = 0; Count <= SelectedStringStart -1 - thePosition; Count++)  
                        {
                            if (Count <= SelectedStringStart -1 - thePosition)
                            {
                                if ((FirstString.charAt(Count) == '|') || (FirstString.charAt(Count) == '~')) 
	                            {
	                                CountHighlights ++;
	                            }
                            }
	                    } 
                    } 
                    FirstString = NewSequence.substring(FirstStringStart - thePosition, FirstStringEnd -1 - thePosition + CountHighlights);
                }
            else
                {
                    FirstString = "";
                    CountHighlights = 0;
                }
            HighlightString = '';
            HighlightString = NewSequence.substring(SelectedStringStart -1 - thePosition + CountHighlights, SelectedStringEnd - thePosition + CountHighlights);
            CountMidHighlights = CountHighlights;

            if (HighlightString.length > 0)
            {
               
                for (var Count = 0; Count < HighlightString.length; Count++) 
                {
                  if ((HighlightString.charAt(Count) == '|') || (HighlightString.charAt(Count) == '~')) 
                    {
                        CountMidHighlights ++;
                    }
                } 
                HighlightString = '';
                HighlightString = NewSequence.substring(SelectedStringStart -1 - thePosition + CountHighlights, SelectedStringEnd - thePosition + CountMidHighlights);
                CountHighlights = CountMidHighlights; 
            }           
            if (LastStringStart > 0)
            {
                LastString = NewSequence.substring(LastStringStart  - thePosition + CountHighlights, LastStringEnd - thePosition + CountHighlights);
                if (LastString.length > 0)
                {
                    for ( var Count = 0; Count < LastString.length; Count++) 
                    {
                        if ((LastString.charAt(Count) == '|') || (LastString.charAt(Count) == '~')) 
                        {
                            CountMidHighlights ++;
                        }
                    }
                    LastString = NewSequence.substring(LastStringStart  - thePosition + CountHighlights, LastStringEnd - thePosition  + CountMidHighlights);
                }             
           }
           else
           {
               LastString = "";    
           }           
           if ((FirstString.length > 0) || (HighlightString.length > 0) || (LastString.length > 0))
           {
               NewSequence = FirstString + '|' + HighlightString + '~' + LastString;
               $get(SequenceDisplay).innerHTML = NewSequence;
           }
        }        
    var LocationsControl =  ParentElement + 'SequencingLocations' + i + '_Locations';	
    var tbStartPosition =  ParentElement + 'SequencingLocations' + i + '_tbStartPosition';
   
    if ($get(tbStartPosition).value=='-1')
    {
        break;
    }

    }
    var ReplaceSequence = ""
    //ReplaceSequence = $get(SequenceDisplay).innerHTML;
    ReplaceSequence = replace($get(SequenceDisplay).innerHTML, '|', HighlightStart);
    ReplaceSequence = replace(ReplaceSequence, '~', HighlightEnd);    
    $get(SequenceDisplay).innerHTML = ReplaceSequence;
}
function Highlight(theSequence)
{
//SequenceInfo0:SequencingLocations7:EndPosition
    var textareaEndPosition = replace(theSequence.name, ":", "_");
    textareaEndPosition = replace(textareaEndPosition, "StartPosition", "EndPosition");
    var textareaStartPosition = replace(textareaEndPosition, "EndPosition", "StartPosition");
    var textAreaToHighlight = "SequenceInfo0_tbSequence";
    var textAreaHighlight = "SequenceInfo0_SequenceDisplay";
    var SequenceSegment = 1    
    var textAreaSequencePosition = "SequenceInfo0_tbSequencePosition";
    if (document.frmMain[textAreaSequencePosition].value != '')
    {
        SequenceSegment = document.frmMain[textAreaSequencePosition].value;
    }    
    var StartPos = SequenceSegment;
    var EndPos = SequenceSegment + 50;
    var OldString = document.frmMain[textAreaToHighlight].value ;
    var NewString = "";
    
    NewString = OldString.substring(StartPos -1,EndPos);
    $get(textAreaHighlight).innerHTML = NewString;
    
    var temp = $get(textAreaHighlight);
    var save_temp = temp.innerHTML;
 
}

function OnLoadHighlight()
{
	for (i=0;i<document.frmMain.length;i=i+1) 
	{
		if (document.frmMain.elements[i].type == 'textarea') 
		{	
			if (document.frmMain.elements[i].name.substring(1,8) == 'Sequence')
			{
				var textareaName = document.frmMain.elements[i];
				Highlight(textareaName);
			} 
		}
	}
}


//function OnLoadBaseSelector()
//{
//	for (i=0;i<document.frmMain.length;i=i+1) 
//	{
//		if (document.frmMain.elements[i].type == 'textarea') 
//		{	
//			if (document.frmMain.elements[i].name.substring(15,23) == 'Sequence')
//			{
//				var textareaName = document.frmMain.elements[i];
//				BaseCounter(textareaName);
//			} 
//		}
//	}
//}



//function OnLoadBaseCounter()
//{
//	for (i=0;i<document.frmMain.length;i=i+1) 
//	{
//		if (document.frmMain.elements[i].type == 'textarea') 
//		{	
//			if (document.frmMain.elements[i].name.substring(1,8) == 'Sequence')
//			{
//				var textareaName = document.frmMain.elements[i];
//				BaseCounter(textareaName);
//			} 
//		}
//	}
//}

//function RemoveNonBase(theString)
//{
//	var returnString = ""
//	for ( var i = 0; i < theString.length; i++) {
//	if (((theString.charAt(i) == "A") || (theString.charAt(i) == "a") || (theString.charAt(i) == "G") 
//	|| (theString.charAt(i) == "g") || (theString.charAt(i) == "C") || (theString.charAt(i) == "c") 
//	|| (theString.charAt(i) == "T") || (theString.charAt(i) == "t") || (theString.charAt(i) == "R") 
//	|| (theString.charAt(i) == "Y") || (theString.charAt(i) == "M") || (theString.charAt(i) == "K") 
//	|| (theString.charAt(i) == "S") || (theString.charAt(i) == "W") || (theString.charAt(i) == "H") 
//	|| (theString.charAt(i) == "B") || (theString.charAt(i) == "V") || (theString.charAt(i) == "D") 
//	|| (theString.charAt(i) == "N"))) {
//	returnString += theString.charAt(i)
//}
//}
//	return returnString
//}

function CountChar(theString,theChar) {
	var returnValue = 0
	theString = theString.toUpperCase()
	for ( var i = 0; i < theString.length; i++) {
	if (theString.charAt(i) == theChar) {
	returnValue ++
	}
}
	return returnValue
}
function replace(originalString,searchText,replaceText)
{ 
	var strLength = originalString.length; 
	var txtLength = searchText.length; 
	
	
	if ((strLength == 0) || (txtLength == 0)) 
	{ 
		return originalString;
	} 
	var i = originalString.indexOf(searchText); 
	if ((!i) && (searchText != originalString.substring(0,txtLength))) 
	{
		return originalString;
	} 
	if (i == -1) 
	{
		return originalString;
	} 
	var newstr = originalString.substring(0,i) + replaceText; 
	if (i+txtLength < strLength) 
	{
		newstr += replace(originalString.substring(i+txtLength,strLength),searchText,replaceText);
	} 
	return newstr;
} 

//function convertDNAToRNA(theSequence)
//{
//	var theField = theSequence;
//	var selectedText = document.selection;
//	var x;
//	if (selectedText.type == 'Text') {
//		var newRange = selectedText.createRange();
//		theField.focus();
//		
//		x = newRange.text
//		
//		if (checkFor_r(x) < 1)
//		{
//			x = replace(x,"t","T");
//			x = replace(x,"a","A");
//			x = replace(x,"c","C");
//			x = replace(x,"g","G");
//			x = replace(x,"u","U");
//		
//		    x = replace(x,"U","rU");
//			x = replace(x,"T","rU");
//			x = replace(x,"A","rA");
//			x = replace(x,"C","rC");
//			x = replace(x,"G","rG");
//		}
//		else
//		{
//			alert('Your selection already contains RNA bases');
//		}

//		document.selection.createRange().text = x
//		
//	} else {
//		alert('select text in the page and then press this button');		
//	}
//}
function textCounter(field, maxlimit) 
	{
		if (field.value.length > maxlimit)
			{
				field.value = field.value.substring(0, maxlimit);
			}
	} 
function HeaderOnMouseOver(theHeader)
{
    var theHeaderID = theHeader.id;
    $get(theHeaderID).className = 'SciToolTitle'
    //$get(theHeaderID).style="cursor: pointer; cursor: hand;"
}

function HeaderOnMouseOut(theHeader)
{
    var theHeaderID = theHeader.id;
    $get(theHeaderID).className = 'SciToolLargeHeader'
  
}

//delete later
//function SequenceResultsSelector(theTargetSet)
//{
//    var theTargetSetName = theTargetSet.id;  
//    var SequencingPrimerName = replace(theTargetSetName, 'SequenceResults', 'DetailResults');
//    var RightGraphicName = theTargetSetName //replace(theTargetSetName, 'TargetSpecific1_set', 'SequenceImage_RightGraphic');
//    RightGraphicName = replace(RightGraphicName, 'SequenceResults', 'SequenceImage');
//    RightGraphicName = replace(RightGraphicName, 'set', 'RightGraphic');
//    
//    var LeftGraphicName = theTargetSetName //replace(theTargetSetName, 'TargetSpecific1_set', 'SequenceImage_LeftGraphic');
//    LeftGraphicName = replace(LeftGraphicName, 'SequenceResults', 'SequenceImage');
//    LeftGraphicName = replace(LeftGraphicName, 'set', 'LeftGraphic');

//    if($get(theTargetSetName).checked == true)
//    {
//        $get(SequencingPrimerName).checked = true;
//        //document.write(RightGraphicName)
//        imgOn=eval("RightGraphicOn.src");
//        $get(RightGraphicName).src = imgOn;
//        imgOn=eval("LeftGraphicOn.src");
//        $get(LeftGraphicName).src = imgOn;
//    }
//    else
//    {
//        $get(SequencingPrimerName).checked = false;
//        imgOn=eval("RightGraphicOff.src");
//        $get(RightGraphicName).src = imgOn;
//        imgOn=eval("LeftGraphicOff.src");
//        $get(LeftGraphicName).src = imgOn;
//    } 
//}
////delete later
//function DetailsResultsSelector(theSequencingSet)
//{
//    var theSequencingSetName = theSequencingSet.id;   
//    var TargetName = replace(theSequencingSetName, 'DetailResults', 'SequenceResults');
//    var RightGraphicName = theSequencingSetName //replace(theSequencingSetName, 'SequencingPrimer1_set', 'SequenceImage_RightGraphic');
//    RightGraphicName = replace(RightGraphicName, 'DetailResults', 'SequenceImage');
//    RightGraphicName = replace(RightGraphicName, 'set', 'RightGraphic');
//    
//    var LeftGraphicName = theSequencingSetName //replace(theSequencingSetName, 'SequencingPrimer1_set', 'SequenceImage_LeftGraphic');
//    LeftGraphicName = replace(LeftGraphicName, 'DetailResults', 'SequenceImage');
//    LeftGraphicName = replace(LeftGraphicName, 'set', 'LeftGraphic');
//          
//    if($get(theSequencingSetName).checked == true)
//    {    
//        $get(TargetName).checked = true;
//        imgOn=eval("RightGraphicOn.src");
//        $get(RightGraphicName).src = imgOn;
//        imgOn=eval("LeftGraphicOn.src");
//        $get(LeftGraphicName).src = imgOn;
//    }
//    else
//    {
//        $get(TargetName).checked = false;
//        imgOn=eval("RightGraphicOff.src");
//        $get(RightGraphicName).src = imgOn;
//        imgOn=eval("LeftGraphicOff.src");
//        $get(LeftGraphicName).src = imgOn;
//    }    
//}
//delete later
//function GraphicOnClick(theGraphic)
//{
//    var theGraphicID = theGraphic.id;
//    var TargetID = theGraphicID //replace(theGraphicID, 'SequenceImage_RightGraphic', 'TargetSpecific1_set');
//    TargetID = replace(TargetID, 'SequenceImage', 'SequenceResults');
//    TargetID = replace(TargetID, 'RightGraphic', 'set');
//    TargetID = replace(TargetID, 'LeftGraphic', 'set');
//    
//    var SequencingPrimerID = theGraphicID //replace(theGraphicID, 'SequenceImage_RightGraphic', 'SequencingPrimer1_set');
//    SequencingPrimerID = replace(SequencingPrimerID, 'SequenceImage', 'DetailResults');
//    SequencingPrimerID = replace(SequencingPrimerID, 'RightGraphic', 'set');
//    SequencingPrimerID = replace(SequencingPrimerID, 'LeftGraphic', 'set');
//    
//    var RightGraphicName = replace(theGraphicID, 'LeftGraphic', 'RightGraphic');
//    var LeftGraphicName = replace(theGraphicID, 'RightGraphic', 'LeftGraphic');
//    
//    if($get(TargetID).checked == true)
//    {
//    
//        $get(TargetID).checked = false;
//        $get(SequencingPrimerID).checked = false;
//        imgOn=eval("RightGraphicOff.src");
//        $get(RightGraphicName).src = imgOn;
//        imgOn=eval("LeftGraphicOff.src");
//        $get(LeftGraphicName).src = imgOn;
//    }
//    else
//    {
//        $get(TargetID).checked = true;
//        $get(SequencingPrimerID).checked = true;
//        imgOn=eval("RightGraphicOn.src");
//        $get(RightGraphicName).src = imgOn;
//        imgOn=eval("LeftGraphicOn.src");
//        $get(LeftGraphicName).src = imgOn;
//    } 
//}			
//For image manipulation
function ExonSelector(theExon)
{
    var theExonName = theExon.name;
    var ExonImageName = replace(theExonName, '$cbExon', '_SequenceImage_Box');

    if($get(theExonName).checked == true)
    {
        imgOn=eval("pic1on.src");
        $get(ExonImageName).src = imgOn;
    }
    else
    {
        imgOff=eval("pic1off.src");
        $get(ExonImageName).src = imgOff;
    }    
}
function IntronSelector(theIntron)
{
    var theIntronName = theIntron.name;
    var IntronImageName = replace(theIntronName, '$cbIntron', '_SequenceImage_Line');
    //TargetInfo0_SequenceImage_Line1 
    if($get(theIntronName).checked == true)
    {
        imgOn=eval("pic1on.src");
        $get(IntronImageName).src = imgOn;
    }
    else
    {
        imgOff=eval("pic1off.src");
        $get(IntronImageName).src = imgOff;
    }  
}
function ImageOnclick(theImage)
{
//TargetInfo0_SequenceImage_Box3
    var theImageName = theImage.id;
    var theCheckbox = "";
    
    //It is an intron
    if (theImageName.indexOf("Line") >= 0)
    {
        theCheckbox = replace(theImageName, '_SequenceImage_Line', '_cbIntron');
    }
    else //It is an exon
    {
        theCheckbox = replace(theImageName, '_SequenceImage_Box', '_cbExon');
    }
    
    theImageName = replace(theImageName, ':', '_');
    
    if($get(theCheckbox).checked == true)
    {
        $get(theCheckbox).checked = false;
        imgOn=eval("pic1off.src");
        $get(theImageName).src = imgOn;
    }
    else
    {
        $get(theCheckbox).checked = true;
        imgOff=eval("pic1on.src");
        $get(theImageName).src = imgOff;
    }   
}

//For Input
function InputOnload()
{
    var AccessionUpload = "AccessionFileUp";
    var SequenceFileUp = "SequenceFileUp";
    var btnViewAccessionList = "btnViewAccessionList";
    var btnViewSequenceList = "btnViewSequenceList";
    
    $get(AccessionUpload).style.display = 'none'; 
    $get(SequenceFileUp).style.display = 'none';
    $get(btnViewAccessionList).style.display = 'none';
    $get(btnViewSequenceList).style.display = 'none';    
}

function UploadAccessionFile()
{
    var AccessionUpload = "AccessionFileUp";    
    var AccessionHeader = "AccessionHeader";
    var tbAccessionIDs = "tbAccessionIDs";
    var btnUploadAccessionList = "btnUploadAccessionList";
    var SequenceHeader = "SequenceHeader";
    var tdOr = "tdOr";
    var tbSequences = "tbSequences";
    var btnUploadSequenceList = "btnUploadSequenceList";
    var btnViewAccessionList = "btnViewAccessionList";
    var btnClearEntry = "btnClearEntry";
    
    $get(AccessionUpload).style.display = 'block';
    $get(tbAccessionIDs).style.display = 'none';
    $get(btnUploadAccessionList).style.display = 'none';
    $get(SequenceHeader).style.display = 'none';
    $get(tdOr).style.display = 'none';
    $get(tbSequences).style.display = 'none';
    $get(btnUploadSequenceList).style.display = 'none';
    $get(btnViewAccessionList).style.display = 'block';
    $get(btnClearEntry).style.display = 'none';  
    $get(AccessionHeader).innerHTML = 'Enter the path for the text file of accession numbers';
 }
 
 function ViewAccessionList()
 {
    var AccessionUpload = "AccessionFileUp";    
    var AccessionHeader = "AccessionHeader";
    var tbAccessionIDs = "tbAccessionIDs";
    var btnUploadAccessionList = "btnUploadAccessionList";
    var SequenceHeader = "SequenceHeader";
    var tdOr = "tdOr";    
    var tbSequences = "tbSequences";
    var btnUploadSequenceList = "btnUploadSequenceList";
    var btnViewAccessionList = "btnViewAccessionList";
    var btnClearEntry = "btnClearEntry";    
    
    $get(AccessionUpload).style.display = 'none';
    $get(tbAccessionIDs).style.display = 'block';
    $get(btnUploadAccessionList).style.display = 'block';
    $get(SequenceHeader).style.display = 'block';
    $get(tdOr).style.display = 'block';
    $get(tbSequences).style.display = 'block';
    $get(btnUploadSequenceList).style.display = 'block';
    $get(btnViewAccessionList).style.display = 'none';
    $get(btnClearEntry).style.display = 'block';    
    $get(AccessionHeader).innerHTML = 'Enter gene sequence accession numbers of interest (comma separated)';

 }

function UploadSequenceFile()
{
    var SequenceFileUp = "SequenceFileUp";
    var AccessionHeader = "AccessionHeader";
    var tbAccessionIDs = "tbAccessionIDs";
    var btnUploadAccessionList = "btnUploadAccessionList";
    var SequenceHeader = "SequenceHeader";
     var tdOr = "tdOr";
    var tbSequences = "tbSequences";
    var btnUploadSequenceList = "btnUploadSequenceList";
    var btnViewSequenceList = "btnViewSequenceList";
    var btnClearEntry = "btnClearEntry";
    
    $get(tbAccessionIDs).style.display = 'none';
    $get(btnUploadAccessionList).style.display = 'none';
    $get(SequenceHeader).style.display = 'block';
    $get(tdOr).style.display = 'none';
    $get(tbSequences).style.display = 'none';
    $get(btnUploadSequenceList).style.display = 'none';
    $get(btnViewSequenceList).style.display = 'block';
    $get(AccessionHeader).style.display = 'none';
    $get(btnClearEntry).style.display = 'none';    
    $get(SequenceHeader).innerHTML = 'Enter the path for the text file of FASTA formatted sequences';       
    $get(SequenceFileUp).style.display = 'block'; 
}

document.onmousemove = mouseMove;
document.onmouseup   = mouseUp;

var dragObject  = null;
var mouseOffset = null;
var ObjFlank = null;
var ObjImageLength = null;
var ObjSequenceLength = null;

//function mouseMove(ev){
//	ev  = ev || window.event;
//	var mousePos = mouseCoords(ev);
//}

function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}



function makeClickable(object)
{
	object.onmousedown = function()
	{
		dragObject = this;
	}
}

function mouseUp(ev)
{
    if (isNS)
    {
        aMouseUp(dragObject, ObjFlank, ObjImageLength, ObjSequenceLength)
    }
    else if (isIE)
    {
        dragObject = null;
    }
    else
    {
        aMouseUp(dragObject, ObjFlank, ObjImageLength, ObjSequenceLength)
    }
    
	
}

function getMouseOffset(target, ev)
{
	ev = ev || window.event;

	var docPos    = getPosition(target);
	var mousePos  = mouseCoords(ev);
	return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}

function getPosition(e){
	var left = 0;
	var top  = 0;

	while (e.offsetParent)
	{
		left += e.offsetLeft - 37;
		top  += e.offsetTop;
		e     = e.offsetParent;
	}
	left += e.offsetLeft;
	top  += e.offsetTop;

	return {x:left, y:top};
}


function aMouseUp(item, Flank, ImageLength, SequenceLength)
{
    var tbSequencePosition = item.id;    
    tbSequencePosition = replace(tbSequencePosition, "Indicator", "");
    tbSequencePosition = tbSequencePosition + "_tbSequencePosition";   
    var tbSequenceDisplay = replace(tbSequencePosition, "tbSequenceDisplay", "tbSequencePosition");
    var thePosition = document.frmMain[tbSequencePosition].value;
    var ImagePosition = replace(item.style.left, "px", "");
    ImagePosition = parseInt(ImagePosition) - 27;	
	
	if(ImagePosition <= 0)
    {
        thePosition = 1;
    }
    else
    {
        thePosition = Math.round((ImagePosition * SequenceLength) / ImageLength);
    }
    
  
    if (thePosition > SequenceLength - 50)
    {
        thePosition = SequenceLength - 50 + 1
    }
 
    theEndPosition = thePosition;
    theEndPosition = theEndPosition * 1;
    theEndPosition += 50;
    theEndPosition --;
        
    var tbSequenceEndPosition =  replace(tbSequencePosition, "tbSequencePosition", "tbSequenceEndPosition");//"SequenceInfo0_tbSequenceEndPosition"; 
   
    document.frmMain[tbSequencePosition].value = thePosition;
    document.frmMain[tbSequenceEndPosition].value = theEndPosition;
 
    UpdateSequenceSegment(tbSequencePosition, ImageLength, SequenceLength)
  
	dragObject = null;
	
	HighlightAreas($get(tbSequenceDisplay));
}


function mouseMove(ev)
{
        
    
	ev = ev || window.event;
	var mousePos = mouseCoords(ev);

	if(dragObject)
	{
	
		dragObject.style.position = 'absolute';
		//dragObject.style.top      = mousePos.y - mouseOffset.y;
		dragObject.style.left     = ((mousePos.x * 1) - (mouseOffset.x * 1)) + "px";
	
		//alert( "mousePos.x: " + mousePos.x + "mouseOffset.x: " + mouseOffset.x)

        if ((mousePos.x - mouseOffset.x < 27))
        {
            dragObject.style.left  = 27 + "px";
        }
        else if ((mousePos.x - mouseOffset.x > 667) && isIE)
        {
            dragObject.style.left  = 667 + "px";
        }
        else if ((mousePos.x - mouseOffset.x > 607) && !(isIE))
        {
            dragObject.style.left  = 607 + "px";
        }
        else if (mousePos.x - mouseOffset.x > 667)
        {
            dragObject.style.left  = 667 + "px";
        }
        else
        {
            dragObject.style.left = ((mousePos.x * 1) - (mouseOffset.x * 1)) + "px";
        }


        var tbSequencePosition = dragObject.id;
        tbSequencePosition = replace(tbSequencePosition, "Indicator", "");
        tbSequencePosition = tbSequencePosition + "_tbSequencePosition";
        
        var thePosition = document.frmMain[tbSequencePosition].value;
        var ImagePosition = replace(dragObject.style.left, "px", "");
        
      

        ImagePosition = parseInt(ImagePosition) - 27;
        

        
        //alert( "ImagePosition: " + ImagePosition + " ObjSequenceLength: " + ObjSequenceLength + " ObjImageLength: " + ObjImageLength)

	    if(ImagePosition <= 0)
        {
            thePosition = 1;
        }
        else
        {
            thePosition = Math.round((ImagePosition * ObjSequenceLength) / ObjImageLength);
        }
        
      
        if (thePosition > ObjSequenceLength - 50)
        {
            thePosition = ObjSequenceLength - 50 + 1
        }
  
  
        theEndPosition = thePosition;
        theEndPosition = theEndPosition * 1;
        theEndPosition += 50;
        theEndPosition --;
           
        var tbSequenceEndPosition =  replace(tbSequencePosition, "tbSequencePosition", "tbSequenceEndPosition");//"SequenceInfo0_tbSequenceEndPosition"; 
       
        document.frmMain[tbSequencePosition].value = thePosition;
        document.frmMain[tbSequenceEndPosition].value = theEndPosition;

		//dragObject.title = thePosition;
		dragObject.title.visibility="show" ;
		
		UpdateSequenceSegment(tbSequencePosition, ObjImageLength, ObjSequenceLength);
		
		return false;
	}
}

function makeDraggable(item, Flank, ImageLength, SequenceLength)
{

    ObjFlank = Flank;
    ObjImageLength = ImageLength;
    ObjSequenceLength = SequenceLength;

	if(!item) return;
	item.onmousedown = function(ev)
	{
		dragObject  = this;
		mouseOffset = getMouseOffset(this, ev);
		return false;
	}
	
}

//Selection box

function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}




function SequenceSelectionOnMouseOut(theSequence)
{
    
    if (isIE)
    {
        //var tbSequence = theSequence.id; 
        var tbSequenceSelection = theSequence.id; 
    
        var tbSequenceDisplay = replace(tbSequenceSelection, 'tbSequenceSelection', 'SequenceDisplay');
        
        var oSel = document.selection.createRange().duplicate();
        var selectionLength = oSel.text.length;
        
        if (selectionLength < 1)
        {
            $get(tbSequenceSelection).style.display = 'none';
            $get(tbSequenceDisplay).style.display = 'block';              
            HighlightAreas($get(tbSequenceDisplay));
        }
    } 
    else if(window.getSelection)
    {
         var s = window.getSelection();
         
        
  
        if(!((s.anchorOffset > s.focusOffset) || (s.anchorOffset < s.focusOffset))) 
        {
            HighlightAreas(theSequence);
        }
    }
    
}



function SequenceSelectionOnMouseMove(theSequence)
{
    
 
    var tbSequenceDisplay = theSequence.id;
    var tbSequence = replace(tbSequenceDisplay, 'SequenceDisplay', 'tbSequence'); 
    var tbSequenceSelection = replace(tbSequenceDisplay, 'SequenceDisplay', 'tbSequenceSelection'); 
    

    var tbSelectionStart = replace(tbSequenceDisplay, 'SequenceDisplay', 'SelectionCommit_tbSelectionStart'); 
    var tbSelectionEnd = replace(tbSequenceDisplay, 'SequenceDisplay', 'SelectionCommit_tbSelectionEnd'); 
    var tbSequencePosition =  replace(tbSequenceDisplay, 'SequenceDisplay', 'tbSequencePosition'); 
    var Position = $get(tbSequencePosition).value;
    var SequenceLength = $get(tbSequence).innerHTML.length;
  
    
    Position = (Position * 1) - 1

    if (isIE)
     {
        $get(tbSequenceSelection).style.display = 'block';   
   
        $get(tbSequenceDisplay).style.display = 'none'; 
          
        if(Position < 3500)
        {
            $get(tbSequenceSelection).scrollLeft  = 1 + (Position * 7);    
        }
        else
        {
            $get(tbSequenceSelection).scrollLeft  = 1 + (3500  * 7);    
        }
           
     }
    // Firefox support
    else if (window.getSelection)//if($get(tbSequenceDisplay).innerHTML.selectionStart || $get(SequenceArea).innerHTML.selectionStart == '0')
    {
        var oCaretPos = new CaretPosition();
    
        var s = window.getSelection();
        //var AddCaret = '|' + s;
  
        if(s.anchorOffset <= s.focusOffset) 
        {
            oCaretPos.start  =  s.anchorOffset + 1;
            oCaretPos.end  = s.focusOffset;
        }
        else if (s.anchorOffset > s.focusOffset) 
        {
            
            oCaretPos.end  =  s.anchorOffset;
            oCaretPos.start  = s.focusOffset + 1;
        }      
        
        
        
        
        
        if(oCaretPos.end + Position > Position + 50 - 2)
        {
            if (TimerID == '')
            {
                if(oCaretPosHold <= 0)
                {
                    oCaretPosHold = oCaretPos.start  + Position;                  
                }
                clearInterval(TimerID);
                TimerID = setInterval("Increment('" + tbSequenceDisplay + "','540','" + SequenceLength + "')",10);
            
            
            }            
        }
        ////This is to decrement when selecting backwards....Not working properly.
//        else if((oCaretPos.start + Position < Position + 3) && (oCaretPos.start < oCaretPos.end))
//        {
//            if (TimerID == '')
//            {
//                if(oCaretPosHoldEnd <= 0)
//                {
//                    //oCaretPosHold = oCaretPos.start  + Position;  
//                    oCaretPosHoldEnd = oCaretPos.start  + Position;                
//                }
//                
//                clearInterval(TimerID);
//                TimerID = '';
//                //TimerID = setInterval("Decrement('" + tbSequenceDisplay + "','540','" + SequenceLength + "')",10);
//                TimerID = setInterval("Decrement('" + tbSequencePosition + "','540','" + SequenceLength + "')",100);
//    
//            }
//        }  
//        else if (oCaretPosHoldEnd > 1)
//        {
//            s.focusOffset = s.focusOffset + 10;
//            if(oCaretPos.start + Position > Position + 3)   
//            {
//                clearInterval(TimerID);
//                TimerID = '';
//                
//            }         
//        }
        
      
        else
        {
            clearInterval(TimerID);
            TimerID = '';
        }
        var StartPosition = 0
        if(oCaretPosHold > 0)
        {
            StartPosition = oCaretPosHold
        }
        else
        {
            StartPosition = oCaretPos.start + Position
        }
        if (StartPosition < oCaretPos.end + Position ) //they selected left to right
        {
            $get(tbSelectionStart).value = StartPosition;
            $get(tbSelectionEnd).value = oCaretPos.end + Position;
        }
        else if (StartPosition - 1 > oCaretPos.end + Position ) //they selected from right to left
        {
            $get(tbSelectionStart).value = oCaretPos.end + Position;
            $get(tbSelectionEnd).value = StartPosition;
        }
        else //only one base is selected
        {
            $get(tbSelectionStart).value = StartPosition;
            $get(tbSelectionEnd).value = StartPosition;
        } 
    }  
}


function SequenceSelection(theSequence)
{

    var tbSequenceSelection = replace(theSequence.id, 'SequenceDisplay', 'tbSequenceSelection');    
    var SequenceDisplay = replace(theSequence.id, 'tbSequenceSelection', 'SequenceDisplay'); 
    var tbSequence = replace(SequenceDisplay, 'SequenceDisplay', 'tbSequence');
    var CommitTable = replace(tbSequence, '_tbSequence', '_SelectionCommit_CommitTable'); 
    var tbSelectionStart = replace(tbSequence, 'tbSequence', 'SelectionCommit_tbSelectionStart'); 
    tbSelectionStart = replace(tbSelectionStart, 'SequenceDisplay', 'SelectionCommit_tbSelectionStart');     
    var tbSelectionEnd = replace(tbSelectionStart, 'SelectionCommit_tbSelectionStart', 'SelectionCommit_tbSelectionEnd'); 
    var tbSequencePosition =  replace(tbSelectionStart, 'SelectionCommit_tbSelectionStart', 'tbSequencePosition'); 
    var Position = $get(tbSequencePosition).value;
    Position = (Position * 1) - 1
    
    var lblSelectSeq =   replace(tbSequence, 'tbSequence', 'lblSelectSeq'); 
    $get(lblSelectSeq).style.display = 'none';   
    
    
    if (theSequence.createTextRange) 
    {
        theSequence.caretPos = document.selection.createRange().duplicate();   
    }
     
    var oCaretPos = new CaretPosition();
    
//ie suppport
    if(document.selection)
    {        
        var SequenceLength = $get(tbSequence).innerHTML.length;
        var oSel = document.selection.createRange().duplicate();
        var selectionLength = oSel.text.length;
        var Selection = oSel.text;
                
        if (Selection.length <= 1)
        {
              if(Position < 3500)
                {
                    $get(tbSequenceSelection).scrollLeft  = 1 + (Position * 7);    
                }
                else
                {
                    $get(tbSequenceSelection).scrollLeft  = 1 + (3500  * 7);    
                }
        }
        
        oSel.moveStart ('character', -$get(tbSequenceSelection).value.length);

        var SequenceString = $get(tbSequenceSelection).innerHTML;

 

        var cursorPoint = oSel.text.length - selectionLength; 


        oCaretPos.start = cursorPoint + 1;
        oCaretPos.end = cursorPoint + selectionLength;
        
        if (Position >= 3500)
        {
            oCaretPos.start = oCaretPos.start + (Position - 3500);
            oCaretPos.end = oCaretPos.end + (Position - 3500);
        }
            
        Position = 0;
      
        
    }
    // Firefox support
    else if (window.getSelection)
    {
        var s = window.getSelection();
        //var AddCaret = '|' + s;

    // This is a whole lot easier in Firefox

        if(s.anchorOffset <= s.focusOffset) 
        {
            oCaretPos.start  =  s.anchorOffset + 1;
            oCaretPos.end  = s.focusOffset;
        }
        else if (s.anchorOffset > s.focusOffset) 
        {
            
            oCaretPos.end  =  s.anchorOffset;
            oCaretPos.start  = s.focusOffset + 1;
        }

    }
    
    var StartPosition = 0
        if(oCaretPosHold > 0)
        {
            StartPosition = oCaretPosHold
        }
        else
        {
            StartPosition = oCaretPos.start + Position
        }
    
   
    if (oCaretPos.end > 0) 
    {
        $get(CommitTable).style.display = 'block'
    }
    

 
 if (StartPosition < oCaretPos.end ) //they selected left to right
  {
    $get(tbSelectionStart).value = StartPosition;
    $get(tbSelectionEnd).value = oCaretPos.end;
  }
  else if (StartPosition - 1 > oCaretPos.end ) //they selected from right to left
  {
    $get(tbSelectionStart).value = oCaretPos.end;
    $get(tbSelectionEnd).value = StartPosition;
  }
  else //only one base is selected
  {
    $get(tbSelectionStart).value = StartPosition;
    $get(tbSelectionEnd).value = StartPosition;
  } 



	
}


//for committing selected area of the sequence


function CommitSelection(btCommitSelection, SequencingLocationsCount)
{
    var btCommitSelectionID = btCommitSelection.id;    
    var tbSelectionStart = replace(btCommitSelectionID, "btCommitSelection", "tbSelectionStart");
    var tbSelectionEnd = replace(btCommitSelectionID, "btCommitSelection", "tbSelectionEnd");
    var SequenceDisplay = replace(btCommitSelectionID, "SelectionCommit_btCommitSelection", "SequenceDisplay");
    var tbSequenceSelection = replace(btCommitSelectionID, 'SelectionCommit_btCommitSelection', 'tbSequenceSelection');    
    var FinalLock = replace(btCommitSelectionID, "_SelectionCommit_btCommitSelection", "_SequencingLocationsFinal_Locations");
    

           
    for (i=1;i<100;i=i+1) 
    {
        var btLock = replace(btCommitSelectionID, "SelectionCommit", "SequencingLocations" + i);
        btLock = replace(btLock, "btCommitSelection", "btLock");
        var LocationsControl = replace(btLock, "btLock", "Locations");        
        var btUnlock = replace(btLock, "btLock", "btUnlock");
        
        if(!($get(LocationsControl).style.display == 'none') && ($get(btUnlock).style.display == 'none') )
        {
            if(i < SequencingLocationsCount - 1)
            {  
                var tbStartPosition = replace(btLock, "btLock", "tbStartPosition");
                var tbEndPosition = replace(btLock, "btLock", "tbEndPosition");
                var btRemove = replace(btLock, "btLock", "btRemove");
                
                $get(tbStartPosition).value = $get(tbSelectionStart).value;
                $get(tbEndPosition).value = $get(tbSelectionEnd).value;
                
                $get(btLock).style.display = 'none';
                $get(btUnlock).style.display = 'block';    
                $get(btRemove).style.display = 'block';          
                DisableTextbox(tbStartPosition, true);
                DisableTextbox(tbEndPosition, true);
                
                var NextLocation = i + 1      
                var SequencingLocations = replace(btCommitSelectionID, "SelectionCommit", "SequencingLocations" + NextLocation);
                var NextUnlock =  replace(SequencingLocations, "btCommitSelection", "btUnlock");
                SequencingLocations = replace(SequencingLocations, "btCommitSelection", "Locations");
                $get(SequencingLocations).style.display = 'block';            
                var NexttbStartPosition =  replace(NextUnlock, "btUnlock", "tbStartPosition");
                var NexttbEndPosition =  replace(NextUnlock, "btUnlock", "tbEndPosition");
                
                if (!($get(NexttbStartPosition).disabled))
                {
                    $get(NextUnlock).style.display = 'none';
                    if ($get(NexttbStartPosition).value == '-1')
                    {
                        $get(NexttbStartPosition).value = '';
                        $get(NexttbEndPosition).value = '';
                    }
                    if ($get(NexttbEndPosition).value == '')
                    {
                        var NextLock =  replace(NextUnlock, "btUnlock", "btLock");
                        $get(NextLock).style.display = 'none';
                    }     
                }
            }
            else
            {
                var tbStartPosition = replace(btLock, "btLock", "tbStartPosition");
                var tbEndPosition = replace(btLock, "btLock", "tbEndPosition");
                var btFinalCommitSelection = replace(btCommitSelectionID, "_btCommitSelection", "_btFinalCommitSelection");
               
                
                $get(tbStartPosition).value = $get(tbSelectionStart).value;
                $get(tbEndPosition).value = $get(tbSelectionEnd).value;
                
                $get(btLock).style.display = 'none';
                $get(btUnlock).style.display = 'block'; 
                 
                DisableTextbox(tbStartPosition, true);
                DisableTextbox(tbEndPosition, true);
                
                $get(FinalLock).style.display = 'block'; 
                $get(btFinalCommitSelection).style.display = 'block';   
                btCommitSelection.style.display = 'none'; 
                
                //btLock = replace(btLock, '_SequencingLocations','_SequencingLocationsFinal');
                btLock = replace(btCommitSelectionID, "_SelectionCommit_btCommitSelection", "_SequencingLocationsFinal_btLock");
                $get(btLock).style.display = 'none'; 
    
                break;
            }
            
           
            break;
        }  
     
     }  
    
    $get(SequenceDisplay).style.display = 'block';
    $get(tbSequenceSelection).style.display = 'none';
    
    oCaretPosHold = -1;
    
}

function DisableTextbox(aTextboxID, DisableState)
{
    $get(aTextboxID).disabled = DisableState;
    if(DisableState)
    {
        if ($get(aTextboxID))
        {
         $get(aTextboxID).className = 'ScitoolFlatTextBoxDisabled';
        }
    }
    else
    {
      if ($get(aTextboxID))
        {
         $get(aTextboxID).className = 'SciToolText';
        }
    }
    
    
}


function UnlockSelection(btUnlock)
{
    var btUnlockID = btUnlock.id;
    var btLock = replace(btUnlockID, "btUnlock", "btLock");
    var tbStartPosition = replace(btLock, "btLock", "tbStartPosition");
    var tbEndPosition = replace(btLock, "btLock", "tbEndPosition");
    var btRemove = replace(btLock, "btLock", "btRemove");
    
    DisableTextbox(tbStartPosition, false);
    DisableTextbox(tbEndPosition, false);
    
    $get(btLock).style.display = 'block';
    $get(btUnlockID).style.display = 'none';   
    $get(btRemove).style.display = 'none';  
}



function LockSelection(btLock, SequencingLocationsCount)
{
    //TargetInfo0_SequencingLocations2_btLock
    var btLockID = btLock.id;
    btLockID = replace(btLockID, 'tbEndPosition', 'btLock')
    var btUnlock = replace(btLockID, "btLock", "btUnlock");
    var tbStartPosition = replace(btUnlock, "btUnlock", "tbStartPosition");
    var tbEndPosition = replace(btUnlock, "btUnlock", "tbEndPosition");
    var btRemove = replace(btUnlock, "btUnlock", "btRemove");
    
    $get(btRemove).style.display = 'block';  
     
    if(!($get(tbStartPosition).value == '') && !($get(tbEndPosition).value == ''))
    {
        if (($get(tbStartPosition).value * 1) > ($get(tbEndPosition).value * 1))
        {
            var HoldValue = $get(tbStartPosition).value;
            $get(tbStartPosition).value = $get(tbEndPosition).value;
            $get(tbEndPosition).value = HoldValue;
        } 
        
        DisableTextbox(tbStartPosition, true);
        DisableTextbox(tbEndPosition, true);
        
        $get(btLockID).style.display = 'none';
        $get(btUnlock).style.display = 'block';  

        
        var ParentID = btLockID.substring(0, btLockID.indexOf('_') + 1);
        var NextLocation = replace(btLockID, ParentID, '');
        var ChildID = NextLocation.substring(0, NextLocation.indexOf('_'));
        var LocationNumber = replace(ChildID, 'SequencingLocations', '');
        LocationNumber = (LocationNumber * 1) + 1
        NextLocation = ParentID + 'SequencingLocations' + LocationNumber + '_Locations';
        
        if(LocationNumber < SequencingLocationsCount -1)
        {          
            var NexttbStartPosition = replace(NextLocation, '_Locations', '_tbStartPosition');
            var NexttbEndPosition = replace(NextLocation, '_Locations', '_tbEndPosition');
            
            $get(NextLocation).style.display = 'block'; 
            
            if  ($get(NexttbStartPosition).value == '-1')
            {
                $get(NexttbStartPosition).value = ''
                $get(NexttbEndPosition).value = ''
            }
            
            if($get(NexttbStartPosition).value == '' || $get(NexttbEndPosition).value == '')
            {
                var NextbtLock = replace(NextLocation, '_Locations', '_btLock');
                var NextbtUnlock = replace(NextLocation, '_Locations', '_btUnlock');
                
                $get(NextbtLock).style.display = 'none'; 
                $get(NextbtUnlock).style.display = 'none'; 
             }   
        }
        else
        {
        //TargetInfo0_SequencingLocationsFinal_Locations
        //TargetInfo1_SelectionCommit_btFinalCommitSelection
            var SequencingLocationsFinal = ParentID + 'SequencingLocationsFinal_Locations';
            $get(SequencingLocationsFinal).style.display = 'block'; 
            var btFinalCommitSelection = ParentID + 'SelectionCommit_btFinalCommitSelection';
            var btCommitSelection = ParentID + 'SelectionCommit_btCommitSelection';        
            var btLock = replace(SequencingLocationsFinal, '_Locations','_btLock');
            
            $get(btCommitSelection).style.display = 'none'; 
            $get(btFinalCommitSelection).style.display = 'block';         
            $get(btLock).style.display = 'none'; 
            $get(NextLocation).style.display = 'none'; 
        
        }
    }
}

function FinalLocationCommit(theObject, LocationsCount)
{
     var theObjectID = theObject.id
     var objParentID = theObjectID.substring(0, theObjectID.indexOf('_') + 1);
     
     for (k=1;k<=LocationsCount;k=k+1) 
        {
            var LocationsID = objParentID + 'SequencingLocations' + k + '_Locations';             
            var tbStartPosition = objParentID + 'SequencingLocations' + k + '_tbStartPosition';
            var tbEndPosition = objParentID + 'SequencingLocations' + k + '_tbEndPosition'; 
            
            
            if($get(LocationsID).style.display == 'none')
            {
            
                var tbSelectionStart = objParentID + 'SelectionCommit_tbSelectionStart';
                var tbSelectionEnd = objParentID + 'SelectionCommit_tbSelectionEnd';   
            
                $get(tbStartPosition).value = $get(tbSelectionStart).value;
                $get(tbEndPosition).value = $get(tbSelectionEnd).value;

                break;
            }   
        } 
}
function FinalLocationLock(theObject, LocationsCount)
{
     var theObjectID = theObject.id
     var objParentID = theObjectID.substring(0, theObjectID.indexOf('_') + 1);
    
     for (k=1;k<=LocationsCount;k=k+1) 
        {
            var LocationsID = objParentID + 'SequencingLocations' + k + '_Locations';             
            var tbStartPosition = objParentID + 'SequencingLocations' + k + '_tbStartPosition';
            var tbEndPosition = objParentID + 'SequencingLocations' + k + '_tbEndPosition'; 
                        
            if($get(LocationsID).style.display == 'none')
            {
            
                var tbFinalStartPosition = objParentID + 'SequencingLocationsFinal_tbStartPosition';
                var tbFinalEndPosition = objParentID + 'SequencingLocationsFinal_tbEndPosition';                
                $get(tbStartPosition).value = $get(tbFinalStartPosition).value;
                $get(tbEndPosition).value = $get(tbFinalEndPosition).value;
                
                break;
            }
        } 
}

function EnableAllTextboxes(theObject, TargetInfoCount, SeqInfoCount, LocationsCount, ParentName)
{
    var ParentID;
    if(TargetInfoCount > 0)
    {   
        for (i=0;i<TargetInfoCount;i=i+1) 
        {             
            ParentID = ParentName + i;   
            var tbSequencePosition =  ParentID + '_tbSequencePosition';
            var tbSequenceEndPosition =  ParentID + '_tbSequenceEndPosition';
            $get(tbSequencePosition).disabled = false;
            $get(tbSequenceEndPosition).disabled = false; 
            
            
            $get(tbSequencePosition).className = 'ScitoolFlatTextBoxDisabled';
            $get(tbSequenceEndPosition).className = 'ScitoolFlatTextBoxDisabled';               
            
            for (k=1;k<LocationsCount;k=k+1) 
            {
                var tbStartPosition = ParentID + '_SequencingLocations' + k + '_tbStartPosition';
                var tbEndPosition = ParentID + '_SequencingLocations' + k + '_tbEndPosition';            
                $get(tbStartPosition).disabled = false;
                $get(tbEndPosition).disabled = false; 
            }         
         }    
    }
    if(SeqInfoCount > 0)
    {
        for (i=1;i<=SeqInfoCount;i=i+1) 
        {             
            ParentID = replace(ParentName, 'TargetInfo', 'SequenceInfo') + i;   
            var tbSequencePosition =  ParentID + '_tbSequencePosition';
            var tbSequenceEndPosition =  ParentID + '_tbSequenceEndPosition';
            
            $get(tbSequencePosition).disabled = false;
            $get(tbSequenceEndPosition).disabled = false;
            $get(tbSequencePosition).className = 'ScitoolFlatTextBoxDisabled';
            $get(tbSequenceEndPosition).className = 'ScitoolFlatTextBoxDisabled';               
            
            for (k=1;k<LocationsCount;k=k+1) 
            {
                var tbStartPosition = ParentID + '_SequencingLocations' + k + '_tbStartPosition';
                var tbEndPosition = ParentID + '_SequencingLocations' + k + '_tbEndPosition';            
                $get(tbStartPosition).disabled = false;
                $get(tbEndPosition).disabled = false; 
            }      
        }
     }        
}

function DisableTextboxes(theObject, TargetInfoCount, SeqInfoCount, LocationsCount, ParentName)
{    
    if(TargetInfoCount > 0)
    {
        for (i=0;i<TargetInfoCount;i=i+1) 
        {
            var ParentID;        
            ParentID = ParentName + i;   
            var tbSequencePosition =  ParentID + '_tbSequencePosition';
            var tbSequenceEndPosition =  ParentID + '_tbSequenceEndPosition';
           
           //alert("tbSequencePosition: " & tbSequencePosition);
           
            $get(tbSequencePosition).disabled = true;
            $get(tbSequenceEndPosition).disabled = true; 
            
            for (k=1;k<LocationsCount;k=k+1) 
            {
                var tbStartPosition = ParentID + '_SequencingLocations' + k + '_tbStartPosition';
                var tbEndPosition = ParentID + '_SequencingLocations' + k + '_tbEndPosition';  
                var btUnlock =  ParentID + '_SequencingLocations' + k + '_btUnlock'; 
                
                if($get(btUnlock).style.display == 'block')
                {
                    DisableTextbox(tbStartPosition, true);
                    DisableTextbox(tbEndPosition, true);
                } 
            }         
         }   
     }
    if(SeqInfoCount > 0)
    {
         for (i=1;i<=SeqInfoCount;i=i+1) 
        {
            var ParentID;        
            ParentID = replace(ParentName, 'TargetInfo', 'SequenceInfo') + i;    
            var tbSequencePosition =  ParentID + '_tbSequencePosition';
            var tbSequenceEndPosition =  ParentID + '_tbSequenceEndPosition';
           
          //alert("tbSequencePosition: " + tbSequencePosition);
       
            $get(tbSequencePosition).disabled = true;
            $get(tbSequenceEndPosition).disabled = true; 
            
            for (k=1;k<LocationsCount;k=k+1) 
            {
                var tbStartPosition = ParentID + '_SequencingLocations' + k + '_tbStartPosition';
                var tbEndPosition = ParentID + '_SequencingLocations' + k + '_tbEndPosition';  
                var btUnlock =  ParentID + '_SequencingLocations' + k + '_btUnlock'; 
                
                if($get(btUnlock).style.display == 'block')
                {
                    DisableTextbox(tbStartPosition, true);
                    DisableTextbox(tbEndPosition, true);
                } 
            }         
         }   
    }
}


function EnableAllSeqTextboxes(theObject, TargetInfoCount, LocationsCount, ParentName)
{
    var ParentID;   
    //alert("test ParentName: " + ParentName + " Count: "  + TargetInfoCount);
    
    
    for (i=0;i<TargetInfoCount -1;i=i+1) 
    {             
        ParentID = ParentName + (i + 1);   
        var tbSequencePosition =  ParentID + '_tbSequencePosition';
//        if (i = 3)
//        {
//alert("test 3: " + tbSequencePosition);
//        }
        
        var tbSequenceEndPosition =  ParentID + '_tbSequenceEndPosition';
        $get(tbSequencePosition).disabled = false;
        $get(tbSequenceEndPosition).disabled = false; 
        
        for (k=1;k<LocationsCount;k=k+1) 
        {
            var tbStartPosition = ParentID + '_SequencingLocations' + k + '_tbStartPosition';
            var tbEndPosition = ParentID + '_SequencingLocations' + k + '_tbEndPosition';            
            $get(tbStartPosition).disabled = false;
            $get(tbEndPosition).disabled = false; 
        }         
     } 
}

function DisableSeqTextboxes(theObject, TargetInfoCount, LocationsCount, ParentName)
{
//SequenceInfo1:tbSequencePosition
    for (i=0;i<TargetInfoCount - 1;i=i+1) 
    {
        var ParentID;        
        ParentID = ParentName + (i + 1);   
        var tbSequencePosition = ParentID + '_tbSequencePosition';
        var tbSequenceEndPosition = ParentID + '_tbSequenceEndPosition';
        //document.write(tbSequenceEndPosition);
       
        $get(tbSequencePosition).disabled = true;
        $get(tbSequenceEndPosition).disabled = true; 
        
        for (k=1;k<LocationsCount;k=k+1) 
        {
            var tbStartPosition = ParentID + '_SequencingLocations' + k + '_tbStartPosition';
            var tbEndPosition = ParentID + '_SequencingLocations' + k + '_tbEndPosition';  
            var btUnlock =  ParentID + '_SequencingLocations' + k + '_btUnlock'; 
            
            if($get(btUnlock).style.display == 'block')
            {
                DisableTextbox(tbStartPosition, true);
                DisableTextbox(tbEndPosition, true);
            } 
        }         
     }   
}



function HideLocationsOnload(Locations, StartLocations, LocationsCount)
{
    var ShowDisplay = true;
    var btUnlock = Locations + '_SequencingLocations1_btUnlock';
    var btRemove = Locations + '_SequencingLocations1_btRemove';
    var FinalLock = Locations + '_SequencingLocationsFinal' + '_Locations';
    var btFinalCommitSelection = Locations + '_SelectionCommit_btFinalCommitSelection';
    var btCommitSelection = Locations + '_SelectionCommit_btCommitSelection';
    
    
    var tbStartPosition = Locations + '_SequencingLocations1' + '_tbStartPosition';
    var tbEndPosition = Locations + '_SequencingLocations1' + '_tbEndPosition';
    
    if ($get(tbStartPosition).value == '-1')
    {
        $get(tbStartPosition).value = '';
        $get(tbEndPosition).value = '';
    }
    $get(btUnlock).style.display = 'none'; 
    $get(btRemove).style.display = 'none'; 
    $get(FinalLock).style.display = 'none';     
    $get(btCommitSelection).style.display = 'block'; 
    

    
    for (i=1;i<=LocationsCount + 1;i=i+1) 
    {
        var LocationsID;        
        LocationsID = Locations + '_SequencingLocations' + i + '_Locations';
        var tbEndPosition = Locations + '_SequencingLocations' + i + '_tbEndPosition';
        //$get(btFinalCommitSelection).style.display = 'none'
        
        if(($get(tbEndPosition).value == '-1')  || ($get(tbEndPosition).value.length < 1)) //&& i >= StartLocations )
        {
          
           btRemove =  Locations + '_SequencingLocations' + i + '_btRemove';
           $get(btRemove).style.display = 'none'; 
                
            if(ShowDisplay == false)
            {
                $get(LocationsID).style.display = 'none';   
            }
            else
            {
                var NexttbStartPosition = Locations + '_SequencingLocations' + i + '_tbStartPosition';
                $get(NexttbStartPosition).value = '';
                $get(tbEndPosition).value = '';
                
                if (i == (LocationsCount - 5))
                {
                    $get(FinalLock).style.display = 'block';                   
                    $get(LocationsID).style.display = 'none';                       
                    $get(btCommitSelection).style.display = 'none';
                    $get(btFinalCommitSelection).style.display = 'block';   
                }   
                else
                {
                    $get(btCommitSelection).style.display = 'block';
                    $get(btFinalCommitSelection).style.display = 'none';
                }
                
                
                btUnlock =  Locations + '_SequencingLocations' + i + '_btUnlock'; 
                $get(btUnlock).style.display = 'none';
                  
                if ($get(tbEndPosition).value == '')
                {
                    var btLock =  Locations + '_SequencingLocations' + i + '_btLock'; 
                    $get(btLock).style.display = 'none'; 
                }   
            }
            ShowDisplay = false;
        } 
      
        else //if ($get(tbEndPosition).value.length >= 1)
        {
            var tbStartPosition = Locations + '_SequencingLocations' + i + '_tbStartPosition';
            var tbEndPosition = Locations + '_SequencingLocations' + i + '_tbEndPosition';
            btUnlock =  Locations + '_SequencingLocations' + i + '_btUnlock'; 
            btLock =  Locations + '_SequencingLocations' + i + '_btLock'; 
            
            $get(btLock).style.display = 'none'; 
            $get(btUnlock).style.display = 'block'; 
            DisableTextbox(tbStartPosition, true);
            DisableTextbox(tbEndPosition, true);  
            
            if ($get(tbStartPosition).value == '-1')
            {
                $get(tbStartPosition).value = '';
                $get(tbEndPosition).value = '';
            }
             
        }  
            
     }       
}

function ResetSequenceDisplay(theControl)
{
    var theControlID = theControl.id
    var ParentElement = theControlID.substring(0, theControlID.indexOf('_') + 1);
    var tbSequencePosition = ParentElement + 'tbSequencePosition';
    var SequenceDisplay = ParentElement + 'SequenceDisplay';
    var tbSequence = ParentElement + 'tbSequence';
    var DisplaySequence = $get(SequenceDisplay).innerHTML;
    
    if (DisplaySequence.indexOf('>') > 0)
    {
        var thePosition = $get(tbSequencePosition).value;    
        var Sequence = $get(tbSequence).value;
                
        theEndPosition = thePosition;
        theEndPosition = theEndPosition * 1;
        theEndPosition += 50;
        
        $get(SequenceDisplay).innerHTML = Sequence.substring(thePosition - 1, theEndPosition - 1);
    }

}

function TextboxIsNumeric(theTextbox)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   var sText =  theTextbox.value;
   var TextVal = "";  

   
   for (i = 0; i < sText.length; i++) 
      { 
      Char = sText.charAt(i); 
      if (!(ValidChars.indexOf(Char) == -1))
         {
            TextVal = TextVal + ValidChars.indexOf(Char);
         }       
      }
   theTextbox.value = TextVal;
}

function ShowLock(theTextbox)
{
    //TargetInfo0_SequencingLocations1_tbEndPosition
    //TargetInfo0_SequencingLocations1_Locations
    //TargetInfo0_SequencingLocationsFinal_btLock
    
    var ParentElement = theTextbox.id.substring(0, theTextbox.id.indexOf('_'));
    var Location = replace(theTextbox.id, ParentElement,'');
    Location = replace(Location, '_SequencingLocations','');
    Location = replace(Location, '_tbEndPosition','');
    Location = replace(Location, '_tbStartPosition','');    
    
    var tbStartPosition = replace(theTextbox.id, '_tbEndPosition','_tbStartPosition');
    var tbEndPosition = replace(theTextbox.id, '_tbStartPosition','_tbEndPosition');    
    var btLock = replace(tbEndPosition, '_tbEndPosition','_btLock');   
    
    if(!($get(tbStartPosition).value == '') && !($get(tbEndPosition).value == ''))
    {       
        $get(btLock).style.display = "block"; 
        
        if(!(Location.indexOf('Final') >= 0))
        {
            Location = (Location * 1) + 1
            var NextLocation = ParentElement + '_SequencingLocations' + Location + '_Locations'
            var NextLock = ParentElement + '_SequencingLocations' + Location + '_btLock'
            var NextUnlock = ParentElement + '_SequencingLocations' + Location + '_btUnlock'
            var NexttbStartPosition = ParentElement + '_SequencingLocations' + Location + '_tbStartPosition'
            var NexttbEndPosition = ParentElement + '_SequencingLocations' + Location + '_tbEndPosition'
            
            $get(NextLocation).style.display = "block"; 
            
            if  ($get(NexttbStartPosition).value == '-1')
            {
                $get(NexttbStartPosition).value = ''
                $get(NexttbEndPosition).value = ''
            }
            if($get(NexttbStartPosition).value == '')
            {
                $get(NextLock).style.display = "none"; 
                $get(NextUnlock).style.display = "none"; 
            }
        }       
             
    }
    else
    {
        $get(btLock).style.display = "none";
    }    
    
}

function RemoveLocation(RemoveButton)
{
    var ParentElement = RemoveButton.id.substring(0, RemoveButton.id.indexOf('_'));
    var Location = replace(RemoveButton.id, '_btRemove','_Locations');    
    var tbStartPosition = replace(RemoveButton.id, '_btRemove','_tbStartPosition');
    var tbEndPosition = replace(RemoveButton.id, '_btRemove','_tbEndPosition'); 
       
    $get(tbStartPosition).value = '';
    $get(tbEndPosition).value = ''; 
    DisableTextbox(tbStartPosition, false);
    DisableTextbox(tbEndPosition, false);   
    $get(Location).style.display = "none";     
}


function RemoveSequenceBoxOnLoad()
{
    
    $get('tbSequences').style.display = "none";     
    $get('SequenceHeader').style.display = "none"; 
    $get('tdOr').style.display = "none";   
    $get('btnUploadSequenceList').style.display = "none";  
}


function PrimerSelection(thePrimer)
{
    var thePrimerID = thePrimer.id;
    
    if (thePrimerID.indexOf('FORWARD') > 0 )
    {
        var ReversePrimerID = replace(thePrimerID, 'FORWARD', 'REVERSE')
        if($get(thePrimerID).selectedIndex == 0)
        {
            $get(ReversePrimerID).selectedIndex = 1;
        }
        else
        {
          $get(ReversePrimerID).selectedIndex = 0;
        }
    }
    else
    {
        var ForwardPrimerID = replace(thePrimerID, 'REVERSE', 'FORWARD')
        if($get(thePrimerID).selectedIndex == 0)
        {
            $get(ForwardPrimerID).selectedIndex = 1;
        }
        else
        {
          $get(ForwardPrimerID).selectedIndex = 0;
        }
    }
}

function MidChange(aObject, TargetID)
{
    var ParentElement = aObject.id.substring(0, aObject.id.indexOf('_'));    
    var tbTarget = $get(ParentElement + "_tb" + TargetID);
    var lblTarget = $get(ParentElement + "_lbl" + TargetID);
    if (aObject.value == 'Custom')
    {
        tbTarget.style.display = 'block';
        lblTarget.style.display = 'none';
        lblTarget.innerHTML = '';        
    }
    else
    {
        tbTarget.style.display = 'none';
        lblTarget.style.display = 'block';
        lblTarget.innerHTML = aObject.value;    
    }
}


function MIDSelectCount(aObject, CustID)
{
    //TargetInfo0_ddMIDCount_5644
    //TargetInfo0_MIDs_0_ddMid
    var ParentElement = aObject.id.substring(0, aObject.id.indexOf('_'));     
    DisableMIDs(ParentElement + "_");   
     var tdExpandMID = $get(ParentElement + "_tdExpandMID");
    var trMIDs = $get(ParentElement + "_trMIDs");

    if (aObject.value > 0)
    {
        var MIDCount = aObject.value * 1;
        for(var x=0;x<MIDCount;x++)
        {
            var aDropDown = $get(ParentElement + "_tdMIDs_" + x );
            aDropDown.style.display = 'block';
        }
        tdExpandMID.style.display = 'block';       
       ExpandMids($get(ParentElement + "_tdExpandMID"), 'imgECMIDs_' + CustID, 'trMIDs');        
    }
    else
    {
         trMIDs.style.display = 'none';
         tdExpandMID.style.display = 'none';
    }
}

function MIDGlobalCount(aObject)
{
    DisableMIDs("");   
    var trMIDs = $get("trMIDs");
    if (aObject.value > 0)
    {
        var MIDCount = aObject.value * 1;
        for(var x=0;x<MIDCount;x++)
        {
            var aDropDown = $get("tdMIDs_" + x );
            aDropDown.style.display = 'block';
        }      
    }
}

function DisableMIDs(ParentElement)
{
     for(var x=0;x<12;x++)
        {
            var aDropDown = $get(ParentElement + "tdMIDs_" + x );
            aDropDown.style.display = 'none';
        }
}

function ViewMids(aObject)
{
    //TargetInfo0_ddMIDCount_5644
    //TargetInfo0_MIDs_0_ddMid
    //tdExpandMID
    var ParentElement = aObject.id.substring(0, aObject.id.indexOf('_'));     
    DisableMIDs(ParentElement + "_");   
    var phMIDs = $get(ParentElement + "_phMIDs");
    if (aObject.value > 1)
    {
        phMIDs.style.display = 'block';
        var MIDCount = aObject.value * 1;
        for(var x=0;x<MIDCount;x++)
        {
            var aDropDown = $get(ParentElement + "_tdMIDs_" + x );
            aDropDown.style.display = 'block';
        }
    }
    else
    {
        phMIDs.style.display = 'none';         
    }
}

function ExpandMids(theObject, ImgName, TargetID)
{    
    var EListID = theObject.id.replace("tdExpandMID", TargetID)
    $get(EListID).style.display = 'block';  
    
    theObject.onclick = function(){CollapseMids(theObject, ImgName, TargetID);}
    ChangeImg('Collapse', ImgName)
}

function CollapseMids(theObject, ImgName, TargetID)
{
    var EListID = theObject.id.replace("tdExpandMID", TargetID);
    $get(EListID).style.display = 'none'; 
    theObject.onclick = function(){ExpandMids(theObject, ImgName, TargetID);}
    ChangeImg('Expand', ImgName)
}

function Collapse(theObject, ImgName, TargetID)
{
    $get(TargetID).style.display = 'none'; 
    theObject.onclick = function(){Expand(theObject, ImgName, TargetID);}
    ChangeImg('Expand', ImgName)
}

function Expand(theObject, ImgName, TargetID)
{    
    $get(TargetID).style.display = 'block';  
    theObject.onclick = function(){Collapse(theObject, ImgName, TargetID);}    
    ChangeImg('Collapse', ImgName)
}

function ChangeImg(ImgState, ImgName)
{
    var ImgObj = $get(ImgName);
    ImgObj.src = "/Scitools/Images/general/" + ImgState + "_Off.gif";     
    ImgObj.onmouseover = function(){this.src="/Scitools/Images/general/" + ImgState + "_On.gif";}
    ImgObj.onmouseout = function(){this.src="/Scitools/Images/general/" + ImgState + "_Off.gif";}
    ImgObj.alt = "Click to " + ImgState;
    ImgObj.style.verticalalign = 'bottom';
}

function GlobalChange(theObj, ParentID, Count, StartPos)
{
     for(var x=StartPos;x<Count;x++)
        {
            var ddMIDCount = $get(ParentID + x + "_ddMIDCount")
            ddMIDCount.selectedIndex = theObj.selectedIndex;
            if (ddMIDCount.onchange) {ddMIDCount.onchange()};
        }
    
}

//TargetInfo0_MIDs_0_ddMid
function GlobalMidSelection(theObj, MidCount, TargetCount, SequenceCount)
{
    //TargetInfo0_MIDs_1_ddMid
    //TargetInfo0_MIDs_1_ddMid
    
    var MidLoc =  replace(theObj.id, "MIDs_", "");
    MidLoc =  replace(MidLoc, "_ddMid", "");

    for(x=0;x<TargetCount;x++)
    {
            $get("TargetInfo" + x + "_MIDs_" + MidLoc + "_ddMid").selectedIndex = theObj.selectedIndex
    }
    
     for(x=1;x<SequenceCount;x++)
    {
            $get("SequenceInfo" + x + "_MIDs_" + MidLoc + "_ddMid").selectedIndex = theObj.selectedIndex
    }
}

function GetCheckBoxID(ImageName) {
    var theCheckbox = "";
    //It is an intron
    if (ImageName.indexOf("Line") >= 0) {
        theCheckbox = replace(ImageName, '_SequenceImage_Line', '_cbIntron');
    }
    else //It is an exon
    {
        theCheckbox = replace(ImageName, '_SequenceImage_Box', '_cbExon');
    }
    return theCheckbox
}

function HighlightImage(theImage) {

    var theImageName = theImage.id;
    var theImageAltName = replace(theImage.id, "_Mature", "_Sequence")
    var theCheckbox = "";

    theCheckbox = GetCheckBoxID(theImageAltName);
    theImageName = replace(theImageName, ':', '_');
    if ($get(theCheckbox).checked != true) {
        imgOff = eval("pic1on.src");
        $get(theImageName).src = imgOff;
        $get(theImageAltName).src = imgOff;
    }
}

function HighlightImageEnd(theImage) {
    var theImageName = theImage.id;
    var theImageAltName = replace(theImage.id, "_Mature", "_Sequence")
    var theCheckbox = "";

    theCheckbox = GetCheckBoxID(theImageAltName);
    theImageName = replace(theImageName, ':', '_');

    if ($get(theCheckbox).checked != true) {
        imgOff = eval("pic1off.src");
        $get(theImageName).src = imgOff;
        $get(theImageAltName).src = imgOff;
    }
}

//  End -->
//document.write(theImage.name)
//var ParentID = theTextbox.substring(0, theTextbox.indexOf('_') + 1);