var js_Return="";
var szJsReturnDelimiter = "!!";
var szJsReturnItemDelimiter = "==";
var nCenterX,nCenterY;
var aryHiddenParam = new Array();
var tmp_ImgSrc="";

function tmpChangeImgSrc()
{
	if(MpDegree == 0) 
	{
		lcChangeImgSrc( tmp_ImgSrc );
		imgSrc = tmp_ImgSrc;
	}
	else { window.setTimeout("tmpChangeImgSrc()",50);}
}


function commAnalyzeJsReturn( jsReturn )
{
	var tmpval, tmpval2;
	var aryRet;
	var aryHirerlayer;
	tmpval = imgSrc;  // wsd add
	if(tmpval != ""){
		nOptNum += 1;
		aryCx[nOptNum] = nCenterX;
		aryCy[nOptNum] = nCenterY;
		aryZoom[nOptNum] = szMapZoom;
		aryImgURL[nOptNum] = tmpval;	

		aryRight[nOptNum] = eRight; //- wsd add
		aryLeft[nOptNum] = eLeft;   //-当前图形坐标范围
		aryTop[nOptNum] = eTop;
		aryBottom[nOptNum] = eBottom;

		nOptIndex = nOptNum;
		commBorwseSetting();
	}
}

function commSplit( strRet, delimiter )
{
	var aryRet;
	aryRet = strRet.split(delimiter);
	return aryRet;
}

function commGetSubmitHidden( aryRet, delimiter ) 
{
	var szHidden  = "hidden_MapImageWidth,hidden_MapImageHeight,hidden_UserID";
	var aryHidden = szHidden.split( "," );
	var nHiddens  = aryHidden.length;
	var i;

	for( i=0; i < nHiddens; ++i )
		aryHidden[i] += "=" + commGetItemFromRet( aryRet, aryHidden[i], delimiter );
	return aryHidden;
}

function commGetItemFromRet( aryRet, name, delimiter ) 
{
	var aryTmp;
	for( i=0; i < aryRet.length; ++i ) {
		aryTmp = aryRet[i].split( delimiter );
		if(aryTmp[0] == name)
			return aryTmp[1];
	} 
	return "";
}

// 生成图层列表
function commGenLayerList( szNameList )
{
	var aryAllLayer;
	var szList = "";
	var szName = "";
	var szLayer;

	if( szNameList != "" ) {
		aryAllLayer = commSplit( szNameList, "," );
		for( i=0; i < aryAllLayer.length; ++i ) {
			szLayer = aryAllLayer[i];
			if( szLayer == "全部单位" )
				szList += '<option value="all">' + szLayer;
			else {
				szName = szLayer.substr( szLayer.indexOf( "_" ) + 1 );
				szName = szName.substring(0,4);
				szList += '<option value="' + szLayer +'">' + szName;
			}
		}
	}
	else
		szList = "<option value=\"all\">全部单位";
	return szList;
}

