var URLParams = new Object();

if(location.search)
{
	var tmp		= location.search.substr(1);
	var pair	= new Array();
	var tmp2	= new Array();
	
	if(pair = tmp.split('&'))
	{
		for(var i = 0; i < pair.length; i++)
		{
			if(!pair[i]) continue;

			tmp2 = pair[i].split('=');
			
			if(tmp2[0]) URLParams[tmp2[0]] = tmp2[1];
		}
	}
}

var page_url	= window.location.pathname + window.location.search.replace(/&refer=[^&]*/, '');

if(page_url.substr(page_url.length - 1, 1) == '&') page_url = page_url.substr(0, page_url.length - 1);

page_url = escape(page_url);

function doCancel()
{
	var frm = null;

	if(window.event && window.event.shiftKey) frm = window.open('about:blank');
	else frm = window;

	if(!frm) frm = window;

	frm.location = URLParams['refer'] ? unescape(URLParams['refer']) : _CurrentURL;
}

function openWin(url, name, windowStyle)
{
	newwin = window.open(url, name, windowStyle);
	
	newwin.focus();
}

function logout()
{
	if(confirm(lang_logout_confirm))
	{
		top.location = _PHP_SELF + '?act=logout';
	}
}

function reverseCheck(obj)
{
	if(!obj) return;
	
	if(!obj.length)
	{
		if(obj.disabled) return false;
		obj.checked = !obj.checked;
		
		highlight_row(obj);
	}
	else
	{
		for(i = 0; i < obj.length; i++)
		{
			if(obj[i].disabled) continue;
			if(obj[i].checked) obj[i].checked = false;
			else obj[i].checked = true;

			highlight_row(obj[i]);
		}
	}
}

function deleteSelect(attr)
//--------------------------------------------------------------------------------------
//descript: send the select element checkbox set to a delete url
//--------------------------------------------------------------------------------------
{
	var hasSelected		= false;
	var frmInfo			= document.frmInfo;
	var obj				= frmInfo.sid;
	
	if(!attr) var attr = '';
	
	if(obj)
	{
		if(typeof obj.length != 'undefined')
		{
			for(i = 0; i < obj.length; i++)
			{
				if(obj[i].checked)
				{
					hasSelected = true;
					break;
				}
			}
		}
		else hasSelected = obj.checked;
	}
	else hasSelected = false;
	
	if(!hasSelected)
	{
		alert(lang_nosel);
		return false;
	}

	if(confirm(lang_opt_confirm))
	{
		frmInfo.action = _CurrentURL + '&code=delete&refer=' + page_url + '&' + attr;
		frmInfo.submit();
	}
}

function deoxlsSelect(attr)
//--------------------------------------------------------------------------------------
//descript: send the select element checkbox set to a delete url
//--------------------------------------------------------------------------------------
{
	var hasSelected		= false;
	var frmInfo			= document.frmInfo;
	var obj				= frmInfo.sid;
	
	if(!attr) var attr = '';
	
	if(obj)
	{
		if(typeof obj.length != 'undefined')
		{
			for(i = 0; i < obj.length; i++)
			{
				if(obj[i].checked)
				{
					hasSelected = true;
					break;
				}
			}
		}
		else hasSelected = obj.checked;
	}
	else hasSelected = false;
	
	if(!hasSelected)
	{
		alert(lang_nosel);
		return false;
	}


		frmInfo.action = _CurrentURL + '&code=doxls&refer=' + page_url + '&' + attr;
		frmInfo.submit();
}

