﻿function DrawImage(ImgD,ImgWidth,ImgHeight)
{//按比例缩小图片
	var flag=false;
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0 && ImgWidth>0 && ImgHeight>0)
	{
		flag=true;
		if(image.width/image.height>= ImgWidth/ImgHeight)
		{
			if(image.width>ImgWidth)
			{ 
				ImgD.width=ImgWidth;
				ImgD.height=(image.height*ImgWidth)/image.width;
			}
			else
			{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}
		else
		{
			if(image.height>ImgHeight)
			{ 
				ImgD.height=ImgHeight;
				ImgD.width=(image.width*ImgHeight)/image.height; 
			}
			else
			{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}
	}
}

//
//设置菜单()
//obj----对象
//type---类型(1、改变，2、恢复)
function setmenu(obj,type)
{
	if(obj==null) return;
	if(type==1)
		obj.className='p2';
	else if (type==3)
		obj.className='p4';
	else if (type==4)
		obj.className='p3';		
	else
		obj.className='';
}

//
//设置菜单()
//obj----对象
//s----要改变的样式
//type---类型(1、改变，2、恢复)
function setStyle(obj,s,type)
{
	if(obj==null) return;
	if(type==1)
		obj.className=s;
	else
		obj.className=s;
}

//
//设置菜单()
//obj----对象
//s----样式
function getKh(obj,s)
{
	document.getElementById(obj).className=s;
}

//
//设置投票()
function setVote(id,type,str)
{
  alert("投票成功");  
	document.getElementById("vote_"+id+"_"+type).innerHTML=str;
	parent.whc_Modal.Close();
}

function pr_onfocus(obj)
{
	if(obj.value=="型号/名称")
		obj.value="";
}

function pr_onblur(obj)
{
	if(obj.value=="")
		obj.value="型号/名称";
}

function goto(s)
{
	location.href="../"+s+"/index.html";
}

//
//查询工程案例
//----headUrl---链接地址的头部(../)
function searchCase(headUrl)
{
	location.href=headUrl+"case/search.aspx?ClassID="+document.getElementById("case_dwlClassID").value+"&regionID="+document.getElementById("case_dwlRegionID").value+"&keyword="+escape(document.getElementById("case_txtKeyword").value);
	return false;
}

//
//查询产品
//----headUrl---链接地址的头部(../)
function searchProduct(headUrl)
{
	var keyword = document.getElementById("txtProductKeyword").value;
	if(keyword=="型号/名称") 	keyword="";
	location.href=headUrl+"product/search.aspx?ClassID="+document.getElementById("dwlProductClassID").value+"&specID="+document.getElementById("dwlSpecID").value+"&useID="+document.getElementById("dwlProductUseID").value+"&keyword="+escape(keyword);
	return false;
}

//
//查询销售网络
//----headUrl---链接地址的头部(../)
function searchNetwork(headUrl)
{
	var keyword = document.getElementById("network_txtKeyword").value;
	location.href=headUrl+"network/search.aspx?regionID="+document.getElementById("network_dwlRegionID").value+"&keyword="+escape(keyword);
	return false;
}

//
//查询资讯
//----headUrl---链接地址的头部(../)
function searchInfo(headUrl)
{
	var keyword = document.getElementById("txtInfoKeyword").value;
	location.href=headUrl+"info/search.aspx?ClassID="+document.getElementById("dwlInfoClassID").value+"&keyword="+escape(keyword);
	return false;
}

//
//查询企业荣誉
//----headUrl---链接地址的头部(../)
function searchHonor(headUrl)
{
	location.href=headUrl+"honor/search.aspx?keyword="+escape(document.getElementById("honor_txtKeyword").value);
	return false;
}


function getEvent() //获取event对象,同时兼容ie和ff的写法 
{  
	if(document.all)  return window.event;    
	func=getEvent.caller;        
	while(func!=null){  
		var arg0=func.arguments[0]; 
		if(arg0) 
		{ 
		  if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) 
		  {  
		  return arg0; 
		  } 
		} 
		func=func.caller; 
	} 
	return null; 
}

