function disabledEvent(evt) {
	if (typeof(evt) != "object")
		evt = event;
		
	if (evt.srcElement.tagName == "INPUT" && evt.srcElement.type == "text" ||
		evt.srcElement.tagName == "INPUT" && evt.srcElement.type == "file" ||
		evt.srcElement.tagName == "TEXTAREA")
	{
		if (evt.srcElement.disabled)
			return false;
			
		return true;
	}
	else
		return false;
}

function ieVersion() {
	var strVersion = navigator.appVersion;
	var nVersion = 0;
	var nLoc = -1;

	nLoc = strVersion.indexOf("MSIE ");

	if (nLoc > -1)
		nVersion = parseFloat(strVersion.substring(nLoc + 5, strVersion.length));

	return nVersion;
}

function allTrim(strText) {
	return leftTrim(rightTrim(strText));
}

function leftTrim(strText) {
	var strLen=strText.length;
	var charIndex=0;
	
	for (;charIndex<strLen;charIndex++)	{
		if (strText.charAt(charIndex)!=" ") break;
	}
	strText=strText.substring(charIndex,strLen);
	return strText;
}

function rightTrim(strText) {
	var strLen=strText.length;
	var charIndex=strLen-1;
	
	for (;charIndex>-1;charIndex--)	{
		if (strText.charAt(charIndex)!=" ") break;
	}
	strText=strText.substring(0,charIndex+1);
	return strText;
}

function getBaseName(strFileSpec) {
	var strTemp = strFileSpec;
	var nLoc = strTemp.lastIndexOf("\\");
	if (nLoc == -1) nLoc = strTemp.lastIndexOf("/");
	
	strTemp = strTemp.substring(nLoc + 1, strTemp.length);
	
	nLoc = strTemp.lastIndexOf(".");
	if (nLoc != -1)
		strTemp = strTemp.substring(0,nLoc);
	return strTemp;
}

function getParentPath(strPathSpec) {
	var nLoc = strPathSpec.lastIndexOf("/");
	
	if (nLoc < 0) {
		nLoc = strPathSpec.lastIndexOf("\\");
		if (nLoc < 0) {
			return "";
		}
	}
	
	return strPathSpec.substring(0, nLoc + 1);
}

function getFolderName(strPathSpec) {
	if (strPathSpec == "") return "";
	
	var nLoc = strPathSpec.length - 1;
	var strLast = strPathSpec.charAt(nLoc);
	if (strLast == "/" || strLast == "\\") {
		strPathSpec = strPathSpec.substring(0, nLoc);
	}
	
	nLoc = strPathSpec.lastIndexOf("/");
	
	if (nLoc < 0) {
		nLoc = strPathSpec.lastIndexOf("\\");
		if (nLoc < 0) {
			return "";
		}
	}

	return strPathSpec.substring(nLoc + 1, strPathSpec.length);
}

function isInteger(strValue, bNull) {
	var strNumeric = "0123456789";
	
	if (strValue == "" && bNull != true) return false;
	
	for (var i = 0; i < strValue.length; i ++) {
		if (strNumeric.indexOf(strValue.charAt(i)) == -1)
			return false;
	}
	return true;
}

function isSpace(sText) {
	return sText.replace(/ /g,"") == "";
}

function getByteLength(sText) {
	var nByteLength = 0;
	for (var i = 0;i < sText.length;i ++)
		if (sText.charCodeAt(i) > 128)
			nByteLength += 2;
		else
			nByteLength ++;
	return nByteLength
}

function isNumber(strText)
{
	var strCheck = "0123456789";

	for (var i = 0; i < strText.length; i ++)
	{
		if (strCheck.indexOf(strText.charAt(i)) >= 0)
		{
			return true;
		}
	}

	return false;
}

function ChangeQueryString(sourceQueryString, key, value)
{
	value = escape(value);
	
	var anchor = "";
	var pos1 = 0, pos2 = 0;	
		
	key = key.toLowerCase();
	sourceQueryString = sourceQueryString.toLowerCase();
	
	var nAch = sourceQueryString.indexOf("#");
	if (nAch != -1) 
	{
		anchor = sourceQueryString.substring(nAch, sourceQueryString.length);
		sourceQueryString = sourceQueryString.substring(0, nAch);		
	}
       
	pos1 = sourceQueryString.indexOf("&" + key + "=");
	
	if(pos1 == -1)
		pos1= sourceQueryString.indexOf("?" + key + "=");
	
	if(pos1 == -1)
	{
		if (sourceQueryString.indexOf("?") == -1)
			return (sourceQueryString + "?" + key + "=" + value + anchor);
		else if (sourceQueryString.indexOf("?") + 1 == sourceQueryString.length)
			return (sourceQueryString + key + "=" + value + anchor);
		else
			return (sourceQueryString + "&" + key + "=" + value + anchor);
	}
	
	pos2 = sourceQueryString.indexOf("&", pos1 + 1);

	if(pos2 == -1)
	{
		return (sourceQueryString.substring(0, sourceQueryString.lastIndexOf("=") + 1) + value + anchor); 
	}
	else
	{
		var str1, str2;
		str2 = sourceQueryString.substring(pos2, sourceQueryString.length);

		str1 = sourceQueryString.substring(0, pos2);

		str1 = str1.substring(0, str1.lastIndexOf("=") + 1);
		
		return str1 + value + str2 + anchor;
	}
}

	function hex(charCode, bits)
	{
		var sHEXChars="0123456789abcdef";
		var str="";
		if (typeof(bits) == "undefined")
			bits = 4;
		if (bits == 2)
			str = sHEXChars.charAt(charCode >> 4 & 0x0F) + sHEXChars.charAt(charCode & 0x0F)
		else
			str = sHEXChars.charAt(charCode >> 12 & 0x0F) + sHEXChars.charAt(charCode >> 8 & 0x0F) + sHEXChars.charAt(charCode >> 4 & 0x0F) + sHEXChars.charAt(charCode & 0x0F)

		return str;
	}

	function urlEncode(url)
	{
		if (url == null) return "";
		var c;
		var s = "";
		
		for (var i = 0; i < url.length; i ++)	
		{
			c = url.charCodeAt(i);
			if (c > 127)
				s += "%u"+ hex(c);
			else if (c >= 0x30 && c <= 0x39 || c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A)
				s += url.charAt(i);
			else
				s += "%"+ hex(c, 2);
		}
		
		return s;
	}