function editItem(id, attr, frm)
{
	if(!id) return false;
	if(!attr) attr = '';

	if(!frm)
	{
		if(window.event && window.event.shiftKey) frm = window.open('about:blank');
		else frm = window;
	}

	if(!frm) frm = window;

	frm.location = _CurrentURL + '&code=modify&ids=' + id + '&refer=' + page_url + '&' + attr;
}
function editItemcaca(id,attr ,article_id,frm)
{
	if(!id) return false;

	if(!frm)
	{
		if(window.event && window.event.shiftKey) frm = window.open('about:blank');
		else frm = window;
	}

	if(!frm) frm = window;

	frm.location = _CurrentURL + '&code=modify&ids=' + id  + '&refer='+attr+'&article_id='+article_id;
}
function editItemcacas(id,attr ,article_id,frm)
{
	if(!id) return false;

	if(!frm)
	{
		if(window.event && window.event.shiftKey) frm = window.open('about:blank');
		else frm = window;
	}

	if(!frm) frm = window;

	frm.location = _CurrentURL + '&code=category_modify&ids=' + id  + '&refer='+attr+'&article_id='+article_id;
}
function viewItem(id, attr, frm)
{
	if(!id) return false;
	if(!attr) attr = '';

	if(!frm)
	{
		if(window.event && window.event.shiftKey) frm = window.open('about:blank');
		else frm = window.open('about:blank');
	}

	if(!frm) frm = window.open('about:blank');

	frm.location = _CurrentURL + '&code=preview&ids=' + id + '&refer=' + page_url + '&' + attr;
}

function deleteItem(id, Caption, attr)
{
	if(!id) return false;
	if(!attr) attr = '';
	
	if(confirm(lang_delete_confirm))
	{
		window.location = _CurrentURL + '&code=delete&ids=' + id + '&refer=' + page_url+ '&' + attr;
	}
}
function deleteItemcaca(id,attr ,article_id)
{
	if(!id) return false;

	
	if(confirm(lang_delete_confirm))
	{
		window.location = _CurrentURL + '&code=delete&ids=' + id  + '&refer='+attr+'&article_id='+article_id;
	}
}
function deleteItemcacas(id,attr ,article_id)
{
	if(!id) return false;

	
	if(confirm(lang_delete_confirm))
	{
		window.location = _CurrentURL + '&code=category_delete&ids=' + id  + '&refer='+attr+'&article_id='+article_id;
	}
}
function frontdeleteItem(act,id, Caption, attr)
{
	if(!id) return false;
	if(!attr) attr = '';
	
	if(confirm(lang_delete_confirm))
	{
		window.location = 'admincp.php?act='+act+ '&code=delete&ids=' + id + '&refer=' + page_url+ '&' + attr;
	}
}

function myShowModalDialog(url, width, height)
{
	showModalDialog(url, '', 'resizable:no;scroll:no;status:no;center:yes;help:no;dialogWidth:' + width + ' px;dialogHeight:' + height + ' px');
}

function about()
{
	showModalDialog(_PHP_SELF + '?act=about', '', 'resizable:no;scroll:no;status:no;center:yes;help:no;dialogWidth:400 px;dialogHeight:223 px');
}
function doSomethingcaca(code, id, needConfirm, attr, frm)
{
	if(!attr) attr = '';

	var newwin = window.event && window.event.shiftKey ? true : false;
	
	if(needConfirm)
	{
		if(!confirm(lang_opt_confirm)) return;
	}

	if(!frm)
	{
		if(newwin) frm = window.open('about:blank');
		else frm = window;
	}

	if(!frm) frm = window;

	frm.location = _CurrentURL + '&code=' + code + '&ids=' + id + attr;
}
function doSomething(code, id, needConfirm, attr, frm)
{
	if(!attr) attr = '';

	var newwin = window.event && window.event.shiftKey ? true : false;
	
	if(needConfirm)
	{
		if(!confirm(lang_opt_confirm)) return;
	}

	if(!frm)
	{
		if(newwin) frm = window.open('about:blank');
		else frm = window;
	}

	if(!frm) frm = window;

	frm.location = _CurrentURL + '&code=' + code + '&ids=' + id + attr + '&refer=' + page_url;
}

