﻿//#########################################################################
//#                                 JS                                    #
//#            程启明  Www.Ucolo.Cn badboy45@126.com,ucolo@126.com         #
//#########################################################################

//滚轮控制图片大小
function AutoImg(ImgD,iwidth,iheight) {
     var image=new Image();
     image.src=ImgD.src;
     if(image.width>0 && image.height>0){
        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;
            }
　　　　　ImgD.style.cursor= "pointer"; //改变鼠标指针
　　　　　ImgD.onclick = function() { window.open(this.src);} //点击打开大图片
　　　　if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器，如果是IE
　　　　　　ImgD.title = "请使用鼠标滚轮缩放图片，点击图片可在新窗口打开";
　　　　　　ImgD.onmousewheel = function img_zoom() //滚轮缩放
　　　　　 {
　　　　　　　　　　var zoom = parseInt(this.style.zoom, 10) || 100;
　　　　　　　　　　zoom += event.wheelDelta / 12;
　　　　　　　　　　if (zoom> 0)　this.style.zoom = zoom + "%";
　　　　　　　　　　return false;
　　　　　 }
　　　  } else { //如果不是IE
　　　　　　　     ImgD.title = "点击图片可在新窗口打开";
　　　　　　   }
    }
}


//控制图片在某个范围内
function SizeImg(ImgD,iwidth,iheight) {
     var image=new Image();
     image.src=ImgD.src;
     if(image.width>0 && image.height>0){
        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;
                }
        }
        else{
                if(image.height>iheight){
                       ImgD.height=iheight;
                       ImgD.width=(image.width*iheight)/image.height;
                }else{
                        ImgD.width=image.width;
                        ImgD.height=image.height;
                     }
            }
    }
}

//auto IFRAME
//style="height:expression(1); aho:expression(autoResize())"  id=
function autoResize()
{ try { document.all["test"].style.height=test.document.body.scrollHeight } catch(e){} }


//弹出窗口 根据图片大小改变WIDTH HEIGHT
//<img id="Badboy45.cn"> 
//OpenByImg(弹出窗口名称,，要弹出的图片地址，距上，距左)
function OpenByImg(WindowName,ImgUrl,Top,Left)
{
	var $=document.getElementById("Badboy45.cn"); 
	$.src=ImgUrl; 
	$.style.display="none";
	window.open(WindowName+"?ImgUrl="+ImgUrl,"","width="+$.width+",height="+$.height+",top="+Top+",left="+Left);
}



// HTML 获取传值  HtmlGet("id")
function HtmlGet(name){
	var str=window.location.search;
	if (str.indexOf(name)!=-1){
		var pos_start=str.indexOf(name)+name.length+1;
		var pos_end=str.indexOf("&",pos_start);
		if (pos_end==-1)
		{
			return str.substring(pos_start);
		}
		else
		{
			return str.substring(pos_start,pos_end)
		}
		}
	else{
		return "没有值";
	}
}

////双击鼠标滚动屏幕的代码
//var currentpos,timer;
//function initialize()
//{timer=setInterval ("scrollwindow ()",30);}
//function sc()
//{clearInterval(timer);}
//function scrollwindow()
//{currentpos=document.body.scrollTop;
//window.scroll(0,++currentpos);
//if (currentpos !=document.body.scrollTop)
//sc();}
//document.onmousedown=sc
//document.ondblclick=initialize

//全选
function CheckAll(form){
    for (var i=0;i<form.elements.length;i++){  
      var e = form.elements[i];
             e.checked = 1;
        }
} 

//全不选
function Checkzero(form){
    for (var i=0;i<form.elements.length;i++){  
      var e = form.elements[i];
             e.checked = 0;
        }
} 

function CheckBoxAll(o,btname){
	if(o==" 全  选 "){
		CheckAll(form);	
		document.getElementById(btname).value=" 全不选 ";
	}else{
		Checkzero(form);
		document.getElementById(btname).value=" 全  选 ";
	}		
}


function JumpUrl(o,num){
	if(o.value!=""){
		if(num==1){
			location.href=o;
		}else if(num==2){
			window.open(o);
		}
	}	
}

/*  留言本选择头像  */
function CheckFace(value)
{
	if(value.length>1)
	{
		document.getElementById("Face").src="Ubb/Book/"+value;
		}
	}
	
/*  Ubb  帮助  */
function showPopDiv(sSelectName)
{
	var sUrl
	if (sSelectName=='help')
	{
		sUrl='Ubb/help.html'
	}
	else if (sSelectName=='face')
	{
		sUrl='Ubb/face.html'
	}
	with (lookDiv.style)
	{	
		if(display!='block') display='block';
		posLeft=event.x-50;
		posTop=(document.body.clientHeight-parseFloat(height))/2-10;
	}	
	lookIfrmae.location.replace(sUrl);
}

/*  帮助关闭  */
function look_hiddenPopDiv()
{
	with (lookDiv.style)
	{	
		if(display=='block') display='none';
	}	
}

/*  提交留言  */
function CheckBook()
{
	str1=document.getElementById("username").value;
	str1=str1.replace(/\s+/g,"");
	str2=document.getElementById("title").value;
	str2=str2.replace(/\s+/g,"");
	str3=document.getElementById("message").value;
	str3=str3.replace(/\s+/g,"");
	str4=document.getElementById("code").value;
	str4=str4.replace(/\s+/g,"");
	if(str1.length<1){
		//document.getElementById("msg1").innerHTML="<img src='Ubb/err.gif'>";
		alert("请输入你的称呼");
		return false;
	}else if(str2.length<1)
	{
		//document.getElementById("msg1").innerHTML="";
		//document.getElementById("msg5").innerHTML="<img src='Ubb/err.gif'>";
		alert("请输入标题");
		return false;
	}else if(str3.length<1)
	{
		//document.getElementById("msg5").innerHTML="";
		//document.getElementById("msg6").innerHTML="<img src='Ubb/err.gif'>";
		alert("请输入内容");
		return false;	
	}else if(str4.length<1)
	{
		//document.getElementById("msg6").innerHTML="";
		//document.getElementById("msg7").innerHTML="<img src='Ubb/err.gif'>";
		alert("请输入验证码");
		return false;
	}else
	{
		return true;
		}
}

//body 图片大小控制在某范围内
function BodyImg(width)
{
   var myimg,oldwidth;
   var maxwidth=width;
   for(i=0;i<document.images.length;i++){
     myimg = document.images[i];
     if(myimg.width > maxwidth)
     {
        oldwidth = myimg.width;
        myimg.width = maxwidth;
        myimg.height = myimg.height * (maxwidth/oldwidth);
     }
   }
}

function chkzx(){
	var str1,str2;
	str1=document.getElementById("title").value;
	str2=document.getElementById("Message").value;
	str1=str1.replace(/\s+/g,"");
	str2=str2.replace(/\s+/g,"");
	if(str1.length<1){
		alert("请输入标题");
		return false;
	}else if(str2.length<2){
		alert("请输入内容");
		return false;
	}else{
		return true;	
	}
}