/**
 * Title		: UNICRO COMMON SCRIPT
 * Author		: mindeye
 * Update Date  : 2008.01.30
 * Description 	: À¯´ÏÅ©·Î¿¡¼­ °øÅëÀ¸·Î »ç¿ëÇÒ script ¸ðÀ½
 */

isIE = document.all;
topTagName = isIE ? "BODY" : "HTML";
layerPopup = "";
isMoving = false;
window.onresize=function() {
	if(typeof(layerInfo) != 'undefined')
		layerInfo.mask.chkSize();
}
var layerArray = new Array();
function layerPopupInit(e, id, titleId) {
  layerPopup = document.getElementById(id);
  if(!layerPopup) return;

  movingBar  = isIE ? event.srcElement : e.target;
  while (movingBar.id!=titleId && movingBar.tagName!=topTagName) {
    movingBar = isIE ? movingBar.parentElement : movingBar.parentNode;
  }
  if (movingBar.id == titleId) {
    offsetx   = isIE ? event.clientX : e.clientX;
    offsety   = isIE ? event.clientY : e.clientY;
    nowX      = parseInt(layerPopup.style.left);
    nowY      = parseInt(layerPopup.style.top);
    isMoving = true;
    document.onmousemove = layerPopupMove;
  }
}

function layerPopupMove(e) {
  if (!isMoving) return;
  layerPopup.style.left = isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
  layerPopup.style.top  = isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;
}
/*
document.onkeydown=function() {
	if(typeof(layerInfo) != 'undefined') {
		event.keyCode=0;
	}
}
*/
function makeLayer( layerName, width, height ) {
	//layerInfo = makeLayer.getInstance( layerName );
	document.body.focus();
	layerInfo = new LayerInfo( layerName );
	layerInfo.setSize( width, height );
	layerInfo.setScroll( "N" );
	layerInfo.setMask( "Y" );
	layerInfo.view();
	layerArray.push(layerInfo);
}

/* ±âÁ¸ ·¹ÀÌ¾î »èÁ¦(09.02.27)
function removeLayer( layerName ) {
    layerInfo.mask.chkSize();
    layerInfo.hide();
    layerArray.pop(layerInfo);
    layerInfo = layerArray[layerArray.length-1];
    document.body.scroll="yes";
}
*/
function removeLayer( layerName ) {

	for(var i=0;i<layerArray.length;i++) {
		layerInfo2 = layerArray[i];
		if(layerName == layerInfo2.layerName) {
			layerInfo2.mask.chkSize();
			layerInfo2.hide();
			layerArray.splice(i,1);
			layerInfo = layerArray[layerArray.length-1];
			if(document.body.clientHeight < document.body.scrollHeight)	
				document.body.scroll = "yes";
			break;
		}
	}

}

/* scrollbar Ç×»ó Çã¿ë(¹Ì´Ï¼¶) */
function removeLayer2( layerName ) {

	for(var i=0;i<layerArray.length;i++) {
		layerInfo2 = layerArray[i];
		if(layerName == layerInfo2.layerName) {
			layerInfo2.mask.chkSize();
			layerInfo2.hide();
			layerArray.splice(i,1);
			layerInfo = layerArray[layerArray.length-1];
			//document.body.scroll = "yes";
			break;
		}
	}

}
function LayerInfo( layerName ) {

	this.left = 0;
	this.top = 0;
	this.width = 0;
	this.height = 0;
	this.myPos = 'N';
	this.layerName = layerName;

	this.mask = new bodyMask();

	//var layerHTML = document.getElementById(layerName).innerHTML;
	//this.layerBox = document.createElement( "DIV" );
	//this.layerBox.id = "layerBox";

	this.layerBox = document.getElementById(layerName);
	with( this.layerBox.style ) {
    	display = "block";
    	left 	= this.left + "px";
    	top 	= this.top  + "px";
    	width  	= this.width + "px";
    	height 	= this.height + "px";
    	position= "absolute";
	}
	//this.layerBox.innerHTML = layerHTML;

	this.layerFrame = document.createElement( "iframe" );
	this.layerFrame.id = "layerFrame";
	this.layerFrame.src = "/webasp_common/blank.html";
	with( this.layerFrame.style ) {
		display	= "block";
    	left 	= this.left + "px";
    	top 	= this.top  + "px";
		width	= this.width + "px";
		height	= this.height + "px";
		position= "absolute";
	}
}
LayerInfo.prototype.setMask = function( mask ) {
	if( mask == "Y" )
		this.mask.show();
}
LayerInfo.prototype.setScroll = function( scroll ) {
	if( scroll == "N" ) {
		document.body.scroll='no';	
	}
}
LayerInfo.prototype.setPos = function( t, l ) {
   	this.layerBox.style.top = t;
   	this.layerBox.style.left = l;
   	this.layerFrame.style.top = t;
   	this.layerFrame.style.left = l;
	this.myPos = 'Y';
}
LayerInfo.prototype.setSize = function( w, h ) {
   	this.layerBox.style.width = w;
   	this.layerBox.style.height = h;
   	//this.layerFrame.style.width = w;
   	//this.layerFrame.style.height = h;
}
LayerInfo.prototype.view = function() {
	document.body.appendChild( this.layerFrame );
	document.body.appendChild( this.layerBox );
	if( this.myPos != 'Y' ) 
		this.setCenter();
}
LayerInfo.prototype.hide = function() {
	this.layerBox.style.display = "none";

	if( this.layerFrame.parentNode == null )
		return;
	this.layerFrame.parentNode.removeChild( this.layerFrame );
	this.mask.hide();	
}
LayerInfo.prototype.frameHide = function() {
    if(layerInfo.layerFrame.parentNode != null)
    	this.layerFrame.parentNode.removeChild( this.layerFrame );
}
LayerInfo.prototype.setCenter = function() {
   	try {
       	var x = 0;
       	var y = 0;
       	var hWd = parseInt( document.body.clientWidth / 2 + document.body.scrollLeft );
       	var hHt = parseInt( document.body.clientHeight / 2 + document.body.scrollTop );
       	var hBW = parseInt( this.layerBox.offsetWidth ) / 2;
       	var hBH = parseInt( this.layerBox.offsetHeight) / 2;

       	x = hWd - hBW;
       	if ( x < 0 )
           	x = 0;
       	y = hHt - hBH;
       	if ( y < 0 )
           	y = 0;

       	this.layerBox.style.left = x + "px";
       	this.layerBox.style.top  = y + "px";
       	this.layerFrame.style.left = x + "px";
       	this.layerFrame.style.top  = y + "px";
   	} catch( e ) { }
}

