function DisableTextSelect(obj)
{
	if ($.browser.mozilla)
	{//Firefox
		$(obj).css('MozUserSelect', 'none');
	} else if ($.browser.msie)
	{//IE
		$(obj).bind('selectstart', function() { return false; });
	} else
	{//Opera, etc.
		$(obj).mousedown(function() { return false; });
	}

}
function OpenWindow(theURL, winName, features, w, h, scrollbars, center)
{
	if (w == null || w < 1)
		w = window.screen.availWidth;
	if (h == null || h < 1)
		h = window.screen.availHeight;
	var l = window.screen.availWidth / 2 - (w / 2);
	l = l > 0 ? l : 1;
	var t = window.screen.availHeight / 2 - (h / 2);
	t = t > 0 ? t : 1;
	var win = window.open(theURL, winName, features + ",toolbar=0,location=1,status=1,menubar=0,width=" + (w - 12) + ",height=" + (h - 64) + (scrollbars != null && scrollbars ? ",scrollbars=1" : "") + (center ? ",left=" + l + ",top=" + t : ""));
	win.focus();
	if (center != true)
		win.moveTo(1, 1);
	win.resizeTo(w, h);
	return win;
}
function ResizeWindow(w, h, scrollbars, center)
{
	if (w == null || w < 1)
		w = window.screen.availWidth;
	if (h == null || h < 1)
		h = window.screen.availHeight;
	var l = window.screen.availWidth / 2 - (w / 2);
	l = l > 0 ? l : 1;
	var t = window.screen.availHeight / 2 - (h / 2);
	t = t > 0 ? t : 1;
	window.resizeTo(w, h);
	if (center == null || center == true)
		window.moveTo(l, t);
}
function FireDefaultButton(event, targetId)
{
	if (event.keyCode == 13)
	{
		var src = event.srcElement || event.target;
		if (!src || src.tagName.toLowerCase() != "textarea")
		{
			var defaultButton = document.getElementById(targetId);
			if (defaultButton && (typeof defaultButton.click != "undefined" || typeof defaultButton.href != "undefined"))
			{
				if (typeof defaultButton.click != "undefined")
					defaultButton.click();
				else
					eval(defaultButton.href);
				event.cancelBubble = true;
				if (event.stopPropagation)
				{
					event.stopPropagation();
				}
				return false;
			}
		}
	}
	return true;
}
function GetBodyMaxHeight(defaultHeight)
{
	var maxHeight = document.body.clientHeight;
	if (defaultHeight == null)
		return maxHeight;
	if (defaultHeight <= maxHeight)
		return defaultHeight;
	else
		return maxHeight;
}
function GetBodyMaxWidth(defaultWidth)
{
	var maxWidth = document.body.clientWidth;
	if (defaultWidth == null)
		return maxWidth;
	if (defaultWidth <= maxWidth)
		return defaultWidth;
	else
		return maxWidth;
}
function GetBody()
{
	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}
function GetObj(id)
{
	return document.getElementById(id);
}
function ShowDiv(divId, show, x, y, allwayShow)
{
	var objDiv = document.getElementById(divId);
	if (objDiv == null)
		return;

	if (show == null)
		if (objDiv.style.display == "")
		objDiv.style.display = "none";
	else
		objDiv.style.display = "";
	else
		if (show == false)
		objDiv.style.display = "none";
	else
		objDiv.style.display = "";

	if (x != null && y != null)
	{
		if (allwayShow)
		{
			var winwidth = GetBody().scrollLeft;
			var winheight = GetBody().scrollTop;
			if (x + objDiv.offsetWidth - GetBody().scrollLeft > winwidth)
				x = x - objDiv.offsetWidth - 20;
			if (y + objDiv.offsetHeight - GetBody().scrollTop > winheight)
				y = y - objDiv.offsetHeight - 20;
		}
		objDiv.style.left = x + "px";
		objDiv.style.top = y + "px";
	}
}
function ShowDivAtMouse(event, divId, dx, dy, allwayShow)
{
	var curX = event.clientX + GetBody().scrollLeft;
	var curY = event.clientY + GetBody().scrollTop;
	if (dx == null)
		dx = 0;
	if (dy == null)
		dy = 0;
	ShowDiv(divId, true, curX + dx, curY + dy, allwayShow);
}

function ShowDivByObj(divId, obj, timeoutObj)
{
	var position = GetOffsetPosition(obj);
	ShowDiv(divId, true, position[0] + obj.offsetWidth, position[1]);
	var divObj = document.getElementById(divId);
	var divMouseover = function() { clearTimeout(timeoutObj); };
	var divMouseout = function() { timeoutObj = setTimeout("ShowDiv('" + divId + "', false)", 200); };
	if (document.all)
	{
		obj.attachEvent("onmouseover", divMouseover);
		obj.attachEvent("onmouseout", divMouseout);

		divObj.attachEvent("onmouseover", divMouseover);
		divObj.attachEvent("onmouseout", divMouseout);
	}
	else
	{
		obj.addEventListener("mouseover", divMouseover, false);
		obj.addEventListener("mouseout", divMouseout, false);

		divObj.addEventListener("mouseover", divMouseover, false);
		divObj.addEventListener("mouseout", divMouseout, false);
	}
}

