//复制到剪贴板
function copyToClipBoard(content){
	document.execCommand("Copy");

	//window.clipboardData.clearData();
	//window.clipboardData.setData("Text",content);
}

function checknum(p, len) {
	var l = p.length;
	var count=0;

	if (p == "") {
		return true;
	} else {
		if (len > 0 && l != len) {
			return false;
		}

		for(var i=0; i<l; i++) {
			var digit = p.charAt(i);
			if(digit < "0" || digit > "9")	{
				return false;
			}
		}

		return true;
	}
}

function isAlpaNum(str) {

	var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
	var ch;
	var i;
	var temp;

	for (i=0;i<=(str.length-1);i++) {
		ch = str.charAt(i);
		temp = strSource.indexOf(ch);
		if (temp == -1) {
			return false;
		}
	}

	return true;

}

function checkFileName(str) {

	var strLen;

	strLen = str.length;

	if ( strLen > 0 && strLen <= 5) {
		return false;
	}

	if ( strLen > 5 ) {
		if ( str.substring(strLen-5,strLen) != ".html" ) {
			return false;
		}

	}

	return true;

}

// 整数であるかをチェックします。
function isNumber(str)
{
	if (str.length < 1) {
		return true;
	}
	var strSource ="0123456789";
	var ch;
	var i;
	var temp;

	for (i=0;i<=(str.length-1);i++) {
		ch = str.charAt(i);
		temp = strSource.indexOf(ch);
		if (temp==-1) {
		return false;
		}
	}
	return true;
}

// 数値であるかをチェックします。
function isNumeric(num) {
	if (num.length < 1) {
		return true;
	}
	if (num.match(/[^0-9\-\.]/g)) {
		return false;
	}
	if (!num.match(/^\-?[0-9]*\.?[0-9]*$/g)) {
		return false;
	}
	return true;
}

function isPointNumber(str)
{
	var strSource ="0123456789.";
	var ch;
	var i;
	var temp;

	for (i=0;i<=(str.length-1);i++) {
		ch = str.charAt(i);
		temp = strSource.indexOf(ch);
		if (temp==-1) {
		return false;
		}
	}
	return true;
}

function isDateString(sDate) {
	var iaMonthDays = [31,29,31,30,31,30,31,31,30,31,30,31];
	var iaDate = new Array(4);
	var year, month, day, hour;

	if (sDate.length != 8 && sDate.length != 10) return false;

	if (checknum(sDate, 0) == false ) {
		return false;
	}

	iaDate[0] = sDate.charAt(0) + sDate.charAt(1) + sDate.charAt(2) + sDate.charAt(3);
	iaDate[1] = sDate.charAt(4) + sDate.charAt(5);
	iaDate[2] = sDate.charAt(6) + sDate.charAt(7);
	if (sDate.length == 10) {
		if ( checknum(sDate,10) == false ) { return false; }
		iaDate[3] = sDate.charAt(8) + sDate.charAt(9);
	} else {
		iaDate[3] = "00";
	}
	if (iaDate[1].length > 2 || iaDate[2].length > 2 || iaDate[3].length > 2) return false;

	year = parseFloat(iaDate[0]);
	month = parseFloat(iaDate[1]);
	day = parseFloat(iaDate[2]);
	hour = parseFloat(iaDate[3]);

	if (year < 1900 || year > 2100) return false;
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
	if (month < 1 || month > 12) return false;
	if (day < 1 || day > iaMonthDays[month - 1]) return false;
	if (hour > 23 || hour < 0) return false;
	return true;
}

function isDateTimeString(sDate) {
	var iaMonthDays = [31,29,31,30,31,30,31,31,30,31,30,31];
	var iaDate = new Array(5);
	var year, month, day, hour, min;

	if (sDate.length != 8 && sDate.length != 10 && sDate.length != 12) {
		return false;
	}

	if (checknum(sDate, 0) == false ) {
		return false;
	}

	iaDate[0] = sDate.charAt(0) + sDate.charAt(1) + sDate.charAt(2) + sDate.charAt(3);
	iaDate[1] = sDate.charAt(4) + sDate.charAt(5);
	iaDate[2] = sDate.charAt(6) + sDate.charAt(7);

	if (sDate.length == 10) {
		iaDate[3] = sDate.charAt(8) + sDate.charAt(9);
		iaDate[4] = "00";
	}
	if (sDate.length == 12) {
		iaDate[3] = sDate.charAt(8) + sDate.charAt(9);
		iaDate[4] = sDate.charAt(10) + sDate.charAt(11);
	}

	year = parseFloat(iaDate[0]);
	month = parseFloat(iaDate[1]);
	day = parseFloat(iaDate[2]);
	hour = parseFloat(iaDate[3]);
	min = parseFloat(iaDate[4]);

	if (year < 1900 || year > 2100) return false;
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
	if (month < 1 || month > 12) return false;
	if (day < 1 || day > iaMonthDays[month - 1]) return false;
	if (hour > 23 || hour < 0) return false;
	if (min > 59 || min < 0) return false;

	return true;
}