function bodyMask() {

  this.mainBox = document.createElement( "DIV" );
  this.mainBox.id = "mainBox";
	with( this.mainBox.style ) {
    	display = "block";
    	left = 0 + "px";
    	top = 0 + "px";
    	width  = 100 + "%";
    	height = 100 + "%";
    	backgroundImage = "url('/images/item/mask.gif')";
    	position = "absolute";
	}

	this.show = function() {
    	document.body.appendChild( this.mainBox );
		this.chkSize();
	}
	this.chkSize = function() { 
    	var d = document;
    	var w =
      	(window.innerWidth) ? window.innerWidth
    	: (d.documentElement && d.documentElement.clientWidth) ? d.documentElement.clientWidth
    	: d.body.clientWidth;
    	var h =
      	(window.innerHeight && window.scrollMaxY) ? window.innerHeight + window.scrollMaxY
    	: (d.body.scrollHeight > d.body.offsetHeight) ? d.body.scrollHeight
    	: d.body.offsetHeight;
	
    	this.setSize( w, h );
	}
	this.setSize = function( w, h ) {
    	this.mainBox.style.width = w;
    	this.mainBox.style.height = h;
	}
	this.hide = function() {
    	if ( this.mainBox.parentNode == null )
        	return;
    	this.mainBox.parentNode.removeChild( this.mainBox );
	}
}

/** ¿À´Ã³¯Â¥°¡ ±â°£¿¡ Æ÷ÇÔµÇ´Â Áö Ã¼Å© 
 *  param ex) "20080101"
 */
function dateTerm( sDate, eDate ) {
	var now = new Date();
	var year = now.getFullYear();
	var month = String(now.getMonth()+1);
	var day = String(now.getDate());
	var today;

	if( month.length == 1 ) 
		month = "0"+month;
	if( day.length == 1 ) 
		day = "0"+day;

	today = year+""+month+""+day;

	if(today >= sDate && today <= eDate) 
		return true;

	return false;

}

/** ¿À´Ã³¯Â¥°¡ ±â°£¿¡ Æ÷ÇÔµÇ´Â Áö Ã¼Å© (½Ã°£Æ÷ÇÔ)
 *  param ex) "200801012100"
 */
function dateTimeTerm( sDate, eDate ) {
	var now = new Date();
	var year = now.getFullYear();
	var month = String(now.getMonth()+1);
	var day = String(now.getDate());
	var hour = String(now.getHours());
	var min = String(now.getMinutes());
	var today;

	if( month.length == 1 ) 
		month = "0"+month;
	if( day.length == 1 ) 
		day = "0"+day;
	if( hour.length == 1 )
		hour = "0"+hour;
	if( min.length == 1 ) 
		min = "0"+min;

	today = year+""+month+""+day+""+hour+""+min;

	if(today >= sDate && today <= eDate) 
		return true;

	return false;

}

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.number = function() {
    return this.trim().replace(/[^0-9]/g,"");
}