function commChangeLinkChar( src )
{
	var tmp;
	tmp = src.replace( /~~/g, "==" );
	tmp = tmp.replace( /%%/g, "!!" );
	tmp = tmp.replace( /#col#/g, "," );
	tmp = tmp.replace( /#row#/g, ";" );
	return tmp;
}

function commGenrandom()
{
	var seed_adv = 100000000;
	return Math.round( Math.random() * seed_adv );
}

function commSetGlobalFrameVars( frmOutput )
{
	frmMappage  = this;
	frmOprtpage = this;
	frmInfopage = this;
}

function commBorwseSetting()
{
	if(nOptIndex <= 0 && nOptNum <=0) return;

	if (nOptIndex == 0)
	{
		commCursorHand( 'linkprev', false);
	} else 
	{
		commCursorHand( 'linkprev', true);
	}

	if (nOptIndex == nOptNum)
	{
		commCursorHand( 'linknext', false);
		commCursorHand( 'linklast', false);
	}
	else
	{
		commCursorHand( 'linknext', true);
		commCursorHand( 'linklast', true);
	}		
}
function commCursorHand( objname , bl)
{
	var obj = eval("document.all." + objname);
	if(obj != null)
	{
		if( bl) obj.style.cursor = "hand";
		if( !bl )obj.style.cursor = "";
	}
}
function commBrowserStatus(objname)
{
	var obj = eval("document.all." + objname);
	if(obj != null)
	{
		if(obj.style.cursor == "hand") return true;
		else 
		{
			return false;
		}
	}
}
function commBrowserAction(act)
{
	if(act =='prev' && commBrowserStatus('linkprev'))
	{
		nOptIndex = nOptIndex - 1;
		bolOptBrowser = true;
	}
	if(act =='next' && commBrowserStatus('linknext'))
	{
		nOptIndex = nOptIndex + 1;
		bolOptBrowser = true;
	}
	if(act =='last' && commBrowserStatus('linklast'))
	{
		nOptIndex = nOptNum;
		bolOptBrowser = true;
	}
	if(bolOptBrowser == true){
		lcChangeImgSrc( aryImgURL[nOptIndex] );
		imgSrc = aryImgURL[nOptIndex];	
		szMapZoom = aryZoom[nOptIndex];	
		nCenterX = aryCx[nOptIndex];
		nCenterY = aryCy[nOptIndex];

		eRight = aryRight[nOptIndex]; // -wsd add
		eLeft = aryLeft[nOptIndex]; 
		eTop = aryTop[nOptIndex];
		eBottom = aryBottom[nOptIndex];
		commBorwseSetting();
	}
}

function commTextBorwseSetting()
{
	if(nTextIndex <= 0 && nTextNum <=0)
		return;
	if (nTextIndex == 0){
		commCursorHand( 'Textprev', false);
	} else {
		commCursorHand( 'Textprev', true);
	}
	if (nTextIndex == nTextNum){
		commCursorHand( 'Textnext', false);
		commCursorHand( 'Textlast', false);
	}
	else{
		commCursorHand( 'Textnext', true);
		commCursorHand( 'Textlast', true);
	}		
}

function commTextAction(act)
{
	if(act =='prev' && commBrowserStatus('Textprev'))
	{
		nTextIndex = nTextIndex - 1;
		bolTextBrowser = true;
	}
	if(act =='next' && commBrowserStatus('Textnext'))
	{
		nTextIndex = nTextIndex + 1;
		bolTextBrowser = true;
	}
	if(act =='last' && commBrowserStatus('Textlast'))
	{
		nTextIndex = nTextNum;
		bolTextBrowser = true;
	}
	if(bolTextBrowser == true){
		lcReplaceLayerContent2("layerOutput", aryTextResult[nTextIndex])
		nTableRows = arySelCount[nTextIndex];
		commTextBorwseSetting();
	}
}


function WindowOpen(url,w,h) 
{ 
	NewWin=window.open(url, 'NewWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no'); 
	NewWin.resizeTo(w,h); 
	leftpost=(screen.width-w)/2;
	NewWin.moveTo(leftpost,2);
}


function getCookieVal(offset)
      {
         var endstr=document.cookie.indexOf(";",offset);
         if(endstr==-1)
         endstr=document.cookie.length;
         return unescape(document.cookie.substring(offset,endstr));
      }


function GetCookie(name)
{
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while(i<clen)
    {
		var j=i+alen;
		if(document.cookie.substring(i,j)==arg)
					return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if(i==0)
		break;
	}
	return null;
}

function SetCookie(name,value)
{
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(2<argc)?argv[2]:null;
	var path=(3<argc)?argv[3]:null;
	var domain=(4<argc)?argv[4]:null;
	var secure=(5<argc)?argv[5]:false;
	document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
}


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>');
	}
}

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;
}

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;
		if( layername == szLayerOutput )
			fullname = "frmInfopage." + fullname;
	}
	else
		return null;
	return eval( fullname );
}

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;
}

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
		}
	}
}

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;
		}
	}
}

