//简化定义对像
function $byid(objectId) {
if(document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId);// W3C DOM
    } else if (document.all && document.all(objectId)) {
        return document.all(objectId);// MSIE 4 DOM
    } else if (document.layers && document.layers[objectId]) {
        return document.layers[objectId];// NN 4 DOM.. note: this won't find nested layers
    } else {
        return false;
    }
}

//查找网页内宽度太大的图片进行缩放
function ReBigImgSize(w){
	if (w==null)w=600;
	for (i=0;i<document.images.length;i++)
	{
		if (document.all){
			if (document.images[i].width>w)
			{
				document.images[i].width=w;
				document.images[i].border=0;
				try{
				document.images[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank">'+document.images[i].outerHTML+'</a>'
				}catch(e){}
			}
		}
		else
		{
			if (document.images[i].width>400) {
			document.images[i].style.cursor="pointer"
			document.images[i].onclick=function(e){window.open(this.src)}
			}
		}
	}
}

function setCookie(name,value,d)//两个参数，一个是cookie的名子，一个是值
{
   // var Days = 30; //此 cookie 将被保存 30 天
   var Days = arguments[2] || 30;
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return "";

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

//显示数字时，两位小数，每三个数字用逗号隔开
function setCurrency(str){   
s=str
if(/[^0-9\.\-]/.test(s))   return   "invalid   value";   
s=s.replace(/^(\d*)$/,"$1.");   
s=(s+"00").replace(/(\d*\.\d\d)\d*/,"$1");   
s=s.replace(".",",");   
var   re=/(\d)(\d{3},)/;   
while(re.test(s))   
s=s.replace(re,"$1,$2");   
s=s.replace(/,(\d\d)$/,".$1");   
s=s.replace(/^\./,"0.");   
return s;   
}   
//获取radio的值
function getRadiovalue(obj){

	var f_radiolen=obj.length;
	for(i=0;i<f_radiolen;i++)   
    {   
     if(obj[i].checked)
          return obj[i].value;
    }
}
//图片按比例缩放 
var flag=false; 
function DrawImage(ImgD,iwidth,iheight){ 
//参数(图片,允许的宽度,允许的高度) 
var image=new Image(); 
image.src=ImgD.src; 
if(image.width>0 && image.height>0){ 
flag=true; 
if(image.width/image.height>= iwidth/iheight){ 
if(image.width>iwidth){ 
ImgD.width=iwidth; 
ImgD.height=(image.height*iwidth)/image.width; 
}else{ 
ImgD.width=image.width; 
ImgD.height=image.height; 
} 
ImgD.alt=image.width+"×"+image.height; 
} 
else{ 
if(image.height>iheight){ 
ImgD.height=iheight; 
ImgD.width=(image.width*iheight)/image.height; 
}else{ 
ImgD.width=image.width; 
ImgD.height=image.height; 
} 
ImgD.alt=image.width+"×"+image.height; 
} 
} 
} 


//显示背景为暗色的浮动层
function showfontwindow(url,jhwidth,jhheight)
{
	showForbid();
	document.getElementById("fontwindow").style.display='block';
	document.getElementById("fontwindow1").style.width=jhwidth;
	document.getElementById("fontwindow1").style.height=jhheight;
	document.getElementById("fontwindow").style.top=document.documentElement.scrollTop+(document.documentElement.clientHeight/2-jhheight/2)+"px";
	document.getElementById("fontwindow").style.left=document.documentElement.scrollLeft+20+"px";
	document.getElementById("fontwindowiframe").src=url;
	document.getElementById("fontwindowiframe").style.height=jhheight-30;
	var faqsdivtxt="";
	
	document.getElementById("faqsdiv").innerText=faqsdivtxt;
}
function showForbid()
{
	document.getElementById("forbid").style.width = document.body.clientWidth+"px";
	document.getElementById("forbid").style.height = document.body.scrollHeight+"px";
	document.getElementById("blackimg").style.width = document.body.clientWidth+"px";
	document.getElementById("blackimg").style.height = document.body.scrollHeight+"px";
	if (document.getElementById("forbid").style.display=="")
	document.getElementById("forbid").style.display="none";
	else
	document.getElementById("forbid").style.display = "";
	
}

//hidden
function hidefontwindow()
{
	showForbid();
	document.getElementById("fontwindow").style.display='none';
	document.body.style.overflowX='hidden';
	document.body.style.overflowY='auto';
	document.getElementById("fontwindowiframe").src="about:blank";

	return false;
}

function SetCwinHeight(obj)
{
  var cwin=obj;
  if (document.getElementById)
  {
    if (cwin && !window.opera)
    {
      if(cwin.Document && cwin.Document.body.scrollHeight)
	  {
        cwin.height = cwin.Document.body.scrollHeight + 10;//IE
		}

      else if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
        {
		cwin.height = cwin.contentDocument.body.offsetHeight + 20; //FF NS
		
		}

    }
    else
    {
        if(cwin.contentWindow.document && cwin.contentWindow.document.body.scrollHeight)
            cwin.height = cwin.contentWindow.document.body.scrollHeight;//Opera
    }
  }
}