function showMaxImage(MaxImage)
{//根据鼠标位置显示对象,参数ev为event
	var ObjX,ObjX1,ObjY,ObjY1;//对象的位置(x,y)
	var mouseWidth=20;//对象的(x)水平位置距离鼠标的宽度
	var mouseHeight=20;//对象的(y)垂直位置距离鼠标的高度
	var mouseX;//鼠标的x坐标
	var mouseY;//鼠标的y坐标
	var scrollTop = 0;//网页被卷去的高
	var dialog_height=400;//对话框的高度
	var dialog_width=600;//对话框的宽度	
    var scrollTop = document.documentElement.scrollTop||document.body.scrollTop;
	var scrollLeft = document.documentElement.scrollLeft||document.body.scrollLeft;
	var clientHeight = document.documentElement.clientHeight||document.body.clientHeight;
	var clientWidth = document.documentElement.clientWidth||document.body.clientWidth;	
	
	var obj = document.getElementById("maxImage_dialog");//对话框对象	

	var event = getEvent();
	if(event.pageX || event.pageY)
	{//firefox鼠标的位置
		mouseX = event.pageX;
		mouseY = event.pageY;
	}
	else
	{//IE鼠标的位置				
		mouseX = event.clientX + scrollLeft- document.body.clientLeft;
		mouseY = event.clientY + scrollTop - document.body.clientTop;		
	}
	
	ObjX = mouseX;
	ObjY = mouseY;	
	
	var height2 = scrollTop+clientHeight-ObjY;
	width1 = ObjX+dialog_width;
	if(height2<dialog_height && width1>clientWidth)
	{
		ObjY = ObjY-dialog_height;
		if(ObjY<scrollTop) ObjY = scrollTop;
		ObjX = ObjX-dialog_width-mouseWidth;
	}
	else if(height2<dialog_height)
	{
		ObjY = ObjY-dialog_height;
		if(ObjY<scrollTop) ObjY = scrollTop;
		ObjX = ObjX+mouseWidth;
	}
	else if(width1>clientWidth)
	{		
		ObjX = ObjX-dialog_width;
		height2 = height2+mouseHeight;
		if(height2<dialog_height)
			ObjY = ObjY+(dialog_height-height2);
		else
			ObjY = ObjY+mouseHeight;
	}
	else
		ObjY = ObjY+mouseHeight;

	obj.style.left = ObjX + 'px';
	obj.style.top = ObjY + 'px';	
	
	if(MaxImage!="") obj.innerHTML="<img src=\""+MaxImage+"\" height=\"400\" onload=\"DrawImage(this,600,400)\">";
	obj.style.display='';//显示或隐藏对象
}

function hideMaxImage()
{
	document.getElementById("maxImage_dialog").style.display='none';
}

function showNetwork(id)
{//根据鼠标位置显示对象,参数ev为event
	var ObjX,ObjX1,ObjY,ObjY1;//对象的位置(x,y)
	var mouseWidth=20;//对象的(x)水平位置距离鼠标的宽度
	var mouseHeight=20;//对象的(y)垂直位置距离鼠标的高度
	var mouseX;//鼠标的x坐标
	var mouseY;//鼠标的y坐标
	var scrollTop = 0;//网页被卷去的高
	var dialog_height=400;//对话框的高度
	var dialog_width=500;//对话框的宽度	
    var scrollTop = document.documentElement.scrollTop||document.body.scrollTop;
	var scrollLeft = document.documentElement.scrollLeft||document.body.scrollLeft;
	var clientHeight = document.documentElement.clientHeight||document.body.clientHeight;
	var clientWidth = document.documentElement.clientWidth||document.body.clientWidth;
	var objName = "network_dialog";
	var obj = document.getElementById(objName);//对话框对象	

	var event = getEvent();
	if(event.pageX || event.pageY)
	{//firefox鼠标的位置
		mouseX = event.pageX;
		mouseY = event.pageY;
	}
	else
	{//IE鼠标的位置				
		mouseX = event.clientX + scrollLeft- document.body.clientLeft;
		mouseY = event.clientY + scrollTop - document.body.clientTop;		
	}
	
	ObjX = mouseX;
	ObjY = mouseY;	
	
	var height2 = scrollTop+clientHeight-ObjY;
	width1 = ObjX+dialog_width;
	if(height2<dialog_height && width1>clientWidth)
	{
		ObjY = ObjY-dialog_height;
		if(ObjY<scrollTop) ObjY = scrollTop;
		ObjX = ObjX-dialog_width-mouseWidth;
	}
	else if(height2<dialog_height)
	{
		ObjY = ObjY-dialog_height;
		if(ObjY<scrollTop) ObjY = scrollTop;
		ObjX = ObjX+mouseWidth;
	}
	else if(width1>clientWidth)
	{		
		ObjX = ObjX-dialog_width;
		height2 = height2+mouseHeight;
		if(height2<dialog_height)
			ObjY = ObjY+(dialog_height-height2);
		else
			ObjY = ObjY+mouseHeight;
	}
	else
		ObjY = ObjY+mouseHeight;

	obj.style.left = ObjX + 'px';
	obj.style.top = ObjY + 'px';
	obj.style.display='';//显示或隐藏对象
	getInfo("getNetwork.aspx?regionID="+id,objName);
	//if(MaxImage!="") obj.innerHTML="<img src=\""+MaxImage+"\">";
	document.getElementById("network_dwlRegionID").style.display='none';
}

function hideNetwork()
{
	document.getElementById("network_dialog").style.display='none';
	document.getElementById("network_dwlRegionID").style.display='';
}