function doSomething2(act, code, id, needConfirm, attr, frm)
{
	if(!attr) attr = '';

	var newwin = window.event && window.event.shiftKey ? true : false;
	
	if(needConfirm)
	{
		if(!confirm(lang_opt_confirm)) return;
	}

	if(!frm)
	{
		if(newwin) frm = window.open('about:blank');
		else frm = window;
	}

	if(!frm) frm = window;

	frm.location	= _PHP_SELF + '?act=' + act + '&code=' + code + '&ids=' + id + '&refer=' + page_url+ '&' + attr;
}

function doSomethings(code, needConfirm, attr)
{
	var hasSelected = false;
	var obj = frmInfo.sid;
	
	if(!attr) attr = '';

	if(obj.length)
	{
		for(i = 0; i < obj.length; i++)
		{
			if(obj[i].checked)
			{
				hasSelected = true;
				break;
			}
		}
	}
	else hasSelected = obj.checked;
	
	if(!hasSelected)
	{
		alert(lang_nosel);
		return false;
	}
	
	if(needConfirm)
	{
		if(!confirm(lang_opt_confirm)) return;
	}
	
	frmInfo.action = _CurrentURL + '&code=' + code + '&refer=' + page_url + '&' + attr;
	frmInfo.submit();
}

function in_array(val, arr)
{
	for(var i = 0; i < arr.length; i++)
	{
		if(val == arr[i]) return true;
	}
	
	return false;
}

function is_numeric(val)
{
	return /^[0-9\-]+$/.test(val);
}

function is_double(val)
{
	return /^[0-9\.\-]+$/.test(val);
}

function highlight_row(obj)
{
	var bool = obj.checked;
	
	if(obj.parentElement.tagName == 'TD')
	{
		if(bool)
		{
			obj.parentElement.parentElement.className = 'highlight_row';
		}
		else obj.parentElement.parentElement.className = 'list_content';
	}
}

function select_thisrow(obj)
{
	var tmp = null;
	
	if(window.event && window.event.srcElement.tagName == 'IMG'
		|| window.event && window.event.srcElement.tagName == 'INPUT') return;
	
	if(obj.cells[0].children[0].tagName == 'INPUT'
				&& obj.cells[0].children[0].type == 'checkbox')
	{
		tmp = obj.cells[0].children[0];
	}
	else if (obj.cells[1].children[0].tagName == 'INPUT'
				&& obj.cells[1].children[0].type == 'checkbox')
	{
		tmp = obj.cells[1].children[0];
	}

	tmp.checked = !tmp.checked;
	
	highlight_row(tmp);
}

function expandSub(obj, obj2)
{
	if(window.event && window.event.srcElement.tagName != 'TD') return;
	
	Detail(obj.children[0], obj2);
}
			
var old_classname	= 'list_content';
var mouse_over		= false;

function highlightrow2(obj, bool)
{
	if(mouse_over == bool) return;
	
	mouse_over = bool;
	
	if(obj.className == 'highlight_row') return;
	
	if(bool)
	{
		obj.className = 'highlight_row2';
	}
	else 
	{
		obj.className = 'list_content';
	}
}

function addFavorite(cleanup)
{
	newwin = window.open(_PHP_SELF + '?act=favorite&code=add&Url=' + escape(document.location.href) + (cleanup ? '&cleanup=1' : ''), 'favorite', 'Width: 800px; height: 400px; center:yes;status:yes;resizable:yes');
	newwin.focus();
}

function autoFocus()
{
	for(var i = 0; i < document.all.length; i++)
	{
		if(document.all[i].autofocus == 'true')
		{
			if(!document.all[i].disabled)
			{
				document.all[i].focus();
				break;
			}
		}
	}
}

