
var isIE = navigator.userAgent.indexOf("MSIE") > 0;
var Element = {setStyle:function (element, styles, camelized) {
	element = $(element);
	var elementStyle = element.style;
	for (var property in styles) {
		elementStyle[property] = styles[property];
	}
	return element;
}, visible:function (element) {
	element = $(element);
	return element.style.display != "none";
}, hide:function (element) {
	for (var i = 0; i < arguments.length; i++) {
		element = $(arguments[i]);
		element.style.display = "none";
	}
	return element;
}, show:function (element) {
	for (var i = 0; i < arguments.length; i++) {
		element = $(arguments[i]);
		element.style.display = "";
	}
	return element;
}, remove:function (element) {
	element = $(element);
	element.parentNode.removeChild(element);
}, getStyle:function (element, style) {
	var value = $(element).style[style];
	return value == "auto" ? null : value;
}};


//html parameter define;

String.prototype.isNumber = function (a) {
	var r = 0, reg = /^\d+$/;
	if (a == 1) {
		reg = /^\d+\.\d{2}$/;
	}
	if (this.match(reg)) {
		r = 1;
	}
	return r;
};
function getParameter(name, s) {
	s = s || window.location.href;
	return s.parameter(name);
}
function forword(u) {
	window.location.href = u;
}

//empty
function isEmpty() {
	var args = arguments, object = null;
	for (var i = 0; i < args.length; i++) {
		object = args[i];
		if (!object) {
			return true;
		}
		if (typeof (object) == "string") {
			if (object == "" || object == null) {
				return true;
			}
		}
	}
	return false;
}

//选中单选按纽值 
function setRaido(name, value) {
	var raidos = document.getElementsByName(name);
	for (var i = 0; i < raidos.length; i++) {
		if (raidos[i].value == value) {
			raidos[i].checked = true;
		}
	}
}



//得到复选框的值
function getCheckBoxValues(checkId) {
	var checks = document.getElementsByName(checkId);
	var args = "", common = "";
	for (var i = 0; i < checks.length; i++) {
		if (checks[i].checked) {
			args += common + checks[i].value;
			common = ",";
		}
	}
	return args;
}
function getCheckBoxValue(checkId) {
	var checks = document.getElementsByName(checkId);
	var args = "";
	for (var i = 0; i < checks.length; i++) {
		if (checks[i].checked) {
			return args = checks[i].value;
		}
	}
	return args;
}

//通过Id判断是否选择复选框
function isCheckBox(checkId) {
	var checks = document.getElementsByName(checkId);
	for (var i = 0; i < checks.length; i++) {
		if (checks[i].checked) {
			return true;
		}
	}
	return false;
}

//选择所有复选框
function checkall(form, checkboxName) {
	var num = 0;
	for (var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if (e.type == "checkbox" && e.name == checkboxName) {
			e.checked = form.addall.checked;
		}
	}
}
//选择所有复选框
function checkAll(selfCheck, checkboxName) {
	var num = 0;
	var elements = document.getElementsByName(checkboxName);
	for (var i = 0; i < elements.length; i++) {
		var e = elements[i];
		if (e.type == "checkbox" && (e.name == checkboxName || e.id == checkboxName)) {
			e.checked = selfCheck.checked;
		}
	}
}

//得到单选按纽的值
function getRadioValue(name) {
	var radios = document.getElementsByName(name);
	for (var i = 0; i < radios.length; i++) {
		if (radios[i].type == "radio" && radios[i].checked) {
			return radios[i].value;
		}
	}
	return null;
}
function isRadio(name) {
	var radios = document.getElementsByName(name);
	for (var i = 0; i < radios.length; i++) {
		if (radios[i].type == "radio" && radios[i].checked) {
			return true;
		}
	}
	return false;
}
//get raido input value
function getRadioValue(name) {
	var radios = document.getElementsByName(name);
	for (var i = 0; i < radios.length; i++) {
		if (radios[i].type == "radio" && radios[i].checked) {
			return radios[i].value;
		}
	}
	return null;
}
function checkedRadioByValue(name, value) {
	var radios = document.getElementsByName(name);
	for (var i = 0; i < radios.length; i++) {
		if (radios[i].type == "radio" && radios[i].value == value) {
			radios[i].checked = true;
			return;
		}
	}
}
function createRadio(element, value, onclick) {
	if (isIE) {
		radio = "<input type='radio' name='" + element + "' id='" + element + "' value='" + value + "' onclick='" + onclick + "'>";
		radio = document.createElement(radio);
	} else {
		var radio = document.createElement("input");
		radio.type = "radio";
		radio.id = element;
		radio.name = element;
		radio.value = value;
		radio.onclick = new Function("'" + onclick + "'");
	}
	return radio;
}

