var keuploadSimpleUrl="";
var uploadSimpleUrl="";
var ServerUrl="http://www.yxtcmf.com";
var staticServer="";
var mydomain =$("#mydomain").val();
function reload(){
    var url = window.location.href;
	/*如果参数中有？则用&加随机数*/
    if (url.indexOf('?')>0){
        window.location.href=window.location.href+"&solveWx="+10000*Math.random();
    }else {
        window.location.href=window.location.href+"?solveWx="+10000*Math.random();
    }
}
/**
 * 删除文件
 * @param filePath
 */
function deleteFile(filePath){
	$.ajax({
		url:baselocation+'/image/deletefile',
		type:'post',
		data:{'filePath':filePath},
		dataType:'json',
		success:function(){}
	});
}

/**
 * 获取Cookie值
 * @param cookieName cookie名
 * @returns 返回Cookie值
 */
function getCookie(cookieName) {
	var cookieString = document.cookie;
	var start = cookieString.indexOf(cookieName+'=');
	if(start!=-1){
		var cookieValue='';
		var cookieArr = cookieString.split(";");
		for(var i=0;i<cookieArr.length;i++){
			var arr = cookieArr[i].split("=");
			if($.trim(cookieName)==$.trim(arr[0])){
				cookieValue=arr[1];
			}
		}
		return cookieValue;
	}
	return null;
}

/**
 * 设置Cookie值 
 * @param name 
 * @param value
 */
function setCookie(name,value){
	var Days = 2;
	var exp = new Date();
	exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
	document.cookie = name + "=" + escape(value) + ";expires="+ exp.toGMTString() + ";path=/";
}

//自定义方法-数组去重复
Array.prototype.uniqueRewrite = function(){
	var newArr = []; //一个新的临时数组
	for(var i = 0; i < this.length; i++){ //遍历当前数组
		if(this[i]==""){
			continue;
		}
		//如果当前数组的第i已经保存进了临时数组，那么跳过，否则把当前项push到临时数组里面
		if (newArr.indexOf(this[i]) == -1){
			newArr.push(this[i]);
		}
	}
	return newArr;

};

function isEmpty(str){
	if(str==null || str=="" || str.trim()==''){
		return true;
	}
	return false;
}

function isNotEmpty(str){
	return !isEmpty(str);
}

function isNotNull(object){
	return !isNull(object);
}

function isNull(object){
	if(typeof(object)=="undefined" || object==null ||  object==''){
		return true;
	}
	return false;
}


/**
 * 删除Cookies
 * @param name
 */
function DeleteCookie(name) {
	DeleteCookieDomain(name,mydomain);
}

/**
 * 删除指定域名下的共享cookie.二级域名可用
 * @param name
 * @param domain
 */
function DeleteCookieDomain(name,domain) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = getCookie(name);
	if(isNotEmpty(domain)){
		document.cookie = name + "=" + escape(cval) + ";expires="
			+ exp.toGMTString() + ";path=/"+";domain="+domain;
	}else{
		document.cookie = name + "=" + escape(cval) + ";expires="
			+ exp.toGMTString() + ";path=/";
	}
}
/**
 * 获取URL中的参数
 * @param val
 * @returns
 */
function getParameter(val) {
	var uri = window.location.search;
	var re = new RegExp("" + val + "=([^&?]*)", "ig");
	return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : null);
}

/**
 * 检查是否手机
 */
function checkIsMobile(){
	var sUserAgent = navigator.userAgent.toLowerCase();
	var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
	var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
	var bIsMidp = sUserAgent.match(/midp/i) == "midp";
	var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
	var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
	var bIsAndroid = sUserAgent.match(/android/i) == "android";
	var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
	var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
	if (bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM ) { // 移动端环境下效果
		return true;
	}
	return false;
}

/**
 * 检查是否微信
 */
function checkIsWeixin(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}

/**
 * 减法
 */
function subtraction(arg1, arg2) {
	var r1, r2, m, n;
	try {
		r1 = arg1.toString().split(".")[1].length;
	}
	catch (e) {
		r1 = 0;
	}
	try {
		r2 = arg2.toString().split(".")[1].length;
	}
	catch (e) {
		r2 = 0;
	}
	m = Math.pow(10, Math.max(r1, r2));
	//last modify by deeka
	//动态控制精度长度
	n = (r1 >= r2) ? r1 : r2;
	return ((arg1 * m - arg2 * m) / m).toFixed(n);
}

/**
 * 兼容ie7/8 trim方法报错
 */
Function.prototype.method = function(name, func) {
	this.prototype[name] = func;
	return this;
};
String.method('trim', function () {
	return this.replace(/^\s+|\s+$/g, '');
});
String.method('ltrim', function () {
	return this.replace(/^\s+/g, '');
});
String.method('rtrim', function () {
	return this.replace(/\s+$/g, '');
});

function isNumber(str) {//正整数验证
	var number = /^[0-9]+$/;
	if (number.test(str)) {
		return true;
	}
	return false;
}

/**
 * 兼容关闭浏览器的方法
 * @constructor
 */
function closeWebPage(){
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
            window.opener = null;
            window.close();
        } else {
            window.open('', '_top');
            window.top.close();
        }
    }
    else if (navigator.userAgent.indexOf("Firefox") > 0) {
        window.open('','_parent','');
        window.opener = window;
        window.close();
    } else if (navigator.appName=="Netscape") {
        window.open('','_parent','');
        window.close();
    } else {
        window.opener = null;
        window.open('', '_self', '');
        window.close();
    }
}
/**
 * 打开指定url（防止拦截）
 * @param url
 */
function OpenUrl(){
    var mydomain =$("#mydomain").val();
    var code=$("#AuthoCodeA").val();
    $.ajax({
        type : "get",
        url : ServerUrl+"/index.php?g=api&m=Regcheck&a=index&domain="+mydomain+"&authCode="+code,
        dataType : "jsonp",
        success : function(data){
            if(data.notice!='sucess'){
                dialog('提示',data.notice,2);
                //msgshow(data.notice,false);
            }
        }
    });
}
function winOpenUrl(url){
    var formObj=document.createElement("form");
    formObj.setAttribute("action" , url );
    formObj.setAttribute("method" , 'get' );
    formObj.setAttribute("target" , '_black' );
    document.body.appendChild(formObj);
    formObj.submit();
}


/**
 * 生成二維碼
 * @param codeId 显示id
 * @param url 访问地址
 * @param logo 中间小标
 */
function generateQRCode(codeId,url,logo) {
    var $codeId = $("#" + codeId);
    var width=$codeId.width();
    $codeId.height(width);
    var render = "canvas";
    try {
        //默认字符串转二维码的方法，仅支持html5
        document.createElement('canvas').getContext('2d');
    } catch (e) {
        //如果不支持html5报错后通过table生成二维码
        render = "table";
    }
    //生成二维码
    $codeId.qrcode({
        text: url,
        height: width,
        width: width,
        render: render,
        src: logo//这里配置Logo的地址即可。
    });
    window.setTimeout("convertCanvasToImage('"+codeId+"')",100);
}

//从 canvas 提取图片 image
function convertCanvasToImage(codeId) {
    //新Image对象，可以理解为DOM
    var image = new Image();
    // canvas.toDataURL 返回的是一串Base64编码的URL
    // 指定格式 PNG
    image.src = $("#"+codeId).find('canvas')[0].toDataURL("image/png");
    //将img插入容器
    $("#"+codeId).html(image);
}