var form; // its easier to make this global, javascript scope is a bitch and getting a handle on elements is too

function populatePictures( formid ) { // called on gallery selection change

	form = document.getElementById( formid );
	
	gal = form.gals.options[form.gals.selectedIndex].value;

	form.pics.options.length = 0;
	createOption( 0, "Loading...", "" ); // lets see something while we're waiting for the ajax request

	type = 'poppics'; // set global value and add conditional to ajax action function
	AJAXControl( 'xml/images.xml.php?gid=' + gal );
	
}

function popPicsAction( xmlDoc ) { // called on return of xml from ajax control

	form.pics.options.length = 0;
	createOption( 0, "---", "" ); 

	var markers = xmlDoc.documentElement.getElementsByTagName("picture");

	for (var i = 0; i < markers.length; i++) {
		createOption( i + 1, markers[i].getAttribute("filename"), markers[i].getAttribute("filename") ); 
	}

}

function showPreview( formid ) { // called on picture selection change
	
	picture = form.pics.options[form.pics.selectedIndex].value;

	picture = picture.replace(/(\.jpg)/g, "_thumb.jpg");
	picture = picture.replace(/\s{1}/g, "%20");

	document.getElementById(formid + 'preview').innerHTML = '<img src="userimages/' + picture + '"/>';
	document.getElementById(formid + 'src').innerHTML = 'http://www.coconutfunworld.com/userimages/' + picture;

}

function createOption( num, text, value ) { // used to add items to picture selection list 
	form.pics.options[num] = new Option( text,value );
	
}

function addSelectedPic( textid, previewid ) {
  if (document.getElementById) {

	var container 	= document.getElementById( textid );

    container.value += document.getElementById( previewid ).innerHTML;

  }
}
function addToPodcast( textid, previewid ) {
  if (document.getElementById) {

	var container 	= document.getElementById( textid );

    container.value = document.getElementById( previewid ).innerHTML;

  }
}





