//运行文本域代码
function runCode(obj) {
	var winname = window.open('', "_blank", '');
	winname.document.open('text/html', 'replace');
	winname.opener = null // 防止代码对页面修改
	winname.document.write(obj.value);
	winname.document.close();
}
function saveCode(obj) {
	var winname = window.open('', '_blank', 'top=10000');
	winname.document.open('text/html', 'replace');
	winname.document.write(obj.value);
	winname.document.execCommand('saveas','','code.htm');
	winname.close();
}
function copycode(obj) {
	obj.select(); 
	js=obj.createTextRange(); 
	js.execCommand("Copy")
}

//控制图片大小(等比缩放)
function ResizePic(ImgTag,x_Width,x_Height) 
{ 
	var image = new Image(); 
	var FitWidth = x_Width; //图片宽度 
	var FitHeight = x_Height; //图片高度 
	image.src = ImgTag.src; 
	if(image.width>0 && image.height>0){ 
	if(image.width/image.height >= FitWidth/FitHeight){ 
		if(image.width > FitWidth){ 
			ImgTag.width = FitWidth; 
			ImgTag.height = (image.height*FitWidth)/image.width; 
		} 
		else{ 
			ImgTag.width = image.width; 
			ImgTag.height = image.height; 
		} 
		} 
		else{ 
			if(image.height > FitHeight){ 
				ImgTag.height = FitHeight; 
				ImgTag.width = (image.width*FitHeight)/image.height; 
			} 
			else{ 
				ImgTag.width = image.width; 
				ImgTag.height = image.height; 
			} 
		} 
	} 
}

//图片缩放
function resizeimg(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 = "点击图片可在新窗口打开";
　　　　　　   }
    }
}

//读取cookie
function getCookie(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{
			c_start = c_start + c_name.length + 1;
			c_end   = document.cookie.indexOf(";",c_start);
			if (c_end == -1)
			{
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return null;
}

//设置cookie
function setCookie(c_name,value,expiredays)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); //使设置的有效时间正确。增加toGMTString()
}

//检查是否为数字
function OnDigit(){
	 return ((event.keyCode >= 48) && (event.keyCode <= 57));
}

//放大和缩小字体
function doZoom(size){ 
var obj=document.getElementById("list");
obj.style.fontSize=size+"px";
}

//ubb编辑器
function SetDiyContent(oTextarea,strText){   
	oTextarea.focus();
	document.selection.createRange().text+=strText;
	return;
	oTextarea.blur();
}

//ubb编辑器
function getContent(oTextarea,str1,str2) {
	oTextarea.focus();
	var oTextRange=document.selection.createRange();
	if(oTextRange.text!="") {
		oTextRange.text = str1+oTextRange.text+str2;
	}
	return;
	oTextarea.blur();
}

//tab选项卡
function tabit(btn){
	var idname = new String(btn.id);
	var s = idname.indexOf("_");
	var e = idname.lastIndexOf("_")+1;
	var tabName = idname.substr(0, s);
	var id = parseInt(idname.substr(e, 1));
	var tabNumber = btn.parentNode.childNodes.length;
	for(i=0;i<tabNumber;i++){
			document.getElementById(tabName+"_div_"+i).style.display = "none";
			document.getElementById(tabName+"_btn_"+i).className = "";
		}
		document.getElementById(tabName+"_div_"+id).style.display = "block";
		btn.className = "current";
}

//校验是否全由数字组成 
function isDigit(s) 
{ 
var patrn=/^[0-9]{1,20}$/; 
if (!patrn.exec(s)) return false 
return true 
}

//校验邮箱是否合法
function isMail(s)
{ 
var patrn=/^([a-zA-Z0-9]+[_|\_|\.|-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
if (!patrn.exec(s)) return false 
return true 
}

//校验登录名：只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
function isRegisterUserName(s) 
{ 
var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/; 
if (!patrn.exec(s)) return false 
return true 
}

//校验用户姓名：只能输入1-30个以字母开头的字串 
function isTrueName(s)
{ 
var patrn=/^[a-zA-Z]{1,30}$/; 
if (!patrn.exec(s)) return false 
return true 
}

//校验密码：只能输入6-20个字母、数字、下划线 
function isPasswd(s) 
{ 
var patrn=/^(\w){6,20}$/; 
if (!patrn.exec(s)) return false 
return true 
}

//校验普通电话、传真号码：可以“+”开头，除数字外，可含有“-” 
function isTel(s) 
{ 
//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/; 
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false 
return true 
}

//校验手机号码：必须以数字开头，除数字外，可含有“-” 
function isMobil(s)
{ 
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/; 
if (!patrn.exec(s)) return false 
return true 
}

//校验邮政编码 
function isPostalCode(s) 
{ 
//var patrn=/^[a-zA-Z0-9]{3,12}$/; 
var patrn=/^[a-zA-Z0-9 ]{3,12}$/; 
if (!patrn.exec(s)) return false 
return true 
}
