﻿
var targetIframePath = '';
var s_mode = false;

function controlAll( p_Mode, trgtObj ){
	s_mode = (p_Mode == 'disable' ) ? true : false;
	f_col = document.getElementsByTagName('IFRAME');								
	for(i=0;i<f_col.length;i++){					
		if(trgtObj == 'select'){
			try{
				eval("sel_col = window.top['" + f_col[i].name + "'].document.getElementsByTagName('SELECT')");
			}catch(e){
				//alert(e.description + 'controlAll_1');
				continue;
			}
			var x=0 ; 				
			if(sel_col.length>0){					
				for(x=0;x<sel_col.length;x++){					
					sel_col[x].disabled = s_mode;
				}
			}
			frameAction(f_col[i], "window.top['" + f_col[i].name + "']", trgtObj);
			//f_col[i].style.border = '1px solid red';
		}else if(trgtObj == 'button'){
			try{
				eval("btn_col = window.top['" + f_col[i].name + "'].document.getElementsByTagName('INPUT')");
			}catch(e){
				//alert(e.description+ 'controlAll_2');
				continue;
			}
			if(btn_col.length>0){					
				for(x=0;x<btn_col.length;x++){					
					if(btn_col[x].type.toUpperCase() == "BUTTON" && btn_col[x].id.toUpperCase() != disBtnObj.id.toUpperCase() ){
						btn_col[x].disabled = s_mode;
					}
				}
			}			
			frameAction(f_col[i], "window.top['" + f_col[i].name + "']", trgtObj);
		}
	}
}
function frameAction(fObj, iframePath, trgtObj){
	var iframeObj = fObj;	
	try{
		eval("var sf_col = " + iframePath + ".document.getElementsByTagName('IFRAME')");
	}catch(e){
		//alert(e.description);
	}	
	if(sf_col.length>0){
		var j=0;
		for(j=0; j<sf_col.length; j++){					
			if(trgtObj == 'select'){				
				try{
					eval("var sel_col = " + iframePath + "['" + sf_col[j].name + "'].document.getElementsByTagName('SELECT')");
				}catch(e){
					//alert(e.description+ 'frameAction_1');
					continue;
				}	
				var y=0 ; 				
				if(sel_col.length>0){					
					for(y=0;y<sel_col.length;y++){
						sel_col[y].disabled = s_mode;
					}
				}				
			}else if(trgtObj == 'button'){
				try{
					eval("var btn_col = " + iframePath + "['" + sf_col[j].name + "'].document.getElementsByTagName('INPUT')");
				}catch(e){
					//alert(e.description+ 'frameAction_2');
					continue;
				}				
				var z=0 ; 				
				if(btn_col.length>0){					
					for(z=0;z<btn_col.length;z++){							
						if(btn_col[z].type.toUpperCase() == "BUTTON" && btn_col[z].id.toUpperCase() != disBtnObj.id.toUpperCase() ){
							btn_col[z].disabled = s_mode;
						}
					}
				}			
			}
			var newPath = iframePath + "['" + sf_col[j].name + "']" ;
			//sf_col[j].style.border = '1px solid red';
			frameAction(sf_col[j], newPath, trgtObj);
		}
	}	
}			
function maskOn(){
	controlAll('disable', 'select');
	maskObj = window.top.document.getElementById('mask');
	maskObj.style.display = 'block' ;
}
function maskOff(){
	controlAll('enable', 'select');
	maskObj = window.top.document.getElementById('mask');
	maskObj.style.display = 'none' ;
}
var disBtnObj = new Object();
var enBtnObj = new Object();
function disableBtn(thisObj){	
	disBtnObj = thisObj;
	controlAll('disable', 'button');
}
function enableBtn(thisObj){
	enBtnObj = thisObj;
	controlAll('enable', 'button');
}