function AddEventMouseOverOutToObj(divId, objId, showFunctionName, hideFunctionName, timeOut)
{
	eval(showFunctionName + "('" + divId + "','" + objId + "')");
	var obj = document.getElementById(objId);
	var divObj = document.getElementById(divId);
	window[divId + "_" + objId] = null;
	var timeoutObj = window[divId + "_" + objId];
	var divMouseover = function() { clearTimeout(timeoutObj); };
	var divMouseout = function() { timeoutObj = setTimeout(hideFunctionName + "('" + divId + "','" + objId + "')", (timeOut == null ? 400 : timeOut)); };
	if (document.all)
	{
		obj.attachEvent("onmouseover", divMouseover);
		obj.attachEvent("onmouseout", divMouseout);

		divObj.attachEvent("onmouseover", divMouseover);
		divObj.attachEvent("onmouseout", divMouseout);
	}
	else
	{
		obj.addEventListener("mouseover", divMouseover, false);
		obj.addEventListener("mouseout", divMouseout, false);

		divObj.addEventListener("mouseover", divMouseover, false);
		divObj.addEventListener("mouseout", divMouseout, false);
	}
}

function GetOffsetPosition(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
		do
	{
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
	}
	while (obj = obj.offsetParent);
	return [curleft, curtop];
}

function AlphaEffect(divId, startAlpha, endAlpha, step)
{
	var alpha;
	if (startAlpha < endAlpha)
	{
		startAlpha = startAlpha + step;
		if (startAlpha > endAlpha)
			startAlpha = endAlpha;
		alpha = startAlpha;
	}
	else
		if (startAlpha > endAlpha)
	{
		startAlpha = startAlpha - step;
		if (startAlpha < endAlpha)
			startAlpha = endAlpha;
		alpha = startAlpha;
	}
	var style = document.getElementById(divId).style;
	style.display = "";
	style.filter = "Alpha(opacity=" + alpha + ")";
	style.opacity = alpha != 100 ? "0." + alpha : "1";

	if (startAlpha != endAlpha)
		setTimeout("AlphaEffect('" + divId + "', " + startAlpha + ", " + endAlpha + ", " + step + ")", 1);
	else
		if (startAlpha == endAlpha && startAlpha == 0)
		style.display = "none";
}

function ShowOverlay(show, zIndex, objOverlayId)
{
	objOverlayId = objOverlayId ? objOverlayId : "divOverlay";
	var obj = document.getElementById(objOverlayId);
	if (obj == null)
	{
		var divOverlay = document.createElement("div");
		divOverlay.innerHTML = '<div id="' + objOverlayId + '" style="background-color: #000000; opacity: 0.75; filter: alpha(opacity=75); position: absolute; left: 0px; top: 0px; display: none; z-index: ' + (zIndex ? zIndex : 0) + '"></div>';
		theForm.appendChild(divOverlay);
	}
	else
	{
		obj.style.zIndex = zIndex ? zIndex : 0;
		obj.style.position = "absolute";

		obj.style.backgroundColor = "#000000";
		obj.style.left = "0px";
		obj.style.top = "0px";
		obj.style.display = "none";

		if (document.all)
		{
			obj.style.setAttribute("filter", 'alpha(opacity=75)');
		}
		else
		{
			obj.style.opacity = "0.75";
		}
	}
	obj = document.getElementById(objOverlayId);

	obj.style.width = GetBody().scrollWidth + "px";
	obj.style.height = GetBody().scrollHeight + "px";
	if (show == true)
	{
		obj.style.display = "";
	}
	else
	{
		obj.style.display = "none";
	}
}

