/**
 * ±â ¼³Á¤µÈ tabindex¿ÜÀÇ ¸ðµç °´Ã¼µéÀ» Å°º¸µå·Î Á¢±Ù ºÒ°¡´ÉÇÏ°Ô ¼³Á¤ ÇÑ´Ù.
 * @param   Object[]  objs           °Ë»çÇÒ °´Ã¼µéÀÇ ¹è¿­
 */
function setIndex(doc)
{
	try{
		if(!doc.all)
		{
			/**
			var oImg = doc.getElementsByTagName("IMG");
			var oTd = doc.getElementsByTagName("TD");
			var oSpan = doc.getElementsByTagName("SPAN");
			var oIfrmae = doc.getElementsByTagName("IFRAME");
			
			chkTabindex(oImg);
			chkTabindex(oTd);
			chkTabindex(oSpan);
			chkTabindex(oIfrmae);
			**/
			return true;
		}else{
			var objs = doc.all;
			var nCnt = objs.length;
			for(var i=0;i<nCnt;i++)
			{
				//tabindex¸¦ °Ë»çÇÏ¿© titleÀ» Á¤ÀÇÇÑ´Ù.
				if(objs[i].tagName=='AREA'  ||
				   objs[i].tagName=='MAP'   ||
				   objs[i].tagName=='IFRAME'||
				   objs[i].tagName=='IMG'   ||
				   objs[i].tagName=='SELECT')
				{
				
				}
				else if(objs[i].tagName=='IMG')
				{
					objs[i].title = objs[i].alt;
				}
				else 
				{
					if(!objs[i].tabIndex || objs[i].tabIndex <=0)
					{
						objs[i].tabIndex = -1;
					}else{
						setTitle(objs, objs[i]);
					}
				}
			}
			return true;
		}
	}catch(e){
		alert('Exception e : '+e);
		return false;
	}
}

/**
 * À½¼ºÁö¿ø ¼­ºñ½º¸¦ Áö¿øÇÏ±â À§ÇØ titleÀ» ¼³Á¤ÇÑ´Ù.
 * @param   Object[]  objs           °Ë»çÇÒ °´Ã¼µéÀÇ ¹è¿­
 * @param   Object    obj            °Ë»çÇÒ °´Ã¼
 */
function setTitle(objs, obj)
{
	var title = textToHtml(obj.getAttribute('title'));
	if(null==title||''==title)
	{
		var rowNm  = obj.getAttribute('rowNm');
		var colNm  = obj.getAttribute('colNm');
		var valNm  = obj.innerHTML;
		if(valNm==''||valNm==' '||valNm==null)
		{
			obj.title = '';
			obj.tabIndex = -1;
		}
		else
		{
			if(obj.tagName=='TD')
			{
				if(null==rowNm)
				{
					rowNm = '';
					rowNm = setRowName(obj, rowNm, 0);
					valNm = rowNm+' '+valNm;
				}else{
					valNm = rowNm+' '+valNm;
				}
				if(null==colNm)
				{
					colNm = '';
					colNm = getColNm(obj);
					valNm = colNm+' '+valNm;
				}else{
					valNm = colNm+' '+valNm;
				}
			}
			obj.title = textToHtml(rtrim(ltrim(valNm)));
		}
	}else{
		obj.title = textToHtml(title);
	}
}

//titleÀ» ¼³Á¤ÇÑ´Ù.
function chkTabindex(objs)
{
	var nCnt = objs.length;
	for(var i=0;i<nCnt;i++)
	{
		//tabindex¸¦ °Ë»çÇÏ¿© titleÀ» Á¤ÀÇÇÑ´Ù.
		if(!objs[i].tabIndex || objs[i].tabIndex <=0)
		{
			objs[i].tabIndex = -1;
		}else{
			alert("chktabindex="+objs[i]);
			setTitle(objs, objs[i]);
		}
	}
}

