function putImage() {
	var id = document.getElementById("insertImage").value;
	var w = prompt('How wide would you like this image (in pixels)? Enter nothing if you would not like to resize it.', 600);
	var h = prompt('How tall would you like this image (in pixels)? Enter nothing if you would not like to resize it.', 100);
	var s = prompt('Would you like to apply styling to the image? Options are "right", "left" and "center". You may also leave this blank to apply no styling. ');
	var u = prompt('Would like this image to act as a link? If so, enter the URL you would like to reference here.', 'http://');
	if (u=="http://") { u=""; }
	if(w == null) { w = ''; }
	if(h == null) { h = ''; }
	if(s == null) { s = ''; }
	if(u == null) { u = ''; }
	var f = '[[image:' + id + ',' + w + ',' + h + ',' + s + ',' + u + ']]';
	insertAtCursor(f);
	document.getElementById('insertImage').value = '';
}

function putGallery() {
	var id = document.getElementById("insertGallery").value;
	var w = prompt('How wide would you like each image to be (max 600)?', 600);
	var h = prompt('How tall would you like each image to be?');
	var c = prompt('How many images would you like to show in this gallery? Leave blank for all.');
	var u = confirm('Would you like each image to link to the larger version? OK for yes, Cancel for no.');
	if(w == null) { w = ''; }
	if(h == null) { h = ''; }
	if(c == null) { c = ''; }
	if(u == null) { u = ''; }	var f = '[[gallery:' + id + ',' + w + ',' + h + ',' + c + ',' + u + ']]';
	insertAtCursor(f);
	document.getElementById('insertGallery').value = '';
}

function putLink() {
	var id = document.getElementById("insertLink").value.split(",")[0];
	var wTmp = document.getElementById("insertLink").value.replace(id+",", "");
	var w = "";
	while (w == "" || w == false) {
		var w = prompt('What would you like this link to say?', wTmp);
	}
	if(w != null) { 
		var f = '[[link:' + id + ',' + w + ']]';
		insertAtCursor(f);
	}
	document.getElementById('insertLink').value = '';
}

function insertAtCursor(d) {
	q = document.getElementById("data");
	if(document.selection) {
		q.focus();
		sel = document.selection.createRange();
		sel.text = d;
	} else if (q.selectionStart || q.selectionStart == "0") {
		q.focus();
		startPos = q.selectionStart;
		endPos = q.selectionEnd;
		q.value = q.value.substring(0,startPos) + d + q.value.substring(endPos, q.value.length);
	} else {
		q.focus();
		q.value += d;
	}
}

function galleryChange() {
	
}
