function getImage(mls, amount)
{
	var currentImage = parseInt(document.getElementById('currentImage').innerHTML) + parseInt(amount);

	if(currentImage <= 0)
	{
		currentImage = parseInt(document.getElementById('totalImages').innerHTML);
	}
	else if(currentImage > parseInt(document.getElementById('totalImages').innerHTML))
	{
		currentImage = 1;
	}
	document.getElementById('currentImage').innerHTML = currentImage;
	document.getElementById('listingImage').innerHTML = '<a href="listings/' + mls + '/images/' + currentImage + '.jpg" target="_blank"><img src="listings/' + mls + '/images/thumbs/' + currentImage + '.jpg" border="0" /></a>';

}

function selectedToArray(theSel)
{
	var selected = new Array();

	if (theSel.selectedIndex > -1)
		for (var i=theSel.selectedIndex, iterations = theSel.options.length; i<iterations; i++)
			if (theSel.options[i].selected) selected.push(theSel.options[i].value);

	return selected;
}

function addImage(imageName)
{
	var imagePath = document.forms['addListing'][imageName].value;
	var imageNumber = parseInt(imageName.substring(imageName.indexOf('e')+1, imageName.indexOf('e')+2));

	var fileName = imagePath.substring(imagePath.lastIndexOf('\\')+1);
	var nextOption = document.forms['addListing'].imageList.options.length++;
	document.forms['addListing'].imageList.options[nextOption] = new Option(fileName, imagePath);

	alert(document.getElementById('fileList').innerHTML += '<span id="image' + imageNumber+1 + '"><input size="20" name="image' + imageNumber+1 + 'Path" type="file" onChange="addImage(this.value);" /></span>');

//	document.forms['addListing'].imageList.options[document.forms['addListing'].imageList.options.length++] = new Option(document.forms['addListing'].imagePath.value.substring(document.forms['addListing'].imagePath.value.lastIndexOf('\\')+1), document.forms['addListing'].imagePath.value);
//	document.forms['addListing'].imagePath.value = null;
}

function removeImage()
{
	document.forms['addListing'].imageList.options[document.forms['addListing'].imageList.selectedIndex] = null;
}
