function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

function loadtiplist(typ,tagid){
    var xhr; 
    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e) 
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2) 
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }
  
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
			  
			var doc = xhr.responseXML;   // Assign the XML file to a var
			var alltips = doc.getElementsByTagName('record'); 
			//alert(tips.length);
			
			//get all "eco" tips
			var i;
			var ecotips = [];
			for (i=0;i<=alltips.length-1;i++){
				if (alltips[i].getAttribute("type")==typ){
					ecotips[ecotips.length] = alltips[i];
				}
			}
	
			//create list
			var html;
			html  = '<table>';
			i=0;
			for (i=0;i<=ecotips.length-1;i++){
				html += '<tr><td valign="top" align="left"><img src="images/eco_bullet.png" /></td>';
				html += '<td>'+ecotips[i].getAttribute("text")+'<br />&nbsp;</td></tr>';
			}
			html += '</table>';
            
			
		  document.getElementById(tagid).innerHTML = html;
		  
          } else { 
                 alert("Error code " + xhr.status);
			  }
         }
    }

   xhr.open("GET", "kmillar_tips_v1.xml",  true); 
   xhr.send(null); 
}

function loadtip(typ,tagid){
    var xhr; 
    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e) 
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2) 
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }
  
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
			  
			var doc = xhr.responseXML;   // Assign the XML file to a var
			var alltips = doc.getElementsByTagName('record'); 
			//alert(tips.length);
			
			//get all "eco" tips
			var i;
			var ecotips = [];
			for (i=0;i<=alltips.length-1;i++){
				if (alltips[i].getAttribute("type")==typ){
					ecotips[ecotips.length] = alltips[i];
				}
			}
	
			//get a random index number
            var tempint = rand(ecotips.length)-1;
			//alert(tempint);
			
		  document.getElementById(tagid).innerHTML = ecotips[tempint].getAttribute("text") + '<br><br><a href="eco_tips.php"><strong><span id="tipbutton" onmouseover="javascript:tip_button_hover();" onmouseout="javascript:tip_button_unhover();" onclick="javascript:tip_button_unhover();">view all tips</span></strong></a>';
		  
          } else { 
                 alert("Error code " + xhr.status);
			  }
         }
    }

   xhr.open("GET", "kmillar_tips_v1.xml",  true); 
   xhr.send(null); 
}