function createXMLHttpRequest() {
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }
 
 
 function ReDraw(section,myspp){
	 
	 var spp = myspp;
	 var section = section;
	
	
	var ajaxRequest = createXMLHttpRequest();

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById("detailSection");
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
				
		}
	}
	
	var id=new Date('U');
	
	var str;
	
	str="?mySpp="+ spp +"&id="+id+"&limit=30";
	//alert (str);
	if(section==0){
		ajaxRequest.open("GET", "species_map_sa_region.php" + str, true);
	}else if(section==1){
		ajaxRequest.open("GET", "species_map_world.php" + str, true);
	}else if(section==2){
		ajaxRequest.open("GET", "species_map_sabap2.php" + str, true);
	}else if(section==3){
		str=str+"&Year=1950&Year2=1960&Zoom=0";
		ajaxRequest.open("GET", "species_map_safring_decade.php" + str, true);
	}else if(section==4){
		str=str+"&Year=1960&Year2=1970&Zoom=0";
		ajaxRequest.open("GET", "species_map_safring_decade.php" + str, true);
	}else if(section==5){
		str=str+"&Year=1970&Year2=1980&Zoom=0";
		ajaxRequest.open("GET", "species_map_safring_decade.php" + str, true);
	}else if(section==6){
		str=str+"&Year=1980&Year2=1990&Zoom=0";
		ajaxRequest.open("GET", "species_map_safring_decade.php" + str, true);
	}else if(section==7){
		str=str+"&Year=1990&Year2=2000&Zoom=0";
		ajaxRequest.open("GET", "species_map_safring_decade.php" + str, true);
	}else if(section==8){
		str=str+"&Year=2000&Year2=2010&Zoom=0";
		ajaxRequest.open("GET", "species_map_safring_decade.php" + str, true);
	}else if(section==9){
		str=str+"&Year=1950&Year2=2010&Zoom=0";
		ajaxRequest.open("GET", "species_map_safring_decade.php" + str, true);
	}else if(section==10){
		ajaxRequest.open("GET", "species_data_afring.php" + str, true);
	}else{
		ajaxRequest.open("GET", "species_map_world.php" + str, true);
	}
		
	ajaxRequest.send(null); 
}

function format_number(){
	 
	 var intLatDeg = document.form1.latDeg.value;
	 document.form1.latDeg.value = PadDigits(intLatDeg,2);
	 
	 var intLatMin = document.form1.latMin.value;
	 if(intLatMin<59){
		 intLatMin=intLatMin;
	 }else{
		 intLatMin=(intLatMin/100)*60
	 }
	 document.form1.latMin.value = PadDigits(intLatMin,2);
	 
	 var intLongDeg = document.form1.longDeg.value;
	 document.form1.longDeg.value = PadDigits(intLongDeg,3);
	 
	 var intLongMin = document.form1.longMin.value;
	  if(intLongMin<59){
		 intLongMin=intLongMin;
	 }else{
		 intLongMin=(intLongMin/100)*60
	 }
	 document.form1.longMin.value = PadDigits(intLongMin,2);
	 
	 var strAfring
	 strAfring=document.form1.latDeg.value+document.form1.latMin.value+document.form1.latDir.value;
	 strAfring=strAfring+document.form1.longDeg.value+document.form1.longMin.value+document.form1.longDir.value;
	 document.form1.afring_formatted.value=strAfring;
	 
	 }
	 
function selectImage(){
	
	var strtype = document.form1.Inscription.value;
	
	if(strtype=='PlasticPlain'){
		 document.getElementById('ring_image').innerHTML='<img src="images/ring_colour_combination.jpg" alt="Bird ring or band - plastic combination" border="1"  />';
		 document.getElementById('ring_id_request').innerHTML="Please enter the ring number:";
		 
		 document.form1.RingNo.disabled=false;
		 document.form1.DateAccuracy.disabled=false;
		 
		 document.getElementById('basic').style.visibility = 'visible'; 
		 document.getElementById('advanced').style.visibility = 'visible'; 
		 document.getElementById('contact').style.visibility = 'visible'; 
		 
	}else if(strtype=='PlasticText'){
		 document.getElementById('ring_image').innerHTML='<img src="images/ring_canadian.jpg" alt="Bird ring or band - plastic inscribed"  border="1" />';
		 document.getElementById('ring_id_request').innerHTML="Please enter the ring number:";
		 
		 document.form1.RingNo.disabled=false;
		 document.form1.DateAccuracy.disabled=false;
		  
		 document.getElementById('basic').style.visibility = 'visible'; 
		 document.getElementById('advanced').style.visibility = 'visible'; 
		 document.getElementById('contact').style.visibility = 'visible'; 
		 
	}else if(strtype=='PlasicDove'){
		 document.getElementById('ring_image').innerHTML='<img src="images/ring_dove.jpg" alt="Racing pigeon rings"   border="1"/>';
		 document.getElementById('ring_id_request').innerHTML='<br/>This type of ring is used on racing pigeons, and the records are not curated by this project<br/>To enquire about this ring please see the <a href="http://www.racingpigeon.co.za/">Racing pigen website</a>';
		 
		 document.form1.RingNo.disabled=true;
		 document.form1.DateAccuracy.disabled=true;
		 
		 document.getElementById('basic').style.visibility = 'hidden'; 
		 document.getElementById('advanced').style.visibility = 'hidden'; 
		 document.getElementById('contact').style.visibility = 'hidden'; 
		
	}else if(strtype=='FOREIGN'){
		 document.getElementById('ring_image').innerHTML='<img src="images/ring_metal.jpg" alt="Racing pidgeon rings"  border="1" />';
		 document.getElementById('ring_id_request').innerHTML="Please enter the entire inscription on the ring";
		 
		 document.form1.RingNo.disabled=false;
		 document.form1.DateAccuracy.disabled=false;
		  
		 document.getElementById('basic').style.visibility = 'visible'; 
		 document.getElementById('advanced').style.visibility = 'visible'; 
		 document.getElementById('contact').style.visibility = 'visible'; 
	}else{
		 document.getElementById('ring_image').innerHTML='<img src="images/ring_metal.jpg" alt="Bird ring or band"  border="1" />';
		 document.getElementById('ring_id_request').innerHTML="Please enter the ring number:";
		 
		 document.form1.RingNo.disabled=false;
		 document.form1.DateAccuracy.disabled=false;
		  
		 document.getElementById('basic').style.visibility = 'visible'; 
		 document.getElementById('advanced').style.visibility = 'visible'; 
		 document.getElementById('contact').style.visibility = 'visible'; 
	}
		//ring_id_request 
	 }
 
 function PadDigits(n, totalDigits) 
    { 
        n = n.toString(); 
        var pd = ''; 
        if (totalDigits > n.length) 
        { 
            for (i=0; i < (totalDigits-n.length); i++) 
            { 
                pd += '0'; 
            } 
        } 
        return pd + n.toString(); 
    } 
	