//substring String,defualt length 20;
function substr(string, len) {
	if (!len) {
		len = 20;
	}
	if (string) {
		if (string.length <= len) {
			return string;
		} else {
			var subString = string.substring(0, len);
			return subString + "......";
		}
	} else {
		return string;
	}
}
function inline(id) {
	var args = id.split(",");
	for (var i = 0; i < args.length; i++) {
		var obj = document.getElementById(args[i]);
		obj.style.display = "inline";
	}
}
function none(id) {
	var args = id.split(",");
	for (var i = 0; i < args.length; i++) {
		var obj = document.getElementById(args[i]);
		obj.style.display = "none";
	}
}
function changeStyle(id) {
	var obj = document.getElementById(id);
	if (obj.style.display == "inline") {
		obj.style.display = "none";
	} else {
		obj.style.display = "inline";
	}
}
function chkCheckBoxChs(objNam) {
	var obj = document.getElementsByName(objNam);
	var objLen = obj.length;
	var i;
	objYN = false;
	for (i = 0; i < objLen; i++) {
		if (obj[i].checked == true) {
			objYN = true;
			break;
		}
	}
	return objYN;
}

//得到年中月的最大天
function getMaxDay(year, month) {
	if ((year != null) && (month != null)) {
		year = parseInt(year);
		month = parseInt(month);
	} else {
		return;
	}
	var check4 = (0 == year % 4);
	var check100 = (0 == year % 100);
	var check400 = (0 == year % 400);
	var day;
	if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)) {
		day = "31";
	} else {
		day = "30";
	}
	if ((check4 && !check100) || check400) {
		if (month == 2) {
			day = "29";
		}
	} else {
		if (month == 2) {
			day = "28";
		}
	}
	return day;
}
function cleanText(_ID) {
	_form = document.getElementById(_ID);
	if (_form == null) {
		_form = document.getElementsByName(_ID)[0];
	}
	if (_form != null) {
		var size = _form.elements.length;
		for (var i = 0; i < size; i++) {
			_element = _form.elements[i];
			if (_element.type == "text" || _element.type == "textarea") {
				_element.value = "";
			}
		}
	}
}
Date.prototype.format = function (format) {
	var o = {"M+":this.getMonth() + 1, "d+":this.getDate(), "h+":this.getHours(), "m+":this.getMinutes(), "s+":this.getSeconds(), "q+":Math.floor((this.getMonth() + 3) / 3), "S":this.getMilliseconds()};
	if (/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
};
function toBreakWord(intLen, strContent) {
	var strTemp = "";
	while (strContent.length > intLen) {
		strTemp += strContent.substr(0, intLen) + "<br>";
		strContent = strContent.substr(intLen, strContent.length);
	}
	strTemp += strContent;
	return strTemp;
}
function ChkUtil() {
}
ChkUtil.isNumStr = function (str) {
	var patrn = /[^\x00-\xff]/ig;
	return patrn.test(str);
};

ChkUtil.isPlusInteger = function (str) {
	var patrn = /^[1-9]\d*$/;
	return patrn.test(str);
};
ChkUtil.isPlusFloat = function (str) {
	var patrn = /^([+]?)\d*\.\d+$/;
	return patrn.test(str);
};

//是否是数字
ChkUtil.isDigit = function (str) {
	var patrn = /^\d+$/;
	return patrn.test(str);
};

//是否是电话
ChkUtil.isPhone = function (str) {
	var patrn = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
	return patrn.test(str);
};

//是否是手机
ChkUtil.isMobile = function (str) {
	var reg0 = /^13\d{5,9}$/;   //130--139。至少7位
	var reg1 = /^153\d{4,8}$/;  //联通153。至少7位
	var reg2 = /^159\d{4,8}$/;  //移动159。至少7位
	var ok = false;
	if (reg0.test(str)) {
		ok = true;
	}
	if (reg1.test(str)) {
		ok = true;
	}
	if (reg2.test(str)) {
		ok = true;
	}
	return ok;
};



//校验URL地址   
ChkUtil.isUrl = function (str) {
//var patrn=/[a-zA-z]+://[^s]*/;   
	var patrn = /((^http)|(^https)|(^ftp)):\/\/(\w)+.(\w)+/;
	return patrn.test(str);
};   
//校验电邮地址   
ChkUtil.isEmail = function (str) {
	var patrn = /^[\w-]+@[\w-]+(\.[\w-]+)+$/;
	return patrn.test(str);
};   
//校验邮编   
ChkUtil.isZipCode = function (str) {
	var patrn = /^\d{6}$/;
	return patrn.test(str);
};   
//校验合法时间   
ChkUtil.isDate = function (str) {
	if (!/\d{4}(\.|\/|\-)\d{1,2}(\.|\/|\-)\d{1,2}/.test(str)) {
		return false;
	}
	var r = str.match(/\d{1,4}/g);
	if (r == null) {
		return false;
	}
	var d = new Date(r[0], r[1] - 1, r[2]);
	return (d.getFullYear() == r[0] && (d.getMonth() + 1) == r[1] && d.getDate() == r[2]);
};  
//long型数据转化成date
ChkUtil.convertDate = function (num) {
	if (num != null) {
		return new Date(1000 * num);
	}
};
function getfocus(inputobj) {
	if (inputobj.value.indexOf("\u8bf7\u8f93\u5165") != -1) {
		inputobj.value = "";
	}
	if (inputobj.value == "") {
		inputobj.style.borderWidth = "1px";
		inputobj.style.borderStyle = "solid";
		inputobj.style.borderColor = "#B4B4B4";
		inputobj.style.height = "17px";
		inputobj.style.backgroundRepeat = "no-repeat";
		inputobj.style.backgroundPosition = "right";
	}
}
function getTextAreafocus(inputobj) {
	if (inputobj.value.indexOf("\u8bf7\u8f93\u5165") != -1) {
		inputobj.value = "";
	}
	if (inputobj.value == "") {
		inputobj.style.borderWidth = "1px";
		inputobj.style.borderStyle = "solid";
		inputobj.style.borderColor = "#B4B4B4";
	}
}

//取小数点的位数
function fixed(x, n) {
	with (Math) {
		var N = Math.pow(10, n);
		return Math.round(x * N) / N;
	}
}
ChkUtil.imagePath = function (str) {
	var path = str.substr(0, str.lastIndexOf(".")) + "_s.jpg";
	return path;
};

//校验合法时间   
ChkUtil.isDate = function (str) {
	if (!/\d{4}(\.|\/|\-)\d{1,2}(\.|\/|\-)\d{1,2}/.test(str)) {
		return false;
	}
	var r = str.match(/\d{1,4}/g);
	if (r == null) {
		return false;
	}
	var d = new Date(r[0], r[1] - 1, r[2]);
	return (d.getFullYear() == r[0] && (d.getMonth() + 1) == r[1] && d.getDate() == r[2]);
};
ChkUtil.isFloat = function (str) {
	return parseFloat(str, 10) == (str * 1) ? true : false;
};

//判断是否有有全角
ChkUtil.isSBCaseStr=function(str) {   
        var newstr=str.replace(/[^\uff00-\uffff]/g,"");
        if(newstr.length==0){
         return false;
        }   
         return true;
         
 };  
 
function check_length(id, nLength, maxLength) {
	var value = $(id).value;
	var lgth = value.length;
	var result;
	value = value.replace(/[^\u4E00-\u9FA5]/g, "");
	lgth += value.length;
	if (!maxLength) {
		maxLength = 2000;
	}
	if (lgth <= maxLength && lgth >= nLength) {
		result = true;
		return result;
	} else {
		if (lgth < nLength) {
			result = "short";
			return result;
		}
		if (lgth > maxLength) {
			result = "long";
			return result;
		}
	}
}
function isValidUser(uName, obj) {
	if (uName == "") {
		obj.style.color = "red";
		obj.innerHTML = "\u7528\u6237\u4e0d\u80fd\u4e3a\u7a7a!";
		return false;
	} else {
		if (ChkUtil.isNumStr(uName)) {
			obj.style.color = "red";
			obj.innerHTML = "\u7528\u6237\u540d\u4e0d\u80fd\u6709\u4e2d\u6587\u5b57\u7b26!";
			return false;
		}
	}
	if (uName != "") {
		url = "/bind/isValid.dhtml?uName=" + encodeURIComponent(uName);
		new Ajax.Request(url, {onComplete:function (res) {
			if (res.responseText == "1") {
				obj.style.color = "red";
				obj.innerHTML = "\u7528\u6237\u5b58\u5728\uff0c\u8bf7\u6362\u4e2a\u65b0\u7684!";
				return false;
			} else {
				obj.style.color = "green";
				obj.innerHTML = "\u606d\u559c\uff0c\u8be5\u7528\u6237\u540d\u53ef\u7528";
				return true;
			}
		}});
	}
	return true;
}

/*得到字符的长度*/
function getStrLong(str) {
	var valueLen = 0;
	var charNum = 0;
	if (str != "") {
		for (i = 0; i < str.length; i++) {
			var code = escape(str.charAt(i));
			if ((code.length >= 4) && (code < "%uFF60" || code > "%uFF9F")) {
				valueLen += 3;
			} else {
				valueLen += 1;
			}
			if (valueLen <= 100) {
				charNum++;
			}
		}
	}
	return Array(valueLen, charNum);
}

function $(ID){
  
return document.getElementById(ID);  

}
//only input number,-,backspace
function justNum(passCode){
          var evt = window.event?window.event:justNum.caller.arguments[0];
	      var code = window.event?event.keyCode:evt.which;
	      var b0=((code>=48)&&(code<=57)||(code==8));var b1=false;
	      if(!!passCode){
	        for(var i=0;i<passCode.length;i++){
	           if(code==passCode[i]) b1=true;
	        }
	      }
	      if(!(b0||b1)){
	         window.event?window.event.keyCode=0:evt.preventDefault();
	      }
 }
function checkSuffix(value){
	  var pattern = /^.*\.((jpg)||(bmp)||(gif))$/gi;
	  return pattern.test(value);
}
/*  
*    ForDight(Dight,How):数值格式化函数，Dight要  
*    格式化的  数字，How要保留的小数位数。  
*/  
function  forDight(Dight,How)  
{  
    Dight  =  Math.round  (Dight*Math.pow(10,How))/Math.pow(10,How);  
     return  Dight;  
}  
function checkFileSizeTrue(filePath)   
{  
   var picMaxSize=512;//K 
   var width=200;
   var hieght=200;
   var image=new Image();
   image.src=filePath;  
   // alert("调试信息imageSize:"+image.fileSize+"字节"); 
   var tempSize=forDight(image.fileSize/1024,1); //单位K
   if(tempSize>picMaxSize){
   		return false;
   }
   if((image.width<width-5||image.width>width+5)||(image.height<height-5||image.height>height+5)){
   		return false;
   }
   return true;
} 

function checkFileSizeIsTrue(filePath,width,height)   
{  
   var picMaxSize=1024;//K
   if(getBrowseType()=="MSIE"){//只对IE进行判断
   		var image=new Image();
   image.src=filePath;  
   // alert("调试信息imageSize:"+image.fileSize+"字节"); 
   var tempSize=forDight(image.fileSize/1024,1); //单位K
   if(tempSize>picMaxSize){
   		return false;
   }
   }   
   return true;
} 

function checkFlashType(value){
	  var pattern = /^.*\.((flv)||(swf))$/gi;
	  return pattern.test(value);
}
//--------判断浏览器类型--------------------
function getBrowseType() { 
    var OsObject = ""; 
   if(navigator.userAgent.indexOf("MSIE")>0) { 
        return "MSIE"; 
   } 
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
        return "Firefox"; 
   } 
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
        return "Safari"; 
   }  
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
        return "Camino"; 
   } 
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){ 
        return "Gecko"; 
   } 
   
} 

function downTheWholeReport(form,oldAction,newAction){
      form.action=newAction;
      form.submit();
      form.action=oldAction;
 
 }
