
function callPage(url, layer , afterFunc , afterStr,  params , isHistory )
{	
	progress_bar(true);
	if( isHistory == undefined || isHistory == 'false' )
	{
		try
		{
			dhtmlHistory.add(url, '{ "url":"'+url+'","layer":"'+layer+'", "afterFunc":"'+afterStr+'" , "params":"'+params+'" }' );
		} catch(e)
		{}
	}
	new Ajax.Request(
		url, 
		{
			method : 'get',			
			onSuccess: function(transport) 
		    { 
				progress_bar(false);
				
				if( params != undefined && params != 'undefined' )
				{					
					printPage2(transport,layer,afterFunc, params);
				}
				else
				{	
					printPage(transport,layer,afterFunc);
				}
		    },
		    onFailure: function(transport)
		    {		    	
		    	progress_bar(false);
		    	var error_code = transport.status;
		    	if( error_code == '404' )
		    		callPage('/404.jsp', 'index');
		    	else
		    		callPage('/500.jsp', 'index');
		    	return;
		    }
		});
		
	window.scrollTo(0,0);

}

function callHistoryPage( url, layer , afterFunc , afterStr ,  params )
{	
	callPage(url, layer , afterFunc , afterStr,  params , true );		    
}

/*
 * main div 에 page print
 * 
 */
function printPage(transport,layer, afterFunc) {	
	
	var output = document.getElementById(layer);	
	var _msg =  transport.responseText; 
	var _param = null; 
	if(_msg.indexOf('SESSION_OUT') != -1)
	{	
		var _arr = _msg.split('|');		
		_param = _arr[1];
		//alert(_param);
		//alert('1');		
		loadLoginPreProcess();
		//alert('2');				
		Close_Server();
		//alert('3');		
		callPage('/login.jsp?'+_param, 'index');
		//alert('4');		
		return;
	}
	output.innerHTML = _msg; 
	
	if (afterFunc != undefined)
	{
		try
		{
		//eval
		afterFunc();
		} catch(e){}
	}
	
}


function printPage2(transport,layer, afterFunc, params) {
		
	var output = document.getElementById(layer);	
	var _msg =  transport.responseText; 
	var _param = null; 
	if(_msg.indexOf('SESSION_OUT') != -1)
	{		
		var _arr = _msg.split('|');		
		_param = _arr[1];
		//alert(_param);
		//alert('1');	
		loadLoginPreProcess();
		//alert('2');		
		Close_Server();
		//alert('3');
		callPage('/login.jsp?'+_param, 'index');		
		return;
	}
	
	output.innerHTML = _msg; 
	
	if (afterFunc !=undefined)
	{
		afterFunc(params);
	}
	
}



/*
 * data async 전송 (CUD 처리)
 *   
 */

function send(url, params, rUrl, layer)
{
	new Ajax.Updater({ success: 'out' }, url, {
						method: 'post',
    					asynchronous:false,
				        onSuccess  : function(returnValue)
				        {
				            callPage(rUrl, layer);
				        },
						contentType: 'application/x-www-form-urlencoded',						
						parameters: params  
				 	  }
				);

}



function send(url, params, rUrl, layer, afterFunc)
{
	new Ajax.Updater({ success: 'out' }, url, {
						method: 'post',
    					asynchronous:false,
				        onSuccess  : function(returnValue)
				        {
				            callPage(rUrl, layer, afterFunc);
				        },
						contentType: 'application/x-www-form-urlencoded',						
						parameters: params  
				 	  }
				);

}



/** json */
JJJSON = function(jsonText)
{
    try{
    	this.json = eval("(" + jsonText + ")");
    }catch(e){}
}

JJJSON.prototype.getValue = function(attr) 
{
    var val;
    try{
    val = eval("this.json." + attr);
    if (val == undefined)
        return "";
    }catch(e){ return "";}
    return val;
}