function isYYYYMMDDHHString(sDate) {
	var iaMonthDays = [31,29,31,30,31,30,31,31,30,31,30,31];
	var iaDate = new Array(4);
	var year, month, day, hour;

	if (checknum(sDate, 10) == false ) {
		return false;
	}

	iaDate[0] = sDate.charAt(0) + sDate.charAt(1) + sDate.charAt(2) + sDate.charAt(3);
	iaDate[1] = sDate.charAt(4) + sDate.charAt(5);
	iaDate[2] = sDate.charAt(6) + sDate.charAt(7);
	iaDate[3] = sDate.charAt(8) + sDate.charAt(9);

	year = parseFloat(iaDate[0]);
	month = parseFloat(iaDate[1]);
	day = parseFloat(iaDate[2]);
	hour = parseFloat(iaDate[3]);

	if (year < 1900 || year > 2100) return false;
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
	if (month < 1 || month > 12) return false;
	if (day < 1 || day > iaMonthDays[month - 1]) return false;
	if (hour > 23 || hour < 0) return false;

	return true;
}

function isYYYYMMDDHHMIString(sDate) {
	var iaMonthDays = [31,29,31,30,31,30,31,31,30,31,30,31];
	var iaDate = new Array(4);
	var year, month, day, hour;

	if (checknum(sDate, 12) == false ) {
		return false;
	}

	iaDate[0] = sDate.charAt(0) + sDate.charAt(1) + sDate.charAt(2) + sDate.charAt(3);
	iaDate[1] = sDate.charAt(4) + sDate.charAt(5);
	iaDate[2] = sDate.charAt(6) + sDate.charAt(7);
	iaDate[3] = sDate.charAt(8) + sDate.charAt(9);
	iaDate[4] = sDate.charAt(10) + sDate.charAt(11);

	year = parseFloat(iaDate[0]);
	month = parseFloat(iaDate[1]);
	day = parseFloat(iaDate[2]);
	hour = parseFloat(iaDate[3]);
	minute = parseFloat(iaDate[4]);

	if (year < 1900 || year > 2100) return false;
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
	if (month < 1 || month > 12) return false;
	if (day < 1 || day > iaMonthDays[month - 1]) return false;
	if (hour > 23 || hour < 0) return false;
	if (minute > 59 || minute < 0) return false;

	return true;
}

function isHHiiString(sTime) {
	 if (!sTime.match(/^\d{2}\:\d{2}$/)) {
	  return false;
	 }
	 hour = parseFloat(sTime.charAt(0) + sTime.charAt(1));
	 minute = parseFloat(sTime.charAt(3) + sTime.charAt(4));
	 if (hour > 23 || hour < 0) return false;
	 if (minute > 59 || minute < 0) return false;
	 return true;
}

function Check(reg,str)
{
	if(reg.test(str)) {
		return true;
	}
	return false;
}

function CheckEmail(str) {
	var reg = /^[\-a-zA-Z0-9_][\.\-a-zA-Z0-9_]*@[\-a-zA-Z0-9_]+(.[\-a-zA-Z0-9_]+)*$/;
	return Check(reg,str);
}

function isMobileName(str) {

	var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
	var ch;
	var i;
	var temp;

	for (i=0;i<=(str.length-1);i++) {
		ch = str.charAt(i);
		temp = strSource.indexOf(ch);
		if (temp == -1) {
			return false;
		}
	}

	return true;

}

// ひらがなチェック
function isHiragana(var_string){

	if (var_string.length < 1) {
		// 空文字列ならとりあえずOK
		return true;
	}

	//if(var_string.match(/^[\u3040-\u309F]*$/)) {
	if(var_string.match(/^[ぁ-ん゛゜ーゝヾゞ]+$/)) {
		return true;
	}else{
		return false;
	}
}

// カタカナチェック
function isKatagana(var_string) {

	if (var_string.length < 1) {
		// 空文字列ならとりあえずOK
		return true;
	}

	//if(var_string.match(/^[\u30A0-\u30FF]*$/)) {
	if(var_string.match(/^[ァ-ヶ゛゜ーゝヾゞ]+$/)) {
		return true;
	}else{
		return false;
	}
}

/**
 * 引数strに対して、trim処理を行います。
 */
function trim(str) {
	for(var i = 0; i < str.length && str.charAt(i) == " "; i++) {
	}

	for(var j = str.length; j > 0 && str.charAt(j-1) == " "; j--) {
	}

	if(i > j) {
		return  "";
	}

	return  str.substring(i,j);
}
function checkUrl(url) {
	if (url.match(/^(https?:\/\/)?(([0-9a-z][0-9a-z-]*\.)|(([0-9a-z-]+\.)+))[a-z]+/i)) {
		return true;
	}
	return false;
}

