// dynodes.js
// Kent Brewster, 2005
// http://www.mindsack.com/uxe/dynodes/
// feel free to use or distribute this code
// but please retain this notice

// Gotcha: onLoad takes a camelCase L, or IE won't work
// Gotcha: need init(), not init, or Opera won't work

window.onLoad=init();

function init()
{
    //Write the remote script
    h();
    //Call the function to execute remote script after 400ms so browser
    //has chance to update the page
    setTimeout('k()',400);
}

//prepare the remote script
function h()
{
		// create a new node to host the remote script
		var remoteScript=document.createElement('script');
		remoteScript.id = 'rs';
		remoteScript.setAttribute('type','text/javascript');
		remoteScript.setAttribute('src','http://www.doggysnaps.com/vBulletinHeader.aspx');
		var hd=document.getElementsByTagName('head')[0];

		// Gotcha: set attribute and src BEFORE appending, or Safari won't work
		hd.appendChild(remoteScript);
}

// Click: execute remote function, remove the remote script
function k()
{
	// getStuff is a function in the remote script
	// which will call doStuffWith() here
	getStuff();
	
	// and remove it
	removeScript('rs');
}

// remove script node
function removeScript(id)
{
	var hd=document.getElementsByTagName('head')[0];
	hd.removeChild(document.getElementById(id));
}

// called by the remote script upon successful execution
function doStuffWith(theStuffIGotSomewhereElse)
{
	document.getElementById('dogCount').innerHTML = theStuffIGotSomewhereElse.dogCount;
}