function LoadPage(url, show, width, height, zIndex, scrollBar)
{
	if (window["divLoadPageIndex"] == null)
		window["divLoadPageIndex"] = 0;

	divLoadPageIndex += 1;
	var frameName = "fLoadPage" + divLoadPageIndex;
	var divLoadPage = document.getElementById("divLoadPage");
	if (divLoadPage == null)
	{
		var divLoadPageObj = document.createElement("div");
		divLoadPageObj.innerHTML += '<div id="divLoadPage" style="position: absolute; left: 0px; top: 0px; width: auto; height: auto; display: none; z-index: ' + (zIndex ? zIndex : 1) + ';">' +
									'<iframe id="' + frameName + '" src="about:blank" name="' + frameName + '" width="1" height="1" frameborder="0" marginheight="0" marginwidth="0" style="background-color:#ffffff;" ' + (scrollBar != true ? 'scrolling="no"' : '') + '></iframe>' +
								'</div>';
		document.body.appendChild(divLoadPageObj);
		divLoadPage = document.getElementById("divLoadPage");
	}
	if (url == null || show == false)
	{
		//AlphaEffect("divLoadPage", 50, 0, 5);

		//		divLoadPage.style.display = "none";

		setTimeout('document.getElementById("divLoadPage").parentNode.parentNode.removeChild(document.getElementById("divLoadPage").parentNode); ShowOverlay(false);', 100);

		//		if (url == null)
		//			url = "about:blank";
		//		setTimeout("window.frames['" + frameName + "'].location = '" + url + "'", 500);
	}
	else
	{
		ShowOverlay(true);

		divLoadPage.style.display = "";

		var fLoadPage = window.frames[frameName];

		if (width != null)
			fLoadPage.frameElement.width = width;
		if (height != null)
			fLoadPage.frameElement.height = height;
		fLoadPage.location = url;

		//AlphaEffect("divLoadPage", 50, 100, 5);

		divLoadPage.style.left = ((GetBody().clientWidth - divLoadPage.offsetWidth) / 2) + "px";
		divLoadPage.style.top = (GetBody().scrollTop + ((GetBody().clientHeight - divLoadPage.offsetHeight) / 2)) + "px";
	}
}

function LoadDiv(divId, show, width, height, margin, padding, overlayId)
{
	padding = padding ? padding : 0;
	margin = margin ? margin : 0;
	var objDiv = document.getElementById(divId);
	var theBody = GetBody();

	if (show == false)
	{
		objDiv.style.display = "none";
		ShowOverlay(false, null, overlayId);
		return;
	}

	ShowOverlay(true, null, overlayId);
	if (width == null)
	{
		width = theBody.offsetWidth - margin * 2;
		height = theBody.offsetHeight - margin * 2;
	}

	objDiv.style.display = "";
	objDiv.style.width = width + "px";
	objDiv.style.height = height + "px";
	objDiv.style.left = ((theBody.offsetWidth - width) / 2 - padding) + "px";
	objDiv.style.top = ((theBody.offsetHeight - height) / 2 - padding) + "px";
}

function SetSelectedValue(selectObjId, value)
{
	var selectObj = document.getElementById(selectObjId);
	selectObj.value = value;
}

function CheckKeyPressAndRun(e, keyCode, evalString)
{
	var event = e ? e : window.event;
	var key = event.keyCode ? event.keyCode : event.which;
	if (key == keyCode)
		return eval(evalString);
};

function GetQueryString(queryStringName)
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i = 0; i < vars.length; i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == queryStringName)
			return pair[1];
	}
	return null;
}

function CheckCheckboxRadioByValue(name, value)
{
	var checkObjList = document.getElementsByName(name);
	if (checkObjList == null)
		return;

	for (var i = 0; i < checkObjList.length; i++)
		checkObjList[i].checked = (checkObjList[i].value == value.toString());
}

function GetValueOfSelectRadio(name)
{
	var checkObjList = document.getElementsByName(name);
	if (checkObjList == null)
		return null;

	for (var i = 0; i < checkObjList.length; i++)
		if (checkObjList[i].checked)
		return checkObjList[i].value;

	return null;
}

function GetFlashObj(movieName)
{
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? document.getElementById(movieName) : document[movieName];
}

function HideBodyScrollBar()
{
	document.body.scroll = "no"; // IE
	document.body.style.overflow = "hidden"; // Non IE
	document.documentElement.style.overflow = 'hidden'; // Non IE
}

function InsertCharAtCursor(myField, myValue)
{
	//IE support
	if (document.selection)
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}

	//MOZILLA/NETSCAPE support
	else
	{
		if (myField.selectionStart || myField.selectionStart == '0')
		{
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			restoreTop = myField.scrollTop;
			myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
			myField.selectionStart = startPos + myValue.length;
			myField.selectionEnd = startPos + myValue.length;

			if (restoreTop>0)
			{
				myField.scrollTop = restoreTop;
			}
		}
		else
		{
			myField.value += myValue;
		}
	}
}

function InterceptCharTabs(evt, control)
{
	key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
	if (key == 9)
	{
		InsertCharAtCursor(control, '\t');
		return false;
	}
	else
	{
		return key;
	}
}

// String Function

String.prototype.Trim = function()
{
	return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.LeftTrim = function()
{
	return this.replace(/^\s+/, "");
}
String.prototype.RightTrim = function()
{
	return this.replace(/\s+$/, "");
}

// ajax jquery
function AjaxBindOptions(_url, targetId, lastselected)
{
	var oTarget = $('#' + targetId);
	$.ajax(
 {
 	url: _url,
 	cache: false,
 	success: function(data)
 	{
 		oTarget.empty();
 		var options = eval(data);
 		if (typeof options == 'object')
 		{
 			$.each(options, function(i)
 			{
 				oTarget.append('<option value="' + this[1] + '">' + this[0] + '</option>');
 			});
 			if (lastselected)
 				oTarget.find("option:last").attr("selected", "true");
 		}
 	}
 });
}