function setOrderField()
{
	autoFocus();

	var obj			= document.all.orderby;
	
	if(!obj) return;
	
	if(!obj.length)
	{
		obj.innerHTML = "<a href='" + OrderURL + '&orderField=' + obj.orderfield + '&orderMode=' + (CurOrderMode == '1' ? 0 : 1) + "'><b>" + obj.innerHTML + "</b></a>";
		if(CurOrderField == obj.orderfield) obj.innerHTML += (CurOrderMode == '1' ? '↑' : '↓');
	}
	else
	{
		for(var i = 0; i < obj.length; i++)
		{
			obj[i].innerHTML = "<a href='" + OrderURL + '&orderField=' + obj[i].orderfield + '&orderMode=' + (CurOrderMode == '1' ? 0 : 1) + "'><b>" + obj[i].innerHTML + "</b></a>";
			if(CurOrderField == obj[i].orderfield) obj[i].innerHTML += (CurOrderMode == '1' ? '↑' : '↓');
		}
	}
	
	for(var i = 0; i < document.all.length; i++)
	{
		if(document.all[i].autofocus == 'true')
		{
			if(!document.all[i].disabled)
				document.all[i].focus();
			break;
		}
	}
}

window.onload = setOrderField;


//todo. �??????�度??��??
function checkValid(oForm)
{
	var oObj = oForm;
	
	for(var i = 0; i < oObj.length; i++)
	{
		if(oObj[i].tagName.toLowerCase() == 'input' || oObj[i].tagName.toLowerCase() == 'textarea' || oObj[i].tagName.toLowerCase() == 'file')
		{
			if(oObj[i].type.toLowerCase() == 'password' || oObj[i].type.toLowerCase() == 'text' || oObj[i].type.toLowerCase() == 'textarea' || oObj[i].type.toLowerCase() == 'file')
			{
				if(oObj[i].getAttribute("notnull") && !oObj[i].value)
				{
					alert(oObj[i].getAttribute("detail") + ' ' + lang_notnull);

					oObj[i].focus();
					
					return false;
				}
				
				if(oObj[i].value && oObj[i].getAttribute("isnumeric"))
				{
					if(!/^[0-9]+$/.test(oObj[i].value))
					{
						alert(oObj[i].getAttribute("detail") + ' ' + lang_neednumeric);
						
						oObj[i].focus();

						return false;
					}
				}
				
				if(oObj[i].value && oObj[i].getAttribute("isaccount"))
				{
					if(!/^[0-9A-Za-z]*$/.test(oObj[i].value))
					{
						alert(oObj[i].getAttribute("detail") + ' ' + lang_needaccount);
						
						oObj[i].focus();

						return false;
					}
				}

				if(oObj[i].value && oObj[i].getAttribute("isfloat"))
				{
					if(!/^[0-9\.]+$/.test(oObj[i].value))
					{
						alert(oObj[i].getAttribute("detail") + ' ' + lang_needfloat);
						
						oObj[i].focus();

						return false;
					}
				}

				if(oObj[i].value && oObj[i].getAttribute("isemail"))
				{
					if(!/^[0-9a-zA-Z\-\_]+@([0-9a-zA-Z\-\_]+\.)+([a-zA-Z]{2,3})$/.test(oObj[i].value))
					{
						alert(oObj[i].getAttribute("detail") + ' ' + lang_needemail);
						
						oObj[i].focus();

						return false;
					}
				}

				if(oObj[i].value && oObj[i].getAttribute("isdate"))
				{
					
					tmp=Date_Ex(oObj[i].value);
					if(tmp!='')
					{
						alert(oObj[i].getAttribute("detail") + ' ' + tmp);

						oObj[i].focus();
						
						return false;
					}
				}
				
				if(oObj[i].minlength && strlen(oObj[i].value) < parseInt(oObj[i].minlength))
				{
					alert(oObj[i].getAttribute("detail") + ' ' + lang_minlength + oObj[i].minlength);
					
					oObj[i].focus();
					
					return false;
				}
				
				if(oObj[i].maxlength && strlen(oObj[i].value) > parseInt(oObj[i].maxlength))
				{
					alert(oObj[i].getAttribute("detail") + ' ' + lang_maxlength + oObj[i].maxlength);
					
					oObj[i].focus();
					
					return false;
				}
				
				if(oObj[i].allowext && oObj[i].allowext.length > 1 && oObj[i].value)
				{
					var tmp = oObj[i].allowext.split(',');
					
				  if(!in_array(getFileExt(oObj[i].value.toLowerCase()), tmp))
					{
						alert(oObj[i].getAttribute("detail") + ' ' + lang_err_fileformat.replace(/%s/i, oObj[i].allowext));

						oObj[i].focus();
						
						return false;
					}
				}
			}
			else if(oObj[i].type.toLowerCase() == 'checkbox' || oObj[i].type.toLowerCase() == 'radio')
			{
				if(oObj[i].getAttribute("notnull"))
				{
					var tmp = new Object();
					eval("tmp = document." + (oForm.id ? oForm.id : oForm.name) + '.' + (oObj[i].id ? oObj[i].id : oObj[i].name));
					
					var found = false;
					
					for(var j = 0; j < tmp.length; j++)
					{
						if(tmp[j].checked)
						{
							found = true;
							break;
						}
					}
					
					if(!found)
					{
						alert(oObj[i].getAttribute("detail") + ' ' + lang_notnull);
						
						oObj[i].focus();
						
						return false;
					}
				}
			}
		}
		else if(oObj[i].tagName.toLowerCase() == 'select')
		{
			if(oObj[i].getAttribute("notnull"))
			{
				var tmp = oObj[i];
				
				var found = false;
				
				if(tmp.selectedIndex != -1 && tmp.options[tmp.selectedIndex].value)
				{
					found = true;
				}
				
				if(!found)
				{
					alert(oObj[i].getAttribute("detail") + ' ' + lang_notnull);
	
					oObj[i].focus();
					
					return false;
				}
			}
		}
	}
	
	return true;
}