//row NameÀ» ¼³Á¤ÇÑ´Ù.
function setRowName(obj, rowNm, i)
{
	if(null!=obj){
		var tmp = obj.parentNode.childNodes(i);
		
		if(null==i)i = 0;
		
		if(null!=rowNm||''!=rowNm)rowNm = rowNm+' ';
		
		if(!tmp.tabIndex||tmp.tabIndex <= 0)
			rowNm = rowNm+tmp.innerHTML;
		
		if(tmp.rowSpan>=2)
			rowNm = setRowName(obj, rowNm, ++i);
	}
	return rowNm;
}

//¾µ¸ð¾ø´Â ¹®ÀÚ¸¦ Ä¡È¯ÇÑ´Ù.
function textToHtml(strText)
{
	if(null!=strText)
	{
	    strText=sReplace_str(strText, "&nbsp;", " ");
	    strText=sReplace_str(strText, "&quot;", "\"");
	    strText=sReplace_str(strText, "&#39;" , "\'");
	    strText=sReplace_str(strText, "&lt;"  , "<");
	    strText=sReplace_str(strText, "&gt;"  , ">");
		strText=sReplace_str(strText, "<br>"  , "\r\n");
		strText=sReplace_str(strText, "<BR>"  , "\r\n");
		strText=sReplace_str(strText, "<BR tabIndex=-1>"  , "\r\n");
	    strText=sReplace_str(strText, "&#63;" , "?");
    }
    return strText;
}

//strName¸¦ ¹è¿­·Î °¡Á®¿Â´Ù.
function getColList(objs,strName)
{
	var cols = new Array(getColCnt(objs));
	var objCnt = objs.length;
	j = 0;
	for(var i=0;i<objCnt;i++)
	{
		if(null!=objs[i].getAttribute(strName)&&objs[i].tagName=='TD')
		{
			cols[j++] = objs[i].innerHTML;
		}
	}
	
	return cols;
}

//colseq°¹¼ö¸¦ °¡Á®¿Â´Ù.
function getColCnt(objs)
{
	var j = 0;
	var objCnt = objs.length;
	for(var i=0;i<objCnt;i++)
	{
		if(null!=objs[i].getAttribute('colseq')&&objs[i].tagName=='TD')
		{
			j++;
		}
	}
	return j;
}

//ÇØ´ç Å×ÀÌºí ³»ÀÇ colseq·Î ¼³Á¤µÈ column NameÀ» °¡Á®¿Â´Ù.
function getColNm(obj)
{
	var colNm = '';
	var oTable = getTable(obj);
	if(null!=oTable&&oTable.tagName=='TABLE')
	{
		var nCnt = oTable.getElementsByTagName('TD').length; //table ³»ÀÇ td °´Ã¼¼ö
		var oTd = oTable.getElementsByTagName('TD');
		var colIdx = getColIdx(obj, 0);
		var tCnt = 0;
		
		for(var i=0;i<nCnt;i++)
		{
			if(null!=oTd[i].getAttribute('colseq')&&oTd[i].tagName=='TD')
			{
				if(colIdx==tCnt)
				{
					colNm = oTd[i].innerHTML;
				}
				tCnt++;
			}
		}
	}
	return colNm;
}

//ÇöÀçTDÀÇ À§Ä¡°ªÀ» °¡Á®¿Â´Ù.
function getColIdx(obj, colIdx)
{
	if(null==colIdx||''==colIdx)colIdx = 0;
	var temp = obj.previousSibling;
	if(null!=temp)
	{
		if(temp.tabIndex && temp.tabIndex > 0)
		{
			colIdx++;
			colIdx = getColIdx(temp, colIdx);
		}
	}
	return colIdx;
}

//ÇØ´çTDÀÇ TABLEÀ» °¡Á®¿Â´Ù.
function getTable(obj)
{
	if(obj.tagName=='TD')
	{
		var tempObj = obj.parentNode.parentNode.parentNode;
		if(tempObj.tagName=='TABLE')
		{
			return tempObj;
		}
	}
	return null;
}