function progress_bar(display)
	{
		var curtain = document.getElementById("progress_bar_curtain");
		var pbox = document.getElementById("progress_bar_box");
		var w = (document.all? document.body.clientWidth : window.innerWidth);
        var h = (document.all? document.body.clientHeight : window.innerHeight);

		curtain.style.top = 0;
        curtain.style.left = w/2;
        
		curtain.style.width = '120';
        curtain.style.height = '50';
		
		if (display)
		{
			curtain.style.display = "block";
			pbox.style.display = "block";
		}
		else
		{
			curtain.style.display = "none";
			pbox.style.display = "none";
		}
	}


var isw3c=(document.getElementById)?true:false;
var isie=(document.all)?true:false;
var progN=-1;
function createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks,count,action){

	if(isie||isw3c){
		var t='<div id="_xpbar'+(++progN)+'" style="visibility:visible; position:relative; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
		t+='<span id="blocks'+progN+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';
		for(i=0;i<blocks;i++){
			t+='<span style="background-color:'+blkC+'; left:-'+((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; '
			t+=(isie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
			t+='"></span>';
		}
		t+='</span></div>';
		document.write(t);
		var bA=(isie)?document.all['blocks'+progN]:document.getElementById('blocks'+progN);
		bA.bar=(isie)?document.all['_xpbar'+progN]:document.getElementById('_xpbar'+progN);
		bA.blocks=blocks;
		bA.progN=progN;
		bA.w=w;
		bA.h=h;
		bA.speed=speed;
		bA.ctr=0;
		bA.count=count;
		bA.action=action;
		bA.togglePause=togglePause;
	bA.showBar=function(){
	this.bar.style.visibility="visible";
	}
	bA.hideBar=function(){
	this.bar.style.visibility="hidden";
	}
	bA.tid=setInterval('startBar('+progN+')',speed);
	return bA;
	}
}

function startBar(bn)
{
	
	var t=(isie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn);
	if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w){
	t.style.left=-(t.h*2+1)+'px';
	t.ctr++;
	if(t.ctr>=t.count){
	eval(t.action);
	t.ctr=0;
	}}else t.style.left=(parseInt(t.style.left)+t.h+1)+'px';
}

function togglePause(){
	if(this.tid==0){
	this.tid=setInterval('startBar('+this.progN+')',this.speed);
	}else{
	clearInterval(this.tid);
	this.tid=0;
	}
}

function togglePause(){
	if(this.tid==0){
	this.tid=setInterval('startBar('+this.progN+')',this.speed);
	}else{
	clearInterval(this.tid);
	this.tid=0;
	}
}


var helpManualWin = null;
function js_help_pop(arg , w )
{	
  if(helpManualWin == null)
  {
	  helpManualWin = new Ext.Window({
		id:'helpManualWin',
		title:'Help',
		layout:'fit',
		width:w,
		autoHeight:true,
		resizable:false,
		closeAction:'close',
		modal:true
	    });

	  helpManualWin.on('render', function() { 
		  helpManualWin.load({
	      method: 'GET',
	      url: '/help/'+arg+'.html'
	    }); 
	  }); 
	 
	  helpManualWin.on('close', function() { 
		  helpManualWin.close();
		  helpManualWin = null;
	  });
	 
	  helpManualWin.show();
	}
}

function howtoActionDiv(arg)
{
	var divNm = 'howtoDiv' + arg;
	var obj = document.getElementById(divNm);
	var url = '/help/manual_'+arg + '.html';
	var textMsg = '';
	
	if( obj.style.display == 'none')
	{
		obj.style.display = 'block';
	}else{
		obj.style.display = 'none';
		return;
	}
	
	new Ajax.Request(
		url, 
		{
			method : 'get',			
			onSuccess: function(transport) 
		    { 
		    	textMsg = transport.responseText; 
		    	obj.innerHTML = textMsg;
				return;
		    },
		    onFailure: function(transport)
		    {
		    	var error_code = transport.status;
		    	if( error_code == '404' )
		    		callPage('/404.jsp', 'index');
		    	else
		    		callPage('/500.jsp', 'index');
		    	return;
		    }
		});
	
}

