//form
var g_boxContainer = null;
var g_box = null;
var prevContents = null;

function showForm(contents)
{

	//폼 컨트롤 얻어오기
	var cloneContents = $(contents + 'Container');

	//박스 콘텐이너가 존재하지 않을때
	if (!$chk(g_boxContainer)){
		g_boxContainer = new Element('div',{
			'styles': {
				position: 'absolute',
				backgroundColor: 'black',
				top: 0, left: 0,
				width: '100%', height: Window.getScrollHeight(),
				opacity: 0.3, zIndex: 250

			}
		});
	}


	//g_box 가 존재하지 안을 때 생성
	if (!$chk(g_box)){
		g_box = new Element('div', {
			'styles': {
				position: 'absolute',
				backgroundColor: 'transparent',
				opacity: 1 ,
				//padding: '4px 10px 10px 10px',
				//border: '2px solid #ccc',
				zIndex: 500
			}
		});
	}

	//이전 콘텐츠 없고 현재 콘텐츠와 같이 않을때
	if (prevContents == null || prevContents != cloneContents){

		//이전 콘텐츠 삽입
		if (prevContents) {
			prevContents.setStyle('display', 'none');
			prevContents.injectInside($(document.body));
		}
		injectContentsToBox(cloneContents);
		
//		
//		var handles = $ES('.formContainer', g_box);
//		var dragOption = {
//			onStart: function(){
//				g_boxContainer.setStyle('height', Window.getScrollHeight());
//				g_boxContainer.injectInside($(document.body));
//			},
//			onComplete: function(){
//				g_boxContainer.remove();
//			}
//		};
//		if (handles.length > 0){
//			dragOption.handle = handles[0];
//			handles[0].setStyle('cursor', 'move');
//		}
		g_box.setStyle('cursor', 'move');
		g_box.makeDraggable();
		prevContents = cloneContents;

	}else{
		injectContentsToBox(prevContents);
	}

	g_boxContainer.setStyle('height', Window.getScrollHeight());
	g_boxContainer.injectInside($(document.body));
	g_box.injectInside($(document.body));
	window.addEvent("resize",function(){g_boxContainer.setStyle("height" , Window.getScrollHeight() + 'px' );});
	//select box 숨김
	$$('select.hide').each(function(sel){sel.setStyle('display','none');});
	
}
//폼 출력
function injectContentsToBox(contents){
	contents.setStyle('display', 'block');
	var contentsDim = contents.getSize();
	g_box.setStyles({
		top: (window.getHeight()/2) - (contentsDim.size.y / 2), left: (Window.getWidth() / 2) - (contentsDim.size.x / 2),
		//top: Window.getScrollTop() + 20, left: (Window.getWidth() / 2) - (contentsDim.size.x / 2),
		width: contentsDim.size.x, height: contentsDim.size.y
	});

	window.addEvent("resize" , function(){
		g_box.setStyles({
			top: (window.getHeight()/2) - (contentsDim.size.y / 2), left: (Window.getWidth() / 2) - (contentsDim.size.x / 2)
		});
	});

	contents.injectInside(g_box);
}

function injectContentsToBox(contents){
	contents.setStyle('display', 'block');
	var contentsDim = contents.getSize();
	g_box.setStyles({
		top: (window.getHeight()/2) - (contentsDim.size.y / 2), left: (Window.getWidth() / 2) - (contentsDim.size.x / 2),
		//top: Window.getScrollTop() + 20, left: (Window.getWidth() / 2) - (contentsDim.size.x / 2),
		width: contentsDim.size.x, height: contentsDim.size.y
	});

	window.addEvent("resize" , function(){
		g_box.setStyles({
			top: (window.getHeight()/2) - (contentsDim.size.y / 2), left: (Window.getWidth() / 2) - (contentsDim.size.x / 2)
		});
	});

	contents.injectInside(g_box);
}
//폼 숨김
function hideForm(){
	if( $defined(prevContents) ){
		prevContents.setStyle('display', 'none');
		prevContents.injectInside($(document.body));
		g_boxContainer.remove();
		g_box.remove();
		//select box 생성
		$$('select.hide').each(function(sel){sel.setStyle('display','');});
	}
}

function showFormWrite(contents,errCnt)
{
	document.getElementById("groupFormContainer").style.top = "0";
	//폼 컨트롤 얻어오기
	var cloneContents = $(contents + 'Container');
	//박스 콘텐이너가 존재하지 않을때
	if (!$chk(g_boxContainer)){
		g_boxContainer = new Element('div',{
			'styles': {
				position: 'absolute',
				backgroundColor: 'black',
				top: 0, left: 0,
				width: '100%', height: Window.getScrollHeight(),
				opacity: 0.3, zIndex: 250

			}
		});
	}


	//g_box 가 존재하지 안을 때 생성
	if (!$chk(g_box)){
		g_box = new Element('div', {
			'styles': {
				position: 'absolute',
				backgroundColor: 'transparent',
				opacity: 1 ,
				//padding: '4px 10px 10px 10px',
				//border: '2px solid #ccc',
				zIndex: 500
			}
		});
	}

	//이전 콘텐츠 없고 현재 콘텐츠와 같이 않을때
	if (prevContents == null || prevContents != cloneContents){

		//이전 콘텐츠 삽입
		if (prevContents) {
			prevContents.setStyle('display', 'none');
			prevContents.injectInside($(document.body));
		}
		injectContentsToBox(cloneContents);
		
//		
//		var handles = $ES('.formContainer', g_box);
//		var dragOption = {
//			onStart: function(){
//				g_boxContainer.setStyle('height', Window.getScrollHeight());
//				g_boxContainer.injectInside($(document.body));
//			},
//			onComplete: function(){
//				g_boxContainer.remove();
//			}
//		};
//		if (handles.length > 0){
//			dragOption.handle = handles[0];
//			handles[0].setStyle('cursor', 'move');
//		}
		g_box.setStyle('cursor', 'move');
		g_box.makeDraggable();
		prevContents = cloneContents;

	}else{
		injectContentsToBox(prevContents);
	}

	g_boxContainer.setStyle('height', Window.getScrollHeight());
	g_boxContainer.injectInside($(document.body));
	g_box.injectInside($(document.body));
	window.addEvent("resize",function(){g_boxContainer.setStyle("height" , Window.getScrollHeight() + 'px' );});
	//select box 숨김
	$$('select.hide').each(function(sel){sel.setStyle('display','none');});


	
		for (i=0; i < 15 ; i++ )
		{
			errId = "errmsg"+i;
			document.getElementById(errId).style.display = "none";
		}
		document.getElementById("errmsg1-1").style.display = "none";
	
	document.getElementById(errCnt).style.display = "";
	
	
}

function hideFormWrite(){
	if( $defined(prevContents) ){
		prevContents.setStyle('display', 'none');
		prevContents.injectInside($(document.body));
		g_boxContainer.remove();
		g_box.remove();
		//select box 생성
		$$('select.hide').each(function(sel){sel.setStyle('display','');});

		for (i=0; i < 15 ; i++ )
		{
			errId = "errmsg"+i;
			document.getElementById(errId).style.display = "none";
		}
		document.getElementById("errmsg1-1").style.display = "none";

	}

	document.getElementById("groupFormContainer").style.top = "0";
}
