<?php
    include("connection.php");
    include("frames_header.php");
?>

<script>
var selected_part=new Array();

function popup_anatomy_selector() {
  dev = "";
  names = "";
  for(a=0; a<window.document.formulaire.elements['devstage[]'].options.length; ++a){
  	if(window.document.formulaire.elements['devstage[]'].options[a].selected==true){
	  	dev  += window.document.formulaire.elements['devstage[]'].options[a].value+':'; // tab[a-1]+':';
		names+= window.document.formulaire.elements['devstage[]'].options[a].text+':';
	}
  }
  if(dev.length<=1){
  	alert("Select an Ascidian species and specific developmental stages first");
	return;
  }
  
  species=window.document.formulaire.species.options[window.document.formulaire.species.selectedIndex].text;

  if ((window.document.anat_keywords == null) || (window.document.anat_keywords.closed == true)) {
    window.document.anat_keywords = window.open("anatomyTreeLine.php?namedev="+names+"&iddev="+dev+"&species="+species,"anat_keywords","menubar=yes,toolbar=no,scrollbars=yes,resizable=yes,height=500,width=600");
  } else {
    window.document.anat_keywords.focus();
  }
}


function update(){
	window.document.formulaire.elements['region[]'].options.length = selected_part.length;
	//ids="";
	for(a=0; a<selected_part.length; ++a){
		window.document.formulaire.elements['region[]'].options[a].text  = selected_part[a][0];//+" ("+selected_part[a][1]+")";
		window.document.formulaire.elements['region[]'].options[a].value = selected_part[a][1];
		//ids+=selected_part[a][1]+":";
	}
	//window.document.formulaire.idanat.value=ids;
}

function addtoarray(name,value){
	if(selected_part.length>=1){
	  alert("Select only one cell");
	  return;
	}
  
	selected_part[selected_part.length]=[name,value];
	update();
}

function retrenchtoarray(num){
	selected_part.splice(num,1);
	update();
}

function remove_structures(){
	
	for(a=0; a<selected_part.length; ++a){
		if(window.document.formulaire.elements['region[]'].options[a].selected == true){
			selected_part.splice(a,1);
			window.document.formulaire.elements['region[]'].options[a]=null;
			a-=1;
		}
	}
	update();
	//reloadit();
}

function reset_structures(){
	window.document.formulaire.elements['region[]'].options.length=0;
	selected_part=new Array();
	//window.document.formulaire.idanat.value='';
	//reloadit();
	update();
}


function selectanatomy(){
  for(a=0; a<window.document.formulaire.elements['region[]'].options.length; ++a){
 		window.document.formulaire.elements['region[]'].options[a].selected=true;
  }
}
</script>


<h2><strong><em>Delete lineage.</em></strong> </h2>
<center>

<form name="formulaire" action="lineage-delete2.php" method="post" target="_blank">

            
	        <table width="99%" border="0" cellspacing="0" cellpadding="0" background="pictures/barre.jpg">
              <tr bgcolor="#990000"> 
                <td>&nbsp;</td>
				<td>&nbsp;</td>
                <td align="right" background="pictures/barre-red.jpg"><em><strong>delete lineage</strong></em></td>
              </tr>
              <tr> 
                <td>&nbsp;</td>
                <td>&nbsp;</td>
				<td>&nbsp;</td>
              </tr>
			  
              <tr> 
                
				<td align="center" valign="top">
				    <strong>Species</strong>
				    <!--
					<select name="species" size="1" onChange="javascript: self.location.href = 'fate-search.php?species=' + this.options[ this.selectedIndex ].value;">
					<select name="species" size="1" onChange="javascript: self.formulaire.action='lineage-search.php'; self.formulaire.target='_self'; submit();">
					-->
					<br>
					<select name="species" size="1" onChange="javascript: document.forms[0].action='lineage-delete.php'; document.forms[0].target='_self'; submit();">
						<option></option>
						<?php
							$species="";
							if (isset($_POST["species"])) $species=$_POST["species"];
							
							$requete = "select \"NAME\" from \"SPECIES\" ";
							$stmt0 = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
							while ($row0=pg_fetch_array($stmt0))
							{
								$name = $row0["NAME"];
								print "<option value=\"$name\"";
								if($species==$name)
									print " selected";
								print ">$name</option>";
							}
						?>
				    </select>&nbsp;
				</td>
                <td align="center" valign="top">
		            <strong>Developmental stage</strong><br>
                    <select name="devstage[]" size="10" style="width:200">
                    
                    <?php
						
						if(strlen($species)>0){
							 $query="SELECT \"NAME\", \"DEV_STAGE_ID\" FROM \"DEV_STAGE\" WHERE \"SPECIES\"='$species' ORDER BY \"DEV_PERCENT\"";
							 $stmt = pg_query($c,$query) or die("<strong>Error</strong> ".pg_last_error($c));
	
							 while($row=pg_fetch_array($stmt)){
								print "<option value=\"".$row["DEV_STAGE_ID"]."\">";
								print $row["NAME"]."</option>\n";
								
							 }
						}
					 ?>
                  </select>
				</td>
				<td align="center" valign="top">
				    
				    <table width="100%" border="0" cellspacing="0" cellpadding="0">
					  <tr>
						<td align="center">
						    <strong>Anatomical part</strong><br>
						    <select name="region[]" size="10" style="width:200">
						        
                            </select>
							<br>
							<img src="pictures/button-add.jpg" onClick="self.popup_anatomy_selector();" border="0">
							<img src="pictures/button-reset.jpg" onClick="self.reset_structures();" border="0">

					    </td>
						<td>
						    <input name="ance" type="checkbox" value="y" checked>Ancestors
							<br>
						    <input name="desc" type="checkbox" value="y">Descendants
							<br><br>
						    <input name="and" type="radio" value="y">and
							&nbsp;&nbsp;
							<input name="and" type="radio" value="n" checked>or
						</td>
					  </tr>
					</table>

				</td>
              </tr>
			  
              <tr> 
                <td><hr size="1" color="#505F70"></td>
                <td><hr size="1" color="#505F70"></td>
				<td><hr size="1" color="#505F70"></td>
              </tr>
			  
              <tr>
                <td>&nbsp;</td>
				<td>&nbsp;</td>
                <td align="right">
				    <input name="submit" type="image" src="pictures/button-submit.jpg" onClick="self.selectanatomy(); submit">
					&nbsp;&nbsp;
				    <br>
				</td>
              </tr>
            </table>
</form>

</center>


<?php
    include("frames_footer.php");
?>