function checkDomain(str) {
	var reg = /^[0-9a-zA-Z]+[0-9a-zA-Z\-\.]+\.([a-zA-Z]{2,})$/;
	return Check(reg,str);
}

function checkRedirect(str) {

	var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-";
	var ch;
	var i;
	var temp;

	for (i=0;i<=(str.length-1);i++) {
		ch = str.charAt(i);
		temp = strSource.indexOf(ch);
		if (temp == -1) {
			return false;
		}
	}

	return true;

}

function isSpecialNumber(str) {
	var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var ch;
	var i;
	var temp;

	for (i=0;i<=(str.length-1);i++) {
		ch = str.charAt(i);
		temp = strSource.indexOf(ch);
		if (temp == -1) {
			return false;
		}
	}
	return true;
}

function isHalfKatagana(str) {
	if (str.match(/^[｡-ﾟ]*$/)) {
		return true;
	}
	return false;

}

function trashGomi(s) {
	s = unescape(escape(s).split("%00")[0]);
	return s;
}

function getByte(str) {
	if (str == "" || !str || str == null) return 0;
	str = trashGomi (str);
	var strS = str.replace (/[^0-9a-zｱ-ﾝ\!\"\#\$\%\&\'\(\)\-\=\^\~\\\|\@\`\[\{\;\+\:\*\]\}\,\<\.\>\/\?\_]/ig, "##");
	return strS.length;
}

function isFullString(str) {
	if (getByte(str) != str.length * 2) {
		return false;
	}
	return true;
}

function isAlpaNumSpace(str) {

	var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_- ";
	var ch;
	var i;
	var temp;

	for (i=0;i<=(str.length-1);i++) {
		ch = str.charAt(i);
		temp = strSource.indexOf(ch);
		if (temp == -1) {
			return false;
		}
	}

	return true;

}

function formIsChange(form){
	var oElem;
	var isChange = false;
	cycle:for (var i = 0; i < form.elements.length; i++) {
			oElem = form[i];
			switch (oElem.type) {
				case "text" :
				case "password" :
				case "textarea" :
				case "file" :
				case "hidden" :
					if (oElem.defaultValue != oElem.value){
						isChange = true;
						break cycle;
					}
					break;
				case "checkbox" :
				case "radio" :
					if (oElem.defaultChecked != oElem.checked){
						isChange = true;
						break cycle;
					}
					break;
				case "select-one" :
				case "select-multiple":
					for (var n = 0; n < oElem.options.length; n++  ) {
						if (oElem.options[n].value != 0 && oElem.options[n].selected != oElem.options[n].defaultSelected) {
							isChange = true;
							break cycle;
						}
					}
				break;
			}
	}
	return isChange;
}

// check Ip
function checkIp(str) {
    if (str == "" || !str || str == null) return false;
    var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g;
    if(re.test(str)) {
        if(RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256) return true;
    }
    return false;
}

function checkImg(filename) {
	var fileType = (filename.substring(filename.lastIndexOf(".")+1,filename.length)).toLowerCase();
	var supportFile = new Array();
	supportFile[0] = "gif";
	supportFile[1] = "png";
	supportFile[2] = "jpg";
	is_type_supported = false;

	for (var i =0;i<supportFile.length;i++) {
		if (supportFile[i]==fileType) {
			is_type_supported = true;
			break;
		} else{
			continue;
		}
	}

	return is_type_supported;
}

function setImagePreview(aval, bval, cval) {
    var docObj = document.getElementById(aval);
    var imgObjPreview = document.getElementById(bval);
    var divs = document.getElementById(cval);
    if (docObj.files && docObj.files[0]) {
        //火狐下，直接设img属性
        imgObjPreview.style.width = '75px';
        //imgObjPreview.style.height = '40px';
        //imgObjPreview.src = docObj.files[0].getAsDataURL();
        //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
       imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
    } else {
        //IE下，使用滤镜
        docObj.select();
        var imgSrc = document.selection.createRange().text;
        var localImagId = document.getElementById(cval);
        //必须设置初始大小
        localImagId.style.width = "75px";
        //localImagId.style.height = "40px";
        //图片异常的捕捉，防止用户修改后缀来伪造图片
        try {
            localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
            localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
        } catch(e) {
            return false;
        }
        imgObjPreview.style.display = 'none';
        document.selection.empty();
    }
    return true;
}

function isFullDateTimeString(str) {
    if (r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})\s(\d{1,2}):(\d{1,2}):(\d{1,2})$/)) {
    	var d = new Date(r[1], r[3]-1, r[4]);
	    if (d.getFullYear() == r[1] && d.getMonth()+1 == r[3] && d.getDate() == r[4]) {
	    	if (r[5] >= 0 && r[5] <= 23 && r[6] >= 0 && r[6] <= 59 && r[7] >= 0 && r[7] <= 59) {
	    		return true;
	    	}
	    }
    }
    return false;
}