/***
	Index Of Util Part
	1. Window Size & Scroll
	2. Select & Option Object
	3. CheckBox Object
***/


/***** 1. Window Size & Scroll ******/
/*
	moves the scroll in window specfied point
	<td id=abc >
	oneOfTdInTable = document.all("abc");
	moveScroll( oneOfTdInTable );

*/
function moveScroll( obj )
{
	po = 0;
	for( p=obj ; p.nodeName != "BODY" ; p=p.offsetParent )
	{
		po += p.offsetTop;
	}
	halfSize = document.body.offsetHeight/2;
	if ( po - halfSize > 0 )
		po = po - halfSize;
	else
		po = 0;
	window.scroll(0, po );
}
/*
*/
function getTop( obj )
{
	po = 0;
	for( p=obj ; p.nodeName != "BODY" ; p=p.offsetParent )
	{
		po += p.offsetTop;
	}
	return po
}

function getLeft( obj )
{
	po = 0;
	for( p=obj ; p.nodeName != "BODY" ; p=p.offsetParent )
	{
		po += p.offsetLeft;
	}
	return po
}
/***** End Of 1. Window Size & Scroll ******/

/***** 2. Select & Option Object ******/
/* default compareMethod => compareOptionByValue
 Usage : sortSelect( document.job.MY_SELECT , myCompare );
 		 sortSelect( document.job.MY_SELECT );
*/
function sortSelect( obj , compareMethod )
{
	if( compareMethod == null )
		compareMethod = compareOptionByValue;

	var arr = new Array();
	for( i=obj.options.length-1 ; i>=0 ; i=obj.options.length-1 )
	{
		arr[i] = obj.options[i];
		obj.remove(i);
	}
	arr.sort( compareMethod );
	for( var i=0 ; i<arr.length ; i++ )
		obj.add( arr[i] );
}

function compareOptionByValue( o1 , o2 )
{
	v1 = parseInt(o1.value);
	v2 = parseInt(o2.value);
	if( v1 > v2 )
		return 1;
	else if( v1 < v2 )
		return -1;
	else
		return 0;
}
/* sample compareMethod For table 
	function compareInt( a , b )
	{
		aa = a.all.item(sortKey);
		bb = b.all.item(sortKey);
		first = aa.childNodes[0].nodeValue*1;
		second = bb.childNodes[0].nodeValue*1;
		if( first > second )
			return descSort;
		else if( first < second )
			return descSort*-1;
		else
			return 0;
	}
*/

function selectOption( selectObj , optionObj )
{
	for( var i=0 ; i<selectObj.options.length ; i++ )
	{
		if( selectObj.options[i] == optionObj )
			selectObj.options[i].selected = true;
		else
			selectObj.options[i].selected = false;
	}
}

function selectOptionByIndex( selectObj , index )
{
	for( var i=0 ; i<selectObj.options.length ; i++ )
	{
		if( i == index )
			selectObj.options[i].selected = true;
		else
			selectObj.options[i].selected = false;
	}
}

function removeAllSelectOption( selectObj )
{
	for( var i=selectObj.length-1 ; i>=0 ; i-- )
		selectObj.remove(i);
}

function makeOption( selectObj , value , text )
{
	var opt = document.createElement("OPTION");
	selectObj.options.add(opt);
	opt.text = text;
	opt.value = value;
}

function existSameValueInOption(selectObj, value)
{
	for( var i=0 ; i<selectObj.length ; i++ )
	{
		if( selectObj.options[i].value == value )
			return true;
	}
	return false;
}
/***** End Of 2. Select & Option Object ******/

/***** 3. CheckBox Object ******/

/***** End Of 3. CheckBox Object ******/

/***** Etc ******/
function _openWindow(url,width,height,popupname){
	var w = width;
	var h = height;  
	var x = (screen.availWidth - w) / 2;
	var y = (screen.availHeight - h) / 2;
	return window.open(url, popupname===undefined?"":popupname, "toolbar=0, status=0, scrollbars=yes, location=0, menubar=0, width="+w+", height="+h+", left="+x+", top="+y);
}