function hideBoxes(name) {
	var ele=document.getElementsByName(name);
	for (i=0; i<ele.length; i++) {
		ele[i].style.display = 'none';
	}
}

function showElement(id) {
	document.getElementById(id).style.display = 'block';
}

function hideElement(id) {
	document.getElementById(id).style.display = 'none';
}

function resetInput(field) {
	field.value = "";
	field.focus();
}

function changeDisplayType(id) {
	if (document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display = 'block';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}

function changeDisplayTypein(id) {
	if (document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display = 'inline';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}

function get_pos (o) { 
	var pos = { top:0, left:0 }; 
	if(!o) return pos; 
	else if(typeof o == 'string' ) o = document.getElementById(o); 
	 
	if( typeof o != 'object'  || typeof o.offsetTop == 'undefined') return pos; 
	while (o && o.tagName != 'BODY') 
	{ 
		pos.top  += parseInt( o.offsetTop ); 
		pos.left += parseInt( o.offsetLeft ); 
		o = o.offsetParent; 
	} 
	return pos; 
}
	
function mouse_pos(evt) { 
	if(!evt) evt = window.event; 
	var pos = {left: evt.clientX, top: evt.clientY}; 
	var body = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ?  
	window.document.documentElement : window.document.body || null; 
	if (body) 
	{ 
		pos.left += body.scrollLeft; 
		pos.top += body.scrollTop; 
	} 
	return pos; 
}

function bbinsert(field, startTag, endTag, offset) {
	field.focus();
	if (document.getSelection) { //FF, NS
		selStart = field.selectionStart;
		selEnd = field.selectionEnd;
		text = field.value.substring(selStart, selEnd);
		field.value = field.value.substring(0, selStart) + startTag + text + endTag + field.value.substring(selEnd);
		if (text.length > 0) {
			if (offset != 0) {
				field.selectionStart = selStart + startTag.length + text.length - offset;
			} else {
				field.selectionStart = selStart + startTag.length + text.length + endTag.length;
			}
		} else {
			field.selectionStart = selStart + startTag.length;
	    }
		field.selectionEnd = field.selectionStart;
	} else if (document.selection) { //IE
		marker = document.selection.createRange();
		text = marker.text;
		marker.text = startTag+text+endTag;
		marker = document.selection.createRange();
		if (text.length > 0) {
			if (offset != 0) {
				marker.move('character', startTag.length + text.length - offset);
			} else {
				marker.move('character', startTag.length + text.length + endTag.length + offset);
			}
		} else {
			marker.move('character', -(endTag.length));
		}
		marker.select();
	}
}

function checkInputLength(value, charcount_id, max_chars, change_color_limit) {
	if (value.length > max_chars) {
		value = value.substring(0, max_chars);
	}
	charsleft = max_chars - value.substring(0, max_chars).length;
	document.getElementById(charcount_id).innerHTML = charsleft;
	if (charsleft <= change_color_limit) {
		document.getElementById(charcount_id).style.color = '#ff0000';
	} else {
		document.getElementById(charcount_id).style.color = '#777777';
	}
}