//限制只能输入数字
function checkInputNum(){
	return true;
	var key = event.keyCode;
	if(key >= 7 && key <= 40)return true;
	if((key >= 48 && key <= 57) || key == 8 || key == 46)return true;
	event.returnValue = false;
	return false;
}

function padLeft(value, length){
	value = value.toString();
	for(var i=value.length; i<length; i++){
		value = "0" + value;
	}
	return value;
}
function replace(value,find,reValue){
	find = find.replace(/\\/g,"\\\\");
	find = find.replace(/\$/g,"\\$");
	find = find.replace(/\*/g,"\\*");
	find = find.replace(/\{/g,"\\{");
	find = find.replace(/\}/g,"\\}");
	find = find.replace(/\+/g,"\\+");
	find = find.replace(/\?/g,"\\?");
	var r = new RegExp(find,"g");
	return value.replace(r,reValue);
}
function trimStart(value, c){
	if(c == undefined)c = ' ';
	var r = new RegExp("^" + c + "+","g");
	value = value.toString().replace(r,"");
	return value;
}
function trim(value,c){
	if(c == undefined)c = ' ';
	var r = new RegExp("^" + c + "+|" + c + "+$","g");
	value = value.replace(r,"");
	return value;
}
function toInt(value){
	if(typeof(value) == 'number')return Math.round(value);
	if(value == undefined)return 0;
	value = trimStart(value,"0")
	if(value == "")return 0;
	if(isNaN(value))return 0;
	return parseInt(value);
}
function htmlEncode(text){
	text = text.replace(/&/g, "&amp;") ;
	text = text.replace(/"/g, "&quot;") ;
	text = text.replace(/</g, "&lt;") ;
	text = text.replace(/>/g, "&gt;") ;
	text = text.replace(/'/g, "&#146;") ;

	return text ;
}
//判断是否符合某个模式匹配
function isMatch(value,length,pattern){
	if(value == null)return false;
	if(length == 0 && value.length == 0){
		return true;
	}else if(length > 0 && value.length < length){
		return false;
	}

	var r = new RegExp(pattern,"ig");
	return r.test(value);
}
//取得扩展名称
function getExt(str){
	var intStart;if(str=="")return "";intStart=str.lastIndexOf(".");if(intStart==-1)return "";return str.substr(intStart+1).toLowerCase();
}
//是否图片文件
function isValidImage(fileName){
	var ipos = fileName.lastIndexOf('.');
	if(ipos < 1)return false;
	var ext = fileName.substring(ipos+1).toLowerCase();
	switch(ext){
		case "jpg":
		case "jpeg":
		case "png":
		case "gif":
		case "bmp":
			return true;
		default:
			return false;
	}
}
//检查文件扩展名
function CheckFileExt(strExt,AllowExt){
	//AllowExt = "jpg,gif,png,bmp,jepg";

	AllowExt = "," + AllowExt + ",".toLowerCase();
	strExt = "," + strExt + ",".toLowerCase();

	return (AllowExt.indexOf(strExt)==-1)?false:true;
}
//获取某个对象
function Get$(id){
	var o = null;
	for(var i=0; i<document.forms.length; i++){
		o = document.forms(i).item(id);
		if(o != null)return o;
	}
	if(o == null){
		o = document.getElementById(id);
	}
	return o;
}

//设置radio或checkbox控件的值
function setRadio(id,value){
	var radio = Get$(id);
	if(radio == null || value == undefined)return;

	value = value.toString().toLowerCase();
	if(radio.length == undefined){
		if(radio.type != "radio" && radio.type != "checkbox")return;
		radio.checked = (radio.value.toLowerCase() == value);
	}else{
		for(var i=0; i<radio.length; i++){
			if(radio[i].type == "radio" || radio[i].type == "checkbox"){
				radio[i].checked = (radio[i].value.toLowerCase() == value);
			}
		}
	}
}

function setRadioAll(value,id){
	var radio = Get$(id);
	if(radio == null)return;
	
	if(radio.length == undefined){
		if(radio.type != "radio" && radio.type != "checkbox")return;
		radio.checked = value;
	}else{
		for(var i=0; i<radio.length; i++){
			if(radio[i].type == "radio" || radio[i].type == "checkbox"){
				radio[i].checked = value;
			}
		}
	}
}

function isCheckRadioBox(id){
	var radio = Get$(id);
	if(radio == null)return false;
	
	var flag = false;
	if(radio.length == undefined){
		if(radio.type != "radio" && radio.type != "checkbox")return false;
		flag = radio.checked;
	}else{
		for(var i=0; i<radio.length; i++){
			if(radio[i].type == "radio" || radio[i].type == "checkbox"){
				if(radio[i].checked){
					flag = true;
					break;
				}
			}
		}
	}
	return flag;
}

function checkSubmitTodo(id,todo,message){
	if(!isCheckRadioBox(id))return false;
	
	Get$("todo").value = todo;
	if(message != undefined && message != null && message != "")return confirm(message);
	return true;
}

function checkSubmitToDele(id){
	if(isCheckRadioBox(id)){
		return confirm("是否确认要删除所有选择的记录？");
	}
	return false;
}

function showBoolean(value,yes,no){
	if(value == "1" || value.toLowerCase() == "true"){
		document.write(yes);
	}else{
		document.write(no);
	}
}

function toGoBack(){
	var o = Get$('refferurl');
	if(o == null){
		history.back(1);
		return;
	}else{
		self.location.href = o.value;
		return;
	}
}

function showBindName(bindName){
	if(bindName.length < 1){
		document.write('无');
	}else{
		document.write('<a href="http://' + bindName + '.oiwm.com" target="_blank">' + bindName + '.oiwm.com</a>');
	}
}
