var count =0;
var isIE = navigator.appVersion.indexOf("MSIE")>-1;
var _imageLength=0;
var imgDiv;
var DE = document.documentElement;



function initIframe( b ){
	var doc =window.frames["mFrame"].document;
	if( doc == null )
	{
		setTimeout( initIframe, 100 );
	}

	if(b && !document.all ){
		var all = doc.getElementsByTagName("*");
		for( var i=all.length-1;i>-1;i--)
		{
			if( all[i].style.lineHeight=="8%" )
				all[i].style.lineHeight="";
		}
	}
	if(doc.body)
		doc.body.style.background="transparent";
	var height ;
	try{
		height= Math.max( doc.documentElement.scrollHeight||0,doc.body.scrollHeight||0);
	}catch( PermissionException ){return ;}
	
	if( height < 400 )
		height = 400;
	if( height-10 > initIframe.height)
	{
		document.getElementById("mFrame").style.height = height+"px";
		initIframe.height = height;
	}
	clearTimeout( initIframe.timer ) ;
	if( !b )
		initIframe.timer = setTimeout( initIframe, 1000 );
}
initIframe.timer = -1;
initIframe.height=0;

/*
function initIframe()
{
	if( !isIE )
	{
		//alert(2);
		window.frames[0].document.body.innerHTML = 
			window.frames[0].document.body.innerHTML.replace(/line-height\s*:\s*8%/ig,"");
		
		
	}
}
function fixFrameHeight(){
   try{
		var frame = document.getElementById("mFrame");
		var td =frame.parentNode;
		var doc = window.frames["mFrame"].document;
		
		//调整页面高度，以完全显示页面内容
		var height = Math.max( doc.body.scrollHeight , doc.documentElement.scrollHeight);
		var width = Math.max( doc.body.scrollWidth , doc.documentElement.scrollWidth);
		if(frame.offsetHeight < height)
		{
			frame.style.height = (height+40)+"px";
		}
		else if(frame.offsetHeight>height+50){
				frame.style.height = Math.max(height+50,350)+"px";
			
		}
		
		
		
		////////////////
		//  图片点击放大　
		////////////////
		//for IE
		if(isIE)
		{
			doc.onclick = doc_click;
		}
		else{
			//for others,IE中无效
			var images = doc.getElementsByTagName("img");
			
			if(images.length > _imageLength)
			{
				
				for(var i=0;i<images.length;i++)
				{
					images[i].onclick = enlargeImage;
					
				}
				_imageLength = images.length;
			}
		}
   }catch(ex){
   		window.errMessage=ex.description;
   }
}
*/
/**
 * IE 使用的是shape来显示图片，所以作特殊处理
 */
function doc_click(){
	if(!isIE)
		return;
	var src = window.frames[0].event.srcElement;
	if(String.prototype.toLocaleLowerCase.call( src.tagName ) =="shape")
	{
		var html = window.frames[0].event.srcElement.innerHTML.toLowerCase();
		if( /<v:imagedata([^>]+)src\s*=\s*"([^"]+)"/.test(html))
		{
			var imgurl = RegExp.$2
			showImage( imgurl );
		}
		else{
			//alert( html);
		}
	}
	else{
		//alert( src.tagName );
	}
	
}
function enlargeImage(){
	//v:shape 中的imagedata　图片为大图 ,以下代码为提取v:shape中的v:中的imagedata 的图片路径
	var img = this;
	var shapeid = img.getAttribute("v:shapes");
	var html = window.frames[0].document.body.innerHTML;
	var index1 = html.indexOf( shapeid );
	var index2 = html.indexOf(shapeid,index1+10);
	if(index2>index1)
	{
		html = html.substring( index1, index2);
		/imagedata[^>]+src="([^"]*)"/.test(html);
		var src = RegExp.$1;
		//alert(src);
		showImage( src );
		return;
	}
	else{
	}
	showImage( img.src );
}
function showImage(src){
	if(  !(  /^\//.test( src )  ) &&  !( /^[a-z]+:/i.test( src )  )  )
	{
		src = window.frames[0].document.URL
				.replace(/[^\\\/]+$/,"")
				+ src ;
	}
	if(!imgDiv)
	{
		imgDiv = document.createElement("div");
		document.body.appendChild(imgDiv);
	}
	imgDiv.innerHTML ="";
	imgDiv.id = "imgBgDiv";
	imgDiv.onclick = hideLargeImage;
	
	var bg = document.createElement("div");
	imgDiv.appendChild(bg);
	bg.className ="bg";
	imgDiv.style.display = "block";
	
	var bigimg = document.createElement("img");
	imgDiv.appendChild( bigimg );
	bigimg.style.top = Math.max(DE.scrollTop , document.body.scrollTop)   + "px";
	bigimg.style.left = Math.max(DE.scrollLeft , document.body.scrollLeft)  + "px";
	bg.style.height = 
	imgDiv.style.height = Math.max( DE.scrollHeight , document.body.scrollHeight) +"px";
	
	bigimg.onload = bigImg_onload;
	bigimg.src = src;
	
	
}
function bigImg_onload(){
	var img = this;
	var ctnrHeight = DE.clientHeight;
	var ctnrWidth = DE.clientWidth;
	//img.style.maxWidth = ctnrWidth+"px";
	//img.style.maxHeight = ctnrHeight+"px";
	img.style.marginTop = ( ctnrHeight - img.height )/2 + "px";
	img.style.marginLeft = ( ctnrWidth - img.width )/2 + "px";
	
	
}
function hideLargeImage(){
		imgDiv.innerHTML = "";
		imgDiv.style.display = "none";
}





function $(){return document.getElementById(arguments[0]);}


