function ShowItem(img, itemId, str1, str2){
	if(document.getElementById(itemId).style.display == "none"){
		img.src = img.src.replace(str1,str2);
		document.getElementById(itemId).style.display = "inline";
	}
	else{
		img.src = img.src.replace(str2,str1);
		document.getElementById(itemId).style.display = "none";
	}
}

function onlydigits(str)
{
	var re = new RegExp("([0-9]+)");
    return (re.exec(str)!=null && RegExp.$1==str);
}

function rightTrim( strValue ) 
{
	var objRegExp = /^([\w\W]*)(\b\s*)$/;

    if(objRegExp.test(strValue)) 
    {
       strValue = strValue.replace(objRegExp, '$1');
    }
	return strValue;
}

function leftTrim( strValue ) 
{
	var objRegExp = /^(\s*)(\b[\w\W]*)$/;

    if(objRegExp.test(strValue)) 
    {
       strValue = strValue.replace(objRegExp, '$2');
    }

	return strValue;
}

function trim(str)
{
    return str.replace(/^\s+/,"").replace(/\s+$/,"");
}

function changeImage(img, IsOver){
	img.src = img.src.replace(IsOver?/_still/:/_over/,IsOver?'_over':'_still');
}

function ChangeImgCal(img, mode){
	if(mode == 1){ // up
		img.src = img.src.replace(/_calendar_down/,'_calendar');
	}
	else if(mode == 2){ //out
		img.src = img.src.replace(/_calendar_down/,'_calendar');
	}
	else{ // mode == 3 : down
		img.src = img.src.replace(/_calendar/,'_calendar_down');
	}
}

function OpenCalendar(img){    
	var txt = img.parentNode.firstChild;
	popUpCalendar(img, txt,'dd/mm/yyyy','../Images/');
}

function OpenCalendar(img, index){    
	var txt = img.parentNode.children[index];
	popUpCalendar(img, txt,'dd/mm/yyyy','../Images/');
}

////////////////
//in the set of panels hname :  turn on panel i, turn off panel j
function showmachine(i, j, hname)
{
	var iname = TopTab[i];
	var jname = TopTab[j];
	document.all[iname+'txt'].className = 'tdontab';
	document.all[iname+'_layer'].style.zIndex = 0;
	document.all[iname+'_layer'].style.visibility = 'visible';
	//document.all[iname+'_layer'].style.display = 'inline-block';
	document.all[jname+'txt'].className = 'tdofftab';
	document.all[jname+'_layer'].style.zIndex = -1;
	document.all[jname+'_layer'].style.visibility = 'hidden';
	//document.all[jname+'_layer'].style.display = 'none';
	var oTab = document.getElementById(hname).all.tags("IMG");
	if (i==0) {
		oTab.item(j*2).src = oTab.item(j*2).src.replace(/ontab_left/,"offtab_left");
		oTab.item(j*2+1).src = oTab.item(j*2+1).src.replace(/ontab_right/,"offtab_right");					
		oTab.item(j*2-1).src = oTab.item(j*2-1).src.replace(/onofftab_right/,"offtab_right");					
		oTab.item(i*2).src = oTab.item(i*2).src.replace(/offtab_leftfirst/,"ontab_leftfirst");
		oTab.item(i*2+1).src = oTab.item(i*2+1).src.replace(/offtab_right/,"ontab_right");
	}
	else if (j==0){
		oTab.item(j*2).src = oTab.item(j*2).src.replace(/ontab_leftfirst/,"offtab_leftfirst");
		oTab.item(j*2+1).src = oTab.item(j*2+1).src.replace(/ontab_right/,"offtab_right");					
		oTab.item(i*2).src = oTab.item(i*2).src.replace(/offtab_left/,"ontab_left");
		oTab.item(i*2+1).src = oTab.item(i*2+1).src.replace(/offtab_right/,"ontab_right");
		oTab.item(i*2-1).src = oTab.item(i*2-1).src.replace(/offtab_right/,"onofftab_right");
	}
	else{
		oTab.item(j*2).src = oTab.item(j*2).src.replace(/ontab_left/,'offtab_left');
		oTab.item(j*2+1).src = oTab.item(j*2+1).src.replace(/ontab_right/,'offtab_right');					
		oTab.item(j*2-1).src = oTab.item(j*2-1).src.replace(/onofftab_right/,'offtab_right');					
		oTab.item(i*2).src = oTab.item(i*2).src.replace(/offtab_left/,'ontab_left');
		oTab.item(i*2+1).src = oTab.item(i*2+1).src.replace(/offtab_right/,'ontab_right');
		oTab.item(i*2-1).src = oTab.item(i*2-1).src.replace(/offtab_right/,'onofftab_right');
	}
}
var preTab=0;

function ShowTab(i, header)
{
	if (i == preTab) return;
	showmachine(i,preTab,header);
	preTab=i;
}

function InitTab(hname)
{
	for (var loop=1;loop<TopTab.length ;loop++)
		showmachine(0, loop, hname);
}

function posInit(hname)
{
	preTab = 0;
	var header = document.getElementById(hname); 
	header.style.position = 'absolute';
	
	var top = header.offsetTop + header.offsetHeight - 1;
	for (var loop=0;loop<TopTab.length;loop++)
	{
		document.getElementById(TopTab[loop]+'_layer').style.position='absolute';
		document.getElementById(TopTab[loop]+'_layer').style.top = top;
		document.getElementById(TopTab[loop]+'_layer').style.left = header.offsetLeft;  
		document.getElementById(TopTab[loop]+'_layer').style.visibility = (loop==0)?'visible':'hidden';
		
	}
}
function tabinit()
{
	posInit('tblHeader');
	InitTab('tblHeader');
}

//Dung cho Open Image
var fBrw=(navigator.userAgent.indexOf('MSIE')!= -1 && navigator.userAgent.indexOf('Windows')!= -1);
function openImage(vLink, vHeight, vWidth)
{
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;

	if (sLink == '')
	{
		return false;
	}

	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" alt="', (fBrw) ? '&#272;&#243;ng l&#7841;i' : 'Dong lai', '" border=0></a>');
	newwin.document.writeln('</body>');

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}
function isFF(){
return(navigator.userAgent.match(/firefox/i))?true:false
}
getText=function(a){
return (!isFF())?a.innerText:a.textContent
}

