/**
 * [OElove] (C)2010-2099 oelove.com biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2019.01.04 by CL $
*/
var JS_ANIMATE_TIME = 200;
var JS_FADEIN_TIME = 200;
var JS_FADEOUT_TIME = 200;

//document tips
function dc() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') element = document.getElementById(element);
    if (arguments.length == 1) return element;
    elements.push(element);
  }
  return elements;
}

//随机数
function get_rndnum(n) {
	var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
	var res = "";
	for(var i = 0; i < n ; i ++) {
		var id = Math.ceil(Math.random()*35);
		res += chars[id];
	}
	return res;
}


//close message
function closemsg() {
	try{dc('msgbox').innerHTML = '';dc('msgbox').style.display = 'none';}catch(e){}
}

//dmsg
function dmsg(str, id, s, t) {
	var t = t ? t : 5000;
	var s = s ? true : false;
	try{if(s){window.scrollTo(0,0);}dc('d'+id).innerHTML = '<img src="'+_ROOT_PATH+'tpl/static/images/check_error.gif" width="12" height="12" align="absmiddle"/> '+str+sound('tip');$(id).focus();}catch(e){}
	window.setTimeout(function(){dc('d'+id).innerHTML = '';}, t);
}

//d sound
function sound(file) {
	return '<div style="float:left;"><embed src="'+_ROOT_PATH+'tpl/static/images/'+file+'.swf" quality="high" type="application/x-shockwave-flash" height="0" width="0" hidden="true"/></div>';
}

//全选
function checkAll(e, itemName){
  var aa = document.getElementsByName(itemName);
  for (var i=0; i<aa.length; i++)
   aa[i].checked = e.checked;
}
function checkItem(e, allName){
  var all = document.getElementsByName(allName)[0];
  if(!e.checked) all.checked = false;
  else{
    var aa = document.getElementsByName(e.name);
    for (var i=0; i<aa.length; i++)
     if(!aa[i].checked) return;
    all.checked = true;
  }
}

//判断是否为数字
function isDigit(){
    return ((event.keyCode >= 48) && (event.keyCode <= 57));
}
function isDigit2(){
    return ((event.keyCode >= 48) && (event.keyCode <= 57) || (event.keyCode = 46));
}

//只能由汉字，字母，数字和下横线组合
function check_userstring(str){  
    var re1 = new RegExp("^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|_|[a-zA-Z0-9])*$");
	if(!re1.test(str)){
		return false;
	}else{
		return true;
	}
}

//判断字符长度，一个汉字为2个字符
function strlen(s){
	var l = 0;
	var a = s.split("");
	for (var i=0;i<a.length;i++){
		if (a[i].charCodeAt(0)<299){
			l++;
		}else{
			l+=2;
		}
	}
	return l;
}


//判断字数个数
function strQuantity(s){
	var l = 0;
	var a = s.split("");
	for (var i=0;i<a.length;i++){
		if (a[i].charCodeAt(0)<299){
			l++;
		}else{
			l++;
		}
	}
	return l;
}

//判断所选择数量
function check_maxnum(id, my , num){
	var oEvent = document.getElementById('em_' + id + '_edit');
	var chks = oEvent.getElementsByTagName("INPUT");
	var count = 0;
	for(var i=0; i<chks.length; i++){
		if(chks[i].type=="checkbox"){
			if(chks[i].checked == true){
				count ++;
			}
			if(count > num){
				my.checked = false;
				alert('最多只能选择' + num + '项');
				return false;
			}
		}
	}
}


//valid Email
function isEmail(str) {
	var re = /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	return re.test(str);
}


//获取当前文件名
function get_curl() {
	var curl = document.URL;
	var filename = curl.split("?")[0];
	return filename;
}


//只能输入整数
function validIntval() { 
    var keyCode = event.keyCode;  
    if ((keyCode >= 48 && keyCode <= 57)) {  
		event.returnValue = true;  
    } 
	else {  
		event.returnValue = false;  
    }  
}

//允许输入浮点数
function validFloat() {
    var keyCode = event.keyCode;  
    if ((keyCode >= 48 && keyCode <= 57) || (keyCode == 46)) {  
		event.returnValue = true;  
    } 
	else {  
		event.returnValue = false;  
    }
}