var prevObj = null;

function highlightDynamicRow()
{
	if(!window.event) return;
	obj = window.event.srcElement;
	
	while(obj.tagName.toLowerCase() != 'tr' || obj.parentElement.parentElement.id == '')
	{
		obj = obj.parentElement;
	}
	
	if(prevObj) prevObj.style.backgroundColor = normalColor;
	
	obj.style.backgroundColor = highlightColor;
	
	prevObj = obj;
}

function addRow(id, cellArr)
{
	var dynamicTable = document.getElementById(id);
	
	if(!dynamicTable) return;
	
	var newRow = dynamicTable.insertRow();
	
	newRow.onclick = highlightDynamicRow;
	newRow.style.backgroundColor = normalColor;
	
	for(var i = 0; i < cellArr.length; i++)
	{
		var cell = newRow.insertCell();
		
		cell.style.textAlign= 'center';
		cell.innerHTML	= cellArr[i];
	}
}

function deleteRow(id)
{
	var obj = document.getElementById(id);
	
	if(!obj || !prevObj) return;
	
	if(prevObj.parentElement && prevObj.parentElement.parentElement == obj)
	{
		obj.deleteRow(prevObj.rowIndex);
	}
}

function autoSelected(obj, defVal)
{
	if(!obj) return;
	
	if((typeof defVal).toLowerCase() != 'object')
	{
		var tmp = defVal;
		
		defVal = new Array();
		defVal[0] = tmp;
	}
	
	if(obj.tagName)
	{
		switch(obj.tagName.toLowerCase())
		{
			case 'select':
					for(var i = 0; i < obj.length; i++)
					{
						if(in_array(obj.options[i].value, defVal))
						{
							obj.options[i].selected = true;
						}
					}
			case 'input':
					if(obj.type.toLowerCase() == 'checkbox' || obj.type.toLowerCase() == 'radio')
					{
						if(in_array(obj.value, defVal))
						{
							obj.checked = true;
						}
					}
					break;
		}
	}
	else
	{
		for(var i = 0; i < obj.length; i++)
		{
			if(obj[i].tagName.toLowerCase() == 'select')
			{
				for(var j = 0; j < obj[i].length; j++)
				{
					if(in_array(obj[i].options[j].value, defVal))
					{
						obj[i].options[j].selected = true;
					}
				}
			}
			else if(obj[i].tagName.toLowerCase() == 'input')
			{
				if(in_array(obj[i].value, defVal))
				{
					obj[i].checked = true;
				}
			}
		}
	}
}