var popupObj = new Object();
var popupMaskObj = new Object();
//  window.top.popUp('kpi_definition.html', thisObj, 'center', 'middle', 750, 350);  
function popUp(pUrl, thisObj, pX, pY, pXi, pYi){
	
	var pu_url = (pUrl == undefined) ? '' : pUrl; 
	var posArray = new Array();
	posArray[0] = pX;		
	posArray[1] = pY;		
	posArray[2] = (pXi == undefined || pXi == '') ? '300' : pXi;		
	posArray[3] = (pYi == undefined || pYi == '') ? '300' : pYi;				
	
	if( pX == 'center' && pY == 'middle'){
		var posArray = popUpAt( '', 'screenCenter', posArray[2], posArray[3]);	
	}else if( pX == '' && pY == '' ){
		var posArray = popUpAt( thisObj, 'belowActiveObject', posArray[2], posArray[3]);	
	}else{
		posArray[0] = 0;		
		posArray[1] = 0;
	}
	
	pu_x = posArray[0]; 
	pu_y = posArray[1]; 
	pu_xi = posArray[2]; 
	pu_yi = posArray[3];

	popupObj = window.top.document.getElementById('popUpIframeDiv');	
	popupObj.style.left = pu_x;
	popupObj.style.top = pu_y;
	popupObj.style.width = pu_xi;
	popupObj.style.height = pu_yi;
	popupObj.style.display = 'block';	

	if(pu_url != ''){
		window.top.popUpIframe.location = pu_url;
	}else{
		window.top.popUpIframe.document.close();
	}

	popupMaskObj = window.top.document.getElementById('popUpMaskDiv');	
	popupMaskObj.style.left = pu_x;
	popupMaskObj.style.top = pu_y;
	popupMaskObj.style.width = pu_xi;
	popupMaskObj.style.height = pu_yi;
	popupMaskObj.style.display = 'block';	

	window.top.maskOn();
	window.top.popUpIframe.focus();
}

function closeWin(){
	//window.top.popUpIframe.location = 'index/blank.cfm';
	popupObj.style.display = 'none';
	popupMaskObj.style.display = 'none';
	try{
		window.top.maskOff();
	}catch(e){
		//alert(e.description);
	}
}

function closeError(){
	errorObj = window.top.document.getElementById('errorDiv');	
	errorObj.style.display = 'none';
}

function popUpAt(t_Obj, s_mode, a_width, a_height){		
	if(s_mode == 'screenCenter'){
		a_x = docAlignHorizontal(a_width, 'center');
		a_y = docAlignVertical(a_height, 'middle');
		posAry = [a_x, a_y, a_width, a_height];		
	}else	if(s_mode == 'belowActiveObject'){
		//return position array;
		a_x = getCoords(t_Obj, 'screen', 'left') - 0;
		a_y = getCoords(t_Obj, 'screen', 'top') + parseInt(t_Obj.clientHeight) + 1;
//		a_width = parseInt(t_Obj.clientWidth) + 2;
//		a_height = parseInt(t_Obj.clientHeight) * 10;	
		var posAry = new Array();
		posAry = [a_x, a_y, a_width, a_height];
	}
	return posAry;
}

function docHtml(str, w, h){
	aHtml = '<html><link rel=stylesheet href="css/common.css" type="text/css" media="all" ><body scroll="no" >' +
		'<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" >' + 
		'<tr><td valign="middle" align="center" >' +
		'<img class="previewImage" src="'+str+'" height="' + h + '" onclick="try{window.top.closeWin()}catch(e){}" />' + 
		'</td></tr></table></body></html>'
		return aHtml;
}

winClickX = 0;
winClickY = 0;
function popUpIframeOnDrag(thisObj){
	//window.top.popErr(event.x + '_' + event.y);	
	if(eval(event.x - winClickX) >= 0){
		window.top.document.getElementById('popUpIframeDiv').style.left = eval(event.x - winClickX);
		window.top.document.getElementById('popUpMaskDiv').style.left = eval(event.x - winClickX);
	}
	if(eval(event.y - winClickY) >= 0){
		window.top.document.getElementById('popUpIframeDiv').style.top = eval(event.y - winClickY);
		window.top.document.getElementById('popUpMaskDiv').style.top = eval(event.y - winClickY);
	}
}

function popUpIframeOnMouseMove(thisObj){
	//window.top.popErr(e.offsetX + '_' + e.offsetY);	
	//alert( e);
//	layerY
	winClickX = event.offsetX;
	winClickY = event.offsetY;
}