/**
 * 检测上传图片后缀是否符合
 * @param:: string $fileurl 图片地址
 * @return:: bool true/false
*/
function validImageType(fileurl) {
	var result = false;
	var right_type = new Array(".jpg", ".jpeg", ".png", ".gif");
	var right_typeLen = right_type.length;
	var imgUrl = fileurl.toLowerCase();
	var postfixLen = imgUrl.length;
	var len4 = imgUrl.substring(postfixLen-4, postfixLen);
	var len5 = imgUrl.substring(postfixLen-5, postfixLen);
	for (i = 0; i<right_typeLen; i++){
		if((len4 == right_type[i]) || (len5==right_type[i])) {
			result = true;
		}
	}
	return result;
}

/**
 * 检测是否合法的11位手机号码 8.01.30
 * @param:: string $mobile 手机号码
 * @return:: bool true/false
*/
function validMobile(mobile) {
	var partten = /^1[3,4,5,6,8,9]\d{9}$/;
	if (partten.test(mobile)) {
		return true;
	}
	else {
		return false;
	}
}

/**
 * 刷新验证码
 * @param:: string $id
 * @return:: string
*/
function refresh_code(id) {
	if (typeof(id) == 'undefined') {id = 'checkCodeImg';}
	var ccImg = document.getElementById(id);
	if (ccImg) {
		ccImg.src= ccImg.src + '&' +Math.random();
	}
}

/**
 * 限制输入字符个数
 * 函数，3个参数，表单名字，表单域元素名，限制字符；  
*/
function textCounter(field, countfield, maxlimit) {  
	var contentvalue = $.trim($('#'+field).val());
	if (contentvalue.length > maxlimit) {
		$('#'+field).val(contentvalue.substring(0, maxlimit)); 
	}
	else  
		{  
		var cannum = (maxlimit - contentvalue.length);
		$('#'+countfield).html(cannum); 
	}
}

/**
 * 判断是否为合法中国手机号码 8.01.30
 * @param:: string mobile 手机号码
 * @return:: bool true/false
*/
function isMobile(mobile) {
	if (mobile.length != 11) {
		return false;
	}
	else {
		var is = false;
		var reg0 = /^13\d{5,9}$/; //13段号
		var reg1 = /^15\d{5,9}$/; //15段号
		var reg2 = /^18\d{5,9}$/; //18段号
		var reg3 = /^14\d{5,9}$/; //14段号
		var reg4 = /^17\d{5,9}$/; //17段号
        var reg5 = /^16\d{5,9}$/; //16段号
        var reg6 = /^19\d{5,9}$/; //19段号
		

		if (reg0.test(mobile)) is = true;
		if (reg1.test(mobile)) is = true;
		if (reg2.test(mobile)) is = true;
		if (reg3.test(mobile)) is = true;
		if (reg4.test(mobile)) is = true;
        if (reg5.test(mobile)) is = true;
        if (reg6.test(mobile)) is = true;

		if (!is) {
			return false;
		}
		else {
			return true;
		}
	}
}

/**
* 判断是否为合法QQ号码 
* @param:: string qq QQ号码 5-11位数字
* @return:: bool true/false
*/
function isQQ(qq){
	if (qq.length < 5 || qq.length > 11) {
		return false;
	}
	else {
		var is = false;
		var reg = /^[0-9]\d{4,12}$/;
		if (reg.test(qq))is = true;

		if (!is) {
			return false;
		}
		else {
			return true;
		}
	}
}


/**
 * post ajax
 * return:: string 
*/
function oeAjaxPost(url) {
	$response = 0;
	$result = "请求失败，请检查网络！";
	if (url.length > 0) {
		$.ajax({
			type: "POST",
			url: url,
			cache: false,
			data: {r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
			},
			error: function() {

			}
		});
	}
	$rs = $response+"|"+$result;
	return $rs;

}

//时间倒计时 2016.04.22
function countDownTime($time, tips, $color, $overtime_text) {
	if (typeof($color) == "undefined") {
		$color = "blue";
	}
	if (typeof($overtime_text) == "undefined") {
		$overtime_text = "已超时";
	}
	$_html = "";
	if ($time > 0) {
		$_date = new Date();
		$_now_time = $_date.getTime()/1000; //当前时间
		$_diff_time = ($time-$_now_time); //间隔时间

		if ($_diff_time > 0) { //未过时
			$_d = parseInt($_diff_time/(24*3600));//天
			$_h = parseInt(parseInt($_diff_time%(24*3600))/3600);//小时
			$_m = parseInt(parseInt($_diff_time%(24*3600)%3600)/60);//分
			$_s = parseInt(($_diff_time%(24*3600)%60)%60);//秒

			if ($_d > 0) {
				$_html += $_d+"天 ";
			}
			if ($_h > 0) {
				$_html += $_h+"小时 ";
			}
			if ($_m > 0) {
				$_html += $_m+"分钟 ";
			}
			$_html += $_s+"秒 ";
			if ($("#"+tips).length > 0) {
				$("#"+tips).html("<font color='"+$color+"'>"+$_html+"</font>");
			}
			setTimeout(function(){
				countDownTime($time, tips, $color);
			}, 1000); //循环跳动
		}
		else {
			$_html = "<font color='"+$color+"'>"+$overtime_text+"</font>";
			if ($("#"+tips).length > 0) {
				$("#"+tips).html($_html);
			}
			return false; //终止循环
		}
	}
}


