// FrameWork 에서 사용되는 스크립트 정의 //
var wizSep = "[#wizSep#]" ; 
var wizSubmitForm ; 
var subFlashWidth = "1000" ; 
var subFlashHeight = "225" ; 

var WizSubmitFrame = Class.create();			
	WizSubmitFrame.prototype = {
		initialize: function() {
			//alert("test");
			var TempId	= Math.floor(Math.random() * 99999);
			var FrameId	= 'iframe' + TempId ; 
			var FormId	= 'form' + 	 TempId ; 
			var wizIFrame = document.createElement('DIV');
			 wizIFrame.innerHTML = '<iframe  style="display:none; width:0px; height:0px;" src="about:blank" id="'+FrameId+'" name="'+FrameId+'" ></iframe>';
			document.body.appendChild(wizIFrame);

			var wizForm = document.createElement('FORM') ;
			wizForm.name	= FormId ;
			wizForm.id		= FormId ; 
			wizForm.method	= "POST" ; 
			wizForm.target	= FrameId ; 
			wizIFrame.appendChild(wizForm) ; 

			this.wizFrame	= $(FrameId); 
			this.WizForm	= $(FormId)	; 
			this.FrameId	= FrameId ; 

			//$(wizIFrame).setStyle({
			//	'backgroundColor'	: '#F7F7F7',
			//	'fontSize'			:    '12px',
			//	'border'			:   '1px solid #CCCCCC',
			//	'width'				: '0px' , 
			//	'height'			: '0px'
			//	});
		} ,
		WizSubmit: function(sSourceForm, sAction,sTarget) {
			var oForm  =$(sSourceForm) ; 
			var cForm  = $(this.WizForm)  ; 

			cForm.innerHTML = "" ; 

			if ( sTarget == undefined) {
				var  Target = this.FrameId  }
			else {
				var  Target = sTarget 
			}
			cForm.action = sAction ; 
			cForm.target = Target ; 

			CreateFields() ; 
			cForm.submit() ; 


			function CreateFields() {
			var FieldType = "" ; 
				 for (var i=0; i < oForm.elements.length; i++ ) {
					 if (oForm.elements[i].FieldType != undefined) { 
						 FieldType = oForm.elements[i].FieldType ; 
						 var WizField = 	document.createElement('Input') ;
							WizField.type		= "text" ;
							WizField.name		=  oForm.elements[i].name ; 
							WizField.id			=  oForm.elements[i].id ; 
							WizField.value		=  oForm.elements[i].value ; 
							WizField.FieldType	= oForm.elements[i].FieldType ;  
							cForm.appendChild(WizField) ; 
							cForm.appendChild(document.createElement('BR')) ; 
							setInputField(cForm, $(WizField) ,FieldType) ;
					 }
				 }

				
			}; // CreateFields

			function setInputField(objForm, objElement,FieldType) {
			var elementType = objElement.type ; 
			if (FieldType == "E") { //html editor
					var oEditor = FCKeditorAPI.GetInstance(objElement.name) ;
					objElement.value = oEditor.GetXHTML() ; 
				}
				switch(elementType) {
					case "select-one" :
						for (var j=0; j < objElement.options.length ; j++ )
							{
								if ( objElement.options[j].selected)
								{
									objElement.options[j].value = objForm.name+'.'+objElement.name + wizSep+ objElement.options[j].value + wizSep + FieldType ; 
								}
							}
						break;
					case "hidden"	:
					case "text"		:
					case "textarea" :
					case "password" :
						objElement.value = objForm.name+'.'+objElement.name + wizSep+ objElement.value + wizSep + FieldType ; 
						break;
					case "radio"	:
					case "checkbox"	:
						break;
					default :
						break;
				} //switch


				return(true) ; 
			} // setInputField

		} // WizSubmit
	};  // WizForm.prototype


/**
*
*  AJAX IFRAME METHOD (AIM)
*  http://www.webtoolkit.info/
*
**/

AIM = {

	frame : function(c) {

		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
	},

	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},

	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}

}
// ---------------------------------
	function changeDivDisplay(divName) {
    //div 태그 표시를 토글한다. 
        var divObj = $(divName);
        if(divObj.style.display == "none") {
            divObj.style.display = "";
        } else {
            divObj.style.display = "none";
        }
    }