function selectAll(obj)
{
	if(!obj || !obj.length) return;
	
	for(var i = 0; i < obj.length; i++)
	{
		if(obj[i].tagName.toLowerCase() == 'input') obj[i].checked = true;
		else obj[i].selected = true;
	}
}

//util function
	var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	var base64DecodeChars = new Array(
		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
		52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
		-1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
		15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
		-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
		41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
	
	function base64encode(str) {
		var out, i, len;
		var c1, c2, c3;
	
		len = str.length;
		i = 0;
		out = "";
		while(i < len) {
		c1 = str.charCodeAt(i++) & 0xff;
		if(i == len)
		{
			out += base64EncodeChars.charAt(c1 >> 2);
			out += base64EncodeChars.charAt((c1 & 0x3) << 4);
			out += "==";
			break;
		}
		c2 = str.charCodeAt(i++);
		if(i == len)
		{
			out += base64EncodeChars.charAt(c1 >> 2);
			out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
			out += base64EncodeChars.charAt((c2 & 0xF) << 2);
			out += "=";
			break;
		}
		c3 = str.charCodeAt(i++);
		out += base64EncodeChars.charAt(c1 >> 2);
		out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
		out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
		out += base64EncodeChars.charAt(c3 & 0x3F);
		}
		return out;
	}
	
	function strlen(str)
	{
		len = 0;
		
		for(var i = 0; i < str.length; i++)
		{
			if(str.charCodeAt(i) > 0xA0) len += 2;
			else len++;
		}
		
		return len;
	}
	
	function base64decode(str) {
		var c1, c2, c3, c4;
		var i, len, out;
	
		len = str.length;
		i = 0;
		out = "";
		while(i < len) {
		/* c1 */
		do {
			c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
		} while(i < len && c1 == -1);
		if(c1 == -1)
			break;
	
		/* c2 */
		do {
			c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
		} while(i < len && c2 == -1);
		if(c2 == -1)
			break;
	
		out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
	
		/* c3 */
		do {
			c3 = str.charCodeAt(i++) & 0xff;
			if(c3 == 61)
			return out;
			c3 = base64DecodeChars[c3];
		} while(i < len && c3 == -1);
		if(c3 == -1)
			break;
	
		out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
	
		/* c4 */
		do {
			c4 = str.charCodeAt(i++) & 0xff;
			if(c4 == 61)
			return out;
			c4 = base64DecodeChars[c4];
		} while(i < len && c4 == -1);
		if(c4 == -1)
			break;
		out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
		}
		return out;
	}
	
	function utf16to8(str) {
		var out, i, len, c;
	
		out = "";
		len = str.length;
		for(i = 0; i < len; i++) {
		c = str.charCodeAt(i);
		if ((c >= 0x0001) && (c <= 0x007F)) {
			out += str.charAt(i);
		} else if (c > 0x07FF) {
			out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
			out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
			out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
		} else {
			out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
			out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
		}
		}
		return out;
	}
	
	function utf8to16(str) {
		var out, i, len, c;
		var char2, char3;
	
		out = "";
		len = str.length;
		i = 0;
		while(i < len) {
		c = str.charCodeAt(i++);
		switch(c >> 4)
		{ 
		  case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
			// 0xxxxxxx
			out += str.charAt(i-1);
			break;
		  case 12: case 13:
			// 110x xxxx   10xx xxxx
			char2 = str.charCodeAt(i++);
			out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
			break;
		  case 14:
			// 1110 xxxx  10xx xxxx  10xx xxxx
			char2 = str.charCodeAt(i++);
			char3 = str.charCodeAt(i++);
			out += String.fromCharCode(((c & 0x0F) << 12) |
						   ((char2 & 0x3F) << 6) |
						   ((char3 & 0x3F) << 0));
			break;
		}
		}
	
		return out;
	}

function Date_Ex(value1)
  {
 var strDate = value1;
 if (strDate.length == 0)
  return '請先輸入日期';

 
 var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/;  
 var r = strDate.match(reg);

 if (r != null)   
   strDate = strDate + " 00:00:00";
 
 reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})/;
 r = strDate.match(reg);
 if (r == null)
 {
  
  return "日期格式有誤，格式應為：2007-12-01 或 2007/12/01";
 }

 var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
 
 if (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()== r[7])
 {
  return '';
 }
 else
 {
  return "日期或時間超出有效範圍！";
 }
 return '';
  }