$(function(){
	//焦点处理
	//$("[f='changept']").bind("click", function(){
	$(document).on("click", "[f='changept']", function(){
		$_input_id = $(this).attr("data-id");
		$("#"+$_input_id).focus();
	});
	//$("[f='checkinput']").bind("blur", function(){
	$(document).on("blur", "[f='checkinput']", function(){
		$_input_id = $(this).attr("id");
		if ($("#"+$_input_id).val().length > 0) {
			$("#"+$_input_id+"_pt").hide();
		}
		else {
			$("#"+$_input_id+"_pt").show();
		}
	});
	//$("[f='checkinput']").bind("keyup", function(){
	$(document).on("keyup", "[f='checkinput']", function(){
		$_input_id = $(this).attr("id");
		if ($("#"+$_input_id).val().length > 0) {
			$("#"+$_input_id+"_pt").hide();
		}
		else {
			$("#"+$_input_id+"_pt").show();
		}
	});
});
window.onload = function (){
    //隐藏input框提示文字
    setTimeout("_input_pt()",2000);
}
//隐藏input框提示文字
function _input_pt(){
    $("[f='checkinput']").each(function(){
        $_input_id = $(this).attr("id");
        if ($("#"+$_input_id).val().length > 0) {
            $("#"+$_input_id+"_pt").hide();
        }
    });
}


//统计textarea里的文本长度 7.03.31
function _countTextSize($input, $tips) {
	$_size = 0;
	$tips_obj = $("#"+$tips);
	$cont = $("#"+$input).val();
	if ($cont.length > 0) {
		$_size = strQuantity($cont);
	}
	$tips_obj.html($_size);
}

//获取IE版本号 8.04.25
function _get_ie_version() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if (isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if (fIEVersion == 7) {
            return 7;
        } 
        else if (fIEVersion == 8) {
            return 8;
        }
        else if (fIEVersion == 9) {
            return 9;
        }
        else if (fIEVersion == 10) {
            return 10;
        }
        else {
            return 6;//IE版本<=7
        }   
    } 
    else if(isEdge) {
        return 'edge';//edge
    } 
    else if(isIE11) {
        return 11; //IE11  
    }
    else{
        return -1;//不是ie浏览器
    }
}


//set cookie 8.08.28
function _setCookie2($name, $value, $days) {
    if (typeof($days) == "undefined") {
        $days = 30;
    }
    $exp = new Date();
    $exp.setTime($exp.getTime()+($days*24*60*60*1000));
    document.cookie = $name+"="+escape($value)+";expires="+$exp.toGMTString();
}

//get cookie 8.08.28
function _getCookie2($name) {
    var arr, reg = new RegExp("(^| )"+$name+"=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        return unescape(arr[2]);
    }
    else {
        return "";
    }
}

//del cookie 8.08.28
function _delCookie2($name) {
    $exp = new Date();
    $exp.setTime($exp.getTime() - 1);
    $cookie_val = _getCookie2($name);
    if ($cookie_val != null) {
        document.cookie= $name+"="+$cookie_val+";expires="+$exp.toGMTString();
    }
}


//打开引导... 2018.12.21
function _openGuide($name) {
    $('[data-pupop="'+ $name +'"]').show();
    $('[data-pupop="'+ $name +'"] .pupop').addClass('animated bounceIn');
}

//关闭引导... 2018.12.21
function _closeGuide($name) {
    $('[data-pupop="'+ $name +'"]').hide();
}


//set cookie 按分钟保存  2019.01.05
function _setCookieMin2($name, $value, $min) {
    if (typeof($min) == "undefined") {
        $min = 1; //默认1分钟....
    }
    $exp = new Date();
    $exp.setTime($exp.getTime()+($min*60*1000));
    document.cookie = $name+"="+escape($value)+";expires="+$exp.toGMTString();
}
