//////////////////////////////////////////////////////////////////
//
//	LayerControl.js功能
//
//		控制主窗口中的功能区(DIV)的建立、显示、隐藏等操作。
//
//		本程序中所有函数有前缀 lc。
//                        
//////////////////////////////////////////////////////////////////


// 同时创建 LAYER 和 DIV 
function lcCreateLayer(name, left, top, width, height, visible, content)
{
	var layer;
	if (document.layers) {
		document.writeln('<layer name="' + name + '" left=' + left + ' top=' + top + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') +  '>');
		document.writeln(content);
		document.writeln('</layer>');
	}

	if (document.all) {
		document.writeln('<div id="' + name + '" style="position:absolute; overflow:none; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
		document.writeln(content);
		document.writeln('</div>');
	}
}

// 取得 LAYER 或 DIV
function lcGetLayer2( layername )
{
	var fullname;
	var layer;
	if( document.layers ) {
		layer = document.layers[ layername ];
		return layer;
	}
	else if( document.all )
		return eval("document.all." + layername);
	else
		return null;
}

// 取得 LAYER 或 DIV 的子对象
function lcGetLayerObject( layername, objname )
{
	var fullname;
	var layer;
	if( document.layers ) {
		layer = document.layers[ layername ];
		fullname = "layer.document." + objname;
	}
	else if( document.all ) {
		fullname = "document.all." + objname;

	}
	else
		return null;
	return eval( fullname );
}

// 取得 LAYER 或 DIV 的属性串
//function lcGetLayerStyle(name)
function lcGetLayer(name)
{
	var layer;
	if( document.layers ) {
		layer = document.layers[name];
		return layer;
	}
	else if( document.all ) {
		if( eval('document.all.' + name) != null ) {
			layer = eval('document.all.' + name + '.style');
			return layer;
		}
		else 
			return null;
	}
	else 
		return null;
}

// 移动 LAYER 或 DIV
function lcMoveLayer(name,x,y)
{
	var layer = lcGetLayer(name);
	if( layer != null ) {
		if( document.layers ) {
			layer.moveTo(x,y);
		} else if( document.all ) {
			layer.top = y
			layer.left = x
		}
	}
}

// 拉框和改变 DIV 或 LAYER 的大小
function lcResizeLayer(name,w,h)
{
	var layer = lcGetLayer(name);
	if( layer != null ) {
		if( document.layers ) {
			layer.resize(w,h);
			layer.document.open();
			layer.document.writeln('<table bordercolor="red" border="1" width="' + w + '" height="' + h + '"><tr><td></td></tr></table>');
			layer.document.close();
		}
		else if( document.all ) {
			layer.width = w;
			layer.height = h;
		}
	}
}

// 改变图片的 SRC
function lcChangeImgSrc( src )
{
	if( document.layers ) {
		var layer = lcGetLayer( szLayerMapImage );
		layer.document.open();
		layer.document.writeln( '<img src=' + src + ' name=' + szImageMap + 'width=' + width + ' height=' + height + '>' );
		layer.document.close();
	}
	else if( document.all ) {
		var img = eval( 'document.all.' + szImageMap );
		img.src = src;
	}
}

function lcSetImgSize( name, w, h )
{
	if( document.all )
	{
		var img = eval( 'document.all.' + name );
		img.width = w;
		img.height = h;
		
	} else if( document.layer ) {
		alert("null");
	}
}

// 改变图片尺寸
function lcChangeImgSize( w, h )
{
	if( document.all )
	{
		var img = eval( 'document.all.' + szImageMap );
		img.width = w;
		img.height = h;
	}
}

// 隐藏 LAYER 或 DIV
function lcHideLayer(name)
{		
  	var layer = lcGetLayer(name);		
	if (layer != null) {
	  	if (document.layers)
    		layer.visibility = "hide";
	  	if (document.all)
			layer.visibility = "hidden";
	}
}

// 显示 LAYER 或 DIV
function lcShowLayer(name)
{		
  	var layer = lcGetLayer(name);		
	if (layer != null) {
	  	if (document.layers)
    		layer.visibility = "show";
	  	if (document.all) 
			layer.visibility = "visible";
	}
}

//
// 创建输入图层
//
function lcCreateInputLayer( left, top, width, height, visible, content)
{
	Input_Left = left;
	Input_Top = top;
	blCommonPage = true;
	lcCreateLayer( szLayerInput, left, top, width, height, visible, content);
}

//
// 创建输出图层
//
function lcCreateOutputLayer( left, top, width, height, visible, content)
{
	Output_Left = left;
	Output_Top = top;
	lcCreateLayer( szLayerOutput, left, top, width, height, visible, content);
}

//
// 创建图片层
//
function lcCreateMapLayer( l, t, w, h, border, szBGImg )
{
	var content, contentBg;

	left	= l;
	top	= t;
	width	= w;
	height	= h;
	Owidth	= w;
	Oheight	= h;


	// 地图的背景
	if( szBGImg != "" ) {
		content = '<img name="' + szImageMapAreaBg + '" src="' + szBGImg + '" width=' + width + ' height=' + height + ' border='+ border +'>';
		lcCreateLayer( szLayerMapBackground, left-1, top-1, width , height, true, content );
	}

	content = '<img name="' + szImageMap + '" src="images/pixel.gif" width=' + width + ' height=' + height + ' border=0 onload="lcCtlLoad();">';
	contentBg = '<img name="' + szImageMapBg + '" src="images/pixel.gif" width=' + width + ' height=' + height + ' border=0>';

	if( document.all ) {
		// 地图 IMAGE for IE
		document.writeln( '<div id="layClip" style="position:absolute; width:' + width + 'px; height:' + height + 'px; left:' + left + 'px; top:' + top + 'px; clip: rect(0 ' + width + ' ' + height + ' 0);"> ' );
		lcCreateLayer( szLayerMapImageBg, 0, 0, width, height, true, contentBg );
		lcCreateLayer( szLayerMapImage, 0, 0, width, height, true, content );
		document.writeln( '</div>' );
	
	} else if( document.layers ) {
		// 地图 IMAGE for NS
		lcCreateLayer( szLayerMapImage, left, top, width, height, true, content );
	}

	// 拖框层 - 用于放大、缩小等
	content = '<table bordercolor="red" border="2" width="100%" height="100%"><tr><td></td></tr></table>';
	lcCreateLayer( szLayerBorder,1,1,1,1,false,content );
	
	// 虚线层
	if( document.all ) {
		for( var i=0; i < 10; i++ ) {
			lcCreateLayer( 'div' + i, 1, 1, 1, 1, false, '<img name="img' + i + '" src="images/pixel.gif">' );
		}
	}

	// Loading...层
	var loadW = 115;
	var loadH = 29;
	content = "<img src=\"images/loading.gif\">";		
	lcCreateLayer( szLayerLoading, left+width/2-loadW/2, top+height/2-loadH/2, loadW, loadH, true, content );

	// 防止拖框鼠标变禁止 for MAP
	lcCreateLayer( szLayerMask, left, top, width, height, true, "" );
	var layMask = eval("document.all." + szLayerMask);
	layMask.style.backgroundImage = "url(image/pixel.gif)";	
	}

function lcCtlLoad()
{
	var img = eval( "document.all." + szImageMap);
	var imgbg = eval( "document.all." + szImageMapBg );

	if( img != null && img.src.indexOf("pixel.gif") <= 0) {
		imgbg.src = imgSrc;
		lcSetImgSize( szImageMapBg, width, height );
		lcMoveLayer( szLayerMapImageBg, 0, 0 );
	}

}

function lcCreateBarLayer( left, top, bgWidth, bgHeight, btWidth, btHeight, bgImg, btImg )
{	

	var content;
	
	blBarExit = true;

	Bar_bgWidth		= bgWidth;
	Bar_bgHeight		= bgHeight;
	Bar_Width		= btWidth;
	Bar_Height		= btHeight;
	Bar_bgTop		= top;
	Bar_bgLeft		= left;
	Bar_Left		= Bar_bgLeft +( Bar_bgWidth - Bar_Width )/2;
	Bar_Top			= Bar_bgTop +( Bar_bgHeight/2 ) - Bar_Height/2;
	oBar_bgLeft		= left;
	oBar_bgHeight	= bgHeight;
    	ifthereisbar="y"
	// 滑轨背景
	content = "<img  name=\"imgBgBar\" src="+ bgImg +" width="+ bgWidth +" height="+ bgHeight +">";
	lcCreateLayer( szLayerBgBar, left, top, bgWidth, bgHeight, true, content);
	// 按钮层
	content = "<img src="+ btImg +" width="+ btWidth +" height="+ btHeight +">";
	lcCreateLayer( szLayerBar, left+(bgWidth-btWidth)/2, top+(bgHeight/2)-btHeight/2, btWidth, btHeight, true, content);
	// 滑轨蒙板
	lcCreateLayer( szLayerBarMask, left, top, bgWidth, bgHeight, true, "");
	var layMask = eval("document.all." + szLayerBarMask);
	layMask.style.backgroundImage = "url(image/pixel.gif)";	
	layMask.style.cursor = "hand";
}//end of lcCreateBarLayer(

// 改变大小后的 Bar 设置 
function lcResetLayerBar( w, h )
{
	var temp1 = w - Owidth;
	var temp2 = h - Oheight;

	Bar_bgLeft		= oBar_bgLeft + temp1;
	Bar_bgHeight	= oBar_bgHeight + temp2;
	Bar_Left		= Bar_bgLeft +( Bar_bgWidth - Bar_Width )/2;
	Bar_Top			= Bar_bgTop +( Bar_bgHeight/2 ) - Bar_Height/2;
	
	lcMoveLayer( szLayerBgBar,		Bar_bgLeft,		Bar_bgTop );
	lcMoveLayer( szLayerBar,		Bar_Left,		Bar_Top );
	lcMoveLayer( szLayerBarMask,	Bar_bgLeft,		Bar_bgTop );
	lcResizeLayer( szLayerBarMask,	Bar_bgWidth,	Bar_bgHeight );
	lcSetImgSize( "imgBgBar",		Bar_bgWidth,	Bar_bgHeight );
	
}//end of lcResetLayerBar(
//
// 改变大小后的地图设置
//
function lcResetLayerAfterResizeImg( w, h )
{
	var temp1 = w - Owidth;
	var temp2 = h - Oheight;
	var layer = lcGetLayer( "layClip" );
	
	lcResizeLayer( szLayerMapBackground, w, h);
	lcResizeLayer( "layClip", w, h);
	lcResizeLayer( szLayerMapImage, w, h);
	lcResizeLayer( szLayerMapImageBg, w, h);
	lcResizeLayer( szLayerMask, w, h);
	layer.clip = 'rect(0 ' + w + ' ' + h + ' 0)';		
	lcSetImgSize( szImageMapAreaBg, w, h );
	lcSetImgSize( szImageMap, w, h );
	width	= w;
	height	= h;
}
function lcResetLayerLoading(l,t,w,h)
{
	//Created at 2002-10-17 10:34:31 By soym

	var loadW = 115; 
	var loadH = 29;  //应与上面的 Loading...层统一

	var Lleft = l;
	var Ltop  = t;
	document.all.layLoading.style.pixelLeft = Lleft+(w-loadW)/2;
	document.all.layLoading.style.pixelTop  = Ltop+(h-loadH)/2;
}
