document.attachEvent ("onreadystatechange", function() {
   if (document.readyState=="complete")   {
      if (window.cbOnBeforeLoad) window.cbOnBeforeLoad();
   }
})

/**
 * @type   : function
 * @access : public
 * @desc   : 
 * @author : tkyushin
 */

function actSubmitValidate(oform, action, target) {
  if (target) oform.target = target;
  if (action) oform.action = action;
  if (!oform.method) oform.method = "post";
  if (oform.fireSubmit) oform.fireSubmit();
  else oform.submit();
  
}

function actCancel(oform, action, target) {
  if (target) oform.target = target;
  if (action) oform.action = action;
  if (!oform.method) oform.method = "post";
	oform.reset();
  oform.submit();
}

function actSubmit(oform, action, target) {
  if (target) oform.target = target;
  if (action) oform.action = action;
  if (!oform.method) oform.method = "post";
  oform.submit();
}

function xjosiate(oTag) {
  _xjosiage(oTag.getElementsByTagName("INPUT"));
  _xjosiage(oTag.getElementsByTagName("SELECT"));
  _xjosiage(oTag.getElementsByTagName("TEXTAREA"));
}

function _xjosiage(oTags) {
  for (var idx=0; idx < oTags.length; idx ++) {
    if (!window.xGetOption("X_SUPPORT_HIDDEN_TYPE") && oTags[idx].type == 'hidden') continue;
    oTags[idx].initialize = em_initialize;
    oTags[idx].initialize(oTags[idx].form);
  }
}

function findParentTag(oTag, tagName) {
  while (oTag && oTag.tagName != "BODY") {
    if (oTag.tagName == tagName) return oTag;
    oTag = oTag.parentNode;
  }
  return null;
}

function findTagByName(oTag, tagName, name) {
	var tags = oTag.getElementsByTagName(tagName);
	for (var idx=0; idx<tags.length; idx++) {
		if (tags[idx].name == name) return tags[idx];
	}
  return null;
}

function flipCheckBox(oCheck) {
	if (!oCheck) return;
	if (oCheck.tagName && oCheck.tagName=="INPUT" && oCheck.type=="checkbox") {
		oCheck.checked = oCheck.checked ? false : true;	
	} else if (oCheck.length && oCheck.length > 1) {
		var until = oCheck.length;
		for (var idx=0; idx < until; idx++) {
			oCheck[idx].checked = oCheck[idx].checked ? false : true;	
		}		
	}
}

function getCheckedOnly(inputs) {
	var result = new Array();
	if (inputs && inputs.tagName == "INPUT" && inputs.checked) result[0] = inputs;
	else if (inputs && inputs.length && inputs.length > 0 ) {
		var until = inputs.length;
		for (var idx=0; idx<until; idx++) {
			if (inputs[idx].tagName == "INPUT" && inputs[idx].checked) result[result.length] = inputs[idx];
		}
	}
	return result;
}


function cloneRow(sourceRowId, targetTableId, xjosEnable) {
	var oTR = document.getElementById(sourceRowId);
	var tTable = document.getElementById(targetTableId);
	var tTbody = tTable.tBodies[0];
	var oNewTR = oTR.cloneNode(true);
	oNewTR.id = "";
	tTbody.appendChild(oNewTR);
	if (xjosEnable == true) xjosiate(oNewTR);
	return oNewTR;
}

function getLength(inputs) {
	return (!inputs || !inputs.length) ?  0 : inputs.length;
}


function clearInput(oInput) {
	if (oInput.tagName == "FORM") {
		var until = oInput.elements.length;
		for (var idx=0; idx < until; idx++) {
			clearInput(oInput.elements[idx]);
		}
	} else if (oInput.tagName == "INPUT" ||  oInput.tagName == "SELECT" || oInput.tagName == "TEXTAREA") {
		  switch (oInput.type) {
		    case "text" :  case "hidden" : case "password" : case "textarea" : 
  			case "select-one" : case "select-multiple" :		    
		      oInput.value = "";
		    break;
		    case "radio" :  case "checkbox" :
		      oInput.checked = false;
		    break;		
		  }
	} 
}

function removeOptions(oSelect) {
	if (oSelect.tagName != "SELECT") return;
		var until = oSelect.options.length;
  	for (var idx=0; idx < until ; idx++) oSelect.remove(0);	
}

/************************************************************
  이름 : openWin (window.open)
 ******************************************
  권한 처리 및 인증 처리를 위해 popup window 용 공통 함수를 적용
  parameter는 
	url
	url, width, height
	url, target, width, height
	url, target, width, height, session check flag	
	url, target, width, height, left, top	
	경우로 받을 수 있다.
  return
	window.open()의 return값	
 ***********************************************************/
 function openWin(){
 	var args=openWin.arguments ;
 	var url, target, features , width, height;
 	url = args[0] ;
 	target = "popDefault" ;
 	width = "400px" ;
 	height = "435px" ;
 	features = "resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no," ;
 	
 	switch (args.length.toString()){
 		case '3' :
			features += "titlebar=no,left=" + Number(screen.width/2-Number(args[2])/2) +",top=" +  Number(screen.height/2-Number(args[3])/2) + "," ;
 			features += "width=" + args[1] + ",height=" + args[2] ;		
 			break ;
 		case '4' :
 			target = args[1] ;
			features += "titlebar=no,left=" + Number(screen.width/2-Number(args[2])/2) +",top=" +  Number(screen.height/2-Number(args[3])/2) + "," ;
 			features += "width=" + args[2] + ",height=" + args[3] ;
 			break ;
 		case '5' :
 			target = args[1] ;
 			features += "width=" + args[2] + ",height=" + args[3] ;
 			break ;
 		case '6' :
 			target = args[1] ;
			features += "titlebar=no,left=" + Number(screen.width/2-Number(args[2])/2) +",top=" +  Number(screen.height/2-Number(args[3])/2) + "," ;
 			features += "width=" + args[2] + ",height=" + args[3] ;		
 			break ;
 		default :
 			features += "width=" + width + ",height=" + height ;
 			break ;
 	}
 	return window.open(url,target,features) ;
 }
 
/*===========================================================================*/
// return first object value about pObjName's paramemr
/*===========================================================================*/
function getObjectFirst(pObjName)	{
	return document.getElementsByName(pObjName)[0];
}

/*===========================================================================*/
// return first object value about pObjName's paramemr
/*===========================================================================*/
function getObjectList(pObjName, pDoc)	{

	var tObjDoc = document;
	if (pDoc != null)	{
		tObjDoc = pDoc;
	}

	return tObjDoc.getElementsByName(pObjName);

}
 