function lcChangeImgSrc( src )
{
	imageSrc = 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;
	}
}

function lcHideLayer(name)
{		
  	var layer = lcGetLayer(name);		
	if (layer != null) {
	  	if (document.layers)
    		layer.visibility = "hide";
	  	if (document.all)
			layer.visibility = "hidden";
	}
}

function lcShowLayer(name)
{		
  	var layer = lcGetLayer(name);		
	if (layer != null) {
	  	if (document.layers)
    		layer.visibility = "show";
	  	if (document.all) 
			layer.visibility = "visible";
	}
}

function lcReplaceLayerContent(name, content)
{
	if(name == "layerOutput"){
		nTextNum += 1;
		aryTextResult[nTextNum] = content;
		arySelCount[nTextNum] = nTableRows;
		nTextIndex = nTextNum;
		commTextBorwseSetting();
	}
	content = content.replace( /\'/g, "\\'" );
	var str = "document.all." + name + ".innerHTML = '" + content + "'";
	if( name == szLayerOutput )
		str = "frmInfopage." + str;
	eval(str);
}

function lcReplaceLayerContent2(name, content)
{
	content = content.replace( /\'/g, "\\'" );
	var str = "document.all." + name + ".innerHTML = '" + content + "'";
	if( name == szLayerOutput )
		str = "frmInfopage." + str;
	eval(str);
}

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=1 onload="lcCtlLoad();">';
	contentBg = '<img name="' + szImageMapBg + '" src="images/pixel.gif" width=' + width + ' height=' + height + ' border=1>';

	if( document.all ) {
		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 ) 
	{
		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">' );
		}
	}
	lcCreateLayer( 'divStart', 1, 1, 1, 1, false, '<img name="imgStart" src="images/startPt.gif">');
	lcCreateLayer( 'divEnd', 1, 1, 1, 1, false, '<img name="imgEnd" src="images/endPt.gif">' );
	//lcCreateLayer( 'divMove', 1, 1, 1, 1, false, '<img name="imgMove" src="images/MovePt.gif">' );
	var loadW = 115;
	var loadH = 29;
	content = "<img src=\"images/starting.gif\">";
	lcCreateLayer(szLayerLoading, left+width/2-loadW/2, top+height/2-loadH/2, loadW, loadH, true, content );
	lcCreateMaskLayer(szLayerMask, left, top, width, height, "");
}

function lcCtlLoad()
{
	var img = eval( "document.all." + szImageMap);
	var imgbg = eval( "document.all." + szImageMapBg );
	if( img != null && img.src.indexOf("pixel.gif") <= 0) {
		imgSrc = img.src;
		imgbg.src = imgSrc;
		tmp_ImgSrc = 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);
	lcCreateMaskLayer(szLayerBarMask,left, top, bgWidth, bgHeight,"");
	var layMask = eval("document.all." + szLayerBarMask);
	layMask.style.cursor = "hand";
}

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 );
	
}

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)
{
	var loadW = 115; 
	var loadH = 29;
	var Lleft = l;
	var Ltop  = t;
	document.all.layLoading.style.pixelLeft = Lleft+(w-loadW)/2;
	document.all.layLoading.style.pixelTop  = Ltop+(h-loadH)/2;
}


function lcCreateMaskLayer(layerName,iLeft,iTop,iWidth,iHeight,content)
{
	if (document.all) {
		document.writeln('<div id="' + layerName + '" style="position:absolute; overflow:none; left:' + iLeft + 'px; top:' + iTop + 'px; width:' + iWidth + 'px; height:' + iHeight + 'px; visibility: visible; background-image: url(images/Pixel.gif); layer-background-image: url(images/Pixel.gif); border: 1px none #000000;">');
		document.writeln(content);
		document.writeln('</div>');
	}
}
