//--------------------------------------
// $Id$
//--------------------------------------

	// busy flag
	var g_onButton_flag = false;
	// onLoad flag
	var g_onLoad_Flag = false;
	// onUnLoad flag
	var g_onUnLoad_Flag = false;

	// submit function
	// form name,action , method, view , error view, alert message, dlg type, current row no, key id, add param add function, ajax_id )
	//function OnSubmitView( obj_formName, obj_action, obj_method, obj_view, obj_errorview, obj_msg, obj_dlg, obj_row, obj_id, obj_actionParam, obj_addinFunction, obj_ajax_id ){
	//	OnSubmitView( obj_formName, obj_action, obj_method, obj_view, obj_errorview, obj_msg, obj_dlg, obj_row, obj_id, obj_actionParam, obj_addinFunction, obj_ajax_id, '', '' );
	//}

	// submit function
	// form name,action , method, view , error view, alert message, dlg type, current row no, key id, add param add function, ajax_id, ajax_befor_func, ajax_after_func , window.open name,  window.open param )
	function OnSubmitView( obj_formName, obj_action, obj_method, obj_view, obj_errorview, obj_msg, obj_dlg, obj_row, obj_id, obj_actionParam, obj_addinFunction, obj_ajax_id, obj_ajax_befor_func, obj_ajax_after_func, obj_winName, obj_winParam ){

		//alert("debug:" + obj_winName);

		// check onLoad
		if(  g_onLoad_Flag == false ){
			//alert("Not End View");
			return false;
		}
		// duble push button check
		if( g_onButton_flag == true ){
			//alert("Busy now...Please wait");
			return false;
		}

		// AddInFunction check
		if( obj_addinFunction == "true" ){

			var objMethod = obj_method;
			if( objMethod == '' ){
				objMethod = eval('document.' + obj_formName + '.Method.value');
			}
			var ret = eval('AddInFunction("' + objMethod + '","' + obj_actionParam + '")');
			if( ret == false ){
				return false;
			}

		}

		// continue flag
		var f = 1;

		// button check flag
		var onButton_check_flag = true;

		// dlg type check
		if (obj_msg != ''){
			if( obj_dlg == "confirm" ){
				f = confirm(obj_msg);
			} else if( obj_dlg == "alert_nocheck" ){
				f = confirm(obj_msg);
				onButton_check_flag = false;
			} else if( obj_dlg == "alert" ){
				alert(obj_Msg);
				f = 1;
			} else if( obj_dlg == "alert_nocheck" ){
				alert(obj_Msg);
				f = 1;
				onButton_check_flag = false;
			} else if( obj_dlg == "checkonly" ){
				f = 1;
			} else if( obj_dlg == "checkonly_nocheck" ){
				f = 1;
				onButton_check_flag = false;
			} else {
				alert(obj_msg);
				f = 1;
			}
		}

		// continue
		if(f == 1) {

			if (obj_action != ''){

				//replace ReturnAction keyword
				var hit_cnt = obj_action.lastIndexOf('/ReturnAction');
				if( hit_cnt == -1 ){
				} else {
					var actionStr = eval('document.' + obj_formName + '.ReturnAction.value');
					obj_action = obj_action.replace('ReturnAction', actionStr );
				}
				//set action
				eval('document.' + obj_formName + '.action=\'' + obj_action  + '\'');

			}
			if (obj_method != ''){
				//set method
				eval('document.' + obj_formName + '.Method.value=\'' + obj_method  + '\'');
			}
			if (obj_view != ''){
				//set view
				if( obj_view == 'ReturnView' ){
					obj_view = eval('document.' + obj_formName + '.ReturnView.value');
				}
				eval('document.' + obj_formName + '.View.value=\'' + obj_view  + '\'');
			}
			if (obj_errorview != ''){
				//set error view
				eval('document.' + obj_formName + '.ErrorView.value=\'' + obj_errorview  + '\'');
			}
			if (obj_row != ''){
				//set row
				eval('document.' + obj_formName + '.Row.value=\'' + obj_row  + '\'');
			}
			if (obj_id != ''){
				//set id
				eval('document.' + obj_formName + '.Id.value=\'' + obj_id  + '\'');
			}
			if (obj_actionParam != ''){
				//set actionParam
				eval('document.' + obj_formName + '.ActionParam.value=\'' + obj_actionParam  + '\'');
			}

			//set busy flag
			if( onButton_check_flag == true ){
				g_onButton_flag = true;
			}

			// set UnLoad flag
			g_onUnLoad_Flag = true;

			if (obj_ajax_id != ''){

				var objFrm = eval('document.' + obj_formName );
				var objAction = eval('document.' + obj_formName + '.action');
				var objMethod = eval('document.' + obj_formName + '.Method.value');

				//g_onButton_flag = false;
				ajax_submit( objFrm, objAction, objMethod, obj_ajax_id, obj_ajax_befor_func, obj_ajax_after_func );

			} else {
				//do submit
				if( typeof(obj_winName) != "undefined" && obj_winName != '' ){

					//new window open
					var newWin = window.open("about:blank", obj_winName , obj_winParam );
					eval('document.' + obj_formName + '.target="' +  obj_winName + '"' );
					eval('document.' + obj_formName + '.submit()' );
					newWin.focus();
					eval('document.' + obj_formName + '.target="_self"' );
					
					g_onButton_flag = false;
				
				} else {
					eval('document.' + obj_formName + '.target="_self"' );
					eval('document.' + obj_formName + '.submit()' );
				}
			}

		}

		return f;

	}

	// simple submit
	// form name
	function OnSubmitOnlyView( obj_formName ){

		// check onLoad
		if(  g_onLoad_Flag == false ){
			return false;
		}

		// check busy
		g_onUnLoad_Flag = true;

		//do submit
		eval('document.' + obj_formName + '.submit()' );

	}

	// line change 
	// select element,method,form name, select object name j
	function DispLineChangeView(obj_element, obj_methodName, obj_formName, obj_selectKey ){

		// check onLoad
		if(  g_onLoad_Flag == false ){
			return false;
		}

		var dispLine = eval('document.' + obj_formName + '.' + obj_selectKey + '.options[document.' + obj_formName + '.' + obj_selectKey + '.selectedIndex].value');

		if (dispLine != ''){
			eval('document.' + obj_formName + '.DispLine.value=\'' + dispLine +'\'' );
		}

		//set method
		eval('document.' + obj_formName + '.Method.value=\'' + obj_methodName  + '\'');

		//set UnLoad flag
		g_onUnLoad_Flag = true;

		//do submit
		eval('document.' + obj_formName + '.submit()' );

	}

	// all checkbox cheked
	// form name
	function AllCheck(obj_formName){

		//check onLoad
		if(  g_onLoad_Flag == false ){
		} else {

			var iCnt = eval('document.' + obj_formName + '.elements.length');
			for (i = 0; i < iCnt; i++ ) {
				// is checkbox object?
				if ( eval('document.' + obj_formName + '.elements[i].type') == 'checkbox' ) {
					// set on
					eval('document.' + obj_formName + '.elements[i].checked = true');
				}
			}

		}

	}

	// all checkbox not cheked
	// form name
	function AllClear(obj_formName){

		//check onLoad
		if(  g_onLoad_Flag == false ){
		} else {

			var iCnt = eval('document.' + obj_formName + '.elements.length');
			for (i = 0; i < iCnt; i++ ) {
				// is checkbox object?
				if ( eval('document.' + obj_formName + '.elements[i].type') == 'checkbox' ) {
					// set off
					eval('document.' + obj_formName + '.elements[i].checked = false');
				}
			}

		}

	}

	// onLoad work
	// if on err, view alert dlg
	function LoadFunc(){
		return LoadFunc(null);
	}

	// onLoad work
	// if on err, view alert dlg
	function LoadFunc(errMesg) {


		// check cookie
		var checkCookie = tmpGetCookie("movecheck");
		if( checkCookie == false ){
			// not found cookie
			//alert("Not Found Cookie!");
		} else if( checkCookie == 'ok' ){
			// ok
		} else if( checkCookie == 'ng' ){

			// ng
			//alert("Please Not Use Back or Reload on your browser."); 
			//set cookie value
			tempSetCookie("movecheck","ok");
			g_onUnLoad_Flag = true;
			//history.forward();

		} else {
			//alert("getCookie=" + checkCookie );
		}

		if (
			errMesg != 'No Err Message.' &&
			errMesg != '' &&
			errMesg != null) {
			alert(errMesg);
		}
		//<webfw:if dataname="DN_RIAS_ERR_INFO" name="ErrorMessage1" equal="" not="true" >
		//	alert('<webfw:errormessage dataname="DN_RIAS_ERR_INFO" />');
		//</webfw:if>

		//set onLoad flag
		g_onLoad_Flag = true;

		return true;

	}

	// onUnLoad work
	function UnLoadFunc(){

		if( g_onUnLoad_Flag ){
			//set ok to cookie
			tempSetCookie("movecheck","ok");
		} else {
			//set ng to cookie
			tempSetCookie("movecheck","ng");
		}

	}

	//-------------------------------------------------------------------------------
	// make temp cookie function
	// return Ok=true NG=false
	//-------------------------------------------------------------------------------
	function tempSetCookie(theName__,theValue__)
	{
		if ((theName__ != null) && (theValue__ != null))
		{
			document.cookie = theName__ + "="+theValue__;
			return true;
		}
		return false;
	}

	//-------------------------------------------------------------------------------
	// get value from Cookie function
	// return OK=value( not null) NG=false
	//-------------------------------------------------------------------------------
	function tmpGetCookie(theName__)
	{
		theName__ += "=";
		theCookie__ = document.cookie+";";
		start__ = theCookie__.indexOf(theName__);
		if (start__ != -1)
		{
			end__ = theCookie__.indexOf(";",start__);
			return unescape(theCookie__.substring(start__+theName__.length,end__));
		}
		return false;
	}

	//-------------------------------------------------------------------------------
	// Block EnterKey Event
	//-------------------------------------------------------------------------------
	function BlockEnter(evt){
		evt = (evt) ? evt : event; 
		var charCode=(evt.charCode) ? evt.charCode : 
			((evt.which) ? evt.which : evt.keyCode);
		if ( Number(charCode) == 13 || Number(charCode) == 3) {
			return false;
		} else {
			return true;
		}
	}

	//-------------------------------------------------------------------------------
	// Attach BlockEnter to textbox 
	//-------------------------------------------------------------------------------
	function attachBlockEnter(formid) {
		var elements = document.forms[formid].elements;
		for (var j=0; j < elements.length; j++) {
			var e = elements[j];	
			if (e.type == "text"){
				e.onkeypress=BlockEnter;
			}
		}
	}