function autoTooltip()
{
	
}

function getFileExt(fileName)
{
	if(fileName.lastIndexOf('.') == -1) return '';

	return fileName.substr(fileName.lastIndexOf('.'), fileName.length);
}

function showh(showid,objid,delid)
{
	//alert(delid);
	document.getElementById(delid).style.display='none';
	returnstr='"'+showid+'","'+objid+'","'+delid+'",this.value';
	selectid='h'+objid;
	document.getElementById(showid).innerHTML=
	"<select size=12 id="+selectid+" onchange='returnvalue("+returnstr+")'><option value=x>[時]關閉X</option><option value=00>00</option><option value=01>01</option><option value=02>02</option><option value=03>03</option><option value=04>04</option><option value=05>05</option><option value=06>06</option><option value=07>07</option><option value=08>08</option><option value=09>09</option><option value=10>10</option><option value=11>11</option><option value=12>12</option><option value=13>13</option><option value=14>14</option><option value=15>15</option><option value=16>16</option><option value=17>17</option><option value=18>18</option><option value=19>19</option><option value=20>20</option><option value=21>21</option><option value=22>22</option><option value=23>23</option></select>";
	
}

function showi(showid,objid,delid)
{
	//alert(delid);
	document.getElementById(delid).style.display='none';
	returnstr='"'+showid+'","'+objid+'","'+delid+'",this.value';
	selectid='i'+objid;
	document.getElementById(showid).innerHTML=
	"<select size=12 id="+selectid+" onchange='returnvalue("+returnstr+")'><option value=x>[分]關閉X)</option><option value=00>00</option><option value=01>01</option><option value=02>02</option><option value=03>03</option><option value=04>04</option><option value=05>05</option><option value=06>06</option><option value=07>07</option><option value=08>08</option><option value=09>09</option><option value=10>10</option><option value=11>11</option><option value=12>12</option><option value=13>13</option><option value=14>14</option><option value=15>15</option><option value=16>16</option><option value=17>17</option><option value=18>18</option><option value=19>19</option><option value=20>20</option><option value=21>21</option><option value=22>22</option><option value=23>23</option><option value=24>24</option><option value=25>25</option><option value=26>26</option><option value=27>27</option><option value=28>28</option><option value=29>29</option><option value=30>30</option><option value=31>31</option><option value=32>32</option><option value=33>33</option><option value=34>34</option><option value=35>35</option><option value=36>36</option><option value=37>37</option><option value=38>38</option><option value=39>39</option><option value=40>40</option><option value=41>41</option><option value=42>42</option><option value=43>43</option><option value=44>44</option><option value=45>45</option><option value=46>46</option><option value=47>47</option><option value=48>48</option><option value=49>49</option><option value=50>50</option><option value=51>51</option><option value=52>52</option><option value=53>53</option><option value=54>54</option><option value=55>55</option><option value=56>56</option><option value=57>57</option><option value=58>58</option><option value=59>59</option></select>";
	
}



function returnvalue(showid,objid,delid,v)
{
	 
	if(v!='x') 
	   document.getElementById(objid).value=v;
	if(delid!='')
	  document.getElementById(delid).style.display='';
	if(showid!='')
	  document.getElementById(showid).innerHTML='';
}
function getFileName(fileName)
{
	if(fileName.lastIndexOf('/') == -1&&fileName.lastIndexOf('\\') == -1) return '';
    lastslash=fileName.lastIndexOf('\\')?fileName.lastIndexOf('\\'):fileName.lastIndexOf('/');
	return fileName.substr(lastslash+1, fileName.length);
}
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}				
	