	// ------------------------------------------------------------------------------------------------- //
	// SET language 
	function set_language(pLang,pSystem)
	{
		if(pLang != "")
		{
			$.get("../ajax/ajax_set_language.php?uLang=" + pLang, 
			function(data)
			{
				if(data == "true")
				{
					if(pSystem == "public" || pSystem == "home")
						window.location = "../home/index.php";
					else
						location.reload(true);
				}
				else if(data == "false")
				{
					// SET language failed
				}
			});
		}
	}
	// ------------------------------------------------------------------------------------------------- //
	// SET company 
	function set_company(comp)
	{
		if(comp != "")
		{
			$.get("../ajax/ajax_set_company.php?uComp=" + comp, 
			function(data)
			{
				if(data == "true")
				{
					location.reload(true);
				}
				else if(data == "false")
				{
					// SET language failed
				}
			});
		}
	}
	// ------------------------------------------------------------------------------------------------- //
	// SORT option
	function sort_option(pOpt,pSortBy)
	{
		function compare_option_text(a,b)
			{return a.text!=b.text ? a.text<b.text ? -1 : 1 : 0;}
		function compare_option_value(a,b)
			{return a.value!=b.value ? a.value<b.value ? -1 : 1 : 0;}

		var vItems = pOpt.options.length;
		var aTemp = new Array(vItems);
		
		vTempValue = "";
		vTempText = "";
		
		for(i=0; i<vItems; i++)
			aTemp[i] = new Option(pOpt.options[i].text,pOpt.options[i].value);
			
		switch(pSortBy)
		{
			case "value":
				aTemp.sort(compare_option_value);
				break;
			case "text":
				aTemp.sort(compare_option_text);
				break;
			default:
				aTemp.sort(compare_option_value);
				break;
		}
		for (i=0; i<vItems; i++)
			pOpt.options[i] = new Option(aTemp[i].text,aTemp[i].value);
	}
	// ------------------------------------------------------------------------------------------------- //
	function ajax_load_opt(url,objID, callback)
	{
		$.getJSON(url,
	
			function(j)
			{
				var options = '';
				var selIndex = "";
				for (var i = 0; i < j.length; i++)
				{
					if(j[i].optionClass != undefined && j[i].optionClass != "")
						vClass = j[i].optionClass;
					else
						vClass = "";
					
					options += '<option value="' + j[i].optionValue + '" class="' + vClass + '"' ;
					if(j[i].selected == "SELECTED") {
						selIndex = j[i].optionValue;
						options += ' selected>' + j[i].optionDisplay + '</option>'; //selIndex = j[i].optionValue;
					}
					else
						options += ' >' + j[i].optionDisplay + '</option>';
					
				}
			   	
				$("select#"+objID).html(options);
				
				// this for firefox
				try
				{
					$("#"+objID).val(selIndex);
					if(callback != "" || callback != undefined)
						eval(callback);
				}
				catch(ex)
				{}
			}
		)
	}
	// ------------------------------------------------------------------------------------------------- //
	function trim(stringToTrim)
	{
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	// ------------------------------------------------------------------------------------------------- //
	function redirect(url)
	{
		window.location = url;	
	}
	// ------------------------------------------------------------------------------------------------- //
	function left(str, n)
	{
		if (n <= 0)
			return "";
		else if (n > String(str).length)
			return str;
		else
			return String(str).substring(0,n);
	}
	// ------------------------------------------------------------------------------------------------- //
	function right(str, n)
	{
		if (n <= 0)
			return "";
		else if (n > String(str).length)
			return str;
		else
		{
			var iLen = String(str).length;
			return String(str).substring(iLen, iLen - n);
		}
	}
	// ------------------------------------------------------------------------------------------------- //
	function filter_id(pValue)
	{	
		pValue = pValue.replace(/\s{0,}/g,"");	// replace all whitespace to empty	
		pValue = pValue.replace(/\,{0,}$/g,"");	// replace ',' at the end of the string
		pValue = pValue.replace(/^\,{0,}/g,"");	// replace ',' at the front of the string
		pValue = pValue.replace(/\,{1,}/g,",");	// replace ',' at the front of the string
		
		return pValue
	}
	// ------------------------------------------------------------------------------------------------- //
	function is_date(pValue)
	{
		re = /^(\d{4})\-(\d{1,2})\-(\d{1,2})$/;
		if(regs = pValue.match(re))
		{ 
			if(regs[3] < 1 || regs[3] > 31)
				return false;
			if(regs[2] < 1 || regs[2] > 12)
				return false; 
			if(regs[1] < 1902)
				return false; 
		} 
		else 
			return false;
			
		return true;
	}
	// ------------------------------------------------------------------------------------------------- //
	function is_number(pValue)
	{
		return /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(pValue)
	}
	// ------------------------------------------------------------------------------------------------- //
	// REPLACE all
	function replace_all(pStr, pKey, pReplace)
	{
	    while (pStr.indexOf(pKey) != -1)
	    {
	        pStr = pStr.replace(pKey,pReplace);
	    }
	    return pStr;
	}
	// ------------------------------------------------------------------------------------------------- //
	// DAYS in month
	function days_in_month(month,year)
	{
		var dd = new Date(year, month, 0);
		return dd.getDate();
	} 
	// ------------------------------------------------------------------------------------------------- //
	// STRPAD
	function str_pad(val)
	{
		return (!isNaN(val) && val.toString().length==1)?"0"+val:val;
	}