function insertAtCursor(id, startVal, endVal){
	var o = document.getElementById(id);
	insertAtCursorObj(o, startVal, endVal);
}

function insertAtCursorObj(o, startVal, endVal){	
	var startPos = o.selectionStart;
	var endPos = o.selectionEnd;
	o.value = o.value.substring(0,startPos) + startVal + o.value.substring(startPos,endPos) + endVal + o.value.substring(endPos,o.value.length);
	var pos = endPos + startVal.length;
	o.setSelectionRange(pos, pos);
	o.focus();
}

function openCenteredWindow(url, name, width, height){
	var left = Math.round(document.body.clientWidth / 2 - width / 2);
	var top = Math.round(document.body.offsetHeight / 2 - height / 2);
	var win = open(url, name, 'width='+width+',height='+height+',left='+left+',top='+top+',resizable=yes,scrollbars=yes,status=yes');
} // End function

function fileSelection(controlId){
	openCenteredWindow('fileBrowser.aspx?type=file&controlId='+controlId, '_filebrowser', 800, 600);
}

function imageSelection(controlId){
	openCenteredWindow('fileBrowser.aspx?type=image&controlId='+controlId, '_filebrowser', 800, 600);
}

function show(id){
	document.getElementById(id).style.display = 'block';
}

function hide(id){
	document.getElementById(id).style.display = 'none';
}

function changeVisible(id){
	var control;
	control = document.getElementById(id);
	control.style.display = (control.style.display == 'none') ? 'block' : 'none';	
}
