﻿DD_belatedPNG.fix('.png');

/*******以下为校验方法********/
function isNull(str) {
    if (str == ""||str==null) return true;
    var regu = "^[ ]+$";
    var re = new RegExp(regu);
    return re.test(str);
}

function isInteger(str) {
    var regu = /^[-]{0,1}[0-9]{1,}$/;
    return regu.test(str);
}

function isDecimal(str) {
    if (isInteger(str)) return true;

    if (str.indexOf(".") == 0 || str.indexOf(".") == str.length - 1) {
        return false;
    }
    var re = /^\-?(\d+)[\.]+(\d{0,5})$/;
    if (re.test(str)) {
        if (RegExp.$1 < 0 && RegExp.$2 == 0) return false;
        return true;
    } else {
        return false;
    }
}

function formatNumber(str) {
    if (isNull(str) == true) {
        return "0";
    }
    if (str.indexOf(".") > 1) {
        str = str.substring(0, str.indexOf(".") + 2);
    }
    re = /(\d{1,3})(?=(\d{3})+(?:$|\.))/g;
    alert(str.replace(re, "$1,"));
    return str;
}

function deFormatNumber(str) {
    str = str.replace(",", "");
    return str;
}

function isEmail(str) {
    var re = /^[\w-]+(\.[\w-]{1,})*@[\w-]+(\.[\w-]{2,6})+$/;
    return re.test(str);
}

function isTel(str) {
    var re = /^[0-9-()]{11,20}$/;
    var re2 = /^[0-9]{8,15}$/;
    return (re.test(str)||re2.test(str));
}

function isMobi(str) {
    var re = /^[0-9]{11,15}$/;
    return re.test(str);
}

function isName(str) {
    var re = /^[a-zA-Z0-9]{4,20}$/;
    return re.test(str);
}

function isPass(str) {
    var re = /^.{6,16}$/;
    return re.test(str);
}

// 字符长度
function getLength(str) {
    var len = str.length;
    var reLen = 0;
    for (var i = 0; i < len; i++) {        
        if (str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126) { 
            reLen += 2;
        } else {
            reLen++;
        }
    }
    return reLen;    
} 

/**
* 判断输入的信息是否超过合法的长度。传入参数中，nLen为允许输入的英文字符个数
*
* @param {String} str 待检测的字符串
* @param {Number} maxLength 允许输入的英文字符个数
* @return true if str's length<=maxLength, false otherwise.
* @type Boolean
*/
function isLegal(str, maxLength) {
    var realLength = getStringLength(str);
    return (realLength <= maxLength);
}

/**
* Return the length of a string in ISO-8859 format. This is because the
* disunity of different encodings under different platforms. Eg. getStringLength("ABC")
* will get 3, getStringLength("中文") will get 4. Note you'd better add a line of meta
* information to your html so as the browser can detect what encoding it should
* employ. eg. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
*
* @param {String} str 待检测的字符串
* @return str的长度(英文字符个数)
* @type Number
*/
function getStringLength(str) {
    if (str == null || str.length == 0) {
        return 0;
    }
    var strLong = 0;
    var browserLen = str.length;
    var result = 0;
    var charCode = 0;
    for (i = 0; i < browserLen; i++) {
        charCode = str.charCodeAt(i);
        if (charCode > 255) {
            strLong += 2;
        } else {
            strLong += 1;
        }
    }
    return strLong;
}

function isDigit(num) {
    var string = "1234567890";
    if (string.indexOf(num) != -1) {
        return true;
    }
    return false;
}

// 获取滚动条距离
function getScrollTop() { 
    var t
    if (document.documentElement && document.documentElement.scrollTop) {
        t = document.documentElement.scrollTop;
    }
    else if (document.body) {
        t = document.body.scrollTop;
    }

    return t;
}

// 加载图片集
function LoadThumb(options) {
    var arrLen=$(options).size();
    
    var k=0;
    $.each( options, function(i, n){
        loadImg(n);
        k++
    }); 
    
    if(arrLen==k){return true;}
    else{return false;}
}

// 加载图片
function loadImg(src){
	var img = new Image();
	img.src =src;
	
    //如果图像已经被缓存了
    if (img.complete) {}
    else{img.onload = function () {};} //当图像载入完成，异步执行回调函数
}


function getSplit(str,split){
    if(isNull(str)){ return str}
    else{  return str.split(split); }
}

//***********************************************************************************

function GetJson(obj){
   return eval('('+obj+')');
}

//***********************************************************************************

function changeImgCode() {    
    var imgNode = document.getElementById("imgCode");    
    imgNode.src = "/web_public/chkCode.aspx?t=" + (new Date()).valueOf();
}  

// 限制内容里图片宽度
function change_ImgWidth(obj,width){
    var img=$(obj+' img');
    
	$(''+obj+' img').each(function(i,n){
		if($(this).width()>width){
			var o_width=$(this).width();
			var o_height=$(this).height();
			var height=(o_height*width)/o_width
			$(this).width(width);
			$(this).height(height);
		}	
	});
}

//***********************************************************************************

// li元素滑过效果
function liTabFun(id){
    var Ptr=document.getElementById(id).getElementsByTagName("li");
    //function $() {
    //      for (i=1;i<Ptr.length+1;i++) { 
    //      Ptr[i-1].className = (i%2>0)?"t1":"t2"; 
    //      }
    //}
    window.onload=$;
    for(var i=0;i<Ptr.length;i++) {
          Ptr[i].onmouseover=function(){
          this.tmpClass=this.className;
          this.className = "t3";    
          };
          Ptr[i].onmouseout=function(){
          this.className=this.tmpClass;
          };
    }
}

//***********************************************************************************

function play_video(width,height,file,emid,autostart)
{
    var s1 = new SWFObject("/style/jscommon/flv/flvplayer_player.swf","ply",width,height,"9","#000000");
    s1.addParam("allowfullscreen","true");
    s1.addParam("allowscriptaccess","always");
	s1.addParam("menu","false");
    s1.addParam("wmode","opaque");
	s1.addParam("flashvars","file="+file+"&autostart="+autostart+'');
    s1.write(emid);
}

function showflash(file,width,height,emid){
   var so = new SWFObject(file, "mymovie", width, height, "7", "#fff");
   so.addParam("quality", "high");
   so.addParam("wmode", "transparent");
   so.addParam("salign", "t");
   so.write(emid);

}
