icheck_blur_color  = "#ffffff";
icheck_focus_color = "#ccfcff";

function adjustTextareaRows(obj, org, plus) {
	var brlen = null;
	if (obj.wrap) {
		if (obj.wrap == 'virtual' || obj.wrap == 'soft') {
			brlen = obj.cols;
		}
	}
	var aLen = countLines(obj.value, brlen);
	var aRows = aLen + plus;
	var move = 0;
	var scroll = 14;
	if (org) {
		if (aRows > org + plus) {
			if (obj.rows < aRows) {
				move = (aRows - obj.rows) * scroll;
			} else if (obj.rows > aRows) {
				move = (aRows - obj.rows) * -scroll;
			}
			if (move !== 0) {
				if (move < 0) {
					window.scrollBy(0, move);
				}
				obj.rows = aRows;
				if (move > 0) {
					window.scrollBy(0, move);
				}
			}
			
		}
	} else if (obj.rows < aRows) {
		move = (aRows - obj.rows) * scroll;
		obj.rows = aRows;
		window.scrollBy(0, move);
	}
}

function countLines(str, brlen) {
	var lines = str.split("\n");
	var count = lines.length;
	var aLen = 0;
	for (var i = 0; i < lines.length; i++) {
		aLen = jstrlen(lines[i]);
		if (brlen) {
			var adjust = 1.15;
			if ((aLen * adjust) > brlen) {
				count = count + Math.floor((aLen * adjust) / brlen);
			}
		}
	}
	return count;
}

function jstrlen(str) {
	var len = 0;
	str = escape(str);
	for (var i = 0; i < str.length; i++, len++) {
		if (str.charAt(i) == "%") {
			if (str.charAt(++i) == "u") {
				i += 3;
				len++;
			}
			i++;
		}
	}
	return len;
}

function setFocus(ID){
	var obj = document.getElementById(ID);
	if (obj.disabled !== true) {
		obj.focus();
	}
}

function setHiddenValue(button) {
	if (button.name) {
		var q = document.createElement('input');
		q.type = 'hidden';
		q.name = button.name;
		q.value = button.value;
		button.form.appendChild(q);
	}
}

function Enter2Tab() {
	window.document.onkeydown = function(evt){
		if (evt){
			if (evt.keyCode == 13) {
				if (evt.target.type != 'submit' &&
					evt.target.type != 'textarea') {
					return false;
				}
			}
		}else{
			if (event.keyCode == 13) {
				if (window.event.srcElement.type != 'submit' &&
					window.event.srcElement.type != 'textarea') {
					event.keyCode = 9;
				}
			}
		}
	};
}
