function isInt(value) {
    if ((/^(\+|-)?\d+$/.test(value)) || value < 0) {
        return true;
    } else {
        jQuery("#amount").val("0");
        return false;
    }
}

function mAlert(title, value) {
	top.dialog({
		title: title,
		content: value,
		fixed: false,
		padding: 40
	}).showModal();
}

/*
* 检测客户端是否存在
*/
function checkeInstalled() {
    try {
        new ActiveXObject("EIMSDll.EIMSCheck");
        return true;
    }
    catch (e) {
        return false;
    }

    return true;
}

function loading(val) {
    var height = $(document.body).height();
    height = parseInt(height, 10) < 1 ? '100%' : height + 'px';
    val = (typeof val == undefined || val == null) ? '正在努力为您加载中，请耐心等待...' : val;

    $(document.body).append("<div class=\"mbody\" style=\"height:" + height + "\" id=\"page_loading\"><div class=\"load_main\"><div class=\"load_img\"><img src=\""+webroot+"theme/eycmscn/images/view/loading.gif\" width=\"70\" height=\"70\" /></div><div class=\"load_font\"><font size=\"3\">" + val + "</font></div></div></div>");
}

function clearload() {
    $('#page_loading').remove();
}

function initDiagWindowSize(width, height) {
    var _w = width;
    var _h = height;

    if (typeof _w == 'undefined' || _w < 1) {
        _w = document.body.clientWidth;
    }
    if (typeof _h == 'undefined' || _h < 1) {
        _h = document.body.clientHeight;
    }
    try {
        $('#art_iframe', window.parent.document).css({ 'height': _h + 'px', 'width': _w + 'px' });
		top.dialog.get(window).width(_w);
		if (_h>0){top.dialog.get(window).height(_h);}
    } catch (a) { }
}

$(function () {
    $(window).bind("scroll", function (event) {
        _scrollLoad();
    });

    $('#scrolltop>div').hover(
            function () {
                $(this).find('div:eq(1)').animate({ 'left': '-48px' }, 300);
            },
            function () {
                $(this).find('div:eq(1)').animate({ 'left': '32px' }, 300);
            }
    );

    /* IE6 环境下的提示 */
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
	(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
	(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
	(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
	(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
    var ieversion;
    if (Sys.ie) {
        ieversion = parseInt(Sys.ie);
        if (ieversion < 7) {
            alert('您的浏览器版本较低！\r\n为了不影响您的正常使用，建议您升级高版本浏览器！');
        }
    }
});

function _scrollLoad() {
    var top = document.documentElement.scrollTop + document.body.scrollTop;
    var textheight = $(document).height();
}

function srcollTop() {
    $('body,html').animate({ 'scrollTop': 0 }, 500);
}

function IsNullOrEmpty(str) {
    if (str == null || str == undefined || typeof str == undefined || str == "null" || str == "undefined" || str == "") { return true; }
    else { return false; }
}

function fnSaveCookie(key, value, expireHour) {
    var exDate = new Date();
    if (!IsNullOrEmpty(expireHour)) {
        exDate.setTime(exDate.getTime() + expireHour * 3600 * 1000); document.cookie = key + "=" + value + (IsNullOrEmpty(expireHour) ? "" : ";expires=" + exDate);
    } else { document.cookie = key + "=" + value; }
}

//处理url中的字符串，取出某个键p的值
function getParam(p) {
    var url = window.location.search;
    var paras = url.substring(url.indexOf("?") + 1, url.length).split("&");
    return splitChain(paras, p);
}
//处理a=1&b=2&c=3这样的字符串，分割并取出键p的值
function splitChain(paras, p) {
    var paraObj = {}
    for (i = 0; j = paras[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    if (p != null) {
        var returnValue = paraObj[p.toLowerCase()];
        if (typeof (returnValue) == "undefined") {
            return "";
        } else {
            return returnValue;
        }
    } else {
        return paraObj;
    }
}

String.prototype.padLeft = function (totalWidth, paddingChar) {
    if (this.length >= totalWidth || (paddingChar == undefined || paddingChar.length == 0))
        return this;
    else {
        left = "";
        while (left.length < (totalWidth - this.length))
            left += paddingChar.toString();
        return left.toString() + this;
    }
};

function WindowOpen(url) {

    var newWindow = window.open(url, "_blank");

    if (IsNullOrEmpty(newWindow)) {

        var form = $(document).find("form:first");

        if (form.length == 0) {
            return;
        }

        var actionUrl = form.attr("action");
        var actionTarget = form.attr("target");

        form.attr({ action: url, target: "_blank" });
        form.submit();

        setTimeout(function () {
            $(document).find("form:first").attr({ action: actionUrl, target: actionTarget });
        }, 1000);
    }
}

function strCut(val, len) {
    if (typeof val == 'undefined' || val == null) {
        return '';
    }

    if (val.length < len) {
        return val;
    }

    return val.substr(0, len) + '..';
}

//跳转方法，避免open方法被浏览器阻止
function openwin(url) {
    var a = window.parent.document.createElement("a");
    a.setAttribute("href", url);
    a.setAttribute("target", "_blank");
    a.setAttribute("id", "openwin");
    window.parent.document.body.appendChild(a);
    a.click();
}


function SaveCookie(key, value, expireHour) {
    var exDate = new Date();
    if (!IsNullOrEmpty(expireHour)) {
        exDate.setTime(exDate.getTime() + expireHour * 3600 * 1000);
        document.cookie = key + "=" + escape(value) +
            (IsNullOrEmpty(expireHour) ? "" : ";expires=" + exDate);
    } else {
        document.cookie = key + "=" + escape(value);
    }
}

//2014-9-28判断为移动端就隐藏两边的二维码等信息

var browser = {
    versions: function () {
        var u = navigator.userAgent, app = navigator.appVersion;
        return {
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
            mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
            iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
            iPad: u.indexOf('iPad') > -1, //是否iPad
            webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
        };
    } ()
}
$(function () {
    if ((browser.versions.mobile && browser.versions.android) || (browser.versions.mobile && browser.versions.ios)) {
        //判断为移动端就隐藏两边的二维码等信息
        $(".jb_ewmk").hide();
        $("iframe").contents().find("div.main").hide();

    }
});
window.onload = function () {
    if ((browser.versions.mobile && browser.versions.android) || (browser.versions.mobile && browser.versions.ios)) {
        //判断为移动端就隐藏两边的二维码等信息
        $(".jb_ewmk").hide();
        $("iframe").contents().find("div.main").hide();

    }
};
//end 2014-9-28

function setqq(qq){
    var tempSrc=webroot+'plug/wpa.asp?rantime='+Math.random()+"&qq="+qq;
    var oldscript=document.getElementById('testJs');
    var newscript=document.createElement('script');
    newscript.setAttribute('type','text/javascript'); 
    newscript.setAttribute('id', 'testJs');
    newscript.setAttribute('src',tempSrc);
    if(oldscript == null){
        document.body.appendChild(newscript);}
    else{
        oldscript.parentNode.replaceChild(newscript, oldscript);
    }
    return false;
}